@seqyuan/annovibe 0.8.37 → 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 +6 -6
  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 +2 -2
  19. package/.next/server/app/_not-found.segments/_full.segment.rsc +2 -2
  20. package/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  21. package/.next/server/app/_not-found.segments/_index.segment.rsc +2 -2
  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 +2 -2
  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 +3 -3
  30. package/.next/server/app/index.segments/__PAGE__.segment.rsc +2 -2
  31. package/.next/server/app/index.segments/_full.segment.rsc +3 -3
  32. package/.next/server/app/index.segments/_head.segment.rsc +1 -1
  33. package/.next/server/app/index.segments/_index.segment.rsc +2 -2
  34. package/.next/server/app/index.segments/_tree.segment.rsc +2 -2
  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 +2 -2
  38. package/.next/server/app/login.segments/_full.segment.rsc +2 -2
  39. package/.next/server/app/login.segments/_head.segment.rsc +1 -1
  40. package/.next/server/app/login.segments/_index.segment.rsc +2 -2
  41. package/.next/server/app/login.segments/_tree.segment.rsc +2 -2
  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 +3 -3
  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 +2 -2
  48. package/.next/server/app/smoke.rsc +2 -2
  49. package/.next/server/app/smoke.segments/_full.segment.rsc +2 -2
  50. package/.next/server/app/smoke.segments/_head.segment.rsc +1 -1
  51. package/.next/server/app/smoke.segments/_index.segment.rsc +2 -2
  52. package/.next/server/app/smoke.segments/_tree.segment.rsc +2 -2
  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 +6 -6
  56. package/.next/server/middleware-build-manifest.js +1 -1
  57. package/.next/server/pages/404.html +1 -1
  58. package/.next/server/pages/500.html +1 -1
  59. package/.next/server/server-reference-manifest.json +1 -1
  60. package/.next/static/chunks/app/page-443865609e7e67a7.js +27 -0
  61. package/.next/static/css/{5a346973ceb3dbc6.css → 56d2e8f8c1614464.css} +1 -1
  62. package/package.json +1 -1
  63. package/.next/static/chunks/app/page-fb7e974c7c588911.js +0 -27
  64. /package/.next/static/{LPDY7d1rQxff1OqgbwTWa → tzG34HSOTS30YvTSTz81W}/_buildManifest.js +0 -0
  65. /package/.next/static/{LPDY7d1rQxff1OqgbwTWa → tzG34HSOTS30YvTSTz81W}/_ssgManifest.js +0 -0
@@ -1,27 +0,0 @@
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.37":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),[R,L]=(0,o.useState)(null),[W,E]=(0,o.useState)(""),[$,P]=(0,o.useState)(null),[D,B]=(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,G]=(0,o.useState)(null),Z=(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(Z.current){Z.current=!1;return}if(Q.current){Q.current=!1;return}v?.(R)},[R,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,L(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===R){if(i&&!en.current){en.current=!0;let e=k.find(e=>e.id===i);if(e){L(e.cwd),ei(e.cwd),t(e,!0);return}l?.()}let e=S[0]?.cwd;e&&(L(e),ei(e))}},[k,S,R,i,t,l,ei]);let es=g??R,ea=(0,o.useCallback)(e=>{if(!e){O("chat"),B(!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),B(!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),B(!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&&(Z.current=!0,L(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=>{G("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{G(null)}},[et]),em=(0,o.useCallback)(async(e,t)=>{G(`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{G(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:D,initialPath:es||W||null,onClose:()=>B(!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"],R=[...I,S];function L(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 R;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"},D={off:"无工具,纯聊天",default:"4 项内置工具",full:"全部内置工具",workbench:"全工具 + Workbench 运行时",agent:"High + 子代理"},B={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
- ${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
- ${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
- ${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
-
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,R,L,[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),[G,Z]=(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&&!l,ex=et?"var(--text)":"var(--text-muted)",eg={padding:"7px 8px",borderRadius:8,background:"var(--bg-panel)",border:"1px solid var(--border)",width:"100%",textAlign:"left",cursor:"pointer"},[ef,ev]=(0,o.useState)(null),em=(0,o.useRef)(null),ey=(0,o.useRef)(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.useCallback)(e=>{let t=em.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=em.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=em.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){eI(e)},addImages(e){eM(e)},addFiles(e){eR(e)}}));let eM=(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])},[]),eR=(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&&eM(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])}},[eM]),eL=(0,o.useCallback)(e=>{el(t=>{let r=[...t];return URL.revokeObjectURL(r[e].previewUrl),r.splice(e,1),r})},[]),eW=(0,o.useCallback)(e=>{ea(t=>{let r=[...t];return r.splice(e,1),r})},[]),eE=(0,o.useCallback)(()=>{el(e=>(e.forEach(e=>URL.revokeObjectURL(e.previewUrl)),[])),ea([])},[]),e$=d&&d.length>0?d.map(e=>({provider:e.provider,modelId:e.id,name:e.name,input:e.input})):Object.entries(a??{}).map(([e,t])=>({provider:s?.provider??"unknown",modelId:e,name:t})),eP=[];for(let e of e$){let t=eP.find(t=>t.provider===e.provider);t?t.options.push(e):eP.push({provider:e.provider,options:[e]})}let eD=s?e$.find(e=>e.modelId===s.modelId&&e.provider===s.provider)?.name??s.modelId:e$.length>0?e$[0].name:null,eB=s?e$.find(e=>e.modelId===s.modelId&&e.provider===s.provider):e$[0],eN=eB?.input?.includes("image")??!0,eO=ei.length>0&&eB?.input!==void 0&&!eN,eA=(!!W.trim()||ei.length>0||es.length>0)&&!eO,eH=u?A:A.filter(e=>"/compact"!==e.command),eF=eH.filter(e=>"native"===e.kind),eU=eH.filter(e=>"shortcut"===e.kind),e_=v??[],eJ=e_.length>0?`${e_.length} enabled`:"off",eV=eD??"Default",eK=(()=>{let e=y??"auto";if("auto"===e||!k)return e;let t=k[e];return null!=t?t:e})(),eY=Object.entries(P).find(([,e])=>e===(g??"full"))?.[0]??"full",eq=ed?26:32,eX=ed?7:9;(0,o.useEffect)(()=>{eO||ev(null)},[eO]);let eG=(0,o.useCallback)(e=>{if(!W.trim()){E(e),requestAnimationFrame(()=>{let t=em.current;t&&(t.focus(),t.setSelectionRange(e.length,e.length),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)});return}eI(e)},[eI,W]),eZ=(0,o.useCallback)(()=>{let t=W.trim();if(t||ei.length||es.length){if(ei.length&&!eN)return void ev("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");if(!l){if("/compact"===t&&!ei.length&&!es.length&&u){h?p?.():u(),E(""),em.current&&(em.current.style.height="auto");return}e(t,ei.length?ei:void 0,es.length?es:void 0),E(""),eE(),em.current&&(em.current.style.height="auto")}}},[W,ei,es,eN,l,e,eE,u,p,h]),eQ=(0,o.useCallback)(e=>{let t=W.trim();if(!t&&!ei.length&&!es.length)return;if(ei.length&&!eN)return void ev("当前模型不支持图片输入。请切换到带 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(""),eE(),em.current&&(em.current.style.height="auto")},[W,ei,es,eN,r,i,eE]),e0=(0,o.useCallback)(e=>{"Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),l&&(r||i)?eQ(r?"steer":"followup"):eZ())},[l,r,i,eQ,eZ]),e1=(0,o.useCallback)(()=>{let e=em.current;e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[]),e2=(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(),eR(t.map(e=>e.getAsFile()).filter(e=>null!==e)))},[eR]);return(0,o.useEffect)(()=>{if(!F&&!V&&!q&&!G&&!Q&&!et)return;let e=e=>{let t=e.target;if(!(t instanceof Node))return;let r=!!ey.current?.contains(t),n=!!eb.current?.contains(t);r||n||U(!1),ej.current?.contains(t)||Y(!1),ek.current?.contains(t)||X(!1),ew.current?.contains(t)||Z(!1),eS.current?.contains(t)||ee(!1),eC.current?.contains(t)||er(!1)};return document.addEventListener("pointerdown",e,!0),()=>{document.removeEventListener("pointerdown",e,!0)}},[F,V,q,G,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: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},children:[(0,n.jsx)("input",{ref:eT,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:e=>{eM(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsx)("input",{ref:ez,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=>{eR(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 ${eO?"rgba(220,38,38,0.45)":"var(--border)"}`,display:"block"}}),(0,n.jsx)("button",{onClick:()=>eL(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:()=>eW(t)},`doc-${t}`))]}),(eO||ef)&&(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:ef??"当前模型不支持图片输入。请切换到带 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:em,value:W,onChange:e=>E(e.target.value),onKeyDown:e0,onInput:e1,onPaste:e2,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:()=>eQ("steer"),disabled:!eA,title:eO?"当前模型不支持图片输入":"打断 Agent 当前运行,立即注入消息",style:{display:"flex",alignItems:"center",gap:ed?3:5,padding:"7px 12px",background:eA?"rgba(234,179,8,0.12)":"none",border:"1px solid rgba(234,179,8,0.35)",borderRadius:8,color:eA?"rgba(180,130,0,1)":"var(--text-dim)",cursor:eA?"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:()=>eQ("followup"),disabled:!eA,title:eO?"当前模型不支持图片输入":"在 Agent 完成后排队发送",style:{display:"flex",alignItems:"center",gap:ed?3:5,padding:"7px 12px",background:eA?"rgba(129,140,248,0.12)":"none",border:"1px solid rgba(129,140,248,0.35)",borderRadius:8,color:eA?"rgba(99,102,241,1)":"var(--text-dim)",cursor:eA?"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:eZ,disabled:!eA,title:eO?"当前模型不支持图片输入":"Send",style:{flexShrink:0,alignSelf:"flex-end",display:"flex",alignItems:"center",gap:ed?3:6,padding:ed?"5px 9px":"7px 14px",marginBottom:+!!ed,background:eA?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:8,color:eA?"#fff":"var(--text-dim)",cursor:eA?"pointer":"not-allowed",fontSize:ed?11:13,fontWeight:600,letterSpacing:"-0.01em",boxShadow:eA?"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:ed?3:6,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:()=>eT.current?.click(),disabled:l,title:"Attach image (right-click for document)",style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:eq,height:eq,padding:0,background:"none",border:"none",borderRadius:eX,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(),ez.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:ej,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>{l||(Y(e=>!e),X(!1),U(!1),Z(!1),ee(!1))},disabled:l,title:"插入斜杠命令",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:eq,height:eq,padding:0,background:V?"var(--bg-hover)":"none",border:"none",borderRadius:eX,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:{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}),eF.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"}),eF.map(e=>(0,n.jsxs)("button",{onClick:()=>{(Y(!1),"/compact"===e.command&&h)?p?.():eG(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))]}),eU.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:{marginTop:2*(eF.length>0),padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:eF.length>0?"1px solid var(--border)":"none"},children:"Prompt Shortcuts"}),eU.map(e=>(0,n.jsxs)("button",{onClick:()=>{Y(!1),eG(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:ek,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>{l||(X(e=>!e),Y(!1),U(!1),Z(!1),ee(!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:e_.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=e_.length>0?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=q?"var(--bg-hover)":"none",e.currentTarget.style.color=e_.length>0?"var(--accent)":"var(--text-muted)"},children:[" >_".trim(),e_.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:{position:"absolute",bottom:"calc(100% + 6px)",left:0,zIndex:100,minWidth:ed?220: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=e_.includes(e),r=B[e];return(0,n.jsxs)("button",{onClick:()=>{m(t?e_.filter(t=>t!==e):[...e_,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)})]})]}),e$.length>0&&eD&&c&&(0,n.jsxs)("div",{ref:ey,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:e=>{let t=e.currentTarget.getBoundingClientRect();J({top:t.top,left:t.left,width:t.width}),Y(!1),X(!1),Z(!1),ee(!1),U(e=>!e)},disabled:l,style:{display:"flex",alignItems:"center",gap:6,padding:ep,height:eu,maxWidth:ed?44: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:eD})]}),F&&_&&(R=(M=window.visualViewport?.height??window.innerHeight)-_.top+6,L=Math.max(120,Math.min(_.top-8,.6*M)),(0,n.jsx)("div",{ref:eb,style:{position:"fixed",bottom:R,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:L,overflowY:"auto"},children:eP.map((e,t)=>(0,n.jsxs)("div",{children:[eP.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: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.jsx)("span",{style:{flex:ed?"0 0 100%":1,width:ed?"100%":void 0,height:ed?0:void 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:eh?"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:[eh&&(0,n.jsxs)("div",{ref:eC,style:{position:"relative"},children:[(0,n.jsx)("button",{onClick:()=>{Y(!1),X(!1),U(!1),Z(!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:ex,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:{position:"absolute",right:0,bottom:"calc(100% + 6px)",zIndex:110,minWidth:220,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 -6px 20px rgba(0,0,0,0.12)",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:[(0,n.jsxs)("button",{onClick:()=>{er(!1),ee(!1),Z(!1),X(!1),U(!0)},style:eg,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"},children:eV})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:4},children:[(0,n.jsxs)("button",{onClick:()=>{er(!1),U(!1),Z(!1),X(!1),ee(!0)},style:eg,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:eK})]}),(0,n.jsxs)("button",{onClick:()=>{er(!1),U(!1),ee(!1),X(!1),Z(!0)},style:eg,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:eY})]})]}),(0,n.jsxs)("button",{onClick:()=>{er(!1),U(!1),ee(!1),Z(!1),X(!0)},style:eg,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:e_.length>0?"var(--accent)":"var(--text)",marginTop:2},children:eJ})]})]})]})]}),!eh&&!l&&b&&(0,n.jsxs)("div",{ref:eS,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>{l||(Y(!1),X(!1),U(!1),Z(!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:{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)",overflow:"hidden",minWidth:ed?160:180},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)})})]}),!eh&&!l&&f&&(0,n.jsxs)("div",{ref:ew,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>{l||(Y(!1),X(!1),U(!1),ee(!1),Z(e=>!e))},disabled:l,title:"切换工具预设",style:{display:"flex",alignItems:"center",gap:ed?3:5,padding:ep,height:eu,background:G?"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=G?"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"})]}),G&&(0,n.jsx)("div",{style:{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)",overflow:"hidden",minWidth:ed?110:120},children:$.map(e=>{let t=P[e],r=(g??"full")===t,o="agent"===e&&!1===en,i=o?"需安装 pi-subagents":D[e];return(0,n.jsxs)("button",{onClick:()=>{!o&&(Z(!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,R=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&&R===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=R===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 G(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function Z(e,t=220){if(!e)return;let r=e.trim();if(r)return r.length>t?`${r.slice(0,t)}...`:r}function 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:Z(r.content.split("\n").slice(3).join("\n")),timestamp:r.timestamp})}}if("assistant"===r.role){let e=r.content;if(!e)continue;for(let n of e)if("toolCall"===n.type&&"subagent"===n.toolName&&n.input){let e=n.input,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(!G(t))return{...e,summary:Z(r)};let o=Array.isArray(t.results)?t.results.filter(G):[],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:Z(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 G(t)&&Array.isArray(t.results)&&t.results.some(e=>G(e)&&"number"==typeof e.exitCode&&0!==e.exitCode)?"failed":"completed"}(r)},r.details,n))}}return Array.from(t.values()).sort((e,t)=>(t.timestamp??0)-(e.timestamp??0))}function 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:Z(e.task,150)}),t&&c&&(0,n.jsxs)("div",{style:{borderTop:`1px solid ${s}`,background:"var(--bg)",padding:"8px 10px",display:"flex",flexDirection:"column",gap:7},children:[e.summary&&(0,n.jsx)("pre",{style:{margin:0,color:"var(--text-muted)",fontSize:11,lineHeight:1.45,whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:160,overflow:"auto"},children:e.summary}),(0,n.jsx)(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.37"??"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:D,modelThinkingLevels:B,modelThinkingLevelMaps:N,toolPreset:O,memoryTools:A,thinkingLevel:H,retryInfo:F,contextUsage:U,forkingEntryId:_,isCompacting:J,compactError:V,displayModel:K,sessionStats:q,agentPhase:G,agentError:Z,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:eR,handleThinkingLevelChange:eL,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,D]=(0,o.useState)({}),[B,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"),[G,Z]=(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),eR=(0,o.useRef)(null),eL=(0,o.useRef)(new Map),eW=(0,o.useRef)(new Set),eE=e.setNewSessionModel??_,e$=e.setToolPreset??V,eP=e.setMemoryTools??Y,eD=ei??u?.context.model??ep??null,eB=c?U:eD,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
- ${t}
8
- ${e.extractedText}`.trim()}return`${r}
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=eL.current;r.set(t,(r.get(t)??0)+1)},[]),eA=(0,o.useCallback)(e=>{let t=ec(e);if(!t)return!1;let r=eL.current,n=r.get(t)??0;return!(n<=0)&&(1===n?r.delete(t):r.set(t,n-1),!0)},[]),eH=(()=>{let e={input:0,output:0,cacheRead:0,cacheWrite:0},t=0;for(let r of y){if("assistant"!==r.role)continue;let n=r.usage;n&&(e.input+=n.input??0,e.output+=n.output??0,e.cacheRead+=n.cacheRead??0,e.cacheWrite+=n.cacheWrite??0,t+=n.cost?.total??0)}return e.input+e.output+e.cacheRead+e.cacheWrite>0?{tokens:e,cost:t}:null})(),eF=(0,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??[]),eL.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??[]),eL.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=L(e),o=L(r),""===n?"none":n===L(z)?"default":n===L(I)?"full":n===L(M)?"workbench":n===L(R)?"agent":""===o?"none":o===L(z)?"default":o===L(I)?"full":o===L(M)?"workbench":o===L(R)||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),Z(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":Z({attempt:e.attempt,maxAttempts:e.maxAttempts,errorMessage:e.errorMessage});break;case"auto_retry_end":Z(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}
10
-
11
- Attached document text:
12
-
13
- ${l}`:e:l?`Attached document text:
14
-
15
- ${l}`:"",a=n?.map(e=>({type:"image",source:{type:"base64",media_type:e.mimeType,data:e.data}})),d={role:"user",content:a?.length?[...s.trim()?[{type:"text",text:s}]:[],...a]:s,timestamp:Date.now()};eO(d),b(e=>[...e,d]),ej(null),$(!0),ey({kind:"waiting_model"}),T({type:"start"}),eI.current=!0;let u=n?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType}));try{if(c&&r){U&&eh(U);let t=E(J,K),n=await fetch("/api/agent/new",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:r,type:"prompt",message:s,toolNames:t,...u?.length?{images:u}:{},...U?{provider:U.provider,modelId:U.modelId}:{},..."auto"!==q?{thinkingLevel:q}:{}})}),o=await n.json().catch(()=>({}));if(!n.ok||o.error||!o.sessionId)throw Error(o.error??`HTTP ${n.status}`);let l=o.sessionId;ew.current=l,eJ(l,{replay:!0}),i?.({id:l,path:"",cwd:r,name:void 0,created:new Date().toISOString(),modified:new Date().toISOString(),messageCount:1,firstMessage:e})}else if(t){let e=E(J,K);eJ(t.id),await ea(t.id,{type:"prompt",message:s,toolNames:e,...u?.length?{images:u}:{}})}}catch(e){eA(d),console.error("Failed to send message:",e),ej(e instanceof Error?e.message:String(e)),$(!1),ey(null),T({type:"end"})}},[c,r,U,J,K,q,t,W,eJ,i,eN,eA,eO]),eK=(0,o.useCallback)(async()=>{let e=ew.current;if(e){eS.current=!1,ej(null),$(!1),ey(null),T({type:"end"}),ek.current?.close(),ek.current=null;try{await ea(e,{type:"abort"}),await eF(e)}catch(t){console.error("Failed to abort:",t),await eF(e)}}},[eF]),eY=(0,o.useCallback)(async e=>{let t=ew.current;if(t){eo(e);try{let{cancelled:r,newSessionId:n}=await ea(t,{type:"fork",entryId:e})??{};!r&&n&&l?.(n)}catch(e){console.error("Fork failed:",e)}finally{eo(null)}}},[l]),eq=(0,o.useCallback)(async e=>{let t=ew.current;t&&(ea(t,{type:"navigate_tree",targetId:e}).catch(()=>{}),m(e),await eU(t,e))},[eU]),eX=(0,o.useCallback)(async e=>{m(e);let t=ew.current;t&&(await eU(t,e),e&&ea(t,{type:"navigate_tree",targetId:e}).catch(()=>{}))},[eU]),eG=(0,o.useCallback)(async(e,t)=>{if(c)return void eE({provider:e,modelId:t});let r=ew.current;if(r)try{await ea(r,{type:"set_model",provider:e,modelId:t}),el({provider:e,modelId:t})}catch(e){console.error("Failed to set model:",e)}},[c,eE]),eZ=(0,o.useCallback)(async()=>{let e=ew.current;if(e&&!ex){eg(!0),ev(null);try{await ea(e,{type:"compact"}),await eF(e,!0)}catch(e){ev(e instanceof Error?e.message:String(e))}finally{eg(!1)}}},[ex,eF]),eQ=(0,o.useCallback)(async(e,t,r)=>{let n=ew.current;if(!n)return;let o=eN(r),i=e.trim()?o?`${e}
16
-
17
- Attached document text:
18
-
19
- ${o}`:e:o?`Attached document text:
20
-
21
- ${o}`:"",l={role:"user",content:`[steer] ${i}`,timestamp:Date.now()};eO(l),b(e=>[...e,l]);let s=t?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType}));try{await ea(n,{type:"steer",message:i,...s?.length?{images:s}:{}})}catch(e){eA(l),console.error("Failed to steer:",e)}},[eN,eA,eO]),e0=(0,o.useCallback)(async(e,t,r)=>{let n=ew.current;if(!n)return;let o=eN(r),i=e.trim()?o?`${e}
22
-
23
- Attached document text:
24
-
25
- ${o}`:e:o?`Attached document text:
26
-
27
- ${o}`:"",l={role:"user",content:i,timestamp:Date.now()};eO(l),b(e=>[...e,l]);let s=t?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType}));try{await ea(n,{type:"follow_up",message:i,...s?.length?{images:s}:{}})}catch(e){eA(l),console.error("Failed to follow up:",e)}},[eN,eA,eO]),e1=(0,o.useCallback)(async()=>{let e=ew.current;if(e)try{await ea(e,{type:"abort_compaction"})}catch(e){console.error("Failed to abort compaction:",e)}},[]),e2=(0,o.useCallback)(async e=>{if(X(e),"auto"===e)return;let t=ew.current;if(t)try{await ea(t,{type:"set_thinking_level",level:e})}catch(e){console.error("Failed to set thinking level:",e)}},[]),e5=(0,o.useCallback)(async e=>{e$(e);let t=E(e,K),r=ew.current;if(r)try{await ea(r,{type:"set_tools",toolNames:t})}catch(e){console.error("Failed to set tools:",e)}},[K,e$]),e4=(0,o.useCallback)(async e=>{eP(e);let t=E(J,e),r=ew.current;if(r)try{await ea(r,{type:"set_tools",toolNames:t})}catch(e){console.error("Failed to set memory tools:",e)}},[eP,J]),e3=(0,o.useCallback)((e="smooth")=>{eM.current?.scrollIntoView({behavior:e})},[]),e8=(0,o.useCallback)(()=>{let e=eR.current,t=ez.current;if(!e||!t)return;let r=t.getBoundingClientRect().top-e.getBoundingClientRect().top+e.scrollTop;e.scrollTo({top:r-16,behavior:"smooth"})},[]);return(0,o.useEffect)(()=>(t&&(ew.current=t.id,(async()=>{let e=await eF(t.id,!0,!0);ew.current===t.id&&(await e_(t.id),e?.running&&($(!0),ey({kind:"waiting_model"}),T({type:"start"}),eJ(t.id,{replay:!0})),e?.state&&(void 0!==e.state.isCompacting&&eg(e.state.isCompacting),void 0!==e.state.contextUsage&&ee(e.state.contextUsage??null),void 0!==e.state.systemPrompt&&er(e.state.systemPrompt??null),void 0!==e.state.thinkingLevel&&X(e.state.thinkingLevel??"auto")))})()),()=>{ek.current?.close(),ek.current=null}),[eJ,eF,e_,a,d,t]),(0,o.useEffect)(()=>{d?.(et)},[et,d]),(0,o.useEffect)(()=>{a&&a(u?.tree??[],v,eX)},[u?.tree,v,eX,a]),(0,o.useEffect)(()=>{y.length>0&&(eI.current?(eI.current=!1,eT.current=!0,e8()):eT.current?eS.current||e3("smooth"):(eT.current=!0,e3("instant")))},[y.length,W,e3,e8]),(0,o.useEffect)(()=>{fetch("/api/models").then(e=>e.json()).then(e=>{if(D(e.models),e.thinkingLevels&&A(e.thinkingLevels),e.thinkingLevelMaps&&F(e.thinkingLevelMaps),e.modelList&&(N(e.modelList),c&&e.modelList.length>0)){let t=e.defaultModel,r=t&&e.modelList.find(e=>e.id===t.modelId&&e.provider===t.provider);eE(r?{provider:r.provider,modelId:r.id}:{provider:e.modelList[0].provider,modelId:e.modelList[0].id})}}).catch(()=>{})},[c,s,eE]),(0,o.useEffect)(()=>{if(!ef)return;let e=setTimeout(()=>ev(null),3e3);return()=>clearTimeout(e)},[ef]),{data:u,loading:h,error:g,activeLeafId:v,messages:y,entryIds:j,streamState:w,agentRunning:W,modelNames:P,modelList:B,modelThinkingLevels:O,modelThinkingLevelMaps:H,newSessionModel:U,toolPreset:J,memoryTools:K,thinkingLevel:q,retryInfo:G,contextUsage:Q,systemPrompt:et,forkingEntryId:en,isCompacting:ex,compactError:ef,currentModel:eD,displayModel:eB,sessionStats:eH,agentPhase:em,agentError:eb,isNew:c,sessionIdRef:ew,eventSourceRef:ek,messagesEndRef:eM,scrollContainerRef:eR,lastUserMsgRef:ez,pendingScrollToUserRef:eI,initialScrollDoneRef:eT,handleSend:eV,handleAbort:eK,handleFork:eY,handleNavigate:eq,handleModelChange:eG,handleCompact:eZ,handleSteer:eQ,handleFollowUp:e0,handleAbortCompaction:e1,handleToolPresetChange:e5,handleMemoryToolsChange:e4,handleThinkingLevelChange:e2,loadTools:e_,setActiveLeafId:m,setData:p,setMessages:b,dispatch:T,setAgentRunning:$,setForkingEntryId:eo,handleAgentEventRef:eC}}({session:e,newSessionCwd:t,onAgentEnd:r,onSessionCreated:i,onSessionForked:l,modelsRefreshKey:s,onBranchDataChange:d,onSystemPromptChange:u}),{soundEnabled:eE,onSoundToggle:e$,playDoneSound:eP}=function(){let[e,t]=(0,o.useState)(()=>{let e=localStorage.getItem("pi-sound-enabled");return null===e||"true"===e}),r=(0,o.useRef)(e);return(0,o.useEffect)(()=>{r.current=e},[e]),{soundEnabled:e,onSoundToggle:(0,o.useCallback)(()=>{t(e=>{let t=!e;return localStorage.setItem("pi-sound-enabled",String(t)),t})},[]),playDoneSound:(0,o.useCallback)(()=>{if(r.current)try{let e=new AudioContext,t=e.currentTime;[523.25,659.25].forEach((r,n)=>{let o=e.createOscillator(),i=e.createGain();o.connect(i),i.connect(e.destination),o.type="sine",o.frequency.value=r;let l=t+.18*n;i.gain.setValueAtTime(0,l),i.gain.linearRampToValueAtTime(.18,l+.02),i.gain.exponentialRampToValueAtTime(.001,l+.45),o.start(l),o.stop(l+.45)}),setTimeout(()=>e.close(),1200)}catch{}},[]),soundEnabledRef:r}}(),eD=(0,o.useRef)(eP);eD.current=eP;let eB=(0,o.useRef)(eE);eB.current=eE;let eN=eW.current;(0,o.useEffect)(()=>{eW.current=e=>{"agent_end"===e.type&&eB.current&&eD.current(),eN?.(e)}},[eN,eW]);let eO=q?`${q.tokens.input}|${q.tokens.output}|${q.tokens.cacheRead}|${q.tokens.cacheWrite}|${q.cost??0}`:null,eA=(0,o.useRef)(q);eA.current=q,(0,o.useEffect)(()=>{p?.(eA.current)},[eO,p]),(0,o.useEffect)(()=>()=>{p?.(null)},[p]);let eH=U?`${U.percent??"null"}|${U.contextWindow}|${U.tokens??"null"}`:null,eF=(0,o.useRef)(U);eF.current=U,(0,o.useEffect)(()=>{h?.(eF.current)},[eH,h]),(0,o.useEffect)(()=>()=>{h?.(null)},[h]);let{isDragOver:eU,handleDragEnter:e_,handleDragOver:eJ,handleDragLeave:eV,handleDrop:eK}=function(e){let[t,r]=(0,o.useState)(!1),n=(0,o.useRef)(0),i=(0,o.useCallback)(e=>{Array.from(e.dataTransfer.items).some(eh)&&(e.preventDefault(),n.current+=1,r(!0))},[]),l=(0,o.useCallback)(e=>{Array.from(e.dataTransfer.items).some(eh)&&e.preventDefault()},[]);return{isDragOver:t,handleDragEnter:i,handleDragOver:l,handleDragLeave:(0,o.useCallback)(()=>{n.current-=1,n.current<=0&&(n.current=0,r(!1))},[]),handleDrop:(0,o.useCallback)(t=>{t.preventDefault(),n.current=0,r(!1),e(Array.from(t.dataTransfer.files))},[e])}}((0,o.useCallback)(e=>{a?.current?.addFiles(e)},[a])),[eY,eq]=(0,o.useState)(null);(0,o.useEffect)(()=>{if(!Q)return;let e=!1;return fetch("/api/version").then(e=>e.ok?e.json():null).then(t=>{!e&&t?.updateAvailable&&eq(t)}).catch(()=>{}),()=>{e=!0}},[Q]);let eX=(f=j.filter(e=>"user"===e.role||"assistant"===e.role).length,(v=(0,o.useRef)([])).current=Array(f).fill(null).map((e,t)=>v.current[t]??null),v),eG=(0,o.useRef)(new Set),eZ=(0,o.useRef)(new Set),eQ=(0,o.useMemo)(()=>{let e=new Map;for(let t of j)"toolResult"===t.role&&e.set(t.toolCallId,t);return e},[j]);(0,o.useEffect)(()=>{eG.current.clear(),eZ.current.clear()},[e?.id]),(0,o.useEffect)(()=>{if(e?.id&&!$&&!T.isStreaming)for(let t of j.flatMap(e=>"assistant"!==e.role?[]:(Array.isArray(e.content)?e.content:[]).flatMap(e=>"text"!==e.type?[]:(0,ex.W_)(e.text)))){let r=`${e.id}:${t.raw}`;eG.current.has(r)||(eG.current.add(r),fetch(`/api/reports/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"apply_update",update:t.update,updateKey:t.raw})}).then(e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);x?.()}).catch(()=>{eG.current.delete(r)}))}},[$,j,x,e?.id,T.isStreaming]),(0,o.useEffect)(()=>{if(!e?.id||$||T.isStreaming)return;let t=function(e){for(let t=e.length-1;t>=0;t--)if("user"===e[t].role)return e.slice(t);return e}(j),r=t.filter(e=>"assistant"===e.role).map(ej).join("\n");if((0,ex.W_)(r).length>0||!function(e){if(0===e.length)return!1;let t=e.map(ej).join("\n");return!!ef.test(t)&&(em.test(t)||ev.test(t)||/\b(saved|wrote|created|exported|generated|output|result)\b|输出|生成|保存|文件/.test(t))}(t))return;let n=function(e){for(let t=e.length-1;t>=0;t--){if("user"!==e[t].role)continue;let r=ej(e[t]).replace(/\s+/g," ").trim();if(r)return r.slice(0,90)}return"Current bioinformatics analysis"}(j),o=`${e.id}:${W??"latest"}:${n}`;eZ.current.has(o)||(eZ.current.add(o),fetch(`/api/reports/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"generate",leafId:W,topic:n})}).then(e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);x?.()}).catch(()=>{eZ.current.delete(o)}))},[W,$,j,x,e?.id,T.isStreaming]);let e0=Q&&0===j.length&&!T.isStreaming&&!$,e1=function(e=768){let[t,r]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{let t=window.matchMedia(`(max-width: ${e-1}px)`),n=()=>r(t.matches);return(n(),"function"==typeof t.addEventListener)?(t.addEventListener("change",n),()=>t.removeEventListener("change",n)):(t.addListener(n),()=>t.removeListener(n))},[e]),t}(),[e2,e5]=(0,o.useState)(!1),e4=et(j),e3=e4.filter(e=>"running"===e.status).length;(0,o.useEffect)(()=>{0===e4.length&&e2&&e5(!1)},[e4.length,e2]),(0,o.useEffect)(()=>{e1&&e2&&e5(!1)},[e1,e2]);let e8=K?B[`${K.provider}:${K.modelId}`]??null:null,e6=K?N[`${K.provider}:${K.modelId}`]??null:null,e7=(0,n.jsx)(Y,{ref:a,onSend:ei,onAbort:el,onSteer:$?eT:void 0,onFollowUp:$?ez:void 0,isStreaming:$,model:K,modelNames:P,modelList:D,onModelChange:eS,onCompact:e||Q?eC:void 0,onAbortCompaction:eI,isCompacting:J,compactError:V,toolPreset:O,onToolPresetChange:e||Q?eM:void 0,memoryTools:A,onMemoryToolsChange:e||Q?eR:void 0,thinkingLevel:H,onThinkingLevelChange:e||Q?eL:void 0,availableThinkingLevels:e8,thinkingLevelMap:e6,retryInfo:F,soundEnabled:eE,onSoundToggle:e$,cornerBadge:e0?(0,n.jsx)(eb,{status:eY}):void 0}),e9=(0,o.useCallback)(e=>{$?a?.current?.insertText(e):ei(e)},[$,a,ei]);return y?(0,n.jsx)("div",{className:"flex h-full items-center justify-center text-text-muted",children:"Loading session..."}):b?(0,n.jsx)("div",{className:"flex h-full items-center justify-center text-red-400",children:b}):(0,n.jsxs)("div",{className:"relative flex h-full flex-col overflow-hidden",onDragEnter:e_,onDragOver:eJ,onDragLeave:eV,onDrop:eK,children:[eU&&(0,n.jsxs)("div",{className:"pointer-events-none absolute inset-0 z-50 flex animate-[drop-zone-in_0.15s_ease_both] items-center justify-center bg-[rgba(37,99,235,0.06)] backdrop-blur-[1px]",children:[(0,n.jsx)("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",children:[0,.8,1.6].map(e=>(0,n.jsx)("div",{className:"absolute h-[720px] w-[720px] rounded-full border-[1.5px] border-solid border-[rgba(37,99,235,0.5)] animate-[drop-ripple_2.4s_ease-out_infinite_backwards]",style:{transformOrigin:"center",animationDelay:`${e}s`}},e))}),(0,n.jsxs)("svg",{width:"280",height:"280",viewBox:"0 0 140 140",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"drop-shadow-[0_6px_18px_rgba(37,99,235,0.18)]",children:[(0,n.jsx)("rect",{x:"28",y:"44",width:"84",height:"60",rx:"8",fill:"rgba(37,99,235,0.08)",stroke:"rgba(37,99,235,0.50)",strokeWidth:"1.8"}),(0,n.jsx)("path",{d:"M36 100 L54 72 L68 88 L80 74 L104 100Z",fill:"rgba(37,99,235,0.16)",stroke:"rgba(37,99,235,0.40)",strokeWidth:"1.4",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"96",cy:"58",r:"8",fill:"rgba(37,99,235,0.22)",stroke:"rgba(37,99,235,0.55)",strokeWidth:"1.6"}),(0,n.jsxs)("g",{stroke:"rgba(37,99,235,0.45)",strokeWidth:"1.4",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"96",y1:"46",x2:"96",y2:"43"}),(0,n.jsx)("line",{x1:"96",y1:"70",x2:"96",y2:"73"}),(0,n.jsx)("line",{x1:"84",y1:"58",x2:"81",y2:"58"}),(0,n.jsx)("line",{x1:"108",y1:"58",x2:"111",y2:"58"}),(0,n.jsx)("line",{x1:"87.5",y1:"49.5",x2:"85.4",y2:"47.4"}),(0,n.jsx)("line",{x1:"104.5",y1:"66.5",x2:"106.6",y2:"68.6"}),(0,n.jsx)("line",{x1:"104.5",y1:"49.5",x2:"106.6",y2:"47.4"}),(0,n.jsx)("line",{x1:"87.5",y1:"66.5",x2:"85.4",y2:"68.6"})]})]})]}),e0?(0,n.jsx)("div",{className:"flex flex-1 flex-col items-center justify-center overflow-y-auto px-4 py-8",children:(0,n.jsxs)("div",{className:"w-full max-w-[820px]",children:[(0,n.jsx)("div",{className:"mb-3",style:{display:"flex",alignItems:"center",justifyContent:"flex-start",gap:12,marginLeft:16,marginRight:16,fontFamily:"var(--font-mono)"},children:(0,n.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10,minWidth:0,flex:1,lineHeight:1.4},children:[(0,n.jsx)("span",{style:{fontSize:23,color:"var(--text)",fontWeight:750,letterSpacing:0},children:c}),(0,n.jsx)("span",{style:{fontSize:14,minWidth:0,overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"},children:(0,n.jsx)(ey,{phrases:eg})})]})}),e7]})}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"relative flex flex-1 overflow-hidden",children:[(0,n.jsx)("div",{ref:en,className:"flex-1 overflow-y-auto pt-4 [scrollbar-width:none]",children:(0,n.jsxs)("div",{className:"mx-auto max-w-[820px] px-4",style:e1?{paddingBottom:"calc(env(safe-area-inset-bottom, 0px) + 128px)"}:void 0,children:[(()=>{let r=-1;for(let e=j.length-1;e>=0;e--)if("user"===j[e].role){r=e;break}let o=0;return j.map((i,l)=>{let s="user"===i.role&&l>0&&"assistant"===j[l-1].role?k[l-1]:void 0,d="user"===i.role||"assistant"===i.role,c=d?o++:-1,u=!1;if("assistant"===i.role){u=!0;for(let e=l+1;e<j.length;e++){let t=j[e].role;if("user"===t)break;if("assistant"===t){u=!1;break}}u&&T.isStreaming&&l===j.length-1&&(u=!1)}let p=(0,n.jsx)(w.D,{message:i,toolResults:eQ,modelNames:P,entryId:k[l],onFork:$||Q||0===l&&"user"===i.role?void 0:ep,forking:_===k[l],onNavigate:$?void 0:ew,prevAssistantEntryId:$?void 0:s,onEditContent:e=>a?.current?.insertIfEmpty(e),onSendMessage:e9,showTimestamp:u,prevTimestamp:l>0?j[l-1].timestamp:void 0,renderVisualCodeBlocks:!!g,cwd:m?.info?.cwd??e?.cwd??t??void 0},l);return d?(0,n.jsx)("div",{ref:e=>{eX.current[c]=e,l===r&&(eo.current=e)},children:p},l):p})})(),T.isStreaming&&T.streamingMessage&&(0,n.jsx)(w.D,{message:T.streamingMessage,isStreaming:!0,toolResults:eQ,modelNames:P,onSendMessage:e9,renderVisualCodeBlocks:!!g,cwd:m?.info?.cwd??e?.cwd??t??void 0}),$&&!T.streamingMessage&&(0,n.jsx)("div",{className:"py-2 text-[13px] text-text-muted",children:(0,n.jsx)("span",{className:"animate-[pulse_1.5s_infinite]",children:function(e){if(e?.kind==="running_tools"){let t=e.tools.map(e=>e.name);return 0===t.length?"Running tool...":1===t.length?`Running ${t[0]}...`:t.length<=3?`Running ${t.join(", ")}...`:`Running ${t.slice(0,2).join(", ")} (+${t.length-2})...`}return e?.kind==="waiting_model"?"Waiting for model...":"Thinking..."}(G)})}),m?.info?.cwd&&!1===m.info.cwdExists&&(0,n.jsxs)("div",{className:"my-3 rounded-[7px] border border-[rgba(248,113,113,0.35)] bg-[rgba(248,113,113,0.07)] px-3 py-2 text-[12px] leading-relaxed text-red-400",children:["Project directory no longer exists: ",(0,n.jsx)("code",{className:"font-mono",children:m.info.cwd})]}),Z&&(0,n.jsx)("div",{className:"my-3 rounded-[7px] border border-[rgba(248,113,113,0.35)] bg-[rgba(248,113,113,0.07)] px-3 py-2 text-[12px] leading-relaxed text-red-400",children:Z}),$&&(0,n.jsx)("div",{style:{height:en.current?en.current.clientHeight:"80vh"}}),(0,n.jsx)("div",{ref:ee})]})}),!e1&&(0,n.jsx)("div",{style:{position:"relative",zIndex:0,pointerEvents:"auto"},children:(0,n.jsx)(X,{messages:j,streamingMessage:T.streamingMessage,scrollContainer:en,messageRefs:eX})}),e4.length>0&&(0,n.jsxs)("button",{onClick:()=>e5(e=>!e),title:e2?"Hide subagent runs":"Show subagent runs",style:{position:"absolute",right:e1?8:e2?260:40,top:8,minWidth:28,height:28,display:"flex",alignItems:"center",justifyContent:"center",gap:6,padding:e3>0||e4.length>1?"0 8px":0,background:e2?"var(--bg-selected)":"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:e2?"var(--accent)":"var(--text-dim)",cursor:"pointer",zIndex:30,fontSize:12,transition:"right 0.2s ease, background 0.12s"},onMouseEnter:e=>{e2||(e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e2||(e.currentTarget.style.color="var(--text-dim)")},children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),(0,n.jsx)("circle",{cx:"9",cy:"7",r:"4"}),(0,n.jsx)("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),(0,n.jsx)("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]}),(e3>0||e4.length>1)&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4,fontSize:10,fontWeight:700,color:e3>0?"var(--accent)":"var(--text-dim)"},children:[e3>0&&(0,n.jsxs)("span",{children:[e3," active"]}),(0,n.jsx)("span",{children:e4.length})]})]}),e2&&e4.length>0&&(0,n.jsxs)("div",{style:{position:"absolute",right:e1?8:48,top:4,bottom:4,width:e1?"calc(100vw - 16px)":250,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"-2px 0 12px rgba(0,0,0,0.08)",zIndex:25,overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"6px 12px",fontSize:11,fontWeight:600,color:"var(--text-dim)",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Subagents"}),(0,n.jsx)(er,{runs:e4})]})]}),(0,n.jsx)("div",{className:"relative",children:e7})]})]})}var ew=r(88110);function eS(e,t,r){return Math.min(Math.max(e,t),r)}function eC({id:e,filePath:t,fileName:r,cwd:i,active:l,stackIndex:s,zIndex:a,onClose:d,onFocus:c,onOpenFile:u}){let[p,h]=(0,o.useState)(()=>{let e,t,r,n,o,i,l;return e=window.innerWidth,t=window.innerHeight,n=(r=e<720||t<560)?8:36,i=Math.max(320,e-2*n-(o=r?0:s%6*28)),l=Math.max(260,t-2*n-o),{left:n+o,top:n+o,width:r?i:Math.min(1180,i),height:r?l:Math.min(820,l),maximized:!1}}),[x,g]=(0,o.useState)(!1),[f,v]=(0,o.useState)(!1),m=(0,o.useRef)(null),y=(0,o.useRef)(null),b=(0,o.useRef)(null);(0,o.useEffect)(()=>{l&&m.current?.focus({preventScroll:!0})},[l]),(0,o.useEffect)(()=>{let e=()=>{h(e=>{if(e.maximized)return e;let t=Math.max(320,window.innerWidth-16),r=Math.max(260,window.innerHeight-16),n=Math.min(e.width,t),o=Math.min(e.height,r);return{...e,width:n,height:o,left:eS(e.left,8,Math.max(8,window.innerWidth-n-8)),top:eS(e.top,8,Math.max(8,window.innerHeight-o-8))}})};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]);let j=(0,o.useCallback)(t=>{c(e),0!==t.button||p.maximized||(t.preventDefault(),t.currentTarget.setPointerCapture(t.pointerId),y.current={pointerId:t.pointerId,startX:t.clientX,startY:t.clientY,left:p.left,top:p.top},g(!0))},[p.left,p.maximized,p.top,e,c]),k=(0,o.useCallback)(e=>{let t=y.current;if(!t||t.pointerId!==e.pointerId)return;let r=t.left+e.clientX-t.startX,n=t.top+e.clientY-t.startY;h(e=>({...e,left:eS(r,8,Math.max(8,window.innerWidth-120)),top:eS(n,8,Math.max(8,window.innerHeight-48))}))},[]),w=(0,o.useCallback)(e=>{let t=y.current;t?.pointerId===e.pointerId&&(e.currentTarget.releasePointerCapture(e.pointerId),y.current=null,g(!1))},[]),S=(0,o.useCallback)(()=>{c(e),h(e=>({...e,maximized:!e.maximized}))},[e,c]),C=(0,o.useCallback)(t=>{c(e),0!==t.button||p.maximized||(t.preventDefault(),t.stopPropagation(),t.currentTarget.setPointerCapture(t.pointerId),b.current={pointerId:t.pointerId,startX:t.clientX,startY:t.clientY,width:p.width,height:p.height},v(!0))},[p.height,p.maximized,p.width,e,c]),T=(0,o.useCallback)(e=>{let t=b.current;if(!t||t.pointerId!==e.pointerId)return;let r=t.width+e.clientX-t.startX,n=t.height+e.clientY-t.startY;h(e=>({...e,width:eS(r,360,Math.max(360,window.innerWidth-e.left-8)),height:eS(n,280,Math.max(280,window.innerHeight-e.top-8))}))},[]),z=(0,o.useCallback)(e=>{let t=b.current;t?.pointerId===e.pointerId&&(e.currentTarget.releasePointerCapture(e.pointerId),b.current=null,v(!1))},[]),I=p.maximized?{position:"fixed",inset:12,zIndex:a}:{position:"fixed",left:p.left,top:p.top,width:p.width,height:p.height,zIndex:a};return(0,n.jsxs)("div",{ref:m,role:"dialog","aria-label":`Preview ${r}`,tabIndex:-1,onPointerDown:()=>c(e),onKeyDown:t=>{"Escape"===t.key&&d(e)},style:{...I,display:"flex",flexDirection:"column",minWidth:p.maximized?void 0:360,minHeight:p.maximized?void 0:280,background:"var(--bg)",border:l?"1px solid rgba(37,99,235,0.55)":"1px solid var(--border)",borderRadius:8,boxShadow:l?"0 18px 60px rgba(0,0,0,0.26)":"0 10px 34px rgba(0,0,0,0.20)",overflow:"hidden",outline:"none"},children:[(0,n.jsxs)("div",{onPointerDown:j,onPointerMove:k,onPointerUp:w,onPointerCancel:w,style:{height:34,display:"flex",alignItems:"center",gap:8,padding:"0 8px 0 12px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",cursor:p.maximized?"default":x?"grabbing":"grab",flexShrink:0,userSelect:"none"},children:[(0,n.jsx)("div",{style:{minWidth:0,flex:1},children:(0,n.jsx)("div",{title:t,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:12,fontWeight:650,color:"var(--text)"},children:r})}),(0,n.jsx)("button",{type:"button",onPointerDown:e=>e.stopPropagation(),onClick:S,title:p.maximized?"Restore preview":"Maximize preview","aria-label":p.maximized?"Restore preview":"Maximize preview",style:eT,children:p.maximized?(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("path",{d:"M6 3.5h6.5V10"}),(0,n.jsx)("path",{d:"M3.5 6H10v6.5H3.5z"})]}):(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,n.jsx)("path",{d:"M4 4h8v8H4z"})})}),(0,n.jsx)("button",{type:"button",onPointerDown:e=>e.stopPropagation(),onClick:()=>d(e),title:"Close preview","aria-label":"Close preview",style:eT,children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round","aria-hidden":"true",children:[(0,n.jsx)("line",{x1:"4",y1:"4",x2:"12",y2:"12"}),(0,n.jsx)("line",{x1:"12",y1:"4",x2:"4",y2:"12"})]})})]}),(0,n.jsx)("div",{style:{flex:1,minHeight:0,overflow:"hidden",background:"var(--bg)"},children:(0,n.jsx)(ew.h,{filePath:t,cwd:i,onOpenFile:u})}),!p.maximized&&(0,n.jsx)("div",{role:"separator","aria-orientation":"horizontal","aria-label":"Resize preview",title:"Resize preview",onPointerDown:C,onPointerMove:T,onPointerUp:z,onPointerCancel:z,style:{position:"absolute",right:0,bottom:0,width:18,height:18,cursor:"nwse-resize",color:"var(--text-dim)",display:"flex",alignItems:"flex-end",justifyContent:"flex-end",padding:3,background:"linear-gradient(135deg, transparent 0 48%, rgba(127,127,127,0.18) 48% 52%, transparent 52% 100%)"}})]})}let eT={width:26,height:24,padding:0,border:"1px solid transparent",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},ez="var(--text-dim)";function eI({size:e=14,open:t=!1}){return t?(0,n.jsxs)("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none",children:[(0,n.jsx)("path",{d:"M1 4.5A1 1 0 0 1 2 3.5H5.5L7 5h7.5v1H1V4.5Z",fill:ez}),(0,n.jsx)("path",{d:"M1 6h14.5L14 13H2L1 6Z",stroke:ez,strokeWidth:"1",fill:ez,fillOpacity:"0.12"})]}):(0,n.jsx)("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none",children:(0,n.jsx)("path",{d:"M1 4.5A1 1 0 0 1 2 3.5H5.5L7 5H14a1 1 0 0 1 1 1v6a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4.5Z",stroke:ez,strokeWidth:"1",fill:ez,fillOpacity:"0.1"})})}function eM({size:e=14}){return(0,n.jsxs)("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none",children:[(0,n.jsx)("path",{d:"M3 2h7l3 3v9H3V2Z",stroke:ez,strokeWidth:"1",fill:ez,fillOpacity:"0.08"}),(0,n.jsx)("path",{d:"M10 2v3h3",stroke:ez,strokeWidth:"1",fill:"none",strokeLinejoin:"round"})]})}function eR({label:e,size:t=14}){let r=t/14;return(0,n.jsxs)("svg",{width:t,height:t,viewBox:"0 0 14 14",fill:"none",children:[(0,n.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:ez,strokeWidth:"0.9",fill:ez,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:ez,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("text",{x:"7",y:"9.5",textAnchor:"middle",fontSize:3.4*r,fontFamily:"var(--font-mono), monospace",fontWeight:"600",fill:ez,letterSpacing:"0",children:e})]})}function eL({size:e=14}){return(0,n.jsx)(eR,{label:"TS",size:e})}function eW({size:e=14}){return(0,n.jsx)(eR,{label:"TSX",size:e})}function eE({size:e=14}){return(0,n.jsx)(eR,{label:"JS",size:e})}function e$({size:e=14}){return(0,n.jsx)(eR,{label:"JSX",size:e})}function eP({size:e=14}){return(0,n.jsx)(eR,{label:"PY",size:e})}function eD({size:e=14}){return(0,n.jsx)(eR,{label:"{}",size:e})}function eB({size:e=14}){return(0,n.jsx)(eR,{label:"CSS",size:e})}function eN({size:e=14}){return(0,n.jsx)(eR,{label:"SC",size:e})}function eO({size:e=14}){return(0,n.jsx)(eR,{label:"HTM",size:e})}function eA({size:e=14}){return(0,n.jsxs)("svg",{width:e,height:e,viewBox:"0 0 14 14",fill:"none",children:[(0,n.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:ez,strokeWidth:"0.9",fill:ez,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:ez,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M3.5 9.5V7l1.5 1.5L6.5 7v2.5",stroke:ez,strokeWidth:"0.9",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,n.jsx)("path",{d:"M8 7v2.5M7 9l1 1.5 1-1.5",stroke:ez,strokeWidth:"0.9",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]})}function eH({size:e=14}){return(0,n.jsx)(eR,{label:"YML",size:e})}function eF({size:e=14}){return(0,n.jsx)(eR,{label:"TOM",size:e})}function eU({size:e=14}){return(0,n.jsxs)("svg",{width:e,height:e,viewBox:"0 0 14 14",fill:"none",children:[(0,n.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:ez,strokeWidth:"0.9",fill:ez,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:ez,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M4 7.5l2 1.5-2 1.5",stroke:ez,strokeWidth:"0.95",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,n.jsx)("path",{d:"M7.5 10.5h2.5",stroke:ez,strokeWidth:"0.95",strokeLinecap:"round"})]})}function e_({size:e=14}){return(0,n.jsx)(eR,{label:"RS",size:e})}function eJ({size:e=14}){return(0,n.jsx)(eR,{label:"GO",size:e})}function eV({size:e=14}){return(0,n.jsx)(eR,{label:"SQL",size:e})}function eK({size:e=14}){return(0,n.jsx)(eR,{label:"GQL",size:e})}function eY({size:e=14}){return(0,n.jsx)(eR,{label:"TF",size:e})}function eq({size:e=14}){return(0,n.jsxs)("svg",{width:e,height:e,viewBox:"0 0 14 14",fill:"none",children:[(0,n.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:ez,strokeWidth:"0.9",fill:ez,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:ez,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("rect",{x:"3.5",y:"6.5",width:"2",height:"1.5",rx:"0.3",stroke:ez,strokeWidth:"0.8"}),(0,n.jsx)("rect",{x:"6",y:"6.5",width:"2",height:"1.5",rx:"0.3",stroke:ez,strokeWidth:"0.8"}),(0,n.jsx)("rect",{x:"3.5",y:"8.5",width:"2",height:"1.5",rx:"0.3",stroke:ez,strokeWidth:"0.8"})]})}function eX({size:e=14}){return(0,n.jsxs)("svg",{width:e,height:e,viewBox:"0 0 14 14",fill:"none",children:[(0,n.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:ez,strokeWidth:"0.9",fill:ez,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:ez,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"5.5",cy:"8.5",r:"1.5",stroke:ez,strokeWidth:"0.9"}),(0,n.jsx)("path",{d:"M7 8.5h2.5M8.5 8.5v1.5",stroke:ez,strokeWidth:"0.9",strokeLinecap:"round"})]})}function eG({size:e=14}){return(0,n.jsxs)("svg",{width:e,height:e,viewBox:"0 0 14 14",fill:"none",children:[(0,n.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:ez,strokeWidth:"0.9",fill:ez,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:ez,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"5",cy:"6.5",r:"1",stroke:ez,strokeWidth:"0.85"}),(0,n.jsx)("circle",{cx:"9",cy:"6.5",r:"1",stroke:ez,strokeWidth:"0.85"}),(0,n.jsx)("circle",{cx:"5",cy:"10",r:"1",stroke:ez,strokeWidth:"0.85"}),(0,n.jsx)("path",{d:"M5 7.5V9",stroke:ez,strokeWidth:"0.85",strokeLinecap:"round"}),(0,n.jsx)("path",{d:"M9 7.5v.5a2 2 0 0 1-2 2H6",stroke:ez,strokeWidth:"0.85",strokeLinecap:"round",fill:"none"})]})}function eZ({size:e=14}){return(0,n.jsxs)("svg",{width:e,height:e,viewBox:"0 0 14 14",fill:"none",children:[(0,n.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:ez,strokeWidth:"0.9",fill:ez,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:ez,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("rect",{x:"4.5",y:"8.5",width:"5",height:"3",rx:"0.6",stroke:ez,strokeWidth:"0.9"}),(0,n.jsx)("path",{d:"M5.5 8.5V7.5a1.5 1.5 0 0 1 3 0v1",stroke:ez,strokeWidth:"0.9",strokeLinecap:"round",fill:"none"})]})}function eQ({size:e=14}){return(0,n.jsxs)("svg",{width:e,height:e,viewBox:"0 0 14 14",fill:"none",children:[(0,n.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:ez,strokeWidth:"0.9",fill:ez,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:ez,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"7",cy:"8.5",r:"1.3",stroke:ez,strokeWidth:"0.9"}),(0,n.jsx)("path",{d:"M7 6.5v.7M7 10.3v.7M5 8.5h.7M8.3 8.5H9M5.5 6.9l.5.5M8.5 9.6l-.5-.5M5.5 10.1l.5-.5M8.5 7.4l-.5.5",stroke:ez,strokeWidth:"0.8",strokeLinecap:"round"})]})}function e0(e,t=14){let r=e.toLowerCase(),o=r.split(".").pop()??"";if("dockerfile"===r||r.startsWith("dockerfile."))return(0,n.jsx)(eq,{size:t});if(".env"===r||r.startsWith(".env."))return(0,n.jsx)(eX,{size:t});if(".gitignore"===r||".gitattributes"===r||".gitmodules"===r)return(0,n.jsx)(eG,{size:t});if("package-lock.json"===r||"yarn.lock"===r||"bun.lock"===r||"pnpm-lock.yaml"===r||"cargo.lock"===r)return(0,n.jsx)(eZ,{size:t});if(r.endsWith(".config.ts")||r.endsWith(".config.js")||r.endsWith(".config.mjs")||r.endsWith(".config.cjs")||[".eslintrc",".eslintrc.js",".eslintrc.json",".eslintrc.yml","eslint.config.mjs","eslint.config.js"].includes(r))return(0,n.jsx)(eQ,{size:t});switch(o){case"ts":return(0,n.jsx)(eL,{size:t});case"tsx":return(0,n.jsx)(eW,{size:t});case"js":case"mjs":case"cjs":return(0,n.jsx)(eE,{size:t});case"jsx":return(0,n.jsx)(e$,{size:t});case"py":return(0,n.jsx)(eP,{size:t});case"json":case"jsonl":return(0,n.jsx)(eD,{size:t});case"css":case"less":return(0,n.jsx)(eB,{size:t});case"scss":return(0,n.jsx)(eN,{size:t});case"html":case"htm":return(0,n.jsx)(eO,{size:t});case"md":case"mdx":return(0,n.jsx)(eA,{size:t});case"yaml":case"yml":return(0,n.jsx)(eH,{size:t});case"toml":return(0,n.jsx)(eF,{size:t});case"sh":case"bash":case"zsh":case"fish":return(0,n.jsx)(eU,{size:t});case"rs":return(0,n.jsx)(e_,{size:t});case"go":return(0,n.jsx)(eJ,{size:t});case"sql":return(0,n.jsx)(eV,{size:t});case"graphql":case"gql":return(0,n.jsx)(eK,{size:t});case"tf":case"hcl":return(0,n.jsx)(eY,{size:t});case"lock":return(0,n.jsx)(eZ,{size:t});default:return(0,n.jsx)(eM,{size:t})}}var e1=r(28999);async function e2(e){let t=(0,e1.HG)(e),r=await fetch(`/api/files/${t}?type=list`);return r.ok?((await r.json()).entries??[]).map(t=>({name:t.name,fullPath:(0,e1.e_)(e,t.name),isDir:t.isDir,size:t.size,children:t.isDir?[]:void 0,loaded:!t.isDir})):[]}function e5(e,t){let r=t.trim().toLowerCase();return!!(!r||e.name.toLowerCase().includes(r))||(e.children??[]).some(e=>e5(e,r))}function e4(e){return!!Array.from(e.types).includes("Files")||Array.from(e.items).some(e=>"file"===e.kind)}function e3(e){return Array.from(e.files).filter(e=>!!e.name)}function e8(e,t){return e===t?".":(0,e1.qP)(e,t)}function e6({node:e,depth:t,cwd:r,onOpenFile:i,onExploreFile:l,onAtMention:s,expandedPaths:a,onToggleExpanded:d,onUploadFiles:c,uploadTargetPath:u,refreshKey:p,searchQuery:h}){let x=!!h?.trim(),g=x?e.isDir:a.has(e.fullPath),[f,v]=(0,o.useState)(e.children??[]),[m,y]=(0,o.useState)(e.loaded??!1),[b,j]=(0,o.useState)(!1),[k,w]=(0,o.useState)(!1),[S,C]=(0,o.useState)(!1),T=e.isDir&&(S||u===e.fullPath),z=!!s&&k,I=!!l&&k&&!e.isDir&&e.name.toLowerCase().endsWith(".h5ad"),M=z||I,R=x?f.filter(e=>e5(e,h??"")):f,L=(0,o.useCallback)(async(t=!1)=>{if(!m||t){j(!0);try{let t=await e2(e.fullPath);v(t),y(!0)}catch{}finally{j(!1)}}},[m,e.fullPath]),W=(0,o.useRef)(m);(0,o.useEffect)(()=>{W.current=m}),(0,o.useEffect)(()=>{g&&m&&L(!0)},[p]);let E=(0,o.useCallback)(()=>{if(e.isDir){let t=!g;d(e.fullPath,t),t&&!m&&L()}else i(e.fullPath,e.name)},[e.isDir,e.fullPath,e.name,m,g,L,i,d]),$=(0,o.useCallback)(t=>{e.isDir&&e4(t.dataTransfer)&&(t.preventDefault(),t.stopPropagation(),t.dataTransfer.dropEffect="copy",C(!0))},[e.isDir]),P=(0,o.useCallback)(t=>{e.isDir&&e4(t.dataTransfer)&&(t.preventDefault(),t.stopPropagation(),t.dataTransfer.dropEffect="copy")},[e.isDir]),D=(0,o.useCallback)(t=>{if(!e.isDir)return;let r=t.relatedTarget;r instanceof Node&&t.currentTarget.contains(r)||C(!1)},[e.isDir]),B=(0,o.useCallback)(t=>{if(!e.isDir||!e4(t.dataTransfer))return;t.preventDefault(),t.stopPropagation(),C(!1);let r=e3(t.dataTransfer);r.length>0&&(c(r,e.fullPath),g||d(e.fullPath,!0),m||L())},[L,m,e.fullPath,e.isDir,d,c,g]);return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{onClick:E,onMouseEnter:()=>w(!0),onMouseLeave:()=>w(!1),onDragEnter:$,onDragOver:P,onDragLeave:D,onDrop:B,style:{position:"relative",display:"flex",alignItems:"center",gap:4,paddingLeft:8+14*t,paddingRight:M?z&&I?146:82:8,height:24,cursor:"pointer",background:T?"rgba(37,99,235,0.14)":k?"var(--bg-hover)":"transparent",outline:T?"1px solid rgba(37,99,235,0.42)":"none",outlineOffset:-1,borderRadius:4,userSelect:"none",transition:"background 0.12s, outline-color 0.12s"},children:[e.isDir&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:g?"rotate(90deg)":"none",transition:"transform 0.1s"},children:(0,n.jsx)("polyline",{points:"3 2 7 5 3 8"})}),!e.isDir&&(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flexShrink:0,display:"flex",alignItems:"center"},children:e.isDir?(0,n.jsx)(eI,{size:14,open:g}):e0(e.name,14)}),(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},title:e.fullPath,children:e.name}),b&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",children:(0,n.jsx)("path",{d:"M12 2v4M12 18v4M4.93 4.93l2.83 2.83M16.24 16.24l2.83 2.83M2 12h4M18 12h4"})}),M&&(0,n.jsxs)("div",{style:{position:"absolute",right:4,top:"50%",transform:"translateY(-50%)",display:"flex",alignItems:"center",gap:4},children:[I&&(0,n.jsxs)("button",{onClick:t=>{t.stopPropagation(),l?.(e.fullPath,e.name)},title:"Explore H5AD",style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,padding:"0 8px",height:20,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:4,color:"var(--accent)",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.1",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"7"}),(0,n.jsx)("path",{d:"M16 16l4 4"}),(0,n.jsx)("path",{d:"M8.5 11h5"}),(0,n.jsx)("path",{d:"M11 8.5v5"})]}),"@explore"]}),z&&(0,n.jsxs)("button",{onClick:t=>{t.stopPropagation(),s?.((0,e1.qP)(e.fullPath,r))},title:"Insert path into chat",style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,padding:"0 8px",height:20,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:4,color:"var(--accent)",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"4"}),(0,n.jsx)("path",{d:"M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8"})]}),"@mention"]})]})]}),e.isDir&&g&&(0,n.jsxs)("div",{children:[R.map(e=>(0,n.jsx)(e6,{node:e,depth:t+1,cwd:r,onOpenFile:i,onExploreFile:l,onAtMention:s,expandedPaths:a,onToggleExpanded:d,onUploadFiles:c,uploadTargetPath:u,refreshKey:p,searchQuery:h},e.fullPath)),0===R.length&&m&&!x&&(0,n.jsx)("div",{style:{paddingLeft:8+(t+1)*14,fontSize:11,color:"var(--text-dim)",height:22,display:"flex",alignItems:"center"},children:"empty"})]})]})}function e7({cwd:e,onOpenFile:t,onExploreFile:r,refreshKey:i,onAtMention:l,searchQuery:s="",onSearchChange:a}){let[d,c]=(0,o.useState)([]),[u,p]=(0,o.useState)(!0),[h,x]=(0,o.useState)(null),[g,f]=(0,o.useState)(new Set),[v,m]=(0,o.useState)(!1),[y,b]=(0,o.useState)(null),[j,k]=(0,o.useState)(null),w=(0,o.useRef)(null),S=(0,o.useRef)(null),C=(0,o.useRef)(0),T=(0,o.useCallback)((e,t)=>(p(t),x(null),e2(e).then(e=>c(e)).catch(e=>x(String(e))).finally(()=>p(!1))),[]),z=(0,o.useCallback)((e,t)=>{f(r=>{let n=new Set(r);return t?n.add(e):n.delete(e),n})},[]);(0,o.useEffect)(()=>{let t=w.current!==e;w.current=e,t&&f(new Set),T(e,t)},[e,i,T]),(0,o.useEffect)(()=>()=>{S.current&&clearTimeout(S.current)},[]);let I=(0,o.useCallback)(()=>{T(e,0===d.length)},[e,d.length,T]),M=(0,o.useCallback)(()=>{S.current&&clearTimeout(S.current),S.current=setTimeout(()=>k(null),5e3)},[]),R=(0,o.useCallback)((t,r)=>{if(0===t.length)return;C.current=0,m(!1),S.current&&clearTimeout(S.current);let n=t.reduce((e,t)=>e+t.size,0),o=e8(r,e);b(r),k({phase:"uploading",targetPath:r,fileCount:t.length,loaded:0,total:n,message:`Uploading ${t.length} file${1===t.length?"":"s"} to ${o}`});let i=new FormData;t.forEach(e=>i.append("files",e,e.name));let l=new XMLHttpRequest,s=(0,e1.HG)(r);l.open("POST",`/api/files/${s}?type=upload`),l.upload.onprogress=e=>{e.lengthComputable&&k(t=>t?{...t,loaded:e.loaded,total:e.total}:t)},l.onload=()=>{b(null);let e={};try{e=JSON.parse(l.responseText)}catch{e={}}if(l.status>=200&&l.status<300){let i=e.uploaded??[],l=e.failed??[],s=[...i.filter(e=>e.name!==e.originalName).slice(0,3).map(e=>`${e.originalName} saved as ${e.name}`),...l.slice(0,3).map(e=>`${e.name}: ${e.error}`)];k({phase:l.length>0?"warning":"success",targetPath:r,fileCount:t.length,loaded:n,total:n,message:l.length>0?`Uploaded ${i.length}, ${l.length} failed`:`Uploaded ${i.length} file${1===i.length?"":"s"} to ${o}`,details:s}),I(),M()}else{let o=e.error??`Upload failed (HTTP ${l.status})`;k({phase:(l.status,"error"),targetPath:r,fileCount:t.length,loaded:0,total:n,message:o,details:403===l.status?["Check directory write permission or project access."]:void 0}),M()}},l.onerror=()=>{b(null),k({phase:"error",targetPath:r,fileCount:t.length,loaded:0,total:n,message:"Upload failed due to a network error"}),M()},l.onabort=()=>{b(null),k({phase:"error",targetPath:r,fileCount:t.length,loaded:0,total:n,message:"Upload canceled"}),M()},l.send(i)},[e,I,M]),L=(0,o.useCallback)(e=>{e4(e.dataTransfer)&&(e.preventDefault(),C.current+=1,m(!0))},[]),W=(0,o.useCallback)(e=>{e4(e.dataTransfer)&&(e.preventDefault(),e.dataTransfer.dropEffect="copy")},[]),E=(0,o.useCallback)(()=>{C.current-=1,C.current<=0&&(C.current=0,m(!1))},[]),$=(0,o.useCallback)(t=>{if(!e4(t.dataTransfer))return;t.preventDefault(),C.current=0,m(!1);let r=e3(t.dataTransfer);r.length>0&&R(r,e)},[e,R]),P=s.trim()?d.filter(e=>e5(e,s)):d,D=s.trim().length>0;return u?(0,n.jsx)(e9,{cwd:e,isDraggingFiles:v,uploadState:j,onDragEnter:L,onDragOver:W,onDragLeave:E,onDrop:$,children:(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:"Loading files..."})}):h?(0,n.jsx)(e9,{cwd:e,isDraggingFiles:v,uploadState:j,onDragEnter:L,onDragOver:W,onDragLeave:E,onDrop:$,children:(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"#f87171"},children:h})}):(0,n.jsx)(e9,{cwd:e,isDraggingFiles:v,uploadState:j,onDragEnter:L,onDragOver:W,onDragLeave:E,onDrop:$,children:(0,n.jsxs)("div",{style:{padding:"2px 4px"},children:[P.map(o=>(0,n.jsx)(e6,{node:o,depth:0,cwd:e,onOpenFile:t,onExploreFile:r,onAtMention:l,expandedPaths:g,onToggleExpanded:z,onUploadFiles:R,uploadTargetPath:y,refreshKey:i,searchQuery:s},o.fullPath)),0===P.length&&(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:D?"No matching files":"No files found"})]})})}function e9({cwd:e,isDraggingFiles:t,uploadState:r,onDragEnter:o,onDragOver:i,onDragLeave:l,onDrop:s,children:a}){let d=r&&r.total>0?Math.max(0,Math.min(100,Math.round(r.loaded/r.total*100))):r?.phase==="uploading"?8:100,c=r?.phase==="success"?"#22c55e":r?.phase==="warning"?"#f59e0b":r?.phase==="error"?"#ef4444":"var(--accent)";return(0,n.jsxs)("div",{onDragEnter:o,onDragOver:i,onDragLeave:l,onDrop:s,style:{position:"relative",display:"flex",flexDirection:"column",height:"100%",minHeight:0,outline:t?"1px solid rgba(37,99,235,0.45)":"none",outlineOffset:-1,background:t?"rgba(37,99,235,0.04)":void 0,transition:"background 0.12s, outline-color 0.12s"},children:[(0,n.jsx)("div",{style:{flex:1,minHeight:0,overflowY:"auto",overscrollBehavior:"contain",scrollbarWidth:"thin"},children:a}),t&&(0,n.jsx)("div",{style:{pointerEvents:"none",position:"absolute",inset:6,top:42,border:"1px dashed rgba(37,99,235,0.62)",borderRadius:8,background:"rgba(37,99,235,0.07)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:2},children:(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"7px 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",fontSize:12,boxShadow:"0 8px 24px rgba(0,0,0,0.16)"},children:[(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,n.jsx)("polyline",{points:"17 8 12 3 7 8"}),(0,n.jsx)("line",{x1:"12",y1:"3",x2:"12",y2:"15"})]}),"Drop to upload into ",e8(e,e)]})}),r&&(0,n.jsxs)("div",{style:{margin:"6px",padding:"7px 8px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",boxShadow:"0 8px 24px rgba(0,0,0,0.12)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:7,minWidth:0},children:[(0,n.jsx)("span",{style:{width:8,height:8,borderRadius:999,background:c,flexShrink:0}}),(0,n.jsx)("span",{title:r.message,style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text)",fontSize:11,fontWeight:600},children:r.message}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,flexShrink:0},children:"uploading"===r.phase?`${d}%`:function(e){if(!Number.isFinite(e)||e<=0)return"0 B";let t=["B","KB","MB","GB"],r=e,n=0;for(;r>=1024&&n<t.length-1;)r/=1024,n+=1;return`${r>=10||0===n?Math.round(r):r.toFixed(1)} ${t[n]}`}(r.total)})]}),(0,n.jsx)("div",{style:{marginTop:6,height:3,borderRadius:999,background:"var(--bg)",overflow:"hidden"},children:(0,n.jsx)("div",{style:{width:`${d}%`,height:"100%",borderRadius:999,background:c,transition:"width 0.15s ease"}})}),r.details&&r.details.length>0&&(0,n.jsx)("div",{style:{marginTop:5,display:"grid",gap:2},children:r.details.map(e=>(0,n.jsx)("div",{title:e,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontSize:10},children:e},e))})]})]})}function te({cwd:e,refreshKey:t=0,onOpenFile:r,onExploreFile:i,onAtMention:l}){let[s,a]=(0,o.useState)(""),[d,c]=(0,o.useState)(0);return(0,o.useEffect)(()=>{c(e=>e+1)},[t]),(0,n.jsxs)("div",{style:{height:"100%",display:"flex",flexDirection:"column",background:"var(--bg)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:"9px 10px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",flexShrink:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Files"}),(0,n.jsx)("div",{title:e??"",style:{marginTop:2,fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)"},children:e??"No project selected"})]}),(0,n.jsx)("button",{type:"button",onClick:()=>c(e=>e+1),disabled:!e,title:"Refresh files",style:{width:28,height:28,padding:0,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text-muted)",cursor:e?"pointer":"not-allowed",display:"flex",alignItems:"center",justifyContent:"center",opacity:e?1:.55},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("path",{d:"M21 12a9 9 0 0 1-15.3 6.4"}),(0,n.jsx)("path",{d:"M3 12A9 9 0 0 1 18.3 5.6"}),(0,n.jsx)("path",{d:"M18 2v4h4"}),(0,n.jsx)("path",{d:"M6 22v-4H2"})]})})]}),(0,n.jsxs)("div",{style:{position:"relative",marginTop:9},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",style:{position:"absolute",left:8,top:"50%",transform:"translateY(-50%)",color:"var(--text-dim)",pointerEvents:"none"},"aria-hidden":"true",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)("input",{value:s,onChange:e=>a(e.target.value),placeholder:"Filter files...",disabled:!e,style:{width:"100%",height:30,boxSizing:"border-box",padding:"0 28px 0 26px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:12,outline:"none",opacity:e?1:.6}}),s&&(0,n.jsx)("button",{type:"button",onClick:()=>a(""),title:"Clear filter",style:{position:"absolute",right:4,top:"50%",transform:"translateY(-50%)",width:20,height:20,display:"flex",alignItems:"center",justifyContent:"center",border:"none",borderRadius:4,background:"transparent",color:"var(--text-dim)",cursor:"pointer",padding:0},children:(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round","aria-hidden":"true",children:[(0,n.jsx)("line",{x1:"2",y1:"2",x2:"8",y2:"8"}),(0,n.jsx)("line",{x1:"8",y1:"2",x2:"2",y2:"8"})]})})]})]}),(0,n.jsx)("div",{style:{flex:1,minHeight:0,overflow:"hidden"},children:e?(0,n.jsx)(e7,{cwd:e,onOpenFile:r,onExploreFile:i,refreshKey:d,onAtMention:l,searchQuery:s,onSearchChange:a}):(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",padding:18,textAlign:"center",color:"var(--text-dim)",fontSize:12},children:"Select a project to browse files."})})]})}var tt=r(27568),tr=r(96793);let tn={__soul__:{apiPath:"/api/soul",title:"SOUL.md"},__harness__:{apiPath:"/api/harness",title:"HARNESS.md"}};function to({filePath:e}){let t=tn[e],{isDark:r}=(0,tr.D)(),[i,l]=(0,o.useState)(""),[s,a]=(0,o.useState)(!0),[d,c]=(0,o.useState)(null),[u,p]=(0,o.useState)(!1),[h,x]=(0,o.useState)(!1);(0,o.useEffect)(()=>{t&&(a(!0),fetch(t.apiPath).then(e=>e.json()).then(e=>l(e.content??"")).catch(e=>c(String(e))).finally(()=>a(!1)))},[t]);let g=(0,o.useCallback)(async()=>{if(t){p(!0);try{await fetch(t.apiPath,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:i})}),x(!0),setTimeout(()=>x(!1),2e3)}catch(e){c(String(e))}finally{p(!1)}}},[t,i]);return t?s?(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:"Loading…"}):d?(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#f87171",fontSize:13},children:d}):(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"4px 16px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",background:"var(--bg)",flexShrink:0},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontWeight:600,color:"var(--text)"},children:t.title}),(0,n.jsx)("span",{style:{marginLeft:"auto",fontSize:10,color:"var(--text-dim)"},children:"Global"}),h&&(0,n.jsx)("span",{style:{color:"#4ade80",fontWeight:600,animation:"saved-pop 0.3s ease"},children:"✓ Saved"}),(0,n.jsx)("button",{onClick:g,disabled:u,title:"Save (Ctrl+S)",style:{padding:"2px 10px",fontSize:11,cursor:u?"not-allowed":"pointer",background:"var(--accent)",color:"#fff",border:"1px solid var(--accent)",borderRadius:5,fontWeight:600,opacity:u?.6:1},children:u?"Saving…":"Save"})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"hidden"},children:(0,n.jsx)(tt.g,{initialContent:i,language:"markdown",isDark:r,onChange:l,onSave:g})})]}):null}var ti=r(74987);function tl({sessionId:e,cwd:t,refreshKey:r=0,onOpenFile:i}){let[l,s]=(0,o.useState)(null),[a,d]=(0,o.useState)(!1),[c,u]=(0,o.useState)(!1),[p,h]=(0,o.useState)(null),[x,g]=(0,o.useState)("preview");(0,o.useEffect)(()=>{if(!e){s(null),h(null);return}let t=!1;return d(!0),h(null),fetch(`/api/reports/${encodeURIComponent(e)}`).then(e=>e.ok?e.json():e.json().then(t=>Promise.reject(Error(t.error??`HTTP ${e.status}`)))).then(e=>{t||s(e.report)}).catch(e=>{t||h(e instanceof Error?e.message:String(e))}).finally(()=>{t||d(!1)}),()=>{t=!0}},[e,r]);let f=(0,o.useCallback)(()=>{e&&(u(!0),h(null),fetch(`/api/reports/${encodeURIComponent(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"generate"})}).then(e=>e.ok?e.json():e.json().then(t=>Promise.reject(Error(t.error??`HTTP ${e.status}`)))).then(e=>{s(e.report),g("preview")}).catch(e=>h(e instanceof Error?e.message:String(e))).finally(()=>u(!1)))},[e]),v=(0,o.useMemo)(()=>{if(t)return`${t.replace(/\/+$/,"")}/analysis_report.md`},[t]);return e?(0,n.jsxs)("div",{style:{height:"100%",display:"flex",flexDirection:"column",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"8px 10px",borderBottom:"1px solid var(--border)",background:"var(--bg)",flexShrink:0},children:[["preview","changes","source"].map(e=>(0,n.jsx)("button",{type:"button",onClick:()=>g(e),style:{height:28,padding:"0 9px",border:"1px solid var(--border)",borderRadius:7,background:x===e?"var(--bg-selected)":"var(--bg-panel)",color:x===e?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:11,textTransform:"capitalize"},children:e},e)),(0,n.jsx)("div",{style:{flex:1}}),(0,n.jsx)("button",{type:"button",onClick:f,disabled:c,title:"Refresh analysis report from this session",style:{height:28,padding:"0 10px",border:"1px solid rgba(37,99,235,0.45)",borderRadius:7,background:"var(--bg-selected)",color:"var(--accent)",cursor:c?"default":"pointer",fontSize:11,fontWeight:600,opacity:c?.65:1},children:c?"Updating...":"Update"})]}),p&&(0,n.jsx)("div",{style:{padding:"8px 12px",color:"#ef4444",fontSize:12,borderBottom:"1px solid var(--border)",background:"rgba(239,68,68,0.08)"},children:p}),a?(0,n.jsx)("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:12},children:"Loading report..."}):l?(0,n.jsxs)("div",{style:{flex:1,overflow:"auto"},children:["preview"===x&&(0,n.jsx)(ti.T,{content:l.markdown,className:"markdown-body markdown-file-preview",style:{padding:"22px 26px 40px",maxWidth:860,margin:"0 auto"},codeBlockVariant:"file",baseFilePath:v,onOpenLocalFile:i,enableImageGallery:!0}),"changes"===x&&(0,n.jsx)("div",{style:{padding:14},children:0===l.changes.length?(0,n.jsx)("div",{style:{color:"var(--text-dim)",fontSize:12},children:"No report changes yet."}):l.changes.map(e=>(0,n.jsxs)("div",{style:{padding:"10px 0",borderBottom:"1px solid var(--border)"},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:700,color:"var(--text)",marginBottom:4},children:e.title}),(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",marginBottom:6},children:new Date(e.timestamp).toLocaleString()}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:e.detail})]},e.id))}),"source"===x&&(0,n.jsx)("pre",{style:{margin:0,padding:18,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"var(--font-mono)",fontSize:12,lineHeight:1.55,color:"var(--text-muted)"},children:l.markdown})]}):(0,n.jsx)("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:12},children:"No report available."})]}):(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",padding:24,color:"var(--text-dim)",fontSize:12,textAlign:"center"},children:"Select or start a session to build an analysis report."})}function ts(){document.body.style.cursor="",document.body.style.userSelect=""}function ta({side:e,onResize:t,onResizeStart:r,onResizeEnd:i,ariaLabel:l}){let s=(0,o.useRef)(null),a=(0,o.useRef)(!1),d=(0,o.useRef)(0),[c,u]=(0,o.useState)(!1),p=(0,o.useCallback)(e=>{if(!a.current)return;a.current=!1,u(!1);let t=s.current;t&&void 0!==e&&t.hasPointerCapture(e)&&t.releasePointerCapture(e),ts(),i?.()},[i]),h=(0,o.useCallback)(e=>{0===e.button&&e.isPrimary&&(e.preventDefault(),a.current=!0,d.current=e.clientX,u(!0),r?.(),e.currentTarget.setPointerCapture(e.pointerId),document.body.style.cursor="col-resize",document.body.style.userSelect="none")},[r]),x=(0,o.useCallback)(e=>{if(!a.current)return;e.preventDefault();let r=e.clientX-d.current;d.current=e.clientX,t(r)},[t]),g=(0,o.useCallback)(e=>{e.preventDefault(),p(e.pointerId)},[p]),f=(0,o.useCallback)(e=>{p(e.pointerId)},[p]);return(0,o.useEffect)(()=>()=>{a.current&&(a.current=!1,ts(),i?.())},[i]),(0,n.jsx)("div",{ref:s,role:"separator","aria-label":l??"Resize panel","aria-orientation":"vertical",className:`resize-handle${c?" resize-handle-dragging":""}`,"data-side":e,onPointerDown:h,onPointerMove:x,onPointerUp:g,onPointerCancel:f,style:{alignSelf:"stretch",cursor:"col-resize",display:"flex",flexShrink:0,justifyContent:"center",marginLeft:-5,marginRight:-5,position:"relative",touchAction:"none",width:10,zIndex:250},children:(0,n.jsx)("div",{className:"resize-handle-line"})})}function td(e){return"running"===e?"#22c55e":"starting"===e?"rgba(234,179,8,0.95)":"error"===e?"#ef4444":"var(--text-dim)"}function tc(e){return"h5adexp"===e?"H5AD Exp":"stexp"}function tu(e,t,r){return Math.min(Math.max(e,t),r)}function tp(e){if(!e||"object"!=typeof e||!("app"in e))return null;let t=e.app;return t&&"object"==typeof t&&"id"in t?t:null}function th({appType:e,filePath:t,cwd:r,sessionId:i,appId:l,onClose:s,onAppChanged:a,onOpenTools:d}){var c;let[u,p]=(0,o.useState)(null),[h,x]=(0,o.useState)(null),[g,f]=(0,o.useState)(!1),[v,m]=(0,o.useState)(!1),[y,b]=(0,o.useState)(0),[j,k]=(0,o.useState)(()=>{let e,t,r,n,o,i;return e=window.innerWidth,t=window.innerHeight,n=(r=e<720||t<560)?8:34,o=Math.max(360,e-2*n),i=Math.max(320,t-2*n),{left:n,top:n,width:r?o:Math.min(1280,o),height:r?i:Math.min(880,i),maximized:!1}}),[w,S]=(0,o.useState)(!1),[C,T]=(0,o.useState)(!1),z=(0,o.useRef)(null),I=(0,o.useRef)(null),M=(0,o.useRef)(null),R=!!t||!!l,L=t?(0,e1.WP)(t):u?(0,e1.WP)(u.filePath):"",W=t&&r?(0,e1.qP)(t,r):u?.filePath&&u.cwd?(0,e1.qP)(u.filePath,u.cwd):t??u?.filePath??"",E=u?.status??"idle",$=(0,o.useMemo)(()=>u?.logs?.join("\n")??"",[u?.logs]),P=u?.appType==="h5adexp"?u.url:u?.directUrl??u?.url??"",D=(0,o.useCallback)(e=>{p(e),a?.(e)},[a]),B=(0,o.useCallback)(async e=>{let t=await fetch(`/api/apps?appId=${encodeURIComponent(e)}`),r=await t.json(),n=tp(r);if(!t.ok||!n)throw Error(r&&"object"==typeof r&&"error"in r?String(r.error):`HTTP ${t.status}`);return D(n),n},[D]),N=(0,o.useCallback)(async()=>{if(t&&r&&!g){f(!0),x(null);try{let n=await fetch("/api/apps",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"start",appType:e,filePath:t,cwd:r,sessionId:i})}),o=await n.json(),l=tp(o);if(!n.ok||!l){let e=o&&"object"==typeof o&&"error"in o?String(o.error):`HTTP ${n.status}`;throw Error(e)}D(l),b(e=>e+1)}catch(e){x(e instanceof Error?e.message:String(e))}finally{f(!1)}}},[e,D,g,r,t,i]);(0,o.useEffect)(()=>{if(R){if(x(null),m(!1),l)return void B(l).then(()=>b(e=>e+1)).catch(e=>x(e instanceof Error?e.message:String(e)));p(null),N()}},[R,l,t]),(0,o.useEffect)(()=>{if(!u?.id||"stopped"===u.status||"error"===u.status)return;let e=window.setInterval(()=>{B(u.id).catch(()=>{})},2500);return()=>window.clearInterval(e)},[u?.id,u?.status,B]),(0,o.useEffect)(()=>{R&&z.current?.focus({preventScroll:!0})},[R,u?.id]),(0,o.useEffect)(()=>{let e=()=>{k(e=>{if(e.maximized)return e;let t=Math.max(360,window.innerWidth-16),r=Math.max(320,window.innerHeight-16),n=Math.min(e.width,t),o=Math.min(e.height,r);return{...e,width:n,height:o,left:tu(e.left,8,Math.max(8,window.innerWidth-n-8)),top:tu(e.top,8,Math.max(8,window.innerHeight-o-8))}})};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]);let O=(0,o.useCallback)(async()=>{if(u?.id&&!g){f(!0),x(null);try{let e=await fetch("/api/apps",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"stop",appId:u.id})}),t=await e.json(),r=tp(t);if(!e.ok||!r){let r=t&&"object"==typeof t&&"error"in t?String(t.error):`HTTP ${e.status}`;throw Error(r)}D(r)}catch(e){x(e instanceof Error?e.message:String(e))}finally{f(!1)}}},[u?.id,D,g]),A=(0,o.useCallback)(e=>{0!==e.button||j.maximized||(e.preventDefault(),e.currentTarget.setPointerCapture(e.pointerId),I.current={pointerId:e.pointerId,startX:e.clientX,startY:e.clientY,left:j.left,top:j.top},S(!0))},[j.left,j.maximized,j.top]),H=(0,o.useCallback)(e=>{let t=I.current;if(!t||t.pointerId!==e.pointerId)return;let r=t.left+e.clientX-t.startX,n=t.top+e.clientY-t.startY;k(e=>({...e,left:tu(r,8,Math.max(8,window.innerWidth-120)),top:tu(n,8,Math.max(8,window.innerHeight-48))}))},[]),F=(0,o.useCallback)(e=>{let t=I.current;t?.pointerId===e.pointerId&&(e.currentTarget.releasePointerCapture(e.pointerId),I.current=null,S(!1))},[]),U=(0,o.useCallback)(e=>{0!==e.button||j.maximized||(e.preventDefault(),e.stopPropagation(),e.currentTarget.setPointerCapture(e.pointerId),M.current={pointerId:e.pointerId,startX:e.clientX,startY:e.clientY,width:j.width,height:j.height},T(!0))},[j.height,j.maximized,j.width]),_=(0,o.useCallback)(e=>{let t=M.current;if(!t||t.pointerId!==e.pointerId)return;let r=t.width+e.clientX-t.startX,n=t.height+e.clientY-t.startY;k(e=>({...e,width:tu(r,420,Math.max(420,window.innerWidth-e.left-8)),height:tu(n,340,Math.max(340,window.innerHeight-e.top-8))}))},[]),J=(0,o.useCallback)(e=>{let t=M.current;t?.pointerId===e.pointerId&&(e.currentTarget.releasePointerCapture(e.pointerId),M.current=null,T(!1))},[]),V=(0,o.useCallback)(()=>{d?.(),s()},[s,d]),K=(0,o.useCallback)(()=>{k(e=>({...e,maximized:!e.maximized}))},[]);if(!R)return null;let Y=j.maximized?{position:"fixed",inset:12,zIndex:900}:{position:"fixed",left:j.left,top:j.top,width:j.width,height:j.height,zIndex:900};return(0,n.jsxs)("div",{ref:z,role:"dialog","aria-label":`${u?.title??tc(e)} window`,tabIndex:-1,onKeyDown:e=>{"Escape"===e.key&&V()},style:{...Y,display:"flex",flexDirection:"column",minWidth:j.maximized?void 0:420,minHeight:j.maximized?void 0:340,background:"var(--bg)",border:"1px solid rgba(37,99,235,0.5)",borderRadius:8,boxShadow:"0 18px 60px rgba(0,0,0,0.26)",overflow:"hidden",outline:"none"},children:[(0,n.jsxs)("div",{onPointerDown:A,onPointerMove:H,onPointerUp:F,onPointerCancel:F,style:{display:"flex",alignItems:"center",gap:8,padding:"8px 9px 8px 12px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",flexShrink:0,userSelect:"none",cursor:j.maximized?"default":w?"grabbing":"grab"},children:[(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,n.jsx)("span",{style:{fontSize:13,fontWeight:700,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u?.title??tc(e)}),(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:td(E),flexShrink:0}}),(0,n.jsx)("span",{style:{fontSize:11,color:td(E),textTransform:"capitalize",flexShrink:0},children:E}),u?.pid&&(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-dim)",flexShrink:0},children:["pid ",u.pid]}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",flexShrink:0},children:(c=u?.rssBytes)&&Number.isFinite(c)?c<1048576?`${(c/1024).toFixed(0)}K`:c<0x40000000?`${(c/1024/1024).toFixed(1)}M`:`${(c/1024/1024/1024).toFixed(1)}G`:"-"})]}),(0,n.jsx)("div",{title:t??u?.filePath??"",style:{marginTop:2,fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)"},children:W||L})]}),(0,n.jsx)("button",{type:"button",onPointerDown:e=>e.stopPropagation(),onClick:()=>b(e=>e+1),disabled:!P||u?.status==="stopped",style:tx,title:"Reload",children:"Reload"}),(0,n.jsx)("button",{type:"button",onPointerDown:e=>e.stopPropagation(),onClick:()=>m(e=>!e),style:{...tx,background:v?"var(--bg-selected)":"var(--bg)",color:v?"var(--text)":"var(--text-muted)"},title:"Toggle logs",children:"Logs"}),(0,n.jsx)("button",{type:"button",onPointerDown:e=>e.stopPropagation(),onClick:V,style:tx,title:"Show in Tools",children:"Tools"}),(0,n.jsx)("button",{type:"button",onPointerDown:e=>e.stopPropagation(),onClick:()=>void O(),disabled:!u||"stopped"===u.status||g,style:{...tx,border:"1px solid rgba(239,68,68,0.35)",background:"rgba(239,68,68,0.08)",color:"#ef4444",opacity:!u||"stopped"===u.status||g?.55:1},title:"Stop process",children:"Stop"}),(0,n.jsx)("button",{type:"button",onPointerDown:e=>e.stopPropagation(),onClick:V,"aria-label":"Minimize",title:"Minimize",style:tg,children:(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round","aria-hidden":"true",children:(0,n.jsx)("line",{x1:"4",y1:"11",x2:"12",y2:"11"})})}),(0,n.jsx)("button",{type:"button",onPointerDown:e=>e.stopPropagation(),onClick:K,"aria-label":j.maximized?"Restore":"Maximize",title:j.maximized?"Restore":"Maximize",style:tg,children:j.maximized?(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("path",{d:"M6 3.5h6.5V10"}),(0,n.jsx)("path",{d:"M3.5 6H10v6.5H3.5z"})]}):(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,n.jsx)("path",{d:"M4 4h8v8H4z"})})}),(0,n.jsx)("button",{type:"button",onPointerDown:e=>e.stopPropagation(),onClick:s,"aria-label":"Close window",title:"Close window",style:tg,children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round","aria-hidden":"true",children:[(0,n.jsx)("line",{x1:"4",y1:"4",x2:"12",y2:"12"}),(0,n.jsx)("line",{x1:"12",y1:"4",x2:"4",y2:"12"})]})})]}),(h||u?.error)&&(0,n.jsx)("div",{style:{padding:"8px 12px",borderBottom:"1px solid rgba(248,113,113,0.25)",background:"rgba(248,113,113,0.08)",color:"#f87171",fontSize:12},children:h??u?.error}),(0,n.jsxs)("div",{style:{flex:1,minHeight:0,display:"flex",background:"var(--bg)"},children:[(0,n.jsx)("div",{style:{flex:1,minWidth:0,position:"relative"},children:g&&!u?.url?(0,n.jsxs)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:["Starting ",tc(e),"..."]}):P&&u?.status!=="stopped"?(0,n.jsx)("iframe",{src:P,title:`${u?.title??tc(e)} - ${L}`,style:{width:"100%",height:"100%",border:"none",display:"block",background:"#fff"}},`${P}:${y}`):(0,n.jsxs)("div",{style:{height:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:10,color:"var(--text-muted)",fontSize:13},children:[(0,n.jsxs)("div",{children:[tc(e)," is stopped."]}),t&&r&&(0,n.jsx)("button",{type:"button",onClick:()=>void N(),disabled:g,style:{height:32,padding:"0 12px",border:"none",borderRadius:6,background:"var(--accent)",color:"#fff",cursor:g?"not-allowed":"pointer",fontSize:12,fontWeight:650},children:"Start again"})]})}),v&&(0,n.jsxs)("div",{style:{width:360,borderLeft:"1px solid var(--border)",background:"var(--bg-panel)",display:"flex",flexDirection:"column",minHeight:0},children:[(0,n.jsx)("div",{style:{padding:"8px 10px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-muted)",fontWeight:650},children:"Process Logs"}),(0,n.jsx)("pre",{style:{flex:1,margin:0,padding:10,overflow:"auto",fontSize:11,lineHeight:1.45,color:"var(--text-muted)",fontFamily:"var(--font-mono)",whiteSpace:"pre-wrap"},children:$||"No logs yet."})]})]}),!j.maximized&&(0,n.jsx)("div",{role:"separator","aria-orientation":"horizontal","aria-label":"Resize explore window",title:"Resize",onPointerDown:U,onPointerMove:_,onPointerUp:J,onPointerCancel:J,style:{position:"absolute",right:0,bottom:0,width:18,height:18,cursor:"nwse-resize",background:"linear-gradient(135deg, transparent 0 48%, rgba(127,127,127,0.22) 48% 52%, transparent 52% 100%)"}})]})}let tx={height:30,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text-muted)",cursor:"pointer",fontSize:12,flexShrink:0},tg={width:30,height:30,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,padding:0};function tf(e){return"running"===e?"#22c55e":"starting"===e?"rgba(234,179,8,0.95)":"error"===e?"#ef4444":"var(--text-dim)"}function tv(e){return"waiting_model"===e?"rgba(234,179,8,0.95)":"running_tools"===e?"#38bdf8":"streaming"===e?"#22c55e":"compacting"===e?"#a78bfa":"var(--text-dim)"}function tm(e){return e&&Number.isFinite(e)?e<1048576?`${(e/1024).toFixed(0)}K`:e<0x40000000?`${(e/1024/1024).toFixed(1)}M`:`${(e/1024/1024/1024).toFixed(1)}G`:"-"}function ty(e){if(!e||!Number.isFinite(e))return"-";let t=Math.max(0,Math.floor(e/1e3)),r=Math.floor(t/3600),n=Math.floor(t%3600/60),o=t%60;return r>0?`${r}h ${n}m`:n>0?`${n}m ${o}s`:`${o}s`}function tb({refreshKey:e=0,visibleAppId:t,cwd:r,onOpenApp:i,onAppChanged:l,onAppsChanged:s}){let[a,d]=(0,o.useState)([]),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(null),[x,g]=(0,o.useState)(null),[f,v]=(0,o.useState)(null),[m,y]=(0,o.useState)(null),[b,j]=(0,o.useState)(null),[k,w]=(0,o.useState)(null),[S,C]=(0,o.useState)(null),[T,z]=(0,o.useState)(null),I=(0,o.useMemo)(()=>[...a].sort((e,t)=>{let r=+!!e.running,n=+!!t.running;return r!==n?n-r:Date.parse(t.lastActivity)-Date.parse(e.lastActivity)}),[a]),M=(0,o.useCallback)(async()=>{try{let e=await fetch("/api/apps",{cache:"no-store"}),t=await e.json();if(!e.ok||!Array.isArray(t.apps))throw Error(t.error??`HTTP ${e.status}`);d(t.apps),s?.(t.apps),g(null)}catch(e){g(e instanceof Error?e.message:String(e))}},[s]),R=(0,o.useCallback)(async()=>{try{let e=new URLSearchParams;r&&e.set("cwd",r);let t=await fetch(`/api/agent/runtime${e.toString()?`?${e}`:""}`,{cache:"no-store"}),n=await t.json();if(!t.ok||!Array.isArray(n.sessions))throw Error(n.error??`HTTP ${t.status}`);u(n),h(n.memory??null),v(null)}catch(e){v(e instanceof Error?e.message:String(e))}},[r]);(0,o.useEffect)(()=>{M(),R()},[M,R,e]),(0,o.useEffect)(()=>{let e=window.setInterval(()=>{M(),R()},3e3);return()=>window.clearInterval(e)},[M,R]);let L=(0,o.useCallback)(async e=>{w(e.id),g(null);try{let t=await fetch("/api/apps",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"stop",appId:e.id})}),r=await t.json();if(!t.ok||!r.app)throw Error(r.error??`HTTP ${t.status}`);d(e=>e.map(e=>e.id===r.app.id?r.app:e)),l?.(r.app),await M()}catch(e){g(e instanceof Error?e.message:String(e))}finally{w(null)}},[M,l]),W=(0,o.useCallback)(async e=>{C(e.sessionId),v(null);try{let t=await fetch(`/api/agent/${encodeURIComponent(e.sessionId)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"abort"})}),r=await t.json().catch(()=>({}));if(!t.ok||r.error)throw Error(r.error??`HTTP ${t.status}`);await R()}catch(e){v(e instanceof Error?e.message:String(e))}finally{C(null)}},[R]),E=(0,o.useCallback)(async(e,t)=>{if(r){j(`${e}:${t}`),y(null);try{let n=await fetch("/api/memory/promote",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:r,memoryId:e,target:t})}),o=await n.json().catch(()=>({}));if(!n.ok)throw Error(o.error??`HTTP ${n.status}`);await R()}catch(e){y(e instanceof Error?e.message:String(e))}finally{j(null)}}},[r,R]),$=a.filter(e=>e.running).length,P=a.reduce((e,t)=>e+(t.running?t.rssBytes??0:0),0),D=c?.sessions??[],B=D.filter(e=>e.busy),N=B.filter(e=>"waiting_model"===e.phase);return(0,n.jsxs)("div",{style:{height:"100%",display:"flex",flexDirection:"column",background:"var(--bg)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:"10px 12px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",flexShrink:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:10},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Status"}),(0,n.jsxs)("div",{style:{marginTop:3,fontSize:11,color:"var(--text-dim)"},children:[B.length," agent running \xb7 ",$," explore \xb7 ",tm(P)]})]}),(0,n.jsx)("button",{type:"button",onClick:()=>{M(),R()},style:tC,title:"Refresh status",children:"Refresh"})]}),x&&(0,n.jsx)("div",{style:{marginTop:8,padding:"7px 8px",border:"1px solid rgba(248,113,113,0.25)",borderRadius:6,background:"rgba(248,113,113,0.08)",color:"#f87171",fontSize:11},children:x}),f&&(0,n.jsx)("div",{style:{marginTop:8,padding:"7px 8px",border:"1px solid rgba(248,113,113,0.25)",borderRadius:6,background:"rgba(248,113,113,0.08)",color:"#f87171",fontSize:11},children:f}),m&&(0,n.jsx)("div",{style:{marginTop:8,padding:"7px 8px",border:"1px solid rgba(248,113,113,0.25)",borderRadius:6,background:"rgba(248,113,113,0.08)",color:"#f87171",fontSize:11},children:m})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"auto",padding:10},children:(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[(0,n.jsxs)("section",{children:[(0,n.jsx)(tj,{title:"Agent Runtime",subtitle:N.length>0?`${N.length} waiting for model first token`:`${B.length} active chat${1===B.length?"":"s"}`}),0===D.length?(0,n.jsx)(tk,{label:"No agent runtime is active."}):(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:D.map(e=>{var t;let r=e.model?`${e.model.provider}/${e.model.id}`:"-",o=e.cwd?(0,e1.WP)(e.cwd)||e.cwd:"-",i=e.activeTools.map(e=>e.name).join(", ");return(0,n.jsxs)("div",{style:{border:`1px solid ${e.busy?"rgba(37,99,235,0.35)":"var(--border)"}`,borderRadius:8,background:e.busy?"var(--bg-selected)":"var(--bg-panel)",padding:10},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[(0,n.jsx)("span",{style:{width:8,height:8,borderRadius:"50%",background:tv(e.phase),marginTop:5,flexShrink:0}}),(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:7,minWidth:0},children:[(0,n.jsx)("span",{style:{fontSize:12,fontWeight:700,color:tv(e.phase),textTransform:"uppercase",flexShrink:0},children:"waiting_model"===(t=e.phase)?"waiting model":"running_tools"===t?"running tools":"streaming"===t?"streaming":"compacting"===t?"compacting":"idle"}),(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:r,children:r})]}),(0,n.jsxs)("div",{title:e.cwd??void 0,style:{marginTop:3,fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[o," \xb7 ",e.sessionId.slice(0,8)]})]})]}),(0,n.jsxs)("div",{style:{marginTop:9,display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:"5px 10px",fontSize:11,color:"var(--text-muted)"},children:[(0,n.jsx)(tw,{label:"uptime",value:ty(e.uptimeMs)}),(0,n.jsx)(tw,{label:"wait",value:ty(e.waitingForModelMs),color:"waiting_model"===e.phase?tv(e.phase):void 0}),(0,n.jsx)(tw,{label:"pending",value:null===e.pendingMessageCount?"-":String(e.pendingMessageCount)}),(0,n.jsx)(tw,{label:"event",value:e.lastEventType??"-"}),(0,n.jsx)(tw,{label:"tools",value:i||"-"}),(0,n.jsx)(tw,{label:"ops",value:e.operations.join(", ")||"-"})]}),"waiting_model"===e.phase&&(e.waitingForModelMs??0)>8e3&&(0,n.jsx)("div",{style:{marginTop:8,padding:"7px 8px",border:"1px solid rgba(234,179,8,0.25)",borderRadius:6,background:"rgba(234,179,8,0.08)",color:"rgba(234,179,8,0.95)",fontSize:11,lineHeight:1.45},children:"Waiting before the first model token. If another chat uses the same provider or gateway, the upstream may be queueing requests."}),e.errorMessage&&(0,n.jsx)("div",{style:{marginTop:8,padding:"7px 8px",border:"1px solid rgba(248,113,113,0.25)",borderRadius:6,background:"rgba(248,113,113,0.08)",color:"#f87171",fontSize:11,lineHeight:1.45},children:e.errorMessage}),(0,n.jsx)("div",{style:{marginTop:10,display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:(0,n.jsx)("button",{type:"button",onClick:()=>void W(e),disabled:!e.busy||S===e.sessionId,style:{...tC,border:"1px solid rgba(239,68,68,0.35)",color:"#ef4444",background:"rgba(239,68,68,0.08)",opacity:e.busy&&S!==e.sessionId?1:.55},children:"Abort"})})]},e.sessionId)})})]}),(0,n.jsxs)("section",{children:[(0,n.jsx)(tj,{title:"Memory",subtitle:p?`${p.count} stored \xb7 ${p.candidateCount} candidates`:r?"loading":"No project selected"}),r?p?(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",padding:10},children:[(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:"5px 10px",fontSize:11,color:"var(--text-muted)"},children:[(0,n.jsx)(tw,{label:"fact",value:String(p.byType.fact)}),(0,n.jsx)(tw,{label:"context",value:String(p.byType.context)}),(0,n.jsx)(tw,{label:"decision",value:String(p.byType.decision)}),(0,n.jsx)(tw,{label:"preference",value:String(p.byType.preference)}),(0,n.jsx)(tw,{label:"note",value:String(p.byType.note)}),(0,n.jsx)(tw,{label:"candidates",value:String(p.candidateCount),color:p.candidateCount>0?"var(--accent)":void 0})]}),(0,n.jsx)("div",{title:p.filePath,style:{marginTop:8,fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(0,e1.qP)(p.filePath,r)})]}),(0,n.jsx)(tS,{title:"Promotion Candidates",emptyLabel:"No promotion candidates yet.",items:p.topCandidates,onPromote:E,busyAction:b}),(0,n.jsx)(tS,{title:"Recent Memory",emptyLabel:"No memory stored for this project.",items:p.recent})]}):(0,n.jsx)(tk,{label:"Memory status unavailable."}):(0,n.jsx)(tk,{label:"Select a project to inspect memory status."})]}),(0,n.jsxs)("section",{children:[(0,n.jsx)(tj,{title:"Explore Tools",subtitle:`${$} running \xb7 ${tm(P)}`}),0===I.length?(0,n.jsx)(tk,{label:"No explore tools are running."}):(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:I.map(e=>{let o,l=t===e.id,s=T===e.id;return(0,n.jsxs)("div",{style:{border:`1px solid ${l?"rgba(37,99,235,0.5)":"var(--border)"}`,borderRadius:8,background:l?"var(--bg-selected)":"var(--bg-panel)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:10},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[(0,n.jsx)("span",{style:{width:8,height:8,borderRadius:"50%",background:tf(e.status),marginTop:5,flexShrink:0}}),(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:7,minWidth:0},children:[(0,n.jsx)("span",{style:{fontSize:12,fontWeight:700,color:"var(--text)",textTransform:"uppercase",flexShrink:0},children:e.appType}),(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:e.filePath,children:(0,e1.WP)(e.filePath)})]}),(0,n.jsx)("div",{title:e.filePath,style:{marginTop:3,fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(o=r&&e.filePath.startsWith(r)?r:e.cwd,(0,e1.qP)(e.filePath,o))})]})]}),(0,n.jsxs)("div",{style:{marginTop:9,display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:"5px 10px",fontSize:11,color:"var(--text-muted)"},children:[(0,n.jsx)(tw,{label:"status",value:e.status,color:tf(e.status)}),(0,n.jsx)(tw,{label:"pid",value:e.pid?String(e.pid):"-"}),(0,n.jsx)(tw,{label:"memory",value:tm(e.rssBytes)}),(0,n.jsx)(tw,{label:"uptime",value:ty(e.uptimeMs)}),(0,n.jsx)(tw,{label:"port",value:String(e.port)}),(0,n.jsx)(tw,{label:"session",value:e.sessionId?e.sessionId.slice(0,8):"-"})]}),(0,n.jsxs)("div",{style:{marginTop:10,display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:[(0,n.jsx)("button",{type:"button",onClick:()=>i(e),style:tC,children:"Open"}),(0,n.jsx)("button",{type:"button",onClick:()=>z(t=>t===e.id?null:e.id),style:{...tC,background:s?"var(--bg-selected)":"var(--bg)"},children:"Logs"}),(0,n.jsx)("button",{type:"button",onClick:()=>void L(e),disabled:!e.running||k===e.id,style:{...tC,border:"1px solid rgba(239,68,68,0.35)",color:"#ef4444",background:"rgba(239,68,68,0.08)",opacity:e.running&&k!==e.id?1:.55},children:"Stop"})]})]}),s&&(0,n.jsx)("pre",{style:{maxHeight:220,overflow:"auto",margin:0,padding:10,borderTop:"1px solid var(--border)",background:"var(--bg)",color:"var(--text-muted)",fontSize:11,lineHeight:1.45,fontFamily:"var(--font-mono)",whiteSpace:"pre-wrap"},children:e.logs.join("\n")||"No logs yet."})]},e.id)})})]})]})})]})}function tj({title:e,subtitle:t}){return(0,n.jsxs)("div",{style:{marginBottom:8,display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:10},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:700,color:"var(--text)"},children:e}),(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t})]})}function tk({label:e}){return(0,n.jsx)("div",{style:{border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",padding:"18px 10px",color:"var(--text-dim)",fontSize:12,textAlign:"center"},children:e})}function tw({label:e,value:t,color:r}){return(0,n.jsxs)("div",{style:{minWidth:0,display:"flex",alignItems:"center",gap:5},children:[(0,n.jsx)("span",{style:{color:"var(--text-dim)",flexShrink:0},children:e}),(0,n.jsx)("span",{style:{color:r??"var(--text-muted)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)"},children:t})]})}function tS({title:e,emptyLabel:t,items:r,onPromote:o,busyAction:i}){return(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"8px 10px",borderBottom:"1px solid var(--border)",fontSize:12,fontWeight:700,color:"var(--text)"},children:e}),0===r.length?(0,n.jsx)("div",{style:{padding:"14px 10px",fontSize:12,color:"var(--text-dim)",textAlign:"center"},children:t}):(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column"},children:r.map((e,t)=>(0,n.jsxs)("div",{style:{padding:"9px 10px",borderTop:0===t?"none":"1px solid var(--border)",display:"flex",flexDirection:"column",gap:5},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,minWidth:0},children:[(0,n.jsx)("span",{style:{fontSize:10,color:"project_memory"===e.candidate?"#f59e0b":"spark"===e.candidate?"var(--accent)":"var(--text-dim)",fontWeight:700,textTransform:"uppercase",flexShrink:0},children:"none"===e.candidate?e.memoryType:e.candidate}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)",flexShrink:0},children:e.importance.toFixed(2)}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:new Date(e.timestamp).toLocaleString()})]}),(0,n.jsx)("div",{title:e.content,style:{fontSize:12,color:"var(--text)",lineHeight:1.45,display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical",overflow:"hidden"},children:e.content}),o&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:[(0,n.jsx)("button",{type:"button",disabled:e.promotedTo.includes("memory")||i===`${e.id}:context`||i===`${e.id}:memory`,onClick:()=>void o(e.id,"memory"),style:{...tC,height:24,padding:"0 8px",opacity:e.promotedTo.includes("memory")||i===`${e.id}:context`||i===`${e.id}:memory`?.55:1},children:e.promotedTo.includes("memory")?"In MEMORY.md":i===`${e.id}:memory`?"Saving...":"To MEMORY.md"}),(0,n.jsx)("button",{type:"button",disabled:e.promotedTo.includes("context")||i===`${e.id}:context`||i===`${e.id}:memory`,onClick:()=>void o(e.id,"context"),style:{...tC,height:24,padding:"0 8px",opacity:e.promotedTo.includes("context")||i===`${e.id}:context`||i===`${e.id}:memory`?.55:1},children:e.promotedTo.includes("context")?"In CONTEXT.md":i===`${e.id}:context`?"Saving...":"To CONTEXT.md"})]})]},e.id))})]})}let tC={height:28,padding:"0 9px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:550};function tT({tabs:e,activeTabId:t,onSelectTab:r,onCloseTab:i}){let[l,s]=(0,o.useState)(null);return(0,n.jsx)("div",{style:{display:"flex",alignItems:"flex-end",background:"var(--bg-panel)",overflowX:"auto",flexShrink:0,height:36},children:e.map(e=>{let o=e.id===t,a=!1!==e.closable;return(0,n.jsxs)("div",{onClick:()=>r(e.id),style:{display:"flex",alignItems:"center",gap:6,height:36,paddingLeft:12,paddingRight:6,borderRight:"1px solid var(--border)",background:o?"var(--bg)":"var(--bg-panel)",cursor:"pointer",fontSize:12,color:o?"var(--text)":"var(--text-muted)",whiteSpace:"nowrap",maxWidth:180,minWidth:80,flexShrink:0,userSelect:"none",transition:"background 0.1s, color 0.1s"},children:[(0,n.jsx)("span",{style:{flexShrink:0,opacity:o?1:.7,display:"flex",alignItems:"center"},children:"files"===e.icon?(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)("path",{d:"M3 7.5V6a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v1.5"}),(0,n.jsx)("path",{d:"M3 7.5h18l-1.6 9.6A2 2 0 0 1 17.4 19H6.6a2 2 0 0 1-2-1.9z"})]}):"report"===e.icon?(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)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,n.jsx)("polyline",{points:"14 2 14 8 20 8"}),(0,n.jsx)("line",{x1:"8",y1:"13",x2:"16",y2:"13"}),(0,n.jsx)("line",{x1:"8",y1:"17",x2:"13",y2:"17"})]}):"tools"===e.icon?(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:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.1-3.1a6 6 0 0 1-7.9 7.9l-5.7 5.7a2.1 2.1 0 0 1-3-3l5.7-5.7a6 6 0 0 1 7.9-7.9z"})}):e0(e.filePath??e.label,13)}),(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",flex:1,fontWeight:o?500:400},title:e.filePath??e.label,children:e.label}),a&&(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),i(e.id)},onMouseEnter:()=>s(e.id),onMouseLeave:()=>s(null),style:{display:"flex",alignItems:"center",justifyContent:"center",width:16,height:16,background:l===e.id?"var(--bg-hover)":"transparent",border:"none",borderRadius:3,color:l===e.id?"var(--text)":"var(--text-dim)",cursor:"pointer",padding:0,flexShrink:0,transition:"background 0.1s, color 0.1s"},title:"Close",children:(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"2",y1:"2",x2:"8",y2:"8"}),(0,n.jsx)("line",{x1:"8",y1:"2",x2:"2",y2:"8"})]})})]},e.id)})})}function tz(e){let t=e,r=0;for(;1===t.children.length;)t=t.children[0],r++;return{node:t,skipped:r}}function tI({node:e,activePathIds:t,depth:r,isLast:o,parentLines:i,onSelect:l}){let{node:s,skipped:a}=tz(e),d=t.has(s.entry.id),c=t.has(e.entry.id)||t.has(s.entry.id),u=function(e){if("message"===e.type&&"message"in e){let t=e.message,r=t.content,n="";if("string"==typeof r?n=r:Array.isArray(r)&&(n=r.filter(e=>"text"===e.type).map(e=>e.text).join(" ")),n.length>40&&(n=n.slice(0,40)+"…"),n)return n;if("assistant"===t.role)return"[assistant]"}return e.type}(s.entry),p="message"===s.entry.type&&"message"in s.entry?s.entry.message.role:null;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",height:24,cursor:"pointer"},onClick:()=>l(s.entry.id),children:[i.map((e,t)=>(0,n.jsx)("div",{style:{width:16,flexShrink:0,position:"relative",height:"100%",alignSelf:"stretch"},children:e&&(0,n.jsx)("div",{style:{position:"absolute",left:7,top:0,bottom:0,width:1,background:"var(--border)"}})},t)),(0,n.jsxs)("div",{style:{width:16,flexShrink:0,position:"relative",height:"100%",alignSelf:"stretch"},children:[(0,n.jsx)("div",{style:{position:"absolute",left:7,top:0,bottom:o?"50%":0,width:1,background:"var(--border)"}}),(0,n.jsx)("div",{style:{position:"absolute",left:7,top:"50%",width:9,height:1,background:"var(--border)"}})]}),(0,n.jsx)("div",{style:{width:7,height:7,borderRadius:"50%",flexShrink:0,background:d?"var(--accent)":c?"var(--text-muted)":"var(--border)",border:d?"none":"1px solid var(--text-dim)",marginRight:6,transition:"background 0.12s"}}),p&&(0,n.jsx)("span",{style:{fontSize:9,fontFamily:"var(--font-mono)",color:"user"===p?"var(--accent)":"var(--text-dim)",background:"user"===p?"rgba(37,99,235,0.08)":"var(--bg-hover)",border:`1px solid ${"user"===p?"rgba(37,99,235,0.2)":"var(--border)"}`,borderRadius:3,padding:"0 4px",marginRight:5,flexShrink:0,lineHeight:"16px"},children:"user"===p?"U":"A"}),a>0&&(0,n.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",marginRight:5,flexShrink:0},children:["+",a]}),(0,n.jsx)("span",{style:{fontSize:11,color:d?"var(--text)":c?"var(--text-muted)":"var(--text-dim)",fontWeight:d?500:400,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,minWidth:0},children:u})]}),s.children.map((e,a)=>(0,n.jsx)(tI,{node:e,activePathIds:t,depth:r+1,isLast:a===s.children.length-1,parentLines:[...i,!o],onSelect:l},e.entry.id))]})}function tM({tree:e,activeLeafId:t,onLeafChange:r,inline:i,containerRef:l,open:s,onToggle:a,hasSession:d}){let[c,u]=(0,o.useState)(!1),p=void 0!==s?s:c,h=(0,o.useRef)(null),[x,g]=(0,o.useState)(null);(0,o.useEffect)(()=>{if(!p||!i)return;let e=l?.current??h.current;if(!e)return;let t=()=>{let t=e.getBoundingClientRect();g({top:t.bottom,left:t.left,width:t.width})};t();let r=new ResizeObserver(t);return r.observe(e),()=>r.disconnect()},[p,i,l]);let f=(0,o.useMemo)(()=>t?new Set(function e(r,n){for(let o of r){let r=[...n,o.entry.id];if(o.entry.id===t)return r;let i=e(o.children,r);if(i)return i}return null}(e,[])??[]):new Set,[e,t]),v=(0,o.useCallback)(e=>{r(e)},[r]),m=d?!function e(t){for(let r of t)if(r.children.length>1||e(r.children))return!0;return!1}(e)?"This session has no branches":null:"No active session",y=e.length>0?tz(e[0]):null,b=y?.node??null,j=!m&&b&&b.children.length>1,k=(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:j?"var(--accent)":"var(--text-dim)",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"})]}),w=(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:{marginLeft:2,transform:p?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})});return i?(0,n.jsxs)("div",{style:{height:"100%",display:"flex",alignItems:"stretch"},children:[(0,n.jsxs)("button",{ref:h,className:"topbar-branches-button",onClick:()=>a?a():u(e=>!e),title:"Branches","aria-label":"Branches",style:{display:"flex",alignItems:"center",gap:6,height:28,padding:"0 9px",background:p?"var(--bg-selected)":"var(--bg-panel)",border:`1px solid ${p?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,cursor:"pointer",color:p?"var(--text)":"var(--text-muted)",fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s, border-color 0.1s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color=p?"var(--text)":"var(--text-muted)",e.currentTarget.style.background=p?"var(--bg-selected)":"var(--bg-panel)"},children:[(0,n.jsx)("span",{className:"topbar-branches-icon",children:k}),(0,n.jsx)("span",{className:"topbar-branches-label",children:"Branches"})]}),p&&x&&(0,n.jsx)("div",{style:{position:"fixed",top:x.top,left:x.left,width:x.width,background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",zIndex:500},children:j&&b?(0,n.jsx)("div",{style:{padding:"4px 12px 8px 12px",maxHeight:260,overflowY:"auto"},children:b.children.map((e,t)=>(0,n.jsx)(tI,{node:e,activePathIds:f,depth:0,isLast:t===b.children.length-1,parentLines:[],onSelect:v},e.entry.id))}):(0,n.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:m})})]}):(0,n.jsxs)("div",{style:{borderBottom:"1px solid var(--border)",background:"var(--bg)",flexShrink:0,position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>u(e=>!e),style:{display:"flex",alignItems:"center",gap:6,width:"100%",padding:"5px 12px",background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",fontSize:11,textAlign:"left"},children:[k,(0,n.jsx)("span",{style:{color:"var(--text-muted)"},children:"Branches"}),w]}),p&&(0,n.jsx)("div",{style:{position:"absolute",top:"100%",left:0,right:0,background:"var(--bg)",borderBottom:"1px solid var(--border)",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100},children:j&&b?(0,n.jsx)("div",{style:{padding:"4px 12px 8px 12px",maxHeight:260,overflowY:"auto"},children:b.children.map((e,t)=>(0,n.jsx)(tI,{node:e,activePathIds:f,depth:0,isLast:t===b.children.length-1,parentLines:[],onSelect:v},e.entry.id))}):(0,n.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:m??"This session has no branches"})})]})}function tR(e,t="0 0 24 24"){let r=({size:r=24,style:o})=>(0,n.jsx)("svg",{width:r,height:r,viewBox:t,fill:"none",style:o,children:e});return r.displayName="ProviderIcon",r}let tL=tR((0,n.jsx)("path",{d:"M17.5 3H6.5L3 21h4l1.2-6h7.6l1.2 6h4L17.5 3zm-2.3 9H8.8L12 5.5 15.2 12z",fill:"currentColor"})),tW=tR((0,n.jsx)("path",{d:"M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5",stroke:"currentColor",strokeWidth:"1.5",strokeLinejoin:"round"})),tE=tR((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("path",{d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92a5.06 5.06 0 01-2.2 3.32v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.1z",fill:"#4285F4"}),(0,n.jsx)("path",{d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z",fill:"#34A853"}),(0,n.jsx)("path",{d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z",fill:"#FBBC05"}),(0,n.jsx)("path",{d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z",fill:"#EA4335"})]})),t$=tR((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"3",fill:"#4D6BFE"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"white",fontSize:"10",fontWeight:"bold",fontFamily:"sans-serif",children:"DS"})]})),tP=tR((0,n.jsx)("path",{d:"M4 4h16v16H4z",fill:"#F55036"}),"0 0 24 24"),tD=tR((0,n.jsx)("path",{d:"M4 4h5v5H4zm5.5 0h5v5h-5zM15 4h5v5h-5zM4 9.5h5v5H4zm5.5 5.5h5v5h-5zM15 9.5h5v5h-5z",fill:"#FA6F00"})),tB=tR((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),"0 0 24 24"),tN=tR((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"3",fill:"#00D4AA"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"white",fontSize:"9",fontWeight:"bold",fontFamily:"sans-serif",children:"MM"})]})),tO=tR((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",fill:"#FF5722"}),"0 0 24 24"),tA=tR((0,n.jsx)("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 5h2v3h-2V7zm0 4h2v2h-2v-2zm3 5H7v-2h7v2z",fill:"#FFD21E"})),tH=tR((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"3",fill:"#E84026"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"white",fontSize:"9",fontWeight:"bold",fontFamily:"sans-serif",children:"CB"})]})),tF=tR((0,n.jsx)("path",{d:"M12 2l9 5v10l-9 5-9-5V7l9-5z",stroke:"currentColor",strokeWidth:"1.5",fill:"none"})),tU=tR((0,n.jsx)("path",{d:"M4 4l8 8 8-8M4 20l8-8 8 8",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})),t_=tR((0,n.jsx)("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 5l4 3-4 3V7z",fill:"#F38020"})),tJ={anthropic:{Icon:tL,hasColor:!1},openai:{Icon:tW,hasColor:!1},"openai-codex":{Icon:tW,hasColor:!1},google:{Icon:tE,hasColor:!0},"google-vertex":{Icon:tE,hasColor:!0},deepseek:{Icon:t$,hasColor:!0},groq:{Icon:tP,hasColor:!1},mistral:{Icon:tD,hasColor:!0},moonshotai:{Icon:tB,hasColor:!1},"moonshotai-cn":{Icon:tB,hasColor:!1},moonshot:{Icon:tB,hasColor:!1},minimax:{Icon:tN,hasColor:!0},"minimax-cn":{Icon:tN,hasColor:!0},fireworks:{Icon:tO,hasColor:!0},huggingface:{Icon:tA,hasColor:!0},cerebras:{Icon:tH,hasColor:!0},openrouter:{Icon:tF,hasColor:!1},xai:{Icon:tU,hasColor:!1},"cloudflare-ai-gateway":{Icon:t_,hasColor:!0},"cloudflare-workers-ai":{Icon:t_,hasColor:!0},"vercel-ai-gateway":{Icon:tR((0,n.jsx)("path",{d:"M12 2L22 20H2L12 2z",fill:"currentColor"})),hasColor:!1},"github-copilot":{Icon:tR((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),"0 0 24 24"),hasColor:!1},"amazon-bedrock":{Icon:tR((0,n.jsx)("path",{d:"M3 15h2l1-3h2l1 3h2V9H9v3L8 9H6l-1 3V9H3v6zm9 0h2v-2h2v-2h-2V9h-2v2h-2v2h2v2z",fill:"#FF9900"})),hasColor:!0},"azure-openai-responses":{Icon:tR((0,n.jsx)("path",{d:"M12 2L3 18h5l4-6 4 6h5L12 2z",fill:"#0078D4"})),hasColor:!0},"kimi-coding":{Icon:tR((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"3",fill:"#6C5CE7"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"white",fontSize:"10",fontWeight:"bold",fontFamily:"sans-serif",children:"Ki"})]})),hasColor:!0},qwen:{Icon:tR((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"3",fill:"#615CED"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"white",fontSize:"9",fontWeight:"bold",fontFamily:"sans-serif",children:"QW"})]})),hasColor:!0},zai:{Icon:tR((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"3",fill:"#3859FF"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"white",fontSize:"9",fontWeight:"bold",fontFamily:"sans-serif",children:"ZP"})]})),hasColor:!0},cohere:{Icon:tR((0,n.jsx)("path",{d:"M4 8h16v2H4zm0 4h12v2H4zm0 4h8v2H4z",fill:"#3059B1"})),hasColor:!0},perplexity:{Icon:tR((0,n.jsx)("path",{d:"M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5",stroke:"#1DB954",strokeWidth:"1.5",fill:"none",strokeLinejoin:"round"})),hasColor:!0},together:{Icon:tR((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",fill:"#0F6CBD"}),"0 0 24 24"),hasColor:!0},grok:{Icon:tR((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),"0 0 24 24"),hasColor:!1}},tV=["openai-completions","openai-responses","anthropic-messages","google-generative-ai"],tK="openai-completions",tY={off:"none",xhigh:"xhigh"};function tq(e){let t=e?.toLowerCase().replace(/\s+/g,"-")??"";return/(^|[^a-z0-9])gpt-5($|[.-])/.test(t)}function tX(e,t=tK){return tq(e.id)||tq(e.name)?{...e,api:e.api??("openai-responses"===t?void 0:"openai-responses"),reasoning:e.reasoning??!0,thinkingLevelMap:e.thinkingLevelMap??tY}:e}function tG({label:e,children:t}){return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("label",{style:{fontSize:11,color:"var(--text-muted)",fontWeight:500},children:e}),t]})}let tZ={padding:"6px 9px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",fontSize:12,outline:"none",width:"100%",boxSizing:"border-box"};function tQ({value:e,onChange:t,placeholder:r,mono:o}){return(0,n.jsx)("input",{value:e,onChange:e=>t(e.target.value),placeholder:r,style:{...tZ,fontFamily:o?"var(--font-mono)":"inherit"}})}function t0({value:e,onChange:t,placeholder:r,mono:i,onKeyDown:l,autoComplete:s="off",spellCheck:a=!1,style:d}){let[c,u]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{e||u(!1)},[e]),(0,n.jsxs)("div",{style:{position:"relative",width:"100%",...d},children:[(0,n.jsx)("input",{type:c?"text":"password",value:e,onChange:e=>t(e.target.value),onKeyDown:l,placeholder:r,style:{...tZ,paddingRight:34,fontFamily:i?"var(--font-mono)":"inherit"},autoComplete:s,spellCheck:a}),(0,n.jsx)("button",{type:"button",onClick:()=>u(e=>!e),"aria-label":c?"Hide API key":"Show API key",title:c?"Hide API key":"Show API key",style:{position:"absolute",right:5,top:"50%",transform:"translateY(-50%)",width:24,height:24,padding:0,border:"none",background:"transparent",color:"var(--text-dim)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},children:c?(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M17.94 17.94A10.94 10.94 0 0 1 12 20C7 20 2.73 16.89 1 12a18.45 18.45 0 0 1 5.06-6.94"}),(0,n.jsx)("path",{d:"M9.9 4.24A10.94 10.94 0 0 1 12 4c5 0 9.27 3.11 11 8a18.5 18.5 0 0 1-2.16 3.19"}),(0,n.jsx)("path",{d:"M14.12 14.12A3 3 0 0 1 9.88 9.88"}),(0,n.jsx)("path",{d:"M1 1l22 22"})]}):(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8S1 12 1 12Z"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})})]})}function t1({value:e,onChange:t,placeholder:r}){return(0,n.jsx)("input",{type:"number",value:e,onChange:e=>t(e.target.value),placeholder:r,style:tZ})}function t2({value:e,onChange:t,options:r,required:o}){return(0,n.jsxs)("select",{value:e,onChange:e=>t(e.target.value),style:{...tZ,color:e?"var(--text)":"var(--text-dim)"},children:[!o&&(0,n.jsx)("option",{value:"",children:"— inherit / none —"}),r.map(e=>(0,n.jsx)("option",{value:e,children:e},e))]})}function t5({label:e,checked:t,onChange:r}){return(0,n.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:6,cursor:"pointer",fontSize:12,color:"var(--text-muted)"},children:[(0,n.jsx)("input",{type:"checkbox",checked:t,onChange:e=>r(e.target.checked),style:{width:13,height:13,accentColor:"var(--accent)",cursor:"pointer"}}),e]})}function t4({children:e}){return(0,n.jsx)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:2},children:e})}function t3({name:e,provider:t,onChange:r,onRename:i,onDelete:l}){let[s,a]=(0,o.useState)(e);(0,o.useEffect)(()=>a(e),[e]);let d=(e,n)=>r({...t,[e]:n});return(0,o.useEffect)(()=>{t.api||r({...t,api:"openai-completions"})},[t.api]),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(t4,{children:"Provider"}),(0,n.jsx)("button",{onClick:l,style:{padding:"3px 8px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:4,color:"#ef4444",cursor:"pointer",fontSize:11},children:"Delete"})]}),(0,n.jsxs)(tG,{label:"Provider name",children:[(0,n.jsx)(tQ,{value:s,onChange:a,placeholder:"provider-name",mono:!0}),s!==e&&s.trim()&&(0,n.jsx)("button",{onClick:()=>i(s.trim()),style:{marginTop:4,padding:"3px 10px",background:"var(--accent)",border:"none",borderRadius:4,color:"#fff",cursor:"pointer",fontSize:11,alignSelf:"flex-start"},children:"Rename"})]}),(0,n.jsx)(tG,{label:"Base URL",children:(0,n.jsx)(tQ,{value:t.baseUrl??"",onChange:e=>d("baseUrl",e||void 0),placeholder:"https://api.example.com/v1",mono:!0})}),(0,n.jsxs)(tG,{label:"API Key",children:[(0,n.jsx)(t0,{value:t.apiKey??"",onChange:e=>d("apiKey",e||void 0),placeholder:"ENV_VAR_NAME, !shell-command, or literal key",mono:!0}),(0,n.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:["Prefix with ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)"},children:"!"})," to run a shell command, or use an env var name"]})]}),(0,n.jsx)(tG,{label:"API",children:(0,n.jsx)(t2,{value:t.api??"openai-completions",onChange:e=>d("api",e),options:tV,required:!0})})]})}let t8=["off","minimal","low","medium","high","xhigh"],t6={off:"var(--text-dim)",minimal:"#6b7280",low:"#60a5fa",medium:"#a78bfa",high:"#f472b6",xhigh:"#fb923c"};function t7({value:e,onChange:t}){let r=e??{},o=(e,n)=>{let o={...r};"omit"===n?delete o[e]:o[e]=n,t(Object.keys(o).length?o:void 0)};return(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:2},children:t8.map(e=>{let t=r[e],i=e in r?null===t?"null":"string":"omit",l="string"==typeof t?t:"",s=t6[e],a={padding:"4px 10px",fontSize:10,border:"none",cursor:"pointer",fontWeight:400,transition:"background 0.1s, color 0.1s",whiteSpace:"nowrap",background:"var(--bg-panel)",color:"var(--text-dim)"},d={background:"var(--accent)",color:"#fff",fontWeight:600};return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"5px 4px",borderRadius:6,background:"transparent",border:"1px solid transparent"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:5,width:68,flexShrink:0},children:[(0,n.jsx)("span",{style:{width:6,height:6,borderRadius:"50%",background:s,flexShrink:0,opacity:"null"===i?.3:1}}),(0,n.jsx)("span",{style:{fontSize:11,fontFamily:"var(--font-mono)",color:"null"===i?"var(--text-dim)":"var(--text-muted)",textDecoration:"null"===i?"line-through":"none"},children:e})]}),(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,border:"1px solid var(--border)",overflow:"hidden",flexShrink:0},children:[(0,n.jsx)("button",{onClick:()=>o(e,"omit"),style:{...a,..."omit"===i?d:{}},children:"Default"}),(0,n.jsx)("button",{onClick:()=>o(e,null),style:{...a,borderLeft:"1px solid var(--border)",..."null"===i?{background:"#ef4444",color:"#fff",fontWeight:600}:{}},children:"Disabled"})]}),(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,border:`1px solid ${"string"===i?"var(--accent)":"var(--border)"}`,overflow:"hidden",transition:"border-color 0.1s"},children:[(0,n.jsx)("button",{onClick:()=>o(e,l||e),style:{...a,..."string"===i?d:{},borderRight:"1px solid var(--border)",flexShrink:0},children:"Custom"}),(0,n.jsx)("input",{value:l,onChange:t=>o(e,t.target.value),onFocus:()=>{"string"!==i&&o(e,l||e)},placeholder:e,maxLength:10,style:{width:"12ch",background:"string"===i?"var(--bg)":"var(--bg-panel)",border:"none",outline:"none",color:"string"===i?"var(--text)":"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11,padding:"4px 7px",transition:"background 0.1s, color 0.1s"}})]})]},e)})})}let t9={thinkingFormat:"deepseek",requiresReasoningContentOnAssistantMessages:!0};function re({providerName:e,provider:t,model:r,onChange:i,onDelete:l}){let[s,a]=(0,o.useState)({phase:"idle"}),d=(e,t)=>i({...r,[e]:t}),c=e=>{i(tX(e,t.api??tK))},u=(()=>{if("idle"===s.phase)return null;if("testing"===s.phase)return"Testing model connection...";let e=[void 0!==s.latencyMs?`${s.latencyMs}ms`:null,void 0!==s.status?`HTTP ${s.status}`:null].filter(Boolean);return"success"===s.phase?["Connected",...e,s.responseText||null].filter(Boolean).join(" \xb7 "):["Failed",...e,s.message].filter(Boolean).join(" \xb7 ")})();(0,o.useEffect)(()=>{a({phase:"idle"})},[e,t.baseUrl,t.api,t.apiKey,r.id,r.api]);let p=(0,o.useCallback)(async()=>{if(r.id.trim()&&"testing"!==s.phase){a({phase:"testing"});try{let n=await fetch("/api/models-config/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerName:e,provider:t,model:r})}),o=await n.json();if(!n.ok||!o.ok)return void a({phase:"error",message:o.error??`HTTP ${n.status}`,latencyMs:o.latencyMs,status:o.status});a({phase:"success",latencyMs:o.latencyMs,status:o.status,responseText:o.responseText})}catch(e){a({phase:"error",message:e instanceof Error?e.message:String(e)})}}},[r,t,e,s.phase]);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(t4,{children:"Model"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[u&&(0,n.jsx)("span",{title:u,style:{maxWidth:260,height:24,padding:"0 8px",border:`1px solid ${"error"===s.phase?"#fecaca":"success"===s.phase?"#bbf7d0":"var(--border)"}`,borderRadius:4,background:"error"===s.phase?"#fee2e2":"success"===s.phase?"#dcfce7":"#e5e7eb",color:"#111827",fontSize:11,display:"inline-flex",alignItems:"center",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",boxSizing:"border-box"},children:u}),(0,n.jsxs)("button",{onClick:p,disabled:!r.id.trim()||"testing"===s.phase,title:"Test model connection",style:{height:24,padding:"0 8px",background:"success"===s.phase?"#16a34a":"none",border:`1px solid ${"success"===s.phase?"#16a34a":"var(--border)"}`,borderRadius:4,color:"success"===s.phase?"#fff":r.id.trim()&&"testing"!==s.phase?"var(--text-muted)":"var(--text-dim)",cursor:r.id.trim()&&"testing"!==s.phase?"pointer":"not-allowed",fontSize:11,display:"inline-flex",alignItems:"center",justifyContent:"center",boxSizing:"border-box",gap:5},children:["success"===s.phase&&(0,n.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}),"testing"===s.phase?"Testing…":"success"===s.phase?"OK":"Test"]}),(0,n.jsx)("button",{onClick:l,style:{height:24,padding:"0 8px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:4,color:"#ef4444",cursor:"pointer",fontSize:11,boxSizing:"border-box"},children:"Remove"})]})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[(0,n.jsx)(tG,{label:"ID *",children:(0,n.jsx)(tQ,{value:r.id,onChange:e=>c({...r,id:e}),placeholder:"model-id",mono:!0})}),(0,n.jsx)(tG,{label:"Name",children:(0,n.jsx)(tQ,{value:r.name??"",onChange:e=>c({...r,name:e||void 0}),placeholder:"Display name"})})]}),(0,n.jsx)(tG,{label:"API override",children:(0,n.jsx)(t2,{value:r.api??"",onChange:e=>d("api",e||void 0),options:tV})}),(0,n.jsxs)("div",{style:{display:"flex",gap:20,flexWrap:"wrap"},children:[(0,n.jsx)(t5,{label:"Reasoning / thinking",checked:r.reasoning??!1,onChange:e=>d("reasoning",e||void 0)}),(0,n.jsx)(t5,{label:"Image input",checked:r.input?.includes("image")??!1,onChange:e=>d("input",e?["text","image"]:void 0)})]}),r.reasoning&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t5,{label:"DeepSeek thinking compat",checked:r.compat?.thinkingFormat==="deepseek",onChange:e=>i(function(e,t){if(t)return{...e,compat:{...e.compat??{},...t9}};if(!e.compat)return e;let r={...e.compat};return delete r.thinkingFormat,delete r.requiresReasoningContentOnAssistantMessages,{...e,compat:Object.keys(r).length?r:void 0}}(r,e))}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:8},children:[(0,n.jsx)(t4,{children:"Thinking level map"}),r.thinkingLevelMap&&(0,n.jsx)("button",{onClick:()=>d("thinkingLevelMap",void 0),style:{fontSize:10,padding:"2px 7px",background:"none",border:"1px solid var(--border)",borderRadius:4,color:"var(--text-dim)",cursor:"pointer"},children:"clear all"})]}),(0,n.jsx)(t7,{value:r.thinkingLevelMap,onChange:e=>d("thinkingLevelMap",e)})]})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[(0,n.jsx)(tG,{label:"Context window (tokens)",children:(0,n.jsx)(t1,{value:void 0!==r.contextWindow?String(r.contextWindow):"",onChange:e=>d("contextWindow",e?parseInt(e):void 0),placeholder:"128000"})}),(0,n.jsx)(tG,{label:"Max output tokens",children:(0,n.jsx)(t1,{value:void 0!==r.maxTokens?String(r.maxTokens):"",onChange:e=>d("maxTokens",e?parseInt(e):void 0),placeholder:"16384"})})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)(t4,{children:"Cost (per million tokens)"}),(0,n.jsx)("div",{style:{marginTop:8,display:"grid",gridTemplateColumns:"1fr 1fr 1fr 1fr",gap:8},children:["input","output","cacheRead","cacheWrite"].map(e=>(0,n.jsx)(tG,{label:e,children:(0,n.jsx)(t1,{value:r.cost?.[e]!==void 0?String(r.cost[e]):"",onChange:t=>{let n;return n=parseFloat(t),void i({...r,cost:{...r.cost??{},[e]:isNaN(n)?void 0:n}})},placeholder:"0"})},e))})]})]})}function rt({provider:e,onRefresh:t}){let[r,i]=(0,o.useState)({phase:"idle"}),[l,s]=(0,o.useState)(""),a=(0,o.useRef)(null),d=(0,o.useRef)(null);(0,o.useEffect)(()=>{("auth"===r.phase||"prompt"===r.phase)&&setTimeout(()=>d.current?.focus(),50)},[r.phase]),(0,o.useEffect)(()=>{i({phase:"idle"}),s(""),a.current?.close(),a.current=null},[e.id]),(0,o.useEffect)(()=>()=>{a.current?.close()},[]);let c=(0,o.useCallback)(()=>{a.current?.close(),i({phase:"connecting"}),s("");let r=new EventSource(`/api/auth/login/${encodeURIComponent(e.id)}`);a.current=r,r.onmessage=e=>{let n=JSON.parse(e.data);"auth"===n.type?(i({phase:"auth",url:n.url,instructions:n.instructions??null,token:n.token}),window.open(n.url,"_blank","noopener,noreferrer")):"device_code"===n.type?(i({phase:"device_code",userCode:n.userCode,verificationUri:n.verificationUri,intervalSeconds:n.intervalSeconds??null,expiresInSeconds:n.expiresInSeconds??null}),window.open(n.verificationUri,"_blank","noopener,noreferrer")):"prompt_request"===n.type?i({phase:"prompt",message:n.message,placeholder:n.placeholder??null,token:n.token}):"select_request"===n.type?i({phase:"select",message:n.message,options:n.options??[],token:n.token}):"progress"===n.type?i({phase:"progress",message:n.message}):"success"===n.type?(r.close(),i({phase:"success"}),t()):"error"===n.type?(r.close(),i({phase:"error",message:n.message})):"cancelled"===n.type&&(r.close(),i({phase:"idle"}))},r.onerror=()=>{r.close(),i(e=>"success"===e.phase?e:{phase:"error",message:"Connection lost"})}},[e.id,t]),u=(0,o.useCallback)(async()=>{await fetch(`/api/auth/logout/${encodeURIComponent(e.id)}`,{method:"POST"}),i({phase:"idle"}),t()},[e.id,t]),p=(0,o.useCallback)(async(t,r)=>{if(r.trim()){i({phase:"progress",message:"Verifying…"});try{let n=await fetch(`/api/auth/login/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:t,code:r.trim()})});if(!n.ok){let e=await n.json().catch(()=>({}));i({phase:"error",message:e.error??`Server error ${n.status}`});return}s("")}catch(e){i({phase:"error",message:e instanceof Error?e.message:"Network error"})}}},[e.id]),h=(0,o.useCallback)(async(t,r)=>{i({phase:"progress",message:"Continuing…"});try{let n=await fetch(`/api/auth/login/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:t,code:r})});if(!n.ok){let e=await n.json().catch(()=>({}));i({phase:"error",message:e.error??`Server error ${n.status}`})}}catch(e){i({phase:"error",message:e instanceof Error?e.message:"Network error"})}},[e.id]),x="connecting"===r.phase||"progress"===r.phase||"auth"===r.phase||"device_code"===r.phase||"prompt"===r.phase||"select"===r.phase;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(t4,{children:"Subscription"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:e.loggedIn?"#4ade80":"var(--border)",display:"inline-block"}}),(0,n.jsx)("span",{style:{fontSize:11,color:e.loggedIn?"#4ade80":"var(--text-dim)"},children:e.loggedIn?"connected":"not connected"})]})]}),(0,n.jsxs)("div",{style:{minHeight:48},children:["idle"===r.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:e.loggedIn?"Already connected. You can re-login or disconnect.":`Connect your ${e.name} account.`}),"connecting"===r.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)"},children:"Opening browser…"}),"select"===r.phase&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:r.message}),(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:r.options.map(e=>(0,n.jsx)("button",{onClick:()=>h(r.token,e.id),style:{padding:"6px 9px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",cursor:"pointer",fontSize:12,textAlign:"left"},children:e.label},e.id))})]}),("auth"===r.phase||"prompt"===r.phase)&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:"auth"===r.phase?"Complete sign-in in the browser, then copy the redirect URL from the address bar and paste it below.":r.message}),"auth"===r.phase&&(0,n.jsxs)("p",{style:{margin:0,fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:["If the browser window did not open,"," ",(0,n.jsx)("a",{href:r.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)",wordBreak:"break-all"},children:"click here to open the login page"}),"."]}),(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsx)("input",{ref:d,value:l,onChange:e=>s(e.target.value),onKeyDown:e=>{"Enter"===e.key&&p(r.token,l)},placeholder:"auth"===r.phase?"http://localhost:1455/auth/callback?code=…":r.placeholder??"Enter value…",style:{flex:1,padding:"6px 9px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",fontSize:12,outline:"none",fontFamily:"var(--font-mono)",boxSizing:"border-box"}}),(0,n.jsx)("button",{onClick:()=>p(r.token,l),disabled:!l.trim(),style:{padding:"6px 12px",background:l.trim()?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:5,color:l.trim()?"#fff":"var(--text-dim)",cursor:l.trim()?"pointer":"not-allowed",fontSize:12,fontWeight:600,flexShrink:0},children:"Submit"})]})]}),"device_code"===r.phase&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:"Open the verification page and enter this code:"}),(0,n.jsx)("div",{style:{padding:"8px 10px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",fontSize:16,fontWeight:700,fontFamily:"var(--font-mono)",letterSpacing:0},children:r.userCode}),(0,n.jsxs)("p",{style:{margin:0,fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:[(0,n.jsx)("a",{href:r.verificationUri,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)",wordBreak:"break-all"},children:r.verificationUri}),r.expiresInSeconds?` Expires in ${Math.ceil(r.expiresInSeconds/60)} minutes.`:""]})]}),"progress"===r.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)"},children:r.message}),"success"===r.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"#4ade80"},children:"Connected successfully."}),"error"===r.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"#f87171"},children:r.message})]}),(0,n.jsx)("div",{style:{display:"flex",gap:8},children:x?(0,n.jsx)("button",{onClick:()=>{a.current?.close(),i({phase:"idle"})},style:{padding:"5px 12px",background:"none",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Cancel"}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:c,style:{padding:"5px 14px",background:"var(--accent)",border:"none",borderRadius:5,color:"#fff",cursor:"pointer",fontSize:12,fontWeight:600},children:e.loggedIn?"Re-login":"Login"}),e.loggedIn&&(0,n.jsx)("button",{onClick:u,style:{padding:"5px 12px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:5,color:"#ef4444",cursor:"pointer",fontSize:12},children:"Disconnect"})]})})]})}function rr({provider:e,onRefresh:t}){let[r,i]=(0,o.useState)(""),[l,s]=(0,o.useState)(!1),[a,d]=(0,o.useState)(!1),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(!1);(0,o.useEffect)(()=>{i(""),u(null),h(!1)},[e.id]);let x=(0,o.useCallback)(async()=>{if(r.trim()){s(!0),u(null),h(!1);try{let n=await fetch(`/api/auth/api-key/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:r.trim()})}),o=await n.json();!n.ok||o.error?u(o.error??`HTTP ${n.status}`):(i(""),h(!0),setTimeout(()=>h(!1),2e3),t())}catch(e){u(String(e))}finally{s(!1)}}},[r,e.id,t]),g=(0,o.useCallback)(async()=>{d(!0),u(null);try{let r=await fetch(`/api/auth/api-key/${encodeURIComponent(e.id)}`,{method:"DELETE"}),n=await r.json();!r.ok||n.error?u(n.error??`HTTP ${r.status}`):t()}catch(e){u(String(e))}finally{d(!1)}},[e.id,t]);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(t4,{children:"API Key"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:e.configured?"#4ade80":"var(--border)",display:"inline-block"}}),(0,n.jsx)("span",{style:{fontSize:11,color:e.configured?"#4ade80":"var(--text-dim)"},children:e.configured?"configured":"not configured"})]})]}),(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:e.configured?"API key is stored. Enter a new key below to replace it, or disconnect to remove it.":`Enter your ${e.displayName} API key to enable ${e.modelCount} model${1!==e.modelCount?"s":""}.`}),(0,n.jsx)(tG,{label:"API Key",children:(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsx)(t0,{value:r,onChange:i,onKeyDown:e=>{"Enter"===e.key&&r.trim()&&x()},placeholder:e.configured?"Enter new key to replace…":"sk-…",style:{flex:1},autoComplete:"off",spellCheck:!1,mono:!0}),(0,n.jsxs)("button",{onClick:x,disabled:l||!r.trim()||p,style:{padding:"6px 12px",background:p?"#16a34a":r.trim()?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:5,color:r.trim()||p?"#fff":"var(--text-dim)",cursor:l||!r.trim()||p?"not-allowed":"pointer",fontSize:12,fontWeight:600,flexShrink:0,display:"flex",alignItems:"center",gap:5},children:[p&&(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}),p?"Saved":l?"Saving…":"Save"]})]})}),c&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"#f87171"},children:c}),e.configured&&(0,n.jsx)("button",{onClick:g,disabled:a,style:{alignSelf:"flex-start",padding:"5px 12px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:5,color:"#ef4444",cursor:a?"not-allowed":"pointer",fontSize:12},children:a?"Removing…":"Disconnect"})]})}function rn({id:e,size:t}){let r=tJ[e];return r?r.hasColor?(0,n.jsx)(r.Icon,{size:t}):(0,n.jsx)(r.Icon,{size:t,style:{color:"var(--text-muted)"}}):null}function ro({oauthProviders:e,apiKeyProviders:t,onSelectOAuth:r,onSelectApiKey:i,onAddCustom:l,onDiscover:s,onClose:a}){let[d,c]=(0,o.useState)(""),u=(0,o.useRef)(null);(0,o.useEffect)(()=>{setTimeout(()=>u.current?.focus(),30)},[]);let p=d.trim().toLowerCase(),h=e.filter(e=>!e.loggedIn&&(!p||e.name.toLowerCase().includes(p))),x=t.filter(e=>!e.configured&&(!p||e.displayName.toLowerCase().includes(p)||e.id.toLowerCase().includes(p))),g=!p||"custom".includes(p)||"openai-compatible".includes(p)||"anthropic-compatible".includes(p),f=!p||"discover".includes(p)||"base url".includes(p)||"model import".includes(p),v=h.length+x.length+ +!!g+ +!!f,m={display:"flex",flexDirection:"row",alignItems:"center",gap:8,padding:"10px 12px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:7,boxSizing:"border-box",cursor:"pointer",minWidth:0,textAlign:"left",transition:"border-color 0.12s, background 0.12s",width:"100%"};return(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1100,background:"rgba(0,0,0,0.4)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:e=>{e.target===e.currentTarget&&a()},children:(0,n.jsxs)("div",{style:{width:820,maxWidth:"calc(100vw - 32px)",maxHeight:"min(72vh, calc(100vh - 32px))",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.22)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:"10px 14px",borderBottom:"1px solid var(--border)",flexShrink:0,display:"flex",alignItems:"center",gap:8},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:{color:"var(--text-dim)",flexShrink:0},children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,n.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),(0,n.jsx)("input",{ref:u,value:d,onChange:e=>c(e.target.value),onKeyDown:e=>{"Escape"===e.key&&a()},placeholder:"Search providers…",style:{flex:1,background:"none",border:"none",outline:"none",color:"var(--text)",fontSize:13,boxSizing:"border-box"}})]}),(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",padding:14},children:0===v?(0,n.jsx)("div",{style:{padding:"20px 0",fontSize:12,color:"var(--text-dim)",textAlign:"center"},children:"No providers match"}):(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(min(240px, 100%), 1fr))",gap:8},children:[g&&(0,n.jsx)("div",{style:{gridColumn:"1 / -1",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Custom"}),g&&(0,n.jsxs)("button",{onClick:()=>{l(),a()},style:m,onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.background="var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"OpenAI / Anthropic compatible"}),(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:"Custom endpoint format"})]}),(0,n.jsx)("span",{style:{width:26,height:26,borderRadius:5,background:"var(--bg-hover)",border:"1px dashed var(--border)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},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:{color:"var(--text-dim)"},children:[(0,n.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,n.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})})]}),f&&(0,n.jsxs)("button",{onClick:()=>{s(),a()},style:m,onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.background="var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"Discover models from Base URL"}),(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:"OpenAI-compatible / Ollama catalog"})]}),(0,n.jsx)("span",{style:{width:26,height:26,borderRadius:5,background:"var(--bg-hover)",border:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},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:{color:"var(--text-muted)"},children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,n.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})})]}),h.length>0&&(0,n.jsx)("div",{style:{gridColumn:"1 / -1",paddingTop:6*!!g,fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Subscriptions"}),h.map(e=>(0,n.jsxs)("button",{onClick:()=>{r(e.id),a()},style:m,onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.background="var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:"OAuth"})]}),(0,n.jsx)(rn,{id:e.id,size:28})]},e.id)),x.length>0&&(0,n.jsx)("div",{style:{gridColumn:"1 / -1",paddingTop:6*(h.length>0),fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"API Key"}),x.map(e=>(0,n.jsxs)("button",{onClick:()=>{i(e.id),a()},style:m,onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.background="var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.displayName}),(0,n.jsxs)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:[e.modelCount," models"]})]}),(0,n.jsx)(rn,{id:e.id,size:28})]},e.id))]})})]})})}function ri({existingProviders:e,onImport:t,onClose:r}){let[i,l]=(0,o.useState)(""),[s,a]=(0,o.useState)(""),[d,c]=(0,o.useState)("custom-provider"),[u,p]=(0,o.useState)(new Set),[h,x]=(0,o.useState)({phase:"idle"}),g=(0,o.useCallback)(async()=>{let e=i.trim();if(e&&"loading"!==h.phase){x({phase:"loading"});try{let t=await fetch("/api/models-config/discover",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:e,apiKey:s,provider:d,enrich:!1})}),r=await t.json();if(!t.ok||!r.ok||!r.models||!r.piModels||!r.endpoint)return void x({phase:"error",message:r.error??`HTTP ${t.status}`});x({phase:"success",endpoint:r.endpoint,models:r.models,piModels:r.piModels}),p(new Set(r.piModels.map(e=>e.id)))}catch(e){x({phase:"error",message:e instanceof Error?e.message:String(e)})}}},[s,i,d,h.phase]),f="success"===h.phase?h:null,v=u.size,m=!!(f&&d.trim()&&v>0);return(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1100,background:"rgba(0,0,0,0.4)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:e=>{e.target===e.currentTarget&&r()},children:(0,n.jsxs)("div",{style:{width:880,maxWidth:"calc(100vw - 32px)",height:"min(78vh, calc(100vh - 32px))",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.22)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:"12px 16px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)"},children:"Discover models"}),(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",marginTop:2},children:"Fetch model catalog from a Base URL and import selected models."})]}),(0,n.jsx)("button",{onClick:r,style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),(0,n.jsxs)("div",{style:{padding:16,borderBottom:"1px solid var(--border)",display:"grid",gridTemplateColumns:"1.4fr 1fr 0.9fr auto",gap:10,alignItems:"end",flexShrink:0},children:[(0,n.jsx)(tG,{label:"Base URL",children:(0,n.jsx)(tQ,{value:i,onChange:l,placeholder:"https://api.example.com",mono:!0})}),(0,n.jsx)(tG,{label:"API Key",children:(0,n.jsx)(t0,{value:s,onChange:a,placeholder:"optional for local providers",mono:!0})}),(0,n.jsx)(tG,{label:"Provider name",children:(0,n.jsx)(tQ,{value:d,onChange:c,placeholder:"provider-name",mono:!0})}),(0,n.jsx)("button",{onClick:g,disabled:!i.trim()||"loading"===h.phase,style:{height:31,padding:"0 14px",background:i.trim()&&"loading"!==h.phase?"var(--accent)":"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:5,color:i.trim()&&"loading"!==h.phase?"#fff":"var(--text-dim)",cursor:i.trim()&&"loading"!==h.phase?"pointer":"not-allowed",fontSize:12,fontWeight:600,whiteSpace:"nowrap"},children:"loading"===h.phase?"Fetching...":"Fetch models"})]}),(0,n.jsxs)("div",{style:{flex:1,overflow:"hidden",display:"flex",flexDirection:"column"},children:["idle"===h.phase&&(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:"Enter a Base URL to discover available models."}),"loading"===h.phase&&(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:"Fetching model catalog..."}),"error"===h.phase&&(0,n.jsx)("div",{style:{padding:18,color:"#f87171",fontSize:12,lineHeight:1.6},children:h.message}),f&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"8px 16px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-dim)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[f.piModels.length," models from ",f.endpoint]}),(0,n.jsx)("button",{onClick:()=>{if(f){if(u.size===f.piModels.length)return void p(new Set);p(new Set(f.piModels.map(e=>e.id)))}},style:{padding:"2px 8px",fontSize:11,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-muted)",cursor:"pointer"},children:u.size===f.piModels.length?"Clear":"Select all"})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"auto"},children:f.piModels.map((e,t)=>{let r=f.models[t],o=u.has(e.id);return(0,n.jsxs)("label",{style:{display:"grid",gridTemplateColumns:"24px minmax(0, 1fr) 90px 90px 90px 70px",gap:10,alignItems:"center",padding:"8px 16px",borderBottom:"1px solid rgba(127,127,127,0.12)",background:o?"var(--bg-subtle)":"transparent",cursor:"pointer"},children:[(0,n.jsx)("input",{type:"checkbox",checked:o,onChange:()=>{var t;return t=e.id,void p(e=>{let r=new Set(e);return r.has(t)?r.delete(t):r.add(t),r})},style:{width:14,height:14,accentColor:"var(--accent)"}}),(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontFamily:"var(--font-mono)",fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.id}),(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r?.ownedBy??"unknown"})]}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:e.contextWindow}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:e.maxTokens}),(0,n.jsx)("span",{style:{fontSize:10,color:e.reasoning?"var(--accent)":"var(--text-dim)"},children:e.reasoning?"reasoning":""}),(0,n.jsx)("span",{style:{fontSize:10,color:e.input?.includes("image")?"var(--accent)":"var(--text-dim)"},children:e.input?.includes("image")?"image":""})]},e.id)})})]})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:10,padding:"10px 16px",borderTop:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:[v," selected"]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,n.jsx)("button",{onClick:r,style:{padding:"6px 14px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:13},children:"Cancel"}),(0,n.jsx)("button",{onClick:()=>{if(!f||!m)return;let n=i.trim().replace(/\/+$/,""),o=s.trim(),l=Object.entries(e).find(([,e])=>(e.baseUrl??"").replace(/\/+$/,"")===n&&(e.apiKey??"")===o),a=l?.[0]??d.trim(),c=e[a],p=new Map((c?.models??[]).map(e=>[e.id,e])),h=c?.api??tK,x=0;for(let e of f.piModels)u.has(e.id)&&!p.has(e.id)&&(p.set(e.id,tX(e,h)),x+=1);t(a,{...c??{},baseUrl:n,api:h,...o?{apiKey:o}:{},models:Array.from(p.values())},x),r()},disabled:!m,style:{padding:"6px 16px",background:m?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:6,color:m?"#fff":"var(--text-dim)",cursor:m?"pointer":"not-allowed",fontSize:13,fontWeight:600},children:"Import selected"})]})]})]})})}function rl({onClose:e,embedded:t=!1}){let[r,i]=(0,o.useState)({providers:{}}),[l,s]=(0,o.useState)(!0),[a,d]=(0,o.useState)(!1),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(null),[x,g]=(0,o.useState)(!1),[f,v]=(0,o.useState)(null),[m,y]=(0,o.useState)([]),[b,j]=(0,o.useState)([]),[k,w]=(0,o.useState)(!1),[S,C]=(0,o.useState)(!1),T=(0,o.useCallback)(()=>{fetch("/api/auth/providers").then(e=>e.json()).then(e=>y(e.providers)).catch(()=>{})},[]),z=(0,o.useCallback)(()=>{fetch("/api/auth/all-providers").then(e=>e.json()).then(e=>j(e.providers)).catch(()=>{})},[]);(0,o.useEffect)(()=>{fetch("/api/models-config").then(e=>e.json()).then(e=>{let t=e.providers?e:{...e,providers:{}};i(t);let r=Object.keys(t.providers??{});r.length>0&&v({type:"provider",name:r[0]})}).catch(()=>i({providers:{}})).finally(()=>s(!1)),T(),z()},[T,z]);let I=(0,o.useCallback)(()=>{let e="new-provider",t=1;for(;r.providers?.[e];)e=`new-provider-${t++}`;i(t=>({...t,providers:{...t.providers??{},[e]:{api:"openai-completions"}}})),v({type:"provider",name:e})},[r.providers]),M=(0,o.useCallback)((e,t)=>{i(r=>({...r,providers:{...r.providers??{},[e]:t}}))},[]),R=(0,o.useCallback)((e,t)=>{i(r=>{let n=Object.entries(r.providers??{}),o=n.findIndex(([t])=>t===e);return -1===o?r:(n[o]=[t,n[o][1]],{...r,providers:Object.fromEntries(n)})}),v(r=>r?"provider"===r.type&&r.name===e?{type:"provider",name:t}:"model"===r.type&&r.providerName===e?{...r,providerName:t}:r:r)},[]),L=(0,o.useCallback)(e=>{i(t=>{let r={...t.providers??{}};return delete r[e],{...t,providers:r}}),i(e=>{let t=Object.keys(e.providers??{});return v(t.length>0?{type:"provider",name:t[0]}:null),e})},[]),W=(0,o.useCallback)(e=>{i(t=>{let r=t.providers?.[e]??{},n=[...r.models??[],{id:""}];return{...t,providers:{...t.providers??{},[e]:{...r,models:n}}}}),i(t=>{let r=(t.providers?.[e]?.models?.length??1)-1;return v({type:"model",providerName:e,index:r}),t})},[]),E=(0,o.useCallback)((e,t,r)=>{i(n=>{let o=n.providers?.[e]??{},i=[...o.models??[]];return i[t]=r,{...n,providers:{...n.providers??{},[e]:{...o,models:i}}}})},[]),$=(0,o.useCallback)((e,t)=>{i(r=>{let n=r.providers?.[e]??{},o=[...n.models??[]];return o.splice(t,1),{...r,providers:{...r.providers??{},[e]:{...n,models:o.length?o:void 0}}}}),v({type:"provider",name:e})},[]),P=(0,o.useCallback)((e,t,r)=>{i(r=>({...r,providers:{...r.providers??{},[e]:t}})),v({type:"provider",name:e}),g(!1),u(null),h(`${r} model${1===r?"":"s"} imported. Click Save to write models.json.`)},[]),D=(0,o.useCallback)(async()=>{d(!0),u(null),h(null),g(!1);try{let e=await fetch("/api/models-config",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)}),t=await e.json();!e.ok||t.error?u(t.error??`HTTP ${e.status}`):(g(!0),setTimeout(()=>g(!1),2e3))}catch(e){u(String(e))}finally{d(!1)}},[r]),B=Object.entries(r.providers??{}),N=m.filter(e=>e.loggedIn),O=b.filter(e=>e.configured),A=(()=>{if(!f)return null;if("oauth"===f.type){let e=m.find(e=>e.id===f.providerId);return e?(0,n.jsx)(rt,{provider:e,onRefresh:T},e.id):null}if("apikey"===f.type){let e=b.find(e=>e.id===f.providerId);return e?(0,n.jsx)(rr,{provider:e,onRefresh:z},e.id):null}if("provider"===f.type){let e=r.providers?.[f.name];return e?(0,n.jsx)(t3,{name:f.name,provider:e,onChange:e=>M(f.name,e),onRename:e=>R(f.name,e),onDelete:()=>L(f.name)},f.name):null}let e=r.providers?.[f.providerName],t=e?.models?.[f.index];return t?(0,n.jsx)(re,{providerName:f.providerName,provider:e,model:t,onChange:e=>E(f.providerName,f.index,e),onDelete:()=>$(f.providerName,f.index)},`${f.providerName}-${f.index}`):null})();return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:t?{height:"100%",minHeight:0,display:"flex",alignItems:"stretch",justifyContent:"stretch"}:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:r=>{t||r.target!==r.currentTarget||e()},children:(0,n.jsxs)("div",{style:{width:t?"100%":860,height:t?"100%":"78vh",background:"var(--bg)",border:t?"none":"1px solid var(--border)",borderRadius:10*!t,display:"flex",flexDirection:"column",boxShadow:t?"none":"0 8px 32px rgba(0,0,0,0.18)",overflow:"hidden"},children:[!t&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 18px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10},children:[(0,n.jsx)("span",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:"Models"}),(0,n.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:"~/.pi/agent/models.json"})]}),(0,n.jsx)("button",{onClick:e,style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),(0,n.jsxs)("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{width:210,borderRight:"1px solid var(--border)",display:"flex",flexDirection:"column",flexShrink:0,background:"var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,overflowY:"auto",padding:"8px 6px"},children:[N.map(e=>{let t=f?.type==="oauth"&&f.providerId===e.id;return(0,n.jsxs)("div",{onClick:()=>v({type:"oauth",providerId:e.id}),style:{display:"flex",alignItems:"center",gap:7,padding:"5px 8px",borderRadius:5,cursor:"pointer",background:t?"var(--bg-selected)":"none"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,n.jsx)(rn,{id:e.id,size:16}),(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name})]},e.id)}),O.map(e=>{let t=f?.type==="apikey"&&f.providerId===e.id;return(0,n.jsxs)("div",{onClick:()=>v({type:"apikey",providerId:e.id}),style:{display:"flex",alignItems:"center",gap:7,padding:"5px 8px",borderRadius:5,cursor:"pointer",background:t?"var(--bg-selected)":"none"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,n.jsx)(rn,{id:e.id,size:16}),(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.displayName})]},e.id)}),(N.length>0||O.length>0)&&B.length>0&&(0,n.jsx)("div",{style:{margin:"4px 8px",borderTop:"1px solid var(--border)"}}),l?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:"Loading…"}):B.map(([e,t])=>{let r=f?.type==="provider"&&f.name===e,o=t.models??[];return(0,n.jsxs)("div",{style:{marginBottom:2},children:[(0,n.jsxs)("div",{onClick:()=>v({type:"provider",name:e}),style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,cursor:"pointer",background:r?"var(--bg-selected)":"none"},onMouseEnter:e=>{r||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{r||(e.currentTarget.style.background="none")},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:{color:"var(--text-dim)",flexShrink:0},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:{fontSize:12,fontWeight:r?600:400,color:"var(--text)",fontFamily:"var(--font-mono)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e})]}),o.map((t,r)=>{let o=f?.type==="model"&&f.providerName===e&&f.index===r;return(0,n.jsxs)("div",{onClick:()=>v({type:"model",providerName:e,index:r}),style:{display:"flex",alignItems:"center",gap:6,padding:"5px 8px 5px 26px",borderRadius:5,cursor:"pointer",background:o?"var(--bg-selected)":"none"},onMouseEnter:e=>{o||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{o||(e.currentTarget.style.background="none")},children:[(0,n.jsx)("span",{style:{fontSize:11,fontFamily:"var(--font-mono)",color:t.id?"var(--text-muted)":"var(--text-dim)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.id||"new model"}),t.reasoning&&(0,n.jsx)("span",{style:{fontSize:9,padding:"1px 4px",background:"rgba(99,102,241,0.12)",color:"rgba(99,102,241,0.8)",borderRadius:3,flexShrink:0},children:"T"})]},r)}),(0,n.jsx)("div",{onClick:t=>{t.stopPropagation(),W(e)},style:{display:"flex",alignItems:"center",gap:4,padding:"4px 8px 4px 26px",borderRadius:5,cursor:"pointer",color:"var(--text-dim)"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)",e.currentTarget.style.background="none"},children:(0,n.jsx)("span",{style:{fontSize:11},children:"+ model"})})]},e)})]}),(0,n.jsx)("div",{style:{borderTop:"1px solid var(--border)",padding:"8px 6px"},children:(0,n.jsx)("button",{onClick:()=>w(!0),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,width:"100%",padding:"6px 0",background:"none",border:"1px dashed var(--border)",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",fontSize:12},onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.color="var(--text-muted)"},children:"+ Add provider"})})]}),(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:l?null:A??(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:"Select a provider or model"})})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:10,padding:"10px 18px",borderTop:"1px solid var(--border)",flexShrink:0},children:[c?(0,n.jsx)("span",{style:{fontSize:12,color:"#f87171",flex:1},children:c}):p?(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",flex:1},children:p}):null,(0,n.jsx)("button",{onClick:e,style:{padding:"6px 14px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:13},children:"Cancel"}),(0,n.jsxs)("button",{onClick:D,disabled:a||x,style:{position:"relative",padding:"6px 16px",minWidth:92,background:x?"#16a34a":a?"var(--bg-panel)":"var(--accent)",border:"none",borderRadius:6,color:x?"#fff":a?"var(--text-muted)":"#fff",cursor:a||x?"default":"pointer",fontSize:13,fontWeight:600,display:"inline-flex",alignItems:"center",justifyContent:"center",gap:6,transition:"background-color 0.2s ease, color 0.2s ease",animation:x?"saved-pop 0.45s ease":void 0},children:[x&&(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",style:{strokeDasharray:18,animation:"saved-check-draw 0.35s ease forwards",flexShrink:0},children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}),(0,n.jsx)("span",{children:x?"Saved":a?"Saving…":"Save"})]})]})]})}),k&&(0,n.jsx)(ro,{oauthProviders:m,apiKeyProviders:b,onSelectOAuth:e=>v({type:"oauth",providerId:e}),onSelectApiKey:e=>v({type:"apikey",providerId:e}),onAddCustom:I,onDiscover:()=>C(!0),onClose:()=>w(!1)}),S&&(0,n.jsx)(ri,{existingProviders:r.providers??{},onImport:P,onClose:()=>C(!1)})]})}function rs(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function ra(e){let t=e.sourceInfo?.source,r=e.sourceInfo?.scope;return"user"===r||"user"===t?"global":"project"===r||"project"===t?"project":"path"}function rd({enabled:e,loading:t,onToggle:r}){return(0,n.jsx)("button",{onClick:r,disabled:t,title:e?"Visible in model prompt — click to disable":"Hidden from model prompt — click to enable",style:{flexShrink:0,width:40,height:22,borderRadius:11,border:"none",padding:0,cursor:t?"wait":"pointer",background:e?"var(--accent)":"var(--border)",position:"relative",transition:"background 0.18s",outline:"none"},children:(0,n.jsx)("span",{style:{position:"absolute",top:3,left:e?21:3,width:16,height:16,borderRadius:"50%",background:"var(--bg)",boxShadow:"0 1px 4px rgba(0,0,0,0.22)",transition:"left 0.18s cubic-bezier(.4,0,.2,1)"}})})}function rc({skill:e,cwd:t,onToggle:r,toggling:o,saveError:i}){let l=ra(e),s=!e.disableModelInvocation;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:20},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:7},children:[(0,n.jsx)("span",{style:{fontSize:10,padding:"1px 5px",borderRadius:3,flexShrink:0,background:"project"===l?"rgba(99,102,241,0.12)":"rgba(120,120,120,0.12)",color:"project"===l?"rgba(99,102,241,0.8)":"var(--text-dim)"},children:l}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:function(e){if("project"===l&&e.startsWith(t)){let r=e.slice(t.length).replace(/^[/\\]/,"");return`./${r}`}return rs(e)}(e.filePath)}),(0,n.jsx)(rd,{enabled:s,loading:o,onToggle:()=>r(e)}),i&&(0,n.jsx)("span",{style:{fontSize:12,color:"#f87171",flexShrink:0},children:i})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:"Name"}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:14,color:"var(--text)"},children:e.name})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:"Description"}),(0,n.jsx)("span",{style:{fontSize:14,color:"var(--text-muted)",lineHeight:1.6},children:e.description})]})]})}function ru({cwd:e,onInstalled:t}){let[r,i]=(0,o.useState)(""),[l,s]=(0,o.useState)([]),[a,d]=(0,o.useState)(!1),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(null),[x,g]=(0,o.useState)(null),[f,v]=(0,o.useState)(null),[m,y]=(0,o.useState)([]),[b,j]=(0,o.useState)(new Set),[k,w]=(0,o.useState)("global"),S=(0,o.useRef)(null),C=(0,o.useRef)(null);(0,o.useEffect)(()=>{S.current?.focus()},[]),(0,o.useEffect)(()=>()=>{C.current?.abort()},[]);let T=(0,o.useCallback)(async e=>{if(e.trim()){d(!0),u(null),s([]);try{let t=await fetch("/api/skills/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:e.trim()})}),r=await t.json();if(r.error)return void u(r.error);s(r.results??[]),0===(r.results??[]).length&&u("No skills found")}catch(e){u(String(e))}finally{d(!1)}}},[]),z=(0,o.useCallback)(async r=>{let n=new AbortController;C.current=n,h(r),g(null),v("Starting installer"),y(["Starting installer"]);try{let o=await fetch("/api/skills/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({package:r,scope:k,cwd:e,stream:!0}),signal:n.signal});if(!o.ok||!o.body){let e=await o.json().catch(()=>null);g(e?.error??`HTTP ${o.status}`);return}let i=o.body.getReader(),l=new TextDecoder,s="",a=!1,d=e=>{"progress"===e.type?(e.stage&&v(e.stage),e.line&&y(t=>(t.at(-1)===e.line?t:[...t,e.line]).slice(-8))):"done"===e.type&&e.success?(a=!0,v("Installed"),y(e=>[...e,"Installed"].slice(-8))):"error"===e.type&&g(e.error??"Install failed")};for(;;){let{value:e,done:t}=await i.read(),r=(s+=l.decode(e??new Uint8Array,{stream:!t})).split("\n");for(let e of(s=r.pop()??"",r))e.trim()&&d(JSON.parse(e));if(t)break}s.trim()&&d(JSON.parse(s)),a&&(j(e=>new Set(e).add(r)),t())}catch(e){n.signal.aborted?(v("Canceled"),y(e=>[...e,"Canceled"].slice(-8))):g(String(e))}finally{C.current===n&&(C.current=null),h(null)}},[t,k,e]),I=(0,o.useCallback)(()=>{C.current?.abort()},[]),M="global"===k?"~/.pi/agent/skills/":`${rs(e)}/.pi/agent/skills/`;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,marginBottom:20},children:[(0,n.jsx)("div",{style:{fontSize:14,fontWeight:600,color:"var(--text)"},children:"Add Skill"}),(0,n.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,n.jsx)("input",{ref:S,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{"Enter"===e.key&&T(r)},placeholder:"e.g. react, testing, deploy",style:{flex:1,padding:"7px 10px",fontSize:13,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",outline:"none"}}),(0,n.jsx)("button",{onClick:()=>T(r),disabled:a||!r.trim(),style:{padding:"7px 16px",fontSize:13,borderRadius:6,border:"none",background:"var(--accent)",color:"#fff",cursor:a||!r.trim()?"not-allowed":"pointer",opacity:a||!r.trim()?.5:1,flexShrink:0},children:a?"Searching…":"Search"})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10},children:[(0,n.jsx)("div",{style:{display:"flex",borderRadius:5,border:"1px solid var(--border)",overflow:"hidden",fontSize:12,flexShrink:0},children:["global","project"].map(e=>(0,n.jsx)("button",{onClick:()=>w(e),style:{padding:"3px 10px",border:"none",cursor:"pointer",background:k===e?"var(--bg-selected)":"none",color:k===e?"var(--text)":"var(--text-dim)",fontWeight:k===e?600:400,borderRight:"global"===e?"1px solid var(--border)":"none"},children:e},e))}),(0,n.jsxs)("span",{style:{fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["→ ",M]})]}),c&&(0,n.jsx)("div",{style:{fontSize:12,color:"#f87171"},children:c}),x&&(0,n.jsx)("div",{style:{fontSize:12,color:"#f87171",wordBreak:"break-word"},children:x}),p&&(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",padding:10,display:"flex",flexDirection:"column",gap:8},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10},children:[(0,n.jsx)("div",{style:{width:10,height:10,borderRadius:"50%",border:"2px solid var(--border)",borderTopColor:"var(--accent)",animation:"spin 0.8s linear infinite",flexShrink:0}}),(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:f??"Installing"}),(0,n.jsx)("div",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:p})]}),(0,n.jsx)("button",{onClick:I,style:{padding:"4px 9px",fontSize:12,borderRadius:5,border:"1px solid var(--border)",background:"none",color:"var(--text-muted)",cursor:"pointer",flexShrink:0},children:"Cancel"})]}),m.length>0&&(0,n.jsx)("div",{style:{maxHeight:120,overflow:"auto",fontFamily:"var(--font-mono)",fontSize:11,lineHeight:1.6,color:"var(--text-dim)",borderTop:"1px solid var(--border)",paddingTop:8},children:m.map((e,t)=>(0,n.jsx)("div",{children:e},`${t}-${e}`))})]})]}),l.length>0?(0,n.jsx)("div",{style:{flex:1,overflowY:"auto"},children:l.map(e=>{let t=b.has(e.package),r=p===e.package,o=e.package.indexOf("@"),i=o>-1?e.package.slice(0,o):e.package,l=o>-1?e.package.slice(o+1):null;return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:14,padding:"12px 0",borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)",marginBottom:3},children:l??i}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)"},children:i}),(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:e.installs}),e.url&&(0,n.jsx)("a",{href:e.url,target:"_blank",rel:"noreferrer",style:{fontSize:12,color:"var(--accent)",textDecoration:"none"},children:"skills.sh ↗"})]})]}),(0,n.jsx)("button",{onClick:()=>{t||null!==p||z(e.package)},disabled:t||null!==p,style:{flexShrink:0,padding:"5px 14px",fontSize:12,fontWeight:500,borderRadius:5,border:"1px solid var(--border)",cursor:r?"wait":t||null!==p?"not-allowed":"pointer",background:t?"rgba(34,197,94,0.1)":r?"rgba(59,130,246,0.08)":"none",color:t?"#16a34a":r?"var(--accent)":"var(--text-muted)",transition:"color 0.12s"},children:t?"✓ Installed":r?"Installing":"Install"})]},e.package)})}):!c&&!a&&(0,n.jsxs)("div",{style:{fontSize:13,color:"var(--text-dim)",lineHeight:1.8},children:["Search"," ",(0,n.jsx)("a",{href:"https://skills.sh",target:"_blank",rel:"noreferrer",style:{color:"var(--accent)",textDecoration:"none"},children:"skills.sh"})," ","to discover and install skills for your agent."]})]})}function rp({cwd:e,onClose:t,embedded:r=!1}){let[i,l]=(0,o.useState)([]),[s,a]=(0,o.useState)(!0),[d,c]=(0,o.useState)(null),[u,p]=(0,o.useState)(null),[h,x]=(0,o.useState)(new Set),[g,f]=(0,o.useState)(null),[v,m]=(0,o.useState)(!1),y=(0,o.useCallback)(()=>{a(!0),c(null),fetch(`/api/skills?cwd=${encodeURIComponent(e)}`).then(e=>e.json()).then(e=>{if(e.error)return void c(e.error);let t=e.skills??[];l(t),t.length>0&&!u&&p(t[0].filePath)}).catch(e=>c(String(e))).finally(()=>a(!1))},[e,u]);(0,o.useEffect)(()=>{y()},[e]);let b=(0,o.useCallback)(async e=>{let t=!e.disableModelInvocation;x(t=>new Set(t).add(e.filePath)),f(null);try{let r=await fetch("/api/skills",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({filePath:e.filePath,disableModelInvocation:t})}),n=await r.json();if(!r.ok||n.error)return void f(n.error??`HTTP ${r.status}`);l(r=>r.map(r=>r.filePath===e.filePath?{...r,disableModelInvocation:t}:r))}catch(e){f(String(e))}finally{x(t=>{let r=new Set(t);return r.delete(e.filePath),r})}},[]),j=i.find(e=>e.filePath===u)??null;return(0,n.jsx)("div",{style:r?{height:"100%",minHeight:0,display:"flex",alignItems:"stretch",justifyContent:"stretch"}:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:e=>{r||e.target!==e.currentTarget||t()},children:(0,n.jsxs)("div",{style:{width:r?"100%":860,height:r?"100%":"78vh",background:"var(--bg)",border:r?"none":"1px solid var(--border)",borderRadius:10*!r,display:"flex",flexDirection:"column",boxShadow:r?"none":"0 8px 32px rgba(0,0,0,0.18)",overflow:"hidden"},children:[!r&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 18px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10},children:[(0,n.jsx)("span",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:"Skills"}),(0,n.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)",maxWidth:320,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:rs(e)})]}),(0,n.jsx)("button",{onClick:t,style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),(0,n.jsxs)("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{width:210,borderRight:"1px solid var(--border)",display:"flex",flexDirection:"column",flexShrink:0,background:"var(--bg-panel)"},children:[(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",padding:"8px 6px"},children:s?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:"Loading…"}):d?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"#f87171"},children:d}):0===i.length?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"var(--text-dim)"},children:"No skills found"}):(()=>{let e=[];for(let t of["project","global","path"]){let r=i.filter(e=>ra(e)===t);r.length>0&&e.push({label:t,skills:r})}return e.map(({label:e,skills:t})=>(0,n.jsxs)("div",{style:{marginBottom:6},children:[(0,n.jsx)("div",{style:{padding:"4px 8px 3px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.06em"},children:e}),t.map(e=>{let t=!v&&u===e.filePath,r=e.disableModelInvocation;return(0,n.jsxs)("div",{onClick:()=>{p(e.filePath),m(!1)},style:{display:"flex",alignItems:"center",gap:7,padding:"8px 8px",borderRadius:5,cursor:"pointer",background:t?"var(--bg-selected)":"none"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,n.jsx)("span",{style:{flexShrink:0,width:7,height:7,borderRadius:"50%",background:r?"var(--border)":"var(--accent)",boxShadow:r?"none":"0 0 4px var(--accent)",transition:"background 0.15s, box-shadow 0.15s"}}),(0,n.jsx)("span",{style:{fontSize:12,fontWeight:t?600:400,color:r?"var(--text-dim)":"var(--text)",fontFamily:"var(--font-mono)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name})]},e.filePath)})]},e))})()}),(0,n.jsx)("div",{style:{padding:"8px 6px",borderTop:"1px solid var(--border)",flexShrink:0},children:(0,n.jsxs)("div",{onClick:()=>m(!0),style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,cursor:"pointer",background:v?"var(--bg-selected)":"none",color:v?"var(--accent)":"var(--text-dim)",fontSize:12},onMouseEnter:e=>{v||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{v||(e.currentTarget.style.background="none")},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)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,n.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),"Add skill"]})})]}),(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:v?(0,n.jsx)(ru,{cwd:e,onInstalled:()=>{y()}}):s?null:j?(0,n.jsx)(rc,{skill:j,cwd:e,onToggle:b,toggling:h.has(j.filePath),saveError:g},j.filePath):(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:"Select a skill"})})]}),(0,n.jsx)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",padding:"10px 18px",borderTop:"1px solid var(--border)",flexShrink:0},children:(0,n.jsx)("button",{onClick:t,style:{padding:"6px 14px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:13},children:"Close"})})]})})}let rh=[{label:"30m",value:18e5},{label:"2h",value:72e5},{label:"6h",value:216e5},{label:"24h",value:864e5},{label:"48h",value:1728e5},{label:"Never",value:0}];function rx(e){return e?e.replace(/^\/(?:Users|home)\/[^/]+/,"~"):""}function rg(e){if(e<=0)return"never";let t=e/60/1e3;if(t<60)return`${Math.round(t)}m`;let r=t/60;return Number.isInteger(r)?`${r}h`:`${r.toFixed(1)}h`}function rf(e){return{id:"",language:e,displayName:"",command:"python"===e?"python3":"R",argsText:JSON.stringify("python"===e?["-u"]:["--slave","--vanilla"]),envText:"{}"}}function rv(e){return{id:e.id,language:e.language,displayName:e.displayName,command:e.command,argsText:JSON.stringify(e.args),envText:JSON.stringify(e.env,null,2)}}let rm={height:30,padding:"0 11px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12,display:"inline-flex",alignItems:"center",justifyContent:"center",gap:6,whiteSpace:"nowrap"},ry={width:"100%",minWidth:0,padding:"7px 9px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg)",color:"var(--text)",fontSize:12,outline:"none",fontFamily:"var(--font-mono)"};function rb({label:e,children:t}){return(0,n.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:5,minWidth:0},children:[(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",fontWeight:500},children:e}),t]})}function rj({cwd:e}){let[t,r]=(0,o.useState)("python"),[i,l]=(0,o.useState)(null),[s,a]=(0,o.useState)(!0),[d,c]=(0,o.useState)(null),[u,p]=(0,o.useState)(null),[h,x]=(0,o.useState)(null),[g,f]=(0,o.useState)([]),[v,m]=(0,o.useState)(null),[y,b]=(0,o.useState)("view"),[j,k]=(0,o.useState)(()=>rf("python")),[w,S]=(0,o.useState)(1728e5),[C,T]=(0,o.useState)(!1),z=(0,o.useCallback)(async()=>{a(!0),p(null);try{let r=e?`?cwd=${encodeURIComponent(e)}`:"",n=await fetch(`/api/plot-kernels${r}`),o=await n.json();if(!n.ok||o.error)throw Error(o.error??`HTTP ${n.status}`);l(o),f([]),x(null),m(e=>{if(e&&o.kernels.some(t=>t.id===e))return e;let r=o.kernels.find(e=>e.language===t&&e.isEffective);return r?.id??o.kernels.find(e=>e.language===t)?.id??null})}catch(e){p(e instanceof Error?e.message:String(e))}finally{a(!1)}},[e,t]);(0,o.useEffect)(()=>{z()},[z]),(0,o.useEffect)(()=>{let e=!1;return fetch("/api/settings").then(e=>e.ok?e.json():Promise.reject(Error(`HTTP ${e.status}`))).then(t=>{e||"number"!=typeof t.settings?.plotIdleTimeoutMs||S(t.settings.plotIdleTimeoutMs)}).catch(()=>{}),()=>{e=!0}},[]);let I=(0,o.useMemo)(()=>(i?.kernels??[]).filter(e=>e.language===t),[t,i?.kernels]),M=I.find(e=>e.id===v)??null;(0,o.useEffect)(()=>{if("new"===y)return void k(rf(t));let e=M??I.find(e=>e.isEffective)??I[0]??null;e?(v!==e.id&&m(e.id),k(rv(e)),b("view")):(m(null),k(rf(t)),b("new"))},[t,i?.kernels]);let R=(0,o.useCallback)(async(t,r)=>{c(r),p(null),x(null),f([]);try{let r=await fetch("/api/plot-kernels",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,...t})}),n=await r.json();if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);return l(n),f(n.errors??[]),n}catch(e){return p(e instanceof Error?e.message:String(e)),null}finally{c(null)}},[e]),L=(0,o.useCallback)(async e=>{let t=await R({action:"scan",..."all"===e?{}:{language:e}},"scan");t&&x(`Scan added ${t.added?.length??0} kernel${(t.added?.length??0)===1?"":"s"}${t.skipped?`, skipped ${t.skipped} existing`:""}.`)},[R]),W=(0,o.useCallback)(async e=>{await R({action:"select",language:e.language,kernelId:e.id},"select")&&x(`Selected ${e.displayName} for this project.`)},[R]),E=(0,o.useCallback)(async e=>{await R({action:"setDefault",language:e.language,kernelId:e.id},"default")&&x(`Set ${e.displayName} as global default.`)},[R]),$=(0,o.useCallback)(async()=>{let e=j.id.trim();if(!e)return void p("Kernel ID is required");try{let t=function(e){let t=JSON.parse(e.argsText||"[]"),r=JSON.parse(e.envText||"{}");if(!Array.isArray(t))throw Error("Args must be a JSON array");if(!r||"object"!=typeof r||Array.isArray(r))throw Error("Env must be a JSON object");return{language:e.language,command:e.command.trim(),displayName:e.displayName.trim(),args:t.map(e=>String(e)),env:Object.fromEntries(Object.entries(r).map(([e,t])=>[e,String(t)]))}}(j);if(!t.command)throw Error("Command is required");if(!await R({action:"new"===y?"add":"edit",kernelId:e,kernel:t},"save"))return;m(e),b("view"),x("new"===y?"Kernel added.":"Kernel saved.")}catch(e){p(e instanceof Error?e.message:String(e))}},[j,y,R]),P=(0,o.useCallback)(async e=>{let r=await R({action:"delete",kernelId:e.id},"delete");if(!r)return;let n=r.kernels.find(e=>e.language===t&&e.isEffective)??r.kernels.find(e=>e.language===t)??null;m(n?.id??null),b(n?"view":"new"),x("Kernel deleted.")},[t,R]),D=()=>{b("new"),m(null),k(rf(t)),p(null),x(null)},B=(0,o.useCallback)(async e=>{S(e),T(!0),p(null);try{let t=await fetch("/api/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:{plotIdleTimeoutMs:e}})}),r=await t.json();if(!t.ok||r.error)throw Error(r.error??`HTTP ${t.status}`);"number"==typeof r.settings?.plotIdleTimeoutMs&&(S(r.settings.plotIdleTimeoutMs),x(`Workbench idle timeout set to ${rg(r.settings.plotIdleTimeoutMs)}.`))}catch(e){S(w),p(e instanceof Error?e.message:String(e))}finally{T(!1)}},[w]);return(0,n.jsxs)("div",{style:{height:"100%",minHeight:0,display:"flex",flexDirection:"column",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{flexShrink:0,padding:"12px 16px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)"},children:"Workbench Runtime"}),(0,n.jsx)("div",{style:{marginTop:4,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:"Manage the warm R/Python kernels used by Workbench sessions and iterative analysis turns."})]}),(0,n.jsxs)("div",{style:{flexShrink:0,display:"flex",alignItems:"center",gap:10,padding:"12px 16px",borderBottom:"1px solid var(--border)",flexWrap:"wrap"},children:[(0,n.jsx)("div",{style:{display:"flex",padding:2,border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-panel)"},children:["python","r"].map(e=>{let o=t===e;return(0,n.jsx)("button",{type:"button",onClick:()=>r(e),style:{height:26,padding:"0 12px",border:"none",borderRadius:5,background:o?"var(--bg)":"transparent",color:o?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:o?600:500},children:"python"===e?"Python":"R"},e)})}),(0,n.jsxs)("button",{type:"button",onClick:()=>void L(t),disabled:!!d,style:{...rm,opacity:d?.55:1},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)("path",{d:"M21 12a9 9 0 0 1-15.3 6.4"}),(0,n.jsx)("path",{d:"M3 12A9 9 0 0 1 18.3 5.6"}),(0,n.jsx)("path",{d:"M18 2v4h4"}),(0,n.jsx)("path",{d:"M6 22v-4H2"})]}),"scan"===d?"Scanning...":`Scan ${"python"===t?"Python":"R"}`]}),(0,n.jsx)("button",{type:"button",onClick:()=>void L("all"),disabled:!!d,style:{...rm,opacity:d?.55:1},children:"Scan all"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,marginLeft:"auto"},children:[(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:"Idle"}),(0,n.jsx)("div",{style:{display:"flex",padding:2,border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-panel)"},children:rh.map(e=>{let t=w===e.value;return(0,n.jsx)("button",{type:"button",onClick:()=>{t||B(e.value)},disabled:C,title:`Close inactive Workbench kernels after ${rg(e.value)}`,style:{height:24,padding:"0 8px",border:"none",borderRadius:5,background:t?"var(--bg)":"transparent",color:t?"var(--accent)":"var(--text-muted)",cursor:C?"default":"pointer",fontSize:11,fontWeight:t?700:500,opacity:C?.65:1},children:e.label},e.label)})})]}),(0,n.jsxs)("button",{type:"button",onClick:D,style:{...rm,marginLeft:"auto",color:"var(--accent)"},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)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,n.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),"Add kernel"]})]}),(u||h||g.length>0)&&(0,n.jsxs)("div",{style:{flexShrink:0,padding:"8px 16px",borderBottom:"1px solid var(--border)",fontSize:12,lineHeight:1.5},children:[u&&(0,n.jsx)("div",{style:{color:"#f87171"},children:u}),h&&(0,n.jsx)("div",{style:{color:"var(--text-muted)"},children:h}),g.map(e=>(0,n.jsx)("div",{style:{color:"rgba(234,179,8,0.95)"},children:e},e))]}),(0,n.jsxs)("div",{style:{flex:1,minHeight:0,display:"flex",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{width:290,flexShrink:0,borderRight:"1px solid var(--border)",background:"var(--bg-panel)",display:"flex",flexDirection:"column",minHeight:0},children:[(0,n.jsxs)("div",{style:{padding:"8px 10px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:[(0,n.jsxs)("div",{children:["Global: ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:rx(i?.paths.global??"")})]}),e&&(0,n.jsxs)("div",{children:["Project: ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:rx(i?.paths.project??"")})]}),!e&&(0,n.jsx)("div",{children:"Project selection requires an active cwd."})]}),(0,n.jsx)("div",{style:{flex:1,minHeight:0,overflowY:"auto",padding:"8px 6px"},children:s?(0,n.jsx)("div",{style:{padding:"10px 8px",color:"var(--text-muted)",fontSize:12},children:"Loading..."}):0===I.length?(0,n.jsx)("div",{style:{padding:"10px 8px",color:"var(--text-dim)",fontSize:12},children:"No kernels found"}):I.map(e=>{let t=v===e.id&&"new"!==y;return(0,n.jsxs)("button",{type:"button",onClick:()=>{m(e.id),b("view"),k(rv(e)),p(null),x(null)},style:{width:"100%",display:"flex",alignItems:"center",gap:8,padding:"8px 9px",border:"none",borderRadius:6,background:t?"var(--bg-selected)":"transparent",color:"var(--text)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="transparent")},children:[(0,n.jsx)("span",{style:{width:8,height:8,borderRadius:"50%",background:e.isEffective?"var(--accent)":"var(--border)",flexShrink:0}}),(0,n.jsxs)("span",{style:{minWidth:0,flex:1},children:[(0,n.jsx)("span",{style:{display:"block",color:"var(--text)",fontSize:12,fontWeight:t?600:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.displayName}),(0,n.jsx)("span",{style:{display:"block",color:"var(--text-dim)",fontSize:10,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.id})]}),(e.isProjectSelected||e.isDefault)&&(0,n.jsxs)("span",{style:{flexShrink:0,display:"flex",gap:3},children:[e.isProjectSelected&&(0,n.jsx)("span",{title:"Project selected",style:{fontSize:9,color:"var(--accent)",border:"1px solid rgba(37,99,235,0.35)",borderRadius:4,padding:"1px 4px"},children:"P"}),e.isDefault&&(0,n.jsx)("span",{title:"Global default",style:{fontSize:9,color:"var(--text-muted)",border:"1px solid var(--border)",borderRadius:4,padding:"1px 4px"},children:"D"})]})]},e.id)})}),(0,n.jsxs)("div",{style:{padding:"8px 10px",borderTop:"1px solid var(--border)",color:"var(--text-dim)",fontSize:11},children:["Last scan: ",function(e){if(!e)return"never";let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}(i?.scanCache?.lastScan)]})]}),(0,n.jsx)("div",{style:{flex:1,minWidth:0,minHeight:0,overflowY:"auto",padding:18},children:"view"===y&&M?(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16,maxWidth:760},children:[(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,n.jsx)("h3",{style:{margin:0,color:"var(--text)",fontSize:15,lineHeight:1.3},children:M.displayName}),M.isEffective&&(0,n.jsx)("span",{style:{fontSize:10,color:"var(--accent)",border:"1px solid rgba(37,99,235,0.35)",borderRadius:4,padding:"1px 5px"},children:"active"})]}),(0,n.jsx)("div",{style:{marginTop:5,fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)"},children:M.id})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:12},children:[(0,n.jsx)(rb,{label:"Command",children:(0,n.jsx)("input",{readOnly:!0,value:M.command,style:{...ry,color:"var(--text-muted)"}})}),(0,n.jsx)(rb,{label:"Args",children:(0,n.jsx)("input",{readOnly:!0,value:JSON.stringify(M.args),style:{...ry,color:"var(--text-muted)"}})})]}),(0,n.jsx)(rb,{label:"Environment",children:(0,n.jsx)("textarea",{readOnly:!0,value:JSON.stringify(M.env,null,2),rows:5,style:{...ry,resize:"vertical",color:"var(--text-muted)"}})}),(0,n.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[(0,n.jsx)("button",{type:"button",onClick:()=>e&&void W(M),disabled:!e||"select"===d,style:{...rm,background:e?"var(--accent)":"var(--bg-panel)",color:e?"#fff":"var(--text-dim)",opacity:"select"===d?.6:1},children:"Use for project"}),(0,n.jsx)("button",{type:"button",onClick:()=>void E(M),disabled:"default"===d,style:{...rm,opacity:"default"===d?.6:1},children:"Set default"}),(0,n.jsx)("button",{type:"button",onClick:()=>{b("edit"),m(M.id),k(rv(M)),p(null),x(null)},style:rm,children:"Edit"}),!M.id.startsWith("default-")&&(0,n.jsx)("button",{type:"button",onClick:()=>void P(M),disabled:"delete"===d,style:{...rm,color:"#f87171",opacity:"delete"===d?.6:1},children:"Delete"})]})]}):(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:14,maxWidth:760},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:8},children:[(0,n.jsx)("h3",{style:{margin:0,color:"var(--text)",fontSize:15},children:"new"===y?"Add Kernel":"Edit Kernel"}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:"python"===t?"Python":"R"})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:12},children:[(0,n.jsx)(rb,{label:"Kernel ID",children:(0,n.jsx)("input",{value:j.id,readOnly:"edit"===y,onChange:e=>k(t=>({...t,id:e.target.value})),placeholder:"python"===t?"my-python":"my-r",style:{...ry,color:"edit"===y?"var(--text-muted)":"var(--text)"}})}),(0,n.jsx)(rb,{label:"Display name",children:(0,n.jsx)("input",{value:j.displayName,onChange:e=>k(t=>({...t,displayName:e.target.value})),placeholder:"python"===t?"Python 3 (Project)":"R (Project)",style:ry})})]}),(0,n.jsx)(rb,{label:"Command",children:(0,n.jsx)("input",{value:j.command,onChange:e=>k(t=>({...t,command:e.target.value})),placeholder:"/usr/bin/python3",style:ry})}),(0,n.jsx)(rb,{label:"Args JSON",children:(0,n.jsx)("input",{value:j.argsText,onChange:e=>k(t=>({...t,argsText:e.target.value})),style:ry})}),(0,n.jsx)(rb,{label:"Env JSON",children:(0,n.jsx)("textarea",{value:j.envText,onChange:e=>k(t=>({...t,envText:e.target.value})),rows:6,style:{...ry,resize:"vertical"}})}),(0,n.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,n.jsx)("button",{type:"button",onClick:()=>void $(),disabled:"save"===d,style:{...rm,background:"var(--accent)",borderColor:"var(--accent)",color:"#fff",opacity:"save"===d?.6:1},children:"save"===d?"Saving...":"Save"}),(0,n.jsx)("button",{type:"button",onClick:()=>{let e=M??I.find(e=>e.isEffective)??I[0]??null;e?(m(e.id),k(rv(e)),b("view")):D(),p(null)},style:rm,children:"Cancel"})]})]})})]})]})}function rk(e){if(!e)return"Never";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 rw(e){let t=e.split(/[\\/]/).filter(Boolean);return t.length<=3?e:`.../${t.slice(-3).join("/")}`}function rS(e){return e.lastAccessed??e.created??null}function rC({activeCwd:e,onSelectProject:t,onProjectsChanged:r}){let[i,l]=(0,o.useState)([]),[s,a]=(0,o.useState)(!0),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(""),[x,g]=(0,o.useState)(!1),[f,v]=(0,o.useState)(null),[m,y]=(0,o.useState)(null),[b,j]=(0,o.useState)(""),[k,w]=(0,o.useState)(!0),[S,C]=(0,o.useState)(null),[T,z]=(0,o.useState)(null),I=(0,o.useRef)(null),M=(0,o.useCallback)(async()=>{try{a(!0);let e=await fetch("/api/projects?includeHidden=1"),t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);l(t.projects??[]),u(null)}catch(e){u(e instanceof Error?e.message:String(e))}finally{a(!1)}},[]);(0,o.useEffect)(()=>{M()},[M]);let R=(0,o.useMemo)(()=>({projects:i.filter(e=>!e.hidden).length,archived:i.filter(e=>e.hidden).length,chats:i.reduce((e,t)=>e+t.chatCount,0)}),[i]),L=(0,o.useMemo)(()=>({pinnedCount:i.filter(e=>!e.hidden&&!0===e.pinned).length,hasManualOrder:i.some(e=>!e.hidden&&"number"==typeof e.sortOrder)}),[i]),W=(0,o.useMemo)(()=>i.filter(e=>!e.hidden),[i]),E=(0,o.useMemo)(()=>i.filter(e=>e.hidden),[i]),$=(0,o.useCallback)(async()=>{let e=p.trim();if(e){v("add"),u(null);try{let n=await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e})}),o=await n.json();if(!n.ok||o.error)throw Error(o.error??`HTTP ${n.status}`);h(""),r?.(),t?.(e),M()}catch(e){u(e instanceof Error?e.message:String(e))}finally{v(null)}}},[M,r,t,p]),P=(0,o.useCallback)(async e=>{v("add"),u(null);try{let n=await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e})}),o=await n.json();if(!n.ok||o.error)throw Error(o.error??`HTTP ${n.status}`);h(""),g(!1),r?.(),t?.(e),M()}catch(e){u(e instanceof Error?e.message:String(e))}finally{v(null)}},[M,r,t]),D=(0,o.useCallback)(async e=>{v(`rename:${e}`),u(null);try{let t=await fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,name:b})}),n=await t.json();if(!t.ok||n.error)throw Error(n.error??`HTTP ${t.status}`);y(null),j(""),r?.(),await M()}catch(e){u(e instanceof Error?e.message:String(e)),M()}finally{v(null)}},[M,r,b]),B=(0,o.useCallback)(async n=>{let o=n.cwd,i=o===e,l=i?W.find(e=>e.cwd!==o)??null:null;if(u(null),i&&!l)return void u("Restore or add another active project before archiving the current project.");if(!i||!l||window.confirm(`Archive the current project "${n.displayName}" and switch to "${l.displayName}"?`)){v(`archive:${o}`),u(null);try{let e=await fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:o,hidden:!0})}),n=await e.json();if(!e.ok||n.error)throw Error(n.error??`HTTP ${e.status}`);i&&l&&t?t(l.cwd,{closeDialog:!1}):r?.(),await M()}catch(e){u(e instanceof Error?e.message:String(e)),M()}finally{v(null)}}},[e,M,r,t,W]),N=(0,o.useCallback)(async e=>{v(`restore:${e}`),u(null);try{let t=await fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,hidden:!1})}),n=await t.json();if(!t.ok||n.error)throw Error(n.error??`HTTP ${t.status}`);r?.(),await M()}catch(e){u(e instanceof Error?e.message:String(e)),M()}finally{v(null)}},[M,r]),O=(0,o.useCallback)(async(e,t)=>{v(`pin:${e}`),u(null);try{let n=await fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,pinned:t})}),o=await n.json();if(!n.ok||o.error)throw Error(o.error??`HTTP ${n.status}`);r?.(),await M()}catch(e){u(e instanceof Error?e.message:String(e)),M()}finally{v(null)}},[M,r]),A=(0,o.useCallback)(async e=>{v("reorder"),u(null);try{let t=await fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({order:e})}),n=await t.json();if(!t.ok||n.error)throw Error(n.error??`HTTP ${t.status}`);r?.(),await M()}catch(e){u(e instanceof Error?e.message:String(e)),M()}finally{v(null)}},[M,r]),H=(0,o.useCallback)((e,t)=>{if(!e||!t||e===t)return;let r=W.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),A(i)},[A,W]),F=(0,o.useCallback)(e=>{y(e.cwd),j(e.name??e.displayName),window.setTimeout(()=>I.current?.select(),0)},[]);return(0,n.jsxs)("div",{style:{height:"100%",overflowY:"auto",padding:20},children:[(0,n.jsxs)("div",{style:{maxWidth:900,display:"flex",flexDirection:"column",gap:14},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:15,fontWeight:750,color:"var(--text)"},children:"Projects"}),(0,n.jsxs)("div",{style:{marginTop:4,fontSize:12,color:"var(--text-muted)"},children:[R.projects," active / ",R.archived," archived / ",R.chats," chats"]})]}),(0,n.jsx)("button",{type:"button",onClick:()=>void M(),style:{height:30,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Refresh"})]}),(0,n.jsx)("div",{style:{border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",padding:12},children:(0,n.jsxs)("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[(0,n.jsx)("input",{value:p,onChange:e=>h(e.target.value),onKeyDown:e=>{"Enter"===e.key&&$()},placeholder:"/path/to/project",style:{flex:1,minWidth:0,height:32,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:12,outline:"none"}}),(0,n.jsx)("button",{type:"button",onClick:()=>g(!0),style:{height:32,padding:"0 12px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Browse"}),(0,n.jsx)("button",{type:"button",disabled:!p.trim()||"add"===f,onClick:()=>void $(),style:{height:32,padding:"0 12px",border:"none",borderRadius:6,background:p.trim()?"var(--accent)":"var(--bg-hover)",color:p.trim()?"#fff":"var(--text-dim)",cursor:p.trim()?"pointer":"default",fontSize:12,fontWeight:650},children:"Add"})]})}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:"10px 12px",border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)"},children:[(0,n.jsx)("div",{style:{minWidth:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:"Active projects sort by pinned, manual drag order, then project name. Archived projects stay out of the sidebar until restored."}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexShrink:0},children:[(0,n.jsx)("span",{style:{padding:"2px 7px",borderRadius:999,background:"var(--bg)",color:"var(--text-dim)",fontSize:11},children:L.hasManualOrder?"Manual order active":"Name order active"}),L.pinnedCount>0&&(0,n.jsxs)("span",{style:{padding:"2px 7px",borderRadius:999,background:"rgba(37,99,235,0.12)",color:"var(--accent)",fontSize:11},children:[L.pinnedCount," pinned"]})]})]}),c&&(0,n.jsx)("div",{style:{padding:"9px 11px",border:"1px solid rgba(248,113,113,0.35)",borderRadius:7,color:"#f87171",background:"rgba(248,113,113,0.08)",fontSize:12},children:c}),(0,n.jsx)("div",{style:{border:"1px solid var(--border)",borderRadius:8,overflow:"hidden"},children:s?(0,n.jsx)("div",{style:{padding:16,color:"var(--text-muted)",fontSize:12},children:"Loading..."}):0===W.length?(0,n.jsx)("div",{style:{padding:16,color:"var(--text-muted)",fontSize:12},children:"No projects yet."}):W.map(r=>{let o=r.cwd===e,i=m===r.cwd,l=rS(r);return(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) auto",gap:12,alignItems:"center",padding:"12px 14px",borderBottom:"1px solid var(--border)",borderTop:T===r.cwd?"2px solid var(--accent)":"2px solid transparent",background:o?"var(--bg-selected)":"var(--bg)",opacity:S===r.cwd?.55:1},onDragOver:e=>{S&&S!==r.cwd&&"reorder"!==f&&(e.preventDefault(),e.dataTransfer.dropEffect="move",z(r.cwd))},onDragLeave:()=>{T===r.cwd&&z(null)},onDrop:e=>{e.preventDefault();let t=e.dataTransfer.getData("text/project-cwd")||S;z(null),C(null),t&&H(t,r.cwd)},children:[(0,n.jsxs)("div",{style:{minWidth:0},children:[i?(0,n.jsx)("input",{ref:I,value:b,onChange:e=>j(e.target.value),onKeyDown:e=>{"Enter"===e.key&&D(r.cwd),"Escape"===e.key&&y(null)},style:{width:"min(360px, 100%)",height:30,padding:"0 9px",border:"1px solid var(--accent)",borderRadius:6,background:"var(--bg)",color:"var(--text)",fontSize:13,outline:"none"}}):(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,n.jsx)("div",{style:{minWidth:0,color:"var(--text)",fontSize:13,fontWeight:o?750:650,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r.displayName}),r.pinned&&(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--accent)",display:"flex",alignItems:"center"},title:"Pinned project",children:(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"currentColor",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"})})}),!r.exists&&(0,n.jsx)("span",{style:{flexShrink:0,color:"#f87171",fontSize:10},children:"missing"})]}),(0,n.jsx)("div",{style:{marginTop:4,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:r.cwd,children:rw(r.cwd)}),(0,n.jsxs)("div",{style:{marginTop:5,color:"var(--text-muted)",fontSize:11},children:[r.chatCount," chats / last ",rk(l)]})]}),(0,n.jsx)("div",{style:{display:"flex",alignItems:"center",gap:6},children:i?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",disabled:f===`rename:${r.cwd}`,onClick:()=>void D(r.cwd),style:{height:28,padding:"0 9px",border:"none",borderRadius:6,background:"var(--accent)",color:"#fff",cursor:"pointer",fontSize:12},children:"Save"}),(0,n.jsx)("button",{type:"button",onClick:()=>y(null),style:{height:28,padding:"0 9px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Cancel"})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:()=>t?.(r.cwd),style:{height:28,padding:"0 9px",border:"1px solid var(--border)",borderRadius:6,background:o?"var(--accent)":"var(--bg-panel)",color:o?"#fff":"var(--text-muted)",cursor:"pointer",fontSize:12},children:o?"Current":"Switch"}),(0,n.jsx)("button",{type:"button",disabled:f===`pin:${r.cwd}`,onClick:()=>void O(r.cwd,!0!==r.pinned),title:r.pinned?"Unpin project":"Pin project",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:r.pinned?"var(--accent)":"var(--text-muted)",cursor:f===`pin:${r.cwd}`?"wait":"pointer"},children:(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:r.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:()=>F(r),style:{height:28,padding:"0 9px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Rename"}),(0,n.jsx)("button",{type:"button",disabled:f===`archive:${r.cwd}`,onClick:()=>void B(r),title:o&&W.length<=1?"Add or restore another project before archiving the current project":void 0,style:{height:28,padding:"0 9px",border:"1px solid rgba(248,113,113,0.35)",borderRadius:6,background:"transparent",color:"#f87171",cursor:"pointer",fontSize:12},children:o?"Archive Current":"Archive"}),(0,n.jsx)("div",{role:"button",tabIndex:-1,draggable:!0,onDragStart:e=>{"reorder"!==f&&(C(r.cwd),e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/project-cwd",r.cwd))},onDragEnd:()=>{C(null),z(null)},title:"Drag to reorder",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-dim)",cursor:"reorder"===f?"wait":"grab",opacity:"reorder"===f?.65:1,flexShrink:0},children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"currentColor","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"3",cy:"2.5",r:"1"}),(0,n.jsx)("circle",{cx:"9",cy:"2.5",r:"1"}),(0,n.jsx)("circle",{cx:"3",cy:"6",r:"1"}),(0,n.jsx)("circle",{cx:"9",cy:"6",r:"1"}),(0,n.jsx)("circle",{cx:"3",cy:"9.5",r:"1"}),(0,n.jsx)("circle",{cx:"9",cy:"9.5",r:"1"})]})})]})})]},r.cwd)})}),E.length>0&&(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,overflow:"hidden",background:"var(--bg-panel)"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>w(e=>!e),"aria-expanded":k,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:"10px 12px",border:"none",borderBottom:k?"1px solid var(--border)":"none",background:"transparent",color:"var(--text)",cursor:"pointer",fontSize:12,fontWeight:650},children:[(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(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:{flexShrink:0,transform:k?"rotate(90deg)":"rotate(0deg)",transition:"transform 0.15s ease"},"aria-hidden":"true",children:(0,n.jsx)("path",{d:"M3 2l3 3-3 3"})}),(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"Archived Projects"})]}),(0,n.jsx)("span",{style:{flexShrink:0,padding:"2px 7px",borderRadius:999,background:"var(--bg)",color:"var(--text-dim)",fontSize:11},children:E.length})]}),k&&E.map(e=>{let t=rS(e);return(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) auto",gap:12,alignItems:"center",padding:"12px 14px",borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:13,fontWeight:650,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.displayName}),(0,n.jsx)("div",{style:{marginTop:4,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:e.cwd,children:rw(e.cwd)}),(0,n.jsxs)("div",{style:{marginTop:5,color:"var(--text-muted)",fontSize:11},children:[e.chatCount," chats / last ",rk(t)]})]}),(0,n.jsx)("div",{style:{display:"flex",alignItems:"center",gap:6},children:(0,n.jsx)("button",{type:"button",disabled:f===`restore:${e.cwd}`,onClick:()=>void N(e.cwd),style:{height:28,padding:"0 9px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Restore"})})]},e.cwd)})]})]}),(0,n.jsx)(d,{open:x,initialPath:e,onClose:()=>g(!1),onSelect:e=>void P(e)})]})}function rT({checked:e,onChange:t}){return(0,n.jsx)("button",{type:"button",onClick:t,"aria-pressed":e,style:{width:44,height:24,borderRadius:999,border:"none",padding:0,cursor:"pointer",background:e?"var(--accent)":"var(--border)",position:"relative",transition:"background 0.18s",flexShrink:0},children:(0,n.jsx)("span",{style:{position:"absolute",top:3,left:e?23:3,width:18,height:18,borderRadius:"50%",background:"var(--bg)",boxShadow:"0 1px 4px rgba(0,0,0,0.22)",transition:"left 0.18s cubic-bezier(.4,0,.2,1)"}})})}function rz(){return(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.38a2 2 0 0 0-.73-2.73l-.15-.09a2 2 0 0 1-1-1.74v-.51a2 2 0 0 1 1-1.72l.15-.1a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2Z"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})}function rI(e){return"projects"===e?(0,n.jsx)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",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"})}):"models"===e?(0,n.jsxs)("svg",{width:"15",height:"15",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"})]}):"skills"===e?(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),(0,n.jsx)("path",{d:"M2 17l10 5 10-5"}),(0,n.jsx)("path",{d:"M2 12l10 5 10-5"})]}):"generative-ui"===e?(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),(0,n.jsx)("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),(0,n.jsx)("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),(0,n.jsx)("path",{d:"M16 17h5"}),(0,n.jsx)("path",{d:"M18.5 14.5v5"})]}):(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 3v18h18"}),(0,n.jsx)("path",{d:"m19 9-5 5-4-4-3 3"}),(0,n.jsx)("path",{d:"M14 9h5v5"})]})}function rM({cwd:e,generativeUI:t,initialTab:r="projects",onGenerativeUIToggle:i,onClose:l,onModelsChanged:s,onProjectSelect:a,onProjectsChanged:d}){let[c,u]=(0,o.useState)(r);(0,o.useEffect)(()=>{u(r)},[r]),(0,o.useEffect)(()=>{let e=e=>{"Escape"===e.key&&l()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[l]);let p=[{id:"projects",label:"Project",description:e?"Overview and paths":"Add or select a project",icon:rI("projects")},{id:"models",label:"Models",description:"~/.pi/agent/models.json",icon:rI("models")},{id:"skills",label:"Skills",description:e?"Project and global skills":"Select a project first",disabled:!e,icon:rI("skills")},{id:"generative-ui",label:"Generative UI",description:t?"Enabled":"Disabled",icon:rI("generative-ui")},{id:"workbench-runtime",label:"Workbench Runtime",description:e?"Python / R runtime lifecycle":"Global runtime lifecycle",icon:rI("workbench-runtime")}],h=p.find(e=>e.id===c)??p[0];return(0,n.jsx)("div",{className:"settings-dialog-backdrop",onClick:e=>{e.target===e.currentTarget&&l()},children:(0,n.jsxs)("div",{className:"settings-dialog-shell",children:[(0,n.jsxs)("div",{className:"settings-dialog-header",children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:9,minWidth:0},children:[(0,n.jsx)("span",{style:{color:"var(--text-muted)",display:"flex",alignItems:"center",justifyContent:"center"},children:(0,n.jsx)(rz,{})}),(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:15,fontWeight:700,color:"var(--text)",lineHeight:1.25},children:"Settings"}),(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:h.label})]})]}),(0,n.jsx)("button",{type:"button",onClick:l,title:"Close settings","aria-label":"Close settings",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.jsxs)("div",{className:"settings-dialog-body",children:[(0,n.jsx)("div",{className:"settings-dialog-tabs",children:p.map(e=>{let t=c===e.id;return(0,n.jsxs)("button",{type:"button",disabled:e.disabled,onClick:()=>u(e.id),className:"settings-dialog-tab",style:{background:t?"var(--bg-selected)":"transparent",color:t?"var(--text)":"var(--text-muted)",opacity:e.disabled?.45:1,cursor:e.disabled?"not-allowed":"pointer"},onMouseEnter:r=>{t||e.disabled||(r.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="transparent")},children:[(0,n.jsx)("span",{style:{flexShrink:0,color:t?"var(--accent)":"currentColor",display:"flex"},children:e.icon}),(0,n.jsxs)("span",{style:{minWidth:0,flex:1},children:[(0,n.jsx)("span",{style:{display:"block",fontSize:12,fontWeight:t?700:600,lineHeight:1.25},children:e.label}),(0,n.jsx)("span",{style:{display:"block",marginTop:2,fontSize:10,color:"var(--text-dim)",lineHeight:1.25,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.description})]})]},e.id)})}),(0,n.jsxs)("div",{className:"settings-dialog-panel",children:["projects"===c&&(0,n.jsx)(rC,{activeCwd:e,onSelectProject:a,onProjectsChanged:d}),"models"===c&&(0,n.jsx)(rl,{embedded:!0,onClose:()=>{s?.(),l()}}),"skills"===c&&e&&(0,n.jsx)(rp,{cwd:e,embedded:!0,onClose:l}),"generative-ui"===c&&(0,n.jsx)("div",{style:{height:"100%",overflowY:"auto",padding:20},children:(0,n.jsxs)("div",{style:{maxWidth:720,display:"flex",flexDirection:"column",gap:18},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:18,padding:16,border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)",lineHeight:1.35},children:"Generative UI"}),(0,n.jsx)("div",{style:{marginTop:5,fontSize:12,color:"var(--text-muted)",lineHeight:1.55},children:"Render structured widgets and safe visual code blocks directly in chat when the assistant produces UI content."})]}),(0,n.jsx)(rT,{checked:t,onChange:i})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:12},children:[(0,n.jsxs)("div",{style:{padding:14,border:"1px solid var(--border)",borderRadius:8},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:700,color:"var(--text)",marginBottom:5},children:"When enabled"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.6},children:"The agent prompt favors compact visual artifacts for icons, forms, dashboards, and small interactive UI when useful."})]}),(0,n.jsxs)("div",{style:{padding:14,border:"1px solid var(--border)",borderRadius:8},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:700,color:"var(--text)",marginBottom:5},children:"Fallback rendering"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.6},children:"Assistant SVG and safe HTML code blocks can be previewed instead of appearing only as source text."})]})]})]})}),"workbench-runtime"===c&&(0,n.jsx)(rj,{cwd:e})]})]})]})})}function rR(e){return!Number.isFinite(e)||e<=0?"0.0G":`${(e/1024/1024/1024).toFixed(1)}G`}let rL={height:32,padding:"0 12px",borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12};function rW({cwd:e,parentSessionId:t,currentSessionTitle:r,runtime:i,runtimeError:l,busy:s=!1,onClose:a,onLaunch:d,onReleaseCurrentRuntime:c,onOpenSettings:u}){let[p,h]=(0,o.useState)("r"),[x,g]=(0,o.useState)(""),[f,v]=(0,o.useState)("");(0,o.useEffect)(()=>{g(""),v(""),h("r")},[e,t,r]);let m=(0,o.useMemo)(()=>t&&r?`Starts a dedicated child session from "${r}".`:"Starts a dedicated Workbench session in the current project.",[r,t]);return(0,n.jsx)("div",{className:"settings-dialog-backdrop",onClick:e=>{e.target!==e.currentTarget||s||a()},children:(0,n.jsxs)("div",{style:{width:"min(720px, calc(100vw - 40px))",maxHeight:"min(760px, calc(100vh - 40px))",overflow:"auto",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 24px 80px rgba(0,0,0,0.28)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:16,padding:"18px 18px 14px",borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:18,fontWeight:700,color:"var(--text)"},children:"Workbench"}),(0,n.jsxs)("div",{style:{marginTop:6,fontSize:12,color:"var(--text-muted)",lineHeight:1.55},children:[m,e?` Project: ${!e?"":e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}`:""]})]}),(0,n.jsx)("button",{type:"button",onClick:a,disabled:s,style:{width:30,height:30,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:s?"not-allowed":"pointer",fontSize:20,lineHeight:1,opacity:s?.5:1},children:"x"})]}),(0,n.jsxs)("div",{style:{padding:18,display:"grid",gap:18},children:[(0,n.jsxs)("section",{style:{display:"grid",gap:10},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Kernel"}),(0,n.jsx)("div",{style:{display:"flex",gap:8},children:[{id:"r",label:"R",desc:"Seurat, rds, qs, Bioconductor workflows"},{id:"python",label:"Python",desc:"AnnData, h5ad, pandas, scanpy workflows"}].map(e=>{let t=p===e.id;return(0,n.jsxs)("button",{type:"button",onClick:()=>h(e.id),style:{flex:1,textAlign:"left",padding:"12px 13px",borderRadius:10,border:`1px solid ${t?"rgba(37,99,235,0.45)":"var(--border)"}`,background:t?"var(--bg-selected)":"var(--bg-panel)",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer"},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:700},children:e.label}),(0,n.jsx)("div",{style:{marginTop:4,fontSize:11,lineHeight:1.5},children:e.desc})]},e.id)})})]}),(0,n.jsxs)("section",{style:{display:"grid",gap:10},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Sources"}),(0,n.jsxs)("label",{style:{display:"grid",gap:6},children:[(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)"},children:"Primary object or dataset path"}),(0,n.jsx)("input",{value:x,onChange:e=>g(e.target.value),placeholder:"r"===p?"e.g. ./data/sample.rds or ./objects/integrated.qs":"e.g. ./data/sample.h5ad",style:{width:"100%",height:34,padding:"0 10px",borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",fontSize:12,fontFamily:"var(--font-mono)"}})]}),(0,n.jsxs)("label",{style:{display:"grid",gap:6},children:[(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)"},children:"Notes or extra file hints"}),(0,n.jsx)("textarea",{value:f,onChange:e=>v(e.target.value),placeholder:"Optional: metadata table paths, desired comparison, object name hints, or initialization notes.",rows:5,style:{width:"100%",resize:"vertical",minHeight:96,padding:"10px",borderRadius:8,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",fontSize:12,lineHeight:1.55}})]})]}),(0,n.jsxs)("section",{style:{display:"grid",gap:10,padding:14,border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-panel)"},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Runtime"}),(0,n.jsxs)("div",{style:{display:"flex",gap:16,flexWrap:"wrap",fontSize:12,color:"var(--text-muted)"},children:[(0,n.jsxs)("span",{children:["Total memory ",rR(i.totalBytes)]}),(0,n.jsxs)("span",{children:["Current chat ",rR(i.currentSessionBytes)]}),(0,n.jsxs)("span",{children:["Idle timeout ",i.idleTimeoutLabel]})]}),(0,n.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[c&&(0,n.jsx)("button",{type:"button",onClick:c,style:rL,children:"Release current chat"}),u&&(0,n.jsx)("button",{type:"button",onClick:u,style:rL,children:"Runtime settings"})]}),l&&(0,n.jsx)("div",{style:{fontSize:12,color:"#f87171",lineHeight:1.5},children:l})]})]}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,padding:"0 18px 18px"},children:[(0,n.jsx)("button",{type:"button",onClick:a,disabled:s,style:rL,children:"Cancel"}),(0,n.jsx)("button",{type:"button",onClick:()=>void d({kernel:p,sourcePath:x.trim(),notes:f.trim(),parentSessionId:t}),disabled:s||!e,style:{...rL,border:"1px solid rgba(37,99,235,0.45)",background:"rgba(37,99,235,0.12)",color:"var(--accent)",opacity:s||!e?.55:1,cursor:s||!e?"not-allowed":"pointer"},children:s?"Launching...":"Launch Workbench"})]})]})})}function rE({initialWidth:e,minWidth:t,maxWidth:r,storageKey:n,direction:i="right"}){let[l,s]=(0,o.useState)(e),[a,d]=(0,o.useState)(!1),c=(0,o.useRef)(e),u=(0,o.useCallback)(e=>{let o=Math.max(t,Math.min(r,e));s(o),c.current=o,document.documentElement.style.setProperty(n,`${o}px`)},[t,r,n]);(0,o.useEffect)(()=>{try{let e=localStorage.getItem(n);if(e){let n=parseInt(e,10);if(!isNaN(n)&&n>=t&&n<=r)return void u(n)}}catch{}u(c.current)},[n,t,r,u]);let p=(0,o.useCallback)(()=>{d(!0)},[]),h=(0,o.useCallback)(e=>{let t="left"===i?-1:1;u(c.current+e*t)},[u,i]);return{beginResize:p,endResize:(0,o.useCallback)(()=>{d(!1);try{localStorage.setItem(n,String(c.current))}catch{}},[n]),isResizing:a,resizeBy:h,width:l,widthRef:c}}let r$=new Set(["pdf","png","jpg","jpeg","gif","webp","svg","bmp","ico","avif"]);function rP(e){return!Number.isFinite(e)||e<=0?"0.0G":`${(e/1024/1024/1024).toFixed(1)}G`}function rD(e){let t=e.toLowerCase();return t.endsWith(".rds")||t.endsWith(".qs")}function rB(e){return e.toLowerCase().endsWith(".h5ad")}function rN(e){let t=(e.split(/[\\/]/).pop()??e).toLowerCase().split(".").pop()??"";return r$.has(t)}function rO(){let e=(0,i.useRouter)(),t=(0,i.useSearchParams)(),{isDark:r,toggleTheme:l}=(0,tr.D)(),s=function(){let[e,t]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{let e=()=>t(window.innerWidth<=768);return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),e}(),[a,d]=(0,o.useState)(null),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(0),[x,g]=(0,o.useState)(0),[f,v]=(0,o.useState)(0),[m,b]=(0,o.useState)(0),[j,k]=(0,o.useState)(!1),[w,S]=(0,o.useState)("projects"),[C,T]=(0,o.useState)({generativeUI:!0,plotIdleTimeoutMs:1728e5}),[z,I]=(0,o.useState)(!0),M=rE({initialWidth:260,minWidth:180,maxWidth:500,storageKey:"--pi-sidebar-width"}),R=rE({initialWidth:500,minWidth:300,maxWidth:1200,storageKey:"--pi-right-panel-width",direction:"left"}),L=(0,o.useRef)(null),E=(0,o.useRef)(null),[$,P]=(0,o.useState)([]),[D,B]=(0,o.useState)(null),N=(0,o.useRef)(null),O=(0,o.useCallback)((e,t,r)=>{P(e),B(t),N.current=r},[]),A=(0,o.useCallback)(e=>{N.current?.(e)},[]),[H,F]=(0,o.useState)(null),U=(0,o.useRef)(null),[_,J]=(0,o.useState)(!1),[V,K]=(0,o.useState)(""),Y=(0,o.useRef)(null),q=(0,o.useRef)(!1),X=(0,o.useCallback)(e=>{F(e)},[]);(0,o.useEffect)(()=>{J(!1)},[a?.id]);let G=(0,o.useCallback)(e=>e?e.name||e.firstMessage.slice(0,80)||e.id.slice(0,12):"",[]),Z=(0,o.useCallback)(()=>{a&&(q.current=!1,K(a.name||G(a)),J(!0),setTimeout(()=>Y.current?.select(),0))},[G,a]),Q=(0,o.useCallback)(async()=>{if(q.current){q.current=!1,J(!1);return}if(!a)return void J(!1);let e=V.trim(),t=G(a);if(J(!1),e!==(a.name??"")&&(a.name||e!==t))try{(await fetch(`/api/sessions/${encodeURIComponent(a.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e})})).ok&&(d(t=>t&&t.id===a.id?{...t,name:e}:t),h(e=>e+1))}catch{}},[G,a,V]),ee=(0,o.useCallback)(e=>{"Enter"===e.key?(e.preventDefault(),Q()):"Escape"===e.key&&(q.current=!0,J(!1))},[Q]);(0,o.useEffect)(()=>{let e=!1;return fetch("/api/settings").then(e=>e.ok?e.json():null).then(t=>{e||T(e=>({generativeUI:"boolean"==typeof t?.settings?.generativeUI?t.settings.generativeUI:e.generativeUI,plotIdleTimeoutMs:"number"==typeof t?.settings?.plotIdleTimeoutMs?t.settings.plotIdleTimeoutMs:e.plotIdleTimeoutMs}))}).catch(()=>{}),()=>{e=!0}},[]);let et=(0,o.useCallback)(()=>{let e=!C.generativeUI;T(t=>({...t,generativeUI:e})),fetch("/api/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:{generativeUI:e}})}).then(e=>e.ok?e.json():Promise.reject(Error(`HTTP ${e.status}`))).then(e=>{T(t=>({...t,..."boolean"==typeof e.settings?.generativeUI?{generativeUI:e.settings.generativeUI}:{},..."number"==typeof e.settings?.plotIdleTimeoutMs?{plotIdleTimeoutMs:e.settings.plotIdleTimeoutMs}:{}}))}).catch(()=>T(e=>({...e,generativeUI:!e.generativeUI})))},[C.generativeUI]),[er,en]=(0,o.useState)(null),eo=(0,o.useCallback)(e=>{en(e)},[]),[ei,el]=(0,o.useState)(null),es=(0,o.useCallback)(e=>{el(e)},[]),[ea,ed]=(0,o.useState)(null),[ec,eu]=(0,o.useState)(null),[ep,eh]=(0,o.useState)(!1),[ex,eg]=(0,o.useState)(!1),ef=(0,o.useCallback)(e=>{ed(t=>t===e?null:e)},[]);(0,o.useEffect)(()=>{if(!ea||!E.current)return;let e=()=>{let e=E.current.getBoundingClientRect();eu({top:e.bottom,left:e.left,width:e.width})};e();let t=new ResizeObserver(e);return t.observe(E.current),()=>t.disconnect()},[ea]);let[ev,em]=(0,o.useState)([]),[ey,eb]=(0,o.useState)("report"),[ej,eS]=(0,o.useState)(!1),[eT,ez]=(0,o.useState)(0),[eI,eM]=(0,o.useState)(null),[eR,eL]=(0,o.useState)(0),[eW,eE]=(0,o.useState)([]),e$=(0,o.useCallback)(e=>{L.current?.insertText("`"+e+"`")},[]),[eP]=(0,o.useState)(()=>t.get("session")),[eD,eB]=(0,o.useState)(null),[eN,eO]=(0,o.useState)(()=>!t.get("session")),eA=(0,o.useRef)(!1),eH=(0,o.useCallback)(t=>{eB(t),eM(null),t&&!eA.current&&(d(e=>e&&e.cwd!==t?null:e),u(e=>e&&e!==t?null:e),g(e=>e+1),v(e=>e+1),P([]),B(null),F(null),ed(null),e.replace("/",{scroll:!1}))},[e]),eF=(0,o.useCallback)((e,t)=>{eH(e),t?.closeDialog!==!1&&k(!1),h(e=>e+1)},[eH]),eU=(0,o.useCallback)((t,r=!1)=>{u(null),eB(t.cwd),d(t),g(e=>e+1),F(null),eO(!0),r&&(eA.current=!0,setTimeout(()=>{eA.current=!1},0)),r||e.replace(`?session=${encodeURIComponent(t.id)}`,{scroll:!1})},[e]),e_=(0,o.useCallback)((t,r)=>{d(null),u(r),eB(r),g(e=>e+1),P([]),B(null),F(null),ed(null),e.replace("/",{scroll:!1})},[e]),eJ=(0,o.useCallback)(t=>{u(null),eB(t.cwd),d(t),h(e=>e+1),e.replace(`?session=${encodeURIComponent(t.id)}`,{scroll:!1})},[e]),eV=(0,o.useCallback)(()=>{h(e=>e+1),v(e=>e+1)},[]),eK=(0,o.useCallback)(t=>{h(e=>e+1),g(e=>e+1),u(null),d(e=>({...e??{path:"",cwd:"",created:"",modified:"",messageCount:0,firstMessage:""},id:t})),e.replace(`?session=${encodeURIComponent(t)}`,{scroll:!1})},[e]),eY=(0,o.useCallback)(()=>{eO(!0)},[]),eq=(0,o.useCallback)(t=>{if(h(e=>e+1),a?.id===t){let t=a.cwd;d(null),u(t??null),g(e=>e+1),P([]),B(null),F(null),ed(null),e.replace("/",{scroll:!1})}},[a,e]),eX=(0,o.useCallback)((e,t)=>{if(rD(e)||rD(t))return void eM({mode:"start",appType:"stexp",filePath:e,cwd:eD??a?.cwd??c??null,appId:null});if(rN(e)||rN(t)){let r=`preview:${e}`;eE(n=>{let o=n.find(e=>e.id===r),i=n.filter(e=>e.id!==r);return i.push(o?{...o,filePath:e,fileName:t}:{id:r,filePath:e,fileName:t}),i});return}let r=`file:${e}`;em(n=>n.find(e=>e.id===r)?n:[...n,{id:r,label:t,filePath:e}]),eb(r),eS(!0)},[eD,c,a?.cwd]),eG=(0,o.useCallback)((e,t)=>{(rB(e)||rB(t))&&eM({mode:"start",appType:"h5adexp",filePath:e,cwd:eD??a?.cwd??c??null,appId:null})},[eD,c,a?.cwd]),eZ=(0,o.useCallback)(()=>{eb("tools"),eS(!0),eL(e=>e+1)},[]),eQ=(0,o.useCallback)(e=>{eM({mode:"existing",appType:e.appType,filePath:e.filePath,cwd:e.cwd,appId:e.id}),eL(e=>e+1)},[]),e0=(0,o.useCallback)(e=>{eL(e=>e+1),eM(t=>t&&(t.appId===e.id||t.appType===e.appType&&t.filePath===e.filePath&&t.cwd===e.cwd)?"stopped"===e.status||"error"===e.status?null:{mode:"existing",appType:e.appType,filePath:e.filePath,cwd:e.cwd,appId:e.id}:t)},[]),e1=(0,o.useCallback)(e=>{eE(t=>t.filter(t=>t.id!==e))},[]),e2=(0,o.useCallback)(e=>{eE(t=>{let r=t.findIndex(t=>t.id===e);if(r<0||r===t.length-1)return t;let n=[...t],[o]=n.splice(r,1);return n.push(o),n})},[]),e5=(0,o.useCallback)(e=>{"report"!==e&&(em(t=>t.filter(t=>t.id!==e)),eb(t=>{if(t!==e)return t;let r=ev.filter(t=>t.id!==e);return r.length>0?r[r.length-1].id:"report"}))},[ev]),e4=c??(null===a&&eD?eD:null),e3=null!==a||null!==e4,e8=eN&&!e3,e6=[{id:"files",label:"Files",closable:!1,icon:"files"},{id:"report",label:"Report",closable:!1,icon:"report"},{id:"tools",label:"Status",closable:!1,icon:"tools"},...ev],e7=ev.find(e=>e.id===ey)??null,e9=a?G(a):e4?"New chat":"No session",tt=a?.cwd??e4??eD??"",tn=tt?tt.replace(/\/+$/,"").split(/[\\/]/).filter(Boolean).pop()||tt:"",ti=eD??a?.cwd??c??null,ts=(0,o.useCallback)((e="projects")=>{S(e),k(!0)},[]),[td,tc]=(0,o.useState)(null),[tu,tp]=(0,o.useState)(null),[tx,tg]=(0,o.useState)(null),tf=`${a?.id??""}|${ti??""}`,tv=td?.totalBytes??0,tm=td?.currentSessionBytes??0,ty=a?G(a):null,tj=(0,o.useCallback)(async()=>{let e=new URLSearchParams;ti&&e.set("cwd",ti),a?.id&&e.set("sessionId",a.id);try{let t=await fetch(`/api/plot-kernels/status${e.toString()?`?${e}`:""}`),r=await t.json();if(!t.ok||!("totalBytes"in r)||!("kernels"in r))throw Error(r.error??`HTTP ${t.status}`);tc(r),tp(null)}catch(e){tp(e instanceof Error?e.message:String(e))}},[a?.id,ti]);(0,o.useEffect)(()=>{let e=!1,t=async()=>{await tj(),e||(r=window.setTimeout(t,ep?3e3:8e3))},r=window.setTimeout(t,0);return()=>{e=!0,window.clearTimeout(r)}},[tj,tf,ep]);let tk=(0,o.useCallback)(async()=>{if(a?.id&&!tx){tg("all"),tp(null);try{let e=await fetch("/api/plot-kernels/stop",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:a.id})}),t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);window.setTimeout(()=>{tj()},600)}catch(e){tp(e instanceof Error?e.message:String(e))}finally{tg(null)}}},[tj,tx,a?.id]),tw=(0,o.useCallback)(async t=>{let r;if(!ti||ex)return;eg(!0),tp(null);let n=new Date().toISOString(),o=`Workbench \xb7 ${"r"===t.kernel?"R":"Python"}`,i=(r=["Workbench session start.","",`Kernel: ${"r"===t.kernel?"R":"Python"}`],t.sourcePath&&r.push(`Primary source: ${t.sourcePath}`),t.notes&&(r.push("Notes:"),r.push(t.notes)),r.push("","Initialize this workbench for analysis. Prefer the warm runtime tools (`kernel_plot_run`, `kernel_plot_artifacts`, `kernel_plot_stop`) for loading data, inspecting object structure, and generating figures or tables. First, verify inputs, outline what can be loaded immediately, and prepare the session for iterative analysis. Keep the first response concise and operational."),r.join("\n"));try{let r=await fetch("/api/agent/new",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:ti,type:"prompt",message:i,toolNames:W("workbench"),sessionName:o,...t.parentSessionId?{parentSessionId:t.parentSessionId}:{}})}),l=await r.json().catch(()=>({}));if(!r.ok||l.error||!l.sessionId)throw Error(l.error??`HTTP ${r.status}`);eh(!1),u(null),eB(ti),d({id:l.sessionId,path:"",cwd:ti,name:o,created:n,modified:n,messageCount:1,firstMessage:i,...t.parentSessionId?{parentSessionId:t.parentSessionId}:{}}),P([]),B(null),F(null),ed(null),g(e=>e+1),h(e=>e+1),e.replace(`?session=${encodeURIComponent(l.sessionId)}`,{scroll:!1}),window.setTimeout(()=>{tj()},600)}catch(e){tp(e instanceof Error?e.message:String(e))}finally{eg(!1)}},[tj,e,ti,ex]),tS=(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(y,{selectedSessionId:a?.id??null,onSelectSession:eU,onNewSession:e_,initialSessionId:eP,onInitialRestoreDone:eY,refreshKey:p,onSessionDeleted:eq,selectedCwd:a?.cwd??c??eD??null,onCwdChange:eH}),(0,n.jsx)("div",{style:{padding:"8px",flexShrink:0},children:(0,n.jsx)("button",{type:"button",onClick:()=>ts("projects"),title:"Settings","aria-label":"Settings",style:{width:34,display:"flex",alignItems:"center",justifyContent:"center",height:34,padding:0,background:"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:"pointer",fontSize:12,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="none",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.38a2 2 0 0 0-.73-2.73l-.15-.09a2 2 0 0 1-1-1.74v-.51a2 2 0 0 1 1-1.72l.15-.1a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2Z"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})})})]});return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{style:{display:"flex",height:"100dvh",overflow:"hidden",background:"var(--bg)"},children:[(0,n.jsx)("div",{className:"sidebar-overlay-backdrop",onClick:()=>I(!1),style:{position:"fixed",inset:0,zIndex:199,background:"rgba(0,0,0,0.4)",opacity:+!!z,pointerEvents:z?"auto":"none",transition:"opacity 0.25s ease"}}),(0,n.jsx)("div",{className:`sidebar-container${z?" sidebar-open":" sidebar-closed"}`,style:{background:"var(--bg-panel)",borderRight:"1px solid var(--border)",display:"flex",flexDirection:"column",flexShrink:0,zIndex:200,width:M.width,minWidth:M.width,transition:z||M.isResizing?"none":void 0},children:tS}),z&&(0,n.jsx)(ta,{side:"right",ariaLabel:"Resize sidebar",onResizeStart:M.beginResize,onResize:M.resizeBy,onResizeEnd:M.endResize}),(0,n.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden",minWidth:0},children:[(0,n.jsxs)("div",{ref:E,className:"app-topbar",style:{display:"flex",alignItems:"center",gap:8,flexShrink:0,borderBottom:"1px solid var(--border)",height:48,padding:"0 8px",background:"var(--bg)"},children:[(0,n.jsx)("button",{className:"topbar-sidebar-toggle",onClick:()=>I(e=>!e),title:z?"Hide sidebar":"Show sidebar",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="var(--bg-panel)"},children:z?(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,n.jsx)("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]}):(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"3",y1:"6",x2:"21",y2:"6"}),(0,n.jsx)("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),(0,n.jsx)("line",{x1:"3",y1:"18",x2:"21",y2:"18"})]})}),(0,n.jsxs)("div",{className:"topbar-title-area",style:{display:"flex",alignItems:"center",gap:7,minWidth:0,flex:1},children:[(0,n.jsx)("div",{style:{minWidth:0,display:"flex",alignItems:"center",gap:6},children:_&&a?(0,n.jsx)("input",{ref:Y,value:V,onChange:e=>K(e.target.value),onKeyDown:ee,onBlur:()=>void Q(),style:{width:"min(360px, 34vw)",height:28,boxSizing:"border-box",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",padding:"0 8px",fontSize:13,fontWeight:500,outline:"none"}}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"topbar-session-title",title:e9,style:{minWidth:0,maxWidth:"min(420px, 36vw)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:e3?"var(--text)":"var(--text-muted)",fontSize:14,fontWeight:600,lineHeight:1.2},children:e9}),a&&(0,n.jsx)("button",{type:"button",className:"topbar-rename-button",onClick:Z,title:"Rename session",style:{width:22,height:22,display:"flex",alignItems:"center",justifyContent:"center",padding:0,border:"none",borderRadius:5,background:"transparent",color:"var(--text-dim)",cursor:"pointer",flexShrink:0},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)",e.currentTarget.style.background="transparent"},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)("path",{d:"M12 20h9"}),(0,n.jsx)("path",{d:"M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"})]})})]})}),tn&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"topbar-project-crumb",style:{color:"var(--text-dim)",fontSize:12,flexShrink:0},children:"/"}),(0,n.jsx)("span",{className:"topbar-project-crumb",title:tt||tn,style:{minWidth:0,maxWidth:"min(280px, 24vw)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-muted)",fontSize:12,lineHeight:1.2},children:tn})]})]}),e3&&!s&&(0,n.jsxs)("div",{className:"topbar-chat-tools",style:{display:"flex",alignItems:"center",gap:6,height:28,flexShrink:0},children:[(0,n.jsx)("div",{className:"topbar-branches-control",style:{height:"100%",display:"flex",alignItems:"stretch"},children:(0,n.jsx)(tM,{tree:$,activeLeafId:D,onLeafChange:A,inline:!0,containerRef:E,open:"branches"===ea,onToggle:()=>ef("branches"),hasSession:!!a})}),(0,n.jsxs)("button",{ref:U,className:"topbar-system-button",onClick:()=>ef("system"),title:"System prompt","aria-label":"System prompt",style:{display:"flex",alignItems:"center",gap:6,height:28,padding:"0 9px",background:"system"===ea?"var(--bg-selected)":"var(--bg-panel)",border:`1px solid ${"system"===ea?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,cursor:"pointer",color:"system"===ea?"var(--text)":"var(--text-muted)",fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="system"===ea?"var(--text)":"var(--text-muted)",e.currentTarget.style.background="system"===ea?"var(--bg-selected)":"var(--bg-panel)"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:H?"var(--accent)":"var(--text-dim)",flexShrink:0},children:[(0,n.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,n.jsx)("polyline",{points:"14 2 14 8 20 8"}),(0,n.jsx)("line",{x1:"8",y1:"13",x2:"16",y2:"13"}),(0,n.jsx)("line",{x1:"8",y1:"17",x2:"13",y2:"17"})]}),(0,n.jsx)("span",{className:"topbar-system-label",children:"System"})]}),(0,n.jsxs)("button",{type:"button",className:"topbar-plot-button",onClick:()=>{ed(null),eh(!0)},title:tv>0?`Launch Workbench \xb7 runtime ${rP(tv)}`:"Launch Workbench","aria-label":tv>0?`Launch Workbench \xb7 runtime ${rP(tv)}`:"Launch Workbench",style:{display:"flex",alignItems:"center",gap:6,height:28,padding:"0 9px",background:ep?"var(--bg-selected)":tv>0?"rgba(37,99,235,0.08)":"var(--bg-panel)",border:`1px solid ${ep||tv>0?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,cursor:"pointer",color:tv>0?"var(--accent)":"var(--text-muted)",fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s",fontVariantNumeric:"tabular-nums"},onMouseEnter:e=>{e.currentTarget.style.color=tv>0?"var(--accent)":"var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color=tv>0?"var(--accent)":"var(--text-muted)",e.currentTarget.style.background=ep?"var(--bg-selected)":tv>0?"rgba(37,99,235,0.08)":"var(--bg-panel)"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M4 19V5"}),(0,n.jsx)("path",{d:"M4 19h16"}),(0,n.jsx)("path",{d:"m7 16 3-5 4 3 4-7"})]}),(0,n.jsx)("span",{className:"topbar-plot-label",children:"Workbench"}),tv>0&&(0,n.jsx)("span",{className:"topbar-plot-memory",children:rP(tv)})]})]}),e3&&(er||ei)&&(()=>{let e=er?.tokens,t=er?.cost??0,r=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(0)}k`:String(e),o=t>0?t>=.01?`$${t.toFixed(2)}`:"<$0.01":null,i="var(--text-muted)",l=null;if(ei?.contextWindow){let e=ei.percent;null!==e&&e>90?i="#ef4444":null!==e&&e>70&&(i="rgba(234,179,8,0.95)"),l=null!==e?`${e.toFixed(0)}% / ${r(ei.contextWindow)}`:`? / ${r(ei.contextWindow)}`}let s=[];if(e&&(s.push(`in: ${e.input.toLocaleString()}`),s.push(`out: ${e.output.toLocaleString()}`),s.push(`cache read: ${e.cacheRead.toLocaleString()}`),s.push(`cache write: ${e.cacheWrite.toLocaleString()}`),t>0&&s.push(`cost: $${t.toFixed(4)}`)),ei?.contextWindow){let e=ei.percent;s.push(`context: ${null!==e?e.toFixed(1)+"%":"unknown"} of ${ei.contextWindow.toLocaleString()} tokens`)}let a=s.join(" | ");return(0,n.jsxs)("div",{className:"topbar-session-stats",title:a,style:{display:"flex",alignItems:"center",gap:10,padding:"0 8px",height:28,border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-panel)",fontSize:11,color:"var(--text-muted)",whiteSpace:"nowrap",cursor:"default",fontVariantNumeric:"tabular-nums"},children:[e&&e.input>0&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"5",y1:"8.5",x2:"5",y2:"1.5"}),(0,n.jsx)("polyline",{points:"2 4 5 1.5 8 4"})]}),r(e.input)]}),e&&e.output>0&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"5",y1:"1.5",x2:"5",y2:"8.5"}),(0,n.jsx)("polyline",{points:"2 6 5 8.5 8 6"})]}),r(e.output)]}),e&&e.cacheRead>0&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M8.5 5a3.5 3.5 0 1 1-1-2.45"}),(0,n.jsx)("polyline",{points:"6.5 1.5 8.5 2.5 7.5 4.5"})]}),r(e.cacheRead)]}),o&&(0,n.jsx)("span",{style:{display:"flex",alignItems:"center",color:"var(--text)",fontWeight:500},children:o}),l&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4,color:i},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M1 9 L1 5 Q1 1 5 1 Q9 1 9 5 L9 9"}),(0,n.jsx)("line",{x1:"1",y1:"9",x2:"9",y2:"9"})]}),l]})]})})(),(0,n.jsx)("button",{type:"button",className:"topbar-icon-button topbar-generate-ui-toggle",onClick:et,title:`生成式 UI: ${C.generativeUI?"on":"off"}`,"aria-label":`生成式 UI: ${C.generativeUI?"on":"off"}`,style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:28,padding:0,background:C.generativeUI?"var(--bg-selected)":"var(--bg-panel)",border:`1px solid ${C.generativeUI?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,color:C.generativeUI?"var(--accent)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color=C.generativeUI?"var(--accent)":"var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color=C.generativeUI?"var(--accent)":"var(--text-muted)",e.currentTarget.style.background=C.generativeUI?"var(--bg-selected)":"var(--bg-panel)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),(0,n.jsx)("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),(0,n.jsx)("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),(0,n.jsx)("path",{d:"M16 17h5"}),(0,n.jsx)("path",{d:"M18.5 14.5v5"})]})}),(0,n.jsx)("button",{className:"topbar-icon-button topbar-theme-toggle",onClick:e=>{let t=e.currentTarget.getBoundingClientRect();l({x:t.left+t.width/2,y:t.top+t.height/2})},title:r?"Switch to light mode":"Switch to dark mode","aria-label":r?"Switch to light mode":"Switch to dark mode","aria-pressed":r,style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:28,padding:0,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="var(--bg-panel)"},children:r?(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"5"}),(0,n.jsx)("line",{x1:"12",y1:"1",x2:"12",y2:"3"}),(0,n.jsx)("line",{x1:"12",y1:"21",x2:"12",y2:"23"}),(0,n.jsx)("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"}),(0,n.jsx)("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"}),(0,n.jsx)("line",{x1:"1",y1:"12",x2:"3",y2:"12"}),(0,n.jsx)("line",{x1:"21",y1:"12",x2:"23",y2:"12"}),(0,n.jsx)("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"}),(0,n.jsx)("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"})]}):(0,n.jsx)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"})})}),(0,n.jsx)("button",{className:"topbar-icon-button topbar-right-panel-toggle",onClick:()=>eS(e=>!e),title:ej?"Hide report panel":"Show report panel","aria-label":ej?"Hide report panel":"Show report panel",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:28,padding:0,background:ej?"var(--bg-selected)":"var(--bg-panel)",border:`1px solid ${ej?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,color:ej?"var(--accent)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color=ej?"var(--accent)":"var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color=ej?"var(--accent)":"var(--text-muted)",e.currentTarget.style.background=ej?"var(--bg-selected)":"var(--bg-panel)"},children:(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,n.jsx)("line",{x1:"15",y1:"3",x2:"15",y2:"21"})]})}),ea&&ec&&(0,n.jsx)("div",{style:{position:"fixed",top:ec.top,left:ec.left,width:ec.width,zIndex:500},children:"system"===ea&&(0,n.jsx)("div",{style:{background:"var(--bg-panel)",borderBottom:"1px solid var(--border)"},children:H?(0,n.jsx)("div",{style:{maxHeight:"min(600px, 75vh)",overflowY:"auto",padding:"12px 16px",color:"var(--text-muted)",fontSize:12,lineHeight:1.6,whiteSpace:"pre-wrap",fontFamily:"var(--font-mono)"},children:H}):""===H?(0,n.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:"System prompt is empty (tools are disabled)"}):(0,n.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:"Send a message to load the system prompt"})})})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"hidden",position:"relative"},children:e3?(0,n.jsx)(ek,{session:a,newSessionCwd:e4,onAgentEnd:eV,onSessionCreated:eJ,onSessionForked:eK,modelsRefreshKey:m,chatInputRef:L,onBranchDataChange:O,onSystemPromptChange:X,onSessionStatsChange:eo,onContextUsageChange:es,onReportUpdated:()=>ez(e=>e+1),generativeUI:C.generativeUI},x):e8?eD?(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:15},children:"Select a session from the sidebar"}):(0,n.jsxs)("div",{style:{position:"absolute",top:12,left:12,display:"flex",alignItems:"flex-start",gap:8,userSelect:"none",pointerEvents:"none"},children:[(0,n.jsxs)("svg",{width:"44",height:"44",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:.7,flexShrink:0},children:[(0,n.jsx)("line",{x1:"20",y1:"12",x2:"4",y2:"12"}),(0,n.jsx)("polyline",{points:"10 6 4 12 10 18"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:18,fontWeight:600,color:"var(--text)",marginBottom:8},children:"Get Started"}),(0,n.jsxs)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.8},children:[(0,n.jsx)("span",{style:{color:"var(--text-dim)",marginRight:6},children:"1."}),"Select a project directory from the sidebar",(0,n.jsx)("br",{}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",marginRight:6},children:"2."}),"Add models via the ",(0,n.jsx)("strong",{style:{color:"var(--text)"},children:"Models"})," button at the bottom"]})]})]}):null})]}),ej&&(0,n.jsx)(ta,{side:"left",ariaLabel:"Resize right panel",onResizeStart:R.beginResize,onResize:R.resizeBy,onResizeEnd:R.endResize}),(0,n.jsxs)("div",{className:`right-panel-container${ej?" right-panel-open":" right-panel-closed"}`,style:{display:ej?"flex":"none",flexDirection:"column",borderLeft:"1px solid var(--border)",background:"var(--bg)",flexShrink:0,width:R.width,minWidth:R.width,transition:R.isResizing?"none":void 0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",flexShrink:0,background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",height:36},children:[(0,n.jsxs)("button",{type:"button",className:"right-panel-back-button",onClick:()=>eS(!1),title:"Back to chat","aria-label":"Back to chat",style:{height:36,padding:"0 10px",border:"none",borderRight:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12,alignItems:"center",gap:6,flexShrink:0},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("line",{x1:"19",y1:"12",x2:"5",y2:"12"}),(0,n.jsx)("polyline",{points:"12 19 5 12 12 5"})]}),(0,n.jsx)("span",{children:"Chat"})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"hidden"},children:(0,n.jsx)(tT,{tabs:e6,activeTabId:ey,onSelectTab:eb,onCloseTab:e5})})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"hidden"},children:"files"===ey?(0,n.jsx)(te,{cwd:eD??a?.cwd??c??null,refreshKey:f,onOpenFile:eX,onExploreFile:eG,onAtMention:e$}):"report"===ey?(0,n.jsx)(tl,{sessionId:a?.id??null,cwd:a?.cwd??eD??void 0,refreshKey:eT,onOpenFile:eX}):"tools"===ey?(0,n.jsx)(tb,{refreshKey:eR,visibleAppId:eI?.appId??null,cwd:eD??a?.cwd??c??null,onOpenApp:eQ,onAppChanged:e0}):e7?.filePath?e7.filePath.startsWith("__")?(0,n.jsx)(to,{filePath:e7.filePath}):(0,n.jsx)(ew.h,{filePath:e7.filePath,cwd:eD??void 0,onOpenFile:eX}):(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:12},children:"No file open"})})]})]}),j&&(0,n.jsx)(rM,{cwd:ti,generativeUI:C.generativeUI,initialTab:w,onGenerativeUIToggle:et,onModelsChanged:()=>b(e=>e+1),onProjectSelect:eF,onProjectsChanged:()=>h(e=>e+1),onClose:()=>{k(!1),b(e=>e+1)}}),ep&&(0,n.jsx)(rW,{cwd:ti,parentSessionId:a?.id??null,currentSessionTitle:ty,runtime:{totalBytes:tv,currentSessionBytes:tm,idleTimeoutLabel:function(e){if(e<=0)return"never";let t=e/60/60/1e3;return t>=24&&Number.isInteger(t/24)?`${t/24}d`:Number.isInteger(t)?`${t}h`:`${Math.round(e/60/1e3)}m`}(C.plotIdleTimeoutMs)},runtimeError:tu,busy:ex,onClose:()=>eh(!1),onLaunch:e=>tw(e),onReleaseCurrentRuntime:a?.id?()=>{tk()}:void 0,onOpenSettings:()=>ts("workbench-runtime")}),(0,n.jsx)(th,{appType:eI?.appType??"stexp",filePath:eI?.filePath??null,cwd:eI?.cwd??null,appId:eI?.appId??null,sessionId:a?.id??null,onClose:()=>eM(null),onAppChanged:e0,onOpenTools:eZ}),eW.map((e,t)=>(0,n.jsx)(eC,{id:e.id,filePath:e.filePath,fileName:e.fileName,cwd:eD??a?.cwd??c??void 0,active:t===eW.length-1,stackIndex:t,zIndex:700+t,onClose:e1,onFocus:e2,onOpenFile:eX},e.id))]})}},43322:(e,t,r)=>{Promise.resolve().then(r.bind(r,16945))},73321:(e,t,r)=>{"use strict";var n=r(74645);r.o(n,"useRouter")&&r.d(t,{useRouter:function(){return n.useRouter}}),r.o(n,"useSearchParams")&&r.d(t,{useSearchParams:function(){return n.useSearchParams}})}},e=>{e.O(0,[7330,6079,2941,2995,6236,3041,8441,3794,7358],()=>e(e.s=43322)),_N_E=e.O()}]);