@seqyuan/annovibe 0.8.145 → 0.8.147

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 (79) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/app-path-routes-manifest.json +11 -11
  3. package/.next/build-manifest.json +2 -2
  4. package/.next/prerender-manifest.json +4 -4
  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/_tree.segment.rsc +1 -1
  13. package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  14. package/.next/server/app/_not-found.html +1 -1
  15. package/.next/server/app/_not-found.rsc +2 -2
  16. package/.next/server/app/_not-found.segments/_full.segment.rsc +2 -2
  17. package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +2 -2
  18. package/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
  19. package/.next/server/app/api/agent/runtime/route.js +1 -1
  20. package/.next/server/app/api/internal/runtime/route.js +1 -1
  21. package/.next/server/app/api/sessions/[id]/context/route.js +1 -1
  22. package/.next/server/app/api/sessions/[id]/route.js +1 -1
  23. package/.next/server/app/api/sessions/[id]/shadowed/route.js +1 -1
  24. package/.next/server/app/api/settings/route.js +1 -1
  25. package/.next/server/app/api/version/route.js +1 -1
  26. package/.next/server/app/index.html +1 -1
  27. package/.next/server/app/index.rsc +6 -6
  28. package/.next/server/app/index.segments/__PAGE__.segment.rsc +6 -6
  29. package/.next/server/app/index.segments/_full.segment.rsc +6 -6
  30. package/.next/server/app/index.segments/_tree.segment.rsc +2 -2
  31. package/.next/server/app/login/page_client-reference-manifest.js +1 -1
  32. package/.next/server/app/login.html +1 -1
  33. package/.next/server/app/login.rsc +2 -2
  34. package/.next/server/app/login.segments/_full.segment.rsc +2 -2
  35. package/.next/server/app/login.segments/_tree.segment.rsc +2 -2
  36. package/.next/server/app/login.segments/login/__PAGE__.segment.rsc +2 -2
  37. package/.next/server/app/page.js +5 -5
  38. package/.next/server/app/page_client-reference-manifest.js +1 -1
  39. package/.next/server/app/smoke/page.js +2 -2
  40. package/.next/server/app/smoke/page_client-reference-manifest.js +1 -1
  41. package/.next/server/app/smoke/session-stream/page.js +1 -1
  42. package/.next/server/app/smoke/session-stream/page_client-reference-manifest.js +1 -1
  43. package/.next/server/app/smoke/session-stream.html +1 -1
  44. package/.next/server/app/smoke/session-stream.rsc +6 -6
  45. package/.next/server/app/smoke/session-stream.segments/_full.segment.rsc +6 -6
  46. package/.next/server/app/smoke/session-stream.segments/_tree.segment.rsc +2 -2
  47. package/.next/server/app/smoke/session-stream.segments/smoke/session-stream/__PAGE__.segment.rsc +6 -6
  48. package/.next/server/app/smoke.html +3 -51
  49. package/.next/server/app/smoke.rsc +5 -5
  50. package/.next/server/app/smoke.segments/_full.segment.rsc +5 -5
  51. package/.next/server/app/smoke.segments/_tree.segment.rsc +2 -2
  52. package/.next/server/app/smoke.segments/smoke/__PAGE__.segment.rsc +5 -5
  53. package/.next/server/app-paths-manifest.json +11 -11
  54. package/.next/server/chunks/3048.js +264 -0
  55. package/.next/server/chunks/42.js +1 -1
  56. package/.next/server/chunks/6429.js +1 -1
  57. package/.next/server/chunks/7180.js +22 -0
  58. package/.next/server/middleware-build-manifest.js +1 -1
  59. package/.next/server/middleware.js +4 -4
  60. package/.next/server/pages/404.html +1 -1
  61. package/.next/server/pages/500.html +1 -1
  62. package/.next/server/preview-props.json +3 -3
  63. package/.next/server/server-reference-manifest.json +1 -1
  64. package/.next/static/chunks/3449-773a78c2b25dadd5.js +260 -0
  65. package/.next/static/chunks/8477-e7cabb053e63e504.js +22 -0
  66. package/.next/static/chunks/app/page-1ea50af93da7d407.js +22 -0
  67. package/.next/static/chunks/app/smoke/{page-7226fa31540df8a8.js → page-bad59997a18b33e8.js} +2 -2
  68. package/.next/static/chunks/app/smoke/session-stream/{page-ed9bc29486c9e75d.js → page-9f43d950df17f1d3.js} +2 -2
  69. package/.next/static/css/be5cdd302b05dc22.css +1 -0
  70. package/README.md +1 -1
  71. package/package.json +1 -1
  72. package/.next/server/chunks/4801.js +0 -22
  73. package/.next/server/chunks/8305.js +0 -264
  74. package/.next/static/chunks/6630-afa0ca63437a28c6.js +0 -22
  75. package/.next/static/chunks/9867-9e590871a9f2b1b9.js +0 -260
  76. package/.next/static/chunks/app/page-46021c793e1b09a3.js +0 -22
  77. package/.next/static/css/d68ecb6695873888.css +0 -1
  78. /package/.next/static/{Ag1v_S9DTKxBH3_0fOnfG → 33lxcaITML1UfRwyCMnDs}/_buildManifest.js +0 -0
  79. /package/.next/static/{Ag1v_S9DTKxBH3_0fOnfG → 33lxcaITML1UfRwyCMnDs}/_ssgManifest.js +0 -0
@@ -0,0 +1,22 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8974],{43322:(e,t,r)=>{Promise.resolve().then(r.bind(r,99317))},99317:(e,t,r)=>{"use strict";r.d(t,{AppShell:()=>n0});var n=r(95155),o=r(12115),i=r(73321);function l(e,t=Date.now()){let r=new Date(e).getTime();if(!Number.isFinite(r))return"";let n=t-r,o=Math.floor(n/6e4),i=Math.floor(n/36e5),s=Math.floor(n/864e5);return o<1?"just now":o<60?`${o}m ago`:i<24?`${i}h ago`:s<7?`${s}d ago`:new Date(r).toLocaleDateString()}function s(e,t){let r=t&&e.startsWith(t)?`~${e.slice(t.length)}`:e,n=r.includes("/")?"/":"\\",o=r.split(n).filter(Boolean);return o.length<=2?r:`…/${o.slice(-2).join(n)}`}function a(e,t){if(!e)return"No Project";let r=e.replace(/[\\/]+$/,""),n=r.includes("/")?"/":"\\";return r.split(n).filter(Boolean).pop()||s(e,t)}function d(e,t=Math.random){return e+(2*t()-1)*(.2*e)}function c({node:e,selectedSessionId:t,onSelectSession:r,onRenamed:i,onSessionDeleted:l,depth:s,runningSessionIds:a}){let[d,p]=(0,o.useState)(!1),h=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)(u,{session:e.session,isSelected:e.session.id===t,onClick:()=>r(e.session),onRenamed:i,onDeleted:e=>l?.(e),depth:s,hasChildren:h,collapsed:d,onToggleCollapse:()=>p(e=>!e),isRunning:a.has(e.session.id)})]}),h&&!d&&(0,n.jsx)("div",{children:e.children.map(e=>(0,n.jsx)(c,{node:e,selectedSessionId:t,onSelectSession:r,onRenamed:i,onSessionDeleted:l,depth:s+1,runningSessionIds:a},e.session.id))})]})}function u({session:e,isSelected:t,onClick:r,onRenamed:i,onDeleted:s,depth:a=0,hasChildren:d=!1,collapsed:c=!1,onToggleCollapse:p,isRunning:h=!1}){let[x,g]=(0,o.useState)(!1),[f,v]=(0,o.useState)(!1),[m,b]=(0,o.useState)(""),[y,j]=(0,o.useState)(!1),[k,w]=(0,o.useState)(!1),S=(0,o.useRef)(null),C=e.name||e.firstMessage.slice(0,50)||e.id.slice(0,12),T=(0,o.useCallback)(t=>{t.stopPropagation(),b(e.name??""),v(!0),setTimeout(()=>S.current?.select(),0)},[e.name]),z=(0,o.useCallback)(async()=>{let t=m.trim();if(v(!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{}},[m,e.id,e.name,i]),I=(0,o.useCallback)(e=>{e.stopPropagation(),j(!0)},[]),M=(0,o.useCallback)(async t=>{t.stopPropagation(),j(!1),w(!0);try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"DELETE"}),s?.(e.id)}catch{w(!1)}},[e.id,s]),R=(0,o.useCallback)(e=>{e.stopPropagation(),j(!1)},[]);return(0,n.jsx)("div",{onClick:y||f?void 0:r,onMouseEnter:()=>g(!0),onMouseLeave:()=>{g(!1)},style:{display:"flex",alignItems:"center",padding:"7px 8px",paddingLeft:a>0?12*a+14:14,paddingRight:8,cursor:y||f?"default":"pointer",background:y?"rgba(239,68,68,0.06)":t?"var(--bg-selected)":x?"var(--bg-hover)":"transparent",borderLeft:y?"2px solid #ef4444":t?"2px solid var(--accent)":"2px solid transparent",transition:"background 0.1s",opacity:k?.5:1,gap:6,overflow:"hidden"},children:y?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0,fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["Delete ",(0,n.jsxs)("span",{style:{fontWeight:600},children:["“",C.slice(0,22),C.length>22?"…":"","”"]}),"?"]}),(0,n.jsxs)("div",{style:{display:"flex",gap:5,flexShrink:0},children:[(0,n.jsxs)("button",{onClick:M,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,height:30,padding:"0 11px",background:"#ef4444",border:"none",borderRadius:6,color:"#fff",cursor:"pointer",fontSize:12,fontWeight:600,whiteSpace:"nowrap"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,n.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,n.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,n.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]}),"Delete"]}),(0,n.jsx)("button",{onClick:R,style:{display:"flex",alignItems:"center",justifyContent:"center",height:30,padding:"0 11px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:500,whiteSpace:"nowrap"},children:"Cancel"})]})]}):f?(0,n.jsx)("input",{ref:S,value:m,onChange:e=>b(e.target.value),onBlur:z,onKeyDown:e=>{"Enter"===e.key&&z(),"Escape"===e.key&&v(!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:[a>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===a&&(0,n.jsx)("span",{"aria-hidden":"true",style:{width:h?7:5,height:h?7:5,borderRadius:"50%",background:h?"#22c55e":t?"var(--accent)":"var(--text-dim)",opacity:t?1:.35,flexShrink:0,...h?{boxShadow:"0 0 6px rgba(34,197,94,0.5)",animation:"pulse 2s infinite"}:{}}}),(0,n.jsxs)("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:1},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:t?600:500,lineHeight:"18px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text)"},title:C,children:C}),(0,n.jsxs)("div",{style:{display:"flex",gap:8,color:"var(--text-dim)",fontSize:11},children:[(0,n.jsx)("span",{title:e.modified,children:l(e.modified)}),(0,n.jsxs)("span",{children:[e.messageCount," msgs"]}),!1===e.cwdExists&&(0,n.jsx)("span",{title:`Project path missing: ${e.cwd}`,style:{color:"#f87171"},children:"missing path"})]})]}),d&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),p?.()},title:c?"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:c?"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"})})}),x&&(0,n.jsxs)("div",{style:{display:"flex",gap:4,flexShrink:0},children:[(0,n.jsx)("button",{onClick:T,title:"Rename",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-selected)",e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"})})}),(0,n.jsx)("button",{onClick:I,title:"Delete",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.08)",e.currentTarget.style.color="#ef4444",e.currentTarget.style.borderColor="rgba(239,68,68,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,n.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,n.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,n.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]})})]})]})})}function p({pinned:e,onToggle:t}){return(0,n.jsx)("button",{type:"button",onClick:t,title:e?"Unpin project":"Pin project to sidebar",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:"auto",padding:0,border:"1px solid var(--border)",borderRadius:7,background:e?"rgba(234,179,8,0.12)":"var(--bg-hover)",color:e?"#ca8a04":"var(--text-muted)",cursor:"pointer",flexShrink:0},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:e?"currentColor":"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})})}function h({project:e,homeDir:t,isCurrent:r,onSelect:i,onTogglePinned:l}){let[s,d]=(0,o.useState)(!1),c=e.displayName||a(e.cwd,t);return(0,n.jsxs)("div",{onMouseEnter:()=>d(!0),onMouseLeave:()=>d(!1),style:{display:"flex",alignItems:"center",gap:4,background:r?"var(--bg-selected)":s?"var(--bg-hover)":"none",borderBottom:"1px solid var(--border)"},children:[(0,n.jsx)("span",{style:{width:10,marginLeft:6,flexShrink:0}}),(0,n.jsxs)("button",{type:"button",onClick:i,title:e.cwd,style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:7,padding:"8px 10px 8px 0",background:"none",border:"none",color:r?"var(--text)":"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11,fontFamily:"var(--font-mono)"},children:[r?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c}),!e.exists&&(0,n.jsx)("span",{style:{flexShrink:0,color:"#f87171",fontSize:10},children:"missing"})]}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),l()},title:"Pin to sidebar",tabIndex:s?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,marginRight:4,padding:0,border:"none",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,opacity:+!!s,pointerEvents:s?"auto":"none"},children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})})]})}function x({dropdownRef:e,open:t,onToggle:r,onClose:o,effectiveCwd:i,effectiveName:l,projects:a,homeDir:d,onChooseProject:c,onTogglePinned:u}){return(0,n.jsxs)("div",{ref:e,style:{position:"relative",marginTop:8,padding:"0 10px",display:"flex",alignItems:"stretch",gap:4},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>r(),style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:6,padding:"6px 10px",background:i?"var(--bg-hover)":"rgba(37,99,235,0.06)",border:i?"1px solid var(--border)":"1px solid rgba(37,99,235,0.4)",borderRadius:7,cursor:"pointer",fontSize:12,color:"var(--text)",textAlign:"left"},title:i??"Select project",className:"sidebar-project-trigger",children:[(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.35",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:"var(--accent)"},children:(0,n.jsx)("path",{d:"M1.5 5A1.5 1.5 0 0 1 3 3.5h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6.5L13.6 11A1.5 1.5 0 0 1 12.1 12.5H3A1.5 1.5 0 0 1 1.5 11V5Z"})}),(0,n.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)",fontSize:11,color:i?"var(--text)":"var(--text-dim)"},children:i?a.find(e=>e.cwd===i)?.displayName??l??s(i,d):"Select project…"}),(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:t?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),i&&(0,n.jsx)(p,{pinned:a.find(e=>e.cwd===i)?.pinned===!0,onToggle:()=>u(i,a.find(e=>e.cwd===i)?.pinned!==!0)}),t&&(0,n.jsxs)("div",{style:{position:"absolute",top:"calc(100% + 4px)",left:10,right:10,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 6px 20px rgba(0,0,0,0.10)",overflow:"hidden",maxHeight:280,overflowY:"auto"},children:[0===a.length&&(0,n.jsx)("div",{style:{padding:"10px 12px",color:"var(--text-dim)",fontSize:11},children:"No projects yet"}),a.map(e=>{let t=e.cwd===i;return(0,n.jsx)(h,{project:e,homeDir:d,isCurrent:t,onSelect:()=>{c(e.cwd),o()},onTogglePinned:()=>u(e.cwd,!0!==e.pinned)},e.cwd)})]})]})}function g(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 f(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 v({open:e,cwd:t,homeDir:r,onClose:i,onSelectSession:l}){let[s,a]=(0,o.useState)(""),[d,c]=(0,o.useState)("current"),[u,p]=(0,o.useState)([]),[h,x]=(0,o.useState)(!1),[m,b]=(0,o.useState)(null),[y,j]=(0,o.useState)(!1),k=(0,o.useRef)(null);if((0,o.useEffect)(()=>{e&&(c(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=s.trim();if(r.length<2){p([]),x(!1),b(null),j(!1);return}let n=new AbortController,o=setTimeout(async()=>{x(!0),b(null);try{let e=new URLSearchParams({q:r,scope:d});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);p(i.results??[]),j(i.truncated??!1)}catch(e){"AbortError"!==e.name&&b(String(e))}finally{x(!1)}},180);return()=>{clearTimeout(o),n.abort()}},[e,s,d,t]),!e)return null;let w=s.trim(),S=u.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:s,onChange:e=>a(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:()=>c(e.value),style:{height:24,padding:"0 9px",background:d===e.value?"var(--bg-selected)":"transparent",border:"none",borderRadius:5,color:e.disabled?"var(--text-dim)":d===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"===d&&t?g(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&&h&&0===u.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&&!h&&!m&&0===u.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"No matching conversations found."}),u.map(e=>(0,n.jsxs)("div",{style:{borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{l(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:f(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:g(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:()=>{l(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:f(t.timestamp)})]}),(0,n.jsx)("div",{style:{fontSize:12,lineHeight:1.45,color:"var(--text-muted)"},children:function(e,t){let r=t.trim();if(!r)return e;let o=e.toLowerCase().indexOf(r.toLowerCase());return o<0?e:(0,n.jsxs)(n.Fragment,{children:[e.slice(0,o),(0,n.jsx)("mark",{style:{background:"rgba(37,99,235,0.16)",color:"var(--text)",borderRadius:3,padding:"0 2px"},children:e.slice(o,o+r.length)}),e.slice(o+r.length)]})}(t.snippet,w)})]},t.entryId))]},e.session.id))]}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",padding:"8px 12px",borderTop:"1px solid var(--border)",color:"var(--text-dim)",fontSize:11},children:[(0,n.jsx)("span",{children:S>0?`${S}${y?"+":""} results`:"Esc to close"}),h&&u.length>0&&(0,n.jsx)("span",{children:"Updating..."})]})]})})}let m="Home";function b(e){return e instanceof Error?e.message:String(e)}function y(e,t){let r=e.crumbs.findIndex(t=>t.path===e.home);if(-1===r)return e.crumbs;let n=e.crumbs.slice(r+1);return[{name:t,path:e.home},...n]}function j(e){return e.home.includes("\\")?"\\":"/"}function k(e,t,r){let n,o,i=-1===(n="\\"===j(e)?Math.max(t.lastIndexOf("\\"),t.lastIndexOf("/")):t.lastIndexOf("/"))?null:t.slice(0,n+1);if(null===i)return{directory:null,tail:null};let l=i===(o=j(e),e.current.endsWith(o)?e.current:`${e.current}${o}`)||null!==r&&r.directory===i&&r.landed===e.current;return{directory:i,tail:l?t.slice(i.length):null}}let w={display:"flex",flexDirection:"column",gap:2,flex:"1 1 0",minWidth:256,overflowY:"auto",paddingRight:8},S={width:"100%",display:"flex",alignItems:"center",gap:5,height:28,flex:"none",padding:"0 6px",border:"none",borderRadius:6,background:"transparent",textAlign:"left",cursor:"pointer",color:"var(--text)",fontSize:12.5,fontFamily:"inherit"},C={background:"var(--bg-selected)"},T={flex:"1 1 0",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:12.5};function z({entries:e,selectedPath:t,busy:r,onPick:o,showHidden:i,filterPrefix:l}){let s,a,d,c=(s=null===l?"":l.toLowerCase(),a=e=>(i||!e.hidden||s.startsWith("."))&&e.name.toLowerCase().startsWith(s),d=""!==s&&e.some(a),e.filter(e=>e.path===t||(d?a(e):i||!e.hidden)));return(0,n.jsx)("div",{style:w,role:"list",children:c.map(e=>{let i=e.path===t;return(0,n.jsxs)("button",{type:"button",role:"listitem","aria-current":i||void 0,disabled:r,onClick:()=>o(e),title:e.path,style:{...S,...i?C:null},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",style:{flexShrink:0,color:i?"var(--accent)":"var(--text-muted)"},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:T,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:{flexShrink:0,color:"var(--text-dim)"},children:(0,n.jsx)("polyline",{points:"3.5 2 6.5 5 3.5 8"})})]},e.path)})})}function I({open:e,initialPath:t,onClose:r,onSelect:i}){let[l,s]=(0,o.useState)(null),[a,d]=(0,o.useState)(null),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(!1),[x,g]=(0,o.useState)(!1),[f,v]=(0,o.useState)(0),[w,S]=(0,o.useState)(null),[C,T]=(0,o.useState)(null),[M,R]=(0,o.useState)(!1),[L,W]=(0,o.useState)(null),[E,P]=(0,o.useState)(!1),[$,D]=(0,o.useState)(null),N=(0,o.useRef)(0),A=(0,o.useRef)(null),O=(0,o.useRef)(0),B=(0,o.useRef)(!1),H=(0,o.useRef)(!1),F=(0,o.useRef)(null),U=(0,o.useRef)({parent:null,child:null}),q=(0,o.useRef)(null),_=(0,o.useRef)(null);(0,o.useEffect)(()=>{U.current={parent:l,child:c}},[l,c]),(0,o.useEffect)(()=>()=>{N.current+=1,O.current+=1,A.current?.abort()},[]);let J=(0,o.useCallback)((e,t)=>fetch(e?`/api/projects/browse?dir=${encodeURIComponent(e)}`:"/api/projects/browse",{signal:t}).then(async e=>{let t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);return t}),[]),K=(0,o.useCallback)(()=>(A.current?.abort(),A.current=null,++N.current),[]),V=(0,o.useCallback)(()=>{g(!1),v(e=>e+1)},[]),Y=(0,o.useCallback)(e=>{let t=K(),r=new AbortController;return A.current=r,V(),{seq:t,scan:J(e,r.signal)}},[K,V,J]),G=(0,o.useCallback)(e=>{let t=new AbortController;return A.current=t,V(),J(e,t.signal)},[V,J]),X=(0,o.useCallback)((e,t)=>{let r=t?.closeEditor??!1,n=t?.announce??!1,{seq:o,scan:i}=Y(e);h(!0),n&&S(null);let l=()=>{(h(!1),r)?T(null):S(null)};i.then(t=>{if(o!==N.current)return;r||void 0===e||(F.current={directory:e,landed:t.current});let n=!1,i=()=>{n||o!==N.current||(n=!0,s(t),d(null),u(null),l())};if(y(t,"").length<2)return void i();let a=t.crumbs.at(-2);void 0===a?i():(G(a.path).then(e=>{if(o!==N.current)return;let r=j(e),a=e=>"\\"===r?e.toLowerCase():e,c=e.directories.find(e=>a(e.path)===a(t.current));void 0===c?i():(n=!0,s(e),d(c),u(t),l())},()=>{i()}),r&&window.setTimeout(i,200))},e=>{o===N.current&&(h(!1),n&&S(b(e)))})},[Y,G]),Z=(0,o.useCallback)(e=>{X(e,{closeEditor:!0,announce:!0})},[X]),Q=(0,o.useCallback)(e=>{let{seq:t,scan:r}=Y(e.path);null!==C&&T(null),d(e),u(null),h(!0),S(null),r.then(e=>{t===N.current&&(u(e),h(!1))},e=>{t===N.current&&(h(!1),S(b(e)),d(null))})},[Y,C]),ee=(0,o.useCallback)(e=>{null!==c&&(s(c),Q(e))},[c,Q]),et=(0,o.useCallback)(e=>{X(e,{closeEditor:!1,announce:!1})},[X]),er=(0,o.useCallback)(()=>{K(),h(!1),T(null),S(null),null===c&&d(null),null===l&&Z()},[K,c,l,Z]);(0,o.useEffect)(()=>{if(O.current+=1,e){s(null),d(null),u(null),P(!1),R(!1),Z(t??void 0);return}K(),h(!1),S(null),T(null),W(null),D(null)},[e,Z,K,t]),(0,o.useEffect)(()=>{if(!p)return void g(!1);let e=window.setTimeout(()=>{g(!0)},300);return()=>{window.clearTimeout(e)}},[p,f]),(0,o.useEffect)(()=>{if(null===C)return;let e=window.setTimeout(()=>{if(H.current)return;let e=U.current.child??U.current.parent;if(null===e)return;let{directory:t,tail:r}=k(e,C,F.current);null!==t&&null===r&&et(t)},250);return()=>{window.clearTimeout(e)}},[C,et]),(0,o.useEffect)(()=>{if(!e)return;let t=e=>{if("Escape"===e.key){if(null!==L){E||W(null);return}if(null!==C){e.stopPropagation(),er();return}r()}};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[r,e,C,L,E,er]);let en=c??l,eo=null===en?[]:y(en,m),ei=eo.at(-1)?.path,el=c?.current,es=a?.path??l?.current??null;(0,o.useEffect)(()=>{let e=q.current;null!==e&&(e.scrollLeft=e.scrollWidth)},[ei]),(0,o.useEffect)(()=>{let e=_.current;null!==e&&void 0!==el&&(e.scrollLeft=e.scrollWidth)},[el]);let ea=(0,o.useCallback)(()=>{if(null===es||null===L||E||""===L.trim())return;P(!0),D(null);let e=O.current;fetch("/api/projects/browse",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dir:es,name:L})}).then(async e=>{let t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);if("string"!=typeof t.path)throw Error("No path returned");return t.path}).then(t=>{if(e!==O.current)return;P(!1),W(null);let{seq:r,scan:n}=Y(es);h(!0),S(null),n.then(e=>{r===N.current&&(s(e),h(!1),Q({name:L,path:t,hidden:L.startsWith(".")}))},e=>{r===N.current&&(h(!1),S(b(e)))})},t=>{e===O.current&&(P(!1),D(b(t)))})},[es,L,E,Y,Q]),ed={onCompositionStart:()=>{B.current=!0},onCompositionEnd:()=>{B.current=!1}};if(!e)return null;let ec=null!==a,eu=null===en||null===C?null:k(en,C,F.current).tail,ep=a?.name??(null===l?"":y(l,m).at(-1)?.name??l.current),eh=null!==L||E,ex=null!==C,eg=en?.drives??[],ef=en?j(en):"/";return(0,n.jsxs)("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(680px, 100%)",height:"min(500px, calc(100dvh - 32px))",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:{display:"flex",flexDirection:"column",gap:8,flex:"none",padding:"16px 14px 8px 24px",borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",minHeight:24},children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:15,fontWeight:700},children:"Select project path"}),(0,n.jsx)("button",{type:"button",onClick:r,"aria-label":"Close",title:"Close",style:{width:28,height:28,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:18,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:"\xd7"})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4,boxSizing:"border-box",minHeight:26,marginLeft:-9,padding:"0 8px",border:`1px solid ${null!==C?"var(--border)":"transparent"}`,borderRadius:8},children:[eg.length>0&&(0,n.jsxs)("select",{value:eg.find(e=>(en?.current??"").toLowerCase().startsWith(e.toLowerCase()))??"",onChange:e=>{e.target.value&&Z(e.target.value)},disabled:eh,title:"Drive",style:{height:24,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text-muted)",fontSize:11,maxWidth:72},children:[(0,n.jsx)("option",{value:"",children:"Drive"}),eg.map(e=>(0,n.jsx)("option",{value:e,children:e},e))]}),null===C?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{ref:q,role:"navigation",style:{display:"flex",alignItems:"center",gap:4,flex:"0 1 auto",minWidth:0,overflowX:"auto",scrollbarWidth:"none"},children:eo.map((e,t)=>(0,n.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:4,flex:"none",minWidth:0},children:[t>0&&(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,color:"var(--text-dim)"},children:(0,n.jsx)("polyline",{points:"3.5 2 6.5 5 3.5 8"})}),(0,n.jsx)("button",{type:"button",disabled:eh,onClick:()=>Z(e.path),title:e.path,style:{border:"none",background:"transparent",padding:0,maxWidth:160,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)",fontSize:12,color:"var(--text-muted)",cursor:"pointer"},children:e.name})]},e.path))}),(0,n.jsx)("button",{type:"button","aria-label":"Edit path",title:"Edit path",disabled:eh,onClick:()=>{if(K(),h(!1),H.current=!1,null===l)return void T("");let e=a?.path??l.current;T(e.endsWith(ef)?e:`${e}${ef}`)},style:{display:"flex",alignItems:"center",justifyContent:"flex-end",flex:"1 0 34px",minWidth:34,height:22,padding:0,border:"none",background:"transparent",cursor:"text"},children:(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)"},children:(0,n.jsx)("path",{d:"M11.3 2.2a1.9 1.9 0 0 1 2.5 2.5L6 12.5 2.5 13.5 3.5 10l7.8-7.8Z"})})})]}):(0,n.jsx)("input",{value:C,autoFocus:!0,"aria-label":"Edit path",disabled:eh,spellCheck:!1,onChange:e=>{K(),h(!1),H.current=!1,T(e.target.value)},...ed,onKeyDown:e=>{"Enter"!==e.key||B.current||(e.preventDefault(),""!==C.trim()&&(H.current=!0,Z(C)))},onBlur:e=>{if(null===C||!document.hasFocus())return;let t=e.currentTarget.closest('[role="dialog"]');null===t||e.relatedTarget instanceof Node&&t.contains(e.relatedTarget)||er()},style:{boxSizing:"border-box",flex:"1 1 0",minWidth:0,height:22,padding:0,border:"none",outline:"none",background:"transparent",fontFamily:"var(--font-mono)",fontSize:12,color:"var(--text)"}})]})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",flex:"1 1 0",minHeight:0,position:"relative",padding:"16px 16px 16px 24px"},children:[(0,n.jsxs)("div",{ref:_,style:{display:"flex",alignItems:"stretch",flex:"1 1 0",minHeight:0,gap:12,overflowX:"auto",scrollbarWidth:"none"},children:[null!==l&&(0,n.jsx)(z,{entries:l.directories,selectedPath:a?.path??null,busy:eh,onPick:Q,showHidden:M,filterPrefix:null===c?eu:null}),ec&&(0,n.jsx)("span",{style:{flex:"none",width:1,background:"var(--border)"}}),ec&&null!==c&&(0,n.jsx)(z,{entries:c.directories,selectedPath:null,busy:eh,onPick:ee,showHidden:M,filterPrefix:eu})]}),p&&x&&(0,n.jsx)("div",{role:"status",style:{position:"absolute",right:16,bottom:8,padding:"2px 8px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",fontSize:11},children:"Loading…"}),(l?.truncated===!0||c?.truncated===!0)&&(0,n.jsx)("div",{role:"status",style:{padding:"4px 4px 4px 0",color:"var(--text-muted)",fontSize:11},children:"Large directory — list may be incomplete"}),null!==w&&(0,n.jsx)("div",{role:"alert",style:{padding:"4px 4px 4px 0",color:"#f87171",fontSize:11},children:w})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",flexWrap:"wrap",gap:8,flex:"none",padding:"14px 24px",borderTop:"1px solid var(--border)"},children:[(0,n.jsxs)("button",{type:"button",disabled:null===l||p||eh||ex,onClick:()=>{W(""),D(null)},style:{display:"inline-flex",alignItems:"center",gap:5,height:30,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:null===l||p||eh||ex?"var(--text-dim)":"var(--text-muted)",cursor:null===l||p||eh||ex?"default":"pointer",fontSize:12},children:[(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M8 3v10M3 8h10"})}),"New folder"]}),(0,n.jsxs)("button",{type:"button","aria-pressed":M,disabled:eh,onClick:()=>R(e=>!e),style:{display:"inline-flex",alignItems:"center",gap:4,border:"none",background:"transparent",padding:0,fontSize:12,fontWeight:500,color:M?"var(--text)":"var(--text-muted)",cursor:"pointer",whiteSpace:"nowrap"},children:["Show hidden files",M&&(0,n.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"2.5 8.5 6 12 13.5 4.5"})})]}),(0,n.jsx)("div",{style:{flex:"1 1 0"}}),(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",disabled:null===es||p||eh||ex,onClick:()=>{null!==es&&i(es)},style:{height:32,padding:"0 14px",border:"none",borderRadius:6,background:null===es||p||eh||ex?"var(--bg-hover)":"var(--accent)",color:null===es||p||eh||ex?"var(--text-dim)":"#fff",cursor:null===es||p||eh||ex?"default":"pointer",fontSize:12,fontWeight:650},children:"Open"})]})]}),null!==L&&(0,n.jsx)("div",{onMouseDown:e=>{e.target!==e.currentTarget||E||W(null)},style:{position:"fixed",inset:0,zIndex:1300,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.25)"},children:(0,n.jsxs)("div",{style:{width:"min(380px, 100%)",display:"flex",flexDirection:"column",gap:12,padding:"20px 24px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 12px 40px rgba(0,0,0,0.3)"},children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:15,fontWeight:700},children:"New folder"}),(0,n.jsxs)("div",{style:{color:"var(--text)",fontSize:12.5},children:["in ",(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text-muted)"},children:ep})]}),(0,n.jsx)("input",{value:L,"aria-label":"Folder name",placeholder:"untitled folder",autoFocus:!0,disabled:E,spellCheck:!1,onChange:e=>W(e.target.value),...ed,onKeyDown:e=>{"Enter"!==e.key||B.current||(e.preventDefault(),ea()),"Escape"!==e.key||E||(e.stopPropagation(),W(null))},style:{boxSizing:"border-box",width:"100%",height:36,padding:"0 12px",border:"1px solid var(--border)",borderRadius:8,outline:"none",background:"var(--bg-panel)",fontSize:13,color:"var(--text)"}}),null!==$&&(0,n.jsx)("div",{role:"alert",style:{color:"#f87171",fontSize:11},children:$}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:8},children:[(0,n.jsx)("button",{type:"button",disabled:E,onClick:()=>W(null),style:{height:30,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",disabled:E||""===L.trim(),onClick:ea,style:{height:30,padding:"0 14px",border:"none",borderRadius:6,background:E||""===L.trim()?"var(--bg-hover)":"var(--accent)",color:E||""===L.trim()?"var(--text-dim)":"#fff",cursor:E||""===L.trim()?"default":"pointer",fontSize:12,fontWeight:650},children:E?"Creating…":"Create"})]})]})})]})}let M="AnnoVibe";var R=r(16865);let L="annovibe:sidebar:collapsed-projects",W="annovibe:sidebar:collapsed-projects:init-v3";function E(e){window.localStorage.setItem(L,JSON.stringify([...e]))}async function P(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 $(e){return new DOMException(e,"TimeoutError")}function D(e,t){return e instanceof DOMException&&("AbortError"===e.name||"TimeoutError"===e.name)||e instanceof Error&&/aborted without reason|AbortError/i.test(e.message)?t:e instanceof Error?e.message:String(e)}let N="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";function A(){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:N[Math.floor(Math.random()*N.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.147":M,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 O({selectedSessionId:e,onSelectSession:t,onNewSession:r,initialSessionId:i,onInitialRestoreDone:l,restoreSessionId:s,onRestoreSessionDone:u,refreshKey:p,onSessionDeleted:h,selectedCwd:g,onCwdChange:f}){let[m,b]=(0,o.useState)([]),[y,j]=(0,o.useState)({}),[k,w]=(0,o.useState)(()=>new Set),S=(0,o.useRef)(!1),[C,T]=(0,o.useState)(!0),[z,M]=(0,o.useState)(!1),[N,H]=(0,o.useState)(null),[F,U]=(0,o.useState)(null),[q,_]=(0,o.useState)(""),[J,K]=(0,o.useState)(null),[V,Y]=(0,o.useState)(!1),[G,X]=(0,o.useState)("project"),[Z,Q]=(0,o.useState)(!1),[ee,et]=(0,o.useState)(()=>new Set),[er,en]=(0,o.useState)(()=>(function(){try{let e=window.localStorage.getItem(L)??window.localStorage.getItem("pidex:sidebar:collapsed-projects");return e?new Set(JSON.parse(e)):new Set}catch{return new Set}})()),[eo,ei]=(0,o.useState)(null),[el,es]=(0,o.useState)(null),[ea,ed]=(0,o.useState)(null),[ec,eu]=(0,o.useState)(!1),ep=(0,o.useRef)(null),eh=(0,o.useRef)(!1),ex=(0,o.useRef)(!1),eg=(0,o.useRef)(!1),ef=(0,o.useRef)(new Map),ev=(0,o.useRef)(new Map),em=(0,o.useRef)({revision:null,seq:0,retry:0,inFlight:!1}),eb=(0,o.useRef)({}),ey=(0,o.useRef)({}),ej=(0,o.useRef)({}),ek=(0,o.useRef)(new Set);function ew(e){let t=eb.current[e];return t||(t={revision:null,seq:0,retry:0,inFlight:!1},eb.current[e]=t),t}let eS=(0,o.useCallback)((e,t,r)=>{let n=ey.current[e];n&&clearTimeout(n),ey.current[e]=setTimeout(()=>{ey.current[e]=null,r()},function(e,t=Math.random){let r=[250,500,1e3,2e3][Math.min(Math.max(e,0),3)]??2e3;return t()*r}(t))},[]),eC=(0,o.useCallback)((e,t)=>{let r=ej.current[e];r&&clearTimeout(r),ej.current[e]=setTimeout(()=>{ej.current[e]=null,t()},120)},[]),eT=(0,o.useCallback)(async(e=!1,t={})=>{let r=em.current,n=++r.seq;r.inFlight=!0;try{let o;e&&T(!0);let i=new AbortController;try{o=setTimeout(()=>i.abort($("Project loading timed out")),6e4);let e=t.force?"/api/projects?force=1":"/api/projects",l=await fetch(e,{signal:i.signal});if(!l.ok)throw Error(await P("projects",l));let s=await l.json();if(n!==r.seq)return;if(s.stale)return void eS("projects",r.retry++,()=>void eT(!1));r.retry=0,s.revision&&(r.revision=s.revision),b(s.projects),H(null)}finally{clearTimeout(o)}}catch(t){if(n!==r.seq)return;let e=D(t,"Loading projects timed out. Codex may still be starting; click Refresh to retry.");H(e),eS("projects",r.retry++,()=>void eT(!1))}finally{n===r.seq&&(r.inFlight=!1),e&&T(!1)}},[eS]),ez=(0,o.useCallback)(async(e,t=!1,r={})=>{if(!e)return;let n=ef.current.get(e);if(n)return n;let o=(async()=>{let n=ew(e),o=++n.seq;n.inFlight=!0,j(t=>({...t,[e]:{sessions:t[e]?.sessions??[],loaded:t[e]?.loaded??!1,error:null,loading:!0,stale:t[e]?.stale??!1}}));try{let i;t&&T(!0);let l=new AbortController;try{i=setTimeout(()=>l.abort($("Chat loading timed out")),6e4);let t=ev.current.get(e)??50,s=`&limit=${t}`,a=r.force?`/api/sessions?cwd=${encodeURIComponent(e)}&force=1${s}`:`/api/sessions?cwd=${encodeURIComponent(e)}${s}`,d=await fetch(a,{signal:l.signal});if(!d.ok)throw Error(await P("sessions",d));let c=await d.json();if(o!==n.seq)return;if(c.runningSessionIds&&!S.current&&w(new Set(c.runningSessionIds)),c.stale){j(t=>({...t,[e]:{sessions:t[e]?.sessions??[],loaded:t[e]?.loaded??!1,loading:!1,error:null,stale:(t[e]?.sessions?.length??0)>0,total:t[e]?.total,hasMore:t[e]?.hasMore}})),eS(`cwd:${e}`,n.retry++,()=>void ez(e,!1));return}n.retry=0,c.revision&&(n.revision=c.revision),ek.current.add(e),j(t=>({...t,[e]:{sessions:c.sessions,loaded:!0,loading:!1,error:null,stale:!1,total:c.total,hasMore:c.hasMore}}))}finally{clearTimeout(i)}}catch(r){if(o!==n.seq)return;let t=D(r,"Loading chats timed out. Codex may still be starting; click Refresh to retry.");j(r=>({...r,[e]:{sessions:r[e]?.sessions??[],loaded:r[e]?.loaded??!1,loading:!1,error:t,stale:(r[e]?.sessions?.length??0)>0,total:r[e]?.total,hasMore:r[e]?.hasMore}})),eS(`cwd:${e}`,n.retry++,()=>void ez(e,!1))}finally{o===n.seq&&(n.inFlight=!1),t&&T(!1),ef.current.delete(e)}})();return ef.current.set(e,o),o},[eS]),eI=(0,o.useCallback)(async()=>{let e=em.current;if(e.inFlight)return;let t=e.revision?`/api/projects?fingerprint=1&revision=${encodeURIComponent(e.revision)}`:"/api/projects?fingerprint=1";try{let r=await fetch(t);if(!r.ok)throw Error(await P("projects",r));let n=await r.json();if(n.stale)return void eS("projects",e.retry++,()=>void eI());if(!0===n.unchanged)return;eT(!1)}catch{eS("projects",e.retry++,()=>void eI())}},[eT,eS]),eM=(0,o.useCallback)(async e=>{let t=ew(e);if(t.inFlight)return;let r=t.revision?`/api/sessions?cwd=${encodeURIComponent(e)}&fingerprint=1&revision=${encodeURIComponent(t.revision)}`:`/api/sessions?cwd=${encodeURIComponent(e)}&fingerprint=1`;try{let n=await fetch(r);if(!n.ok)throw Error(await P("sessions",n));let o=await n.json();if(o.stale)return void eS(`cwd:${e}`,t.retry++,()=>void eM(e));if(!0===o.unchanged)return;ez(e,!1)}catch{eS(`cwd:${e}`,t.retry++,()=>void eM(e))}},[ez,eS]),eR=(0,o.useRef)(!1);(0,o.useEffect)(()=>{let e=!eR.current;eR.current=!0,eT(e)},[eT,p]),(0,o.useEffect)(()=>{fetch("/api/home").then(e=>e.json()).then(e=>{e.home&&_(e.home)}).catch(()=>{})},[]);let eL=(0,o.useRef)(!1);(0,o.useEffect)(()=>{if(eh.current){eh.current=!1;return}if(ex.current){ex.current=!1;return}f?.(F)},[F,f]);let eW=(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 K(n.error??`HTTP ${r.status}`),null;return eT(!1),n.project?.cwd??e}catch(e){return K(e instanceof Error?e.message:String(e)),null}},[eT]),eE=(0,o.useCallback)(e=>{fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,touch:!0})}).catch(()=>{})},[]),eP=(0,o.useCallback)(e=>{ex.current=!0,ev.current.set(e,50),U(e),K(null),en(t=>{if(!t.has(e))return t;let r=new Set(t);return r.delete(e),E(r),r}),f?.(e),eE(e),ez(e,!1)},[ez,f,eE]),e$=(0,o.useCallback)(e=>{let t=(ev.current.get(e)??50)+50;ev.current.set(e,t),ez(e,!1)},[ez]);(0,o.useEffect)(()=>{if(0!==m.length&&null===F){if(i&&!eL.current){eL.current=!0;let e=Object.values(y).flatMap(e=>e.sessions).find(e=>e.id===i);if(e){U(e.cwd),eE(e.cwd),t(e,!0);return}fetch(`/api/sessions/${encodeURIComponent(i)}?infoOnly=1`).then(e=>e.ok?e.json():null).then(e=>{e?.info?(U(e.info.cwd),eE(e.info.cwd),t(e.info,!0)):l?.()}).catch(()=>l?.());return}let e=m[0]?.cwd;e&&(U(e),eE(e))}},[m,F,i,t,l,y,eE]);let eD=(0,o.useRef)(null);(0,o.useEffect)(()=>{if(!s)return;let e=g??F;if(!e)return;let r=`${e}\0${s}`;if(eD.current===r)return;let n=y[e],o=Object.values(y).flatMap(e=>e.sessions).find(e=>e.id===s);if(!o){if(n?.loaded&&!n.loading&&!n.stale){if(eD.current=r,(n.total??n.sessions.length)<=n.sessions.length)return void u?.();fetch(`/api/sessions/${encodeURIComponent(s)}?infoOnly=1`).then(e=>e.ok?e.json():null).then(r=>{let n=r?.info;n&&n.cwd===e&&(U(n.cwd),eE(n.cwd),t(n,!1)),u?.()}).catch(()=>u?.())}return}eD.current=r,o.cwd!==e||(U(o.cwd),eE(o.cwd),t(o,!1)),u?.()},[s,g,F,y,t,u,eE]);let eN=g??F;(0,o.useEffect)(()=>(0,R.O)(e=>{S.current=!0,w(new Set(e))}),[]);let eA=(0,o.useRef)(null);(0,o.useEffect)(()=>{eA.current=eN},[eN]),(0,o.useEffect)(()=>{let e=new EventSource("/api/session-index/events");return e.onmessage=e=>{let t=null;try{t=JSON.parse(String(e.data))}catch{return}if(t&&"index-invalidated"===t.type&&t.scope){if(("projects"===t.scope||"all-cwds"===t.scope)&&eC("projects",()=>void eI()),"cwd"===t.scope&&t.cwd){let e=t.cwd;eC(`cwd:${e}`,()=>void eM(e))}if("all-cwds"===t.scope)for(let e of ek.current)eC(`cwd:${e}`,()=>void eM(e))}},e.onerror=()=>{},()=>e.close()},[eI,eM,eC]),(0,o.useEffect)(()=>{let e=window.setInterval(()=>{eI()},d(3e4));return()=>window.clearInterval(e)},[eI]),(0,o.useEffect)(()=>{let e=window.setInterval(()=>{let e=new Set;for(let t of(eA.current&&e.add(eA.current),ek.current))e.add(t);for(let t of e)eM(t)},d(1e4));return()=>window.clearInterval(e)},[eM]),(0,o.useEffect)(()=>{let e=()=>{if("visible"!==document.visibilityState)return;eI();let e=new Set;for(let t of(eA.current&&e.add(eA.current),ek.current))e.add(t);for(let t of e)eM(t)};return document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)},[eI,eM]),(0,o.useEffect)(()=>{let e=()=>{eN&&ez(eN,!1)};return window.addEventListener("session-created",e),()=>window.removeEventListener("session-created",e)},[eN,ez]);let eO=(0,o.useCallback)(e=>{if(!e){X("agent"),Y(!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]),eB=(0,o.useCallback)(async e=>{let t=await eW(e,!0);t&&(eP(t),Y(!1),K(null),"agent"===G&&eO(t))},[eP,eO,G,eW]),eH=(0,o.useCallback)(()=>{eO(eN)},[eO,eN]),eF=(0,o.useCallback)(()=>{X("project"),K(null),Y(!0)},[]),eU=(0,o.useMemo)(()=>[...eN&&!m.some(e=>e.cwd===eN)?[{cwd:eN,displayName:a(eN,q),chatCount:y[eN]?.total??y[eN]?.sessions.length??0,lastAccessed:null,created:null,pinned:!1,sortOrder:null,exists:!0,source:"manual"}]:[],...m].sort((e,t)=>{let r=!0===e.pinned;if(r!==(!0===t.pinned))return r?-1:1;let n="number"==typeof e.sortOrder?e.sortOrder:Number.MAX_SAFE_INTEGER,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"})}),[eN,q,m,y]),eq=(0,o.useMemo)(()=>{let e=e=>{var t,r;let n,o,i=y[e.cwd],l=[...i?.sessions??[]].sort((e,t)=>(t.modified||"").localeCompare(e.modified||"")),s=i?.loaded?i.total??i.sessions.length:e.chatCount,d=(t=e.lastAccessed,r=i?.loaded?i.sessions[0]?.modified:null,n=t?new Date(t).getTime():-1/0,o=r?new Date(r).getTime():-1/0,Number.isFinite(n)||Number.isFinite(o)?n>=o?t??null:r??null:null);return{project:e,cwd:e.cwd,displayName:e.displayName||a(e.cwd,q),sessions:l,sessionsState:i,chatCount:s??0,lastAccessed:d??""}},t=eU.filter(e=>!0===e.pinned).map(e);if(eN){let r=eU.find(e=>e.cwd===eN);r&&!0!==r.pinned&&t.push(e(r))}return t},[eN,q,y,eU]);(0,o.useEffect)(()=>{if(0===eq.length||eg.current||(eg.current=!0,!eq[0]?.cwd||window.localStorage.getItem(W)))return;let e=new Set(eq.slice(1).map(e=>e.cwd));en(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)?(E(e),e):t),window.localStorage.setItem(W,"1")},[eq]);let e_=(0,o.useCallback)((e,r=!1)=>{e.cwd!==eN&&(eh.current=!0,U(e.cwd)),en(t=>{if(!t.has(e.cwd))return t;let r=new Set(t);return r.delete(e.cwd),E(r),r}),eE(e.cwd),t(e,r)},[t,eN,eE]),eJ=(0,o.useCallback)(e=>{en(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),E(r),r})},[]);(0,o.useEffect)(()=>{for(let e of eq){let t=y[e.cwd];if(!t?.loaded&&!t?.loading){let t=e.cwd===eN,r=er.has(e.cwd);if(!t&&r)continue;ez(e.cwd,!1)}}},[er,eN,ez,eq,y]);let eK=(0,o.useCallback)(e=>{et(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),eV=(0,o.useCallback)(async e=>{ed("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}`);H(null),eT(!1)}catch(e){H(e instanceof Error?e.message:String(e)),eT(!1)}finally{ed(null)}},[eT]),eY=(0,o.useCallback)(async(e,t)=>{ed(`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}`);H(null),eT(!1)}catch(e){H(e instanceof Error?e.message:String(e)),eT(!1)}finally{ed(null)}},[eT]),eG=(0,o.useCallback)((e,t)=>{if(!e||!t||e===t)return;let r=eU.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,eU]),eX=(0,o.useCallback)(async()=>{M(!0);try{await eT(!1,{force:!0});let e=new Set([...Object.entries(y).filter(([,e])=>e.loaded||e.loading).map(([e])=>e),...eN?[eN]:[]]);await Promise.all([...e].map(e=>ez(e,!1,{force:!0})))}finally{M(!1)}},[eN,eT,ez,y]);return(0,o.useEffect)(()=>{if(!ec)return;let e=e=>{ep.current&&!ep.current.contains(e.target)&&eu(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[ec]),(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)(A,{}),(0,n.jsxs)("div",{style:{display:"flex",gap:6,minWidth:0},children:[(0,n.jsxs)("button",{onClick:eH,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:eN?`New chat in ${eN}`:"New chat in a project path",onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-selected)",e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"6",y1:"1",x2:"6",y2:"11"}),(0,n.jsx)("line",{x1:"1",y1:"6",x2:"11",y2:"6"})]}),"New Chat"]}),(0,n.jsx)("button",{onClick:()=>Q(!0),style:{display:"flex",alignItems:"center",justifyContent:"center",background:"var(--bg-hover)",border:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",width:32,height:32,borderRadius:7,padding:0,flexShrink:0,transition:"background 0.12s, color 0.12s, border-color 0.12s"},title:"Search conversations",onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-selected)",e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"7",cy:"7",r:"4.4"}),(0,n.jsx)("path",{d:"M10.4 10.4 13.2 13.2"})]})})]})]})}),(0,n.jsx)(v,{open:Z,cwd:eN,homeDir:q,onClose:()=>Q(!1),onSelectSession:e=>{e_(e)}}),(0,n.jsx)(x,{dropdownRef:ep,open:ec,onToggle:()=>eu(e=>!e),onClose:()=>eu(!1),effectiveCwd:eN,effectiveName:eU.find(e=>e.cwd===eN)?.displayName??null,projects:eU,homeDir:q,onChooseProject:eP,onTogglePinned:(e,t)=>void eY(e,t)}),(0,n.jsxs)("div",{style:{flexShrink:0,padding:"10px 10px 6px"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,fontWeight:600,letterSpacing:"0.05em",textTransform:"uppercase"},children:"Projects"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4,marginLeft:"auto"},children:[(0,n.jsx)("button",{type:"button",onClick:eX,disabled:z,title:"Refresh projects and chats","aria-label":"Refresh projects and chats",style:{width:22,height:22,display:"flex",alignItems:"center",justifyContent:"center",padding:0,border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:z?"var(--accent)":"var(--text-dim)",cursor:z?"default":"pointer",flexShrink:0},children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{animation:z?"spin 0.9s linear infinite":void 0},children:[(0,n.jsx)("path",{d:"M21 12a9 9 0 0 1-15.5 6.2"}),(0,n.jsx)("path",{d:"M3 12A9 9 0 0 1 18.5 5.8"}),(0,n.jsx)("path",{d:"M7 18H5.5v1.5"}),(0,n.jsx)("path",{d:"M17 6h1.5V4.5"})]})}),(0,n.jsx)("button",{type:"button",onClick:eF,title:"New project","aria-label":"New project",style:{width:28,height:28,display:"flex",alignItems:"center",justifyContent:"center",padding:0,border:"none",borderRadius:"50%",background:"transparent",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,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="transparent",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",style:{flexShrink:0,display:"block"},children:[(0,n.jsx)("path",{transform:"translate(9.52 2.52)",d:"M3.55246 0L3.55246 2.44252L6 2.44252L6 3.55748L3.55246 3.55748L3.55246 6L2.43834 6L2.43834 3.55748L0 3.55748L0 2.44252L2.43834 2.44252L2.43834 0L3.55246 0Z",fill:"currentColor"}),(0,n.jsx)("path",{transform:"translate(0.3496 2.35)",d:"M4.76367 0C5.36861 1.80598e-05 5.93113 0.310294 6.25488 0.821289L6.78027 1.64941C6.79685 1.67558 6.81791 1.69775 6.83887 1.71973C6.72186 2.15521 6.65702 2.61192 6.65137 3.08301C6.25601 2.96045 5.90909 2.70478 5.68164 2.3457L5.15723 1.5166C5.07183 1.38189 4.92318 1.3008 4.76367 1.30078L2.32422 1.30078C1.7589 1.30078 1.30078 1.7589 1.30078 2.32422L1.30078 10.1338C1.30078 10.6991 1.7589 11.1572 2.32422 11.1572L11.9766 11.1572C12.5419 11.1572 13 10.6991 13 10.1338L13 8.58398C13.4545 8.5135 13.8903 8.38748 14.3008 8.21289L14.3008 10.1338C14.3008 11.4171 13.2598 12.458 11.9766 12.458L2.32422 12.458C1.04093 12.458 0 11.4171 0 10.1338L0 2.32422C0 1.04093 1.04093 0 2.32422 0L4.76367 0Z",fill:"currentColor"})]})})]})]}),J&&(0,n.jsx)("div",{style:{marginTop:6,color:"#f87171",fontSize:11,lineHeight:1.4,overflowWrap:"anywhere"},children:J})]}),(0,n.jsxs)("div",{style:{flex:"1 1 auto",overflowY:"auto",padding:"6px 8px 8px",minHeight:80,scrollbarWidth:"thin",overscrollBehavior:"contain"},children:[C&&0===m.length&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Loading…"}),N&&(0,n.jsx)("div",{style:{padding:"12px 14px",color:"#f87171",fontSize:12},children:N}),!C&&!N&&0===eq.length&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Open or create a project to start chatting."}),!C&&!N&&eq.map(t=>{let r,o=er.has(t.cwd),i=t.cwd===eN,l=ee.has(t.cwd),s=function(e){let t=new Map;for(let r of e)t.set(r.id,{session:r,children:[]});let r=new Map;for(let t of e)t.parentSessionId&&r.set(t.id,t.parentSessionId);let n=[];for(let e of t.values()){let o=function(e){let n=new Set([e]),o=null,i=r.get(e);for(;i;){if(n.has(i))return null;n.add(i),!o&&t.has(i)&&(o=i),i=r.get(i)}return o}(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),a=s.length,d=s;if(a>10&&!l){d=s.slice(0,10);let t=s.find(t=>(function e(t,r){return!!r&&(t.session.id===r||t.children.some(t=>e(t,r)))})(t,e));t&&!d.includes(t)&&(d=[...d,t])}let u=a-d.length;return(0,n.jsxs)("div",{style:{marginBottom:6,borderTop:el===t.cwd?"2px solid var(--accent)":"2px solid transparent",paddingTop:2*(el===t.cwd),opacity:eo===t.cwd?.55:1},onDragOver:e=>{eo&&eo!==t.cwd&&(e.preventDefault(),e.dataTransfer.dropEffect="move",es(t.cwd))},onDragLeave:()=>{el===t.cwd&&es(null)},onDrop:e=>{e.preventDefault();let r=e.dataTransfer.getData("text/project-cwd")||eo;es(null),ei(null),r&&eG(r,t.cwd)},children:[(0,n.jsx)(B,{group:t,isCurrent:i,isCollapsed:o,isDragging:eo===t.cwd,pinBusy:ea===`pin:${t.cwd}`,onToggle:()=>eJ(t.cwd),onSelect:()=>eP(t.cwd),onTogglePinned:()=>void eY(t.cwd,!0!==t.project.pinned),onDragStart:e=>{ei(t.cwd),e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/project-cwd",t.cwd)},onDragEnd:()=>{ei(null),es(null)}}),!o&&(0,n.jsxs)("div",{style:{marginTop:2,overflow:"hidden",borderRadius:7},children:[(r=t.sessionsState,r?.loading&&!r?.loaded?(0,n.jsx)("div",{style:{width:"100%",padding:"10px 12px",color:"var(--text-dim)",textAlign:"left",fontSize:12,fontStyle:"italic"},children:"Loading chats…"}):r?.error&&!r?.stale?(0,n.jsx)("div",{style:{width:"100%",padding:"10px 12px",color:"#f87171",textAlign:"left",fontSize:12},children:r.error}):0===t.sessions.length?(0,n.jsx)("div",{style:{width:"100%",padding:"10px 12px",color:"var(--text-muted)",textAlign:"left",fontSize:12},children:"No sessions yet. Use New Chat above to start one."}):(0,n.jsxs)(n.Fragment,{children:[r?.stale&&(0,n.jsx)("div",{style:{width:"100%",padding:"4px 12px",color:"var(--text-dim)",textAlign:"left",fontSize:10,fontStyle:"italic"},children:"Showing cached data — refresh failed"}),d.map(r=>(0,n.jsx)(c,{node:r,selectedSessionId:e,onSelectSession:e_,onRenamed:()=>void ez(t.cwd,!1),onSessionDeleted:e=>{h?.(e),ez(t.cwd,!1)},depth:0,runningSessionIds:k},r.session.id))]})),(l||u>0)&&a>10&&(0,n.jsx)("button",{type:"button",onClick:()=>eK(t.cwd),style:{width:"100%",padding:"6px 10px",background:"transparent",border:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:11,textAlign:"center"},children:l?"Show less":`Show ${Math.max(0,u)} more`}),t.sessionsState?.hasMore&&(0,n.jsxs)("button",{type:"button",onClick:()=>e$(t.cwd),style:{width:"100%",padding:"6px 10px",background:"transparent",border:"none",borderTop:"1px solid var(--border)",color:"var(--accent)",cursor:"pointer",fontSize:11,textAlign:"center"},children:["Load more (",Math.max(0,(t.sessionsState?.total??t.sessions.length)-t.sessions.length)," remaining)"]})]})]},t.cwd||"__no_project")})]}),(0,n.jsx)(I,{open:V,initialPath:eN,onClose:()=>Y(!1),onSelect:e=>eB(e)})]})}function B({group:e,isCurrent:t,isCollapsed:r,isDragging:i,pinBusy:s,onToggle:a,onSelect:d,onTogglePinned:c,onDragStart:u,onDragEnd:p}){let[h,x]=(0,o.useState)(!1),g=e.lastAccessed,f=Math.max(0,e.chatCount??0),v=!0===e.project.pinned,m=(0,o.useCallback)(()=>{t?a():d()},[t,d,a]);return(0,n.jsxs)("div",{role:"button",tabIndex:0,draggable:!0,onClick:m,onDragStart:u,onDragEnd:p,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),m())},onMouseEnter:()=>x(!0),onMouseLeave:()=>x(!1),title:e.cwd,style:{width:"100%",height:32,display:"flex",alignItems:"center",gap:5,padding:"0 8px",background:t?"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, opacity 0.12s",opacity:i?.55:1},children:[(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:r?"none":"rotate(90deg)",transition:"transform 0.15s",flexShrink:0,color:"var(--text-dim)"},children:(0,n.jsx)("polyline",{points:"3 2 7 5 3 8"})}),(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.35",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:t?"var(--accent)":"var(--text-dim)"},children:r?(0,n.jsx)("path",{d:"M1.5 4.5A1.5 1.5 0 0 1 3 3h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6v5A1.5 1.5 0 0 1 13 12.5H3A1.5 1.5 0 0 1 1.5 11V4.5Z"}):(0,n.jsx)("path",{d:"M1.5 5A1.5 1.5 0 0 1 3 3.5h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6.5L13.6 11A1.5 1.5 0 0 1 12.1 12.5H3A1.5 1.5 0 0 1 1.5 11V5Z"})}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13,fontWeight:t?650:560,color:"var(--text)"},children:e.displayName}),!e.project.exists&&(0,n.jsx)("span",{style:{flexShrink:0,color:"#f87171",fontSize:10},children:"missing"}),!h&&f>0&&(0,n.jsxs)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:[f," ",1===f?"chat":"chats"]}),!h&&g&&(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:l(g)}),v?(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),c()},title:"Unpin project",tabIndex:h?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,border:"none",borderRadius:5,background:"rgba(234,179,8,0.12)",color:"#ca8a04",cursor:"pointer",flexShrink:0,opacity:h?1:.85,transition:"opacity 0.12s"},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"currentColor",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})}):(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),c()},disabled:s,title:"Pin project to sidebar",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:s?"wait":"pointer",flexShrink:0,opacity:+!!h,transition:"opacity 0.12s, background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="#ca8a04"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})}),(0,n.jsx)("span",{title:"Drag to reorder",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:18,height:22,flexShrink:0,color:"var(--text-dim)",opacity:h?1:.35,transition:"opacity 0.12s",cursor:"grab"},children:(0,n.jsxs)("svg",{width:"10",height:"12",viewBox:"0 0 10 12",fill:"currentColor",children:[(0,n.jsx)("circle",{cx:"2",cy:"2",r:"1"}),(0,n.jsx)("circle",{cx:"8",cy:"2",r:"1"}),(0,n.jsx)("circle",{cx:"2",cy:"6",r:"1"}),(0,n.jsx)("circle",{cx:"8",cy:"6",r:"1"}),(0,n.jsx)("circle",{cx:"2",cy:"10",r:"1"}),(0,n.jsx)("circle",{cx:"8",cy:"10",r:"1"})]})})]})}let H="annovibe:last-open-by-workspace";function F(){try{return window.localStorage}catch{return null}}function U(e){let t=e.trim();if(!t)return"";let r=t.replace(/\\/g,"/");return r.length>1?r.replace(/\/+$/,""):r}function q(e){try{let t=e.getItem(H);if(!t)return{};let r=JSON.parse(t);return r&&"object"==typeof r&&!Array.isArray(r)?r:{}}catch{return{}}}function _(e,t){try{e.setItem(H,JSON.stringify(t))}catch{}}function J(e,t,r=F()){if(!r||!e||!t)return;let n=U(e);if(!n)return;let o=q(r);o[n]!==t&&(o[n]=t,_(r,o))}var K=r(14755);let V=new Map,Y=new Map;function G(e){e&&Y.delete(e)}let X=["auto","off","minimal","low","medium","high","xhigh"],Z={auto:"沿用 pi 默认设置",off:"关闭推理",minimal:"最少推理",low:"低强度推理",medium:"中等推理",high:"高强度推理",xhigh:"最高强度推理"};function Q({triggerRef:e,panelRef:t,open:r,pane:o,anchorRect:i,isMobile:l,isStreaming:s,mobileCompactButtonSize:a,mobileCompactButtonPadding:d,mobileSheetStyle:c,currentName:u,mobileModelSummary:p,groups:h,model:x,canAdjustThinking:g,thinkingLabel:f,thinkingLevel:v,thinkingLevelMap:m,availableThinkingLevels:b,onToggle:y,onClose:j,onPaneChange:k,onModelChange:w,onThinkingLevelChange:S}){let C=e=>(0,n.jsx)("svg",{width:e,height:e,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"})}),T=(e,t)=>(0,n.jsx)("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0,...t},children:(0,n.jsx)("path",{d:"M9 6l6 6-6 6",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"})}),z=e=>{e.currentTarget.style.background="var(--bg-hover)"},I=e=>{e.currentTarget.style.background="transparent"},M={display:"flex",alignItems:"center",gap:8,width:"100%",height:40,padding:"0 10px",border:"none",borderRadius:10,background:"transparent",color:"var(--text)",fontSize:14,lineHeight:"22px",cursor:"pointer",textAlign:"left",fontFamily:"inherit"},R={display:"flex",alignItems:"center",gap:8,width:"100%",minHeight:38,padding:"6px 8px",border:"none",borderRadius:10,background:"transparent",color:"var(--text)",textAlign:"left",cursor:"pointer",fontFamily:"inherit"},L={position:"sticky",top:0,zIndex:1,padding:"5px 8px 3px",background:"var(--bg-panel)",color:"var(--text-dim)",fontSize:12,lineHeight:"18px",fontWeight:500},W=X.filter(e=>!b||"auto"===e||b.includes(e)),E=(0,n.jsxs)(n.Fragment,{children:["root"===o&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{onClick:()=>k("model"),role:"menuitem",style:M,onMouseEnter:z,onMouseLeave:I,children:[(0,n.jsx)("span",{style:{flex:"1 1 auto",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"模型"}),(0,n.jsx)("span",{style:{flex:"0 1 auto",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontSize:13},children:p}),T(14,{color:"var(--text-dim)"})]}),g&&u&&(0,n.jsxs)("button",{onClick:()=>k("effort"),role:"menuitem",style:M,onMouseEnter:z,onMouseLeave:I,children:[(0,n.jsx)("span",{style:{flex:"1 1 auto",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"推理强度"}),(0,n.jsx)("span",{style:{flex:"0 1 auto",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontSize:13},children:f}),T(14,{color:"var(--text-dim)"})]})]}),"model"===o&&(0,n.jsx)("div",{style:{minHeight:0,overflowY:"auto"},children:h.map(e=>(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:L,children:e.provider}),e.options.map(e=>{let t=e.modelId===x?.modelId&&e.provider===x?.provider,r=e.input&&e.input.length>0?e.input.join(" \xb7 "):void 0;return(0,n.jsxs)("button",{onClick:()=>{j(),t||w(e.provider,e.modelId)},role:"menuitemradio","aria-checked":t,style:R,onMouseEnter:z,onMouseLeave:I,children:[(0,n.jsxs)("span",{style:{display:"flex",flex:1,flexDirection:"column",minWidth:0},children:[(0,n.jsx)("span",{style:{overflow:"hidden",color:"inherit",fontSize:14,lineHeight:"20px",fontWeight:500,textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),void 0!==r&&(0,n.jsx)("span",{style:{overflow:"hidden",color:"var(--text-dim)",fontSize:12,lineHeight:"18px",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r})]}),(0,n.jsx)("span",{style:{display:"grid",placeItems:"center",flex:"0 0 18px",color:"var(--text)"},children:t?C(14):null})]},`${e.provider}:${e.modelId}`)})]},e.provider))}),"effort"===o&&g&&(0,n.jsx)("div",{style:{minHeight:0,overflowY:"auto"},children:W.map(e=>{let t=(v??"auto")===e,r="auto"!==e?m?.[e]:void 0,o="auto"===e?"Default":null!=r&&r!==e?r:e,i="auto"!==e&&null!=r&&r!==e;return(0,n.jsxs)("button",{onClick:()=>{j(),t||S?.(e)},role:"menuitemradio","aria-checked":t,style:R,onMouseEnter:z,onMouseLeave:I,children:[(0,n.jsxs)("span",{style:{display:"flex",flex:1,flexDirection:"column",minWidth:0},children:[(0,n.jsxs)("span",{style:{overflow:"hidden",color:"inherit",fontSize:14,lineHeight:"20px",fontWeight:500,textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[o,i&&(0,n.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",fontFamily:"var(--font-mono)",marginLeft:5},children:["(",e,")"]})]}),(0,n.jsx)("span",{style:{overflow:"hidden",color:"var(--text-dim)",fontSize:12,lineHeight:"18px",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Z[e]})]}),(0,n.jsx)("span",{style:{display:"grid",placeItems:"center",flex:"0 0 18px",color:"var(--text)"},children:t?C(14):null})]},e)})})]}),P=window.visualViewport?.width??window.innerWidth,$=window.visualViewport?.height??window.innerHeight,D=i?$-i.top+6:0,N=i?Math.max(120,Math.min(i.top-8,.6*$)):240,A=i?Math.max(8,P-(i.left+i.width)):0;return(0,n.jsxs)("div",{ref:e,style:{position:"relative",flex:l?"1 1 160px":void 0,minWidth:0},children:[(0,n.jsxs)("button",{onClick:e=>{let t;y(l?null:{top:(t=e.currentTarget.getBoundingClientRect()).top,left:t.left,width:t.width})},disabled:s,title:"选择模型与推理强度",style:{display:"flex",alignItems:"center",gap:4,height:l?a:28,padding:l?d:"0 4px 0 8px",width:l?"100%":void 0,maxWidth:l?"100%":220,overflow:"hidden",background:r?"var(--bg-hover)":"transparent",border:"none",borderRadius:24,color:"var(--text-muted)",cursor:s?"not-allowed":"pointer",fontSize:l?11:13,lineHeight:l?void 0:"20px",fontWeight:l?void 0:500,opacity:s?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{s||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=r?"var(--bg-hover)":"transparent",e.currentTarget.style.color="var(--text-muted)"},children:[(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:u??"Select model"}),g&&u&&(0,n.jsx)("span",{style:{flex:"0 0 auto",color:"var(--text-dim)"},children:f}),(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",style:{flex:"0 0 auto",color:"var(--text-dim)",transform:r?"rotate(180deg)":"none",transition:"transform 120ms ease"},children:(0,n.jsx)("path",{d:"M3 4.5L6 7.5L9 4.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})]}),r&&(l?(0,n.jsxs)("div",{ref:t,style:{...c,display:"flex",flexDirection:"column"},children:[(0,n.jsxs)("div",{style:{padding:"8px 12px 6px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:["root"!==o&&(0,n.jsx)("button",{onClick:()=>k("root"),"aria-label":"返回",style:{display:"flex",alignItems:"center",justifyContent:"center",width:24,height:24,padding:0,flexShrink:0,background:"none",border:"none",borderRadius:6,color:"var(--text-muted)",cursor:"pointer"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:(0,n.jsx)("path",{d:"M15 6l-6 6 6 6",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"})})}),(0,n.jsx)("div",{style:{fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"model"===o?"Models":"effort"===o?"推理强度":"模型"})]}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:"effort"===o?f:p})]}),E]}):i&&(0,n.jsx)("div",{ref:t,role:"menu","aria-label":"模型与推理等级",onKeyDown:e=>{("ArrowDown"===e.key||"ArrowUp"===e.key)&&(e.preventDefault(),(e=>{let r=t.current;if(!r)return;let n=Array.from(r.querySelectorAll('button[role="menuitem"], button[role="menuitemradio"]'));if(0===n.length)return;let o=(Math.max(n.findIndex(e=>e===document.activeElement),0)+e+n.length)%n.length;n[o]?.focus()})("ArrowDown"===e.key?1:-1))},style:{position:"fixed",bottom:D,right:A,zIndex:500,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:12,boxShadow:"0 12px 28px -10px rgba(0,0,0,0.28)",width:"min(240px, calc(100vw - 32px))",maxHeight:N,overflow:"hidden",display:"flex",flexDirection:"column",padding:4},children:E}))]})}function ee({open:e,triggerRef:t,sheetStyle:r,cardButtonStyle:o,iconColor:i,canSelectModel:l,canAdjustThinking:s,canAdjustTools:a,canAdjustMemory:d,mobileModelSummary:c,thinkingLabel:u,mobileToolSummary:p,displayMemoryLabel:h,memoryEnabled:x,onToggle:g,onOpenModel:f,onOpenTools:v,onOpenMemory:m}){return(0,n.jsxs)("div",{ref:t,style:{position:"relative",flexShrink:0},children:[(0,n.jsx)("button",{onClick:()=>g(),title:"更多设置",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:e?"var(--bg-hover)":"none",border:"none",borderRadius:8,color:i,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:t=>{t.currentTarget.style.background=e?"var(--bg-hover)":"none",t.currentTarget.style.color=e?"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"})]})}),e&&(0,n.jsxs)("div",{style:{...r,zIndex:510,padding:"6px",display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("div",{style:{padding:"4px 6px 2px",fontSize:10,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"More"}),(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",padding:"0 6px 4px"},children:"模型、推理、工具等设置已收进这里。"}),(0,n.jsxs)("div",{style:{display:"grid",gap:4},children:[l&&(0,n.jsxs)("button",{onClick:()=>f("root"),style:o,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Model"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2,wordBreak:"break-word",lineHeight:1.35},children:c})]}),s&&(0,n.jsxs)("button",{onClick:()=>f("effort"),style:o,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:u})]}),a&&(0,n.jsxs)("button",{onClick:v,style:o,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:p})]}),d&&(0,n.jsxs)("button",{onClick:m,style:o,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:x?"var(--accent)":"var(--text)",marginTop:2},children:h})]})]})]})]})}let et=["off","default","full","agent"],er={off:"none",default:"default",full:"full",agent:"agent"},en={off:"无工具,纯聊天",default:"4 项内置工具",full:"全部内置工具",agent:"High + 子代理"},eo={retain:{label:"retain",description:"保存稳定事实或决策到项目记忆"},recall:{label:"recall",description:"检索项目记忆中的相关上下文"},reflect:{label:"reflect",description:"基于已存记忆做综合回应"}},ei=[],el=[{command:"/compact",label:"/compact",description:"压缩当前上下文",kind:"native"},{command:"/init",label:"/init",description:"快捷插入,交给模型处理初始化任务",kind:"shortcut"},{command:"/memory",label:"/memory",description:"快捷插入,交给模型处理项目记忆任务",kind:"shortcut"}];function es({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 ea(e){return e.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&").replace(/&quot;/g,'"').replace(/&apos;/g,"'")}async function ed(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 ec(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=>ea(e[1])))}return i.join("").replace(/[ \t]+\n/g,"\n")}async function eu(e){let t=await Promise.all([r.e(4279),r.e(2708)]).then(r.bind(r,26083)),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 ep(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=>ea(e[1]).trim()).filter(Boolean);r.length&&i.push(`Slide ${t[1]}
4
+ ${r.join("\n")}`)}return i.join("\n\n")}async function eh(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 ed(t);else if("docx"===r)o=await ec(t);else if("xlsx"===r)o=await eu(t);else{if("pptx"!==r)return{extractionError:"Text extraction is not supported for this file type"};o=await ep(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 ex=(0,o.forwardRef)(function({onSend:e,onAbort:t,onSteer:r,onFollowUp:i,isStreaming:l,onBash:s,bashRunning:a,model:d,modelNames:c,modelList:u,onModelChange:p,onCompact:h,onAbortCompaction:x,isCompacting:g,compactError:f,compactInfo:v,toolPreset:m,onToolPresetChange:b,memoryTools:y,onMemoryToolsChange:j,thinkingLevel:k,onThinkingLevelChange:w,availableThinkingLevels:S,thinkingLevelMap:C,retryInfo:T,cornerBadge:z,promptHistory:I,sessionHistoryKey:M,draftKey:R,slashCommands:L,cwd:W,activeFilePath:E,onDismissFileContext:P},$){let[D,N]=(0,o.useState)(()=>(function(e){if(!e)return null;let t=Y.get(e);return t?{...t}:null})(R)?.value??""),[A,O]=(0,o.useState)(!1),[B,H]=(0,o.useState)("root"),[F,U]=(0,o.useState)(null),[q,_]=(0,o.useState)(!1),[J,X]=(0,o.useState)(null),[Z,ea]=(0,o.useState)(!1),[ed,ec]=(0,o.useState)(0),[eu,ep]=(0,o.useState)(null),[ex,eg]=(0,o.useState)(!1),[ef,ev]=(0,o.useState)(null),em=(0,o.useRef)(""),[eb,ey]=(0,o.useState)(!1),[ej,ek]=(0,o.useState)(!1),[ew,eS]=(0,o.useState)(!1),[eC,eT]=(0,o.useState)(!1),[ez,eI]=(0,o.useState)(null);(0,o.useEffect)(()=>{R&&function(e,t){if(e){if(!t.value)return Y.delete(e);Y.set(e,{...t})}}(R,{value:D})},[R,D]);let[eM,eR]=(0,o.useState)([]),[eL,eW]=(0,o.useState)([]),eE=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}(),eP=eE?{display:"none"}:void 0,e$=eE?28:32,eD=eE?"6px 8px":"8px 12px",eN=eE&&!l,eA=eC?"var(--text)":"var(--text-muted)",eO=eE?{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},[eB,eH]=(0,o.useState)(null),eF=(0,o.useRef)(null),eU=(0,o.useRef)(null),eq=(0,o.useRef)(null),e_=(0,o.useRef)(null),eJ=(0,o.useRef)(null),eK=(0,o.useRef)(null),eV=(0,o.useRef)(null),eY=(0,o.useRef)(null),eG=(0,o.useRef)(null),eX=(0,o.useRef)(null),eZ=(0,o.useRef)(null),eQ=(0,o.useCallback)(e=>{let t=eF.current;if(!t)return void N(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")?"":" ";N(o+l+e+i),requestAnimationFrame(()=>{let t=eF.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)($,()=>({insertIfEmpty(e){let t=eF.current;(t?t.value:D).trim()||(N(e),requestAnimationFrame(()=>{t&&(t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)}))},insertText(e){eQ(e)},setText(e){N(e),requestAnimationFrame(()=>{let t=eF.current;t&&(t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`,t.setSelectionRange(e.length,e.length))})},addImages(e){e0(e)},addBase64Images(e){eR(t=>[...t,...e.map(e=>({data:e.data,mimeType:e.mimeType,previewUrl:`data:${e.mimeType};base64,${e.data}`}))])},addFiles(e){e1(e)}}));let e0=(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)})));eR(e=>[...e,...r])},[]),e1=(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&&e0(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 eh(e,r);t({data:r,fileName:e.name,mimeType:e.type||"application/octet-stream",size:e.size,...o})},n.onerror=r,n.readAsArrayBuffer(e)})));eW(t=>[...t,...e])}},[e0]),e2=(0,o.useCallback)(e=>{eR(t=>{let r=[...t];return URL.revokeObjectURL(r[e].previewUrl),r.splice(e,1),r})},[]),e5=(0,o.useCallback)(e=>{eW(t=>{let r=[...t];return r.splice(e,1),r})},[]),e4=(0,o.useCallback)(()=>{eR(e=>(e.forEach(e=>URL.revokeObjectURL(e.previewUrl)),[])),eW([])},[]),e8=u&&u.length>0?u.map(e=>({provider:e.provider,modelId:e.id,name:e.name,input:e.input})):Object.entries(c??{}).map(([e,t])=>({provider:d?.provider??"unknown",modelId:e,name:t})),e3=[];for(let e of e8){let t=e3.find(t=>t.provider===e.provider);t?t.options.push(e):e3.push({provider:e.provider,options:[e]})}let e6=d?e8.find(e=>e.modelId===d.modelId&&e.provider===d.provider)?.name??d.modelId:null,e7=d?e8.find(e=>e.modelId===d.modelId&&e.provider===d.provider):e8[0],e9=e7?.input?.includes("image")??!0,te=eM.length>0&&e7?.input!==void 0&&!e9,tt=!!D.trim()||eM.length>0||eL.length>0,tr=D.trim(),tn=0===eM.length&&0===eL.length&&tr.startsWith("!"),to=tn&&tr.startsWith("!!"),ti=tt&&!te,tl=h?el:el.filter(e=>"/compact"!==e.command),ts=tl.filter(e=>"native"===e.kind),ta=tl.filter(e=>"shortcut"===e.kind),td=(()=>{let e=new Set(el.map(e=>e.command)),t=[];for(let r of L??[]){let n=`/${r.name.replace(/^\/+/,"")}`;e.has(n)||(e.add(n),t.push({command:n,label:n,description:r.description??"",kind:"dynamic",source:r.source,dormant:!0===r.disableModelInvocation}))}return t.sort((e,t)=>Number(!0===e.dormant)-Number(!0===t.dormant))})(),tc=(0,o.useMemo)(()=>J&&W?eu?.cwd!==W||eu.truncated&&J.query.trim()?ef?.query===J.query?ef.entries.slice(0,12):[]:function(e,t,r=12){let n=t.trim(),o=[];for(let t of e){let e=function(e,t){let r,n=e.path.toLowerCase(),o=-1===(r=n.lastIndexOf("/"))?n:n.slice(r+1),i=t.toLowerCase();return i&&o!==i?o.startsWith(i)?1:n.startsWith(i)?2:o.includes(i)?3:n.includes(i)?4:!function(e,t){if(!t)return!0;let r=0;for(let n of e)if(n===t[r]&&(r+=1),r===t.length)return!0;return!1}(n,i)?null:5:0}(t,n);null!==e&&o.push({entry:t,score:e})}return o.sort((e,t)=>e.score-t.score||Number(t.entry.isDir)-Number(e.entry.isDir)||e.entry.path.length-t.entry.path.length||e.entry.path.localeCompare(t.entry.path)),o.slice(0,Math.max(0,r)).map(e=>e.entry)}(eu.entries,J.query,12):[],[J,W,eu,ef]),tu=(0,o.useCallback)((e,t)=>{let r=function(e){let t=/(?:^|\s)@"([^"\n]*)$/.exec(e);if(t)return{start:e.length-(t[1].length+2),query:t[1],quoted:!0};let r=/(?:^|\s)@([^\s@]*)$/.exec(e);return r?{start:e.length-r[1].length-1,query:r[1],quoted:!1}:null}(e.slice(0,t)),n=r?`${r.start}:${+!!r.quoted}:${r.query}`:"";em.current!==n&&(em.current=n,ec(0)),X(r),ea(!!(r&&W)),r||ev(null)},[W]),tp=(0,o.useCallback)(e=>{var t;let r=eF.current;if(!r||!J)return;let n=r.selectionStart??r.value.length,o=r.value.slice(0,J.start),i=r.value.slice(n),l=(t=e.path,/[\s"]/.test(t)?`@"${t}" `:`@${t} `);N(o+l+i),ea(!1),X(null),ev(null),em.current="",requestAnimationFrame(()=>{r.focus();let e=o.length+l.length;r.setSelectionRange(e,e),r.style.height="auto",r.style.height=`${Math.min(r.scrollHeight,200)}px`})},[J]),th=(0,o.useCallback)(e=>{let t=e.target.value;N(t),tu(t,e.target.selectionStart??t.length)},[tu]),tx=(0,o.useCallback)(()=>{let e=eF.current;e&&tu(e.value,e.selectionStart??0)},[tu]);(0,o.useEffect)(()=>{if(!Z||!W||eu?.cwd===W)return;let e=!1;return eg(!0),fetch(`/api/file-index?cwd=${encodeURIComponent(W)}`).then(e=>e.json()).then(t=>{e||ep({cwd:W,entries:t.files??[],truncated:!!t.truncated})}).catch(()=>{e||ep({cwd:W,entries:[],truncated:!1})}).finally(()=>{e||eg(!1)}),()=>{e=!0}},[Z,W,eu?.cwd]);let tg=J?.query??"";(0,o.useEffect)(()=>{if(!Z||!W||!eu||eu.cwd!==W||!eu.truncated)return;let e=tg.trim();if(!e)return void ev(null);let t=new AbortController,r=setTimeout(()=>{fetch(`/api/file-index?cwd=${encodeURIComponent(W)}&q=${encodeURIComponent(e)}`,{signal:t.signal}).then(e=>e.json()).then(t=>{ev({query:e,entries:t.files??[]})}).catch(()=>{})},120);return()=>{clearTimeout(r),t.abort()}},[Z,tg,W,eu]);let tf=y??[],tv=tf.length>0?`${tf.length} enabled`:"off",tm=e8.length>0&&!!p,tb=!!w,ty=!!b,tj=(()=>{let e=k??"auto";if("auto"===e)return"Default";if(!C)return e;let t=C[e];return null!=t?t:e})(),tk=e6??"Select model",tw=Object.entries(er).find(([,e])=>e===(m??"full"))?.[0]??"full",tS=eE?26:32,tC=eE?7:9,tT=eE?3:6,tz={position:"fixed",left:8,right:8,bottom:"calc(env(safe-area-inset-bottom, 0px) + 8px)",zIndex:500,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:12,boxShadow:"0 -6px 24px rgba(0,0,0,0.14)",overflow:"hidden",maxHeight:"min(60dvh, 420px)"},tI=eE&&(A||q||eb||ej||ew||eC);(0,o.useEffect)(()=>{te||eH(null)},[te]);let tM=(0,o.useCallback)(e=>{if(!D.trim()){N(e),requestAnimationFrame(()=>{let t=eF.current;t&&(t.focus(),t.setSelectionRange(e.length,e.length),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)});return}eQ(e)},[eQ,D]),tR=(0,o.useCallback)(()=>{let t=D.trim();if(t||eM.length||eL.length){if(eM.length&&!e9)return void eH("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");if(!l){if(tn){if(!s)return;let e=tr.replace(/^!{1,2}\s*/,"").trim();if(!e)return;s(e,to),N(""),G(R),eF.current&&(eF.current.style.height="auto");return}if("/compact"===t&&!eM.length&&!eL.length&&h){g?x?.():h(),N(""),G(R),eF.current&&(eF.current.style.height="auto");return}e(t,eM.length?eM:void 0,eL.length?eL:void 0),N(""),G(R),e4(),eF.current&&(eF.current.style.height="auto")}}},[D,eM,eL,e9,l,tn,to,tr,s,e,e4,h,x,g,R]),tL=(0,o.useCallback)(e=>{let t=D.trim();if(!t&&!eM.length&&!eL.length)return;if(eM.length&&!e9)return void eH("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");let n=eM.length?eM:void 0,o=eL.length?eL:void 0;"steer"===e&&r?r(t,n,o):"followup"===e&&i&&i(t,n,o),N(""),G(R),e4(),eF.current&&(eF.current.style.height="auto")},[D,eM,eL,e9,r,i,e4,R]),tW=I??ei,tE=M??null,tP=(0,o.useCallback)(e=>{if(Z){if("Escape"===e.key){e.preventDefault(),ea(!1),em.current="";return}if(tc.length>0){if("ArrowDown"===e.key){e.preventDefault(),ec(e=>(e+1)%tc.length);return}if("ArrowUp"===e.key){e.preventDefault(),ec(e=>(e-1+tc.length)%tc.length);return}if("Enter"===e.key||"Tab"===e.key){e.preventDefault(),tp(tc[Math.min(ed,tc.length-1)]);return}}}if("ArrowUp"===e.key&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey&&tW.length>0){let t=eF.current;if(!t)return;let r=t.selectionStart??0;if(t.value.slice(0,r).includes("\n"))return;e.preventDefault();let n=function(e,t,r){let n;if(!e||0===r.length)return null;let o=((n=V.get(e))||(n={cursor:-1,draftSnapshot:""},V.set(e,n)),n);if(-1===o.cursor)o.draftSnapshot=t,o.cursor=0;else{if(!(o.cursor<r.length-1))return null;o.cursor+=1}return r[o.cursor]??null}(tE,t.value,tW);null!==n&&(N(n),requestAnimationFrame(()=>{t.setSelectionRange(n.length,n.length)}));return}if("ArrowDown"===e.key&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey&&function(e){if(!e)return!1;let t=V.get(e);return(t?.cursor??-1)>=0}(tE)){e.preventDefault();let t=function(e,t){if(!e)return null;let r=V.get(e);if(!r||-1===r.cursor)return null;if(r.cursor>0)return r.cursor-=1,{text:t[r.cursor]??"",returnedToPresent:!1};let n=r.draftSnapshot;return r.cursor=-1,r.draftSnapshot="",{text:n,returnedToPresent:!0}}(tE,tW);t&&(N(t.text),t.returnedToPresent&&requestAnimationFrame(()=>{let e=eF.current;e&&e.setSelectionRange(t.text.length,t.text.length)}));return}"Enter"===e.key&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),tE&&V.set(tE,{cursor:-1,draftSnapshot:""}),l&&(r||i)?tL(r?"steer":"followup"):tR())},[ed,tc,Z,tp,l,r,i,tL,tR,tW,tE]),t$=(0,o.useCallback)(()=>{let e=eF.current;e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[]),tD=(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(),e1(t.map(e=>e.getAsFile()).filter(e=>null!==e)))},[e1]);(0,o.useEffect)(()=>{if(!A&&!q&&!Z&&!eb&&!ej&&!ew&&!eC)return;let e=e=>{let t=e.target;if(!(t instanceof Node))return;let r=!!eU.current?.contains(t),n=!!eq.current?.contains(t);r||n||O(!1),e_.current?.contains(t)||_(!1),Z&&!eJ.current?.contains(t)&&t!==eF.current&&(ea(!1),em.current=""),eK.current?.contains(t)||ey(!1),eV.current?.contains(t)||ek(!1),eY.current?.contains(t)||eS(!1),eG.current?.contains(t)||eT(!1)};return document.addEventListener("pointerdown",e,!0),()=>{document.removeEventListener("pointerdown",e,!0)}},[A,q,Z,eb,ej,ew,eC]),(0,o.useEffect)(()=>{if(!b)return;let e=!1;return fetch("/api/subagents/status").then(e=>e.ok?e.json():null).then(t=>{e||eI(!!t?.ready)}).catch(()=>{e||eI(!1)}),()=>{e=!0}},[b]),(0,o.useEffect)(()=>{if(!A)return;let e=e=>{"Escape"===e.key&&("root"!==B?H("root"):O(!1))};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[A,B]);let tN=()=>(0,n.jsx)(Q,{triggerRef:eU,panelRef:eq,open:A,pane:B,anchorRect:F,isMobile:eE,isStreaming:l,mobileCompactButtonSize:e$,mobileCompactButtonPadding:eD,mobileSheetStyle:tz,currentName:e6,mobileModelSummary:tk,groups:e3,model:d,canAdjustThinking:tb,thinkingLabel:tj,thinkingLevel:k,thinkingLevelMap:C,availableThinkingLevels:S,onToggle:e=>{e&&U(e),_(!1),ey(!1),ek(!1),eS(!1),eT(!1),H("root"),O(e=>!e)},onClose:()=>{O(!1),H("root")},onPaneChange:H,onModelChange:p,onThinkingLevelChange:w});return(0,n.jsxs)("div",{style:eO,children:[tI&&(0,n.jsx)("div",{"aria-hidden":!0,onClick:()=>{O(!1),_(!1),ey(!1),ek(!1),eS(!1),eT(!1)},style:{position:"fixed",inset:0,zIndex:490,background:"rgba(15, 23, 42, 0.18)",backdropFilter:"blur(1.5px)",WebkitBackdropFilter:"blur(1.5px)"}}),(0,n.jsx)("input",{ref:eX,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:e=>{e0(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=>{e1(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsxs)("div",{style:{maxWidth:eE?"100%":820,margin:"0 auto",position:"relative",width:"100%",padding:eE?"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}),T&&(0,n.jsxs)("div",{style:{marginBottom:eE?6:8,padding:eE?"4px 8px":"5px 10px",background:"rgba(234,179,8,0.08)",border:"1px solid rgba(234,179,8,0.25)",borderRadius:6,fontSize:eE?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 (",T.attempt,"/",T.maxAttempts,")…",T.errorMessage&&(0,n.jsxs)("span",{style:{opacity:.7,marginLeft:4},children:["— ",T.errorMessage]})]}),E&&(0,n.jsxs)("div",{style:{marginBottom:eE?6:8,padding:eE?"3px 8px":"4px 10px",background:"color-mix(in srgb, var(--accent) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--accent) 25%, transparent)",borderRadius:6,fontSize:eE?11:12,color:"var(--text-muted)",display:"inline-flex",alignItems:"center",gap:6,maxWidth:"100%"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"}),(0,n.jsx)("polyline",{points:"14 2 14 8 20 8"})]}),(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:E.replace(/^.*[\\/]/,"")}),P&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),P()},title:"Stop including this file in context",style:{background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:14,lineHeight:1,padding:"0 2px",flexShrink:0},children:"\xd7"})]}),(eM.length>0||eL.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:[eM.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 ${te?"rgba(220,38,38,0.45)":"var(--border)"}`,display:"block"}}),(0,n.jsx)("button",{onClick:()=>e2(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}`)),eL.map((e,t)=>(0,n.jsx)(es,{doc:e,onRemove:()=>e5(t)},`doc-${t}`))]}),(te||eB)&&(0,n.jsxs)("div",{style:{marginTop:6,display:"flex",alignItems:"center",gap:6,fontSize:eE?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:eB??"当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。"})]})]}),Z&&W&&(0,n.jsxs)("div",{ref:eJ,style:{position:"absolute",left:0,right:0,bottom:"100%",marginBottom:6,zIndex:130,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -6px 24px rgba(0,0,0,0.12)",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:"Files"}),ex&&0===tc.length?(0,n.jsx)("div",{style:{padding:"8px 10px",fontSize:11.5,color:"var(--text-dim)"},children:"Searching files…"}):0===tc.length?(0,n.jsx)("div",{style:{padding:"8px 10px",fontSize:11.5,color:"var(--text-dim)"},children:J?.query?"No matching files":"No files"}):(0,n.jsx)("div",{style:{maxHeight:260,overflowY:"auto",padding:"3px 0"},children:tc.map((e,t)=>{let r=e.path.lastIndexOf("/"),o=-1===r?"":e.path.slice(0,r+1),i=-1===r?e.path:e.path.slice(r+1);return(0,n.jsxs)("button",{type:"button",onMouseDown:e=>e.preventDefault(),onClick:()=>tp(e),onMouseEnter:()=>ec(t),style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"5px 10px",background:t===ed?"var(--bg-hover)":"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left"},children:[(0,n.jsx)("span",{style:{width:16,flexShrink:0,color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:12},children:"@"}),(0,n.jsxs)("span",{style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:2,overflow:"hidden"},children:[o&&(0,n.jsx)("span",{style:{color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:o}),(0,n.jsx)("span",{style:{color:"var(--text)",fontFamily:"var(--font-mono)",flexShrink:0},children:i})]})]},e.path)})}),(0,n.jsx)("div",{style:{padding:"4px 10px 6px",fontSize:10,color:"var(--text-dim)",borderTop:"1px solid var(--border)"},children:"↑↓ navigate \xb7 Enter insert \xb7 Esc close"})]}),tn&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,marginBottom:6,padding:"3px 9px",fontSize:11,color:"var(--text-muted)",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",color:"var(--accent)"},children:"$"}),(0,n.jsxs)("span",{children:["Shell — ",to?"output will NOT be added to model context":"output will be added to model context"]})]}),(0,n.jsxs)("div",{style:{display:"flex",gap:eE?4:8,alignItems:eE?"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:eE?13:14,padding:eE?"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:eF,value:D,onChange:th,onKeyDown:tP,onKeyUp:tx,onClick:tx,onInput:t$,onPaste:tD,placeholder:a?"Shell command is running…":l&&(r||i)?"Steer 立即注入 / Follow-up 排队…":l?"Agent is running…":tn?"Shell command… (Enter to run)":"Message…",rows:1,style:{flex:1,alignSelf:eE?"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:+!!eE,paddingBottom:+!!eE}}),l?(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:eE?4:6,flexShrink:0,alignSelf:"flex-end"},children:[r&&(0,n.jsxs)("button",{onClick:()=>tL("steer"),disabled:!ti,title:te?"当前模型不支持图片输入":"打断 Agent 当前运行,立即注入消息",style:{display:"flex",alignItems:"center",gap:5*!eE,padding:eE?"6px 8px":"7px 12px",background:ti?"rgba(234,179,8,0.12)":"none",border:"1px solid rgba(234,179,8,0.35)",borderRadius:8,color:ti?"rgba(180,130,0,1)":"var(--text-dim)",cursor:ti?"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"})]}),!eE&&"Steer"]}),i&&(0,n.jsxs)("button",{onClick:()=>tL("followup"),disabled:!ti,title:te?"当前模型不支持图片输入":"在 Agent 完成后排队发送",style:{display:"flex",alignItems:"center",gap:5*!eE,padding:eE?"6px 8px":"7px 12px",background:ti?"rgba(129,140,248,0.12)":"none",border:"1px solid rgba(129,140,248,0.35)",borderRadius:8,color:ti?"rgba(99,102,241,1)":"var(--text-dim)",cursor:ti?"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"})]}),!eE&&"Follow-up"]})]}):(0,n.jsxs)("button",{onClick:tR,disabled:!ti,title:te?"当前模型不支持图片输入":"Send",style:{flexShrink:0,alignSelf:"flex-end",display:"flex",alignItems:"center",gap:eE?3:6,padding:eE?"5px 9px":"7px 14px",marginBottom:+!!eE,background:ti?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:8,color:ti?"#fff":"var(--text-dim)",cursor:ti?"pointer":"not-allowed",fontSize:eE?11:13,fontWeight:600,letterSpacing:"-0.01em",boxShadow:ti?"0 1px 3px rgba(37,99,235,0.25)":"none",transition:"background 0.15s, box-shadow 0.15s"},children:[(0,n.jsxs)("svg",{width:eE?13:14,height:eE?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:eE?5:8,display:"flex",alignItems:eE?"flex-start":"center",gap:tT,flexWrap:eE?"wrap":"nowrap"},children:[(0,n.jsxs)("div",{className:"chat-input-toolbar-left",style:{flex:eE?"1 1 100%":"0 0 auto",width:eE?"100%":void 0,display:"flex",alignItems:"center",gap:2*!eE,flexWrap:eE?"wrap":"nowrap",rowGap:4*!!eE},children:[(0,n.jsx)("button",{onClick:()=>eX.current?.click(),disabled:l,title:"Attach image (right-click for document)",style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:tS,height:tS,padding:0,background:"none",border:"none",borderRadius:tC,color:eM.length||eL.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=eM.length||eL.length?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=eM.length||eL.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:e_,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>{l||(_(e=>!e),ey(!1),O(!1),ek(!1),eT(!1))},disabled:l,title:"插入斜杠命令",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:tS,height:tS,padding:0,background:q?"var(--bg-hover)":"none",border:"none",borderRadius:tC,color:f?"#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=f?"#ef4444":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=q?"var(--bg-hover)":"none",e.currentTarget.style.color=f?"#ef4444":"var(--text-muted)"},children:["/",f&&(0,n.jsx)("span",{style:{position:"absolute",top:7,right:7,width:5,height:5,borderRadius:"50%",background:"#ef4444"}})]}),q&&(0,n.jsxs)("div",{style:{...eE?tz:{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:f?"1px solid var(--border)":"none"},children:"Commands"}),f&&(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:f}),v&&(0,n.jsx)("div",{style:{padding:"7px 10px",fontSize:11,color:"#34d399",background:"rgba(52,211,153,0.06)",borderBottom:"1px solid var(--border)",lineHeight:1.45},children:v}),ts.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"}),ts.map(e=>(0,n.jsxs)("button",{onClick:()=>{(_(!1),"/compact"===e.command&&g)?x?.():tM(e.command)},style:{display:"flex",alignItems:"center",gap:eE?6:8,width:"100%",padding:eD,background:"none",border:"none",color:"/compact"===e.command&&g?"#ef4444":"var(--text-muted)",cursor:"pointer",fontSize:eE?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&&g?"#ef4444":"var(--text-dim)"},children:"/compact"===e.command&&g?(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&&g?"停止压缩":e.label}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:"/compact"===e.command&&g?"中止当前压缩任务":e.description})]})]},e.command))]}),ta.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:{marginTop:2*(ts.length>0),padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:ts.length>0?"1px solid var(--border)":"none"},children:"Prompt Shortcuts"}),ta.map(e=>(0,n.jsxs)("button",{onClick:()=>{_(!1),tM(e.command)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:eD,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:eE?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))]}),td.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:{marginTop:2,padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:"1px solid var(--border)"},children:"Skills & Commands"}),td.map(e=>(0,n.jsxs)("button",{onClick:()=>{_(!1),tM(e.command)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:eD,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:eE?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:"skill"===e.source?"✦":"extension"===e.source?"⌘":"/"}),(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:e.dormant?"var(--text-dim)":"var(--text)"},children:e.label}),e.dormant&&(0,n.jsx)("span",{style:{flexShrink:0,padding:"0 4px",fontSize:9,color:"var(--text-dim)",border:"1px solid var(--border)",borderRadius:3},children:"dormant"}),e.description&&(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.description})]}),(0,n.jsx)("span",{style:{flexShrink:0,fontSize:9,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:e.source})]},e.command))]})]})]}),j&&(0,n.jsxs)("div",{ref:eK,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>{l||(ey(e=>!e),_(!1),O(!1),ek(!1),eT(!1))},disabled:l,title:"选择 retain / recall / reflect",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:38,height:e$,padding:0,background:eb?"var(--bg-hover)":"none",border:"none",borderRadius:eE?8:9,color:tf.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=tf.length>0?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=eb?"var(--bg-hover)":"none",e.currentTarget.style.color=tf.length>0?"var(--accent)":"var(--text-muted)"},children:[" >_".trim(),tf.length>0&&(0,n.jsx)("span",{style:{position:"absolute",top:7,right:7,width:5,height:5,borderRadius:"50%",background:"currentColor"}})]}),eb&&(0,n.jsxs)("div",{style:{...eE?tz:{position:"absolute",bottom:"calc(100% + 6px)",left:0,zIndex:100,minWidth:280,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)"},overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderBottom:"1px solid var(--border)"},children:"Memory Tools"}),K.SN.map(e=>{let t=tf.includes(e),r=eo[e];return(0,n.jsxs)("button",{onClick:()=>{j(t?tf.filter(t=>t!==e):[...tf,e])},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:eD,background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:eE?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)})]})]}),eE&&(tm||tb)&&tN(),eE&&!l&&(0,n.jsx)(ee,{open:eC,triggerRef:eG,sheetStyle:tz,cardButtonStyle:{padding:"7px 8px",borderRadius:8,background:"var(--bg-panel)",border:"1px solid var(--border)",width:"100%",textAlign:"left",cursor:"pointer"},iconColor:eA,canSelectModel:tm,canAdjustThinking:tb,canAdjustTools:ty,canAdjustMemory:!!j,mobileModelSummary:tk,thinkingLabel:tj,mobileToolSummary:tw,displayMemoryLabel:tv,memoryEnabled:tf.length>0,onToggle:()=>{_(!1),ey(!1),O(!1),ek(!1),eS(!1),eT(e=>!e)},onOpenModel:e=>{eT(!1),ek(!1),eS(!1),ey(!1),O(!0),H(e)},onOpenTools:()=>{eT(!1),O(!1),eS(!1),ey(!1),ek(!0)},onOpenMemory:()=>{eT(!1),O(!1),ek(!1),eS(!1),ey(!0)}})]}),(0,n.jsx)("div",{className:"chat-input-toolbar-spacer",style:{display:eN?"none":void 0,flex:eE?"0 0 auto":1,width:eE?0:void 0,height:eE?0:void 0}}),(0,n.jsxs)("div",{className:"chat-input-toolbar-right",style:{flex:"0 0 auto",width:eE?"auto":void 0,display:"flex",alignItems:"center",gap:eE?4:2,marginLeft:eE?0:"auto",marginTop:0},children:[(!eN&&!l||eE&&ej)&&ty&&(0,n.jsxs)("div",{ref:eV,style:{position:"relative"},children:[!eN&&!l&&(0,n.jsxs)("button",{onClick:()=>{l||(_(!1),ey(!1),O(!1),eS(!1),eT(!1),ek(e=>!e))},disabled:l,title:"切换工具预设",style:{display:"flex",alignItems:"center",gap:eE?3:5,padding:eD,height:e$,background:ej?"var(--bg-hover)":"none",border:"none",borderRadius:eE?8:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:eE?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=ej?"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:eP,children:tw})]}),ej&&(0,n.jsx)("div",{style:{...eE?tz:{position:"absolute",bottom:"calc(100% + 6px)",right:0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",minWidth:120},overflow:"hidden"},children:et.map(e=>{let t=er[e],r=(m??"full")===t,o="agent"===e&&!1===ez,i=o?"需安装 pi-subagents":en[e];return(0,n.jsxs)("button",{onClick:()=>{!o&&(ek(!1),r||b(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:eE?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)})})]}),!eE&&(tm||tb)&&tN(),l&&(0,n.jsxs)("button",{onClick:t,title:"停止 Agent",style:{display:"flex",alignItems:"center",gap:6,padding:"8px 14px",height:e$,background:"rgba(239,68,68,0.08)",border:"1px solid rgba(239,68,68,0.3)",borderRadius:eE?8:9,color:"#ef4444",cursor:"pointer",fontSize:eE?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"]})]})]})]})]})});function eg(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)"}}let ef=(0,o.memo)(function({messages:e,streamingMessage:t,scrollContainer:r,messageRefs:i}){let[l,s]=(0,o.useState)(0),[a,d]=(0,o.useState)(1),[c,u]=(0,o.useState)(!1),[p,h]=(0,o.useState)([]),[x,g]=(0,o.useState)(!1),[f,v]=(0,o.useState)(null),m=(0,o.useRef)(!1),b=(0,o.useRef)(null),y=(0,o.useMemo)(()=>t?[...e,t]:e,[e,t]),j=(0,o.useRef)(y);j.current=y;let k=(0,o.useRef)(null);k.current=()=>{let e=r.current;if(!e)return;let t=e.scrollHeight,n=e.clientHeight,o=t-n;u(o>20),o<=0?(s(0),d(1)):(s(e.scrollTop/o),d(n/t));let l=i.current,a=[],c=0,p=j.current;for(let r=0;r<p.length;r++){let n=p[r];if("user"!==n.role&&"assistant"!==n.role)continue;let o=l?.[c];if(c++,("user"===n.role||"assistant"===n.role&&(n.content??[]).some(e=>"text"===e.type))&&o&&t>0){let r=o.getBoundingClientRect(),i=e.getBoundingClientRect(),l=r.top-i.top+e.scrollTop,s=r.height;a.push({topRatio:l/t,heightRatio:s/t,msg:n,index:a.length})}}h(a)};let w=(0,o.useCallback)(()=>k.current(),[]);(0,o.useEffect)(()=>{let e=r.current;if(!e)return;e.addEventListener("scroll",w,{passive:!0});let t=new ResizeObserver(w);return t.observe(e),e.firstElementChild&&t.observe(e.firstElementChild),w(),()=>{e.removeEventListener("scroll",w),t.disconnect()}},[r,w]),(0,o.useEffect)(()=>{let e=setTimeout(w,50);return()=>clearTimeout(e)},[e.length,w]);let S=(0,o.useCallback)(e=>{let t=r.current;if(!t)return;let n=t.scrollHeight-t.clientHeight;n<=0||(t.scrollTop=Math.max(0,Math.min(1-a,e))/(1-a)*n)},[r,a]),C=(0,o.useCallback)(e=>{if(!c)return;m.current=!0;let t=e.currentTarget.getBoundingClientRect(),r=(e.clientY-t.top)/t.height,n=r-l*(1-a),o=n>=0&&n<=a?n:a/2;S(r-o);let i=e=>{m.current&&S((e.clientY-t.top)/t.height-o)},s=()=>{m.current=!1,window.removeEventListener("mousemove",i),window.removeEventListener("mouseup",s)};window.addEventListener("mousemove",i),window.addEventListener("mouseup",s)},[c,a,l,S]),T=b.current?.clientHeight??600,z=(0,o.useMemo)(()=>{if(!x||0===p.length)return[];let e=p.map(e=>Math.round(e.topRatio*T-11));for(let t=0;t<10;t++){for(let t=1;t<e.length;t++){let r=e[t-1]+22+2;e[t]<r&&(e[t]=r)}for(let t=e.length-2;t>=0;t--){let r=e[t+1]-22-2;e[t]>r&&(e[t]=r)}}for(let t=0;t<e.length;t++)e[t]=Math.max(0,Math.min(T-22,e[t]));return e},[x,p,T]);if(!c)return null;let I=l*(1-a)*100,M=100*a,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:b,onMouseDown:C,onMouseEnter:()=>g(!0),onMouseLeave:()=>{g(!1),v(null)},onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();v((e.clientY-t.top)/t.height)},style:{width:36,flexShrink:0,position:"relative",cursor:"default",userSelect:"none",borderLeft:"1px solid var(--border)",background:"var(--bg-panel)",overflow:"visible"},children:[(0,n.jsx)("div",{style:{position:"absolute",left:0,right:0,top:`${I}%`,height:`${M}%`,background:"rgba(100,100,100,0.1)",borderTop:"1px solid rgba(100,100,100,0.2)",borderBottom:"1px solid rgba(100,100,100,0.2)",pointerEvents:"none",zIndex:1}}),p.map(e=>{let t=eg(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=eg(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})]})},(e,t)=>e.messages===t.messages&&e.scrollContainer===t.scrollContainer&&e.messageRefs===t.messageRefs&&!!e.streamingMessage==!!t.streamingMessage);function ev(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function em(e,t=220){if(!e)return;let r=e.trim();if(r)return r.length>t?`${r.slice(0,t)}...`:r}function eb(...e){for(let t of e)if("string"==typeof t&&t.trim())return t}function ey(...e){for(let t of e)if("number"==typeof t&&Number.isFinite(t))return t}function ej(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:em(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(!ev(t))return{...e,summary:em(r)};let o=Array.isArray(t.results)?t.results.filter(ev):[],i=o[0],l=i?.progressSummary,s=i&&(n=i.artifactPaths)?Object.values(n).filter(e=>"string"==typeof e&&e.trim().length>0):[],a=eb(i?.finalOutput,i?.output,r);return{...e,mode:eb(t.mode),runId:eb(t.runId),agent:eb(i?.agent,e.agent)??e.agent,task:eb(i?.task,e.task),summary:em(a),model:eb(i?.model),durationMs:ey(l?.durationMs),toolCount:ey(l?.toolCount),tokens:ey(l?.tokens),outputPath:eb(i?.savedOutputPath,i?.artifactPaths?.outputPath),sessionFile:eb(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 ev(t)&&Array.isArray(t.results)&&t.results.some(e=>ev(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 ek({messages:e,runs:t}){let r=(0,o.useMemo)(()=>ej(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)(ew,{title:`Active (${l.length})`,runs:l}),s.length>0&&(0,n.jsx)(ew,{title:`Completed (${s.length})`,runs:s,compact:l.length>0})]})}function ew({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)(eS,{run:e},e.id))]})}function eS({run:e}){let[t,r]=(0,o.useState)(!1),i="running"===e.status,l="completed"===e.status?"#22c55e":"failed"===e.status?"#ef4444":i?"var(--accent)":"var(--text-dim)",s="failed"===e.status?"rgba(248,113,113,0.35)":i?"rgba(99,102,241,0.25)":"var(--border)",a="failed"===e.status?"rgba(248,113,113,0.05)":i?"rgba(99,102,241,0.05)":"var(--bg-panel)",d=[e.mode,e.resultCount&&e.resultCount>1?`${e.resultCount} results`:void 0,void 0!==e.toolCount?`${e.toolCount} tools`:void 0,void 0!==e.tokens?`${e.tokens.toLocaleString()} tok`:void 0,void 0!==e.durationMs?`${Math.round(e.durationMs/1e3)}s`:void 0].filter(Boolean).join(" \xb7 "),c=!!(e.summary||e.outputPath||e.sessionFile||e.artifacts?.length||e.model||e.runId);return(0,n.jsxs)("div",{style:{borderRadius:6,border:`1px solid ${s}`,background:a,marginBottom:6,fontSize:12,overflow:"hidden"},children:[(0,n.jsxs)("button",{onClick:()=>c&&r(e=>!e),style:{display:"flex",alignItems:"center",gap:7,width:"100%",border:"none",background:"transparent",padding:"8px 10px",color:"var(--text-muted)",textAlign:"left",cursor:c?"pointer":"default"},children:[(0,n.jsx)(eC,{running:i,color:l}),(0,n.jsx)("span",{style:{fontWeight:650,color:"var(--text)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.agent}),(0,n.jsx)("span",{style:{color:l,fontSize:10,fontWeight:700,flexShrink:0},children:e.status}),d&&(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,marginLeft:"auto",whiteSpace:"nowrap"},children:d}),c&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:t?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),e.task&&(0,n.jsx)("div",{style:{padding:"0 10px 8px 25px",color:"var(--text-muted)",fontSize:11,lineHeight:1.4},children:em(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)(eT,{run:e})]})]})}function eC({running:e,color:t}){return(0,n.jsx)("span",{style:{width:8,height:8,borderRadius:"50%",background:t,display:"inline-block",animation:e?"pulse 1.5s infinite":void 0,flexShrink:0}})}function eT({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 ez({subagentRuns:e,activeSubagentCount:t,isMobile:r,open:o,onToggle:i}){return 0===e.length?null:(0,n.jsxs)(n.Fragment,{children:[e.length>0&&(0,n.jsxs)("button",{onClick:i,title:o?"Hide subagent runs":"Show subagent runs",style:{position:"absolute",right:r?8:o?260:40,top:8,minWidth:28,height:28,display:"flex",alignItems:"center",justifyContent:"center",gap:6,padding:t>0||e.length>1?"0 8px":0,background:o?"var(--bg-selected)":"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:o?"var(--accent)":"var(--text-dim)",cursor:"pointer",zIndex:30,fontSize:12,transition:"right 0.2s ease, background 0.12s"},onMouseEnter:e=>{o||(e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{o||(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"})]}),(t>0||e.length>1)&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4,fontSize:10,fontWeight:700,color:t>0?"var(--accent)":"var(--text-dim)"},children:[t>0&&(0,n.jsxs)("span",{children:[t," active"]}),(0,n.jsx)("span",{children:e.length})]})]}),o&&e.length>0&&(0,n.jsxs)("div",{style:{position:"absolute",right:r?8:48,top:4,bottom:4,width:r?"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)(ek,{runs:e})]})]})}ef.displayName="ChatMinimap";var eI=r(93449);function eM({agentPhase:e,startedAt:t,queuedCount:r=0,onClearQueue:i}){let[l,s]=(0,o.useState)(0);return(0,o.useEffect)(()=>{if(!t)return void s(0);let e=()=>s(Math.max(0,Math.floor((Date.now()-t)/1e3)));e();let r=setInterval(e,1e3);return()=>clearInterval(r)},[t]),(0,n.jsxs)("div",{className:"py-2 text-[13px] text-text-muted",children:[(0,n.jsxs)("span",{className:"animate-[pulse_1.5s_infinite]",children:[function(e){if(e?.kind==="running_tools"){let t=e.tools.map(e=>e.args??e.name);if(0===t.length)return"Running tool…";if(1===t.length){let r=e.tools[0]?.progress;if(r){let e=r.length>90?`…${r.slice(-87)}`:r;return`Running ${t[0]}: ${e}`}return`Running ${t[0]}…`}return`Running ${t.slice(0,2).join(", ")}${t.length>2?` (+${t.length-2})`:""}…`}return e?.kind==="waiting_model"?"Waiting for model…":"Working…"}(e),"\xa0\xa0",function(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);return`${t}m ${String(e%60).padStart(2,"0")}s`}(l)]}),r>0&&(0,n.jsxs)("span",{style:{marginLeft:10,color:"var(--text-dim)",fontSize:11.5},children:["\xb7 ",r," queued",i&&(0,n.jsx)("button",{type:"button",onClick:i,style:{marginLeft:6,padding:"1px 6px",fontSize:10.5,color:"var(--text-muted)",background:"none",border:"1px solid var(--border)",borderRadius:4,cursor:"pointer"},children:"Clear"})]})]})}function eR({cwd:e}){let[t,r]=(0,o.useState)(null),[i,l]=(0,o.useState)(!1),[s,a]=(0,o.useState)(null),[d,c]=(0,o.useState)(!1);if((0,o.useEffect)(()=>{if(!e){r(null),a(null),c(!1);return}let t=new AbortController;return r(null),a(null),c(!1),fetch(`/api/project-trust?cwd=${encodeURIComponent(e)}`,{signal:t.signal}).then(e=>e.json()).then(e=>{e?.requiresTrust&&r(e)}).catch(()=>{}),()=>t.abort()},[e]),!e||!t?.requiresTrust||t.trusted)return null;let u=async()=>{if(!i){l(!0),a(null);try{let t=await fetch("/api/project-trust",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e})}),n=await t.json();if(!t.ok||n.error)throw Error(n.error??`HTTP ${t.status}`);r({...n,requiresTrust:!0,trusted:!0}),c((n.busy?.length??0)>0)}catch(e){a(e instanceof Error?e.message:String(e))}finally{l(!1)}}};return(0,n.jsxs)("div",{style:{margin:"0 0 10px",padding:"9px 12px",border:"1px solid rgba(245,158,11,0.38)",background:"rgba(245,158,11,0.08)",borderRadius:8,display:"flex",alignItems:"flex-start",gap:10,fontSize:12,lineHeight:1.45},children:[(0,n.jsx)("span",{"aria-hidden":!0,style:{fontSize:14,lineHeight:1.2},children:"⚠"}),(0,n.jsxs)("div",{style:{flex:1,minWidth:0,color:"var(--text)"},children:[(0,n.jsx)("div",{style:{fontWeight:600,marginBottom:2},children:"This project contains untrusted pi resources"}),(0,n.jsxs)("div",{style:{color:"var(--text-muted)"},children:["Project-local extensions, settings and skills stay disabled until you trust this directory. The decision is shared with the ",(0,n.jsx)("code",{children:"pi"})," CLI."]}),d&&(0,n.jsx)("div",{style:{marginTop:4,color:"var(--text-muted)"},children:"A session is currently running. Trust is applied the next time it starts."}),s&&(0,n.jsx)("div",{style:{marginTop:4,color:"#f87171"},children:s})]}),(0,n.jsx)("button",{onClick:u,disabled:i,style:{flexShrink:0,padding:"4px 10px",fontSize:11.5,fontWeight:600,color:"var(--text)",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,cursor:i?"default":"pointer",opacity:i?.6:1},children:i?"Trusting…":"Trust project"})]})}function eL({data:e,session:t,newSessionCwd:r,messages:o,entryIds:i,streamState:l,agentRunning:s,agentPhase:a,agentError:d,isNew:c,isMobile:u,generativeUI:p,effectiveFilePath:h,modelNames:x,toolResultsMap:g,compactionShadowCounts:f,activeSubagentCount:v,subagentRuns:m,subagentPanelOpen:b,onToggleSubagentPanel:y,hasMoreMessages:j,loadMoreMessages:k,totalMessages:w,loadedMessagesCount:S,loadShadowedMessages:C,onFork:T,forkingEntryId:z,onNavigate:I,onEditContent:M,onSendMessage:R,onOpenImage:L,onApplyToFile:W,onRunCode:E,onOpenFileAtLine:P,onAcceptDiff:$,showForkSuggestBanner:D,forkingFresh:N,forkError:A,onForkFresh:O,runStartedAt:B,queuedMessages:H,onClearQueue:F,scrollContainerRef:U,messagesEndRef:q,messageRefs:_,lastUserMsgRef:J}){let K=e?.info?.cwd??t?.cwd??r??null;return(0,n.jsxs)("div",{className:"relative flex flex-1 overflow-hidden",children:[(0,n.jsx)("div",{ref:U,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:u?{paddingBottom:"calc(env(safe-area-inset-bottom, 0px) + 128px)"}:void 0,children:[(0,n.jsx)(eR,{cwd:K}),(()=>{let a=-1;for(let e=o.length-1;e>=0;e--)if("user"===o[e].role){a=e;break}let d=-1;for(let e=o.length-1;e>=0;e--)if("assistant"===o[e].role){d=e;break}let u=0;return(0,n.jsxs)(n.Fragment,{children:[j&&o.length>0&&(0,n.jsx)("div",{style:{textAlign:"center",padding:"8px 0 4px"},children:(0,n.jsxs)("button",{onClick:()=>k(),style:{padding:"6px 16px",fontSize:11,color:"var(--accent)",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,cursor:"pointer",transition:"background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-panel)"},children:["Load ",w-S," earlier message",w-S==1?"":"s"]})}),o.map((v,m)=>{let b=i[m]??`i${m}`,y="user"===v.role&&m>0&&"assistant"===o[m-1].role?i[m-1]:void 0,j="user"===v.role||"assistant"===v.role,k=j?u++:-1,w=!1;if("assistant"===v.role){w=!0;for(let e=m+1;e<o.length;e++){let t=o[e].role;if("user"===t)break;if("assistant"===t){w=!1;break}}w&&l.isStreaming&&m===o.length-1&&(w=!1)}let S=(0,n.jsx)(eI.D,{message:v,toolResults:g,modelNames:x,entryId:i[m],sessionId:e?.sessionId??t?.id??null,compactionShadowCount:f.get(i[m]??""),onLoadShadowed:C,onFork:s||c||0===m&&"user"===v.role?void 0:T,forking:z===i[m],onNavigate:s?void 0:I,prevAssistantEntryId:s?void 0:y,onEditContent:e=>M(e),onSendMessage:R,showTimestamp:w,prevTimestamp:m>0?o[m-1].timestamp:void 0,renderVisualCodeBlocks:!!p,cwd:e?.info?.cwd??t?.cwd??r??void 0,onOpenImage:L,activeFilePath:h,agentRunning:s,onApplyToFile:W,onRunCode:E,onOpenFileAtLine:P,onAcceptDiff:$,forkFresh:D&&m===d?{show:!0,busy:N,error:A,onFork:()=>void O()}:void 0},b);return j?(0,n.jsx)("div",{ref:e=>{_.current[k]=e,m===a&&(J.current=e)},style:{contentVisibility:"auto",containIntrinsicSize:"auto 100px"},children:S},b):S})]})})(),s&&(0,n.jsx)(eM,{agentPhase:a,startedAt:B,queuedCount:H.steering.length+H.followUp.length,onClearQueue:F}),l.isStreaming&&l.streamingMessage&&(0,n.jsx)(eI.D,{sessionId:e?.sessionId??t?.id??null,message:l.streamingMessage,isStreaming:!0,toolResults:g,modelNames:x,onSendMessage:R,renderVisualCodeBlocks:!!p,cwd:e?.info?.cwd??t?.cwd??r??void 0,activeFilePath:h,agentRunning:s,onApplyToFile:W,onRunCode:E,onOpenFileAtLine:P,onAcceptDiff:$}),s&&!l.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);if(0===t.length)return"Running tool...";if(1===t.length){let r=e.tools[0]?.progress;if(r){let e=r.length>90?`...${r.slice(-87)}`:r;return`Running ${t[0]}: ${e}`}return`Running ${t[0]}...`}return t.length<=3?`Running ${t.join(", ")}...`:`Running ${t.slice(0,2).join(", ")} (+${t.length-2})...`}return e?.kind==="waiting_model"?"Waiting for model...":"Thinking..."}(a)})}),e?.info?.cwd&&!1===e.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:e.info.cwd})]}),d&&(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:d}),s&&(0,n.jsx)("div",{style:{height:U.current?U.current.clientHeight:"80vh"}}),(0,n.jsx)("div",{ref:q})]})}),!u&&(0,n.jsx)(ef,{messages:o,streamingMessage:l.streamingMessage,scrollContainer:U,messageRefs:_}),(0,n.jsx)(ez,{subagentRuns:m,activeSubagentCount:v,isMobile:u,open:b,onToggle:y})]})}var eW=r(68477);let eE=["image/","application/pdf","application/vnd.openxmlformats-officedocument","application/msword","application/vnd.ms-"];function eP(e){return eE.some(t=>e.type.startsWith(t))}var e$=r(46786);function eD({statuses:e,widgets:t}){return 0===e.length&&0===t.length?null:(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6,marginBottom:6},children:[e.length>0&&(0,n.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:e.map(e=>(0,n.jsx)("span",{title:e.key,style:{padding:"2px 7px",fontSize:10.5,color:"var(--text-muted)",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:999,whiteSpace:"nowrap"},children:e.text},e.key))}),t.map(e=>(0,n.jsx)("pre",{style:{margin:0,padding:"7px 9px",fontSize:11,lineHeight:1.45,color:"var(--text-muted)",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,overflow:"auto",maxHeight:160,whiteSpace:"pre-wrap",fontFamily:"var(--font-mono)"},children:e.lines.join("\n")},e.key))]})}function eN({notices:e,onDismiss:t}){return 0===e.length?null:(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:5,margin:"0 0 8px"},children:e.map(e=>{let r="error"===e.type?"#f87171":"warning"===e.type?"#fbbf24":"var(--text-muted)";return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8,padding:"6px 9px",fontSize:11.5,lineHeight:1.45,color:r,background:"var(--bg-panel)",border:`1px solid ${"error"===e.type?"rgba(248,113,113,0.35)":"var(--border)"}`,borderRadius:6},children:[(0,n.jsx)("span",{style:{flex:1,minWidth:0,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:e.message}),(0,n.jsx)("button",{type:"button",onClick:()=>t(e.id),style:{flexShrink:0,padding:0,width:18,height:18,lineHeight:"16px",color:"var(--text-dim)",background:"none",border:"1px solid var(--border)",borderRadius:4,cursor:"pointer"},"aria-label":"Dismiss",children:"\xd7"})]},e.id)})})}function eA({request:e,onRespond:t}){let[r,i]=(0,o.useState)(e.prefill??""),l=(0,o.useRef)(null);(0,o.useEffect)(()=>{i(e.prefill??"");let r=setTimeout(()=>l.current?.focus(),30),n=r=>{"Escape"===r.key&&(r.preventDefault(),t(e.id,{cancelled:!0}))};return window.addEventListener("keydown",n),()=>{clearTimeout(r),window.removeEventListener("keydown",n)}},[e,t]);let s=()=>t(e.id,{cancelled:!0});return(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1200,background:"rgba(0,0,0,0.38)",display:"flex",alignItems:"center",justifyContent:"center",padding:16},onClick:e=>{e.target===e.currentTarget&&s()},children:(0,n.jsxs)("div",{role:"dialog","aria-modal":"true",style:{width:440,maxWidth:"100%",maxHeight:"80vh",overflow:"auto",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 12px 40px rgba(0,0,0,0.28)",padding:14},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)",marginBottom:8,whiteSpace:"pre-wrap"},children:e.title||"Extension request"}),"confirm"===e.method&&e.message&&(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.55,marginBottom:12,whiteSpace:"pre-wrap"},children:e.message}),"select"===e.method&&(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:5,marginBottom:12},children:(e.options??[]).map((r,o)=>(0,n.jsx)("button",{type:"button",onClick:()=>t(e.id,{value:r}),style:{padding:"7px 10px",fontSize:12,textAlign:"left",color:"var(--text)",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,cursor:"pointer"},children:r},`${r}-${o}`))}),("input"===e.method||"editor"===e.method)&&(0,n.jsx)("div",{style:{marginBottom:12},children:"input"===e.method?(0,n.jsx)("input",{ref:e=>{l.current=e},value:r,onChange:e=>i(e.target.value),onKeyDown:n=>{"Enter"===n.key&&t(e.id,{value:r})},placeholder:e.placeholder??"",style:{width:"100%",boxSizing:"border-box",padding:"7px 9px",fontSize:12,color:"var(--text)",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,outline:"none"}}):(0,n.jsx)("textarea",{ref:e=>{l.current=e},value:r,onChange:e=>i(e.target.value),rows:8,style:{width:"100%",boxSizing:"border-box",padding:"7px 9px",fontSize:12,lineHeight:1.5,color:"var(--text)",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,resize:"vertical",outline:"none"}})}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:[(0,n.jsx)("button",{type:"button",onClick:s,style:{padding:"5px 11px",fontSize:12,color:"var(--text-muted)",background:"none",border:"1px solid var(--border)",borderRadius:6,cursor:"pointer"},children:"Cancel"}),"select"!==e.method&&(0,n.jsx)("button",{type:"button",onClick:()=>"confirm"===e.method?t(e.id,{confirmed:!0}):t(e.id,{value:r}),style:{padding:"5px 12px",fontSize:12,fontWeight:600,color:"var(--text)",background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:6,cursor:"pointer"},children:"confirm"===e.method?"Confirm":"OK"})]})]})})}var eO=r(31775);function eB(e={visibilityState:document.visibilityState,hasFocus:document.hasFocus()}){return"visible"!==e.visibilityState||!e.hasFocus}async function eH(){if(!("Notification"in window))return null;if("default"!==Notification.permission)return Notification.permission;try{return await Notification.requestPermission()}catch{return null}}function eF(e,t={}){if(!function(e={}){return"Notification"in window&&"granted"===(e.permission??("u">typeof Notification?Notification.permission:void 0))}(t))return!1;try{let r=(t.createNotification??((e,t)=>new Notification(e,t)))(e.title,{body:e.body,tag:e.tag,silent:!1});return r.onclick=()=>{try{window.focus()}catch{}e.onClick?.(),r.close()},!0}catch{return!1}}function eU(e){let t=e.content;return"string"==typeof t?t:Array.isArray(t)?t.filter(e=>!!e&&"object"==typeof e&&"text"===e.type&&"string"==typeof e.text).map(e=>e.text).join("\n"):""}let eq=["annotate and analyze.","vibe code bioinformatics.","turn data into figures.","inspect your project.","build a reproducible report.","run R/Python plots.","summarize that paper.","review the pipeline.","compare markers.","draft methods.","find the next analysis step."];function e_({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 eJ({status:e}){let t=e?.current??"0.8.147"??"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 eK({session:e,newSessionCwd:t,onAgentEnd:r,onSessionCreated:i,onSessionForked:l,modelsRefreshKey:s,chatInputRef:a,onBranchDataChange:d,onSessionStatsChange:c,onContextUsageChange:u,generativeUI:p,forkSettings:h,activeFilePath:x,onOpenFileAtLine:g}){var f;let v,[m,b]=(0,o.useState)(null),[y,j]=(0,o.useState)(!1),k=x&&!y?x:null;(0,o.useEffect)(()=>{j(!1)},[x]);let w=e?.name?.trim()||(e?.cwd?e.cwd.replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean).pop():"")||"",S=(0,o.useCallback)(()=>{eB()&&eF({title:w?`${M} \xb7 ${w}`:M,body:"Agent finished",tag:`agent-done-${e?.id??"new"}`}),r?.()},[w,r,e?.id]),{data:C,loading:T,error:z,messages:I,entryIds:R,streamState:L,agentRunning:W,modelNames:E,modelList:P,modelThinkingLevels:$,modelThinkingLevelMaps:D,toolPreset:N,memoryTools:A,thinkingLevel:O,slashCommands:B,retryInfo:H,queuedMessages:F,contextUsage:U,forkingEntryId:q,isCompacting:_,compactError:J,compactInfo:K,displayModel:V,sessionStats:Y,agentPhase:G,agentError:X,extensionStatuses:Z,extensionWidgets:Q,extensionDialog:ee,extensionNotices:et,bashLive:er,bashRunning:en,respondToExtensionUi:eo,dismissExtensionNotice:ei,isNew:el,loadMoreMessages:es,hasMoreMessages:ea,totalMessages:ed,loadedMessagesCount:ec,loadShadowedMessages:eu,messagesEndRef:ep,scrollContainerRef:eh,lastUserMsgRef:eg,handleSend:ef,handleAbort:ev,handleFork:em,handleNavigate:eb,handleModelChange:ey,handleCompact:ek,handleSteer:ew,handleFollowUp:eS,handleAbortCompaction:eC,handleToolPresetChange:eT,handleMemoryToolsChange:ez,handleThinkingLevelChange:eI,handleClearQueue:eM,handleBash:eE,handleAgentEventRef:eV,forkToNewSession:eY}=(0,eW.T)({chatInputRef:a,session:e,newSessionCwd:t,onAgentEnd:S,onSessionCreated:i,onSessionForked:l,modelsRefreshKey:s,onBranchDataChange:d});(0,o.useEffect)(()=>{ee&&eB()&&eF({title:`${M} \xb7 action required`,body:ee.title||"An extension needs your input",tag:`extension-ui-${ee.id}`})},[ee]);let eG=(0,o.useCallback)(()=>{eH()},[]),eX=(0,o.useMemo)(()=>{let e=new Map;for(let t of C?.context.compactions??[])e.set(t.entryId,t.shadowedCount);return e},[C?.context.compactions]),[eZ,eQ]=(0,o.useState)(!1),[e0,e1]=(0,o.useState)(null),e2=(0,o.useRef)(!1),e5=h??{enabled:!1,suggestEnabled:!0,suggestTokens:18e4,autoTokens:4e5,minMessages:20};(0,o.useEffect)(()=>{e1(null),e2.current=!1},[e?.id]);let e4=(0,o.useCallback)(()=>{let r=C?.info?.cwd??e?.cwd??t??null,n=I.filter(e=>"user"===e.role||"assistant"===e.role),o=n.filter(e=>"user"===e.role),i=n.filter(e=>"assistant"===e.role),l=o[0],s=o[o.length-1],a=i[i.length-1],d=(e,t)=>{let r=e.replace(/\s+/g," ").trim();return r.length>t?`${r.slice(0,t)}…`:r};return["以下是从父会话 fork 出的新会话。工作仍在原项目目录中进行,但本会话只携带精简摘要,完整历史不再重发(避免模型 prefill 变慢)。",r?`工作目录: ${r}`:"",l?`最初目标: ${d(eU(l),500)}`:"",s?`最近一次请求: ${d(eU(s),500)}`:"",a?`最近回复要点: ${d(eU(a),900)}`:"",`父会话共 ${ed||n.length} 条消息。若需要更早的细节,请说明是哪个任务,我会让你查看父会话文件或重新提供。`].filter(Boolean).join("\n\n")},[C?.info?.cwd,e?.cwd,t,I,ed]),e8=(0,o.useCallback)(async()=>{if(W||eZ)return{ok:!1,error:"Session is busy"};eQ(!0),e1(null);try{let e=await eY(e4());return e.ok||e1(e.error??"Fork failed"),e}finally{eQ(!1)}},[W,eZ,eY,e4]),e3=U?.tokens??null,e6=I.filter(e=>"user"===e.role||"assistant"===e.role).length,e7=!el&&!W&&!1!==e5.suggestEnabled&&null!=e3&&e3>=e5.suggestTokens&&e6>=e5.minMessages;(0,o.useEffect)(()=>{if(!e5.enabled||el||W)return;let t=U?.tokens;if(null==t||t<e5.autoTokens||e6<e5.minMessages||e2.current)return;let r=e?.id;if(r){try{if(localStorage.getItem(`annovibe.autoFork.dismiss.${r}`))return}catch{}e2.current=!0,(async()=>{let e=await eY(e4());if(e.ok)try{localStorage.setItem(`annovibe.autoFork.dismiss.${r}`,String(Date.now()))}catch{}else e2.current=!1,e1(e.error??"Auto-fork failed")})()}},[e5.enabled,e5.autoTokens,e5.minMessages,el,W,U?.tokens,e6,e?.id,eY,e4]),(0,o.useEffect)(()=>{W&&!m&&b(Date.now()),W||b(null)},[W,m]);let e9=eV.current;(0,o.useEffect)(()=>{eV.current=e=>{"agent_start"===e.type&&b(Date.now()),("agent_end"===e.type&&!0!==e.willRetry||"agent_settled"===e.type)&&b(null),e9?.(e)}},[e9,eV]);let te=Y?`${Y.tokens.input}|${Y.tokens.output}|${Y.tokens.cacheRead}|${Y.tokens.cacheWrite}`:null,tt=(0,o.useRef)(Y);tt.current=Y,(0,o.useEffect)(()=>{c?.(tt.current)},[te,c]),(0,o.useEffect)(()=>()=>{c?.(null)},[c]);let tr=U?`${U.percent??"null"}|${U.contextWindow}|${U.tokens??"null"}`:null,tn=(0,o.useRef)(U);tn.current=U,(0,o.useEffect)(()=>{u?.(tn.current)},[tr,u]),(0,o.useEffect)(()=>()=>{u?.(null)},[u]);let to=(0,o.useCallback)(e=>{a?.current?.addFiles(e)},[a]),ti=(0,o.useCallback)((e,t,r)=>{let n=r?.findIndex(t=>t.src===e)??-1;tx({src:e,gallery:r,index:n>=0?n:0})},[]),{isDragOver:tl,handleDragEnter:ts,handleDragOver:ta,handleDragLeave:td,handleDrop:tc}=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(eP)&&(e.preventDefault(),n.current+=1,r(!0))},[]),l=(0,o.useCallback)(e=>{Array.from(e.dataTransfer.items).some(eP)&&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])}}(to),[tu,tp]=(0,o.useState)(null),[th,tx]=(0,o.useState)(null);(0,o.useEffect)(()=>{if(!el)return;let e=!1;return fetch("/api/version").then(e=>e.ok?e.json():null).then(t=>{!e&&t?.updateAvailable&&tp(t)}).catch(()=>{}),()=>{e=!0}},[el]);let tg=I.filter(e=>"user"===e.role||"assistant"===e.role),tf=(f=tg.length,(v=(0,o.useRef)([])).current=Array(f).fill(null).map((e,t)=>v.current[t]??null),v),tv=(0,o.useMemo)(()=>{let e=new Map;for(let t of I)"toolResult"===t.role&&e.set(t.toolCallId,t);return e},[I]),tm=el&&0===I.length&&!L.isStreaming&&!W,tb=C?.info?.cwd??e?.cwd??t??null,ty=function(e){if(!e)return null;let t=e.replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean);return t[t.length-1]||e}(tb),tj=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}(),[tk,tw]=(0,o.useState)(!1),tS=ej(I),tC=tS.filter(e=>"running"===e.status).length;(0,o.useEffect)(()=>{0===tS.length&&tk&&tw(!1)},[tS.length,tk]),(0,o.useEffect)(()=>{tj&&tk&&tw(!1)},[tj,tk]);let tT=V?$[`${V.provider}:${V.modelId}`]??null:null,tz=V?D[`${V.provider}:${V.modelId}`]??null:null,tI=e?.id??t??"new-chat",tM=(0,o.useMemo)(()=>(function(e){let t=[];for(let r=e.length-1;r>=0;r-=1){let n=e[r];if("user"!==n.role)continue;let o=n.text.trim();o&&t.push(o)}return t})(tg.map(e=>({role:e.role,text:eU(e)}))),[tg]),tR=(0,o.useCallback)(async(e,t,r)=>{eG();let n=e;k&&e.trim()&&(n=`${e}
7
+
8
+ [Current file: \`${k}\`]`),await ef(n,t,r)},[ef,k,eG]),tL=(0,n.jsxs)("div",{children:[(0,n.jsx)(eN,{notices:et,onDismiss:ei}),(0,n.jsx)(eD,{statuses:Z,widgets:Q}),(0,n.jsx)(ex,{ref:a,onSend:tR,onAbort:ev,onSteer:W&&!en?ew:void 0,onFollowUp:W&&!en?eS:void 0,onBash:e?.id||C?.sessionId?(e,t)=>{eG(),eE(e,t)}:void 0,bashRunning:en,isStreaming:W,model:V,modelNames:E,modelList:P,onModelChange:ey,onCompact:e||el?ek:void 0,onAbortCompaction:eC,isCompacting:_,compactError:J,compactInfo:K,toolPreset:N,onToolPresetChange:e||el?eT:void 0,memoryTools:A,onMemoryToolsChange:e||el?ez:void 0,thinkingLevel:O,onThinkingLevelChange:e||el?eI:void 0,availableThinkingLevels:tT,thinkingLevelMap:tz,retryInfo:H,cornerBadge:tm?(0,n.jsx)(eJ,{status:tu}):void 0,promptHistory:tM,sessionHistoryKey:tI,draftKey:tI,slashCommands:B,cwd:C?.info?.cwd??e?.cwd??t??void 0,activeFilePath:k,onDismissFileContext:()=>j(!0)})]}),tW=(0,o.useCallback)(e=>{W?a?.current?.insertText(e):ef(e)},[W,a,ef]),tE=(0,o.useCallback)((e,t,r)=>{if(W)return;let n=e.includes("```")?"````":"```",o=`${n}${t||""}
9
+ ${e}
10
+ ${n}`,i=r?` to \`${r}\``:" to the appropriate file";ef(`Please write the following code${i} and then run it to show the result:
11
+
12
+ ${o}`)},[W,ef]),tP=(0,o.useCallback)((e,t)=>{if(W)return;let r=e.includes("```")?"````":"```",n=`${r}${t||""}
13
+ ${e}
14
+ ${r}`;ef(`Please run the following code and show the output:
15
+
16
+ ${n}`)},[W,ef]),t$=(0,o.useCallback)((e,t)=>{if(W)return;let r=t?` to \`${t}\``:"",n=e.includes("```")?"````":"```",o=`${n}diff
17
+ ${e}
18
+ ${n}`;ef(`Please apply this diff${r}:
19
+
20
+ ${o}`)},[W,ef]);return T?(0,n.jsx)("div",{className:"flex h-full items-center justify-center text-text-muted",children:"Loading session..."}):z?(0,n.jsx)("div",{className:"flex h-full items-center justify-center text-red-400",children:z}):(0,n.jsx)(e$.o,{sessionId:C?.sessionId??e?.id??null,children:(0,n.jsxs)("div",{className:"relative flex h-full flex-col overflow-hidden",onDragEnter:ts,onDragOver:ta,onDragLeave:td,onDrop:tc,children:[tl&&(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"})]})]})]}),tm?(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.jsxs)("div",{className:"mb-3",style:{display:"flex",flexDirection:"column",alignItems:"stretch",justifyContent:"flex-start",gap:10,marginLeft:16,marginRight:16,fontFamily:"var(--font-mono)"},children:[ty&&(0,n.jsxs)("div",{style:{padding:tj?"7px 9px":"9px 12px",border:"1px solid var(--border)",borderRadius:tj?9:10,background:"var(--bg-panel)",minWidth:0,display:"flex",alignItems:"flex-start",gap:tj?8:10,boxShadow:"none"},children:[(0,n.jsx)("div",{"aria-hidden":!0,style:{flex:"0 0 auto",width:tj?18:20,height:tj?18:20,borderRadius:6,marginTop:1,background:"rgba(37,99,235,0.10)",border:"1px solid rgba(37,99,235,0.20)",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--accent)"},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:"M3 7.5 12 4l9 3.5-9 3.5-9-3.5Z"}),(0,n.jsx)("path",{d:"M7 10v4.5c0 .8 2.2 2 5 2s5-1.2 5-2V10"})]})}),(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsx)("div",{style:{fontSize:9,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.08em",marginBottom:2},children:"Current Project"}),(0,n.jsx)("div",{style:{fontSize:tj?12.5:14,color:"var(--text)",fontWeight:700,lineHeight:1.3,wordBreak:"break-word"},children:ty}),tb&&(0,n.jsx)("div",{title:tb,style:{fontSize:10.5,color:"var(--text-dim)",marginTop:2,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:tb})]})]}),(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:M}),(0,n.jsx)("span",{style:{fontSize:14,minWidth:0,overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"},children:(0,n.jsx)(e_,{phrases:eq})})]})]}),(0,n.jsx)(eR,{cwd:tb}),tL]})}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(eL,{data:C,session:e,newSessionCwd:t,messages:I,entryIds:R,streamState:L,agentRunning:W,agentPhase:G,agentError:X,isNew:el,isMobile:tj,generativeUI:!!p,effectiveFilePath:k,modelNames:E,toolResultsMap:tv,compactionShadowCounts:eX,activeSubagentCount:tC,subagentRuns:tS,subagentPanelOpen:tk,onToggleSubagentPanel:()=>tw(e=>!e),hasMoreMessages:ea,loadMoreMessages:es,totalMessages:ed,loadedMessagesCount:ec,loadShadowedMessages:eu,onFork:W||el?void 0:em,forkingEntryId:q,onNavigate:W?void 0:eb,onEditContent:e=>a?.current?.insertIfEmpty(e),onSendMessage:tW,onOpenImage:ti,onApplyToFile:tE,onRunCode:tP,onOpenFileAtLine:g,onAcceptDiff:t$,showForkSuggestBanner:e7,forkingFresh:eZ,forkError:e0,onForkFresh:()=>void e8(),runStartedAt:m,queuedMessages:F,onClearQueue:eM,scrollContainerRef:eh,messagesEndRef:ep,messageRefs:tf,lastUserMsgRef:eg}),(0,n.jsxs)("div",{className:"relative",children:[er&&(0,n.jsx)("div",{className:"mx-auto w-full max-w-[820px] px-4 pb-2",children:(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,overflow:"hidden",background:"var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{padding:"6px 10px",borderBottom:"1px solid var(--border)",fontFamily:"var(--font-mono)",fontSize:11.5,color:"var(--text)"},children:[(0,n.jsx)("span",{style:{color:"var(--accent)"},children:"$"})," ",er.command]}),(0,n.jsx)(eO.m,{text:er.output||"Running…",maxHeight:260,collapsible:!0,background:"var(--bg)",textColor:"var(--text-muted)"})]})}),tL]})]}),ee&&(0,n.jsx)(eA,{request:ee,onRespond:eo}),th&&(0,n.jsxs)("div",{style:{position:"fixed",inset:0,zIndex:100,background:"rgba(0,0,0,0.85)",display:"flex",alignItems:"center",justifyContent:"center",cursor:"zoom-out"},onClick:()=>tx(null),children:[th.gallery&&th.gallery.length>1&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{style:{position:"absolute",left:16,top:"50%",transform:"translateY(-50%)",background:"rgba(255,255,255,0.15)",border:"none",borderRadius:8,color:"#fff",fontSize:28,width:44,height:44,display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",zIndex:101},onClick:e=>{e.stopPropagation();let t=((th.index??0)-1+th.gallery.length)%th.gallery.length;tx({...th,src:th.gallery[t].src,index:t})},children:"←"}),(0,n.jsx)("button",{style:{position:"absolute",right:16,top:"50%",transform:"translateY(-50%)",background:"rgba(255,255,255,0.15)",border:"none",borderRadius:8,color:"#fff",fontSize:28,width:44,height:44,display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",zIndex:101},onClick:e=>{e.stopPropagation();let t=((th.index??0)+1)%th.gallery.length;tx({...th,src:th.gallery[t].src,index:t})},children:"→"})]}),(0,n.jsx)("img",{src:th.src,alt:"",style:{maxWidth:"95vw",maxHeight:"95vh",objectFit:"contain",borderRadius:8,boxShadow:"0 8px 40px rgba(0,0,0,0.5)"}}),(0,n.jsx)("div",{style:{position:"absolute",bottom:16,left:"50%",transform:"translateX(-50%)",background:"rgba(0,0,0,0.5)",color:"rgba(255,255,255,0.7)",borderRadius:6,padding:"4px 12px",fontSize:12},children:th.gallery&&th.gallery.length>1?`${(th.index??0)+1} / ${th.gallery.length}`:"Click anywhere to close"})]})]})})}var eV=r(25618),eY=r(76577);class eG extends o.Component{static getDerivedStateFromError(e){return{hasError:!0,message:e instanceof Error?e.message:String(e)}}componentDidCatch(e,t){console.error("File viewer crashed",{filePath:this.props.filePath,error:e,componentStack:t.componentStack})}componentDidUpdate(e){e.filePath!==this.props.filePath&&this.state.hasError&&this.setState({hasError:!1,message:null})}render(){return this.state.hasError?(0,n.jsx)(eY.fj,{style:{background:"var(--bg)"},children:(0,n.jsx)(eY.nG,{tone:"error",children:(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8,alignItems:"center",textAlign:"center"},children:[(0,n.jsx)("div",{children:"Preview crashed for this file."}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)",maxWidth:560,wordBreak:"break-word"},children:this.props.filePath}),this.state.message&&(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)",maxWidth:560,wordBreak:"break-word"},children:this.state.message})]})})}):this.props.children}constructor(...e){super(...e),this.state={hasError:!1,message:null}}}function eX(e,t,r){return Math.min(Math.max(e,t),r)}function eZ({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),b=(0,o.useRef)(null),y=(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:eX(e.left,8,Math.max(8,window.innerWidth-n-8)),top:eX(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),b.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=b.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:eX(r,8,Math.max(8,window.innerWidth-120)),top:eX(n,8,Math.max(8,window.innerHeight-48))}))},[]),w=(0,o.useCallback)(e=>{let t=b.current;t?.pointerId===e.pointerId&&(e.currentTarget.releasePointerCapture(e.pointerId),b.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),y.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=y.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:eX(r,360,Math.max(360,window.innerWidth-e.left-8)),height:eX(n,280,Math.max(280,window.innerHeight-e.top-8))}))},[]),z=(0,o.useCallback)(e=>{let t=y.current;t?.pointerId===e.pointerId&&(e.currentTarget.releasePointerCapture(e.pointerId),y.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:eQ,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:eQ,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)(eG,{filePath:t,children:(0,n.jsx)(eV.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 eQ={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};function e0(e){return{dirCache:new Map,pathIndex:new Map,loadedDirs:new Set,revision:0,workspaceRoot:e}}function e1(e,t){if(t.delete(e.path),e.children)for(let r of e.children)e1(r,t)}function e2(e,t,r){let n=new Map;if(t)for(let e of t)n.set(e.path,e);if(t){let n=new Set(e.map(e=>e.path));for(let e of t)n.has(e.path)||e1(e,r)}return e.map(e=>{let t=n.get(e.path);return t&&(e.id=t.id,t.childrenLoaded&&t.children?(e.children=t.children,e.childrenLoaded=!0):t.childrenLoaded&&!t.children&&(e.childrenLoaded=!0)),r.set(e.path,e),e})}function e5(e,t,r){let n=e2(r,e.dirCache.get(t),e.pathIndex);e.dirCache.set(t,n),e.loadedDirs.add(t)}function e4(e,t,r){let n=e.dirCache.get(t);if(!n)return;let o=n.findIndex(e=>e.path===r.path);if(-1!==o){let e=n[o];"folder"===e.type&&"folder"===r.type&&(r.children=e.children,r.childrenLoaded=e.childrenLoaded),n[o]=r}else n.push(r),n.sort(e3);e.pathIndex.set(r.path,r)}function e8(e,t,r){let n=e.dirCache.get(t);n&&e.dirCache.set(t,n.filter(e=>e.path!==r));let o=e.pathIndex.get(r);o&&e1(o,e.pathIndex),e.dirCache.delete(r),e.loadedDirs.delete(r)}function e3(e,t){return"folder"===e.type&&"folder"!==t.type?-1:"folder"!==e.type&&"folder"===t.type?1:e.name.localeCompare(t.name)}let e6=new Set(["node_modules","vendor","venv",".venv","Pods","dist","build","out","target",".output","bin","obj",".next",".nuxt",".cache",".turbo",".parcel-cache",".git",".svn",".hg",".idea",".vscode",".vs","coverage",".nyc_output","__pycache__",".pytest_cache",".mypy_cache",".tox","logs","tmp","temp",".annodex-uploads"]),e7="var(--text-dim)";function e9({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:e7}),(0,n.jsx)("path",{d:"M1 6h14.5L14 13H2L1 6Z",stroke:e7,strokeWidth:"1",fill:e7,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:e7,strokeWidth:"1",fill:e7,fillOpacity:"0.1"})})}function te({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:e7,strokeWidth:"1",fill:e7,fillOpacity:"0.08"}),(0,n.jsx)("path",{d:"M10 2v3h3",stroke:e7,strokeWidth:"1",fill:"none",strokeLinejoin:"round"})]})}function tt({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:e7,strokeWidth:"0.9",fill:e7,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:e7,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:e7,letterSpacing:"0",children:e})]})}function tr({size:e=14}){return(0,n.jsx)(tt,{label:"TS",size:e})}function tn({size:e=14}){return(0,n.jsx)(tt,{label:"TSX",size:e})}function to({size:e=14}){return(0,n.jsx)(tt,{label:"JS",size:e})}function ti({size:e=14}){return(0,n.jsx)(tt,{label:"JSX",size:e})}function tl({size:e=14}){return(0,n.jsx)(tt,{label:"PY",size:e})}function ts({size:e=14}){return(0,n.jsx)(tt,{label:"{}",size:e})}function ta({size:e=14}){return(0,n.jsx)(tt,{label:"CSS",size:e})}function td({size:e=14}){return(0,n.jsx)(tt,{label:"SC",size:e})}function tc({size:e=14}){return(0,n.jsx)(tt,{label:"HTM",size:e})}function tu({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:e7,strokeWidth:"0.9",fill:e7,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:e7,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M3.5 9.5V7l1.5 1.5L6.5 7v2.5",stroke:e7,strokeWidth:"0.9",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,n.jsx)("path",{d:"M8 7v2.5M7 9l1 1.5 1-1.5",stroke:e7,strokeWidth:"0.9",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]})}function tp({size:e=14}){return(0,n.jsx)(tt,{label:"YML",size:e})}function th({size:e=14}){return(0,n.jsx)(tt,{label:"TOM",size:e})}function tx({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:e7,strokeWidth:"0.9",fill:e7,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:e7,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M4 7.5l2 1.5-2 1.5",stroke:e7,strokeWidth:"0.95",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,n.jsx)("path",{d:"M7.5 10.5h2.5",stroke:e7,strokeWidth:"0.95",strokeLinecap:"round"})]})}function tg({size:e=14}){return(0,n.jsx)(tt,{label:"RS",size:e})}function tf({size:e=14}){return(0,n.jsx)(tt,{label:"GO",size:e})}function tv({size:e=14}){return(0,n.jsx)(tt,{label:"SQL",size:e})}function tm({size:e=14}){return(0,n.jsx)(tt,{label:"GQL",size:e})}function tb({size:e=14}){return(0,n.jsx)(tt,{label:"TF",size:e})}function ty({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:e7,strokeWidth:"0.9",fill:e7,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:e7,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:e7,strokeWidth:"0.8"}),(0,n.jsx)("rect",{x:"6",y:"6.5",width:"2",height:"1.5",rx:"0.3",stroke:e7,strokeWidth:"0.8"}),(0,n.jsx)("rect",{x:"3.5",y:"8.5",width:"2",height:"1.5",rx:"0.3",stroke:e7,strokeWidth:"0.8"})]})}function tj({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:e7,strokeWidth:"0.9",fill:e7,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:e7,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"5.5",cy:"8.5",r:"1.5",stroke:e7,strokeWidth:"0.9"}),(0,n.jsx)("path",{d:"M7 8.5h2.5M8.5 8.5v1.5",stroke:e7,strokeWidth:"0.9",strokeLinecap:"round"})]})}function tk({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:e7,strokeWidth:"0.9",fill:e7,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:e7,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"5",cy:"6.5",r:"1",stroke:e7,strokeWidth:"0.85"}),(0,n.jsx)("circle",{cx:"9",cy:"6.5",r:"1",stroke:e7,strokeWidth:"0.85"}),(0,n.jsx)("circle",{cx:"5",cy:"10",r:"1",stroke:e7,strokeWidth:"0.85"}),(0,n.jsx)("path",{d:"M5 7.5V9",stroke:e7,strokeWidth:"0.85",strokeLinecap:"round"}),(0,n.jsx)("path",{d:"M9 7.5v.5a2 2 0 0 1-2 2H6",stroke:e7,strokeWidth:"0.85",strokeLinecap:"round",fill:"none"})]})}function tw({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:e7,strokeWidth:"0.9",fill:e7,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:e7,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:e7,strokeWidth:"0.9"}),(0,n.jsx)("path",{d:"M5.5 8.5V7.5a1.5 1.5 0 0 1 3 0v1",stroke:e7,strokeWidth:"0.9",strokeLinecap:"round",fill:"none"})]})}function tS({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:e7,strokeWidth:"0.9",fill:e7,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:e7,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"7",cy:"8.5",r:"1.3",stroke:e7,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:e7,strokeWidth:"0.8",strokeLinecap:"round"})]})}function tC(e,t=14){let r=e.toLowerCase(),o=r.split(".").pop()??"";if("dockerfile"===r||r.startsWith("dockerfile."))return(0,n.jsx)(ty,{size:t});if(".env"===r||r.startsWith(".env."))return(0,n.jsx)(tj,{size:t});if(".gitignore"===r||".gitattributes"===r||".gitmodules"===r)return(0,n.jsx)(tk,{size:t});if("package-lock.json"===r||"yarn.lock"===r||"bun.lock"===r||"pnpm-lock.yaml"===r||"cargo.lock"===r)return(0,n.jsx)(tw,{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)(tS,{size:t});switch(o){case"ts":return(0,n.jsx)(tr,{size:t});case"tsx":return(0,n.jsx)(tn,{size:t});case"js":case"mjs":case"cjs":return(0,n.jsx)(to,{size:t});case"jsx":return(0,n.jsx)(ti,{size:t});case"py":return(0,n.jsx)(tl,{size:t});case"json":case"jsonl":return(0,n.jsx)(ts,{size:t});case"css":case"less":return(0,n.jsx)(ta,{size:t});case"scss":return(0,n.jsx)(td,{size:t});case"html":case"htm":return(0,n.jsx)(tc,{size:t});case"md":case"mdx":return(0,n.jsx)(tu,{size:t});case"yaml":case"yml":return(0,n.jsx)(tp,{size:t});case"toml":return(0,n.jsx)(th,{size:t});case"sh":case"bash":case"zsh":case"fish":return(0,n.jsx)(tx,{size:t});case"rs":return(0,n.jsx)(tg,{size:t});case"go":return(0,n.jsx)(tf,{size:t});case"sql":return(0,n.jsx)(tv,{size:t});case"graphql":case"gql":return(0,n.jsx)(tm,{size:t});case"tf":case"hcl":return(0,n.jsx)(tb,{size:t});case"lock":return(0,n.jsx)(tw,{size:t});default:return(0,n.jsx)(te,{size:t})}}let tT=o.memo(function({node:e,depth:t,isExpanded:r,isLoading:i,isSelected:l,isRenaming:s,isUploadTarget:a,onClick:d,onDoubleClick:c,onContextMenu:u,onRenameSubmit:p,onRenameCancel:h,onDragEnter:x,onDragOver:g,onDragLeave:f,onDrop:v}){var m;let b=!!(m=e.name).startsWith(".")||e6.has(m),[y,j]=o.useState(!1),[k,w]=o.useState(e.name),S=o.useRef(null);o.useEffect(()=>{if(s&&S.current){let t=e.name.lastIndexOf(".");"file"===e.type&&t>0?S.current.setSelectionRange(0,t):S.current.select(),S.current.focus()}},[s,e.name,e.type]);let C=(0,o.useCallback)(()=>{s||d(e.path,"folder"===e.type)},[s,e.path,e.type,d]),T=(0,o.useCallback)(()=>{s||c(e.path)},[s,e.path,c]),z=(0,o.useCallback)(t=>{s||u(t,e.path)},[s,e.path,u]),I=(0,o.useCallback)(t=>{if("Enter"===t.key){t.preventDefault();let r=k.trim();r&&r!==e.name?p(e.path,r):h()}else"Escape"===t.key&&(t.preventDefault(),h())},[k,e.name,e.path,p,h]),M=(0,o.useCallback)(()=>{let t=k.trim();t&&t!==e.name?p(e.path,t):h()},[k,e.name,e.path,p,h]);return(0,n.jsxs)("div",{onClick:C,onDoubleClick:T,onContextMenu:z,onMouseEnter:()=>j(!0),onMouseLeave:()=>j(!1),onDragEnter:x,onDragOver:g,onDragLeave:f,onDrop:v,style:{position:"relative",display:"flex",alignItems:"center",gap:4,paddingLeft:8+14*t,paddingRight:8,height:26,cursor:"pointer",background:a?"rgba(37,99,235,0.14)":l?"var(--bg-selected)":y?"var(--bg-hover)":"transparent",outline:a?"1px solid rgba(37,99,235,0.42)":"none",outlineOffset:-1,borderRadius:4,userSelect:"none",transition:"background 0.08s",opacity:b?.65:1},children:["folder"===e.type?(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:r?"rotate(90deg)":"none",transition:"transform 0.1s"},children:(0,n.jsx)("polyline",{points:"3 2 7 5 3 8"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),i?(0,n.jsx)("span",{style:{flexShrink:0,width:14,height:14,display:"flex",alignItems:"center"},children:(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",style:{animation:"spin 1s linear infinite"},children:(0,n.jsx)("path",{d:"M12 2v4M12 18v4M4.93 4.93l2.83 2.83M16.24 16.24l2.83 2.83M2 12h4M18 12h4"})})}):(0,n.jsx)("span",{style:{flexShrink:0,display:"flex",alignItems:"center"},children:"folder"===e.type?(0,n.jsx)(e9,{size:14,open:r}):tC(e.name,14)}),s?(0,n.jsx)("input",{ref:S,value:k,onChange:e=>w(e.target.value),onKeyDown:I,onBlur:M,style:{flex:1,minWidth:0,height:22,padding:"0 4px",fontSize:12,fontFamily:"inherit",color:"var(--text)",background:"var(--bg-input, var(--bg))",border:"1px solid var(--accent)",borderRadius:3,outline:"none"},onClick:e=>e.stopPropagation(),onDoubleClick:e=>e.stopPropagation(),onContextMenu:e=>e.stopPropagation()}):(0,n.jsx)("span",{style:{fontSize:12,color:b?"var(--text-dim)":"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},title:e.path,children:e.name})]})});function tz({x:e,y:t,actions:r,onClose:i}){let l=(0,o.useRef)(null),[s,a]=o.useState(e),[d,c]=o.useState(t);return((0,o.useEffect)(()=>{if(l.current){let r=l.current.getBoundingClientRect(),n=e,o=t;n+r.width>window.innerWidth-8&&(n=window.innerWidth-r.width-8),o+r.height>window.innerHeight-8&&(o=window.innerHeight-r.height-8),a(n),c(o)}},[e,t]),(0,o.useEffect)(()=>{let e=e=>{l.current&&!l.current.contains(e.target)&&i()},t=e=>{"Escape"===e.key&&i()},r=setTimeout(()=>{document.addEventListener("mousedown",e),document.addEventListener("keydown",t)},0);return()=>{clearTimeout(r),document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[i]),0===r.length)?null:(0,n.jsx)("div",{ref:l,style:{position:"fixed",left:s,top:d,zIndex:1e3,minWidth:190,padding:"4px 0",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 8px 24px rgba(0,0,0,0.18)",fontSize:12},children:r.map((e,t)=>(0,n.jsxs)(o.Fragment,{children:[e.separator&&t>0&&(0,n.jsx)("div",{style:{height:1,margin:"4px 8px",background:"var(--border)"}}),(0,n.jsxs)("div",{onClick:t=>{t.stopPropagation(),e.onClick(),i()},style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 12px",cursor:"pointer",color:e.danger?"#ef4444":"var(--text)"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[(0,n.jsx)("span",{children:e.label}),e.shortcut&&(0,n.jsx)("span",{style:{marginLeft:24,fontSize:10,color:"var(--text-dim)"},children:e.shortcut})]})]},t))})}var tI=r(28999);async function tM(e){let t=(0,tI.HG)(e),r=await fetch(`/api/files/${t}?type=list`);return r.ok?(await r.json()).entries??[]:[]}function tR(e,t,r,n){let o=(0,tI.e_)(t,e.name);return{id:o,name:e.name,path:o,relativePath:(0,tI.qP)(o,r),type:e.isDir?"folder":"file",extension:e.isDir?"":e.name.includes(".")?e.name.split(".").pop()?.toLowerCase()??"":"",size:e.size,modified:e.modified,depth:n,children:e.isDir?[]:void 0,childrenLoaded:!e.isDir}}function tL(e,t){return e===t?".":(0,tI.qP)(e,t)}function tW(e){return!!Array.from(e.types).includes("Files")||Array.from(e.items).some(e=>"file"===e.kind)}function tE(e){return Array.from(e.files).filter(e=>!!e.name)}function tP({cwd:e,onOpenFile:t,onExploreFile:r,refreshKey:i,onAtMention:l,searchQuery:s="",watchEnabled:a=!0}){let d,c,u,p,h=function(){let e=(0,o.useRef)(e0("")),[t,r]=(0,o.useState)(0),[n,i]=(0,o.useState)(""),[l,s]=(0,o.useState)(!1),[a,d]=(0,o.useState)(!1),[c,u]=(0,o.useState)(new Set),[p,h]=(0,o.useState)(new Set),[x,g]=(0,o.useState)(new Set),[f,v]=(0,o.useState)(null),[m,b]=(0,o.useState)([]),y=(0,o.useCallback)(()=>{let t=e.current;b(function e(t,r,n,o){let i=[];for(let l of t){let t="folder"===l.type&&r.has(l.path);if(i.push({node:l,depth:n,isExpanded:t}),t){let t=o.get(l.path)??[];i.push(...e(t,r,n+1,o))}}return i}(t.dirCache.get(t.workspaceRoot)??[],p,0,t.dirCache))},[p]);(0,o.useEffect)(()=>{y()},[t,p,y]);let j=(0,o.useCallback)(async t=>{s(!1),d(!1);let n=e0(t);e.current=n;try{let e=(await tM(t)).map(e=>tR(e,t,t,0));e.sort(e3),e5(n,t,e),i(t),s(!0),r(e=>e+1)}catch{d(!0),s(!0)}},[]),k=(0,o.useCallback)(async t=>{let n=e.current;if(!n.loadedDirs.has(t)){u(e=>new Set(e).add(t));try{let e=(await tM(t)).map(e=>tR(e,t,n.workspaceRoot,0));e.sort(e3),n.loadedDirs.has(t)||(e5(n,t,e),r(e=>e+1))}catch{}finally{u(e=>{let r=new Set(e);return r.delete(t),r})}}},[]),w=(0,o.useCallback)(t=>{h(e=>{let r=new Set(e);return r.has(t)?r.delete(t):r.add(t),r}),e.current.loadedDirs.has(t)||k(t)},[k]),S=(0,o.useCallback)((e,t)=>{g(r=>{if(t){let t=new Set(r);return t.has(e)?t.delete(e):t.add(e),t}return new Set([e])})},[]),C=(0,o.useCallback)(()=>{g(new Set)},[]),T=(0,o.useCallback)(e=>{v(e)},[]),z=(0,o.useCallback)(()=>{v(null)},[]),I=(0,o.useCallback)(async t=>{var r;(r=e.current).dirCache.clear(),r.pathIndex.clear(),r.loadedDirs.clear(),h(new Set),await j(t)},[j]),M=(0,o.useCallback)(t=>e.current.pathIndex.get(t),[]),R=(0,o.useCallback)(t=>e.current.dirCache.get(t),[]),L=(0,o.useCallback)((t,n)=>{e4(e.current,t,n),r(e=>e+1)},[]),W=(0,o.useCallback)((t,n,o)=>{let i=e.current,l=i.pathIndex.get(t);if(!l)return;let s=i.workspaceRoot===t?i.workspaceRoot:t.substring(0,Math.max(t.lastIndexOf("/"),t.lastIndexOf("\\")));e8(i,s,t);let a={...l,id:n,name:o,path:n,relativePath:(0,tI.qP)(n,i.workspaceRoot),extension:"file"===l.type&&o.includes(".")?o.split(".").pop()?.toLowerCase()??"":""};e4(i,s,a),r(e=>e+1)},[]),E=(0,o.useCallback)(t=>{let n=e.current,o=n.workspaceRoot===t?n.workspaceRoot:t.substring(0,Math.max(t.lastIndexOf("/"),t.lastIndexOf("\\")));e8(n,o,t),r(e=>e+1)},[]);return{revision:t,workspaceRoot:n,hasLoaded:l,loadFailed:a,loadingPaths:c,expandedPaths:p,selectedPaths:x,renamingPath:f,flatNodes:m,loadRoot:j,loadChildren:k,toggleExpand:w,select:S,deselectAll:C,startRename:T,stopRename:z,refresh:I,getNode:M,getChildren:R,onFileCreated:L,onFileRenamed:W,onFileDeleted:E,invalidateDir:(0,o.useCallback)(t=>{let r=e.current;r.loadedDirs.delete(t),r.dirCache.delete(t)},[]),applyWatcherEvent:(0,o.useCallback)(t=>{(function(e,t){let r=!1;for(let{dirPath:n,children:o}of t){if(!e.loadedDirs.has(n))continue;let t=o.map(t=>{let r=n===e.workspaceRoot?`${e.workspaceRoot}/${t.name}`:`${n}/${t.name}`;return{id:r,name:t.name,path:r,relativePath:r.startsWith(e.workspaceRoot+"/")?r.slice(e.workspaceRoot.length+1):t.name,type:t.isDir?"folder":"file",extension:t.isDir?"":t.name.includes(".")?t.name.split(".").pop()?.toLowerCase()??"":"",size:t.size,modified:t.modified,depth:0,children:t.isDir?[]:void 0,childrenLoaded:!t.isDir}});t.sort(e3);let i=e2(t,e.dirCache.get(n),e.pathIndex);e.dirCache.set(n,i),r=!0}return r})(e.current,t)&&r(e=>e+1)},[])}}(),x=(d=(0,o.useCallback)(async(t,r)=>{try{let n=t===e?`${e}/${r}`:`${t}/${r}`,o=await fetch("/api/file-tree/write",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:n,content:""})});if(!o.ok){let e=await o.json().catch(()=>({}));return{success:!1,error:e.error??`HTTP ${o.status}`}}return{success:!0,resolvedPath:n}}catch(e){return{success:!1,error:String(e)}}},[e]),c=(0,o.useCallback)(async(t,r)=>{try{let n=t===e?`${e}/${r}`:`${t}/${r}`,o=await fetch("/api/file-tree/mkdir",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:n})});if(!o.ok){let e=await o.json().catch(()=>({}));return{success:!1,error:e.error??`HTTP ${o.status}`}}return{success:!0,resolvedPath:n}}catch(e){return{success:!1,error:String(e)}}},[e]),u=(0,o.useCallback)(async(t,r)=>{try{let n=Math.max(t.lastIndexOf("/"),t.lastIndexOf("\\")),o=n>0?t.slice(0,n):e,i=`${o}/${r}`,l=await fetch("/api/file-tree/rename",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldPath:t,newPath:i})});if(!l.ok){let e=await l.json().catch(()=>({}));return{success:!1,error:e.error??`HTTP ${l.status}`}}return{success:!0,resolvedPath:i}}catch(e){return{success:!1,error:String(e)}}},[e]),p=(0,o.useCallback)(async e=>{try{let t=await fetch("/api/file-tree/delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})});if(!t.ok){let e=await t.json().catch(()=>({}));return{success:!1,error:e.error??`HTTP ${t.status}`}}return{success:!0,resolvedPath:e}}catch(e){return{success:!1,error:String(e)}}},[]),{createFile:d,createFolder:c,renameFile:u,deleteFile:p,moveFile:(0,o.useCallback)(async(e,t)=>{try{let r=e.slice(Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\"))+1),n=`${t}/${r}`,o=await fetch("/api/file-tree/rename",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldPath:e,newPath:n})});if(!o.ok){let e=await o.json().catch(()=>({}));return{success:!1,error:e.error??`HTTP ${o.status}`}}return{success:!0,resolvedPath:n}}catch(e){return{success:!1,error:String(e)}}},[]),revealInFinder:(0,o.useCallback)(async e=>{try{await fetch("/api/file-tree/reveal",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})})}catch{}},[])}),g=(0,o.useRef)(null),f=(0,o.useRef)(null),v=(0,o.useRef)(null),m=(0,o.useRef)(0),[b,y]=(0,o.useState)(!1),[j,k]=(0,o.useState)(null),[w,S]=(0,o.useState)(null),[C,T]=(0,o.useState)(null),[z,I]=(0,o.useState)(-1),[M,R]=(0,o.useState)(null),[L,W]=(0,o.useState)(!1),E=s.trim().length>0;(0,o.useEffect)(()=>{let e=()=>W("hidden"!==document.visibilityState);return e(),document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)},[]),(0,o.useEffect)(()=>{let t=f.current!==e;f.current=e,t&&h.loadRoot(e)},[e,h.loadRoot]),(0,o.useEffect)(()=>{void 0!==i&&h.refresh(e)},[i]),(0,o.useEffect)(()=>()=>{v.current&&clearTimeout(v.current)},[]),(0,o.useEffect)(()=>{if(!e||!a||!L)return;let t=new EventSource(`/api/file-watch?cwd=${encodeURIComponent(e)}`);return t.onmessage=e=>{try{let t=JSON.parse(e.data);t.updatedDirs?.length>0&&h.applyWatcherEvent(t.updatedDirs)}catch{}},t.onerror=()=>{},()=>{t.close()}},[e,L,h,a]),(0,o.useEffect)(()=>{if(M){let e=setTimeout(()=>R(null),3e3);return()=>clearTimeout(e)}},[M]);let P=(()=>{if(E){let e=h.getChildren(h.workspaceRoot);return e?function e(t,r,n){let o=r.trim().toLowerCase(),i=[];for(let l of t){let t=l.name.toLowerCase().includes(o),s=(l.children??[]).some(e=>(function e(t,r){let n=r.trim().toLowerCase();return!!(!n||t.name.toLowerCase().includes(n))||(t.children??[]).some(t=>e(t,n))})(e,o));(t||s)&&(i.push({node:l,depth:n,isExpanded:!0}),l.children&&s&&i.push(...e(l.children,r,n+1)))}return i}(e,s,0):[]}return h.flatNodes})(),[$,D]=(0,o.useState)(0),[N,A]=(0,o.useState)(0);(0,o.useEffect)(()=>{let e=g.current;if(!e)return;let t=new ResizeObserver(e=>{for(let t of e)A(t.contentRect.height)});return t.observe(e),()=>t.disconnect()},[]);let O=(0,o.useCallback)(e=>{D(e.currentTarget.scrollTop)},[]),B=(0,o.useMemo)(()=>{let e=26*P.length,t=Math.max(0,Math.floor($/26)-10),r=Math.min(P.length,Math.ceil(($+N)/26)+10),n=[];for(let e=t;e<r;e++)n.push({index:e,top:26*e});return{items:n,totalHeight:e,startIndex:t}},[P,$,N]),H=(0,o.useCallback)((e,r)=>{if(r)h.toggleExpand(e);else{let r=h.getNode(e);r&&t(e,r.name)}h.select(e),I(P.findIndex(t=>t.node.path===e))},[h,t,P]),F=(0,o.useCallback)(e=>{let r=h.getNode(e);r&&"file"===r.type&&t(e,r.name)},[h,t]),U=(0,o.useCallback)((e,t)=>{e.preventDefault(),T({x:e.clientX,y:e.clientY,targetPath:t}),h.select(t),I(P.findIndex(e=>e.node.path===t))},[h,P]),q=(0,o.useMemo)(()=>{if(!C)return[];let t=h.getNode(C.targetPath);if(!t)return[];let n=[{label:"folder"===t.type?"Expand / Collapse":"Open",shortcut:"folder"===t.type?"→":"Enter",onClick:()=>H(t.path,"folder"===t.type)}];return r&&"file"===t.type&&t.name.toLowerCase().endsWith(".h5ad")&&n.push({label:"Explore H5AD",shortcut:"@explore",onClick:()=>r(t.path,t.name)}),l&&n.push({label:"Mention in Chat",shortcut:"@",onClick:()=>l((0,tI.qP)(t.path,e))}),n.push({label:"",onClick:()=>{},separator:!0}),n.push({label:"Rename",shortcut:"F2",onClick:()=>h.startRename(t.path)}),n.push({label:"Delete",shortcut:"Del",onClick:async()=>{if(!window.confirm(`Are you sure you want to delete "${t.name}"?`))return;let e=await x.deleteFile(t.path);e.success?(h.onFileDeleted(t.path),R(`Deleted "${t.name}"`)):e.error&&R(e.error)},danger:!0}),n.push({label:"",onClick:()=>{},separator:!0}),n.push({label:"Copy Path",onClick:()=>{navigator.clipboard.writeText(t.path).catch(()=>{}),R("Copied path")}}),n.push({label:"Copy Relative Path",onClick:()=>{let r=(0,tI.qP)(t.path,e);navigator.clipboard.writeText(r).catch(()=>{}),R("Copied relative path")}}),n.push({label:"Reveal in Finder",onClick:()=>x.revealInFinder(t.path)}),n},[C,h,x,H,l,r,e]),_=(0,o.useCallback)(async(e,t)=>{h.stopRename();let r=h.getNode(e);if(!r||t===r.name)return;let n=await x.renameFile(e,t);n.success&&n.resolvedPath?(h.onFileRenamed(e,n.resolvedPath,t),R(`Renamed to "${t}"`)):n.error&&R(n.error)},[h,x]),J=(0,o.useCallback)(async()=>{let t=[...h.selectedPaths].map(e=>h.getNode(e)).filter(Boolean),r=t.find(e=>"folder"===e.type)?.path??e,n="untitled.txt",o=await x.createFile(r,n);if(o.success&&o.resolvedPath){let t={id:o.resolvedPath,name:n,path:o.resolvedPath,relativePath:(0,tI.qP)(o.resolvedPath,e),type:"file",extension:"txt",depth:0,childrenLoaded:!0,isOptimistic:!0};h.onFileCreated(r,t),h.expandedPaths.has(r)||h.toggleExpand(r),setTimeout(()=>h.startRename(o.resolvedPath),50)}else o.error&&R(o.error)},[h,x,e]),K=(0,o.useCallback)(async()=>{let t=[...h.selectedPaths].map(e=>h.getNode(e)).filter(Boolean),r=t.find(e=>"folder"===e.type)?.path??e,n="new-folder",o=await x.createFolder(r,n);if(o.success&&o.resolvedPath){let t={id:o.resolvedPath,name:n,path:o.resolvedPath,relativePath:(0,tI.qP)(o.resolvedPath,e),type:"folder",extension:"",depth:0,children:[],childrenLoaded:!0,isOptimistic:!0};h.onFileCreated(r,t),h.expandedPaths.has(r)||h.toggleExpand(r),setTimeout(()=>h.startRename(o.resolvedPath),50)}else o.error&&R(o.error)},[h,x,e]),V=(0,o.useCallback)(e=>{let t=e.target;if("INPUT"!==t.tagName&&"TEXTAREA"!==t.tagName){if("ArrowDown"===e.key)e.preventDefault(),I(e=>Math.min(e+1,P.length-1));else if("ArrowUp"===e.key)e.preventDefault(),I(e=>Math.max(e-1,0));else if("ArrowRight"===e.key){e.preventDefault();let t=P[z]?.node;t?.type!=="folder"||h.expandedPaths.has(t.path)||(h.toggleExpand(t.path),h.select(t.path))}else if("ArrowLeft"===e.key){e.preventDefault();let t=P[z]?.node;t?.type==="folder"&&h.expandedPaths.has(t.path)&&h.toggleExpand(t.path)}else if("Enter"===e.key){e.preventDefault();let t=P[z]?.node;t&&H(t.path,"folder"===t.type)}else if("F2"===e.key){e.preventDefault();let t=P[z]?.node;t&&(h.select(t.path),h.startRename(t.path))}else if("Delete"===e.key||"Backspace"===e.key){e.preventDefault();let t=P[z]?.node;t&&window.confirm(`Delete "${t.name}"?`)&&x.deleteFile(t.path).then(e=>{e.success&&(h.onFileDeleted(t.path),R(`Deleted "${t.name}"`))})}}},[P,z,h,H,x]);(0,o.useEffect)(()=>{if(z>=0&&g.current){let e=26*z,{scrollTop:t,clientHeight:r}=g.current;(e<t||e>t+r-26)&&(g.current.scrollTop=Math.max(0,e-Math.floor(r/2)))}},[z]);let Y=(0,o.useCallback)(()=>{v.current&&clearTimeout(v.current),v.current=setTimeout(()=>S(null),5e3)},[]),G=(0,o.useCallback)((t,r)=>{if(0===t.length)return;m.current=0,y(!1),v.current&&clearTimeout(v.current);let n=t.reduce((e,t)=>e+t.size,0),o=tL(r,e);k(r),S({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,tI.HG)(r);l.open("POST",`/api/files/${s}?type=upload`),l.upload.onprogress=e=>{e.lengthComputable&&S(t=>t?{...t,loaded:e.loaded,total:e.total}:t)},l.onload=()=>{k(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}`)];S({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}),h.invalidateDir(r),h.expandedPaths.has(r)&&h.loadChildren(r),Y()}else{let o=e.error??`Upload failed (HTTP ${l.status})`;S({phase:"error",targetPath:r,fileCount:t.length,loaded:0,total:n,message:o}),Y()}},l.onerror=()=>{k(null),S({phase:"error",targetPath:r,fileCount:t.length,loaded:0,total:n,message:"Upload failed due to a network error"}),Y()},l.onabort=()=>{k(null),S({phase:"error",targetPath:r,fileCount:t.length,loaded:0,total:n,message:"Upload canceled"}),Y()},l.send(i)},[e,h,Y]),X=(0,o.useCallback)(e=>{tW(e.dataTransfer)&&(e.preventDefault(),m.current+=1,y(!0))},[]),Z=(0,o.useCallback)(e=>{tW(e.dataTransfer)&&(e.preventDefault(),e.dataTransfer.dropEffect="copy")},[]),Q=(0,o.useCallback)(()=>{m.current-=1,m.current<=0&&(m.current=0,y(!1))},[]),ee=(0,o.useCallback)(t=>{if(!tW(t.dataTransfer))return;t.preventDefault(),m.current=0,y(!1);let r=tE(t.dataTransfer);r.length>0&&G(r,e)},[e,G]),et=(0,o.useCallback)(e=>t=>{if(!tW(t.dataTransfer))return;t.preventDefault(),t.stopPropagation();let r=tE(t.dataTransfer);r.length>0&&(G(r,e),h.expandedPaths.has(e)||h.toggleExpand(e))},[G,h]),er=w&&w.total>0?Math.max(0,Math.min(100,Math.round(w.loaded/w.total*100))):w?.phase==="uploading"?8:100,en=w?.phase==="success"?"#22c55e":w?.phase==="warning"?"#f59e0b":w?.phase==="error"?"#ef4444":"var(--accent)";return h.loadFailed?(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:"Could not load files"}):(0,n.jsxs)("div",{onDragEnter:X,onDragOver:Z,onDragLeave:Q,onDrop:ee,onKeyDown:V,tabIndex:0,style:{position:"relative",display:"flex",flexDirection:"column",height:"100%",outline:b?"1px solid rgba(37,99,235,0.45)":"none",outlineOffset:-1,background:b?"rgba(37,99,235,0.04)":void 0,transition:"background 0.12s, outline-color 0.12s"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:2,padding:"4px 6px",borderBottom:"1px solid var(--border)",flexShrink:0,minHeight:30},children:[(0,n.jsx)("button",{onClick:J,title:"New File",style:t$,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)("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:"12",y1:"18",x2:"12",y2:"12"}),(0,n.jsx)("line",{x1:"9",y1:"15",x2:"15",y2:"15"})]})}),(0,n.jsx)("button",{onClick:K,title:"New Folder",style:t$,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)("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"}),(0,n.jsx)("line",{x1:"12",y1:"11",x2:"12",y2:"17"}),(0,n.jsx)("line",{x1:"9",y1:"14",x2:"15",y2:"14"})]})}),(0,n.jsx)("button",{onClick:()=>h.refresh(e),title:"Refresh",style:t$,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)("polyline",{points:"23 4 23 10 17 10"}),(0,n.jsx)("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})}),(0,n.jsx)("button",{onClick:()=>{h.deselectAll()},title:"Collapse All",style:t$,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)("polyline",{points:"4 14 10 14 10 20"}),(0,n.jsx)("polyline",{points:"20 10 14 10 14 4"}),(0,n.jsx)("line",{x1:"14",y1:"10",x2:"21",y2:"3"}),(0,n.jsx)("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]})}),(0,n.jsx)("div",{style:{flex:1}}),(0,n.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",paddingRight:4},children:[P.length," items"]})]}),M&&(0,n.jsx)("div",{style:{padding:"4px 10px",fontSize:11,color:"var(--text)",background:"var(--bg-selected)",borderBottom:"1px solid var(--border)"},children:M}),(0,n.jsxs)("div",{ref:g,onScroll:O,style:{flex:1,overflow:"auto",position:"relative"},children:[h.hasLoaded?0===P.length?(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:E?"No matching files":"No files found"}):(0,n.jsx)("div",{style:{height:B.totalHeight,position:"relative"},children:B.items.map(e=>{let{index:t,top:r}=e,{node:o,depth:i,isExpanded:l}=P[t],s=t===z;return(0,n.jsx)("div",{style:{position:"absolute",top:r,left:0,right:0,height:26,outline:s?"1px solid var(--accent)":"none",outlineOffset:-1,borderRadius:4},children:(0,n.jsx)(tT,{node:o,depth:i,isExpanded:l,isLoading:h.loadingPaths.has(o.path),isSelected:h.selectedPaths.has(o.path),isRenaming:h.renamingPath===o.path,isUploadTarget:j===o.path,onClick:H,onDoubleClick:F,onContextMenu:U,onRenameSubmit:_,onRenameCancel:()=>h.stopRename(),onDrop:"folder"===o.type?et(o.path):void 0})},o.id)})}):(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:"Loading files..."}),b&&(0,n.jsx)("div",{style:{pointerEvents:"none",position:"absolute",inset:6,top:0,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",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 ",tL(e,e)]})})]}),w&&(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)",flexShrink:0},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:en,flexShrink:0}}),(0,n.jsx)("span",{title:w.message,style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text)",fontSize:11,fontWeight:600},children:w.message}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,flexShrink:0},children:"uploading"===w.phase?`${er}%`: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]}`}(w.total)})]}),(0,n.jsx)("div",{style:{marginTop:6,height:3,borderRadius:999,background:"var(--bg)",overflow:"hidden"},children:(0,n.jsx)("div",{style:{width:`${er}%`,height:"100%",borderRadius:999,background:en,transition:"width 0.15s ease"}})}),w.details&&w.details.length>0&&(0,n.jsx)("div",{style:{marginTop:5,display:"grid",gap:2},children:w.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))})]}),C&&(0,n.jsx)(tz,{x:C.x,y:C.y,actions:q,onClose:()=>T(null)})]})}let t$={display:"flex",alignItems:"center",justifyContent:"center",width:26,height:26,border:"none",borderRadius:4,background:"transparent",color:"var(--text-dim)",cursor:"pointer",flexShrink:0,transition:"background 0.08s, color 0.08s"};function tD({cwd:e,refreshKey:t=0,onOpenFile:r,onExploreFile:i,onAtMention:l,watchEnabled:s=!0}){let[a,d]=(0,o.useState)("");return(0,n.jsxs)("div",{style:{height:"100%",display:"flex",flexDirection:"column",background:"var(--bg)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:"7px 10px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",flexShrink:0},children:[(0,n.jsx)("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:1,fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)"},children:e??"No project selected"})]})}),(0,n.jsxs)("div",{style:{position:"relative",marginTop:7},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:a,onChange:e=>d(e.target.value),placeholder:"Filter files...",disabled:!e,style:{width:"100%",height:28,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}}),a&&(0,n.jsx)("button",{type:"button",onClick:()=>d(""),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)(tP,{cwd:e,onOpenFile:r,onExploreFile:i,refreshKey:t,onAtMention:l,searchQuery:a,watchEnabled:s}):(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 tN=r(27568),tA=r(96793);let tO={__soul__:{apiPath:"/api/soul",title:"SOUL.md"},__harness__:{apiPath:"/api/harness",title:"HARNESS.md"}};function tB({filePath:e}){let t=tO[e],{isDark:r}=(0,tA.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)(tN.g,{initialContent:i,language:"markdown",isDark:r,onChange:l,onSave:g})})]}):null}function tH(){document.body.style.cursor="",document.body.style.userSelect=""}function tF({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),tH(),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,tH(),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 tU(e){return"running"===e?"#22c55e":"starting"===e?"rgba(234,179,8,0.95)":"error"===e?"#ef4444":"var(--text-dim)"}function tq(e){return"h5adexp"===e?"H5AD Exp":"stexp"}function t_(e,t,r){return Math.min(Math.max(e,t),r)}function tJ(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 tK({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),[b,y]=(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,tI.WP)(t):u?(0,tI.WP)(u.filePath):"",W=t&&r?(0,tI.qP)(t,r):u?.filePath&&u.cwd?(0,tI.qP)(u.filePath,u.cwd):t??u?.filePath??"",E=u?.status??"idle",P=(0,o.useMemo)(()=>u?.logs?.join("\n")??"",[u?.logs]),$=u?.appType==="h5adexp"?u.url:u?.directUrl??u?.url??"",D=(0,o.useCallback)(e=>{p(e),a?.(e)},[a]),N=(0,o.useCallback)(async e=>{let t=await fetch(`/api/apps?appId=${encodeURIComponent(e)}`),r=await t.json(),n=tJ(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]),A=(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=tJ(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),y(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 N(l).then(()=>y(e=>e+1)).catch(e=>x(e instanceof Error?e.message:String(e)));p(null),A()}},[R,l,t]),(0,o.useEffect)(()=>{if(!u?.id||"stopped"===u.status||"error"===u.status)return;let e=window.setInterval(()=>{N(u.id).catch(()=>{})},2500);return()=>window.clearInterval(e)},[u?.id,u?.status,N]),(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:t_(e.left,8,Math.max(8,window.innerWidth-n-8)),top:t_(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=tJ(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,D,g]),B=(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:t_(r,8,Math.max(8,window.innerWidth-120)),top:t_(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]),q=(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:t_(r,420,Math.max(420,window.innerWidth-e.left-8)),height:t_(n,340,Math.max(340,window.innerHeight-e.top-8))}))},[]),_=(0,o.useCallback)(e=>{let t=M.current;t?.pointerId===e.pointerId&&(e.currentTarget.releasePointerCapture(e.pointerId),M.current=null,T(!1))},[]),J=(0,o.useCallback)(()=>{d?.(),s()},[s,d]),K=(0,o.useCallback)(()=>{k(e=>({...e,maximized:!e.maximized}))},[]);if(!R)return null;let V=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??tq(e)} window`,tabIndex:-1,onKeyDown:e=>{"Escape"===e.key&&J()},style:{...V,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:B,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??tq(e)}),(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:tU(E),flexShrink:0}}),(0,n.jsx)("span",{style:{fontSize:11,color:tU(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:()=>y(e=>e+1),disabled:!$||u?.status==="stopped",style:tV,title:"Reload",children:"Reload"}),(0,n.jsx)("button",{type:"button",onPointerDown:e=>e.stopPropagation(),onClick:()=>m(e=>!e),style:{...tV,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:J,style:tV,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:{...tV,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:J,"aria-label":"Minimize",title:"Minimize",style:tY,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:tY,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:tY,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 ",tq(e),"..."]}):$&&u?.status!=="stopped"?(0,n.jsx)("iframe",{src:$,title:`${u?.title??tq(e)} - ${L}`,style:{width:"100%",height:"100%",border:"none",display:"block",background:"#fff"}},`${$}:${b}`):(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:[tq(e)," is stopped."]}),t&&r&&(0,n.jsx)("button",{type:"button",onClick:()=>void A(),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:P||"No logs yet."})]})]}),!j.maximized&&(0,n.jsx)("div",{role:"separator","aria-orientation":"horizontal","aria-label":"Resize explore window",title:"Resize",onPointerDown:U,onPointerMove:q,onPointerUp:_,onPointerCancel:_,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 tV={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},tY={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 tG(e){return"running"===e?"#22c55e":"starting"===e?"rgba(234,179,8,0.95)":"error"===e?"#ef4444":"var(--text-dim)"}function tX(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 tZ(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 tQ(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 t0({refreshKey:e=0,visibleAppId:t,cwd:r,onOpenApp:i,onAppChanged:l,onAppsChanged:s,agentRuntimeExtra:a}){let[d,c]=(0,o.useState)([]),[u,p]=(0,o.useState)(null),[h,x]=(0,o.useState)(null),[g,f]=(0,o.useState)(null),[v,m]=(0,o.useState)(null),[b,y]=(0,o.useState)(null),[j,k]=(0,o.useState)(null),[w,S]=(0,o.useState)(null),[C,T]=(0,o.useState)(null),[z,I]=(0,o.useState)(null),M=(0,o.useMemo)(()=>[...d].sort((e,t)=>{let r=+!!e.running,n=+!!t.running;return r!==n?n-r:Date.parse(t.lastActivity)-Date.parse(e.lastActivity)}),[d]),R=(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}`);c(t.apps),s?.(t.apps),f(null)}catch(e){f(e instanceof Error?e.message:String(e))}},[s]),L=(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}`);p(n),x(n.memory??null),m(null)}catch(e){m(e instanceof Error?e.message:String(e))}},[r]);(0,o.useEffect)(()=>{R(),L()},[R,L,e]),(0,o.useEffect)(()=>{let e=window.setInterval(()=>{R(),L()},3e3);return()=>window.clearInterval(e)},[R,L]);let W=(0,o.useCallback)(async e=>{S(e.id),f(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}`);c(e=>e.map(e=>e.id===r.app.id?r.app:e)),l?.(r.app),await R()}catch(e){f(e instanceof Error?e.message:String(e))}finally{S(null)}},[R,l]),E=(0,o.useCallback)(async e=>{T(e.sessionId),m(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 L()}catch(e){m(e instanceof Error?e.message:String(e))}finally{T(null)}},[L]),P=(0,o.useCallback)(async(e,t)=>{if(r){k(`${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 L()}catch(e){y(e instanceof Error?e.message:String(e))}finally{k(null)}}},[r,L]),$=(0,o.useCallback)(async e=>{if(r){k(`dismiss:${e}`),y(null);try{let t=await fetch("/api/memory/dismiss",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:r,memoryId:e})}),n=await t.json().catch(()=>({}));if(!t.ok)throw Error(n.error??`HTTP ${t.status}`);await L()}catch(e){y(e instanceof Error?e.message:String(e))}finally{k(null)}}},[r,L]),D=d.filter(e=>e.running).length,N=d.reduce((e,t)=>e+(t.running?t.rssBytes??0:0),0),A=u?.sessions??[],O=A.filter(e=>e.busy),B=O.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:[O.length," agent running \xb7 ",D," explore \xb7 ",tZ(N)]})]}),(0,n.jsx)("button",{type:"button",onClick:()=>{R(),L()},style:t8,title:"Refresh status",children:"Refresh"})]}),g&&(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:g}),v&&(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:v}),b&&(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:b})]}),(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)(t1,{title:"Agent Runtime",subtitle:B.length>0?`${B.length} waiting for model first token`:`${O.length} active chat${1===O.length?"":"s"}`}),a,0===A.length?(0,n.jsx)(t2,{label:"No agent runtime is active."}):(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:A.map(e=>{var t;let r=e.model?`${e.model.provider}/${e.model.id}`:"-",o=e.cwd?(0,tI.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:tX(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:tX(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)(t5,{label:"uptime",value:tQ(e.uptimeMs)}),(0,n.jsx)(t5,{label:"wait",value:tQ(e.waitingForModelMs),color:"waiting_model"===e.phase?tX(e.phase):void 0}),(0,n.jsx)(t5,{label:"pending",value:null===e.pendingMessageCount?"-":String(e.pendingMessageCount)}),(0,n.jsx)(t5,{label:"event",value:e.lastEventType??"-"}),(0,n.jsx)(t5,{label:"tools",value:i||"-"}),(0,n.jsx)(t5,{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 E(e),disabled:!e.busy||C===e.sessionId,style:{...t8,border:"1px solid rgba(239,68,68,0.35)",color:"#ef4444",background:"rgba(239,68,68,0.08)",opacity:e.busy&&C!==e.sessionId?1:.55},children:"Abort"})})]},e.sessionId)})})]}),(0,n.jsxs)("section",{children:[(0,n.jsx)(t1,{title:"Memory",subtitle:h?`${h.count} stored \xb7 ${h.candidateCount} candidates`:r?"loading":"No project selected"}),r?h?(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)(t5,{label:"fact",value:String(h.byType.fact)}),(0,n.jsx)(t5,{label:"context",value:String(h.byType.context)}),(0,n.jsx)(t5,{label:"decision",value:String(h.byType.decision)}),(0,n.jsx)(t5,{label:"preference",value:String(h.byType.preference)}),(0,n.jsx)(t5,{label:"note",value:String(h.byType.note)}),(0,n.jsx)(t5,{label:"candidates",value:String(h.candidateCount),color:h.candidateCount>0?"var(--accent)":void 0})]}),(0,n.jsx)("div",{title:h.filePath,style:{marginTop:8,fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(0,tI.qP)(h.filePath,r)})]}),(0,n.jsx)(t4,{title:"Promotion Candidates",emptyLabel:"No promotion candidates yet.",items:h.topCandidates,onPromote:P,onDismiss:$,busyAction:j}),(0,n.jsx)(t4,{title:"Recent Memory",emptyLabel:"No memory stored for this project.",items:h.recent})]}):(0,n.jsx)(t2,{label:"Memory status unavailable."}):(0,n.jsx)(t2,{label:"Select a project to inspect memory status."})]}),(0,n.jsxs)("section",{children:[(0,n.jsx)(t1,{title:"Explore Tools",subtitle:`${D} running \xb7 ${tZ(N)}`}),0===M.length?(0,n.jsx)(t2,{label:"No explore tools are running."}):(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:M.map(e=>{let o,l=t===e.id,s=z===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:tG(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,tI.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,tI.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)(t5,{label:"status",value:e.status,color:tG(e.status)}),(0,n.jsx)(t5,{label:"pid",value:e.pid?String(e.pid):"-"}),(0,n.jsx)(t5,{label:"memory",value:tZ(e.rssBytes)}),(0,n.jsx)(t5,{label:"uptime",value:tQ(e.uptimeMs)}),(0,n.jsx)(t5,{label:"port",value:String(e.port)}),(0,n.jsx)(t5,{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:t8,children:"Open"}),(0,n.jsx)("button",{type:"button",onClick:()=>I(t=>t===e.id?null:e.id),style:{...t8,background:s?"var(--bg-selected)":"var(--bg)"},children:"Logs"}),(0,n.jsx)("button",{type:"button",onClick:()=>void W(e),disabled:!e.running||w===e.id,style:{...t8,border:"1px solid rgba(239,68,68,0.35)",color:"#ef4444",background:"rgba(239,68,68,0.08)",opacity:e.running&&w!==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 t1({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 t2({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 t5({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 t4({title:e,emptyLabel:t,items:r,onPromote:o,onDismiss:i,busyAction:l}){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||i)&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:[o&&(0,n.jsx)("button",{type:"button",disabled:e.promotedTo.includes("memory")||l===`${e.id}:memory`,onClick:()=>void o(e.id,"memory"),style:{...t8,height:24,padding:"0 8px",opacity:e.promotedTo.includes("memory")||l===`${e.id}:memory`?.55:1},children:e.promotedTo.includes("memory")?"In MEMORY.md":l===`${e.id}:memory`?"Saving...":"To MEMORY.md"}),i&&(0,n.jsx)("button",{type:"button",disabled:l===`dismiss:${e.id}`||l===`${e.id}:memory`,onClick:()=>void i(e.id),style:{...t8,height:24,padding:"0 8px",opacity:l===`dismiss:${e.id}`||l===`${e.id}:memory`?.55:1,borderColor:"var(--text-dim)",color:"var(--text-dim)"},children:l===`dismiss:${e.id}`?"Dismissing…":"Ignore"})]})]},e.id))})]})}let t8={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 t3({tabs:e,activeTabId:t,onSelectTab:r,onCloseTab:i,onAskAI:l}){let[s,a]=(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,d=!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"})}):tC(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}),d&&(0,n.jsxs)(n.Fragment,{children:[o&&l&&e.filePath&&!e.icon&&(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),l(e.filePath)},title:`Ask AI about ${e.label}`,style:{display:"flex",alignItems:"center",justifyContent:"center",width:16,height:16,background:"transparent",border:"none",borderRadius:3,color:"var(--accent)",cursor:"pointer",padding:0,flexShrink:0,transition:"background 0.1s"},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:"M15 18H3"}),(0,n.jsx)("path",{d:"M17 6H3"}),(0,n.jsx)("path",{d:"M21 12H3"})]})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),i(e.id)},onMouseEnter:()=>a(e.id),onMouseLeave:()=>a(null),style:{display:"flex",alignItems:"center",justifyContent:"center",width:16,height:16,background:s===e.id?"var(--bg-hover)":"transparent",border:"none",borderRadius:3,color:s===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 t6(e){let t=e,r=t.compressedEntryIds?.length??0;for(;1===t.children.length;)t=t.children[0],r+=1+(t.compressedEntryIds?.length??0);return{node:t,skipped:r}}function t7({node:e,activeLeafId:t,activePathIds:r,depth:o,isLast:i,parentLines:l,onSelect:s}){var a;let{node:d,skipped:c}=t6(e),u=(a=d.entry.id,null!=t&&a===t),p=r.has(e.entry.id)||r.has(d.entry.id),h=d.branchPreview,x=h&&"message"!==d.entry.type?h.text: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}(d.entry),g=h&&"message"!==d.entry.type?h.role??null:"message"===d.entry.type&&"message"in d.entry?d.entry.message.role:null;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",height:24,cursor:"pointer"},onClick:()=>s(d.entry.id),children:[l.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:i?"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:u?"var(--accent)":p?"var(--text-muted)":"var(--border)",border:u?"none":"1px solid var(--text-dim)",marginRight:6,transition:"background 0.12s"}}),g&&(0,n.jsx)("span",{style:{fontSize:9,fontFamily:"var(--font-mono)",color:"user"===g?"var(--accent)":"var(--text-dim)",background:"user"===g?"rgba(37,99,235,0.08)":"var(--bg-hover)",border:`1px solid ${"user"===g?"rgba(37,99,235,0.2)":"var(--border)"}`,borderRadius:3,padding:"0 4px",marginRight:5,flexShrink:0,lineHeight:"16px"},children:"user"===g?"U":"A"}),c>0&&(0,n.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",marginRight:5,flexShrink:0},children:["+",c]}),(0,n.jsx)("span",{style:{fontSize:11,color:u?"var(--text)":p?"var(--text-muted)":"var(--text-dim)",fontWeight:u?500:400,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,minWidth:0},children:x})]}),d.children.map((e,a)=>(0,n.jsx)(t7,{node:e,activeLeafId:t,activePathIds:r,depth:o+1,isLast:a===d.children.length-1,parentLines:[...l,!i],onSelect:s},e.entry.id))]})}function t9({tree:e,activeLeafId:t,onLeafChange:r,inline:i,containerRef:l,open:s,onToggle:a,hasSession:d,embedded:c}){let[u,p]=(0,o.useState)(!1),h=void 0!==s?s:u,x=(0,o.useRef)(null),[g,f]=(0,o.useState)(null);(0,o.useEffect)(()=>{if(!h||!i)return;let e=l?.current??x.current;if(!e)return;let t=()=>{let t=e.getBoundingClientRect();f({top:t.bottom,left:t.left,width:t.width})};t();let r=new ResizeObserver(t);return r.observe(e),()=>r.disconnect()},[h,i,l]);let v=(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||o.compressedEntryIds?.includes(t))return r;let i=e(o.children,r);if(i)return i}return null}(e,[])??[]):new Set,[e,t]),m=(0,o.useCallback)(e=>{r(e)},[r]),b=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?t6(e[0]):null,j=y?.node??null,k=!b&&j&&j.children.length>1,w=(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:k?"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"})]}),S=(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:h?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})});return c?(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"8px 10px",borderBottom:k?"1px solid var(--border)":"none"},children:[w,(0,n.jsx)("span",{style:{fontSize:12,fontWeight:700,color:"var(--text)"},children:"Branches"})]}),k&&j?(0,n.jsx)("div",{style:{padding:"4px 10px 8px",maxHeight:260,overflowY:"auto"},children:j.children.map((e,r)=>(0,n.jsx)(t7,{node:e,activeLeafId:t,activePathIds:v,depth:0,isLast:r===j.children.length-1,parentLines:[],onSelect:m},e.entry.id))}):(0,n.jsx)("div",{style:{padding:"0 10px 10px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:b??"This session has no branches"})]}):i?(0,n.jsxs)("div",{style:{height:"100%",display:"flex",alignItems:"stretch"},children:[(0,n.jsxs)("button",{ref:x,className:"topbar-branches-button",onClick:()=>a?a():p(e=>!e),title:"Branches","aria-label":"Branches",style:{display:"flex",alignItems:"center",gap:6,height:28,padding:"0 9px",background:h?"var(--bg-selected)":"var(--bg-panel)",border:`1px solid ${h?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,cursor:"pointer",color:h?"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=h?"var(--text)":"var(--text-muted)",e.currentTarget.style.background=h?"var(--bg-selected)":"var(--bg-panel)"},children:[(0,n.jsx)("span",{className:"topbar-branches-icon",children:w}),(0,n.jsx)("span",{className:"topbar-branches-label",children:"Branches"})]}),h&&g&&(0,n.jsx)("div",{style:{position:"fixed",top:g.top,left:g.left,width:g.width,background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",zIndex:500},children:k&&j?(0,n.jsx)("div",{style:{padding:"4px 12px 8px 12px",maxHeight:260,overflowY:"auto"},children:j.children.map((e,r)=>(0,n.jsx)(t7,{node:e,activeLeafId:t,activePathIds:v,depth:0,isLast:r===j.children.length-1,parentLines:[],onSelect:m},e.entry.id))}):(0,n.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:b})})]}):(0,n.jsxs)("div",{style:{borderBottom:"1px solid var(--border)",background:"var(--bg)",flexShrink:0,position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>p(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:[w,(0,n.jsx)("span",{style:{color:"var(--text-muted)"},children:"Branches"}),S]}),h&&(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:k&&j?(0,n.jsx)("div",{style:{padding:"4px 12px 8px 12px",maxHeight:260,overflowY:"auto"},children:j.children.map((e,r)=>(0,n.jsx)(t7,{node:e,activeLeafId:t,activePathIds:v,depth:0,isLast:r===j.children.length-1,parentLines:[],onSelect:m},e.entry.id))}):(0,n.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:b??"This session has no branches"})})]})}function re(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 rt=re((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"})),rr=re((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"})),rn=re((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"})]})),ro=re((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"})]})),ri=re((0,n.jsx)("path",{d:"M4 4h16v16H4z",fill:"#F55036"}),"0 0 24 24"),rl=re((0,n.jsx)("path",{d:"M4 4h5v5H4zm5.5 0h5v5h-5zM15 4h5v5h-5zM4 9.5h5v5H4zm5.5 5.5h5v5h-5zM15 9.5h5v5h-5z",fill:"#FA6F00"})),rs=re((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),"0 0 24 24"),ra=re((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"})]})),rd=re((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",fill:"#FF5722"}),"0 0 24 24"),rc=re((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"})),ru=re((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"})]})),rp=re((0,n.jsx)("path",{d:"M12 2l9 5v10l-9 5-9-5V7l9-5z",stroke:"currentColor",strokeWidth:"1.5",fill:"none"})),rh=re((0,n.jsx)("path",{d:"M4 4l8 8 8-8M4 20l8-8 8 8",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})),rx=re((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"})),rg=re((0,n.jsx)("path",{d:"M12 2L22 20H2L12 2z",fill:"currentColor"})),rf=re((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),"0 0 24 24"),rv=re((0,n.jsx)("path",{d:"M3 15h2l1-3h2l1 3h2V9H9v3L8 9H6l-1 3V9H3v6zm9 0h2v-2h2v-2h-2V9h-2v2h-2v2h2v2z",fill:"#FF9900"})),rm=re((0,n.jsx)("path",{d:"M12 2L3 18h5l4-6 4 6h5L12 2z",fill:"#0078D4"})),rb=re((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"})]})),ry=re((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"})]})),rj=re((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"})]})),rk=re((0,n.jsx)("path",{d:"M4 8h16v2H4zm0 4h12v2H4zm0 4h8v2H4z",fill:"#3059B1"})),rw=re((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"})),rS=re((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",fill:"#0F6CBD"}),"0 0 24 24"),rC=re((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),"0 0 24 24"),rT="openai-completions",rz={off:"none",xhigh:"xhigh"},rI={thinkingFormat:"deepseek",requiresReasoningContentOnAssistantMessages:!0};function rM(e){return e?.toLowerCase().replace(/\s+/g,"-")??""}function rR(e){return/(^|[^a-z0-9])gpt-5($|[.-])/.test(rM(e))}function rL(e){return/[.-](minimal|low|medium|high|xhigh)$/.test(rM(e))}function rW(e){return rR(e.id)||rR(e.name)}function rE(e,t=rT){if(!rW(e))return e;let r=e.api??("openai-responses"===t?void 0:"openai-responses");if(rW(e)&&(rL(e.id)||rL(e.name))){let t={...e};return delete t.reasoning,delete t.thinkingLevelMap,{...t,api:r}}return{...e,api:r,reasoning:e.reasoning??!0,thinkingLevelMap:e.thinkingLevelMap??rz}}let rP={anthropic:{Icon:rt,hasColor:!1},openai:{Icon:rr,hasColor:!1},"openai-codex":{Icon:rr,hasColor:!1},google:{Icon:rn,hasColor:!0},"google-vertex":{Icon:rn,hasColor:!0},deepseek:{Icon:ro,hasColor:!0},groq:{Icon:ri,hasColor:!1},mistral:{Icon:rl,hasColor:!0},moonshotai:{Icon:rs,hasColor:!1},"moonshotai-cn":{Icon:rs,hasColor:!1},moonshot:{Icon:rs,hasColor:!1},minimax:{Icon:ra,hasColor:!0},"minimax-cn":{Icon:ra,hasColor:!0},fireworks:{Icon:rd,hasColor:!0},huggingface:{Icon:rc,hasColor:!0},cerebras:{Icon:ru,hasColor:!0},openrouter:{Icon:rp,hasColor:!1},xai:{Icon:rh,hasColor:!1},"cloudflare-ai-gateway":{Icon:rx,hasColor:!0},"cloudflare-workers-ai":{Icon:rx,hasColor:!0},"vercel-ai-gateway":{Icon:rg,hasColor:!1},"github-copilot":{Icon:rf,hasColor:!1},"amazon-bedrock":{Icon:rv,hasColor:!0},"azure-openai-responses":{Icon:rm,hasColor:!0},"kimi-coding":{Icon:rb,hasColor:!0},qwen:{Icon:ry,hasColor:!0},zai:{Icon:rj,hasColor:!0},cohere:{Icon:rk,hasColor:!0},perplexity:{Icon:rw,hasColor:!0},together:{Icon:rS,hasColor:!0},grok:{Icon:rC,hasColor:!1}},r$=["openai-completions","openai-responses","anthropic-messages","google-generative-ai"];function rD({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 rN={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 rA({value:e,onChange:t,placeholder:r,mono:o}){return(0,n.jsx)("input",{value:e,onChange:e=>t(e.target.value),placeholder:r,style:{...rN,fontFamily:o?"var(--font-mono)":"inherit"}})}function rO({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:{...rN,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 rB({value:e,onChange:t,placeholder:r}){return(0,n.jsx)("input",{type:"number",value:e,onChange:e=>t(e.target.value),placeholder:r,style:rN})}function rH({value:e,onChange:t,options:r,required:o}){return(0,n.jsxs)("select",{value:e,onChange:e=>t(e.target.value),style:{...rN,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 rF({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 rU({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 rq({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",{className:"models-config-provider-detail",style:{display:"flex",flexDirection:"column",gap:16},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(rU,{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)(rD,{label:"Provider name",children:[(0,n.jsx)(rA,{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)(rD,{label:"Base URL",children:(0,n.jsx)(rA,{value:t.baseUrl??"",onChange:e=>d("baseUrl",e||void 0),placeholder:"https://api.example.com/v1",mono:!0})}),(0,n.jsxs)(rD,{label:"API Key",children:[(0,n.jsx)(rO,{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)(rD,{label:"API",children:(0,n.jsx)(rH,{value:t.api??"openai-completions",onChange:e=>d("api",e),options:r$,required:!0})})]})}let r_=["off","minimal","low","medium","high","xhigh"],rJ={off:"var(--text-dim)",minimal:"#6b7280",low:"#60a5fa",medium:"#a78bfa",high:"#f472b6",xhigh:"#fb923c"};function rK({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:r_.map(e=>{let t=r[e],i=e in r?null===t?"null":"string":"omit",l="string"==typeof t?t:"",s=rJ[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)})})}function rV({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(rE(e,t.api??rT))},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",{className:"models-config-model-detail",style:{display:"flex",flexDirection:"column",gap:16},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(rU,{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)(rD,{label:"ID *",children:(0,n.jsx)(rA,{value:r.id,onChange:e=>c({...r,id:e}),placeholder:"model-id",mono:!0})}),(0,n.jsx)(rD,{label:"Name",children:(0,n.jsx)(rA,{value:r.name??"",onChange:e=>c({...r,name:e||void 0}),placeholder:"Display name"})})]}),(0,n.jsx)(rD,{label:"API override",children:(0,n.jsx)(rH,{value:r.api??"",onChange:e=>d("api",e||void 0),options:r$})}),(0,n.jsxs)("div",{style:{display:"flex",gap:20,flexWrap:"wrap"},children:[(0,n.jsx)(rF,{label:"Reasoning / thinking",checked:r.reasoning??!1,onChange:e=>d("reasoning",e||void 0)}),(0,n.jsx)(rF,{label:"Image input",checked:r.input?.includes("image")??!1,onChange:e=>d("input",e?["text","image"]:["text"])})]}),r.reasoning&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(rF,{label:"DeepSeek thinking compat",checked:r.compat?.thinkingFormat==="deepseek",onChange:e=>i(function(e,t){if(t)return{...e,compat:{...e.compat??{},...rI}};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)(rU,{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)(rK,{value:r.thinkingLevelMap,onChange:e=>d("thinkingLevelMap",e)})]})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[(0,n.jsx)(rD,{label:"Context window (tokens)",children:(0,n.jsx)(rB,{value:void 0!==r.contextWindow?String(r.contextWindow):"",onChange:e=>d("contextWindow",e?parseInt(e):void 0),placeholder:"128000"})}),(0,n.jsx)(rD,{label:"Max output tokens",children:(0,n.jsx)(rB,{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)(rU,{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)(rD,{label:e,children:(0,n.jsx)(rB,{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 rY({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",{className:"models-config-subscription-detail",style:{display:"flex",flexDirection:"column",gap:16},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(rU,{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 rG({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",{className:"models-config-apikey-detail",style:{display:"flex",flexDirection:"column",gap:16},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(rU,{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)(rD,{label:"API Key",children:(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsx)(rO,{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 rX({id:e,size:t}){let r=rP[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 rZ({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)(rX,{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)(rX,{id:e.id,size:28})]},e.id))]})})]})})}function rQ({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)(rD,{label:"Base URL",children:(0,n.jsx)(rA,{value:i,onChange:l,placeholder:"https://api.example.com",mono:!0})}),(0,n.jsx)(rD,{label:"API Key",children:(0,n.jsx)(rO,{value:s,onChange:a,placeholder:"optional for local providers",mono:!0})}),(0,n.jsx)(rD,{label:"Provider name",children:(0,n.jsx)(rA,{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??rT,x=0;for(let e of f.piModels)u.has(e.id)&&!p.has(e.id)&&(p.set(e.id,rE(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 r0({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,b]=(0,o.useState)([]),[y,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=>b(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}}}})},[]),P=(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})},[]),$=(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]),N=Object.entries(r.providers??{}),A=m.filter(e=>e.loggedIn),O=y.filter(e=>e.configured),B=(()=>{if(!f)return null;if("oauth"===f.type){let e=m.find(e=>e.id===f.providerId);return e?(0,n.jsx)(rY,{provider:e,onRefresh:T},e.id):null}if("apikey"===f.type){let e=y.find(e=>e.id===f.providerId);return e?(0,n.jsx)(rG,{provider:e,onRefresh:z},e.id):null}if("provider"===f.type){let e=r.providers?.[f.name];return e?(0,n.jsx)(rq,{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)(rV,{providerName:f.providerName,provider:e,model:t,onChange:e=>E(f.providerName,f.index,e),onDelete:()=>P(f.providerName,f.index)},`${f.providerName}-${f.index}`):null})();return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"models-config-root",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",{className:"models-config-shell",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",{className:"models-config-body",style:{flex:1,display:"flex",overflow:"hidden"},children:[(0,n.jsxs)("div",{className:"models-config-tree",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:[A.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)(rX,{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)(rX,{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)}),(A.length>0||O.length>0)&&N.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…"}):N.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",{className:"models-config-detail",style:{flex:1,overflowY:"auto",padding:20},children:l?null:B??(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",{className:"models-config-footer",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)(rZ,{oauthProviders:m,apiKeyProviders:y,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)(rQ,{existingProviders:r.providers??{},onImport:$,onClose:()=>C(!1)})]})}function r1(e){return`${e.scope}\0${e.package}`}function r2(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function r5(e){let t=e.sourceInfo?.source,r=e.sourceInfo?.scope;return"user"===r||"user"===t?"global":"project"===r||"project"===t?"project":"path"}function r4({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 r8({skill:e,cwd:t,onToggle:r,toggling:o,saveError:i,update:l,updating:s,updateError:a,onUpdate:d}){let c=r5(e),u=!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"===c?"rgba(99,102,241,0.12)":"rgba(120,120,120,0.12)",color:"project"===c?"rgba(99,102,241,0.8)":"var(--text-dim)"},children:c}),(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"===c&&e.startsWith(t)){let r=e.slice(t.length).replace(/^[/\\]/,"");return`./${r}`}return r2(e)}(e.filePath)}),(0,n.jsx)(r4,{enabled:u,loading:o,onToggle:()=>r(e)}),i&&(0,n.jsx)("span",{style:{fontSize:12,color:"#f87171",flexShrink:0},children:i})]}),e.install&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap",fontSize:12,color:"var(--text-dim)"},children:[(0,n.jsxs)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11},children:[e.install.source,e.install.ref?`#${e.install.ref}`:""]}),(0,n.jsx)("span",{style:{fontSize:10,padding:"1px 5px",borderRadius:3,background:"rgba(120,120,120,0.12)"},children:e.install.scope}),l?.state==="update-available"&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{style:{color:"#d97706",fontWeight:600},children:"↑ Update available"}),(0,n.jsx)("button",{onClick:d,disabled:s,style:{padding:"3px 10px",fontSize:12,borderRadius:5,border:"1px solid var(--border)",background:"rgba(217,119,6,0.12)",color:"#b45309",cursor:s?"wait":"pointer"},children:s?"Updating…":"Update"})]}),l?.state==="up-to-date"&&(0,n.jsx)("span",{style:{color:"#16a34a"},children:"✓ Up to date"}),(l?.state==="unknown"||l?.state==="error")&&(0,n.jsxs)("span",{title:l.message,style:{color:"error"===l.state?"#f87171":"var(--text-dim)",maxWidth:420,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["error"===l.state?"Check failed":"Not comparable",l.message?` — ${l.message}`:""]}),!l&&!e.install.canCheckForUpdates&&(0,n.jsx)("span",{children:"Update check unavailable for this entry"}),a&&(0,n.jsx)("span",{style:{color:"#f87171",maxWidth:520,whiteSpace:"pre-wrap",wordBreak:"break-word",fontSize:11},children:a})]}),(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 r3({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,b]=(0,o.useState)([]),[y,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"),b(["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&&b(t=>(t.at(-1)===e.line?t:[...t,e.line]).slice(-8))):"done"===e.type&&e.success?(a=!0,v("Installed"),b(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"),b(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/":`${r2(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=y.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 r6({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),[b,y]=(0,o.useState)({}),[j,k]=(0,o.useState)(!1),[w,S]=(0,o.useState)(!1),[C,T]=(0,o.useState)(null),[z,I]=(0,o.useState)(null),[M,R]=(0,o.useState)(null),L=(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({}),S(!1),T(null),R(null),L()},[e]),(0,o.useEffect)(()=>{R(null)},[u]);let W=(0,o.useCallback)(async t=>{let r=!t.disableModelInvocation;x(e=>new Set(e).add(t.filePath)),f(null);try{let n=await fetch("/api/skills",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,filePath:t.filePath,disableModelInvocation:r})}),o=await n.json();if(!n.ok||o.error)return void f(o.error??`HTTP ${n.status}`);l(e=>e.map(e=>e.filePath===t.filePath?{...e,disableModelInvocation:r}:e))}catch(e){f(String(e))}finally{x(e=>{let r=new Set(e);return r.delete(t.filePath),r})}},[e]),E=(0,o.useCallback)(async()=>{k(!0),T(null);try{let t=await fetch("/api/skills/check",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e})}),r=await t.json();if(!t.ok||r.error)return void T(r.error??`HTTP ${t.status}`);let n={};for(let e of r.updates??[])n[`${e.scope}\0${e.package}`]=e;y(n),S(!0)}catch(e){T(String(e))}finally{k(!1)}},[e]),P=(0,o.useCallback)(async t=>{let r=t.install;if(r){I(r1(r)),R(null);try{let t=await fetch("/api/skills/update",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,package:r.package,scope:r.scope})}),n=await t.json();if(!t.ok||n.error)return void R(n.error??`HTTP ${t.status}`);let o=await fetch("/api/skills/check",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,package:r.package,scope:r.scope})}),i=await o.json(),l=i.updates?.[0];l&&y(e=>({...e,[r1(l)]:l})),await L()}catch(e){R(String(e))}finally{I(null)}}},[e,L]),$=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:r2(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=>r5(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,o=e.install?b[r1(e.install)]:void 0;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}),o?.state==="update-available"&&(0,n.jsx)("span",{title:"Update available",style:{flexShrink:0,fontSize:11,fontWeight:700,color:"#d97706"},children:"↑"})]},e.filePath)})]},e))})()}),(0,n.jsxs)("div",{style:{padding:"8px 6px",borderTop:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsxs)("button",{onClick:E,disabled:j||s||0===i.length,title:"Compare installed skills with their upstream source",style:{width:"100%",display:"flex",alignItems:"center",gap:6,padding:"7px 8px",marginBottom:2,borderRadius:5,border:"none",background:"none",color:j?"var(--accent)":"var(--text-dim)",fontSize:12,textAlign:"left",cursor:j||s||0===i.length?"not-allowed":"pointer",opacity:s||0===i.length?.5: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 1 1-2.64-6.36"}),(0,n.jsx)("polyline",{points:"21 3 21 9 15 9"})]}),j?"Checking…":"Check updates"]}),C&&(0,n.jsx)("div",{style:{padding:"2px 8px 6px",fontSize:11,color:"#f87171",wordBreak:"break-word"},children:C}),w&&!j&&!C&&0===Object.keys(b).length&&(0,n.jsx)("div",{style:{padding:"2px 8px 6px",fontSize:11,color:"var(--text-dim)"},children:"No installed sources to check"}),(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)(r3,{cwd:e,onInstalled:()=>{L()}}):s?null:$?(0,n.jsx)(r8,{skill:$,cwd:e,onToggle:W,toggling:h.has($.filePath),saveError:g,update:$.install?b[r1($.install)]:void 0,updating:!!$.install&&z===r1($.install),updateError:M,onUpdate:()=>P($)},$.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 r7=[{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 r9(e){return e?e.replace(/^\/(?:Users|home)\/[^/]+/,"~"):""}function ne(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 nt(e){return{id:"",language:e,displayName:"",command:"python"===e?"python3":"R",argsText:JSON.stringify("python"===e?["-u"]:["--slave","--vanilla"]),envText:"{}"}}function nr(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 nn={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"},no={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 ni({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 nl({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),[b,y]=(0,o.useState)("view"),[j,k]=(0,o.useState)(()=>nt("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"===b)return void k(nt(t));let e=M??I.find(e=>e.isEffective)??I[0]??null;e?(v!==e.id&&m(e.id),k(nr(e)),y("view")):(m(null),k(nt(t)),y("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]),P=(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"===b?"add":"edit",kernelId:e,kernel:t},"save"))return;m(e),y("view"),x("new"===b?"Kernel added.":"Kernel saved.")}catch(e){p(e instanceof Error?e.message:String(e))}},[j,b,R]),$=(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),y(n?"view":"new"),x("Kernel deleted.")},[t,R]),D=()=>{y("new"),m(null),k(nt(t)),p(null),x(null)},N=(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(`Kernel idle timeout set to ${ne(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:"Kernel 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 for analysis turns and kernel tools."})]}),(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:{...nn,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:{...nn,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:r7.map(e=>{let t=w===e.value;return(0,n.jsx)("button",{type:"button",onClick:()=>{t||N(e.value)},disabled:C,title:`Close inactive kernels after ${ne(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:{...nn,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:r9(i?.paths.global??"")})]}),e&&(0,n.jsxs)("div",{children:["Project: ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:r9(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"!==b;return(0,n.jsxs)("button",{type:"button",onClick:()=>{m(e.id),y("view"),k(nr(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"===b&&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)(ni,{label:"Command",children:(0,n.jsx)("input",{readOnly:!0,value:M.command,style:{...no,color:"var(--text-muted)"}})}),(0,n.jsx)(ni,{label:"Args",children:(0,n.jsx)("input",{readOnly:!0,value:JSON.stringify(M.args),style:{...no,color:"var(--text-muted)"}})})]}),(0,n.jsx)(ni,{label:"Environment",children:(0,n.jsx)("textarea",{readOnly:!0,value:JSON.stringify(M.env,null,2),rows:5,style:{...no,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:{...nn,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:{...nn,opacity:"default"===d?.6:1},children:"Set default"}),(0,n.jsx)("button",{type:"button",onClick:()=>{y("edit"),m(M.id),k(nr(M)),p(null),x(null)},style:nn,children:"Edit"}),!M.id.startsWith("default-")&&(0,n.jsx)("button",{type:"button",onClick:()=>void $(M),disabled:"delete"===d,style:{...nn,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"===b?"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)(ni,{label:"Kernel ID",children:(0,n.jsx)("input",{value:j.id,readOnly:"edit"===b,onChange:e=>k(t=>({...t,id:e.target.value})),placeholder:"python"===t?"my-python":"my-r",style:{...no,color:"edit"===b?"var(--text-muted)":"var(--text)"}})}),(0,n.jsx)(ni,{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:no})})]}),(0,n.jsx)(ni,{label:"Command",children:(0,n.jsx)("input",{value:j.command,onChange:e=>k(t=>({...t,command:e.target.value})),placeholder:"/usr/bin/python3",style:no})}),(0,n.jsx)(ni,{label:"Args JSON",children:(0,n.jsx)("input",{value:j.argsText,onChange:e=>k(t=>({...t,argsText:e.target.value})),style:no})}),(0,n.jsx)(ni,{label:"Env JSON",children:(0,n.jsx)("textarea",{value:j.envText,onChange:e=>k(t=>({...t,envText:e.target.value})),rows:6,style:{...no,resize:"vertical"}})}),(0,n.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,n.jsx)("button",{type:"button",onClick:()=>void P(),disabled:"save"===d,style:{...nn,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(nr(e)),y("view")):D(),p(null)},style:nn,children:"Cancel"})]})]})})]})]})}var ns=r(7834);function na({text:e,label:t="Copy",title:r,onCopied:i,onError:l}){let[s,a]=(0,o.useState)(!1);(0,o.useEffect)(()=>{if(!s)return;let e=setTimeout(()=>a(!1),1500);return()=>clearTimeout(e)},[s]);let d=(0,o.useCallback)(async()=>{try{await (0,ns.D)(e),a(!0),i?.()}catch(e){l?.(e instanceof Error?e:Error(String(e)))}},[i,l,e]);return(0,n.jsx)("button",{type:"button",onClick:()=>void d(),title:r??(s?"Copied":t),style:{height:24,padding:"0 8px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg-hover)",color:s?"#22c55e":"var(--text-muted)",fontSize:10,fontWeight:600,cursor:"pointer",flexShrink:0},children:s?"Copied":t})}r(41463);let nd="annovibe-im-gateway";function nc({cwd:e,embedded:t=!1}){let[r,i]=(0,o.useState)(null),[l,s]=(0,o.useState)(null),[a,d]=(0,o.useState)(null),[c,u]=(0,o.useState)(""),[p,h]=(0,o.useState)(""),[x,g]=(0,o.useState)(!1),[f,v]=(0,o.useState)(""),[m,b]=(0,o.useState)(""),[y,j]=(0,o.useState)(!1),[k,w]=(0,o.useState)(!1),[S,C]=(0,o.useState)(!1),[T,z]=(0,o.useState)(null),[I,M]=(0,o.useState)(null),R=(0,o.useCallback)((e,t)=>{"success"===t?(M(e),z(null),setTimeout(()=>M(null),4500)):(z(e),M(null))},[]),L=(0,o.useCallback)(async()=>{try{let e=await fetch("/api/im/gateway-status",{cache:"no-store"}),t=await e.json();if(!e.ok||!t.gateway)return;d(t.gateway)}catch{}},[]),W=(0,o.useCallback)(async()=>{j(!0),z(null);try{let t=await fetch(`/api/im/project?cwd=${encodeURIComponent(e)}`,{cache:"no-store"}),r=await t.json();if(!t.ok||!("enabled"in r))throw Error(r.error??`HTTP ${t.status}`);i(r),s(r.gatewayToken??null),u(r.botId),g(r.requireMentionInGroup),v(r.boundChatId??""),b(r.allowedUsers.join("\n")),h("")}catch(e){R(e instanceof Error?e.message:String(e),"error")}finally{j(!1)}},[e,R]);(0,o.useEffect)(()=>{W()},[W]),(0,o.useEffect)(()=>{if(!r?.enabled)return void d(null);L();let e=setInterval(()=>{L()},12e3);return()=>clearInterval(e)},[r?.enabled,L]);let E=(0,o.useCallback)(async t=>{w(!0),z(null),M(null);try{let r=await fetch("/api/im/project",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,config:t})}),n=await r.json();if(!r.ok||!("enabled"in n))throw Error(n.error??`HTTP ${r.status}`);i(n),s(n.gatewayToken??null),h(""),R("IM settings saved.","success")}catch(e){R(e instanceof Error?e.message:String(e),"error")}finally{w(!1)}},[e,R]),P=(0,o.useCallback)(e=>{E({enabled:e,botId:c.trim(),botSecret:p.trim()||void 0,requireMentionInGroup:x,boundChatId:f.trim()||null,allowedUsers:nx(m)})},[c,p,x,f,m,E]),$=(0,o.useCallback)(()=>{E({enabled:r?.enabled??!1,botId:c.trim(),botSecret:p.trim()||void 0,requireMentionInGroup:x,boundChatId:f.trim()||null,allowedUsers:nx(m)})},[r?.enabled,c,p,x,f,m,E]),D=(0,o.useCallback)(()=>{E({regeneratePairingCode:!0})},[E]),N=(0,o.useCallback)(async()=>{if(r?.sessionId&&window.confirm("Reset the IM thread for this project?\n\nThis clears the stored WeCom session. Pairing and bot settings are kept. The next IM message starts a fresh session.")){C(!0);try{let t=await fetch(`/api/im/session-ids?cwd=${encodeURIComponent(e)}`,{method:"DELETE"}),r=await t.json();if(!t.ok||!r.ok)throw Error(r.error??`HTTP ${t.status}`);i(e=>e?{...e,sessionId:null}:null),R("IM thread reset.","success")}catch(e){R(e instanceof Error?e.message:String(e),"error")}finally{C(!1)}}},[r?.sessionId,e,R]);if(y&&!r)return(0,n.jsx)(nv,{label:"Loading IM settings..."});let A=r?.enabled??!1;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8,paddingTop:12*!!t},children:[(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-panel)",padding:12,display:"flex",flexDirection:"column",gap:12},children:[(0,n.jsx)(nh,{label:"WeCom bot for this project",description:A?"启动 im-gateway 后即可通过企业微信 AI bot 与此项目交互。":"关闭 — 开启后可绑定企业微信 bot 到此项目。",checked:A,disabled:k,onChange:P}),A?(0,n.jsxs)(n.Fragment,{children:[a?(0,n.jsx)(nu,{status:a}):null,(0,n.jsx)(ng,{label:"Bot ID",value:c,onChange:u,placeholder:"从企业微信 AI bot 控制台获取"}),(0,n.jsx)(ng,{label:r?.hasSecret?"Bot Secret(留空则不修改)":"Bot Secret",value:p,onChange:h,placeholder:r?.hasSecret?"留空保留现有 secret":"从企业微信 AI bot 控制台获取",secret:!0}),(0,n.jsx)(nh,{label:"群聊中需要 @提及 bot 才响应",description:"开启后,群聊中用户必须 @bot 才会被处理。",checked:x,disabled:k,compact:!0,onChange:g}),(0,n.jsx)(ng,{label:"绑定群聊 ID(可选)",value:f,onChange:v,placeholder:"限制仅此群聊可交互"}),(0,n.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4,fontSize:11,color:"var(--text-muted)"},children:[(0,n.jsx)("span",{children:"允许用户 ID(一行一个)"}),(0,n.jsx)("textarea",{value:m,onChange:e=>b(e.target.value),rows:3,style:ny,placeholder:"用户也可通过配对码自助授权"})]}),(0,n.jsxs)("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[(0,n.jsx)(nf,{primary:!0,disabled:k,onClick:$,children:k?"保存中…":"保存 IM 配置"}),(0,n.jsx)(nf,{disabled:k,onClick:D,children:"重新生成配对码"})]})]}):null]}),A&&r?(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-panel)",padding:12,fontSize:11,color:"var(--text-muted)",display:"flex",flexDirection:"column",gap:8},children:[(0,n.jsx)(np,{label:"配对码",value:r.pairingCode,copyLabel:"复制配对码"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,flexWrap:"wrap"},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("strong",{style:{color:"var(--text)"},children:"IM session:"})," ",r.sessionId?`${r.sessionId.slice(0,12)}…`:"尚未启动"]}),r.sessionId?(0,n.jsx)(nf,{danger:!0,disabled:k||S,onClick:()=>void N(),children:S?"重置中…":"重置 IM thread"}):null]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("strong",{style:{color:"var(--text)"},children:"Gateway token:"})," ",l?`${l.slice(0,8)}…`:"保存时生成"]}),(0,n.jsx)(np,{label:"Gateway 启动命令",value:nd,copyLabel:"复制命令",mono:!0}),(0,n.jsxs)("div",{style:{lineHeight:1.55,color:"var(--text-dim)"},children:["启动 ",(0,n.jsx)("code",{style:nm,children:"annovibe"})," 后,在",(0,n.jsx)("strong",{style:{color:"var(--text-muted)",fontWeight:600},children:"同一 Linux 账户"}),"中运行"," ",(0,n.jsx)("code",{style:nm,children:nd}),"。 Gateway 通过本地 API 读取已启用的项目配置和 bot secret —— 无需手动复制文件。"]}),(0,n.jsxs)("div",{style:{lineHeight:1.55,color:"var(--text-dim)"},children:["配置文件: ",(0,n.jsxs)("code",{style:nm,children:["<project>","/.annovibe/im.json"]})," \xb7 Secrets: ",(0,n.jsx)("code",{style:nm,children:"~/.pi/agent/im-secrets/"})]}),T&&(0,n.jsx)("div",{style:{padding:"6px 10px",background:"rgba(239,68,68,0.08)",borderRadius:6,border:"1px solid rgba(239,68,68,0.3)",color:"#ef4444",fontSize:12},children:T}),I&&(0,n.jsx)("div",{style:{padding:"6px 10px",background:"rgba(34,197,94,0.08)",borderRadius:6,border:"1px solid rgba(34,197,94,0.3)",color:"#22c55e",fontSize:12},children:I})]}):null]})}function nu({status:e}){var t,r,o,i;let l=function(e){if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}(e.startedAt),s=e.alive&&e.pid?`pid ${e.pid}${l?` \xb7 since ${l}`:""}`:l?`last started ${l}`:"在同一个 Linux 账户下运行 annovibe-im-gateway";return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:10,padding:"8px 10px",borderRadius:8,border:`1px solid ${"running"===(t=e.tone)?"rgba(34,197,94,0.28)":"stale"===t?"rgba(245,158,11,0.28)":"rgba(248,113,113,0.28)"}`,background:"running"===(r=e.tone)?"rgba(34,197,94,0.08)":"stale"===r?"rgba(245,158,11,0.08)":"rgba(248,113,113,0.08)"},children:[(0,n.jsx)("span",{"aria-hidden":!0,style:{width:8,height:8,borderRadius:"50%",marginTop:4,flexShrink:0,background:"running"===(o=e.tone)?"#22c55e":"stale"===o?"#f59e0b":"#f87171"}}),(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:11,fontWeight:650,color:"running"===(i=e.tone)?"#22c55e":"stale"===i?"#f59e0b":"#f87171"},children:e.label}),(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:3,lineHeight:1.45},children:s})]})]})}function np({label:e,value:t,copyLabel:r,mono:o}){return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsxs)("strong",{style:{color:"var(--text)"},children:[e,":"]})," ",(0,n.jsx)("code",{style:{...nm,...o?{wordBreak:"break-all"}:{}},children:t})]}),(0,n.jsx)(na,{text:t,label:r})]})}function nh({label:e,description:t,checked:r,disabled:o,compact:i,onChange:l}){return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:i?"2px 0":"10px 12px",borderRadius:8*!i,border:i?"none":`1px solid ${r?"color-mix(in srgb, var(--accent) 35%, var(--border))":"var(--border)"}`,background:i?"transparent":r?"color-mix(in srgb, var(--accent) 8%, var(--bg-panel))":"var(--bg)"},children:[(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:i?11:13,fontWeight:i?500:650,color:"var(--text)"},children:e}),t?(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",marginTop:4,lineHeight:1.45},children:t}):null]}),(0,n.jsx)("button",{type:"button",role:"switch","aria-checked":r,disabled:o,onClick:()=>l(!r),style:{position:"relative",width:44,height:26,borderRadius:999,border:"none",flexShrink:0,background:r?"var(--accent)":"color-mix(in srgb, var(--text-dim) 35%, var(--border))",cursor:o?"default":"pointer",opacity:o?.55:1,transition:"background 0.15s",padding:0},children:(0,n.jsx)("span",{style:{position:"absolute",top:3,left:r?21:3,width:20,height:20,borderRadius:"50%",background:"#fff",boxShadow:"0 1px 3px rgba(0,0,0,0.18)",transition:"left 0.15s"}})})]})}function nx(e){return e.split(/\r?\n/).map(e=>e.trim()).filter(Boolean)}function ng({label:e,value:t,onChange:r,placeholder:o,secret:i}){return(0,n.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4,fontSize:11,color:"var(--text-muted)"},children:[(0,n.jsx)("span",{children:e}),(0,n.jsx)("input",{type:i?"password":"text",value:t,onChange:e=>r(e.target.value),placeholder:o,style:nb})]})}function nf({children:e,disabled:t,primary:r,danger:o,onClick:i}){return(0,n.jsx)("button",{type:"button",disabled:t,onClick:i,style:{height:28,padding:"0 10px",borderRadius:6,border:r?"none":o?"1px solid rgba(248,113,113,0.45)":"1px solid var(--border)",background:r?"var(--accent)":o?"rgba(248,113,113,0.08)":"var(--bg-hover)",color:r?"#fff":o?"#f87171":"var(--text)",fontSize:11,fontWeight:r?600:400,cursor:t?"default":"pointer",opacity:t?.55:1},children:e})}function nv({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})}let nm={fontFamily:"var(--font-mono)",fontSize:"0.95em"},nb={height:30,padding:"0 8px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:12,fontFamily:"var(--font-mono)"},ny={padding:"8px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:12,fontFamily:"var(--font-mono)",resize:"vertical"},nj={border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-panel)"},nk={height:28,padding:"0 9px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12};function nw({cwd:e}){let[t,r]=(0,o.useState)(null),[i,l]=(0,o.useState)(!0),[s,a]=(0,o.useState)(null),[d,c]=(0,o.useState)(null),u=(0,o.useCallback)(async()=>{l(!0),c(null);try{let t=await fetch(`/api/plot-kernels?cwd=${encodeURIComponent(e)}`),n=await t.json().catch(()=>({}));if(!t.ok||n.error||!Array.isArray(n.kernels))throw Error(n.error??`HTTP ${t.status}`);r(n)}catch(e){r(null),c(e instanceof Error?e.message:String(e))}finally{l(!1)}},[e]);(0,o.useEffect)(()=>{u()},[u]);let p=(0,o.useCallback)(async(t,n)=>{a(t),c(null);try{let o=await fetch("/api/plot-kernels",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"select",cwd:e,language:t,kernelId:n})}),i=await o.json().catch(()=>({}));if(!o.ok||i.error||!Array.isArray(i.kernels))throw Error(i.error??`HTTP ${o.status}`);r(i)}catch(e){c(e instanceof Error?e.message:String(e))}finally{a(null)}},[e]),h=e=>{let r=t?.kernels.filter(t=>t.language===e)??[],o=r.find(e=>e.isEffective)??r[0]??null;return(0,n.jsxs)("label",{style:{display:"grid",gap:6},children:[(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)"},children:"r"===e?"Default R kernel":"Default Python kernel"}),(0,n.jsx)("select",{value:o?.id??"",disabled:i||s===e||0===r.length,onChange:t=>{t.target.value&&p(e,t.target.value)},style:{height:32,padding:"0 9px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:12},children:0===r.length?(0,n.jsx)("option",{value:"",children:i?"Loading...":"No configured kernel"}):r.map(e=>(0,n.jsxs)("option",{value:e.id,children:[e.displayName,e.isProjectSelected?" \xb7 project":e.isDefault?" \xb7 global":""," — ",e.command," ",(e.args??[]).join(" ")]},e.id))})]})};return(0,n.jsxs)("section",{style:{...nj,padding:14,display:"grid",gap:12},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Default kernels"}),(0,n.jsx)("div",{style:{marginTop:3,fontSize:11,color:"var(--text-dim)",lineHeight:1.45},children:"Used as the default R/Python kernels for analysis. Chat sessions use these when they call the `kernel_plot_*` tools."})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr)",gap:10},children:[h("r"),h("python")]}),d&&(0,n.jsx)("div",{style:{fontSize:12,color:"#f87171"},children:d})]})}function nS({activeCwd:e,onSelectProject:t,onProjectsChanged:r}){let[i,l]=(0,o.useState)([]),[s,a]=(0,o.useState)(e),[d,c]=(0,o.useState)(null),[u,p]=(0,o.useState)(!0),[h,x]=(0,o.useState)(null),[g,f]=(0,o.useState)(""),[v,m]=(0,o.useState)(!1),[b,y]=(0,o.useState)(null),[j,k]=(0,o.useState)(null),[w,S]=(0,o.useState)(""),[C,T]=(0,o.useState)(null),[z,M]=(0,o.useState)(null),R=(0,o.useRef)(null),L=i.find(e=>e.cwd===s)??i.find(t=>t.cwd===e)??i[0]??null,W=(0,o.useCallback)(async()=>{try{p(!0);let t=await fetch("/api/projects"),r=await t.json();if(!t.ok||r.error)throw Error(r.error??`HTTP ${t.status}`);let n=r.projects??[];l(n),a(t=>t&&n.some(e=>e.cwd===t)?t:e&&n.some(t=>t.cwd===e)?e:n[0]?.cwd??null),x(null)}catch(e){x(e instanceof Error?e.message:String(e))}finally{p(!1)}},[e]);(0,o.useEffect)(()=>{W()},[W]),(0,o.useEffect)(()=>{e&&i.some(t=>t.cwd===e)&&a(e)},[e,i]);let E=(0,o.useMemo)(()=>({projects:i.length,chats:i.reduce((e,t)=>e+t.chatCount,0)}),[i]),P=(0,o.useCallback)(async()=>{let e=g.trim();if(e){y("add"),x(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}`);f(""),a(e),r?.(),t?.(e),W()}catch(e){x(e instanceof Error?e.message:String(e))}finally{y(null)}}},[W,r,t,g]),$=(0,o.useCallback)(async e=>{y("add"),x(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}`);f(""),m(!1),a(e),r?.(),t?.(e),W()}catch(e){x(e instanceof Error?e.message:String(e))}finally{y(null)}},[W,r,t]),D=(0,o.useCallback)(async e=>{y(`rename:${e}`),x(null);try{let t=await fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,name:w})}),n=await t.json();if(!t.ok||n.error)throw Error(n.error??`HTTP ${t.status}`);k(null),S(""),await W(),r?.()}catch(e){x(e instanceof Error?e.message:String(e))}finally{y(null)}},[W,r,w]),N=(0,o.useCallback)(async e=>{if(window.confirm("Remove this project from AnnoVibe? Sessions on disk will not be deleted.")){y(`remove:${e}`),x(null);try{let t=await fetch("/api/projects",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e})}),n=await t.json();if(!t.ok||n.error)throw Error(n.error??`HTTP ${t.status}`);a(t=>t===e?null:t),await W(),r?.()}catch(e){x(e instanceof Error?e.message:String(e))}finally{y(null)}}},[W,r]),A=(0,o.useCallback)(e=>{k(e.cwd),S(e.displayName),requestAnimationFrame(()=>R.current?.focus())},[]),O=(0,o.useCallback)(async e=>{try{let t=await fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({order:e})});if(!t.ok)throw Error(`HTTP ${t.status}`);r?.()}catch{W()}},[W,r]),B=(0,o.useCallback)((e,t)=>{"reorder"!==b&&(T(e),t.dataTransfer.effectAllowed="move",t.dataTransfer.setData("text/project-cwd",e))},[b]),H=(0,o.useCallback)((e,t)=>{t.preventDefault(),t.dataTransfer.dropEffect="move",M(e)},[]),F=(0,o.useCallback)(e=>{if(M(null),!C||C===e)return void T(null);let t=i.map(e=>e.cwd).filter(Boolean),r=t.indexOf(C),n=t.indexOf(e);r<0||n<0?T(null):(t.splice(r,1),t.splice(n,0,C),l(e=>{let r=new Map(e.map(e=>[e.cwd,e]));return t.map(e=>r.get(e)).filter(Boolean)}),T(null),O(t))},[C,O,i]),U=(0,o.useCallback)(()=>{T(null),M(null)},[]);return(0,n.jsxs)("div",{style:{height:"100%",overflow:"hidden",display:"flex",flexDirection:"column"},children:[h&&(0,n.jsx)("div",{style:{marginBottom:12,padding:"10px 12px",borderRadius:8,border:"1px solid rgba(248,113,113,0.35)",background:"rgba(248,113,113,0.08)",color:"#f87171",fontSize:12},children:h}),(0,n.jsxs)("div",{style:{display:"flex",gap:8,marginBottom:14,flexShrink:0},children:[(0,n.jsx)("div",{style:{position:"relative",flex:1,minWidth:0},children:(0,n.jsx)("input",{type:"text",value:g,onChange:e=>f(e.target.value),onKeyDown:e=>{"Enter"===e.key&&P()},placeholder:"/path/to/project",style:{width:"100%",height:30,padding:"0 8px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:12,fontFamily:"var(--font-mono)",outline:"none"}})}),(0,n.jsx)("button",{type:"button",disabled:"add"===b,onClick:()=>void P(),style:{height:30,padding:"0 11px",border:"none",borderRadius:6,background:"var(--accent)",color:"#fff",cursor:"pointer",fontSize:12,fontWeight:500},children:"Add"}),(0,n.jsx)("button",{type:"button",onClick:()=>m(!0),style:{...nk,height:30},children:"Browse…"})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(220px, 34%) minmax(0, 1fr)",gap:14,minHeight:0,flex:1},children:[(0,n.jsxs)("aside",{style:{...nj,minHeight:0,overflow:"hidden",display:"flex",flexDirection:"column"},children:[(0,n.jsxs)("div",{style:{padding:"10px 12px",borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{style:{color:"var(--text)",fontSize:13,fontWeight:700},children:[E.projects," Projects"]}),(0,n.jsxs)("div",{style:{marginTop:3,color:"var(--text-dim)",fontSize:11},children:[E.chats," chats total"]})]}),(0,n.jsx)("div",{style:{overflow:"auto",padding:8,display:"grid",gap:6},children:u?(0,n.jsx)("div",{style:{padding:12,color:"var(--text-muted)",fontSize:12},children:"Loading projects..."}):0===i.length?(0,n.jsx)("div",{style:{padding:12,color:"var(--text-muted)",fontSize:12},children:"No projects yet."}):i.map(t=>{var r;let o,i=t.cwd===e,l=t.cwd===L?.cwd,s=C===t.cwd,u=z===t.cwd&&C!==t.cwd,p=d===t.cwd&&!l;return(0,n.jsxs)("button",{type:"button",draggable:!0,onClick:()=>a(t.cwd),onDragStart:e=>B(t.cwd,e),onDragOver:e=>H(t.cwd,e),onDrop:()=>F(t.cwd),onDragEnd:U,onMouseEnter:()=>c(t.cwd),onMouseLeave:()=>c(null),style:{display:"grid",gap:4,width:"100%",textAlign:"left",padding:"9px 10px",border:`1px solid ${u?"rgba(37,99,235,0.45)":l?"color-mix(in srgb, var(--accent) 45%, var(--border))":"transparent"}`,borderRadius:8,background:u?"rgba(37,99,235,0.06)":l?"color-mix(in srgb, var(--accent) 8%, var(--bg-panel))":"transparent",color:"var(--text)",cursor:"pointer",opacity:s?.55:1},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:12.5,fontWeight:l?750:600},children:t.displayName}),i&&(0,n.jsx)("span",{style:{fontSize:10,color:"var(--accent)",fontWeight:700},children:"current"}),p&&(0,n.jsx)("span",{onClick:e=>{e.stopPropagation(),N(t.cwd)},style:{color:"#f87171",fontSize:11,fontWeight:650},children:"remove"})]}),(0,n.jsx)("div",{style:{color:"var(--text-dim)",fontSize:10.5,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:t.cwd,children:(o=(r=t.cwd).split(/[\\/]/).filter(Boolean)).length<=3?r:`.../${o.slice(-3).join("/")}`})]},t.cwd)})})]}),(0,n.jsx)("main",{style:{minHeight:0,overflow:"auto"},children:L?(0,n.jsxs)("div",{style:{display:"grid",gap:14},children:[(0,n.jsx)("section",{style:{...nj,padding:14,display:"grid",gap:12},children:(0,n.jsxs)("div",{style:{display:"flex",gap:12,alignItems:"flex-start"},children:[(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[j===L.cwd?(0,n.jsx)("input",{ref:R,value:w,onChange:e=>S(e.target.value),onKeyDown:e=>{"Enter"===e.key&&D(L.cwd),"Escape"===e.key&&k(null)},style:{width:"min(420px, 100%)",height:32,padding:"0 9px",border:"1px solid var(--accent)",borderRadius:6,background:"var(--bg)",color:"var(--text)",fontSize:13,outline:"none"}}):(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:16,fontWeight:750},children:L.displayName}),(0,n.jsx)("div",{style:{marginTop:5,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:L.cwd}),(0,n.jsxs)("div",{style:{marginTop:7,color:"var(--text-muted)",fontSize:11},children:[L.chatCount," chats / last ",function(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()}(L.lastAccessed??L.created??null),L.exists?"":" / path missing"]})]}),(0,n.jsx)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",justifyContent:"flex-end"},children:j===L.cwd?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",disabled:b===`rename:${L.cwd}`,onClick:()=>void D(L.cwd),style:{...nk,border:"none",background:"var(--accent)",color:"#fff"},children:"Save"}),(0,n.jsx)("button",{type:"button",onClick:()=>k(null),style:nk,children:"Cancel"})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:()=>t?.(L.cwd),style:{...nk,background:L.cwd===e?"var(--accent)":"var(--bg-panel)",color:L.cwd===e?"#fff":"var(--text-muted)"},children:L.cwd===e?"Current":"Switch"}),(0,n.jsx)("button",{type:"button",onClick:()=>A(L),style:nk,children:"Rename"}),(0,n.jsx)("button",{type:"button",disabled:b===`remove:${L.cwd}`,onClick:()=>void N(L.cwd),style:{...nk,border:"1px solid rgba(248,113,113,0.35)",background:"transparent",color:"#f87171"},children:"Remove"})]})})]})}),(0,n.jsx)(nw,{cwd:L.cwd}),(0,n.jsxs)("section",{style:{...nj,padding:14,display:"grid",gap:12},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"WeCom IM"}),(0,n.jsx)("div",{style:{marginTop:3,fontSize:11,color:"var(--text-dim)"},children:"Project notification and chat gateway settings."})]}),(0,n.jsx)(nc,{cwd:L.cwd,embedded:!0})]})]}):(0,n.jsx)("div",{style:{...nj,padding:18,color:"var(--text-muted)",fontSize:12},children:"Select a project to edit settings."})})]}),(0,n.jsx)(I,{open:v,initialPath:e,onClose:()=>m(!1),onSelect:e=>void $(e)})]})}var nC=r(768);let nT=["127.0.0.0/8","::1","10.0.0.0/8","172.16.0.0/12","192.168.0.0/16"];function nz({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 nI({label:e,description:t,checked:r,onChange:o}){return(0,n.jsxs)("label",{style:{display:"flex",alignItems:"flex-start",gap:10,padding:"10px 12px",borderRadius:8,border:`1px solid ${r?"var(--accent)":"var(--border)"}`,background:r?"rgba(37,99,235,0.04)":"var(--bg)",cursor:"pointer",fontSize:12},children:[(0,n.jsx)("input",{type:"radio",checked:r,onChange:o,style:{marginTop:2,accentColor:"var(--accent)"}}),(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontWeight:600,color:"var(--text)",lineHeight:1.4},children:e}),(0,n.jsx)("div",{style:{color:"var(--text-dim)",lineHeight:1.5,marginTop:2},children:t})]})]})}function nM(){let[e,t]=(0,o.useState)(null),[r,i]=(0,o.useState)(!0),[l,s]=(0,o.useState)(null),[a,d]=(0,o.useState)(null),[c,u]=(0,o.useState)(""),[p,h]=(0,o.useState)(""),[x,g]=(0,o.useState)(null),[f,v]=(0,o.useState)(null),[m,b]=(0,o.useState)(null),[y,j]=(0,o.useState)(!1),[k,w]=(0,o.useState)("always"),[S,C]=(0,o.useState)(!0),[T,z]=(0,o.useState)(nT),[I,M]=(0,o.useState)(""),R=(0,o.useCallback)(async()=>{try{let e=await fetch("/api/auth/totp"),r=await e.json();t(r),w(r.requireMode??"always"),z(r.trustedNetworks??nT),C(!1!==r.proxyHeaderTrusted)}catch{}finally{i(!1)}},[]);(0,o.useEffect)(()=>{R()},[R]);let L=async()=>{if(e){if(g(null),"enabled"===e.status){if(!p||!/^\d{6}$/.test(p))return void g("Enter your 6-digit authenticator code to disable");j(!0);try{let e=await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"disable",code:p})}),r=await e.json();e.ok?(t({status:"disabled",enabled:!1,requireMode:"always",trustedNetworks:nT}),h(""),s(null),d(null),b(null),v("Two-factor authentication disabled")):g(r.error??"Failed to disable")}catch{g("Network error")}finally{j(!1)}return}j(!0);try{let e=await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"setup"})}),r=await e.json();if(e.ok&&r.uri){d(r.uri);let e=await nC.toDataURL(r.uri,{width:200,margin:1});s(e),t({status:"pending",enabled:!1,requireMode:k,trustedNetworks:T}),v(null)}else g(r.error??"Failed to start setup")}catch{g("Network error")}finally{j(!1)}}},W=async()=>{if(!c||!/^\d{6}$/.test(c))return void g("Enter the 6-digit code from your authenticator app");j(!0),g(null);try{let e=await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"verify-setup",code:c})}),r=await e.json();e.ok&&r.success?(await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"set-require-mode",requireMode:k})}),await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"set-trusted-networks",trustedNetworks:T})}),t({status:"enabled",enabled:!0,requireMode:k,trustedNetworks:T}),u(""),s(null),d(null),r.recoveryCodes&&b(r.recoveryCodes),v("Two-factor authentication enabled!")):g(r.error??"Invalid code")}catch{g("Network error")}finally{j(!1)}},E=async()=>{s(null),d(null),u(""),g(null);try{await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"disable"})}),t({status:"disabled",enabled:!1,requireMode:"always",trustedNetworks:nT})}catch{}},P=(0,o.useCallback)(async r=>{if(w(r),e?.status==="enabled")try{await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"set-require-mode",requireMode:r})}),t(e=>e?{...e,requireMode:r}:e)}catch{w(e.requireMode)}},[e]),$=(0,o.useCallback)(async()=>{let r=I.trim();if(!r||T.includes(r))return;let n=r.split("/");if(2!==n.length)return void g("Invalid CIDR format (e.g. 192.168.1.0/24)");let o=parseInt(n[1],10);if(isNaN(o)||o<0||o>128)return void g("Invalid CIDR prefix length");g(null);let i=[...T,r];if(z(i),M(""),e?.status==="enabled")try{await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"set-trusted-networks",trustedNetworks:i})}),t(e=>e?{...e,trustedNetworks:i}:e)}catch{z(T)}},[I,T,e]),D=(0,o.useCallback)(async r=>{let n=T.filter(e=>e!==r);if(z(n),e?.status==="enabled")try{await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"set-trusted-networks",trustedNetworks:n})}),t(e=>e?{...e,trustedNetworks:n}:e)}catch{z(T)}},[T,e]);return r?(0,n.jsx)("div",{style:{padding:20,fontSize:13,color:"var(--text-muted)"},children:"Loading…"}):(0,n.jsx)("div",{style:{height:"100%",overflowY:"auto",padding:20},children:(0,n.jsxs)("div",{style:{maxWidth:600,display:"flex",flexDirection:"column",gap:16},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",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:"Two-Factor Authentication"}),(0,n.jsx)("div",{style:{marginTop:4,fontSize:12,color:"var(--text-muted)",lineHeight:1.55},children:"Require a time-based one-time code in addition to your password."})]}),(0,n.jsx)(nz,{checked:e?.status==="enabled",onChange:()=>{}})]}),e&&(0,n.jsx)("div",{style:{fontSize:11,padding:"4px 10px",borderRadius:999,background:"enabled"===e.status?"rgba(34,197,94,0.12)":"pending"===e.status?"rgba(250,204,21,0.12)":"var(--bg-hover)",color:"enabled"===e.status?"#16a34a":"pending"===e.status?"#ca8a04":"var(--text-dim)",display:"inline-flex",alignSelf:"flex-start",fontWeight:600},children:"enabled"===e.status?"● Active":"pending"===e.status?"◐ Setup in progress":"○ Inactive"}),x&&(0,n.jsx)("div",{style:{fontSize:12,color:"#ef4444",padding:"8px 12px",background:"rgba(239,68,68,0.06)",borderRadius:6},children:x}),f&&!x&&(0,n.jsx)("div",{style:{fontSize:12,color:"#16a34a",padding:"8px 12px",background:"rgba(34,197,94,0.06)",borderRadius:6},children:f}),e?.status==="pending"&&l&&(0,n.jsxs)("div",{style:{padding:20,border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",display:"flex",flexDirection:"column",alignItems:"center",gap:14},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)"},children:"Scan with your authenticator app"}),(0,n.jsx)("div",{style:{background:"#fff",padding:12,borderRadius:8,border:"1px solid var(--border)"},children:(0,n.jsx)("img",{src:l,alt:"TOTP QR Code",style:{display:"block",width:200,height:200}})}),a&&(0,n.jsxs)("div",{style:{fontSize:11,color:"var(--text-dim)",textAlign:"center",maxWidth:280},children:[(0,n.jsx)("div",{style:{marginBottom:4},children:"Or enter this key manually:"}),(0,n.jsx)("code",{style:{fontSize:11,fontFamily:"var(--font-mono), monospace",wordBreak:"break-all",background:"var(--bg)",padding:"4px 8px",borderRadius:4},children:a.split("secret=")[1]?.split("&")[0]??"—"})]}),(0,n.jsxs)("div",{style:{width:"100%",maxWidth:260},children:[(0,n.jsx)("label",{style:{fontSize:12,color:"var(--text-dim)",display:"block",marginBottom:6},children:"Enter the 6-digit code to verify"}),(0,n.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,n.jsx)("input",{type:"text",inputMode:"numeric",pattern:"[0-9]{6}",maxLength:6,value:c,onChange:e=>u(e.target.value.replace(/\D/g,"").slice(0,6)),placeholder:"000 000",style:{flex:1,padding:"8px 12px",fontSize:16,fontFamily:"var(--font-mono), monospace",letterSpacing:"0.12em",textAlign:"center",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",outline:"none"}}),(0,n.jsx)("button",{type:"button",disabled:y||6!==c.length,onClick:W,style:{padding:"8px 16px",fontSize:13,fontWeight:600,background:6===c.length?"var(--accent)":"var(--bg-hover)",color:6===c.length?"#fff":"var(--text-dim)",border:"none",borderRadius:6,cursor:6===c.length?"pointer":"not-allowed"},children:y?"…":"Verify"})]})]}),(0,n.jsx)("button",{type:"button",onClick:E,style:{fontSize:12,color:"var(--text-dim)",background:"none",border:"none",cursor:"pointer"},children:"Cancel setup"})]}),m&&m.length>0&&(0,n.jsxs)("div",{style:{padding:20,border:"1px solid rgba(34,197,94,0.3)",borderRadius:8,background:"rgba(34,197,94,0.04)"},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)",marginBottom:6},children:"Recovery codes"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",marginBottom:12,lineHeight:1.55},children:"Save these codes in a safe place. Each can be used once to sign in if you lose access to your authenticator app. They will not be shown again."}),(0,n.jsx)("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:6,fontFamily:"var(--font-mono), monospace",fontSize:12,color:"var(--text)"},children:m.map((e,t)=>(0,n.jsx)("code",{style:{padding:"6px 10px",background:"var(--bg)",borderRadius:4,border:"1px solid var(--border)"},children:e},t))}),(0,n.jsx)("button",{type:"button",onClick:()=>{b(null),v(null)},style:{marginTop:14,padding:"8px 18px",fontSize:13,fontWeight:600,background:"var(--accent)",color:"#fff",border:"none",borderRadius:6,cursor:"pointer"},children:"I've saved these codes"})]}),(e?.status==="enabled"||e?.status==="pending")&&!m&&(0,n.jsxs)("div",{style:{padding:16,border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)"},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)",marginBottom:12},children:"Scope"}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8,marginBottom:14},children:[(0,n.jsx)(nI,{label:"Require on all networks",description:"TOTP code is always required during login, even from localhost or LAN.",checked:"always"===k,onChange:()=>P("always")}),(0,n.jsx)(nI,{label:"Skip on trusted networks",description:"TOTP code is only required when signing in from outside localhost or LAN.",checked:"untrusted"===k,onChange:()=>P("untrusted")})]}),"untrusted"===k&&!S&&(0,n.jsxs)("div",{style:{marginBottom:10,padding:"9px 12px",borderRadius:8,border:"1px solid var(--border)",background:"var(--bg)",fontSize:12,color:"var(--text-muted)",lineHeight:1.6},children:["This mode needs a trusted reverse proxy: set"," ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono), monospace"},children:"ANNOVIBE_TRUST_PROXY_HEADERS=1"})," ","so annovibe can read the client IP. Without it the IP is unknown and TOTP is required for every sign-in, including localhost."]}),"untrusted"===k&&(0,n.jsxs)("div",{style:{padding:"10px 12px",background:"var(--bg)",borderRadius:8,border:"1px solid var(--border)"},children:[(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)",marginBottom:8,lineHeight:1.5},children:"Trusted CIDR blocks (TOTP will be skipped for requests from these IP ranges):"}),(0,n.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginBottom:10},children:T.map(e=>(0,n.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:4,padding:"3px 8px",borderRadius:999,background:"var(--bg-panel)",border:"1px solid var(--border)",fontSize:11,fontFamily:"var(--font-mono), monospace",color:"var(--text)"},children:[e,(0,n.jsx)("button",{type:"button",onClick:()=>D(e),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-dim)",fontSize:13,lineHeight:1,padding:0},title:"Remove",children:"\xd7"})]},e))}),(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsx)("input",{type:"text",value:I,onChange:e=>M(e.target.value),onKeyDown:e=>{"Enter"===e.key&&$()},placeholder:"e.g. 192.168.1.0/24",style:{flex:1,padding:"6px 10px",fontSize:12,fontFamily:"var(--font-mono), monospace",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",outline:"none"}}),(0,n.jsx)("button",{type:"button",onClick:$,style:{padding:"6px 12px",fontSize:12,fontWeight:600,background:I.trim()?"var(--accent)":"var(--bg-hover)",color:I.trim()?"#fff":"var(--text-dim)",border:"none",borderRadius:6,cursor:I.trim()?"pointer":"not-allowed"},children:"Add"})]})]})]}),e?.status==="enabled"&&!m&&(0,n.jsxs)("div",{style:{padding:16,border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)"},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)",marginBottom:8},children:"Disable two-factor authentication"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",marginBottom:12,lineHeight:1.5},children:"Enter your current authenticator code to disable 2FA. This will make your account less secure."}),(0,n.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,n.jsx)("input",{type:"text",inputMode:"numeric",pattern:"[0-9]{6}",maxLength:6,value:p,onChange:e=>h(e.target.value.replace(/\D/g,"").slice(0,6)),placeholder:"000 000",style:{flex:1,padding:"8px 12px",fontSize:16,fontFamily:"var(--font-mono), monospace",letterSpacing:"0.12em",textAlign:"center",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",outline:"none"}}),(0,n.jsx)("button",{type:"button",disabled:y||6!==p.length,onClick:L,style:{padding:"8px 16px",fontSize:13,fontWeight:600,background:6===p.length?"rgba(239,68,68,0.85)":"var(--bg-hover)",color:6===p.length?"#fff":"var(--text-dim)",border:"none",borderRadius:6,cursor:6===p.length?"pointer":"not-allowed"},children:y?"…":"Disable 2FA"})]})]}),e?.status==="disabled"&&(0,n.jsxs)("div",{style:{padding:16,border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)"},children:[(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.55},children:"When enabled, you'll need to enter a 6-digit code from your authenticator app (Google Authenticator, Authy, 1Password, etc.) each time you sign in from a new browser or after your session expires."}),(0,n.jsx)("button",{type:"button",disabled:y,onClick:L,style:{marginTop:14,padding:"8px 18px",fontSize:13,fontWeight:600,background:"var(--accent)",color:"#fff",border:"none",borderRadius:6,cursor:"pointer",opacity:y?.6:1},children:y?"Setting up…":"Set up authenticator"})]})]})})}function nR({cwd:e,embedded:t=!1}){let[r,i]=(0,o.useState)([]),[l,s]=(0,o.useState)(!0),[a,d]=(0,o.useState)(null),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(""),[x,g]=(0,o.useState)(!1),[f,v]=(0,o.useState)(null),m=(0,o.useCallback)(async()=>{s(!0);try{let t=e?`?cwd=${encodeURIComponent(e)}`:"",r=await fetch(`/api/plugins${t}`,{cache:"no-store"}),n=await r.json();if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);i(Array.isArray(n.packages)?n.packages:[]),d(null)}catch(e){d(e instanceof Error?e.message:String(e))}finally{s(!1)}},[e]);(0,o.useEffect)(()=>{m()},[m]);let b=(0,o.useCallback)(async(t,r,n)=>{if(!f){v(r),u(null);try{let o=await fetch("/api/plugins",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:t,source:r,cwd:e,local:n})}),i=await o.json();if(!o.ok||i.error)throw Error(i.error??`HTTP ${o.status}`);u("install"===t?`Installed ${r}`:"remove"===t?`Removed ${r}`:`Updated ${r}`),"install"!==t||n||h(""),await m()}catch(e){d(e instanceof Error?e.message:String(e))}finally{v(null)}}},[f,e,m]),y=(0,o.useCallback)(()=>{let t=p.trim();t&&!f&&b("install",t,x&&!!e)},[f,e,x,b,p]);return(0,n.jsx)("div",{style:{height:"100%",overflowY:"auto",padding:20*!!t},children:(0,n.jsxs)("div",{style:{maxWidth:760,display:"flex",flexDirection:"column",gap:14},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)"},children:"Package plugins"}),(0,n.jsx)("div",{style:{marginTop:4,fontSize:12,color:"var(--text-muted)",lineHeight:1.55},children:"Install pi packages from npm or git. They can add extensions, skills, prompt templates, and themes. Changes apply to newly started sessions."})]}),(0,n.jsxs)("div",{style:{padding:12,border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[(0,n.jsx)("input",{value:p,onChange:e=>h(e.target.value),onKeyDown:e=>{"Enter"===e.key&&y()},placeholder:"npm package, @scope/package, or git URL",style:{flex:"1 1 300px",minWidth:0,padding:"7px 9px",fontSize:12,color:"var(--text)",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:6,outline:"none"}}),(0,n.jsx)("button",{type:"button",onClick:y,disabled:!p.trim()||!!f,style:{padding:"7px 14px",fontSize:12,fontWeight:600,color:"var(--text)",background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:6,cursor:!p.trim()||f?"not-allowed":"pointer",opacity:!p.trim()||f?.55:1},children:f===p.trim()?"Installing…":"Install"})]}),e&&(0,n.jsxs)("label",{style:{display:"inline-flex",alignItems:"center",gap:6,marginTop:8,fontSize:11.5,color:"var(--text-muted)",cursor:"pointer"},children:[(0,n.jsx)("input",{type:"checkbox",checked:x,onChange:e=>g(e.target.checked),style:{margin:0}}),"Install into this project (otherwise global)"]})]}),a&&(0,n.jsx)("div",{style:{padding:"7px 10px",fontSize:11.5,color:"#f87171",border:"1px solid rgba(248,113,113,0.35)",background:"rgba(248,113,113,0.06)",borderRadius:6},children:a}),c&&(0,n.jsx)("div",{style:{padding:"7px 10px",fontSize:11.5,color:"#34d399",border:"1px solid rgba(52,211,153,0.35)",background:"rgba(52,211,153,0.06)",borderRadius:6},children:c}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,n.jsxs)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.06em"},children:["Installed (",r.length,")"]}),(0,n.jsx)("button",{type:"button",onClick:()=>{m()},disabled:l,style:{padding:"3px 9px",fontSize:11,color:"var(--text-muted)",background:"none",border:"1px solid var(--border)",borderRadius:5,cursor:l?"wait":"pointer"},children:l?"Refreshing…":"Refresh"})]}),l&&0===r.length?(0,n.jsx)("div",{style:{padding:"18px 0",fontSize:12,color:"var(--text-dim)",textAlign:"center"},children:"Loading packages…"}):0===r.length?(0,n.jsx)("div",{style:{padding:"18px 0",fontSize:12,color:"var(--text-dim)",textAlign:"center",border:"1px dashed var(--border)",borderRadius:8},children:"No package plugins installed."}):(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:r.map(e=>{let t=[e.resources.extensions>0?`${e.resources.extensions} ext`:"",e.resources.skills>0?`${e.resources.skills} skills`:"",e.resources.prompts>0?`${e.resources.prompts} prompts`:"",e.resources.themes>0?`${e.resources.themes} themes`:""].filter(Boolean).join(" \xb7 ")||"no resources resolved",r=f===e.source;return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:10,padding:"10px 12px",border:"1px solid var(--border)",borderRadius:8,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:7,minWidth:0},children:[(0,n.jsx)("span",{style:{fontSize:12.5,fontWeight:600,color:"var(--text)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.source}),(0,n.jsx)("span",{style:{flexShrink:0,padding:"0 5px",fontSize:9.5,color:"var(--text-dim)",border:"1px solid var(--border)",borderRadius:3,textTransform:"uppercase"},children:e.scope}),e.filtered&&(0,n.jsx)("span",{style:{flexShrink:0,padding:"0 5px",fontSize:9.5,color:"var(--text-dim)",border:"1px solid var(--border)",borderRadius:3},children:"filtered"})]}),(0,n.jsx)("div",{style:{marginTop:3,fontSize:11,color:"var(--text-muted)"},children:t}),e.installedPath&&(0,n.jsx)("div",{title:e.installedPath,style:{marginTop:2,fontSize:10.5,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.installedPath})]}),(0,n.jsxs)("div",{style:{display:"flex",gap:6,flexShrink:0},children:[(0,n.jsx)("button",{type:"button",disabled:!!f,onClick:()=>{b("update",e.source,"project"===e.scope)},style:{padding:"4px 9px",fontSize:11,color:"var(--text-muted)",background:"none",border:"1px solid var(--border)",borderRadius:5,cursor:f?"not-allowed":"pointer",opacity:f?.55:1},children:r?"Working…":"Update"}),(0,n.jsx)("button",{type:"button",disabled:!!f,onClick:()=>{window.confirm(`Remove ${e.source}?`)&&b("remove",e.source,"project"===e.scope)},style:{padding:"4px 9px",fontSize:11,color:"#f87171",background:"none",border:"1px solid rgba(248,113,113,0.35)",borderRadius:5,cursor:f?"not-allowed":"pointer",opacity:f?.55:1},children:"Remove"})]})]},e.source)})}),(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",lineHeight:1.55},children:"Tip: a package can also be a local path or git URL. Project installs require the project to be trusted."})]})})}let nL={forkSuggestTokens:{min:1e4,max:9e5},forkAutoTokens:{min:2e4,max:2e6},forkMinMessages:{min:5,max:500}},nW={forkEnabled:!1,forkSuggestEnabled:!0,forkSuggestTokens:18e4,forkAutoTokens:4e5,forkMinMessages:20};function nE(e,t){let{min:r,max:n}=nL[e];return Number.isFinite(t)?Math.min(Math.max(Math.round(t),r),n):nW[e]}function nP({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 n$({label:e,hint:t,value:r,min:o,max:i,step:l,disabled:s,onChange:a}){return(0,n.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:6,padding:14,border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",opacity:s?.55:1},children:[(0,n.jsx)("span",{style:{fontSize:12,fontWeight:700,color:"var(--text)"},children:e}),(0,n.jsx)("input",{type:"number",min:o,max:i,step:l,value:r,disabled:s,onChange:e=>a(Number(e.target.value)),style:{height:30,padding:"0 9px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:12,outline:"none"}}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:t})]})}let nD={height:30,padding:"0 13px",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"};function nN({onForkSettingsChanged:e}){let[t,r]=(0,o.useState)(nW),[i,l]=(0,o.useState)(!0),[s,a]=(0,o.useState)(!1),[d,c]=(0,o.useState)(null),[u,p]=(0,o.useState)(!1),[h,x]=(0,o.useState)(!1);(0,o.useEffect)(()=>{let e=!1;return fetch("/api/settings").then(e=>e.ok?e.json():Promise.reject(Error(`HTTP ${e.status}`))).then(t=>{if(e)return;let n=t.settings??{};r({forkEnabled:"boolean"==typeof n.forkEnabled?n.forkEnabled:nW.forkEnabled,forkSuggestEnabled:"boolean"==typeof n.forkSuggestEnabled?n.forkSuggestEnabled:nW.forkSuggestEnabled,forkSuggestTokens:"number"==typeof n.forkSuggestTokens?nE("forkSuggestTokens",n.forkSuggestTokens):nW.forkSuggestTokens,forkAutoTokens:"number"==typeof n.forkAutoTokens?nE("forkAutoTokens",n.forkAutoTokens):nW.forkAutoTokens,forkMinMessages:"number"==typeof n.forkMinMessages?nE("forkMinMessages",n.forkMinMessages):nW.forkMinMessages})}).catch(t=>{e||c(t instanceof Error?t.message:String(t))}).finally(()=>{e||l(!1)}),()=>{e=!0}},[]);let g=(0,o.useCallback)(e=>{r(t=>({...t,...e})),x(!0),p(!1),c(null)},[]),f=(0,o.useCallback)(async()=>{let n={forkEnabled:t.forkEnabled,forkSuggestEnabled:t.forkSuggestEnabled,forkSuggestTokens:nE("forkSuggestTokens",t.forkSuggestTokens),forkAutoTokens:nE("forkAutoTokens",t.forkAutoTokens),forkMinMessages:nE("forkMinMessages",t.forkMinMessages)};a(!0),c(null),p(!1);try{let t=await fetch("/api/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:n})}),o=await t.json().catch(()=>({}));if(!t.ok||o.error)throw Error(o.error??`HTTP ${t.status}`);let i=o.settings??{};r({forkEnabled:"boolean"==typeof i.forkEnabled?i.forkEnabled:n.forkEnabled,forkSuggestEnabled:"boolean"==typeof i.forkSuggestEnabled?i.forkSuggestEnabled:n.forkSuggestEnabled,forkSuggestTokens:"number"==typeof i.forkSuggestTokens?nE("forkSuggestTokens",i.forkSuggestTokens):n.forkSuggestTokens,forkAutoTokens:"number"==typeof i.forkAutoTokens?nE("forkAutoTokens",i.forkAutoTokens):n.forkAutoTokens,forkMinMessages:"number"==typeof i.forkMinMessages?nE("forkMinMessages",i.forkMinMessages):n.forkMinMessages}),x(!1),p(!0),e?.()}catch(e){c(e instanceof Error?e.message:String(e))}finally{a(!1)}},[t,e]);return(0,n.jsx)("div",{style:{height:"100%",overflowY:"auto",padding:20},children:(0,n.jsxs)("div",{style:{maxWidth:720,display:"flex",flexDirection:"column",gap:14},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:"Fork suggestion"}),(0,n.jsx)("div",{style:{marginTop:5,fontSize:12,color:"var(--text-muted)",lineHeight:1.55},children:"Shows a “Fork 新会话” button when the context reaches the threshold. Nothing is created until you click it and confirm. On by default."})]}),(0,n.jsx)(nP,{checked:t.forkSuggestEnabled,onChange:()=>g({forkSuggestEnabled:!t.forkSuggestEnabled})})]}),(0,n.jsx)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(190px, 1fr))",gap:12},children:(0,n.jsx)(n$,{label:"Suggest at (tokens)",hint:"Show the suggestion once input tokens reach this value.",value:t.forkSuggestTokens,min:nL.forkSuggestTokens.min,max:nL.forkSuggestTokens.max,step:1e4,disabled:i,onChange:e=>g({forkSuggestTokens:e})})}),(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:"Auto-fork long sessions"}),(0,n.jsx)("div",{style:{marginTop:5,fontSize:12,color:"var(--text-muted)",lineHeight:1.55},children:"Creates a new child session with a short summary automatically when the context crosses the threshold while idle. This is off by default; the suggestion and manual “Fork from here” remain available."})]}),(0,n.jsx)(nP,{checked:t.forkEnabled,onChange:()=>g({forkEnabled:!t.forkEnabled})})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(190px, 1fr))",gap:12},children:[(0,n.jsx)(n$,{label:"Auto-fork at (tokens)",hint:"Fork automatically once input tokens reach this value while idle.",value:t.forkAutoTokens,min:nL.forkAutoTokens.min,max:nL.forkAutoTokens.max,step:1e4,disabled:i,onChange:e=>g({forkAutoTokens:e})}),(0,n.jsx)(n$,{label:"Minimum messages",hint:"Keep auto-fork off for short sessions.",value:t.forkMinMessages,min:nL.forkMinMessages.min,max:nL.forkMinMessages.max,step:1,disabled:i,onChange:e=>g({forkMinMessages:e})})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,n.jsx)("button",{type:"button",onClick:()=>void f(),disabled:s||i||!h,style:{...nD,background:"var(--accent)",borderColor:"var(--accent)",color:"#fff",opacity:s||i||!h?.55:1,cursor:s||i||!h?"not-allowed":"pointer"},children:s?"Saving...":"Save"}),u&&!h&&(0,n.jsx)("span",{style:{fontSize:12,color:"var(--accent)"},children:"Saved. The current chat picks these up immediately."}),d&&(0,n.jsx)("span",{style:{fontSize:12,color:"#f87171"},children:d})]})]})})}function nA({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 nO(){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 nB(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"})]}):"plugins"===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:"M20.5 7.5 16.5 3.5a2.1 2.1 0 0 0-3 3l1 1-6 6-1-1a2.1 2.1 0 0 0-3 3l4 4a2.1 2.1 0 0 0 3-3l-1-1 6-6 1 1a2.1 2.1 0 0 0 3-3Z"})}):"authenticator"===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:"11",width:"18",height:"11",rx:"2",ry:"2"}),(0,n.jsx)("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"}),(0,n.jsx)("circle",{cx:"12",cy:"16",r:"1"})]}):"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"})]}):"sessions"===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)("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,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 nH({cwd:e,generativeUI:t,initialTab:r="projects",onGenerativeUIToggle:i,onClose:l,onModelsChanged:s,onProjectSelect:a,onProjectsChanged:d,onForkSettingsChanged:c}){let[u,p]=(0,o.useState)(r);(0,o.useEffect)(()=>{p(r)},[r]),(0,o.useEffect)(()=>{let e=e=>{"Escape"===e.key&&l()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[l]);let h=[{id:"projects",label:"Project",description:e?"Overview and paths":"Add or select a project",icon:nB("projects")},{id:"models",label:"Models",description:"~/.pi/agent/models.json",icon:nB("models")},{id:"authenticator",label:"Authenticator",description:"Two-factor authentication",icon:nB("authenticator")},{id:"skills",label:"Skills",description:e?"Project and global skills":"Select a project first",disabled:!e,icon:nB("skills")},{id:"plugins",label:"Plugins",description:e?"Global and project packages":"Global packages",icon:nB("plugins")},{id:"generative-ui",label:"Generative UI",description:t?"Enabled":"Disabled",icon:nB("generative-ui")},{id:"sessions",label:"Sessions",description:"Auto-fork thresholds",icon:nB("sessions")},{id:"kernels",label:"Kernels",description:e?"Project R / Python kernels":"Global R / Python kernels",icon:nB("kernels")}],x=h.find(e=>e.id===u)??h[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)(nO,{})}),(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:x.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:h.map(e=>{let t=u===e.id;return(0,n.jsxs)("button",{type:"button",disabled:e.disabled,onClick:()=>p(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"===u&&(0,n.jsx)(nS,{activeCwd:e,onSelectProject:a,onProjectsChanged:d}),"models"===u&&(0,n.jsx)(r0,{embedded:!0,onClose:()=>{s?.(),l()}}),"authenticator"===u&&(0,n.jsx)(nM,{}),"skills"===u&&e&&(0,n.jsx)(r6,{cwd:e,embedded:!0,onClose:l}),"plugins"===u&&(0,n.jsx)(nR,{cwd:e,embedded:!0}),"generative-ui"===u&&(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)(nA,{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."})]})]})]})}),"kernels"===u&&(0,n.jsx)(nl,{cwd:e}),"sessions"===u&&(0,n.jsx)(nN,{onForkSettingsChanged:c})]})]})]})})}function nF(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(0)}k`:String(e)}function nU({sessionStats:e,contextUsage:t}){let r=e?.tokens,o="var(--text-muted)",i=null;if(t?.contextWindow){let e=t.percent;null!==e&&e>90?o="#ef4444":null!==e&&e>70&&(o="rgba(234,179,8,0.95)"),i=null!==e?`${e.toFixed(0)}% / ${nF(t.contextWindow)}`:`? / ${nF(t.contextWindow)}`}let l=[];if(r&&(l.push(`in: ${r.input.toLocaleString()}`),l.push(`out: ${r.output.toLocaleString()}`),l.push(`cache read: ${r.cacheRead.toLocaleString()}`),l.push(`cache write: ${r.cacheWrite.toLocaleString()}`)),t?.contextWindow){let e=t.percent;l.push(`context: ${null!==e?e.toFixed(1)+"%":"unknown"} of ${t.contextWindow.toLocaleString()} tokens`)}return(0,n.jsxs)("div",{className:"topbar-session-stats",title:l.join(" | "),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:[r&&r.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"})]}),nF(r.input)]}),r&&r.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"})]}),nF(r.output)]}),r&&r.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"})]}),nF(r.cacheRead)]}),i&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4,color:o},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"})]}),i]})]})}function nq({editingTitle:e,selectedSession:t,titleDraft:r,titleInputRef:o,onTitleDraftChange:i,onTitleKeyDown:l,onSaveTitle:s,onStartTitleEdit:a,topBarSessionTitle:d,showChat:c,topBarProjectName:u,topBarCwd:p}){return(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:e&&t?(0,n.jsx)("input",{ref:o,value:r,onChange:e=>i(e.target.value),onKeyDown:l,onBlur:()=>void s(),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:d,style:{minWidth:0,maxWidth:"min(420px, 36vw)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:c?"var(--text)":"var(--text-muted)",fontSize:14,fontWeight:600,lineHeight:1.2},children:d}),t&&(0,n.jsx)("button",{type:"button",className:"topbar-rename-button",onClick:a,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"})]})})]})}),u&&(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:p||u,style:{minWidth:0,maxWidth:"min(280px, 24vw)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-muted)",fontSize:12,lineHeight:1.2},children:u})]})]})}function n_({selectedSession:e,autoNameStatus:t,onAutoName:r}){let o=!!(e&&e.messageCount>0),i="naming"===t.kind,l="success"===t.kind,s="error"===t.kind,a=!e||!o||i,d=i?"Naming…":l?"Title updated":s?"Title failed":"Auto title",c=e?o?s?t.message??"Title generation failed":i?"Generating a title from the conversation…":"Generate a title with the current model":"No messages yet":"No session selected";return(0,n.jsxs)("button",{type:"button",className:"topbar-auto-title-button",onClick:()=>{r()},disabled:a,title:c,"aria-label":d,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,height:28,padding:"0 9px",background:l?"rgba(34,197,94,0.10)":s?"rgba(239,68,68,0.10)":"var(--bg-panel)",border:`1px solid ${l?"rgba(34,197,94,0.45)":s?"rgba(239,68,68,0.45)":"var(--border)"}`,borderRadius:7,cursor:a?"not-allowed":"pointer",color:l?"rgba(34,197,94,0.95)":s?"#dc2626":a?"var(--text-dim)":"var(--text-muted)",fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s",opacity:a&&!i?.55:1},onMouseEnter:e=>{a||(e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{e.currentTarget.style.color=l?"rgba(34,197,94,0.95)":s?"#dc2626":"var(--text-muted)",e.currentTarget.style.background=l?"rgba(34,197,94,0.10)":s?"rgba(239,68,68,0.10)":"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:"M12 3v2"}),(0,n.jsx)("path",{d:"M12 19v2"}),(0,n.jsx)("path",{d:"M3 12h2"}),(0,n.jsx)("path",{d:"M19 12h2"}),(0,n.jsx)("path",{d:"m5.6 5.6 1.4 1.4"}),(0,n.jsx)("path",{d:"m17 17 1.4 1.4"}),(0,n.jsx)("path",{d:"m5.6 18.4 1.4-1.4"}),(0,n.jsx)("path",{d:"m17 7 1.4-1.4"})]}),(0,n.jsx)("span",{className:"topbar-auto-title-label",children:d})]})}function nJ({topBarRef:e,sidebarOpen:t,onToggleSidebar:r,showChat:o,isMobile:i,selectedSession:l,editingTitle:s,titleDraft:a,titleInputRef:d,onTitleDraftChange:c,onTitleKeyDown:u,onSaveTitle:p,onStartTitleEdit:h,topBarSessionTitle:x,topBarProjectName:g,topBarCwd:f,autoNameStatus:v,onAutoName:m,updateStatus:b,updateCommand:y,sessionStats:j,contextUsage:k,generativeUI:w,onGenerativeUIToggle:S,isDark:C,onToggleTheme:T,rightPanelOpen:z,onToggleRightPanel:I}){return(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:r,title:t?"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:t?(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.jsx)(nq,{editingTitle:s,selectedSession:l,titleDraft:a,titleInputRef:d,onTitleDraftChange:c,onTitleKeyDown:u,onSaveTitle:p,onStartTitleEdit:h,topBarSessionTitle:x,showChat:o,topBarProjectName:g,topBarCwd:f}),o&&!i&&(0,n.jsxs)("div",{className:"topbar-chat-tools",style:{display:"flex",alignItems:"center",gap:6,height:28,flexShrink:0},children:[l&&(0,n.jsx)("a",{className:"topbar-export-button",href:`/api/sessions/${encodeURIComponent(l.id)}/export`,download:!0,title:"Export session as HTML","aria-label":"Export session as HTML",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,color:"var(--text-muted)",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:7,textDecoration:"none",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-muted)",e.currentTarget.style.background="var(--bg-panel)"},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 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,n.jsx)("polyline",{points:"7 10 12 15 17 10"}),(0,n.jsx)("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})}),(0,n.jsx)(n_,{selectedSession:l,autoNameStatus:v,onAutoName:m})]}),b&&(0,n.jsx)("button",{type:"button",className:"topbar-update-button",title:b.title,onClick:()=>navigator.clipboard?.writeText(y).catch(()=>{}),style:{height:28,padding:"0 9px",borderRadius:7,border:"1px solid rgba(34,197,94,0.35)",background:"rgba(34,197,94,0.10)",color:"rgba(34,197,94,0.95)",cursor:"pointer",fontSize:11,fontWeight:650,whiteSpace:"nowrap",flexShrink:0},children:b.label}),o&&(j||k)&&(0,n.jsx)(nU,{sessionStats:j,contextUsage:k}),(0,n.jsx)("button",{type:"button",className:"topbar-icon-button topbar-generate-ui-toggle",onClick:S,title:`生成式 UI: ${w?"on":"off"}`,"aria-label":`生成式 UI: ${w?"on":"off"}`,style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:28,padding:0,background:w?"var(--bg-selected)":"var(--bg-panel)",border:`1px solid ${w?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,color:w?"var(--accent)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color=w?"var(--accent)":"var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color=w?"var(--accent)":"var(--text-muted)",e.currentTarget.style.background=w?"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();T({x:t.left+t.width/2,y:t.top+t.height/2})},title:C?"Switch to light mode":"Switch to dark mode","aria-label":C?"Switch to light mode":"Switch to dark mode","aria-pressed":C,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: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)("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:I,title:z?"Hide right panel":"Show right panel","aria-label":z?"Hide right panel":"Show right panel",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:28,padding:0,background:z?"var(--bg-selected)":"var(--bg-panel)",border:`1px solid ${z?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,color:z?"var(--accent)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color=z?"var(--accent)":"var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color=z?"var(--accent)":"var(--text-muted)",e.currentTarget.style.background=z?"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"})]})})]})}function nK({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 nV="files";function nY(e,t){return e.filter(e=>e.id!==t)}let nG=new Set(["pdf","png","jpg","jpeg","gif","webp","svg","bmp","ico","avif"]);function nX(e){let t=e.toLowerCase();return t.endsWith(".rds")||t.endsWith(".qs")}function nZ(e){return e.toLowerCase().endsWith(".h5ad")}function nQ(e){let t=(e.split(/[\\/]/).pop()??e).toLowerCase().split(".").pop()??"";return nG.has(t)}function n0(){let e=(0,i.useRouter)(),t=(0,i.useSearchParams)(),{isDark:r,toggleTheme:l}=(0,tA.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)(null),[x,g]=(0,o.useState)(0),[f,v]=(0,o.useState)(0),[m,b]=(0,o.useState)(0),[y,j]=(0,o.useState)(0),[k,w]=(0,o.useState)(!1),[S,C]=(0,o.useState)("projects"),[T,z]=(0,o.useState)({generativeUI:!0,forkEnabled:!1,forkSuggestEnabled:!0,forkSuggestTokens:18e4,forkAutoTokens:4e5,forkMinMessages:20}),[I,M]=(0,o.useState)(!0),R=nK({initialWidth:260,minWidth:180,maxWidth:500,storageKey:"--pi-sidebar-width"}),L=nK({initialWidth:500,minWidth:300,maxWidth:1200,storageKey:"--pi-right-panel-width",direction:"left"}),W=(0,o.useRef)(null),E=(0,o.useRef)(null),[P,$]=(0,o.useState)([]),[D,N]=(0,o.useState)(null),A=(0,o.useRef)(null),B=(0,o.useCallback)((e,t,r)=>{$(e),N(t),A.current=r},[]),H=(0,o.useCallback)(e=>{A.current?.(e)},[]),[K,V]=(0,o.useState)(!1),[Y,G]=(0,o.useState)(""),X=(0,o.useRef)(null),Z=(0,o.useRef)(!1),[Q,ee]=(0,o.useState)({kind:"idle"}),et=(0,o.useRef)(null),er=(0,o.useCallback)(async()=>{let e=a?.id;if(e&&"naming"!==Q.kind){et.current&&clearTimeout(et.current),ee({kind:"naming"});try{let t=await fetch(`/api/sessions/${encodeURIComponent(e)}/auto-name`,{method:"POST"}),r=await t.json().catch(()=>({}));if(!t.ok||!r.title)throw Error(r.error||`HTTP ${t.status}`);let n=r.title.trim();g(e=>e+1),d(t=>t?.id===e?{...t,name:n}:t),ee({kind:"success"}),et.current=setTimeout(()=>ee({kind:"idle"}),1800)}catch(e){ee({kind:"error",message:e instanceof Error?e.message:String(e)}),et.current=setTimeout(()=>ee({kind:"idle"}),5e3)}}},[Q.kind,a?.id]);(0,o.useEffect)(()=>{et.current&&clearTimeout(et.current),ee({kind:"idle"})},[a?.id]),(0,o.useEffect)(()=>{V(!1)},[a?.id]);let en=(0,o.useCallback)(e=>e?e.name||e.firstMessage.slice(0,80)||e.id.slice(0,12):"",[]),eo=(0,o.useCallback)(()=>{a&&(Z.current=!1,G(a.name||en(a)),V(!0),setTimeout(()=>X.current?.select(),0))},[en,a]),ei=(0,o.useCallback)(async()=>{if(Z.current){Z.current=!1,V(!1);return}if(!a)return void V(!1);let e=Y.trim(),t=en(a);if(V(!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),g(e=>e+1))}catch{}},[en,a,Y]),el=(0,o.useCallback)(e=>{"Enter"===e.key?(e.preventDefault(),ei()):"Escape"===e.key&&(Z.current=!0,V(!1))},[ei]),es=(0,o.useCallback)(async()=>{try{let e=await fetch("/api/settings");if(!e.ok)return;let t=await e.json();z(e=>({generativeUI:"boolean"==typeof t?.settings?.generativeUI?t.settings.generativeUI:e.generativeUI,forkEnabled:"boolean"==typeof t?.settings?.forkEnabled?t.settings.forkEnabled:e.forkEnabled,forkSuggestEnabled:"boolean"==typeof t?.settings?.forkSuggestEnabled?t.settings.forkSuggestEnabled:e.forkSuggestEnabled,forkSuggestTokens:"number"==typeof t?.settings?.forkSuggestTokens?t.settings.forkSuggestTokens:e.forkSuggestTokens,forkAutoTokens:"number"==typeof t?.settings?.forkAutoTokens?t.settings.forkAutoTokens:e.forkAutoTokens,forkMinMessages:"number"==typeof t?.settings?.forkMinMessages?t.settings.forkMinMessages:e.forkMinMessages}))}catch{}},[]);(0,o.useEffect)(()=>{es()},[es]);let ea=(0,o.useCallback)(()=>{let e=!T.generativeUI;z(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=>{z(t=>({...t,..."boolean"==typeof e.settings?.generativeUI?{generativeUI:e.settings.generativeUI}:{}}))}).catch(()=>z(e=>({...e,generativeUI:!e.generativeUI})))},[T.generativeUI]),[ed,ec]=(0,o.useState)(null),eu=(0,o.useCallback)(e=>{ec(e)},[]),[ep,eh]=(0,o.useState)(null),ex=(0,o.useCallback)(e=>{eh(e)},[]),[eg,ef]=(0,o.useState)(null);(0,o.useEffect)(()=>{let e=!1;return fetch("/api/version").then(e=>e.ok?e.json():null).then(t=>{!e&&t?.updateAvailable&&ef(t)}).catch(()=>{}),()=>{e=!0}},[]);let ev=eg?.updateAvailable&&eg.latest?{label:`Update ${eg.latest}`,title:`Current: v${eg.current}
21
+ Latest: v${eg.latest}
22
+ Run: ${eg.updateCommand}`}:null,{fileTabs:em,activeTabId:eb,isOpen:ey,setActiveTabId:ej,setIsOpen:ek,openFileTab:ew,closeTab:eS,openToolsTab:eC,updateViewerState:eT}=function(){let[e,t]=(0,o.useState)([]),[r,n]=(0,o.useState)(nV),[i,l]=(0,o.useState)(!1),s=(0,o.useRef)(e);s.current=e;let a=(0,o.useCallback)((e,r)=>{let o=`file:${e}`;t(t=>{var n;return n={id:o,label:r,filePath:e},t.some(e=>e.id===n.id)?t:[...t,n]}),n(o),l(!0)},[]),d=(0,o.useCallback)(e=>{if(e===nV)return;let r=s.current;t(t=>nY(t,e)),n(t=>(function(e,t,r,n=nV){if(t===n||r!==t)return r;let o=nY(e,t);return o.length>0?o[o.length-1].id:n})(r,e,t))},[]),c=(0,o.useCallback)((e,r)=>{t(t=>t.map(t=>{if(t.id!==e)return t;let n=t.viewerState;return n&&n.scrollTop===r.scrollTop&&n.previewMode===r.previewMode&&n.viewMode===r.viewMode&&n.wrapLines===r.wrapLines?t:{...t,viewerState:r}}))},[]),u=(0,o.useCallback)(()=>{n("tools"),l(!0)},[]);return{fileTabs:e,activeTabId:r,isOpen:i,setActiveTabId:n,setIsOpen:l,openFileTab:a,closeTab:d,openToolsTab:u,updateViewerState:c}}(),[ez,eI]=(0,o.useState)(null),[eM,eR]=(0,o.useState)(0),[eL,eW]=(0,o.useState)([]),eE=(0,o.useCallback)(e=>{W.current?.insertText("`"+e+"`")},[]),[eP]=(0,o.useState)(()=>t.get("session")),[e$,eD]=(0,o.useState)(null),[eN,eA]=(0,o.useState)(()=>!t.get("session")),eO=(0,o.useRef)(!1),eB=(0,o.useCallback)(t=>{eD(t),eI(null),t&&!eO.current&&(h(function(e,t=F()){if(!t||!e)return null;let r=U(e);return r?q(t)[r]??null:null}(t)),d(e=>e&&e.cwd!==t?null:e),u(e=>e&&e!==t?null:e),v(e=>e+1),b(e=>e+1),$([]),N(null),e.replace("/",{scroll:!1}))},[e]),eH=(0,o.useCallback)((e,t)=>{eB(e),t?.closeDialog!==!1&&w(!1),g(e=>e+1)},[eB]),eF=(0,o.useCallback)((t,r=!1)=>{h(null),J(t.cwd,t.id),u(null),eD(t.cwd),d(t),v(e=>e+1),eA(!0),r&&(eO.current=!0,setTimeout(()=>{eO.current=!1},0)),r||e.replace(`?session=${encodeURIComponent(t.id)}`,{scroll:!1})},[e]),eU=(0,o.useCallback)((t,r)=>{h(null),d(null),u(r),eD(r),v(e=>e+1),$([]),N(null),e.replace("/",{scroll:!1})},[e]),eq=(0,o.useCallback)(t=>{h(null),J(t.cwd,t.id),u(null),eD(t.cwd),d(t),g(e=>e+1),e.replace(`?session=${encodeURIComponent(t.id)}`,{scroll:!1}),window.dispatchEvent(new CustomEvent("session-created"))},[e]),e_=(0,o.useCallback)(()=>{g(e=>e+1),b(e=>e+1)},[]),eJ=(0,o.useCallback)(t=>{h(null),g(e=>e+1),v(e=>e+1),u(null),d(e=>{let r=e?.cwd??e$??"";return r&&J(r,t),{...e??{path:"",cwd:"",created:"",modified:"",messageCount:0,firstMessage:""},id:t}}),e.replace(`?session=${encodeURIComponent(t)}`,{scroll:!1})},[e$,e]),eY=(0,o.useCallback)(()=>{eA(!0)},[]),eX=(0,o.useCallback)(t=>{if(g(e=>e+1),a?.id===t){!function(e,t,r=F()){if(!r||!e)return;let n=U(e);if(!n)return;let o=q(r);n in o&&(t&&o[n]!==t||(delete o[n],_(r,o)))}(a.cwd,t);let r=a.cwd;d(null),u(r??null),v(e=>e+1),$([]),N(null),e.replace("/",{scroll:!1})}},[a,e]),eQ=a?.cwd??c??e$??null,[e0,e1]=(0,o.useState)(null);(0,o.useEffect)(()=>{if(null!==e0){let e=setTimeout(()=>e1(null),500);return()=>clearTimeout(e)}},[e0]);let e2=(0,o.useCallback)((e,t)=>{if(nX(e)||nX(t))return void eI({mode:"start",appType:"stexp",filePath:e,cwd:eQ,appId:null});if(nQ(e)||nQ(t)){let r=`preview:${e}`;eW(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}ew(e,t)},[eQ,ew]),e5=(0,o.useCallback)((e,t,r)=>{r&&r>0&&e1(r),e2(e,t)},[e2]),e4=(0,o.useCallback)((e,t)=>{(nZ(e)||nZ(t))&&eI({mode:"start",appType:"h5adexp",filePath:e,cwd:eQ,appId:null})},[eQ]),e8=(0,o.useCallback)(()=>{eC(),eR(e=>e+1)},[eC]),e3=(0,o.useCallback)(e=>{eI({mode:"existing",appType:e.appType,filePath:e.filePath,cwd:e.cwd,appId:e.id}),eR(e=>e+1)},[]),e6=(0,o.useCallback)(e=>{eR(e=>e+1),eI(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)},[]),e7=(0,o.useCallback)(e=>{eW(t=>t.filter(t=>t.id!==e))},[]),e9=(0,o.useCallback)(e=>{eW(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})},[]),te=c??(null===a&&e$?e$:null),tt=null!==a||null!==te,tr=eN&&!tt,tn=[{id:"files",label:"Files",closable:!1,icon:"files"},{id:"tools",label:"Status",closable:!1,icon:"tools"},...em],to=em.find(e=>e.id===eb)??null,ti=a?en(a):te?"New chat":"No session",tl=a?.cwd??te??e$??"",ts=tl?tl.replace(/\/+$/,"").split(/[\\/]/).filter(Boolean).pop()||tl:"",ta=(0,o.useCallback)((e="projects")=>{C(e),w(!0)},[]),td=(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(O,{selectedSessionId:a?.id??null,onSelectSession:eF,onNewSession:eU,initialSessionId:eP,onInitialRestoreDone:eY,restoreSessionId:p,onRestoreSessionDone:()=>h(null),refreshKey:x,onSessionDeleted:eX,selectedCwd:a?.cwd??c??e$??null,onCwdChange:eB}),(0,n.jsx)("div",{style:{padding:"8px",flexShrink:0},children:(0,n.jsx)("button",{type:"button",onClick:()=>ta("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:()=>M(!1),style:{position:"fixed",inset:0,zIndex:199,background:"rgba(0,0,0,0.4)",opacity:+!!I,pointerEvents:I?"auto":"none",transition:"opacity 0.25s ease"}}),(0,n.jsx)("div",{className:`sidebar-container${I?" sidebar-open":" sidebar-closed"}`,style:{background:"var(--bg-panel)",borderRight:"1px solid var(--border)",display:"flex",flexDirection:"column",flexShrink:0,zIndex:200,width:R.width,minWidth:R.width,transition:I||R.isResizing?"none":void 0},children:td}),I&&(0,n.jsx)(tF,{side:"right",ariaLabel:"Resize sidebar",onResizeStart:R.beginResize,onResize:R.resizeBy,onResizeEnd:R.endResize}),(0,n.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden",minWidth:0},children:[(0,n.jsx)(nJ,{topBarRef:E,sidebarOpen:I,onToggleSidebar:()=>M(e=>!e),showChat:tt,isMobile:s,selectedSession:a,editingTitle:K,titleDraft:Y,titleInputRef:X,onTitleDraftChange:G,onTitleKeyDown:el,onSaveTitle:ei,onStartTitleEdit:eo,topBarSessionTitle:ti,topBarProjectName:ts,topBarCwd:tl,autoNameStatus:Q,onAutoName:er,updateStatus:ev,updateCommand:eg?.updateCommand??"",sessionStats:ed,contextUsage:ep,generativeUI:T.generativeUI,onGenerativeUIToggle:ea,isDark:r,onToggleTheme:l,rightPanelOpen:ey,onToggleRightPanel:()=>ek(e=>!e)}),(0,n.jsx)("div",{style:{flex:1,overflow:"hidden",position:"relative"},children:tt?(0,n.jsx)(eK,{session:a,newSessionCwd:te,onAgentEnd:e_,onSessionCreated:eq,onSessionForked:eJ,modelsRefreshKey:y,chatInputRef:W,onBranchDataChange:B,onSessionStatsChange:eu,onContextUsageChange:ex,generativeUI:T.generativeUI,forkSettings:{enabled:T.forkEnabled,suggestEnabled:T.forkSuggestEnabled,suggestTokens:T.forkSuggestTokens,autoTokens:T.forkAutoTokens,minMessages:T.forkMinMessages},activeFilePath:to?.filePath??null,onOpenFileAtLine:e5},f):tr?e$?(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",{className:"empty-start-surface",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})]}),ey&&(0,n.jsx)(tF,{side:"left",ariaLabel:"Resize right panel",onResizeStart:L.beginResize,onResize:L.resizeBy,onResizeEnd:L.endResize}),(0,n.jsxs)("div",{className:`right-panel-container${ey?" right-panel-open":" right-panel-closed"}`,style:{display:ey?"flex":"none",flexDirection:"column",borderLeft:"1px solid var(--border)",background:"var(--bg)",flexShrink:0,width:L.width,minWidth:L.width,transition:L.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:()=>ek(!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)(t3,{tabs:tn,activeTabId:eb,onSelectTab:ej,onCloseTab:eS,onAskAI:e=>{let t=`I'm looking at \`${e}\`. `;W?.current?.insertIfEmpty(t)}})})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"hidden"},children:"files"===eb?(0,n.jsx)(tD,{cwd:e$??a?.cwd??c??null,refreshKey:m,onOpenFile:e2,onExploreFile:e4,onAtMention:eE,watchEnabled:ey&&"files"===eb}):"tools"===eb?(0,n.jsx)(t0,{refreshKey:eM,visibleAppId:ez?.appId??null,cwd:e$??a?.cwd??c??null,onOpenApp:e3,onAppChanged:e6,agentRuntimeExtra:(0,n.jsx)(t9,{tree:P,activeLeafId:D,onLeafChange:H,hasSession:!!a,embedded:!0})}):to?.filePath?to.filePath.startsWith("__")?(0,n.jsx)(tB,{filePath:to.filePath}):(0,n.jsx)(eG,{filePath:to.filePath,children:(0,n.jsx)(eV.h,{filePath:to.filePath,cwd:e$??void 0,onOpenFile:e2,scrollToLine:e0,viewerState:to.viewerState,onViewerStateChange:e=>eT(to.id,e)})}):(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:12},children:"No file open"})})]})]}),k&&(0,n.jsx)(nH,{cwd:eQ,generativeUI:T.generativeUI,initialTab:S,onGenerativeUIToggle:ea,onModelsChanged:()=>j(e=>e+1),onProjectSelect:eH,onProjectsChanged:()=>g(e=>e+1),onForkSettingsChanged:es,onClose:()=>{w(!1),j(e=>e+1)}}),(0,n.jsx)(tK,{appType:ez?.appType??"stexp",filePath:ez?.filePath??null,cwd:ez?.cwd??null,appId:ez?.appId??null,sessionId:a?.id??null,onClose:()=>eI(null),onAppChanged:e6,onOpenTools:e8}),eL.map((e,t)=>(0,n.jsx)(eZ,{id:e.id,filePath:e.filePath,fileName:e.fileName,cwd:e$??a?.cwd??c??void 0,active:t===eL.length-1,stackIndex:t,zIndex:700+t,onClose:e7,onFocus:e9,onOpenFile:e2},e.id))]})}}},e=>{e.O(0,[7330,2941,2995,6079,2693,2254,4936,3449,8477,5618,8441,3794,7358],()=>e(e.s=43322)),_N_E=e.O()}]);