@seqyuan/annovibe 0.8.140 → 0.8.142

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 (77) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/app-path-routes-manifest.json +10 -10
  3. package/.next/build-manifest.json +3 -3
  4. package/.next/prerender-manifest.json +3 -3
  5. package/.next/react-loadable-manifest.json +11 -11
  6. package/.next/required-server-files.js +1 -1
  7. package/.next/required-server-files.json +1 -1
  8. package/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  9. package/.next/server/app/_global-error.html +1 -1
  10. package/.next/server/app/_global-error.rsc +1 -1
  11. package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  12. package/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  13. package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  14. package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  15. package/.next/server/app/_not-found.html +1 -1
  16. package/.next/server/app/_not-found.rsc +1 -1
  17. package/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  18. package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  19. package/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  20. package/.next/server/app/api/agent/runtime/route.js +1 -1
  21. package/.next/server/app/api/internal/runtime/route.js +1 -1
  22. package/.next/server/app/api/version/route.js +1 -1
  23. package/.next/server/app/index.html +1 -1
  24. package/.next/server/app/index.rsc +5 -5
  25. package/.next/server/app/index.segments/__PAGE__.segment.rsc +5 -5
  26. package/.next/server/app/index.segments/_full.segment.rsc +5 -5
  27. package/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  28. package/.next/server/app/login/page_client-reference-manifest.js +1 -1
  29. package/.next/server/app/login.html +1 -1
  30. package/.next/server/app/login.rsc +1 -1
  31. package/.next/server/app/login.segments/_full.segment.rsc +1 -1
  32. package/.next/server/app/login.segments/_tree.segment.rsc +1 -1
  33. package/.next/server/app/login.segments/login/__PAGE__.segment.rsc +1 -1
  34. package/.next/server/app/page.js +13 -13
  35. package/.next/server/app/page_client-reference-manifest.js +1 -1
  36. package/.next/server/app/smoke/page_client-reference-manifest.js +1 -1
  37. package/.next/server/app/smoke/session-stream/page.js +1 -1
  38. package/.next/server/app/smoke/session-stream/page_client-reference-manifest.js +1 -1
  39. package/.next/server/app/smoke/session-stream.html +1 -1
  40. package/.next/server/app/smoke/session-stream.rsc +4 -4
  41. package/.next/server/app/smoke/session-stream.segments/_full.segment.rsc +4 -4
  42. package/.next/server/app/smoke/session-stream.segments/_tree.segment.rsc +1 -1
  43. package/.next/server/app/smoke/session-stream.segments/smoke/session-stream/__PAGE__.segment.rsc +4 -4
  44. package/.next/server/app/smoke.html +2 -2
  45. package/.next/server/app/smoke.rsc +2 -2
  46. package/.next/server/app/smoke.segments/_full.segment.rsc +2 -2
  47. package/.next/server/app/smoke.segments/_tree.segment.rsc +1 -1
  48. package/.next/server/app/smoke.segments/smoke/__PAGE__.segment.rsc +2 -2
  49. package/.next/server/app-paths-manifest.json +10 -10
  50. package/.next/server/chunks/1649.js +1 -0
  51. package/.next/server/chunks/658.js +22 -0
  52. package/.next/server/chunks/8305.js +2 -2
  53. package/.next/server/middleware-build-manifest.js +1 -1
  54. package/.next/server/middleware-react-loadable-manifest.js +1 -1
  55. package/.next/server/middleware.js +4 -4
  56. package/.next/server/next-font-manifest.js +1 -1
  57. package/.next/server/next-font-manifest.json +1 -1
  58. package/.next/server/pages/404.html +1 -1
  59. package/.next/server/pages/500.html +1 -1
  60. package/.next/server/preview-props.json +3 -3
  61. package/.next/server/server-reference-manifest.json +1 -1
  62. package/.next/static/chunks/2708.6503b5c105cc1420.js +1 -0
  63. package/.next/static/chunks/3824-6bb3afa7d2fc5f09.js +22 -0
  64. package/.next/static/chunks/{5618-8aecfc54df369be5.js → 5618-db41ee0c172d3add.js} +1 -1
  65. package/.next/static/chunks/app/page-2e0bf200ed41d4f6.js +22 -0
  66. package/.next/static/chunks/app/smoke/session-stream/{page-9c9a9a2aafa69000.js → page-ce422d02fbbe900d.js} +2 -2
  67. package/.next/static/chunks/c66d966b.4add33ed4e764123.js +1 -0
  68. package/.next/static/chunks/{webpack-36fa69ae1e15e7ce.js → webpack-19f3f7824a602f3b.js} +1 -1
  69. package/package.json +3 -3
  70. package/.next/server/chunks/7734.js +0 -22
  71. package/.next/server/chunks/7765.js +0 -1
  72. package/.next/static/chunks/2170a4aa.4301f7c49f3f0a6e.js +0 -1
  73. package/.next/static/chunks/2257-a948751c1a3d4608.js +0 -22
  74. package/.next/static/chunks/8436.cab94b59cca0a8ff.js +0 -1
  75. package/.next/static/chunks/app/page-b9bbcb2073e77894.js +0 -22
  76. /package/.next/static/{YRLT_dWnNGA0kvsTREpEW → ZpLecbnV0af9eeGcGwT88}/_buildManifest.js +0 -0
  77. /package/.next/static/{YRLT_dWnNGA0kvsTREpEW → ZpLecbnV0af9eeGcGwT88}/_ssgManifest.js +0 -0
@@ -1,22 +0,0 @@
1
- (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8974],{20566:(e,t,r)=>{"use strict";r.d(t,{AppShell:()=>nT});var n=r(95155),i=r(12115),o=r(73321);function l(e,t){let r=t&&e.startsWith(t)?"~"+e.slice(t.length):e,n=r.includes("/")?"/":"\\",i=r.split(n).filter(Boolean);return i.length<=2?r:"..."+n+i.slice(-2).join(n)}function a(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 s({open:e,cwd:t,homeDir:r,onClose:o,onSelectSession:d}){let[c,u]=(0,i.useState)(""),[p,h]=(0,i.useState)("current"),[x,g]=(0,i.useState)([]),[f,v]=(0,i.useState)(!1),[m,b]=(0,i.useState)(null),[y,j]=(0,i.useState)(!1),k=(0,i.useRef)(null);if((0,i.useEffect)(()=>{e&&(h(t?"current":"all"),setTimeout(()=>k.current?.focus(),0))},[e,t]),(0,i.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&o()};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,o]),(0,i.useEffect)(()=>{if(!e)return;let r=c.trim();if(r.length<2){g([]),v(!1),b(null),j(!1);return}let n=new AbortController,i=setTimeout(async()=>{v(!0),b(null);try{let e=new URLSearchParams({q:r,scope:p});t&&e.set("cwd",t);let i=await fetch(`/api/search?${e.toString()}`,{signal:n.signal});if(!i.ok)throw Error(`HTTP ${i.status}`);let o=await i.json();if(o.error)throw Error(o.error);g(o.results??[]),j(o.truncated??!1)}catch(e){"AbortError"!==e.name&&b(String(e))}finally{v(!1)}},180);return()=>{clearTimeout(i),n.abort()}},[e,c,p,t]),!e)return null;let w=c.trim(),S=x.reduce((e,t)=>e+t.matches.length,0);return(0,n.jsx)("div",{role:"dialog","aria-modal":"true","aria-label":"Search conversation history",style:{position:"fixed",inset:0,zIndex:500,display:"flex",alignItems:"flex-start",justifyContent:"center",padding:"8vh 16px 16px",background:"rgba(0,0,0,0.28)"},onMouseDown:e=>{e.target===e.currentTarget&&o()},children:(0,n.jsxs)("div",{style:{width:"min(760px, 100%)",maxHeight:"78vh",display:"flex",flexDirection:"column",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 16px 48px rgba(0,0,0,0.24)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:12,borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1,minWidth:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:8,padding:"0 10px"},children:[(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"7",cy:"7",r:"4.5"}),(0,n.jsx)("path",{d:"M10.5 10.5 13.5 13.5"})]}),(0,n.jsx)("input",{ref:k,value:c,onChange:e=>u(e.target.value),placeholder:"Search conversation history...",style:{flex:1,minWidth:0,height:38,background:"transparent",border:"none",outline:"none",color:"var(--text)",fontSize:14}})]}),(0,n.jsx)("button",{type:"button",onClick:o,title:"Close",style:{width:34,height:34,display:"inline-flex",alignItems:"center",justifyContent:"center",background:"none",border:"none",borderRadius:7,color:"var(--text-dim)",cursor:"pointer"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-dim)"},children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,n.jsx)("path",{d:"M4 4 12 12"}),(0,n.jsx)("path",{d:"M12 4 4 12"})]})})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:10},children:[(0,n.jsx)("div",{style:{display:"inline-flex",padding:2,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7},children:[{value:"current",label:"Current project",disabled:!t},{value:"all",label:"All history",disabled:!1}].map(e=>(0,n.jsx)("button",{type:"button",disabled:e.disabled,onClick:()=>h(e.value),style:{height:24,padding:"0 9px",background:p===e.value?"var(--bg-selected)":"transparent",border:"none",borderRadius:5,color:e.disabled?"var(--text-dim)":p===e.value?"var(--text)":"var(--text-muted)",cursor:e.disabled?"not-allowed":"pointer",fontSize:11,fontWeight:500},children:e.label},e.value))}),(0,n.jsx)("div",{style:{flex:1,minWidth:0,color:"var(--text-dim)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"current"===p&&t?l(t,r):"Searching every saved session"})]})]}),(0,n.jsxs)("div",{style:{flex:1,overflowY:"auto",minHeight:180},children:[w.length<2&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Type at least 2 characters to search saved conversations."}),w.length>=2&&f&&0===x.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Searching..."}),m&&(0,n.jsx)("div",{style:{padding:18,color:"#ef4444",fontSize:13},children:m}),w.length>=2&&!f&&!m&&0===x.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"No matching conversations found."}),x.map(e=>(0,n.jsxs)("div",{style:{borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{d(e.session),o()},style:{width:"100%",display:"flex",alignItems:"center",gap:10,padding:"10px 12px",background:"var(--bg-panel)",border:"none",borderBottom:"1px solid var(--border)",color:"var(--text)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13,fontWeight:600},children:e.session.name||e.session.firstMessage||"(no messages)"}),(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:11},children:a(e.session.modified)})]}),(0,n.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l(e.session.cwd,r)})]}),e.matchCount>e.matches.length&&(0,n.jsxs)("span",{style:{flexShrink:0,color:"var(--text-muted)",fontSize:11},children:[e.matchCount," matches"]})]}),e.matches.map(t=>(0,n.jsxs)("button",{type:"button",onClick:()=>{d(e.session),o()},style:{width:"100%",padding:"9px 14px 9px 28px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:3},children:[(0,n.jsx)("span",{style:{minWidth:54,color:"user"===t.role?"var(--accent)":"var(--text-dim)",fontSize:11,fontWeight:600,textTransform:"capitalize"},children:t.role}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:a(t.timestamp)})]}),(0,n.jsx)("div",{style:{fontSize:12,lineHeight:1.45,color:"var(--text-muted)"},children:function(e,t){let r=t.trim();if(!r)return e;let i=e.toLowerCase().indexOf(r.toLowerCase());return i<0?e:(0,n.jsxs)(n.Fragment,{children:[e.slice(0,i),(0,n.jsx)("mark",{style:{background:"rgba(37,99,235,0.16)",color:"var(--text)",borderRadius:3,padding:"0 2px"},children:e.slice(i,i+r.length)}),e.slice(i+r.length)]})}(t.snippet,w)})]},t.entryId))]},e.session.id))]}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",padding:"8px 12px",borderTop:"1px solid var(--border)",color:"var(--text-dim)",fontSize:11},children:[(0,n.jsx)("span",{children:S>0?`${S}${y?"+":""} results`:"Esc to close"}),f&&x.length>0&&(0,n.jsx)("span",{children:"Updating..."})]})]})})}let d="Home";function c(e){return e instanceof Error?e.message:String(e)}function u(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 p(e){return e.home.includes("\\")?"\\":"/"}function h(e,t,r){let n,i,o=-1===(n="\\"===p(e)?Math.max(t.lastIndexOf("\\"),t.lastIndexOf("/")):t.lastIndexOf("/"))?null:t.slice(0,n+1);if(null===o)return{directory:null,tail:null};let l=o===(i=p(e),e.current.endsWith(i)?e.current:`${e.current}${i}`)||null!==r&&r.directory===o&&r.landed===e.current;return{directory:o,tail:l?t.slice(o.length):null}}let x={display:"flex",flexDirection:"column",gap:2,flex:"1 1 0",minWidth:256,overflowY:"auto",paddingRight:8},g={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"},f={background:"var(--bg-selected)"},v={flex:"1 1 0",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:12.5};function m({entries:e,selectedPath:t,busy:r,onPick:i,showHidden:o,filterPrefix:l}){let a,s,d,c=(a=null===l?"":l.toLowerCase(),s=e=>(o||!e.hidden||a.startsWith("."))&&e.name.toLowerCase().startsWith(a),d=""!==a&&e.some(s),e.filter(e=>e.path===t||(d?s(e):o||!e.hidden)));return(0,n.jsx)("div",{style:x,role:"list",children:c.map(e=>{let o=e.path===t;return(0,n.jsxs)("button",{type:"button",role:"listitem","aria-current":o||void 0,disabled:r,onClick:()=>i(e),title:e.path,style:{...g,...o?f: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:o?"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:v,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 b({open:e,initialPath:t,onClose:r,onSelect:o}){let[l,a]=(0,i.useState)(null),[s,x]=(0,i.useState)(null),[g,f]=(0,i.useState)(null),[v,y]=(0,i.useState)(!1),[j,k]=(0,i.useState)(!1),[w,S]=(0,i.useState)(0),[C,T]=(0,i.useState)(null),[z,I]=(0,i.useState)(null),[R,M]=(0,i.useState)(!1),[L,W]=(0,i.useState)(null),[E,$]=(0,i.useState)(!1),[P,D]=(0,i.useState)(null),N=(0,i.useRef)(0),B=(0,i.useRef)(null),O=(0,i.useRef)(0),A=(0,i.useRef)(!1),H=(0,i.useRef)(!1),F=(0,i.useRef)(null),U=(0,i.useRef)({parent:null,child:null}),q=(0,i.useRef)(null),_=(0,i.useRef)(null);(0,i.useEffect)(()=>{U.current={parent:l,child:g}},[l,g]),(0,i.useEffect)(()=>()=>{N.current+=1,O.current+=1,B.current?.abort()},[]);let J=(0,i.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,i.useCallback)(()=>(B.current?.abort(),B.current=null,++N.current),[]),V=(0,i.useCallback)(()=>{k(!1),S(e=>e+1)},[]),Y=(0,i.useCallback)(e=>{let t=K(),r=new AbortController;return B.current=r,V(),{seq:t,scan:J(e,r.signal)}},[K,V,J]),G=(0,i.useCallback)(e=>{let t=new AbortController;return B.current=t,V(),J(e,t.signal)},[V,J]),X=(0,i.useCallback)((e,t)=>{let r=t?.closeEditor??!1,n=t?.announce??!1,{seq:i,scan:o}=Y(e);y(!0),n&&T(null);let l=()=>{(y(!1),r)?I(null):T(null)};o.then(t=>{if(i!==N.current)return;r||void 0===e||(F.current={directory:e,landed:t.current});let n=!1,o=()=>{n||i!==N.current||(n=!0,a(t),x(null),f(null),l())};if(u(t,"").length<2)return void o();let s=t.crumbs.at(-2);void 0===s?o():(G(s.path).then(e=>{if(i!==N.current)return;let r=p(e),s=e=>"\\"===r?e.toLowerCase():e,d=e.directories.find(e=>s(e.path)===s(t.current));void 0===d?o():(n=!0,a(e),x(d),f(t),l())},()=>{o()}),r&&window.setTimeout(o,200))},e=>{i===N.current&&(y(!1),n&&T(c(e)))})},[Y,G]),Z=(0,i.useCallback)(e=>{X(e,{closeEditor:!0,announce:!0})},[X]),Q=(0,i.useCallback)(e=>{let{seq:t,scan:r}=Y(e.path);null!==z&&I(null),x(e),f(null),y(!0),T(null),r.then(e=>{t===N.current&&(f(e),y(!1))},e=>{t===N.current&&(y(!1),T(c(e)),x(null))})},[Y,z]),ee=(0,i.useCallback)(e=>{null!==g&&(a(g),Q(e))},[g,Q]),et=(0,i.useCallback)(e=>{X(e,{closeEditor:!1,announce:!1})},[X]),er=(0,i.useCallback)(()=>{K(),y(!1),I(null),T(null),null===g&&x(null),null===l&&Z()},[K,g,l,Z]);(0,i.useEffect)(()=>{if(O.current+=1,e){a(null),x(null),f(null),$(!1),M(!1),Z(t??void 0);return}K(),y(!1),T(null),I(null),W(null),D(null)},[e,Z,K,t]),(0,i.useEffect)(()=>{if(!v)return void k(!1);let e=window.setTimeout(()=>{k(!0)},300);return()=>{window.clearTimeout(e)}},[v,w]),(0,i.useEffect)(()=>{if(null===z)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}=h(e,z,F.current);null!==t&&null===r&&et(t)},250);return()=>{window.clearTimeout(e)}},[z,et]),(0,i.useEffect)(()=>{if(!e)return;let t=e=>{if("Escape"===e.key){if(null!==L){E||W(null);return}if(null!==z){e.stopPropagation(),er();return}r()}};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[r,e,z,L,E,er]);let en=g??l,ei=null===en?[]:u(en,d),eo=ei.at(-1)?.path,el=g?.current,ea=s?.path??l?.current??null;(0,i.useEffect)(()=>{let e=q.current;null!==e&&(e.scrollLeft=e.scrollWidth)},[eo]),(0,i.useEffect)(()=>{let e=_.current;null!==e&&void 0!==el&&(e.scrollLeft=e.scrollWidth)},[el]);let es=(0,i.useCallback)(()=>{if(null===ea||null===L||E||""===L.trim())return;$(!0),D(null);let e=O.current;fetch("/api/projects/browse",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dir:ea,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;$(!1),W(null);let{seq:r,scan:n}=Y(ea);y(!0),T(null),n.then(e=>{r===N.current&&(a(e),y(!1),Q({name:L,path:t,hidden:L.startsWith(".")}))},e=>{r===N.current&&(y(!1),T(c(e)))})},t=>{e===O.current&&($(!1),D(c(t)))})},[ea,L,E,Y,Q]),ed={onCompositionStart:()=>{A.current=!0},onCompositionEnd:()=>{A.current=!1}};if(!e)return null;let ec=null!==s,eu=null===en||null===z?null:h(en,z,F.current).tail,ep=s?.name??(null===l?"":u(l,d).at(-1)?.name??l.current),eh=null!==L||E,ex=null!==z,eg=en?.drives??[],ef=en?p(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!==z?"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===z?(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:ei.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(),y(!1),H.current=!1,null===l)return void I("");let e=s?.path??l.current;I(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:z,autoFocus:!0,"aria-label":"Edit path",disabled:eh,spellCheck:!1,onChange:e=>{K(),y(!1),H.current=!1,I(e.target.value)},...ed,onKeyDown:e=>{"Enter"!==e.key||A.current||(e.preventDefault(),""!==z.trim()&&(H.current=!0,Z(z)))},onBlur:e=>{if(null===z||!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)(m,{entries:l.directories,selectedPath:s?.path??null,busy:eh,onPick:Q,showHidden:R,filterPrefix:null===g?eu:null}),ec&&(0,n.jsx)("span",{style:{flex:"none",width:1,background:"var(--border)"}}),ec&&null!==g&&(0,n.jsx)(m,{entries:g.directories,selectedPath:null,busy:eh,onPick:ee,showHidden:R,filterPrefix:eu})]}),v&&j&&(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||g?.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!==C&&(0,n.jsx)("div",{role:"alert",style:{padding:"4px 4px 4px 0",color:"#f87171",fontSize:11},children:C})]}),(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||v||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||v||eh||ex?"var(--text-dim)":"var(--text-muted)",cursor:null===l||v||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":R,disabled:eh,onClick:()=>M(e=>!e),style:{display:"inline-flex",alignItems:"center",gap:4,border:"none",background:"transparent",padding:0,fontSize:12,fontWeight:500,color:R?"var(--text)":"var(--text-muted)",cursor:"pointer",whiteSpace:"nowrap"},children:["Show hidden files",R&&(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===ea||v||eh||ex,onClick:()=>{null!==ea&&o(ea)},style:{height:32,padding:"0 14px",border:"none",borderRadius:6,background:null===ea||v||eh||ex?"var(--bg-hover)":"var(--accent)",color:null===ea||v||eh||ex?"var(--text-dim)":"#fff",cursor:null===ea||v||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||A.current||(e.preventDefault(),es()),"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!==P&&(0,n.jsx)("div",{role:"alert",style:{color:"#f87171",fontSize:11},children:P}),(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:es,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 y="AnnoVibe";var j=r(16865);let k="annovibe:sidebar:collapsed-projects",w="annovibe:sidebar:collapsed-projects:init-v3";function S(e){window.localStorage.setItem(k,JSON.stringify([...e]))}async function C(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 T(e){return new DOMException(e,"TimeoutError")}function z(e,t){return e instanceof DOMException&&("AbortError"===e.name||"TimeoutError"===e.name)||e instanceof Error&&/aborted without reason|AbortError/i.test(e.message)?t:e instanceof Error?e.message:String(e)}function I(e){let t=new Date(e),r=new Date().getTime()-t.getTime(),n=Math.floor(r/6e4),i=Math.floor(r/36e5),o=Math.floor(r/864e5);return n<1?"just now":n<60?`${n}m ago`:i<24?`${i}h ago`:o<7?`${o}d ago`:t.toLocaleDateString()}function R(e,t){let r=t&&e.startsWith(t)?"~"+e.slice(t.length):e,n=r.includes("/")?"/":"\\",i=r.split(n).filter(Boolean);return i.length<=2?r:"…/"+i.slice(-2).join(n)}function M(e,t){if(!e)return"No Project";let r=e.replace(/[\\/]+$/,""),n=r.includes("/")?"/":"\\";return r.split(n).filter(Boolean).pop()||R(e,t)}function L(e){return e+.2*e*(2*Math.random()-1)}let W="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";function E(){let[e,t]=(0,i.useState)(!1),[r,o]=(0,i.useState)(!1),l=(0,i.useRef)(null),a=function(e,t){let[r,n]=(0,i.useState)(e),o=(0,i.useRef)(null),l=(0,i.useRef)(0);return(0,i.useEffect)(()=>{if(!t)return void n(e);l.current=0;let r=4*e.length,i=()=>{l.current+=1;let t=Math.floor(l.current/r*e.length);n(e.split("").map((e,r)=>" "===e?" ":r<t?e:W[Math.floor(Math.random()*W.length)]).join("")),l.current<r?o.current=requestAnimationFrame(i):n(e)};return o.current=requestAnimationFrame(i),()=>{o.current&&cancelAnimationFrame(o.current)}},[e,t]),r}(e?"v0.8.140":y,r),s=(0,i.useCallback)(e=>{t(e),o(!0),setTimeout(()=>o(!1),(e?6:8)*4*(1e3/60)+100)},[]),d=(0,i.useCallback)(()=>{l.current&&clearTimeout(l.current);let t=!e;s(t),t&&(l.current=setTimeout(()=>s(!1),3e3))},[e,s]);return(0,i.useEffect)(()=>()=>{l.current&&clearTimeout(l.current)},[]),(0,n.jsx)("button",{onClick:d,style:{background:"none",border:"none",padding:0,cursor:"default",fontWeight:700,fontSize:15,letterSpacing:"-0.01em",color:e?"var(--accent)":"var(--text)",fontFamily:"var(--font-mono)",minWidth:"9ch"},children:a})}function $({selectedSessionId:e,onSelectSession:t,onNewSession:r,initialSessionId:o,onInitialRestoreDone:l,restoreSessionId:a,onRestoreSessionDone:d,refreshKey:c,onSessionDeleted:u,selectedCwd:p,onCwdChange:h}){let[x,g]=(0,i.useState)([]),[f,v]=(0,i.useState)({}),[m,y]=(0,i.useState)(()=>new Set),I=(0,i.useRef)(!1),[W,O]=(0,i.useState)(!0),[A,H]=(0,i.useState)(!1),[F,U]=(0,i.useState)(null),[q,_]=(0,i.useState)(null),[J,K]=(0,i.useState)(""),[V,Y]=(0,i.useState)(null),[G,X]=(0,i.useState)(!1),[Z,Q]=(0,i.useState)("project"),[ee,et]=(0,i.useState)(!1),[er,en]=(0,i.useState)(()=>new Set),[ei,eo]=(0,i.useState)(()=>(function(){try{let e=window.localStorage.getItem(k)??window.localStorage.getItem("pidex:sidebar:collapsed-projects");return e?new Set(JSON.parse(e)):new Set}catch{return new Set}})()),[el,ea]=(0,i.useState)(null),[es,ed]=(0,i.useState)(null),[ec,eu]=(0,i.useState)(null),[ep,eh]=(0,i.useState)(!1),ex=(0,i.useRef)(null),eg=(0,i.useRef)(!1),ef=(0,i.useRef)(!1),ev=(0,i.useRef)(!1),em=(0,i.useRef)(new Map),eb=(0,i.useRef)({revision:null,seq:0,retry:0,inFlight:!1}),ey=(0,i.useRef)({}),ej=(0,i.useRef)({}),ek=(0,i.useRef)({}),ew=(0,i.useRef)(new Set);function eS(e){let t=ey.current[e];return t||(t={revision:null,seq:0,retry:0,inFlight:!1},ey.current[e]=t),t}let eC=(0,i.useCallback)((e,t,r)=>{let n=ej.current[e];n&&clearTimeout(n),ej.current[e]=setTimeout(()=>{ej.current[e]=null,r()},Math.random()*([250,500,1e3,2e3][Math.min(Math.max(t,0),3)]??2e3))},[]),eT=(0,i.useCallback)((e,t)=>{let r=ek.current[e];r&&clearTimeout(r),ek.current[e]=setTimeout(()=>{ek.current[e]=null,t()},120)},[]),ez=(0,i.useCallback)(async(e=!1,t={})=>{let r=eb.current,n=++r.seq;r.inFlight=!0;try{let i;e&&O(!0);let o=new AbortController;try{i=setTimeout(()=>o.abort(T("Project loading timed out")),6e4);let e=t.force?"/api/projects?force=1":"/api/projects",l=await fetch(e,{signal:o.signal});if(!l.ok)throw Error(await C("projects",l));let a=await l.json();if(n!==r.seq)return;if(a.stale)return void eC("projects",r.retry++,()=>void ez(!1));r.retry=0,a.revision&&(r.revision=a.revision),g(a.projects),U(null)}finally{clearTimeout(i)}}catch(t){if(n!==r.seq)return;let e=z(t,"Loading projects timed out. Codex may still be starting; click Refresh to retry.");U(e),eC("projects",r.retry++,()=>void ez(!1))}finally{n===r.seq&&(r.inFlight=!1),e&&O(!1)}},[eC]),eI=(0,i.useCallback)(async(e,t=!1,r={})=>{if(!e)return;let n=em.current.get(e);if(n)return n;let i=(async()=>{let n=eS(e),i=++n.seq;n.inFlight=!0,v(t=>({...t,[e]:{sessions:t[e]?.sessions??[],loaded:t[e]?.loaded??!1,error:null,loading:!0,stale:t[e]?.stale??!1}}));try{let o;t&&O(!0);let l=new AbortController;try{o=setTimeout(()=>l.abort(T("Chat loading timed out")),6e4);let t=r.force?`/api/sessions?cwd=${encodeURIComponent(e)}&force=1`:`/api/sessions?cwd=${encodeURIComponent(e)}`,a=await fetch(t,{signal:l.signal});if(!a.ok)throw Error(await C("sessions",a));let s=await a.json();if(i!==n.seq)return;if(s.runningSessionIds&&!I.current&&y(new Set(s.runningSessionIds)),s.stale){v(t=>({...t,[e]:{sessions:t[e]?.sessions??[],loaded:t[e]?.loaded??!1,loading:!1,error:null,stale:(t[e]?.sessions?.length??0)>0}})),eC(`cwd:${e}`,n.retry++,()=>void eI(e,!1));return}n.retry=0,s.revision&&(n.revision=s.revision),ew.current.add(e),v(t=>({...t,[e]:{sessions:s.sessions,loaded:!0,loading:!1,error:null,stale:!1}}))}finally{clearTimeout(o)}}catch(r){if(i!==n.seq)return;let t=z(r,"Loading chats timed out. Codex may still be starting; click Refresh to retry.");v(r=>({...r,[e]:{sessions:r[e]?.sessions??[],loaded:r[e]?.loaded??!1,loading:!1,error:t,stale:(r[e]?.sessions?.length??0)>0}})),eC(`cwd:${e}`,n.retry++,()=>void eI(e,!1))}finally{i===n.seq&&(n.inFlight=!1),t&&O(!1),em.current.delete(e)}})();return em.current.set(e,i),i},[eC]),eR=(0,i.useCallback)(async()=>{let e=eb.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 C("projects",r));let n=await r.json();if(n.stale)return void eC("projects",e.retry++,()=>void eR());if(!0===n.unchanged)return;ez(!1)}catch{eC("projects",e.retry++,()=>void eR())}},[ez,eC]),eM=(0,i.useCallback)(async e=>{let t=eS(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 C("sessions",n));let i=await n.json();if(i.stale)return void eC(`cwd:${e}`,t.retry++,()=>void eM(e));if(!0===i.unchanged)return;eI(e,!1)}catch{eC(`cwd:${e}`,t.retry++,()=>void eM(e))}},[eI,eC]),eL=(0,i.useRef)(!1);(0,i.useEffect)(()=>{let e=!eL.current;eL.current=!0,ez(e)},[ez,c]),(0,i.useEffect)(()=>{fetch("/api/home").then(e=>e.json()).then(e=>{e.home&&K(e.home)}).catch(()=>{})},[]);let eW=(0,i.useRef)(!1);(0,i.useEffect)(()=>{if(eg.current){eg.current=!1;return}if(ef.current){ef.current=!1;return}h?.(q)},[q,h]);let eE=(0,i.useCallback)(async(e,t=!1)=>{try{let r=await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,create:t})}),n=await r.json();if(!r.ok||n.error)return Y(n.error??`HTTP ${r.status}`),null;return ez(!1),n.project?.cwd??e}catch(e){return Y(e instanceof Error?e.message:String(e)),null}},[ez]),e$=(0,i.useCallback)(e=>{fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,touch:!0})}).catch(()=>{})},[]),eP=(0,i.useCallback)(e=>{ef.current=!0,_(e),Y(null),eo(t=>{if(!t.has(e))return t;let r=new Set(t);return r.delete(e),S(r),r}),h?.(e),e$(e),eI(e,!1)},[eI,h,e$]);(0,i.useEffect)(()=>{if(0!==x.length&&null===q){if(o&&!eW.current){eW.current=!0;let e=Object.values(f).flatMap(e=>e.sessions).find(e=>e.id===o);if(e){_(e.cwd),e$(e.cwd),t(e,!0);return}fetch(`/api/sessions/${encodeURIComponent(o)}?infoOnly=1`).then(e=>e.ok?e.json():null).then(e=>{e?.info?(_(e.info.cwd),e$(e.info.cwd),t(e.info,!0)):l?.()}).catch(()=>l?.());return}let e=x[0]?.cwd;e&&(_(e),e$(e))}},[x,q,o,t,l,f,e$]);let eD=(0,i.useRef)(null);(0,i.useEffect)(()=>{if(!a)return;let e=p??q;if(!e)return;let r=`${e}\0${a}`;if(eD.current===r)return;let n=f[e],i=Object.values(f).flatMap(e=>e.sessions).find(e=>e.id===a);if(!i){!n?.loaded||n.loading||n.stale||(eD.current=r,d?.());return}eD.current=r,i.cwd!==e||(_(i.cwd),e$(i.cwd),t(i,!1)),d?.()},[a,p,q,f,t,d,e$]);let eN=p??q;(0,i.useEffect)(()=>(0,j.O)(e=>{I.current=!0,y(new Set(e))}),[]);let eB=(0,i.useRef)(null);(0,i.useEffect)(()=>{eB.current=eN},[eN]),(0,i.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)&&eT("projects",()=>void eR()),"cwd"===t.scope&&t.cwd){let e=t.cwd;eT(`cwd:${e}`,()=>void eM(e))}if("all-cwds"===t.scope)for(let e of ew.current)eT(`cwd:${e}`,()=>void eM(e))}},e.onerror=()=>{},()=>e.close()},[eR,eM,eT]),(0,i.useEffect)(()=>{let e=window.setInterval(()=>{eR()},L(3e4));return()=>window.clearInterval(e)},[eR]),(0,i.useEffect)(()=>{let e=window.setInterval(()=>{let e=new Set;for(let t of(eB.current&&e.add(eB.current),ew.current))e.add(t);for(let t of e)eM(t)},L(1e4));return()=>window.clearInterval(e)},[eM]),(0,i.useEffect)(()=>{let e=()=>{if("visible"!==document.visibilityState)return;eR();let e=new Set;for(let t of(eB.current&&e.add(eB.current),ew.current))e.add(t);for(let t of e)eM(t)};return document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)},[eR,eM]),(0,i.useEffect)(()=>{let e=()=>{eN&&eI(eN,!1)};return window.addEventListener("session-created",e),()=>window.removeEventListener("session-created",e)},[eN,eI]);let eO=(0,i.useCallback)(e=>{if(!e){Q("agent"),X(!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]),eA=(0,i.useCallback)(async e=>{let t=await eE(e,!0);t&&(eP(t),X(!1),Y(null),"agent"===Z&&eO(t))},[eP,eO,Z,eE]),eH=(0,i.useCallback)(()=>{eO(eN)},[eO,eN]),eF=(0,i.useCallback)(()=>{Q("project"),Y(null),X(!0)},[]),eU=(0,i.useMemo)(()=>[...eN&&!x.some(e=>e.cwd===eN)?[{cwd:eN,displayName:M(eN,J),chatCount:f[eN]?.sessions.length??0,lastAccessed:null,created:null,pinned:!1,sortOrder:null,exists:!0,source:"manual"}]:[],...x].sort((e,t)=>{let r=!0===e.pinned;if(r!==(!0===t.pinned))return r?-1:1;let n="number"==typeof e.sortOrder?e.sortOrder:Number.MAX_SAFE_INTEGER,i="number"==typeof t.sortOrder?t.sortOrder:Number.MAX_SAFE_INTEGER;return n!==i?n-i:(e.displayName||"").localeCompare(t.displayName||"",void 0,{numeric:!0,sensitivity:"base"})}),[eN,J,x,f]),eq=(0,i.useMemo)(()=>{let e=e=>{var t,r;let n,i,o=f[e.cwd],l=[...o?.sessions??[]].sort((e,t)=>(t.modified||"").localeCompare(e.modified||"")),a=o?.loaded?o.sessions.length:e.chatCount,s=(t=e.lastAccessed,r=o?.loaded?o.sessions[0]?.modified:null,n=t?new Date(t).getTime():-1/0,i=r?new Date(r).getTime():-1/0,Number.isFinite(n)||Number.isFinite(i)?n>=i?t??null:r??null:null);return{project:e,cwd:e.cwd,displayName:e.displayName||M(e.cwd,J),sessions:l,sessionsState:o,chatCount:a??0,lastAccessed:s??""}},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,J,f,eU]);(0,i.useEffect)(()=>{if(0===eq.length||ev.current||(ev.current=!0,!eq[0]?.cwd||window.localStorage.getItem(w)))return;let e=new Set(eq.slice(1).map(e=>e.cwd));eo(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)?(S(e),e):t),window.localStorage.setItem(w,"1")},[eq]);let e_=(0,i.useCallback)((e,r=!1)=>{e.cwd!==eN&&(eg.current=!0,_(e.cwd)),eo(t=>{if(!t.has(e.cwd))return t;let r=new Set(t);return r.delete(e.cwd),S(r),r}),e$(e.cwd),t(e,r)},[t,eN,e$]),eJ=(0,i.useCallback)(e=>{eo(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),S(r),r})},[]);(0,i.useEffect)(()=>{for(let e of eq){let t=f[e.cwd];if(!t?.loaded&&!t?.loading){let t=e.cwd===eN,r=ei.has(e.cwd);if(!t&&r)continue;eI(e.cwd,!1)}}},[ei,eN,eI,eq,f]);let eK=(0,i.useCallback)(e=>{en(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),eV=(0,i.useCallback)(async e=>{eu("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}`);U(null),ez(!1)}catch(e){U(e instanceof Error?e.message:String(e)),ez(!1)}finally{eu(null)}},[ez]),eY=(0,i.useCallback)(async(e,t)=>{eu(`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}`);U(null),ez(!1)}catch(e){U(e instanceof Error?e.message:String(e)),ez(!1)}finally{eu(null)}},[ez]),eG=(0,i.useCallback)((e,t)=>{if(!e||!t||e===t)return;let r=eU.map(e=>e.cwd).filter(Boolean),n=r.indexOf(e),i=r.indexOf(t);if(-1===n||-1===i)return;let o=[...r];o.splice(n,1);let l=o.indexOf(t);o.splice(l,0,e),eV(o)},[eV,eU]),eX=(0,i.useCallback)(async()=>{H(!0);try{await ez(!1,{force:!0});let e=new Set([...Object.entries(f).filter(([,e])=>e.loaded||e.loading).map(([e])=>e),...eN?[eN]:[]]);await Promise.all([...e].map(e=>eI(e,!1,{force:!0})))}finally{H(!1)}},[eN,ez,eI,f]);return(0,i.useEffect)(()=>{if(!ep)return;let e=e=>{ex.current&&!ex.current.contains(e.target)&&eh(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[ep]),(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)(E,{}),(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:()=>et(!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)(s,{open:ee,cwd:eN,homeDir:J,onClose:()=>et(!1),onSelectSession:e=>{e_(e)}}),(0,n.jsxs)("div",{ref:ex,style:{position:"relative",marginTop:8,padding:"0 10px",display:"flex",alignItems:"stretch",gap:4},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>eh(e=>!e),style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:6,padding:"6px 10px",background:eN?"var(--bg-hover)":"rgba(37,99,235,0.06)",border:eN?"1px solid var(--border)":"1px solid rgba(37,99,235,0.4)",borderRadius:7,cursor:"pointer",fontSize:12,color:"var(--text)",textAlign:"left"},title:eN??"Select project",children:[(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.35",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:"var(--accent)"},children:(0,n.jsx)("path",{d:"M1.5 5A1.5 1.5 0 0 1 3 3.5h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6.5L13.6 11A1.5 1.5 0 0 1 12.1 12.5H3A1.5 1.5 0 0 1 1.5 11V5Z"})}),(0,n.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)",fontSize:11,color:eN?"var(--text)":"var(--text-dim)"},children:eN?eU.find(e=>e.cwd===eN)?.displayName??R(eN,J):"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:ep?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),eN&&(0,n.jsx)(P,{pinned:eU.find(e=>e.cwd===eN)?.pinned===!0,onToggle:()=>void eY(eN,eU.find(e=>e.cwd===eN)?.pinned!==!0)}),ep&&(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===eU.length&&(0,n.jsx)("div",{style:{padding:"10px 12px",color:"var(--text-dim)",fontSize:11},children:"No projects yet"}),eU.map(e=>{let t=e.cwd===eN;return(0,n.jsx)(D,{project:e,homeDir:J,isCurrent:t,onSelect:()=>{eP(e.cwd),eh(!1)},onTogglePinned:()=>void eY(e.cwd,!0!==e.pinned)},e.cwd)})]})]}),(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:A,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:A?"var(--accent)":"var(--text-dim)",cursor:A?"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:A?"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"})]})})]})]}),V&&(0,n.jsx)("div",{style:{marginTop:6,color:"#f87171",fontSize:11,lineHeight:1.4,overflowWrap:"anywhere"},children:V})]}),(0,n.jsxs)("div",{style:{flex:"1 1 auto",overflowY:"auto",padding:"6px 8px 8px",minHeight:80,scrollbarWidth:"thin",overscrollBehavior:"contain"},children:[W&&0===x.length&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Loading…"}),F&&(0,n.jsx)("div",{style:{padding:"12px 14px",color:"#f87171",fontSize:12},children:F}),!W&&!F&&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."}),!W&&!F&&eq.map(t=>{let r,i=ei.has(t.cwd),o=t.cwd===eN,l=er.has(t.cwd),a=function(e){let t=new Map;for(let r of e)t.set(r.id,{session:r,children:[]});let r=new Map;for(let t of e)t.parentSessionId&&r.set(t.id,t.parentSessionId);let n=[];for(let e of t.values()){let i=function(e){let n=r.get(e),i=new Set;for(;n&&!i.has(n);){if(i.add(n),t.has(n))return n;n=r.get(n)}return null}(e.session.id);i?t.get(i).children.push(e):n.push(e)}let i=e=>{e.sort((e,t)=>(t.session.modified||"").localeCompare(e.session.modified||"")),e.forEach(e=>i(e.children))};return i(n),n}(t.sessions),s=a.length,d=a;if(s>10&&!l){d=a.slice(0,10);let t=a.find(t=>(function e(t,r){return!!r&&(t.session.id===r||t.children.some(t=>e(t,r)))})(t,e));t&&!d.includes(t)&&(d=[...d,t])}let c=s-d.length;return(0,n.jsxs)("div",{style:{marginBottom:6,borderTop:es===t.cwd?"2px solid var(--accent)":"2px solid transparent",paddingTop:2*(es===t.cwd),opacity:el===t.cwd?.55:1},onDragOver:e=>{el&&el!==t.cwd&&(e.preventDefault(),e.dataTransfer.dropEffect="move",ed(t.cwd))},onDragLeave:()=>{es===t.cwd&&ed(null)},onDrop:e=>{e.preventDefault();let r=e.dataTransfer.getData("text/project-cwd")||el;ed(null),ea(null),r&&eG(r,t.cwd)},children:[(0,n.jsx)(N,{group:t,isCurrent:o,isCollapsed:i,isDragging:el===t.cwd,pinBusy:ec===`pin:${t.cwd}`,onToggle:()=>eJ(t.cwd),onSelect:()=>eP(t.cwd),onTogglePinned:()=>void eY(t.cwd,!0!==t.project.pinned),onDragStart:e=>{ea(t.cwd),e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/project-cwd",t.cwd)},onDragEnd:()=>{ea(null),ed(null)}}),!i&&(0,n.jsxs)("div",{style:{marginTop:2,overflow:"hidden",borderRadius:7},children:[(r=t.sessionsState,r?.loading&&!r?.loaded?(0,n.jsx)("div",{style:{width:"100%",padding:"10px 12px",color:"var(--text-dim)",textAlign:"left",fontSize:12,fontStyle:"italic"},children:"Loading chats…"}):r?.error&&!r?.stale?(0,n.jsx)("div",{style:{width:"100%",padding:"10px 12px",color:"#f87171",textAlign:"left",fontSize:12},children:r.error}):0===t.sessions.length?(0,n.jsx)("div",{style:{width:"100%",padding:"10px 12px",color:"var(--text-muted)",textAlign:"left",fontSize:12},children:"No sessions yet. Use New Chat above to start one."}):(0,n.jsxs)(n.Fragment,{children:[r?.stale&&(0,n.jsx)("div",{style:{width:"100%",padding:"4px 12px",color:"var(--text-dim)",textAlign:"left",fontSize:10,fontStyle:"italic"},children:"Showing cached data — refresh failed"}),d.map(r=>(0,n.jsx)(B,{node:r,selectedSessionId:e,onSelectSession:e_,onRenamed:()=>void eI(t.cwd,!1),onSessionDeleted:e=>{u?.(e),eI(t.cwd,!1)},depth:0,runningSessionIds:m},r.session.id))]})),(l||c>0)&&s>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,c)} more`})]})]},t.cwd||"__no_project")})]}),(0,n.jsx)(b,{open:G,initialPath:eN,onClose:()=>X(!1),onSelect:e=>eA(e)})]})}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 D({project:e,homeDir:t,isCurrent:r,onSelect:o,onTogglePinned:l}){let[a,s]=(0,i.useState)(!1),d=e.displayName||M(e.cwd,t);return(0,n.jsxs)("div",{onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),style:{display:"flex",alignItems:"center",gap:4,background:r?"var(--bg-selected)":a?"var(--bg-hover)":"none",borderBottom:"1px solid var(--border)"},children:[(0,n.jsx)("span",{style:{width:10,marginLeft:6,flexShrink:0}}),(0,n.jsxs)("button",{type:"button",onClick:o,title:e.cwd,style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:7,padding:"8px 10px 8px 0",background:"none",border:"none",color:r?"var(--text)":"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11,fontFamily:"var(--font-mono)"},children:[r?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d}),!e.exists&&(0,n.jsx)("span",{style:{flexShrink:0,color:"#f87171",fontSize:10},children:"missing"})]}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),l()},title:"Pin to sidebar",tabIndex:a?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:+!!a,pointerEvents:a?"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 N({group:e,isCurrent:t,isCollapsed:r,isDragging:o,pinBusy:l,onToggle:a,onSelect:s,onTogglePinned:d,onDragStart:c,onDragEnd:u}){let[p,h]=(0,i.useState)(!1),x=e.lastAccessed,g=Math.max(0,e.chatCount??0),f=!0===e.project.pinned,v=(0,i.useCallback)(()=>{t?a():s()},[t,s,a]);return(0,n.jsxs)("div",{role:"button",tabIndex:0,draggable:!0,onClick:v,onDragStart:c,onDragEnd:u,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),v())},onMouseEnter:()=>h(!0),onMouseLeave:()=>h(!1),title:e.cwd,style:{width:"100%",height:32,display:"flex",alignItems:"center",gap:5,padding:"0 8px",background:t?"var(--bg-selected)":p?"var(--bg-hover)":"transparent",border:"none",borderRadius:6,color:"var(--text)",cursor:o?"grabbing":"pointer",textAlign:"left",overflow:"hidden",transition:"background 0.12s, opacity 0.12s",opacity:o?.55:1},children:[(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:r?"none":"rotate(90deg)",transition:"transform 0.15s",flexShrink:0,color:"var(--text-dim)"},children:(0,n.jsx)("polyline",{points:"3 2 7 5 3 8"})}),(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.35",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:t?"var(--accent)":"var(--text-dim)"},children:r?(0,n.jsx)("path",{d:"M1.5 4.5A1.5 1.5 0 0 1 3 3h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6v5A1.5 1.5 0 0 1 13 12.5H3A1.5 1.5 0 0 1 1.5 11V4.5Z"}):(0,n.jsx)("path",{d:"M1.5 5A1.5 1.5 0 0 1 3 3.5h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6.5L13.6 11A1.5 1.5 0 0 1 12.1 12.5H3A1.5 1.5 0 0 1 1.5 11V5Z"})}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13,fontWeight:t?650:560,color:"var(--text)"},children:e.displayName}),!e.project.exists&&(0,n.jsx)("span",{style:{flexShrink:0,color:"#f87171",fontSize:10},children:"missing"}),!p&&g>0&&(0,n.jsxs)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:[g," ",1===g?"chat":"chats"]}),!p&&x&&(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:I(x)}),f?(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),d()},title:"Unpin project",tabIndex:p?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,border:"none",borderRadius:5,background:"rgba(234,179,8,0.12)",color:"#ca8a04",cursor:"pointer",flexShrink:0,opacity:p?1:.85,transition:"opacity 0.12s"},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"currentColor",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})}):(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),d()},disabled:l,title:"Pin project to sidebar",tabIndex:p?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,border:"none",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:l?"wait":"pointer",flexShrink:0,opacity:+!!p,transition:"opacity 0.12s, background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="#ca8a04"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})}),(0,n.jsx)("span",{title:"Drag to reorder",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:18,height:22,flexShrink:0,color:"var(--text-dim)",opacity:p?1:.35,transition:"opacity 0.12s",cursor:"grab"},children:(0,n.jsxs)("svg",{width:"10",height:"12",viewBox:"0 0 10 12",fill:"currentColor",children:[(0,n.jsx)("circle",{cx:"2",cy:"2",r:"1"}),(0,n.jsx)("circle",{cx:"8",cy:"2",r:"1"}),(0,n.jsx)("circle",{cx:"2",cy:"6",r:"1"}),(0,n.jsx)("circle",{cx:"8",cy:"6",r:"1"}),(0,n.jsx)("circle",{cx:"2",cy:"10",r:"1"}),(0,n.jsx)("circle",{cx:"8",cy:"10",r:"1"})]})})]})}function B({node:e,selectedSessionId:t,onSelectSession:r,onRenamed:o,onSessionDeleted:l,depth:a,runningSessionIds:s}){let[d,c]=(0,i.useState)(!1),u=e.children.length>0;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{position:"relative"},children:[a>0&&(0,n.jsx)("div",{style:{position:"absolute",left:12*a+6,top:0,bottom:0,width:1,background:"var(--border)",pointerEvents:"none"}}),(0,n.jsx)(O,{session:e.session,isSelected:e.session.id===t,onClick:()=>r(e.session),onRenamed:o,onDeleted:e=>l?.(e),depth:a,hasChildren:u,collapsed:d,onToggleCollapse:()=>c(e=>!e),isRunning:s.has(e.session.id)})]}),u&&!d&&(0,n.jsx)("div",{children:e.children.map(e=>(0,n.jsx)(B,{node:e,selectedSessionId:t,onSelectSession:r,onRenamed:o,onSessionDeleted:l,depth:a+1,runningSessionIds:s},e.session.id))})]})}function O({session:e,isSelected:t,onClick:r,onRenamed:o,onDeleted:l,depth:a=0,hasChildren:s=!1,collapsed:d=!1,onToggleCollapse:c,isRunning:u=!1}){let[p,h]=(0,i.useState)(!1),[x,g]=(0,i.useState)(!1),[f,v]=(0,i.useState)(""),[m,b]=(0,i.useState)(!1),[y,j]=(0,i.useState)(!1),k=(0,i.useRef)(null),w=e.name||e.firstMessage.slice(0,50)||e.id.slice(0,12),S=(0,i.useCallback)(t=>{t.stopPropagation(),v(e.name??""),g(!0),setTimeout(()=>k.current?.select(),0)},[e.name]),C=(0,i.useCallback)(async()=>{let t=f.trim();if(g(!1),t!==(e.name??""))try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t})}),o?.()}catch{}},[f,e.id,e.name,o]),T=(0,i.useCallback)(e=>{e.stopPropagation(),b(!0)},[]),z=(0,i.useCallback)(async t=>{t.stopPropagation(),b(!1),j(!0);try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"DELETE"}),l?.(e.id)}catch{j(!1)}},[e.id,l]),R=(0,i.useCallback)(e=>{e.stopPropagation(),b(!1)},[]);return(0,n.jsx)("div",{onClick:m||x?void 0:r,onMouseEnter:()=>h(!0),onMouseLeave:()=>{h(!1)},style:{display:"flex",alignItems:"center",padding:"7px 8px",paddingLeft:a>0?12*a+14:14,paddingRight:8,cursor:m||x?"default":"pointer",background:m?"rgba(239,68,68,0.06)":t?"var(--bg-selected)":p?"var(--bg-hover)":"transparent",borderLeft:m?"2px solid #ef4444":t?"2px solid var(--accent)":"2px solid transparent",transition:"background 0.1s",opacity:y?.5:1,gap:6,overflow:"hidden"},children:m?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0,fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["Delete ",(0,n.jsxs)("span",{style:{fontWeight:600},children:["“",w.slice(0,22),w.length>22?"…":"","”"]}),"?"]}),(0,n.jsxs)("div",{style:{display:"flex",gap:5,flexShrink:0},children:[(0,n.jsxs)("button",{onClick:z,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"})]})]}):x?(0,n.jsx)("input",{ref:k,value:f,onChange:e=>v(e.target.value),onBlur:C,onKeyDown:e=>{"Enter"===e.key&&C(),"Escape"===e.key&&g(!1)},autoFocus:!0,style:{flex:1,fontSize:12,padding:"5px 8px",border:"1px solid var(--accent)",borderRadius:5,outline:"none",background:"var(--bg)",color:"var(--text)",height:28}}):(0,n.jsxs)(n.Fragment,{children:[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:u?7:5,height:u?7:5,borderRadius:"50%",background:u?"#22c55e":t?"var(--accent)":"var(--text-dim)",opacity:t?1:.35,flexShrink:0,...u?{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:w,children:w}),(0,n.jsxs)("div",{style:{display:"flex",gap:8,color:"var(--text-dim)",fontSize:11},children:[(0,n.jsx)("span",{title:e.modified,children:I(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"})]})]}),s&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),c?.()},title:d?"Expand forks":"Collapse forks",style:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,flexShrink:0,background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",transform:d?"rotate(-90deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})}),p&&(0,n.jsxs)("div",{style:{display:"flex",gap:4,flexShrink:0},children:[(0,n.jsx)("button",{onClick:S,title:"Rename",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-selected)",e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"})})}),(0,n.jsx)("button",{onClick:T,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"})]})})]})]})})}let A="annovibe:last-open-by-workspace";function H(){try{return window.localStorage}catch{return null}}function F(e){let t=e.trim();if(!t)return"";let r=t.replace(/\\/g,"/");return r.length>1?r.replace(/\/+$/,""):r}function U(e){try{let t=e.getItem(A);if(!t)return{};let r=JSON.parse(t);return r&&"object"==typeof r&&!Array.isArray(r)?r:{}}catch{return{}}}function q(e,t){try{e.setItem(A,JSON.stringify(t))}catch{}}function _(e,t,r=H()){if(!r||!e||!t)return;let n=F(e);if(!n)return;let i=U(r);i[n]!==t&&(i[n]=t,q(r,i))}var J=r(99867),K=r(14755);let V=new Map,Y=new Map;function G(e){e&&Y.delete(e)}let X=["off","default","full","agent"],Z={off:"none",default:"default",full:"full",agent:"agent"},Q={off:"无工具,纯聊天",default:"4 项内置工具",full:"全部内置工具",agent:"High + 子代理"},ee={retain:{label:"retain",description:"保存稳定事实或决策到项目记忆"},recall:{label:"recall",description:"检索项目记忆中的相关上下文"},reflect:{label:"reflect",description:"基于已存记忆做综合回应"}},et=["auto","off","minimal","low","medium","high","xhigh"],er={auto:"沿用 pi 默认设置",off:"关闭推理",minimal:"最少推理",low:"低强度推理",medium:"中等推理",high:"高强度推理",xhigh:"最高强度推理"},en=[],ei=[{command:"/compact",label:"/compact",description:"压缩当前上下文",kind:"native"},{command:"/init",label:"/init",description:"快捷插入,交给模型处理初始化任务",kind:"shortcut"},{command:"/memory",label:"/memory",description:"快捷插入,交给模型处理项目记忆任务",kind:"shortcut"}];function eo({doc:e,onRemove:t}){var r;let i=e.fileName.split(".").pop()?.toLowerCase()??"",o=function(e){switch(e){case"pdf":return{emoji:"\uD83D\uDCC4",color:"#ef4444"};case"docx":case"doc":return{emoji:"\uD83D\uDCDD",color:"#3b82f6"};case"xlsx":case"xls":return{emoji:"\uD83D\uDCCA",color:"#22c55e"};case"pptx":case"ppt":return{emoji:"\uD83D\uDCFD",color:"#f97316"};default:return{emoji:"\uD83D\uDCCE",color:"var(--text-muted)"}}}(i),l=(r=e.size)<1024?`${r} B`:r<1048576?`${(r/1024).toFixed(1)} KB`:`${(r/1048576).toFixed(1)} MB`;return(0,n.jsxs)("div",{style:{position:"relative",display:"flex",alignItems:"center",gap:6,padding:"5px 10px 5px 7px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,maxWidth:200},title:e.fileName,children:[(0,n.jsx)("span",{style:{color:o.color,fontSize:14,flexShrink:0},children:o.emoji}),(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",lineHeight:1.3},children:e.fileName}),(0,n.jsxs)("div",{style:{fontSize:10,color:"var(--text-dim)",lineHeight:1.3},children:[i.toUpperCase()," \xb7 ",l,e.extractionError?" \xb7 no text":e.truncated?" \xb7 truncated":e.extractedText?" \xb7 text":""]})]}),(0,n.jsx)("button",{onClick:t,style:{flexShrink:0,width:14,height:14,borderRadius:"50%",background:"var(--bg-hover)",border:"none",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,color:"var(--text-dim)"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)"},children:(0,n.jsxs)("svg",{width:"7",height:"7",viewBox:"0 0 7 7",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"1",y1:"1",x2:"6",y2:"6"}),(0,n.jsx)("line",{x1:"6",y1:"1",x2:"1",y2:"6"})]})})]})}function el(e){return e.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&").replace(/&quot;/g,'"').replace(/&apos;/g,"'")}async function ea(e){let t=await Promise.all([r.e(2213),r.e(2619)]).then(r.bind(r,12810));t.GlobalWorkerOptions.workerSrc=new r.U(r(53228)).toString();let n=await t.getDocument({data:e.slice(0)}).promise,i=[];for(let e=1;e<=n.numPages;e+=1){let t=await n.getPage(e),r=(await t.getTextContent()).items.map(e=>"str"in e?e.str:"").filter(Boolean).join(" ");r.trim()&&i.push(`Page ${e}
2
- ${r}`)}return i.join("\n\n")}async function es(e){let t=(await Promise.all([r.e(2619),r.e(4453)]).then(r.t.bind(r,54453,23))).default,n=await t.loadAsync(e),i=["word/document.xml",...Object.keys(n.files).filter(e=>/^word\/(footnotes|endnotes|comments)\.xml$/i.test(e)).sort()],o=[];for(let e of i){let t=n.file(e);if(!t)continue;let r=[...(await t.async("string")).replace(/<w:(br|cr)[^>]*\/>/g,"\n").replace(/<\/w:p>/g,"\n").matchAll(/<w:t[^>]*>([\s\S]*?)<\/w:t>/g)];o.push(...r.map(e=>el(e[1])))}return o.join("").replace(/[ \t]+\n/g,"\n")}async function ed(e){let t=await Promise.all([r.e(3524),r.e(8436)]).then(r.bind(r,15967)),n=t.read(e,{type:"array"});return n.SheetNames.map(e=>{let r=n.Sheets[e],i=t.utils.sheet_to_csv(r);return`Sheet: ${e}
3
- ${i}`}).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),i=Object.keys(n.files).map(e=>({name:e,match:/^ppt\/slides\/slide(\d+)\.xml$/i.exec(e)})).filter(e=>null!==e.match).sort((e,t)=>Number(e.match[1])-Number(t.match[1])),o=[];for(let{name:e,match:t}of i){let r=[...(await n.file(e).async("string")).matchAll(/<a:t[^>]*>([\s\S]*?)<\/a:t>/g)].map(e=>el(e[1]).trim()).filter(Boolean);r.length&&o.push(`Slide ${t[1]}
4
- ${r.join("\n")}`)}return o.join("\n\n")}async function eu(e,t){let r=e.name.split(".").pop()?.toLowerCase()??"";try{let n,i="";if(e.type.startsWith("text/")||["csv","tsv","md","txt","json","xml"].includes(r))i=new TextDecoder("utf-8").decode(t);else if("pdf"===r||"application/pdf"===e.type)i=await ea(t);else if("docx"===r)i=await es(t);else if("xlsx"===r)i=await ed(t);else{if("pptx"!==r)return{extractionError:"Text extraction is not supported for this file type"};i=await ec(t)}let{text:o,truncated:l}=(n=i.replace(/\r\n/g,"\n").replace(/\n{4,}/g,"\n\n\n").trim()).length<=6e4?{text:n,truncated:!1}:{text:`${n.slice(0,6e4)}
5
-
6
- [truncated after 60000 characters]`,truncated:!0};if(!o)return{extractionError:"No extractable text found"};return{extractedText:o,truncated:l}}catch(e){return{extractionError:e instanceof Error?e.message:String(e)}}}let ep=(0,i.forwardRef)(function({onSend:e,onAbort:t,onSteer:r,onFollowUp:o,isStreaming:l,onBash:a,bashRunning:s,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:R,draftKey:M,slashCommands:L,cwd:W,activeFilePath:E,onDismissFileContext:$},P){let[D,N]=(0,i.useState)(()=>(function(e){if(!e)return null;let t=Y.get(e);return t?{...t}:null})(M)?.value??""),[B,O]=(0,i.useState)(!1),[A,H]=(0,i.useState)("root"),[F,U]=(0,i.useState)(null),[q,_]=(0,i.useState)(!1),[J,el]=(0,i.useState)(null),[ea,es]=(0,i.useState)(!1),[ed,ec]=(0,i.useState)(0),[ep,eh]=(0,i.useState)(null),[ex,eg]=(0,i.useState)(!1),[ef,ev]=(0,i.useState)(null),em=(0,i.useRef)(""),[eb,ey]=(0,i.useState)(!1),[ej,ek]=(0,i.useState)(!1),[ew,eS]=(0,i.useState)(!1),[eC,eT]=(0,i.useState)(!1),[ez,eI]=(0,i.useState)(null);(0,i.useEffect)(()=>{M&&function(e,t){if(e){if(!t.value)return Y.delete(e);Y.set(e,{...t})}}(M,{value:D})},[M,D]);let[eR,eM]=(0,i.useState)([]),[eL,eW]=(0,i.useState)([]),eE=function(e=768){let[t,r]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{let t=window.matchMedia(`(max-width: ${e}px)`),n=()=>r(t.matches);return n(),t.addEventListener?.("change",n),()=>t.removeEventListener?.("change",n)},[e]),t}(),e$=eE?{display:"none"}:void 0,eP=eE?28:32,eD=eE?"6px 8px":"8px 12px",eN=eE&&!l,eB=eC?"var(--text)":"var(--text-muted)",eO={padding:"7px 8px",borderRadius:8,background:"var(--bg-panel)",border:"1px solid var(--border)",width:"100%",textAlign:"left",cursor:"pointer"},eA=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},[eH,eF]=(0,i.useState)(null),eU=(0,i.useRef)(null),eq=(0,i.useRef)(null),e_=(0,i.useRef)(null),eJ=(0,i.useRef)(null),eK=(0,i.useRef)(null),eV=(0,i.useRef)(null),eY=(0,i.useRef)(null),eG=(0,i.useRef)(null),eX=(0,i.useRef)(null),eZ=(0,i.useRef)(null),eQ=(0,i.useRef)(null),e0=(0,i.useCallback)(e=>{let t=eU.current;if(!t)return void N(t=>t+(t?" ":"")+e);let r=t.selectionStart??t.value.length,n=t.selectionEnd??t.value.length,i=t.value.slice(0,r),o=t.value.slice(n),l=!(i.length>0)||i.endsWith(" ")||i.endsWith("\n")?"":" ";N(i+l+e+o),requestAnimationFrame(()=>{let t=eU.current;if(!t)return;let n=r+l.length+e.length;t.setSelectionRange(n,n),t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`})},[]);(0,i.useImperativeHandle)(P,()=>({insertIfEmpty(e){let t=eU.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){e0(e)},setText(e){N(e),requestAnimationFrame(()=>{let t=eU.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){e1(e)},addBase64Images(e){eM(t=>[...t,...e.map(e=>({data:e.data,mimeType:e.mimeType,previewUrl:`data:${e.mimeType};base64,${e.data}`}))])},addFiles(e){e2(e)}}));let e1=(0,i.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/"));if(!t.length)return;let r=await Promise.all(t.map(e=>new Promise((t,r)=>{let n=new FileReader;n.onload=()=>{t({data:n.result.split(",")[1],mimeType:e.type,previewUrl:URL.createObjectURL(e)})},n.onerror=r,n.readAsDataURL(e)})));eM(e=>[...e,...r])},[]),e2=(0,i.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/")),r=e.filter(e=>!e.type.startsWith("image/"));if(t.length&&e1(t),r.length){let e=await Promise.all(r.map(e=>new Promise((t,r)=>{let n=new FileReader;n.onload=async()=>{let r=n.result,i=await eu(e,r);t({data:r,fileName:e.name,mimeType:e.type||"application/octet-stream",size:e.size,...i})},n.onerror=r,n.readAsArrayBuffer(e)})));eW(t=>[...t,...e])}},[e1]),e5=(0,i.useCallback)(e=>{eM(t=>{let r=[...t];return URL.revokeObjectURL(r[e].previewUrl),r.splice(e,1),r})},[]),e4=(0,i.useCallback)(e=>{eW(t=>{let r=[...t];return r.splice(e,1),r})},[]),e8=(0,i.useCallback)(()=>{eM(e=>(e.forEach(e=>URL.revokeObjectURL(e.previewUrl)),[])),eW([])},[]),e3=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})),e6=[];for(let e of e3){let t=e6.find(t=>t.provider===e.provider);t?t.options.push(e):e6.push({provider:e.provider,options:[e]})}let e7=d?e3.find(e=>e.modelId===d.modelId&&e.provider===d.provider)?.name??d.modelId:null,e9=d?e3.find(e=>e.modelId===d.modelId&&e.provider===d.provider):e3[0],te=e9?.input?.includes("image")??!0,tt=eR.length>0&&e9?.input!==void 0&&!te,tr=!!D.trim()||eR.length>0||eL.length>0,tn=D.trim(),ti=0===eR.length&&0===eL.length&&tn.startsWith("!"),to=ti&&tn.startsWith("!!"),tl=tr&&!tt,ta=h?ei:ei.filter(e=>"/compact"!==e.command),ts=ta.filter(e=>"native"===e.kind),td=ta.filter(e=>"shortcut"===e.kind),tc=(()=>{let e=new Set(ei.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))})(),tu=(0,i.useMemo)(()=>J&&W?ep?.cwd!==W||ep.truncated&&J.query.trim()?ef?.query===J.query?ef.entries.slice(0,12):[]:function(e,t,r=12){let n=t.trim(),i=[];for(let t of e){let e=function(e,t){let r,n=e.path.toLowerCase(),i=-1===(r=n.lastIndexOf("/"))?n:n.slice(r+1),o=t.toLowerCase();return o&&i!==o?i.startsWith(o)?1:n.startsWith(o)?2:i.includes(o)?3:n.includes(o)?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,o)?null:5:0}(t,n);null!==e&&i.push({entry:t,score:e})}return i.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)),i.slice(0,Math.max(0,r)).map(e=>e.entry)}(ep.entries,J.query,12):[],[J,W,ep,ef]),tp=(0,i.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)),el(r),es(!!(r&&W)),r||ev(null)},[W]),th=(0,i.useCallback)(e=>{var t;let r=eU.current;if(!r||!J)return;let n=r.selectionStart??r.value.length,i=r.value.slice(0,J.start),o=r.value.slice(n),l=(t=e.path,/[\s"]/.test(t)?`@"${t}" `:`@${t} `);N(i+l+o),es(!1),el(null),ev(null),em.current="",requestAnimationFrame(()=>{r.focus();let e=i.length+l.length;r.setSelectionRange(e,e),r.style.height="auto",r.style.height=`${Math.min(r.scrollHeight,200)}px`})},[J]),tx=(0,i.useCallback)(e=>{let t=e.target.value;N(t),tp(t,e.target.selectionStart??t.length)},[tp]),tg=(0,i.useCallback)(()=>{let e=eU.current;e&&tp(e.value,e.selectionStart??0)},[tp]);(0,i.useEffect)(()=>{if(!ea||!W||ep?.cwd===W)return;let e=!1;return eg(!0),fetch(`/api/file-index?cwd=${encodeURIComponent(W)}`).then(e=>e.json()).then(t=>{e||eh({cwd:W,entries:t.files??[],truncated:!!t.truncated})}).catch(()=>{e||eh({cwd:W,entries:[],truncated:!1})}).finally(()=>{e||eg(!1)}),()=>{e=!0}},[ea,W,ep?.cwd]);let tf=J?.query??"";(0,i.useEffect)(()=>{if(!ea||!W||!ep||ep.cwd!==W||!ep.truncated)return;let e=tf.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()}},[ea,tf,W,ep]);let tv=y??[],tm=tv.length>0?`${tv.length} enabled`:"off",tb=e3.length>0&&!!p,ty=!!w,tj=!!b,tk=(()=>{let e=k??"auto";if("auto"===e)return"Default";if(!C)return e;let t=C[e];return null!=t?t:e})(),tw=e7??"Select model",tS=Object.entries(Z).find(([,e])=>e===(m??"full"))?.[0]??"full",tC=eE?26:32,tT=eE?7:9,tz=eE?3:6,tI={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)"},tR=eE&&(B||q||eb||ej||ew||eC);(0,i.useEffect)(()=>{tt||eF(null)},[tt]);let tM=(0,i.useCallback)(e=>{if(!D.trim()){N(e),requestAnimationFrame(()=>{let t=eU.current;t&&(t.focus(),t.setSelectionRange(e.length,e.length),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)});return}e0(e)},[e0,D]),tL=(0,i.useCallback)(()=>{let t=D.trim();if(t||eR.length||eL.length){if(eR.length&&!te)return void eF("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");if(!l){if(ti){if(!a)return;let e=tn.replace(/^!{1,2}\s*/,"").trim();if(!e)return;a(e,to),N(""),G(M),eU.current&&(eU.current.style.height="auto");return}if("/compact"===t&&!eR.length&&!eL.length&&h){g?x?.():h(),N(""),G(M),eU.current&&(eU.current.style.height="auto");return}e(t,eR.length?eR:void 0,eL.length?eL:void 0),N(""),G(M),e8(),eU.current&&(eU.current.style.height="auto")}}},[D,eR,eL,te,l,ti,to,tn,a,e,e8,h,x,g,M]),tW=(0,i.useCallback)(e=>{let t=D.trim();if(!t&&!eR.length&&!eL.length)return;if(eR.length&&!te)return void eF("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");let n=eR.length?eR:void 0,i=eL.length?eL:void 0;"steer"===e&&r?r(t,n,i):"followup"===e&&o&&o(t,n,i),N(""),G(M),e8(),eU.current&&(eU.current.style.height="auto")},[D,eR,eL,te,r,o,e8,M]),tE=I??en,t$=R??null,tP=(0,i.useCallback)(e=>{if(ea){if("Escape"===e.key){e.preventDefault(),es(!1),em.current="";return}if(tu.length>0){if("ArrowDown"===e.key){e.preventDefault(),ec(e=>(e+1)%tu.length);return}if("ArrowUp"===e.key){e.preventDefault(),ec(e=>(e-1+tu.length)%tu.length);return}if("Enter"===e.key||"Tab"===e.key){e.preventDefault(),th(tu[Math.min(ed,tu.length-1)]);return}}}if("ArrowUp"===e.key&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey&&tE.length>0){let t=eU.current;if(!t)return;let r=t.selectionStart??0;if(t.value.slice(0,r).includes("\n"))return;e.preventDefault();let n=function(e,t,r){let n;if(!e||0===r.length)return null;let i=((n=V.get(e))||(n={cursor:-1,draftSnapshot:""},V.set(e,n)),n);if(-1===i.cursor)i.draftSnapshot=t,i.cursor=0;else{if(!(i.cursor<r.length-1))return null;i.cursor+=1}return r[i.cursor]??null}(t$,t.value,tE);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}(t$)){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}}(t$,tE);t&&(N(t.text),t.returnedToPresent&&requestAnimationFrame(()=>{let e=eU.current;e&&e.setSelectionRange(t.text.length,t.text.length)}));return}"Enter"===e.key&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),t$&&V.set(t$,{cursor:-1,draftSnapshot:""}),l&&(r||o)?tW(r?"steer":"followup"):tL())},[ed,tu,ea,th,l,r,o,tW,tL,tE,t$]),tD=(0,i.useCallback)(()=>{let e=eU.current;e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[]),tN=(0,i.useCallback)(e=>{let t=Array.from(e.clipboardData?.items??[]).filter(e=>"file"===e.kind&&(e.type.startsWith("image/")||e.type.includes("pdf")||e.type.includes("officedocument")||e.type.includes("msword")||e.type.includes("ms-")));t.length&&(e.preventDefault(),e2(t.map(e=>e.getAsFile()).filter(e=>null!==e)))},[e2]);(0,i.useEffect)(()=>{if(!B&&!q&&!ea&&!eb&&!ej&&!ew&&!eC)return;let e=e=>{let t=e.target;if(!(t instanceof Node))return;let r=!!eq.current?.contains(t),n=!!e_.current?.contains(t);r||n||O(!1),eJ.current?.contains(t)||_(!1),ea&&!eK.current?.contains(t)&&t!==eU.current&&(es(!1),em.current=""),eV.current?.contains(t)||ey(!1),eY.current?.contains(t)||ek(!1),eG.current?.contains(t)||eS(!1),eX.current?.contains(t)||eT(!1)};return document.addEventListener("pointerdown",e,!0),()=>{document.removeEventListener("pointerdown",e,!0)}},[B,q,ea,eb,ej,ew,eC]),(0,i.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,i.useEffect)(()=>{if(!B)return;let e=e=>{"Escape"===e.key&&("root"!==A?H("root"):O(!1))};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[B,A]);let tB=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"})}),tO=(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"})}),tA=()=>{let e=()=>{O(!1),H("root")},t=e=>{e.currentTarget.style.background="var(--bg-hover)"},r=e=>{e.currentTarget.style.background="transparent"},i={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"},o={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"},a={position:"sticky",top:0,zIndex:1,padding:"5px 8px 3px",background:"var(--bg-panel)",color:"var(--text-dim)",fontSize:12,lineHeight:"18px",fontWeight:500},s=et.filter(e=>!S||"auto"===e||S.includes(e)),c=(0,n.jsxs)(n.Fragment,{children:["root"===A&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{onClick:()=>H("model"),role:"menuitem",style:i,onMouseEnter:t,onMouseLeave:r,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:tw}),tO(14,{color:"var(--text-dim)"})]}),ty&&e7&&(0,n.jsxs)("button",{onClick:()=>H("effort"),role:"menuitem",style:i,onMouseEnter:t,onMouseLeave:r,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:tk}),tO(14,{color:"var(--text-dim)"})]})]}),"model"===A&&(0,n.jsx)("div",{style:{minHeight:0,overflowY:"auto"},children:e6.map(i=>(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:a,children:i.provider}),i.options.map(i=>{let l=i.modelId===d?.modelId&&i.provider===d?.provider,a=i.input&&i.input.length>0?i.input.join(" \xb7 "):void 0;return(0,n.jsxs)("button",{onClick:()=>{e(),l||p(i.provider,i.modelId)},role:"menuitemradio","aria-checked":l,style:o,onMouseEnter:t,onMouseLeave:r,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:i.name}),void 0!==a&&(0,n.jsx)("span",{style:{overflow:"hidden",color:"var(--text-dim)",fontSize:12,lineHeight:"18px",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a})]}),(0,n.jsx)("span",{style:{display:"grid",placeItems:"center",flex:"0 0 18px",color:"var(--text)"},children:l?tB(14):null})]},`${i.provider}:${i.modelId}`)})]},i.provider))}),"effort"===A&&ty&&(0,n.jsx)("div",{style:{minHeight:0,overflowY:"auto"},children:s.map(i=>{let l=(k??"auto")===i,a="auto"!==i?C?.[i]:void 0,s="auto"===i?"Default":null!=a&&a!==i?a:i,d="auto"!==i&&null!=a&&a!==i;return(0,n.jsxs)("button",{onClick:()=>{e(),l||w?.(i)},role:"menuitemradio","aria-checked":l,style:o,onMouseEnter:t,onMouseLeave:r,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:[s,d&&(0,n.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",fontFamily:"var(--font-mono)",marginLeft:5},children:["(",i,")"]})]}),(0,n.jsx)("span",{style:{overflow:"hidden",color:"var(--text-dim)",fontSize:12,lineHeight:"18px",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:er[i]})]}),(0,n.jsx)("span",{style:{display:"grid",placeItems:"center",flex:"0 0 18px",color:"var(--text)"},children:l?tB(14):null})]},i)})})]}),u=window.visualViewport?.width??window.innerWidth,h=window.visualViewport?.height??window.innerHeight,x=F?h-F.top+6:0,g=F?Math.max(120,Math.min(F.top-8,.6*h)):240,f=F?Math.max(8,u-(F.left+F.width)):0;return(0,n.jsxs)("div",{ref:eq,style:{position:"relative",flex:eE?"1 1 160px":void 0,minWidth:0},children:[(0,n.jsxs)("button",{onClick:e=>{if(!eE){let t=e.currentTarget.getBoundingClientRect();U({top:t.top,left:t.left,width:t.width})}_(!1),ey(!1),ek(!1),eS(!1),eT(!1),H("root"),O(e=>!e)},disabled:l,title:"选择模型与推理强度",style:{display:"flex",alignItems:"center",gap:4,height:eE?eP:28,padding:eE?eD:"0 4px 0 8px",width:eE?"100%":void 0,maxWidth:eE?"100%":220,overflow:"hidden",background:B?"var(--bg-hover)":"transparent",border:"none",borderRadius:24,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:eE?11:13,lineHeight:eE?void 0:"20px",fontWeight:eE?void 0:500,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=B?"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:e7??"Select model"}),ty&&e7&&(0,n.jsx)("span",{style:{flex:"0 0 auto",color:"var(--text-dim)"},children:tk}),(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:B?"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"})})]}),B&&(eE?(0,n.jsxs)("div",{ref:e_,style:{...tI,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"!==A&&(0,n.jsx)("button",{onClick:()=>H("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"===A?"Models":"effort"===A?"推理强度":"模型"})]}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:"effort"===A?tk:tw})]}),c]}):F&&(0,n.jsx)("div",{ref:e_,role:"menu","aria-label":"模型与推理等级",onKeyDown:e=>{("ArrowDown"===e.key||"ArrowUp"===e.key)&&(e.preventDefault(),(e=>{let t=e_.current;if(!t)return;let r=Array.from(t.querySelectorAll('button[role="menuitem"], button[role="menuitemradio"]'));if(0===r.length)return;let n=(Math.max(r.findIndex(e=>e===document.activeElement),0)+e+r.length)%r.length;r[n]?.focus()})("ArrowDown"===e.key?1:-1))},style:{position:"fixed",bottom:x,right:f,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:g,overflow:"hidden",display:"flex",flexDirection:"column",padding:4},children:c}))]})};return(0,n.jsxs)("div",{style:eA,children:[tR&&(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:eZ,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:e=>{e1(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsx)("input",{ref:eQ,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=>{e2(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(/^.*[\\/]/,"")}),$&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),$()},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"})]}),(eR.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:[eR.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 ${tt?"rgba(220,38,38,0.45)":"var(--border)"}`,display:"block"}}),(0,n.jsx)("button",{onClick:()=>e5(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)(eo,{doc:e,onRemove:()=>e4(t)},`doc-${t}`))]}),(tt||eH)&&(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:eH??"当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。"})]})]}),ea&&W&&(0,n.jsxs)("div",{ref:eK,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===tu.length?(0,n.jsx)("div",{style:{padding:"8px 10px",fontSize:11.5,color:"var(--text-dim)"},children:"Searching files…"}):0===tu.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:tu.map((e,t)=>{let r=e.path.lastIndexOf("/"),i=-1===r?"":e.path.slice(0,r+1),o=-1===r?e.path:e.path.slice(r+1);return(0,n.jsxs)("button",{type:"button",onMouseDown:e=>e.preventDefault(),onClick:()=>th(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:[i&&(0,n.jsx)("span",{style:{color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i}),(0,n.jsx)("span",{style:{color:"var(--text)",fontFamily:"var(--font-mono)",flexShrink:0},children:o})]})]},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"})]}),ti&&(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||o)?"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:eU,value:D,onChange:tx,onKeyDown:tP,onKeyUp:tg,onClick:tg,onInput:tD,onPaste:tN,placeholder:s?"Shell command is running…":l&&(r||o)?"Steer 立即注入 / Follow-up 排队…":l?"Agent is running…":ti?"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:()=>tW("steer"),disabled:!tl,title:tt?"当前模型不支持图片输入":"打断 Agent 当前运行,立即注入消息",style:{display:"flex",alignItems:"center",gap:5*!eE,padding:eE?"6px 8px":"7px 12px",background:tl?"rgba(234,179,8,0.12)":"none",border:"1px solid rgba(234,179,8,0.35)",borderRadius:8,color:tl?"rgba(180,130,0,1)":"var(--text-dim)",cursor:tl?"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"]}),o&&(0,n.jsxs)("button",{onClick:()=>tW("followup"),disabled:!tl,title:tt?"当前模型不支持图片输入":"在 Agent 完成后排队发送",style:{display:"flex",alignItems:"center",gap:5*!eE,padding:eE?"6px 8px":"7px 12px",background:tl?"rgba(129,140,248,0.12)":"none",border:"1px solid rgba(129,140,248,0.35)",borderRadius:8,color:tl?"rgba(99,102,241,1)":"var(--text-dim)",cursor:tl?"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:tL,disabled:!tl,title:tt?"当前模型不支持图片输入":"Send",style:{flexShrink:0,alignSelf:"flex-end",display:"flex",alignItems:"center",gap:eE?3:6,padding:eE?"5px 9px":"7px 14px",marginBottom:+!!eE,background:tl?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:8,color:tl?"#fff":"var(--text-dim)",cursor:tl?"pointer":"not-allowed",fontSize:eE?11:13,fontWeight:600,letterSpacing:"-0.01em",boxShadow:tl?"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:tz,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:()=>eZ.current?.click(),disabled:l,title:"Attach image (right-click for document)",style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:tC,height:tC,padding:0,background:"none",border:"none",borderRadius:tT,color:eR.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=eR.length||eL.length?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=eR.length||eL.length?"var(--accent)":"var(--text-muted)"},onContextMenu:e=>{e.preventDefault(),eQ.current?.click()},children:(0,n.jsx)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})})}),(0,n.jsxs)("div",{ref:eJ,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>{l||(_(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:tC,height:tC,padding:0,background:q?"var(--bg-hover)":"none",border:"none",borderRadius:tT,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?tI:{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))]}),td.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"}),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:"/"}),(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))]}),tc.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"}),tc.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:eV,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:eP,padding:0,background:eb?"var(--bg-hover)":"none",border:"none",borderRadius:eE?8:9,color:tv.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=tv.length>0?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=eb?"var(--bg-hover)":"none",e.currentTarget.style.color=tv.length>0?"var(--accent)":"var(--text-muted)"},children:[" >_".trim(),tv.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?tI:{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=tv.includes(e),r=ee[e];return(0,n.jsxs)("button",{onClick:()=>{j(t?tv.filter(t=>t!==e):[...tv,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&&(tb||ty)&&tA(),eE&&!l&&(0,n.jsx)(n.Fragment,{children:(0,n.jsxs)("div",{ref:eX,style:{position:"relative",flexShrink:0},children:[(0,n.jsx)("button",{onClick:()=>{_(!1),ey(!1),O(!1),ek(!1),eS(!1),eT(e=>!e)},title:"更多设置",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:eC?"var(--bg-hover)":"none",border:"none",borderRadius:8,color:eB,cursor:"pointer",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background=eC?"var(--bg-hover)":"none",e.currentTarget.style.color=eC?"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"})]})}),eC&&(0,n.jsxs)("div",{style:{...tI,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:[tb&&(0,n.jsxs)("button",{onClick:()=>{eT(!1),ek(!1),eS(!1),ey(!1),O(!0),H("root")},style:eO,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:tw})]}),ty&&(0,n.jsxs)("button",{onClick:()=>{eT(!1),ek(!1),ey(!1),eS(!1),O(!0),H("effort")},style:eO,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:tk})]}),tj&&(0,n.jsxs)("button",{onClick:()=>{eT(!1),O(!1),eS(!1),ey(!1),ek(!0)},style:eO,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:tS})]}),!!j&&(0,n.jsxs)("button",{onClick:()=>{eT(!1),O(!1),ek(!1),eS(!1),ey(!0)},style:eO,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:tv.length>0?"var(--accent)":"var(--text)",marginTop:2},children:tm})]})]})]})]})})]}),(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)&&tj&&(0,n.jsxs)("div",{ref:eY,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:eP,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:e$,children:tS})]}),ej&&(0,n.jsx)("div",{style:{...eE?tI:{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:X.map(e=>{let t=Z[e],r=(m??"full")===t,i="agent"===e&&!1===ez,o=i?"需安装 pi-subagents":Q[e];return(0,n.jsxs)("button",{onClick:()=>{!i&&(ek(!1),r||b(t))},disabled:i,title:i?"运行 pi install npm:pi-subagents 后再启用":void 0,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:r?"var(--bg-selected)":"none",border:"none",color:r?"var(--text)":"var(--text-muted)",cursor:i?"not-allowed":"pointer",fontSize:eE?11:12,textAlign:"left",fontWeight:r?600:400,opacity:i?.5:1,whiteSpace:"nowrap"},onMouseEnter:e=>{r||i||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{r||(e.currentTarget.style.background="none")},children:[r?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1},children:e}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:o})]},e)})})]}),!eE&&(tb||ty)&&tA(),l&&(0,n.jsxs)("button",{onClick:t,title:"停止 Agent",style:{display:"flex",alignItems:"center",gap:6,padding:"8px 14px",height:eP,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 eh(e){return"user"===e.role?{bg:"rgba(37,99,235,0.18)",border:"rgba(37,99,235,0.7)"}:{bg:"rgba(107,114,128,0.12)",border:"rgba(107,114,128,0.5)"}}function ex({messages:e,streamingMessage:t,scrollContainer:r,messageRefs:o}){let[l,a]=(0,i.useState)(0),[s,d]=(0,i.useState)(1),[c,u]=(0,i.useState)(!1),[p,h]=(0,i.useState)([]),[x,g]=(0,i.useState)(!1),[f,v]=(0,i.useState)(null),m=(0,i.useRef)(!1),b=(0,i.useRef)(null),y=(0,i.useMemo)(()=>t?[...e,t]:e,[e,t]),j=(0,i.useRef)(y);j.current=y;let k=(0,i.useRef)(null);k.current=()=>{let e=r.current;if(!e)return;let t=e.scrollHeight,n=e.clientHeight,i=t-n;u(i>20),i<=0?(a(0),d(1)):(a(e.scrollTop/i),d(n/t));let l=o.current,s=[],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 i=l?.[c];if(c++,("user"===n.role||"assistant"===n.role&&(n.content??[]).some(e=>"text"===e.type))&&i&&t>0){let r=i.getBoundingClientRect(),o=e.getBoundingClientRect(),l=r.top-o.top+e.scrollTop,a=r.height;s.push({topRatio:l/t,heightRatio:a/t,msg:n,index:s.length})}}h(s)};let w=(0,i.useCallback)(()=>k.current(),[]);(0,i.useEffect)(()=>{let e=r.current;if(!e)return;e.addEventListener("scroll",w,{passive:!0});let t=new ResizeObserver(w);return t.observe(e),e.firstElementChild&&t.observe(e.firstElementChild),w(),()=>{e.removeEventListener("scroll",w),t.disconnect()}},[r,w]),(0,i.useEffect)(()=>{let e=setTimeout(w,50);return()=>clearTimeout(e)},[e.length,w]);let S=(0,i.useCallback)(e=>{let t=r.current;if(!t)return;let n=t.scrollHeight-t.clientHeight;n<=0||(t.scrollTop=Math.max(0,Math.min(1-s,e))/(1-s)*n)},[r,s]),C=(0,i.useCallback)(e=>{if(!c)return;m.current=!0;let t=e.currentTarget.getBoundingClientRect(),r=(e.clientY-t.top)/t.height,n=r-l*(1-s),i=n>=0&&n<=s?n:s/2;S(r-i);let o=e=>{m.current&&S((e.clientY-t.top)/t.height-i)},a=()=>{m.current=!1,window.removeEventListener("mousemove",o),window.removeEventListener("mouseup",a)};window.addEventListener("mousemove",o),window.addEventListener("mouseup",a)},[c,s,l,S]),T=b.current?.clientHeight??600,z=(0,i.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-s)*100,R=100*s,M=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:`${R}%`,background:"rgba(100,100,100,0.1)",borderTop:"1px solid rgba(100,100,100,0.2)",borderBottom:"1px solid rgba(100,100,100,0.2)",pointerEvents:"none",zIndex:1}}),p.map(e=>{let t=eh(e.msg),r=x&&M===e.index,i="user"===e.msg.role,o=100*e.topRatio;return(0,n.jsx)("div",{style:{position:"absolute",top:`${o}%`,transform:"translateY(-50%)",left:0,right:0,height:"12px",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",zIndex:2},children:(0,n.jsx)("div",{style:{width:i?8:6,height:i?8:6,borderRadius:i?2:"50%",background:t.bg,border:`1.5px solid ${t.border}`,flexShrink:0,transition:"transform 0.1s",transform:r?"scale(1.6)":"scale(1)"}})},e.index)}),(0,n.jsx)("div",{style:{position:"absolute",left:"50%",top:0,bottom:0,width:1,background:"var(--border)",transform:"translateX(-50%)",zIndex:0}}),x&&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),i=eh(e.msg),o=M===e.index;return r&&0!==z.length?(0,n.jsx)("div",{style:{position:"absolute",top:z[t],right:"100%",marginRight:6,background:"var(--bg)",borderTop:`1px solid ${o?i.border:"var(--border)"}`,borderRight:`1px solid ${o?i.border:"var(--border)"}`,borderBottom:`1px solid ${o?i.border:"var(--border)"}`,borderLeft:`2px solid ${i.border}`,borderRadius:4,padding:"2px 7px",width:200,zIndex:100,pointerEvents:"none",opacity:o?1:.45,transition:"top 0.1s, opacity 0.1s"},children:(0,n.jsx)("div",{style:{fontSize:11,color:o?"var(--text)":"var(--text-muted)",lineHeight:1.4,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:r})},e.index):null})]})}function eg(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function ef(e,t=220){if(!e)return;let r=e.trim();if(r)return r.length>t?`${r.slice(0,t)}...`:r}function ev(...e){for(let t of e)if("string"==typeof t&&t.trim())return t}function em(...e){for(let t of e)if("number"==typeof t&&Number.isFinite(t))return t}function eb(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:ef(r.content.split("\n").slice(3).join("\n")),timestamp:r.timestamp})}}if("assistant"===r.role){let e=r.content;if(!e)continue;for(let n of e)if("toolCall"===n.type&&"subagent"===n.toolName&&n.input){let e=n.input,i=e.agent??(e.chain?"chain":e.tasks?"parallel":e.action??"subagent"),o="string"==typeof e.task?e.task:void 0,l=n.toolCallId??`sub-${i}-${r.timestamp??Date.now()}`;t.set(l,{id:l,agent:i,status:"running",task:o,timestamp:r.timestamp})}}if("toolResult"===r.role){if(r.toolName&&"subagent"!==r.toolName||!r.toolCallId||!t.has(r.toolCallId))continue;let e=t.get(r.toolCallId),n=r.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n");t.set(r.toolCallId,function(e,t,r){let n;if(!eg(t))return{...e,summary:ef(r)};let i=Array.isArray(t.results)?t.results.filter(eg):[],o=i[0],l=o?.progressSummary,a=o&&(n=o.artifactPaths)?Object.values(n).filter(e=>"string"==typeof e&&e.trim().length>0):[],s=ev(o?.finalOutput,o?.output,r);return{...e,mode:ev(t.mode),runId:ev(t.runId),agent:ev(o?.agent,e.agent)??e.agent,task:ev(o?.task,e.task),summary:ef(s),model:ev(o?.model),durationMs:em(l?.durationMs),toolCount:em(l?.toolCount),tokens:em(l?.tokens),outputPath:ev(o?.savedOutputPath,o?.artifactPaths?.outputPath),sessionFile:ev(o?.sessionFile,o?.artifactPaths?.jsonlPath),artifacts:a,resultCount:i.length||void 0}}({...e,status:function(e){if(e.isError)return"failed";let t=e.details;return eg(t)&&Array.isArray(t.results)&&t.results.some(e=>eg(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 ey({messages:e,runs:t}){let r=(0,i.useMemo)(()=>eb(e??[]),[e]),o=t??r,l=o.filter(e=>"running"===e.status),a=o.filter(e=>"running"!==e.status);return 0===o.length?null:(0,n.jsxs)("div",{style:{height:"100%",overflow:"auto",padding:12},children:[l.length>0&&(0,n.jsx)(ej,{title:`Active (${l.length})`,runs:l}),a.length>0&&(0,n.jsx)(ej,{title:`Completed (${a.length})`,runs:a,compact:l.length>0})]})}function ej({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)(ek,{run:e},e.id))]})}function ek({run:e}){let[t,r]=(0,i.useState)(!1),o="running"===e.status,l="completed"===e.status?"#22c55e":"failed"===e.status?"#ef4444":o?"var(--accent)":"var(--text-dim)",a="failed"===e.status?"rgba(248,113,113,0.35)":o?"rgba(99,102,241,0.25)":"var(--border)",s="failed"===e.status?"rgba(248,113,113,0.05)":o?"rgba(99,102,241,0.05)":"var(--bg-panel)",d=[e.mode,e.resultCount&&e.resultCount>1?`${e.resultCount} results`:void 0,void 0!==e.toolCount?`${e.toolCount} tools`:void 0,void 0!==e.tokens?`${e.tokens.toLocaleString()} tok`:void 0,void 0!==e.durationMs?`${Math.round(e.durationMs/1e3)}s`:void 0].filter(Boolean).join(" \xb7 "),c=!!(e.summary||e.outputPath||e.sessionFile||e.artifacts?.length||e.model||e.runId);return(0,n.jsxs)("div",{style:{borderRadius:6,border:`1px solid ${a}`,background:s,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)(ew,{running:o,color:l}),(0,n.jsx)("span",{style:{fontWeight:650,color:"var(--text)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.agent}),(0,n.jsx)("span",{style:{color:l,fontSize:10,fontWeight:700,flexShrink:0},children:e.status}),d&&(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,marginLeft:"auto",whiteSpace:"nowrap"},children:d}),c&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:t?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),e.task&&(0,n.jsx)("div",{style:{padding:"0 10px 8px 25px",color:"var(--text-muted)",fontSize:11,lineHeight:1.4},children:ef(e.task,150)}),t&&c&&(0,n.jsxs)("div",{style:{borderTop:`1px solid ${a}`,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)(eS,{run:e})]})]})}function ew({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 eS({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}`))})}var eC=r(12257);let eT=["image/","application/pdf","application/vnd.openxmlformats-officedocument","application/msword","application/vnd.ms-"];function ez(e){return eT.some(t=>e.type.startsWith(t))}function eI({agentPhase:e,startedAt:t,queuedCount:r=0,onClearQueue:o}){let[l,a]=(0,i.useState)(0);return(0,i.useEffect)(()=>{if(!t)return void a(0);let e=()=>a(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",o&&(0,n.jsx)("button",{type:"button",onClick:o,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(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function eM({goal:e}){if(!(e&&"dropped"!==e.status))return null;let t=e.tokenBudget&&e.tokenBudget>0?Math.min(100,Math.round(e.tokensUsed/e.tokenBudget*100)):null;return(0,n.jsx)("div",{style:{marginBottom:16,borderRadius:10,border:"1px solid var(--border)",background:"var(--bg-panel)",overflow:"hidden"},children:(0,n.jsxs)("div",{style:{padding:"10px 14px"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:6},children:[(0,n.jsx)("span",{style:{flexShrink:0,borderRadius:4,padding:"1px 6px",fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.05em",color:"#fff",background:function(e){switch(e){case"active":return"rgba(37,99,235,0.85)";case"complete":return"rgba(34,197,94,0.85)";case"budget-limited":return"rgba(245,158,11,0.85)";case"paused":return"rgba(148,163,184,0.85)";case"dropped":return"rgba(239,68,68,0.85)"}}(e.status)},children:function(e){switch(e){case"active":return"进行中";case"paused":return"已暂停";case"budget-limited":return"预算受限";case"complete":return"已完成";case"dropped":return"已放弃"}}(e.status)}),(0,n.jsx)("span",{style:{fontSize:11,fontWeight:500,color:"var(--text-muted)"},children:"Goal"})]}),(0,n.jsx)("p",{style:{margin:"0 0 6px",fontSize:13,lineHeight:1.5,color:"var(--text)",whiteSpace:"pre-wrap"},children:e.objective}),(0,n.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"4px 16px",fontSize:11,color:"var(--text-muted)"},children:[(0,n.jsx)("span",{children:function(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m ${String(e%60).padStart(2,"0")}s`;let r=Math.floor(t/60);return`${r}h ${t%60}m`}(e.timeUsedSeconds)}),(0,n.jsxs)("span",{children:[eR(e.tokensUsed),e.tokenBudget?` / ${eR(e.tokenBudget)} tokens`:" tokens"]}),null!=t&&(0,n.jsxs)("span",{children:[t,"%"]})]}),null!=t&&(0,n.jsx)("div",{style:{marginTop:6,height:3,borderRadius:999,overflow:"hidden",background:"var(--border)"},children:(0,n.jsx)("div",{style:{height:"100%",borderRadius:999,background:t>=100?"rgba(239,68,68,0.6)":"rgba(37,99,235,0.5)",width:`${Math.min(t,100)}%`,transition:"width 0.3s"}})})]})})}function eL({cwd:e}){let[t,r]=(0,i.useState)(null),[o,l]=(0,i.useState)(!1),[a,s]=(0,i.useState)(null),[d,c]=(0,i.useState)(!1);if((0,i.useEffect)(()=>{if(!e){r(null),s(null),c(!1);return}let t=new AbortController;return r(null),s(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(!o){l(!0),s(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){s(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."}),a&&(0,n.jsx)("div",{style:{marginTop:4,color:"#f87171"},children:a})]}),(0,n.jsx)("button",{onClick:u,disabled:o,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:o?"default":"pointer",opacity:o?.6:1},children:o?"Trusting…":"Trust project"})]})}var eW=r(46786);function eE({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 e$({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 eP({request:e,onRespond:t}){let[r,o]=(0,i.useState)(e.prefill??""),l=(0,i.useRef)(null);(0,i.useEffect)(()=>{o(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 a=()=>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&&a()},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,i)=>(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}-${i}`))}),("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=>o(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=>o(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:a,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 eD=r(31775);function eN(e={visibilityState:document.visibilityState,hasFocus:document.hasFocus()}){return"visible"!==e.visibilityState||!e.hasFocus}async function eB(){if(!("Notification"in window))return null;if("default"!==Notification.permission)return Notification.permission;try{return await Notification.requestPermission()}catch{return null}}function eO(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 eA(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 eH=["annotate and analyze.","vibe code bioinformatics.","turn data into figures.","inspect your project.","build a reproducible report.","run R/Python plots.","summarize that paper.","review the pipeline.","compare markers.","draft methods.","find the next analysis step."];function eF({phrases:e}){let[t,r]=(0,i.useState)(()=>Math.floor(Math.random()*e.length)),[o,l]=(0,i.useState)(""),[a,s]=(0,i.useState)(!1),[d,c]=(0,i.useState)(!0);return(0,i.useEffect)(()=>{let e=setInterval(()=>c(e=>!e),530);return()=>clearInterval(e)},[]),(0,i.useEffect)(()=>{let n,i=e[t];if(a||o!==i)if(a&&""===o)s(!1),r(t=>(t+1)%e.length);else{let e=a?i.slice(0,o.length-1):i.slice(0,o.length+1);n=setTimeout(()=>l(e),a?28:55)}else n=setTimeout(()=>s(!0),1800);return()=>clearTimeout(n)},[o,a,t,e]),(0,n.jsxs)("span",{style:{color:"var(--text-muted)",fontWeight:400},children:[o,(0,n.jsx)("span",{style:{opacity:+!!d,color:"var(--accent)",marginLeft:1},children:"▍"})]})}function eU({status:e}){let t=e?.current??"0.8.140"??"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 eq({session:e,newSessionCwd:t,onAgentEnd:r,onSessionCreated:o,onSessionForked:l,modelsRefreshKey:a,chatInputRef:s,onBranchDataChange:d,onSessionStatsChange:c,onContextUsageChange:u,generativeUI:p,forkSettings:h,activeFilePath:x,onOpenFileAtLine:g}){var f;let v,[m,b]=(0,i.useState)(null),[j,k]=(0,i.useState)(!1),w=x&&!j?x:null;(0,i.useEffect)(()=>{k(!1)},[x]);let S=e?.name?.trim()||(e?.cwd?e.cwd.replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean).pop():"")||"",C=(0,i.useCallback)(()=>{eN()&&eO({title:S?`${y} \xb7 ${S}`:y,body:"Agent finished",tag:`agent-done-${e?.id??"new"}`}),r?.()},[S,r,e?.id]),{data:T,loading:z,error:I,messages:R,entryIds:M,streamState:L,agentRunning:W,modelNames:E,modelList:$,modelThinkingLevels:P,modelThinkingLevelMaps:D,toolPreset:N,memoryTools:B,thinkingLevel:O,slashCommands:A,retryInfo:H,queuedMessages:F,contextUsage:U,forkingEntryId:q,isCompacting:_,compactError:K,compactInfo:V,displayModel:Y,sessionStats:G,agentPhase:X,agentError:Z,extensionStatuses:Q,extensionWidgets:ee,extensionDialog:et,extensionNotices:er,bashLive:en,bashRunning:ei,respondToExtensionUi:eo,dismissExtensionNotice:el,isNew:ea,loadMoreMessages:es,hasMoreMessages:ed,totalMessages:ec,loadedMessagesCount:eu,loadShadowedMessages:eh,messagesEndRef:eg,scrollContainerRef:ef,lastUserMsgRef:ev,handleSend:em,handleAbort:ej,handleFork:ek,handleNavigate:ew,handleModelChange:eS,handleCompact:eT,handleSteer:eR,handleFollowUp:e_,handleAbortCompaction:eJ,handleToolPresetChange:eK,handleMemoryToolsChange:eV,handleThinkingLevelChange:eY,handleClearQueue:eG,handleBash:eX,handleAgentEventRef:eZ,forkToNewSession:eQ}=(0,eC.T)({chatInputRef:s,session:e,newSessionCwd:t,onAgentEnd:C,onSessionCreated:o,onSessionForked:l,modelsRefreshKey:a,onBranchDataChange:d});(0,i.useEffect)(()=>{et&&eN()&&eO({title:`${y} \xb7 action required`,body:et.title||"An extension needs your input",tag:`extension-ui-${et.id}`})},[et]);let e0=(0,i.useCallback)(()=>{eB()},[]),e1=(0,i.useMemo)(()=>{let e=new Map;for(let t of T?.context.compactions??[])e.set(t.entryId,t.shadowedCount);return e},[T?.context.compactions]),[e2,e5]=(0,i.useState)(!1),[e4,e8]=(0,i.useState)(null),e3=(0,i.useRef)(!1),e6=h??{enabled:!0,suggestTokens:18e4,autoTokens:4e5,minMessages:20};(0,i.useEffect)(()=>{e8(null),e3.current=!1},[e?.id]);let e7=(0,i.useCallback)(()=>{let r=T?.info?.cwd??e?.cwd??t??null,n=R.filter(e=>"user"===e.role||"assistant"===e.role),i=n.filter(e=>"user"===e.role),o=n.filter(e=>"assistant"===e.role),l=i[0],a=i[i.length-1],s=o[o.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(eA(l),500)}`:"",a?`最近一次请求: ${d(eA(a),500)}`:"",s?`最近回复要点: ${d(eA(s),900)}`:"",`父会话共 ${ec||n.length} 条消息。若需要更早的细节,请说明是哪个任务,我会让你查看父会话文件或重新提供。`].filter(Boolean).join("\n\n")},[T?.info?.cwd,e?.cwd,t,R,ec]),e9=(0,i.useCallback)(async()=>{if(W||e2)return{ok:!1,error:"Session is busy"};e5(!0),e8(null);try{let e=await eQ(e7());return e.ok||e8(e.error??"Fork failed"),e}finally{e5(!1)}},[W,e2,eQ,e7]),te=U?.tokens??null,tt=R.filter(e=>"user"===e.role||"assistant"===e.role).length,tr=!ea&&!W&&e6.enabled&&null!=te&&te>=e6.suggestTokens&&tt>=e6.minMessages;(0,i.useEffect)(()=>{if(!e6.enabled||ea||W)return;let t=U?.tokens;if(null==t||t<e6.autoTokens||tt<e6.minMessages||e3.current)return;let r=e?.id;if(r){try{if(localStorage.getItem(`annovibe.autoFork.dismiss.${r}`))return}catch{}e3.current=!0,(async()=>{let e=await eQ(e7());if(e.ok)try{localStorage.setItem(`annovibe.autoFork.dismiss.${r}`,String(Date.now()))}catch{}else e3.current=!1,e8(e.error??"Auto-fork failed")})()}},[e6.enabled,e6.autoTokens,e6.minMessages,ea,W,U?.tokens,tt,e?.id,eQ,e7]),(0,i.useEffect)(()=>{W&&!m&&b(Date.now()),W||b(null)},[W,m]);let tn=eZ.current;(0,i.useEffect)(()=>{eZ.current=e=>{"agent_start"===e.type&&b(Date.now()),("agent_end"===e.type&&!0!==e.willRetry||"agent_settled"===e.type)&&b(null),tn?.(e)}},[tn,eZ]);let ti=G?`${G.tokens.input}|${G.tokens.output}|${G.tokens.cacheRead}|${G.tokens.cacheWrite}`:null,to=(0,i.useRef)(G);to.current=G,(0,i.useEffect)(()=>{c?.(to.current)},[ti,c]),(0,i.useEffect)(()=>()=>{c?.(null)},[c]);let tl=U?`${U.percent??"null"}|${U.contextWindow}|${U.tokens??"null"}`:null,ta=(0,i.useRef)(U);ta.current=U,(0,i.useEffect)(()=>{u?.(ta.current)},[tl,u]),(0,i.useEffect)(()=>()=>{u?.(null)},[u]);let ts=(0,i.useCallback)(e=>{s?.current?.addFiles(e)},[s]),td=(0,i.useCallback)((e,t,r)=>{let n=r?.findIndex(t=>t.src===e)??-1;tm({src:e,gallery:r,index:n>=0?n:0})},[]),{isDragOver:tc,handleDragEnter:tu,handleDragOver:tp,handleDragLeave:th,handleDrop:tx}=function(e){let[t,r]=(0,i.useState)(!1),n=(0,i.useRef)(0),o=(0,i.useCallback)(e=>{Array.from(e.dataTransfer.items).some(ez)&&(e.preventDefault(),n.current+=1,r(!0))},[]),l=(0,i.useCallback)(e=>{Array.from(e.dataTransfer.items).some(ez)&&e.preventDefault()},[]);return{isDragOver:t,handleDragEnter:o,handleDragOver:l,handleDragLeave:(0,i.useCallback)(()=>{n.current-=1,n.current<=0&&(n.current=0,r(!1))},[]),handleDrop:(0,i.useCallback)(t=>{t.preventDefault(),n.current=0,r(!1),e(Array.from(t.dataTransfer.files))},[e])}}(ts),[tg,tf]=(0,i.useState)(null),[tv,tm]=(0,i.useState)(null);(0,i.useEffect)(()=>{if(!ea)return;let e=!1;return fetch("/api/version").then(e=>e.ok?e.json():null).then(t=>{!e&&t?.updateAvailable&&tf(t)}).catch(()=>{}),()=>{e=!0}},[ea]);let tb=R.filter(e=>"user"===e.role||"assistant"===e.role),ty=(f=tb.length,(v=(0,i.useRef)([])).current=Array(f).fill(null).map((e,t)=>v.current[t]??null),v),tj=(0,i.useMemo)(()=>{let e=new Map;for(let t of R)"toolResult"===t.role&&e.set(t.toolCallId,t);return e},[R]),tk=ea&&0===R.length&&!L.isStreaming&&!W,tw=T?.info?.cwd??e?.cwd??t??null,tS=function(e){if(!e)return null;let t=e.replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean);return t[t.length-1]||e}(tw),tC=function(e=768){let[t,r]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{let t=window.matchMedia(`(max-width: ${e-1}px)`),n=()=>r(t.matches);return(n(),"function"==typeof t.addEventListener)?(t.addEventListener("change",n),()=>t.removeEventListener("change",n)):(t.addListener(n),()=>t.removeListener(n))},[e]),t}(),[tT,tz]=(0,i.useState)(!1),tI=eb(R),tR=tI.filter(e=>"running"===e.status).length;(0,i.useEffect)(()=>{0===tI.length&&tT&&tz(!1)},[tI.length,tT]),(0,i.useEffect)(()=>{tC&&tT&&tz(!1)},[tC,tT]);let tM=Y?P[`${Y.provider}:${Y.modelId}`]??null:null,tL=Y?D[`${Y.provider}:${Y.modelId}`]??null:null,tW=e?.id??t??"new-chat",tE=(0,i.useMemo)(()=>(function(e){let t=[];for(let r=e.length-1;r>=0;r-=1){let n=e[r];if("user"!==n.role)continue;let i=n.text.trim();i&&t.push(i)}return t})(tb.map(e=>({role:e.role,text:eA(e)}))),[tb]),t$=(0,i.useCallback)(async(e,t,r)=>{e0();let n=e;w&&e.trim()&&(n=`${e}
7
-
8
- [Current file: \`${w}\`]`),await em(n,t,r)},[em,w,e0]),tP=(0,n.jsxs)("div",{children:[(0,n.jsx)(e$,{notices:er,onDismiss:el}),(0,n.jsx)(eE,{statuses:Q,widgets:ee}),(0,n.jsx)(ep,{ref:s,onSend:t$,onAbort:ej,onSteer:W&&!ei?eR:void 0,onFollowUp:W&&!ei?e_:void 0,onBash:e?.id||T?.sessionId?(e,t)=>{e0(),eX(e,t)}:void 0,bashRunning:ei,isStreaming:W,model:Y,modelNames:E,modelList:$,onModelChange:eS,onCompact:e||ea?eT:void 0,onAbortCompaction:eJ,isCompacting:_,compactError:K,compactInfo:V,toolPreset:N,onToolPresetChange:e||ea?eK:void 0,memoryTools:B,onMemoryToolsChange:e||ea?eV:void 0,thinkingLevel:O,onThinkingLevelChange:e||ea?eY:void 0,availableThinkingLevels:tM,thinkingLevelMap:tL,retryInfo:H,cornerBadge:tk?(0,n.jsx)(eU,{status:tg}):void 0,promptHistory:tE,sessionHistoryKey:tW,draftKey:tW,slashCommands:A,cwd:T?.info?.cwd??e?.cwd??t??void 0,activeFilePath:w,onDismissFileContext:()=>k(!0)})]}),tD=(0,i.useCallback)(e=>{W?s?.current?.insertText(e):em(e)},[W,s,em]),tN=(0,i.useCallback)((e,t,r)=>{if(W)return;let n=e.includes("```")?"````":"```",i=`${n}${t||""}
9
- ${e}
10
- ${n}`,o=r?` to \`${r}\``:" to the appropriate file";em(`Please write the following code${o} and then run it to show the result:
11
-
12
- ${i}`)},[W,em]),tB=(0,i.useCallback)((e,t)=>{if(W)return;let r=e.includes("```")?"````":"```",n=`${r}${t||""}
13
- ${e}
14
- ${r}`;em(`Please run the following code and show the output:
15
-
16
- ${n}`)},[W,em]),tO=(0,i.useCallback)((e,t)=>{if(W)return;let r=t?` to \`${t}\``:"",n=e.includes("```")?"````":"```",i=`${n}diff
17
- ${e}
18
- ${n}`;em(`Please apply this diff${r}:
19
-
20
- ${i}`)},[W,em]);return z?(0,n.jsx)("div",{className:"flex h-full items-center justify-center text-text-muted",children:"Loading session..."}):I?(0,n.jsx)("div",{className:"flex h-full items-center justify-center text-red-400",children:I}):(0,n.jsx)(eW.o,{sessionId:T?.sessionId??e?.id??null,children:(0,n.jsxs)("div",{className:"relative flex h-full flex-col overflow-hidden",onDragEnter:tu,onDragOver:tp,onDragLeave:th,onDrop:tx,children:[tc&&(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"})]})]})]}),tk?(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:[tS&&(0,n.jsxs)("div",{style:{padding:tC?"7px 9px":"9px 12px",border:"1px solid var(--border)",borderRadius:tC?9:10,background:"var(--bg-panel)",minWidth:0,display:"flex",alignItems:"flex-start",gap:tC?8:10,boxShadow:"none"},children:[(0,n.jsx)("div",{"aria-hidden":!0,style:{flex:"0 0 auto",width:tC?18:20,height:tC?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:tC?12.5:14,color:"var(--text)",fontWeight:700,lineHeight:1.3,wordBreak:"break-word"},children:tS}),tw&&(0,n.jsx)("div",{title:tw,style:{fontSize:10.5,color:"var(--text-dim)",marginTop:2,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:tw})]})]}),(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:y}),(0,n.jsx)("span",{style:{fontSize:14,minWidth:0,overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"},children:(0,n.jsx)(eF,{phrases:eH})})]})]}),(0,n.jsx)(eL,{cwd:tw}),tP]})}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"relative flex flex-1 overflow-hidden",children:[(0,n.jsx)("div",{ref:ef,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:tC?{paddingBottom:"calc(env(safe-area-inset-bottom, 0px) + 128px)"}:void 0,children:[(0,n.jsx)(eL,{cwd:tw}),(0,n.jsx)(eM,{goal:T?.sessionMeta?.goal??null}),(()=>{let r=-1;for(let e=R.length-1;e>=0;e--)if("user"===R[e].role){r=e;break}let i=-1;for(let e=R.length-1;e>=0;e--)if("assistant"===R[e].role){i=e;break}let o=0;return(0,n.jsxs)(n.Fragment,{children:[ed&&R.length>0&&(0,n.jsx)("div",{style:{textAlign:"center",padding:"8px 0 4px"},children:(0,n.jsxs)("button",{onClick:()=>es(),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 ",ec-eu," earlier message",ec-eu==1?"":"s"]})}),R.map((l,a)=>{let d="user"===l.role&&a>0&&"assistant"===R[a-1].role?M[a-1]:void 0,c="user"===l.role||"assistant"===l.role,u=c?o++:-1,h=!1;if("assistant"===l.role){h=!0;for(let e=a+1;e<R.length;e++){let t=R[e].role;if("user"===t)break;if("assistant"===t){h=!1;break}}h&&L.isStreaming&&a===R.length-1&&(h=!1)}let x=(0,n.jsx)(J.D,{message:l,toolResults:tj,modelNames:E,entryId:M[a],sessionId:T?.sessionId??e?.id??null,compactionShadowCount:e1.get(M[a]??""),onLoadShadowed:eh,onFork:W||ea||0===a&&"user"===l.role?void 0:ek,forking:q===M[a],onNavigate:W?void 0:ew,prevAssistantEntryId:W?void 0:d,onEditContent:e=>s?.current?.insertIfEmpty(e),onSendMessage:tD,showTimestamp:h,prevTimestamp:a>0?R[a-1].timestamp:void 0,renderVisualCodeBlocks:!!p,cwd:T?.info?.cwd??e?.cwd??t??void 0,onOpenImage:td,activeFilePath:w,agentRunning:W,onApplyToFile:tN,onRunCode:tB,onOpenFileAtLine:g,onAcceptDiff:tO,forkFresh:tr&&a===i?{show:!0,busy:e2,error:e4,onFork:()=>void e9()}:void 0},a);return c?(0,n.jsx)("div",{ref:e=>{ty.current[u]=e,a===r&&(ev.current=e)},style:{contentVisibility:"auto",containIntrinsicSize:"auto 100px"},children:x},a):x})]})})(),W&&(0,n.jsx)(eI,{agentPhase:X,startedAt:m,queuedCount:F.steering.length+F.followUp.length,onClearQueue:eG}),L.isStreaming&&L.streamingMessage&&(0,n.jsx)(J.D,{sessionId:T?.sessionId??e?.id??null,message:L.streamingMessage,isStreaming:!0,toolResults:tj,modelNames:E,onSendMessage:tD,renderVisualCodeBlocks:!!p,cwd:T?.info?.cwd??e?.cwd??t??void 0,activeFilePath:w,agentRunning:W,onApplyToFile:tN,onRunCode:tB,onOpenFileAtLine:g,onAcceptDiff:tO}),W&&!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..."}(X)})}),T?.info?.cwd&&!1===T.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:T.info.cwd})]}),Z&&(0,n.jsx)("div",{className:"my-3 rounded-[7px] border border-[rgba(248,113,113,0.35)] bg-[rgba(248,113,113,0.07)] px-3 py-2 text-[12px] leading-relaxed text-red-400",children:Z}),W&&(0,n.jsx)("div",{style:{height:ef.current?ef.current.clientHeight:"80vh"}}),(0,n.jsx)("div",{ref:eg})]})}),!tC&&(0,n.jsx)(ex,{messages:R,streamingMessage:L.streamingMessage,scrollContainer:ef,messageRefs:ty}),tI.length>0&&(0,n.jsxs)("button",{onClick:()=>tz(e=>!e),title:tT?"Hide subagent runs":"Show subagent runs",style:{position:"absolute",right:tC?8:tT?260:40,top:8,minWidth:28,height:28,display:"flex",alignItems:"center",justifyContent:"center",gap:6,padding:tR>0||tI.length>1?"0 8px":0,background:tT?"var(--bg-selected)":"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:tT?"var(--accent)":"var(--text-dim)",cursor:"pointer",zIndex:30,fontSize:12,transition:"right 0.2s ease, background 0.12s"},onMouseEnter:e=>{tT||(e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{tT||(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"})]}),(tR>0||tI.length>1)&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4,fontSize:10,fontWeight:700,color:tR>0?"var(--accent)":"var(--text-dim)"},children:[tR>0&&(0,n.jsxs)("span",{children:[tR," active"]}),(0,n.jsx)("span",{children:tI.length})]})]}),tT&&tI.length>0&&(0,n.jsxs)("div",{style:{position:"absolute",right:tC?8:48,top:4,bottom:4,width:tC?"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)(ey,{runs:tI})]})]}),(0,n.jsxs)("div",{className:"relative",children:[en&&(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:"$"})," ",en.command]}),(0,n.jsx)(eD.m,{text:en.output||"Running…",maxHeight:260,collapsible:!0,background:"var(--bg)",textColor:"var(--text-muted)"})]})}),tP]})]}),et&&(0,n.jsx)(eP,{request:et,onRespond:eo}),tv&&(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:()=>tm(null),children:[tv.gallery&&tv.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=((tv.index??0)-1+tv.gallery.length)%tv.gallery.length;tm({...tv,src:tv.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=((tv.index??0)+1)%tv.gallery.length;tm({...tv,src:tv.gallery[t].src,index:t})},children:"→"})]}),(0,n.jsx)("img",{src:tv.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:tv.gallery&&tv.gallery.length>1?`${(tv.index??0)+1} / ${tv.gallery.length}`:"Click anywhere to close"})]})]})})}var e_=r(25618),eJ=r(76577);class eK extends i.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)(eJ.fj,{style:{background:"var(--bg)"},children:(0,n.jsx)(eJ.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 eV(e,t,r){return Math.min(Math.max(e,t),r)}function eY({id:e,filePath:t,fileName:r,cwd:o,active:l,stackIndex:a,zIndex:s,onClose:d,onFocus:c,onOpenFile:u}){let[p,h]=(0,i.useState)(()=>{let e,t,r,n,i,o,l;return e=window.innerWidth,t=window.innerHeight,n=(r=e<720||t<560)?8:36,o=Math.max(320,e-2*n-(i=r?0:a%6*28)),l=Math.max(260,t-2*n-i),{left:n+i,top:n+i,width:r?o:Math.min(1180,o),height:r?l:Math.min(820,l),maximized:!1}}),[x,g]=(0,i.useState)(!1),[f,v]=(0,i.useState)(!1),m=(0,i.useRef)(null),b=(0,i.useRef)(null),y=(0,i.useRef)(null);(0,i.useEffect)(()=>{l&&m.current?.focus({preventScroll:!0})},[l]),(0,i.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),i=Math.min(e.height,r);return{...e,width:n,height:i,left:eV(e.left,8,Math.max(8,window.innerWidth-n-8)),top:eV(e.top,8,Math.max(8,window.innerHeight-i-8))}})};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]);let j=(0,i.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,i.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:eV(r,8,Math.max(8,window.innerWidth-120)),top:eV(n,8,Math.max(8,window.innerHeight-48))}))},[]),w=(0,i.useCallback)(e=>{let t=b.current;t?.pointerId===e.pointerId&&(e.currentTarget.releasePointerCapture(e.pointerId),b.current=null,g(!1))},[]),S=(0,i.useCallback)(()=>{c(e),h(e=>({...e,maximized:!e.maximized}))},[e,c]),C=(0,i.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,i.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:eV(r,360,Math.max(360,window.innerWidth-e.left-8)),height:eV(n,280,Math.max(280,window.innerHeight-e.top-8))}))},[]),z=(0,i.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:s}:{position:"fixed",left:p.left,top:p.top,width:p.width,height:p.height,zIndex:s};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:eG,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:eG,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)(eK,{filePath:t,children:(0,n.jsx)(e_.h,{filePath:t,cwd:o,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 eG={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 eX(e){return{dirCache:new Map,pathIndex:new Map,loadedDirs:new Set,revision:0,workspaceRoot:e}}function eZ(e,t){if(t.delete(e.path),e.children)for(let r of e.children)eZ(r,t)}function eQ(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)||eZ(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 e0(e,t,r){let n=eQ(r,e.dirCache.get(t),e.pathIndex);e.dirCache.set(t,n),e.loadedDirs.add(t)}function e1(e,t,r){let n=e.dirCache.get(t);if(!n)return;let i=n.findIndex(e=>e.path===r.path);if(-1!==i){let e=n[i];"folder"===e.type&&"folder"===r.type&&(r.children=e.children,r.childrenLoaded=e.childrenLoaded),n[i]=r}else n.push(r),n.sort(e5);e.pathIndex.set(r.path,r)}function e2(e,t,r){let n=e.dirCache.get(t);n&&e.dirCache.set(t,n.filter(e=>e.path!==r));let i=e.pathIndex.get(r);i&&eZ(i,e.pathIndex),e.dirCache.delete(r),e.loadedDirs.delete(r)}function e5(e,t){return"folder"===e.type&&"folder"!==t.type?-1:"folder"!==e.type&&"folder"===t.type?1:e.name.localeCompare(t.name)}let e4=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"]),e8="var(--text-dim)";function e3({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:e8}),(0,n.jsx)("path",{d:"M1 6h14.5L14 13H2L1 6Z",stroke:e8,strokeWidth:"1",fill:e8,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:e8,strokeWidth:"1",fill:e8,fillOpacity:"0.1"})})}function e6({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:e8,strokeWidth:"1",fill:e8,fillOpacity:"0.08"}),(0,n.jsx)("path",{d:"M10 2v3h3",stroke:e8,strokeWidth:"1",fill:"none",strokeLinejoin:"round"})]})}function e7({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:e8,strokeWidth:"0.9",fill:e8,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:e8,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:e8,letterSpacing:"0",children:e})]})}function e9({size:e=14}){return(0,n.jsx)(e7,{label:"TS",size:e})}function te({size:e=14}){return(0,n.jsx)(e7,{label:"TSX",size:e})}function tt({size:e=14}){return(0,n.jsx)(e7,{label:"JS",size:e})}function tr({size:e=14}){return(0,n.jsx)(e7,{label:"JSX",size:e})}function tn({size:e=14}){return(0,n.jsx)(e7,{label:"PY",size:e})}function ti({size:e=14}){return(0,n.jsx)(e7,{label:"{}",size:e})}function to({size:e=14}){return(0,n.jsx)(e7,{label:"CSS",size:e})}function tl({size:e=14}){return(0,n.jsx)(e7,{label:"SC",size:e})}function ta({size:e=14}){return(0,n.jsx)(e7,{label:"HTM",size:e})}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:e8,strokeWidth:"0.9",fill:e8,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:e8,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M3.5 9.5V7l1.5 1.5L6.5 7v2.5",stroke:e8,strokeWidth:"0.9",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,n.jsx)("path",{d:"M8 7v2.5M7 9l1 1.5 1-1.5",stroke:e8,strokeWidth:"0.9",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]})}function td({size:e=14}){return(0,n.jsx)(e7,{label:"YML",size:e})}function tc({size:e=14}){return(0,n.jsx)(e7,{label:"TOM",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:e8,strokeWidth:"0.9",fill:e8,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:e8,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M4 7.5l2 1.5-2 1.5",stroke:e8,strokeWidth:"0.95",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,n.jsx)("path",{d:"M7.5 10.5h2.5",stroke:e8,strokeWidth:"0.95",strokeLinecap:"round"})]})}function tp({size:e=14}){return(0,n.jsx)(e7,{label:"RS",size:e})}function th({size:e=14}){return(0,n.jsx)(e7,{label:"GO",size:e})}function tx({size:e=14}){return(0,n.jsx)(e7,{label:"SQL",size:e})}function tg({size:e=14}){return(0,n.jsx)(e7,{label:"GQL",size:e})}function tf({size:e=14}){return(0,n.jsx)(e7,{label:"TF",size:e})}function tv({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:e8,strokeWidth:"0.9",fill:e8,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:e8,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:e8,strokeWidth:"0.8"}),(0,n.jsx)("rect",{x:"6",y:"6.5",width:"2",height:"1.5",rx:"0.3",stroke:e8,strokeWidth:"0.8"}),(0,n.jsx)("rect",{x:"3.5",y:"8.5",width:"2",height:"1.5",rx:"0.3",stroke:e8,strokeWidth:"0.8"})]})}function tm({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:e8,strokeWidth:"0.9",fill:e8,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:e8,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"5.5",cy:"8.5",r:"1.5",stroke:e8,strokeWidth:"0.9"}),(0,n.jsx)("path",{d:"M7 8.5h2.5M8.5 8.5v1.5",stroke:e8,strokeWidth:"0.9",strokeLinecap:"round"})]})}function tb({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:e8,strokeWidth:"0.9",fill:e8,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:e8,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"5",cy:"6.5",r:"1",stroke:e8,strokeWidth:"0.85"}),(0,n.jsx)("circle",{cx:"9",cy:"6.5",r:"1",stroke:e8,strokeWidth:"0.85"}),(0,n.jsx)("circle",{cx:"5",cy:"10",r:"1",stroke:e8,strokeWidth:"0.85"}),(0,n.jsx)("path",{d:"M5 7.5V9",stroke:e8,strokeWidth:"0.85",strokeLinecap:"round"}),(0,n.jsx)("path",{d:"M9 7.5v.5a2 2 0 0 1-2 2H6",stroke:e8,strokeWidth:"0.85",strokeLinecap:"round",fill:"none"})]})}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:e8,strokeWidth:"0.9",fill:e8,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:e8,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:e8,strokeWidth:"0.9"}),(0,n.jsx)("path",{d:"M5.5 8.5V7.5a1.5 1.5 0 0 1 3 0v1",stroke:e8,strokeWidth:"0.9",strokeLinecap:"round",fill:"none"})]})}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:e8,strokeWidth:"0.9",fill:e8,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:e8,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"7",cy:"8.5",r:"1.3",stroke:e8,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:e8,strokeWidth:"0.8",strokeLinecap:"round"})]})}function tk(e,t=14){let r=e.toLowerCase(),i=r.split(".").pop()??"";if("dockerfile"===r||r.startsWith("dockerfile."))return(0,n.jsx)(tv,{size:t});if(".env"===r||r.startsWith(".env."))return(0,n.jsx)(tm,{size:t});if(".gitignore"===r||".gitattributes"===r||".gitmodules"===r)return(0,n.jsx)(tb,{size:t});if("package-lock.json"===r||"yarn.lock"===r||"bun.lock"===r||"pnpm-lock.yaml"===r||"cargo.lock"===r)return(0,n.jsx)(ty,{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)(tj,{size:t});switch(i){case"ts":return(0,n.jsx)(e9,{size:t});case"tsx":return(0,n.jsx)(te,{size:t});case"js":case"mjs":case"cjs":return(0,n.jsx)(tt,{size:t});case"jsx":return(0,n.jsx)(tr,{size:t});case"py":return(0,n.jsx)(tn,{size:t});case"json":case"jsonl":return(0,n.jsx)(ti,{size:t});case"css":case"less":return(0,n.jsx)(to,{size:t});case"scss":return(0,n.jsx)(tl,{size:t});case"html":case"htm":return(0,n.jsx)(ta,{size:t});case"md":case"mdx":return(0,n.jsx)(ts,{size:t});case"yaml":case"yml":return(0,n.jsx)(td,{size:t});case"toml":return(0,n.jsx)(tc,{size:t});case"sh":case"bash":case"zsh":case"fish":return(0,n.jsx)(tu,{size:t});case"rs":return(0,n.jsx)(tp,{size:t});case"go":return(0,n.jsx)(th,{size:t});case"sql":return(0,n.jsx)(tx,{size:t});case"graphql":case"gql":return(0,n.jsx)(tg,{size:t});case"tf":case"hcl":return(0,n.jsx)(tf,{size:t});case"lock":return(0,n.jsx)(ty,{size:t});default:return(0,n.jsx)(e6,{size:t})}}let tw=i.memo(function({node:e,depth:t,isExpanded:r,isLoading:o,isSelected:l,isRenaming:a,isUploadTarget:s,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(".")||e4.has(m),[y,j]=i.useState(!1),[k,w]=i.useState(e.name),S=i.useRef(null);i.useEffect(()=>{if(a&&S.current){let t=e.name.lastIndexOf(".");"file"===e.type&&t>0?S.current.setSelectionRange(0,t):S.current.select(),S.current.focus()}},[a,e.name,e.type]);let C=(0,i.useCallback)(()=>{a||d(e.path,"folder"===e.type)},[a,e.path,e.type,d]),T=(0,i.useCallback)(()=>{a||c(e.path)},[a,e.path,c]),z=(0,i.useCallback)(t=>{a||u(t,e.path)},[a,e.path,u]),I=(0,i.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]),R=(0,i.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:s?"rgba(37,99,235,0.14)":l?"var(--bg-selected)":y?"var(--bg-hover)":"transparent",outline:s?"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}}),o?(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)(e3,{size:14,open:r}):tk(e.name,14)}),a?(0,n.jsx)("input",{ref:S,value:k,onChange:e=>w(e.target.value),onKeyDown:I,onBlur:R,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 tS({x:e,y:t,actions:r,onClose:o}){let l=(0,i.useRef)(null),[a,s]=i.useState(e),[d,c]=i.useState(t);return((0,i.useEffect)(()=>{if(l.current){let r=l.current.getBoundingClientRect(),n=e,i=t;n+r.width>window.innerWidth-8&&(n=window.innerWidth-r.width-8),i+r.height>window.innerHeight-8&&(i=window.innerHeight-r.height-8),s(n),c(i)}},[e,t]),(0,i.useEffect)(()=>{let e=e=>{l.current&&!l.current.contains(e.target)&&o()},t=e=>{"Escape"===e.key&&o()},r=setTimeout(()=>{document.addEventListener("mousedown",e),document.addEventListener("keydown",t)},0);return()=>{clearTimeout(r),document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[o]),0===r.length)?null:(0,n.jsx)("div",{ref:l,style:{position:"fixed",left:a,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)(i.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(),o()},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 tC=r(28999);async function tT(e){let t=(0,tC.HG)(e),r=await fetch(`/api/files/${t}?type=list`);return r.ok?(await r.json()).entries??[]:[]}function tz(e,t,r,n){let i=(0,tC.e_)(t,e.name);return{id:i,name:e.name,path:i,relativePath:(0,tC.qP)(i,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 tI(e,t){return e===t?".":(0,tC.qP)(e,t)}function tR(e){return!!Array.from(e.types).includes("Files")||Array.from(e.items).some(e=>"file"===e.kind)}function tM(e){return Array.from(e.files).filter(e=>!!e.name)}function tL({cwd:e,onOpenFile:t,onExploreFile:r,refreshKey:o,onAtMention:l,searchQuery:a="",watchEnabled:s=!0}){let d,c,u,p,h=function(){let e=(0,i.useRef)(eX("")),[t,r]=(0,i.useState)(0),[n,o]=(0,i.useState)(""),[l,a]=(0,i.useState)(!1),[s,d]=(0,i.useState)(!1),[c,u]=(0,i.useState)(new Set),[p,h]=(0,i.useState)(new Set),[x,g]=(0,i.useState)(new Set),[f,v]=(0,i.useState)(null),[m,b]=(0,i.useState)([]),y=(0,i.useCallback)(()=>{let t=e.current;b(function e(t,r,n,i){let o=[];for(let l of t){let t="folder"===l.type&&r.has(l.path);if(o.push({node:l,depth:n,isExpanded:t}),t){let t=i.get(l.path)??[];o.push(...e(t,r,n+1,i))}}return o}(t.dirCache.get(t.workspaceRoot)??[],p,0,t.dirCache))},[p]);(0,i.useEffect)(()=>{y()},[t,p,y]);let j=(0,i.useCallback)(async t=>{a(!1),d(!1);let n=eX(t);e.current=n;try{let e=(await tT(t)).map(e=>tz(e,t,t,0));e.sort(e5),e0(n,t,e),o(t),a(!0),r(e=>e+1)}catch{d(!0),a(!0)}},[]),k=(0,i.useCallback)(async t=>{let n=e.current;if(!n.loadedDirs.has(t)){u(e=>new Set(e).add(t));try{let e=(await tT(t)).map(e=>tz(e,t,n.workspaceRoot,0));e.sort(e5),n.loadedDirs.has(t)||(e0(n,t,e),r(e=>e+1))}catch{}finally{u(e=>{let r=new Set(e);return r.delete(t),r})}}},[]),w=(0,i.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,i.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,i.useCallback)(()=>{g(new Set)},[]),T=(0,i.useCallback)(e=>{v(e)},[]),z=(0,i.useCallback)(()=>{v(null)},[]),I=(0,i.useCallback)(async t=>{var r;(r=e.current).dirCache.clear(),r.pathIndex.clear(),r.loadedDirs.clear(),h(new Set),await j(t)},[j]),R=(0,i.useCallback)(t=>e.current.pathIndex.get(t),[]),M=(0,i.useCallback)(t=>e.current.dirCache.get(t),[]),L=(0,i.useCallback)((t,n)=>{e1(e.current,t,n),r(e=>e+1)},[]),W=(0,i.useCallback)((t,n,i)=>{let o=e.current,l=o.pathIndex.get(t);if(!l)return;let a=o.workspaceRoot===t?o.workspaceRoot:t.substring(0,Math.max(t.lastIndexOf("/"),t.lastIndexOf("\\")));e2(o,a,t);let s={...l,id:n,name:i,path:n,relativePath:(0,tC.qP)(n,o.workspaceRoot),extension:"file"===l.type&&i.includes(".")?i.split(".").pop()?.toLowerCase()??"":""};e1(o,a,s),r(e=>e+1)},[]),E=(0,i.useCallback)(t=>{let n=e.current,i=n.workspaceRoot===t?n.workspaceRoot:t.substring(0,Math.max(t.lastIndexOf("/"),t.lastIndexOf("\\")));e2(n,i,t),r(e=>e+1)},[]);return{revision:t,workspaceRoot:n,hasLoaded:l,loadFailed:s,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:R,getChildren:M,onFileCreated:L,onFileRenamed:W,onFileDeleted:E,invalidateDir:(0,i.useCallback)(t=>{let r=e.current;r.loadedDirs.delete(t),r.dirCache.delete(t)},[]),applyWatcherEvent:(0,i.useCallback)(t=>{(function(e,t){let r=!1;for(let{dirPath:n,children:i}of t){if(!e.loadedDirs.has(n))continue;let t=i.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(e5);let o=eQ(t,e.dirCache.get(n),e.pathIndex);e.dirCache.set(n,o),r=!0}return r})(e.current,t)&&r(e=>e+1)},[])}}(),x=(d=(0,i.useCallback)(async(t,r)=>{try{let n=t===e?`${e}/${r}`:`${t}/${r}`,i=await fetch("/api/file-tree/write",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:n,content:""})});if(!i.ok){let e=await i.json().catch(()=>({}));return{success:!1,error:e.error??`HTTP ${i.status}`}}return{success:!0,resolvedPath:n}}catch(e){return{success:!1,error:String(e)}}},[e]),c=(0,i.useCallback)(async(t,r)=>{try{let n=t===e?`${e}/${r}`:`${t}/${r}`,i=await fetch("/api/file-tree/mkdir",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:n})});if(!i.ok){let e=await i.json().catch(()=>({}));return{success:!1,error:e.error??`HTTP ${i.status}`}}return{success:!0,resolvedPath:n}}catch(e){return{success:!1,error:String(e)}}},[e]),u=(0,i.useCallback)(async(t,r)=>{try{let n=Math.max(t.lastIndexOf("/"),t.lastIndexOf("\\")),i=n>0?t.slice(0,n):e,o=`${i}/${r}`,l=await fetch("/api/file-tree/rename",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldPath:t,newPath:o})});if(!l.ok){let e=await l.json().catch(()=>({}));return{success:!1,error:e.error??`HTTP ${l.status}`}}return{success:!0,resolvedPath:o}}catch(e){return{success:!1,error:String(e)}}},[e]),p=(0,i.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,i.useCallback)(async(e,t)=>{try{let r=e.slice(Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\"))+1),n=`${t}/${r}`,i=await fetch("/api/file-tree/rename",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldPath:e,newPath:n})});if(!i.ok){let e=await i.json().catch(()=>({}));return{success:!1,error:e.error??`HTTP ${i.status}`}}return{success:!0,resolvedPath:n}}catch(e){return{success:!1,error:String(e)}}},[]),revealInFinder:(0,i.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,i.useRef)(null),f=(0,i.useRef)(null),v=(0,i.useRef)(null),m=(0,i.useRef)(0),[b,y]=(0,i.useState)(!1),[j,k]=(0,i.useState)(null),[w,S]=(0,i.useState)(null),[C,T]=(0,i.useState)(null),[z,I]=(0,i.useState)(-1),[R,M]=(0,i.useState)(null),[L,W]=(0,i.useState)(!1),E=a.trim().length>0;(0,i.useEffect)(()=>{let e=()=>W("hidden"!==document.visibilityState);return e(),document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)},[]),(0,i.useEffect)(()=>{let t=f.current!==e;f.current=e,t&&h.loadRoot(e)},[e,h.loadRoot]),(0,i.useEffect)(()=>{void 0!==o&&h.refresh(e)},[o]),(0,i.useEffect)(()=>()=>{v.current&&clearTimeout(v.current)},[]),(0,i.useEffect)(()=>{if(!e||!s||!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,s]),(0,i.useEffect)(()=>{if(R){let e=setTimeout(()=>M(null),3e3);return()=>clearTimeout(e)}},[R]);let $=(()=>{if(E){let e=h.getChildren(h.workspaceRoot);return e?function e(t,r,n){let i=r.trim().toLowerCase(),o=[];for(let l of t){let t=l.name.toLowerCase().includes(i),a=(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,i));(t||a)&&(o.push({node:l,depth:n,isExpanded:!0}),l.children&&a&&o.push(...e(l.children,r,n+1)))}return o}(e,a,0):[]}return h.flatNodes})(),[P,D]=(0,i.useState)(0),[N,B]=(0,i.useState)(0);(0,i.useEffect)(()=>{let e=g.current;if(!e)return;let t=new ResizeObserver(e=>{for(let t of e)B(t.contentRect.height)});return t.observe(e),()=>t.disconnect()},[]);let O=(0,i.useCallback)(e=>{D(e.currentTarget.scrollTop)},[]),A=(0,i.useMemo)(()=>{let e=26*$.length,t=Math.max(0,Math.floor(P/26)-10),r=Math.min($.length,Math.ceil((P+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,i.useCallback)((e,r)=>{if(r)h.toggleExpand(e);else{let r=h.getNode(e);r&&t(e,r.name)}h.select(e),I($.findIndex(t=>t.node.path===e))},[h,t,$]),F=(0,i.useCallback)(e=>{let r=h.getNode(e);r&&"file"===r.type&&t(e,r.name)},[h,t]),U=(0,i.useCallback)((e,t)=>{e.preventDefault(),T({x:e.clientX,y:e.clientY,targetPath:t}),h.select(t),I($.findIndex(e=>e.node.path===t))},[h,$]),q=(0,i.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,tC.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),M(`Deleted "${t.name}"`)):e.error&&M(e.error)},danger:!0}),n.push({label:"",onClick:()=>{},separator:!0}),n.push({label:"Copy Path",onClick:()=>{navigator.clipboard.writeText(t.path).catch(()=>{}),M("Copied path")}}),n.push({label:"Copy Relative Path",onClick:()=>{let r=(0,tC.qP)(t.path,e);navigator.clipboard.writeText(r).catch(()=>{}),M("Copied relative path")}}),n.push({label:"Reveal in Finder",onClick:()=>x.revealInFinder(t.path)}),n},[C,h,x,H,l,r,e]),_=(0,i.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),M(`Renamed to "${t}"`)):n.error&&M(n.error)},[h,x]),J=(0,i.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",i=await x.createFile(r,n);if(i.success&&i.resolvedPath){let t={id:i.resolvedPath,name:n,path:i.resolvedPath,relativePath:(0,tC.qP)(i.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(i.resolvedPath),50)}else i.error&&M(i.error)},[h,x,e]),K=(0,i.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",i=await x.createFolder(r,n);if(i.success&&i.resolvedPath){let t={id:i.resolvedPath,name:n,path:i.resolvedPath,relativePath:(0,tC.qP)(i.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(i.resolvedPath),50)}else i.error&&M(i.error)},[h,x,e]),V=(0,i.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,$.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=$[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=$[z]?.node;t?.type==="folder"&&h.expandedPaths.has(t.path)&&h.toggleExpand(t.path)}else if("Enter"===e.key){e.preventDefault();let t=$[z]?.node;t&&H(t.path,"folder"===t.type)}else if("F2"===e.key){e.preventDefault();let t=$[z]?.node;t&&(h.select(t.path),h.startRename(t.path))}else if("Delete"===e.key||"Backspace"===e.key){e.preventDefault();let t=$[z]?.node;t&&window.confirm(`Delete "${t.name}"?`)&&x.deleteFile(t.path).then(e=>{e.success&&(h.onFileDeleted(t.path),M(`Deleted "${t.name}"`))})}}},[$,z,h,H,x]);(0,i.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,i.useCallback)(()=>{v.current&&clearTimeout(v.current),v.current=setTimeout(()=>S(null),5e3)},[]),G=(0,i.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),i=tI(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 ${i}`});let o=new FormData;t.forEach(e=>o.append("files",e,e.name));let l=new XMLHttpRequest,a=(0,tC.HG)(r);l.open("POST",`/api/files/${a}?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 o=e.uploaded??[],l=e.failed??[],a=[...o.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 ${o.length}, ${l.length} failed`:`Uploaded ${o.length} file${1===o.length?"":"s"} to ${i}`,details:a}),h.invalidateDir(r),h.expandedPaths.has(r)&&h.loadChildren(r),Y()}else{let i=e.error??`Upload failed (HTTP ${l.status})`;S({phase:"error",targetPath:r,fileCount:t.length,loaded:0,total:n,message:i}),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(o)},[e,h,Y]),X=(0,i.useCallback)(e=>{tR(e.dataTransfer)&&(e.preventDefault(),m.current+=1,y(!0))},[]),Z=(0,i.useCallback)(e=>{tR(e.dataTransfer)&&(e.preventDefault(),e.dataTransfer.dropEffect="copy")},[]),Q=(0,i.useCallback)(()=>{m.current-=1,m.current<=0&&(m.current=0,y(!1))},[]),ee=(0,i.useCallback)(t=>{if(!tR(t.dataTransfer))return;t.preventDefault(),m.current=0,y(!1);let r=tM(t.dataTransfer);r.length>0&&G(r,e)},[e,G]),et=(0,i.useCallback)(e=>t=>{if(!tR(t.dataTransfer))return;t.preventDefault(),t.stopPropagation();let r=tM(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:tW,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:tW,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:tW,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:tW,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:[$.length," items"]})]}),R&&(0,n.jsx)("div",{style:{padding:"4px 10px",fontSize:11,color:"var(--text)",background:"var(--bg-selected)",borderBottom:"1px solid var(--border)"},children:R}),(0,n.jsxs)("div",{ref:g,onScroll:O,style:{flex:1,overflow:"auto",position:"relative"},children:[h.hasLoaded?0===$.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:A.totalHeight,position:"relative"},children:A.items.map(e=>{let{index:t,top:r}=e,{node:i,depth:o,isExpanded:l}=$[t],a=t===z;return(0,n.jsx)("div",{style:{position:"absolute",top:r,left:0,right:0,height:26,outline:a?"1px solid var(--accent)":"none",outlineOffset:-1,borderRadius:4},children:(0,n.jsx)(tw,{node:i,depth:o,isExpanded:l,isLoading:h.loadingPaths.has(i.path),isSelected:h.selectedPaths.has(i.path),isRenaming:h.renamingPath===i.path,isUploadTarget:j===i.path,onClick:H,onDoubleClick:F,onContextMenu:U,onRenameSubmit:_,onRenameCancel:()=>h.stopRename(),onDrop:"folder"===i.type?et(i.path):void 0})},i.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 ",tI(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)(tS,{x:C.x,y:C.y,actions:q,onClose:()=>T(null)})]})}let tW={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 tE({cwd:e,refreshKey:t=0,onOpenFile:r,onExploreFile:o,onAtMention:l,watchEnabled:a=!0}){let[s,d]=(0,i.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:s,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}}),s&&(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)(tL,{cwd:e,onOpenFile:r,onExploreFile:o,refreshKey:t,onAtMention:l,searchQuery:s,watchEnabled:a}):(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",padding:18,textAlign:"center",color:"var(--text-dim)",fontSize:12},children:"Select a project to browse files."})})]})}var t$=r(27568),tP=r(96793);let tD={__soul__:{apiPath:"/api/soul",title:"SOUL.md"},__harness__:{apiPath:"/api/harness",title:"HARNESS.md"}};function tN({filePath:e}){let t=tD[e],{isDark:r}=(0,tP.D)(),[o,l]=(0,i.useState)(""),[a,s]=(0,i.useState)(!0),[d,c]=(0,i.useState)(null),[u,p]=(0,i.useState)(!1),[h,x]=(0,i.useState)(!1);(0,i.useEffect)(()=>{t&&(s(!0),fetch(t.apiPath).then(e=>e.json()).then(e=>l(e.content??"")).catch(e=>c(String(e))).finally(()=>s(!1)))},[t]);let g=(0,i.useCallback)(async()=>{if(t){p(!0);try{await fetch(t.apiPath,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:o})}),x(!0),setTimeout(()=>x(!1),2e3)}catch(e){c(String(e))}finally{p(!1)}}},[t,o]);return t?a?(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)(t$.g,{initialContent:o,language:"markdown",isDark:r,onChange:l,onSave:g})})]}):null}function tB(){document.body.style.cursor="",document.body.style.userSelect=""}function tO({side:e,onResize:t,onResizeStart:r,onResizeEnd:o,ariaLabel:l}){let a=(0,i.useRef)(null),s=(0,i.useRef)(!1),d=(0,i.useRef)(0),[c,u]=(0,i.useState)(!1),p=(0,i.useCallback)(e=>{if(!s.current)return;s.current=!1,u(!1);let t=a.current;t&&void 0!==e&&t.hasPointerCapture(e)&&t.releasePointerCapture(e),tB(),o?.()},[o]),h=(0,i.useCallback)(e=>{0===e.button&&e.isPrimary&&(e.preventDefault(),s.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,i.useCallback)(e=>{if(!s.current)return;e.preventDefault();let r=e.clientX-d.current;d.current=e.clientX,t(r)},[t]),g=(0,i.useCallback)(e=>{e.preventDefault(),p(e.pointerId)},[p]),f=(0,i.useCallback)(e=>{p(e.pointerId)},[p]);return(0,i.useEffect)(()=>()=>{s.current&&(s.current=!1,tB(),o?.())},[o]),(0,n.jsx)("div",{ref:a,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 tA(e){return"running"===e?"#22c55e":"starting"===e?"rgba(234,179,8,0.95)":"error"===e?"#ef4444":"var(--text-dim)"}function tH(e){return"h5adexp"===e?"H5AD Exp":"stexp"}function tF(e,t,r){return Math.min(Math.max(e,t),r)}function tU(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 tq({appType:e,filePath:t,cwd:r,sessionId:o,appId:l,onClose:a,onAppChanged:s,onOpenTools:d}){var c;let[u,p]=(0,i.useState)(null),[h,x]=(0,i.useState)(null),[g,f]=(0,i.useState)(!1),[v,m]=(0,i.useState)(!1),[b,y]=(0,i.useState)(0),[j,k]=(0,i.useState)(()=>{let e,t,r,n,i,o;return e=window.innerWidth,t=window.innerHeight,n=(r=e<720||t<560)?8:34,i=Math.max(360,e-2*n),o=Math.max(320,t-2*n),{left:n,top:n,width:r?i:Math.min(1280,i),height:r?o:Math.min(880,o),maximized:!1}}),[w,S]=(0,i.useState)(!1),[C,T]=(0,i.useState)(!1),z=(0,i.useRef)(null),I=(0,i.useRef)(null),R=(0,i.useRef)(null),M=!!t||!!l,L=t?(0,tC.WP)(t):u?(0,tC.WP)(u.filePath):"",W=t&&r?(0,tC.qP)(t,r):u?.filePath&&u.cwd?(0,tC.qP)(u.filePath,u.cwd):t??u?.filePath??"",E=u?.status??"idle",$=(0,i.useMemo)(()=>u?.logs?.join("\n")??"",[u?.logs]),P=u?.appType==="h5adexp"?u.url:u?.directUrl??u?.url??"",D=(0,i.useCallback)(e=>{p(e),s?.(e)},[s]),N=(0,i.useCallback)(async e=>{let t=await fetch(`/api/apps?appId=${encodeURIComponent(e)}`),r=await t.json(),n=tU(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]),B=(0,i.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:o})}),i=await n.json(),l=tU(i);if(!n.ok||!l){let e=i&&"object"==typeof i&&"error"in i?String(i.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,o]);(0,i.useEffect)(()=>{if(M){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),B()}},[M,l,t]),(0,i.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,i.useEffect)(()=>{M&&z.current?.focus({preventScroll:!0})},[M,u?.id]),(0,i.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),i=Math.min(e.height,r);return{...e,width:n,height:i,left:tF(e.left,8,Math.max(8,window.innerWidth-n-8)),top:tF(e.top,8,Math.max(8,window.innerHeight-i-8))}})};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]);let O=(0,i.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=tU(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]),A=(0,i.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,i.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:tF(r,8,Math.max(8,window.innerWidth-120)),top:tF(n,8,Math.max(8,window.innerHeight-48))}))},[]),F=(0,i.useCallback)(e=>{let t=I.current;t?.pointerId===e.pointerId&&(e.currentTarget.releasePointerCapture(e.pointerId),I.current=null,S(!1))},[]),U=(0,i.useCallback)(e=>{0!==e.button||j.maximized||(e.preventDefault(),e.stopPropagation(),e.currentTarget.setPointerCapture(e.pointerId),R.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,i.useCallback)(e=>{let t=R.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:tF(r,420,Math.max(420,window.innerWidth-e.left-8)),height:tF(n,340,Math.max(340,window.innerHeight-e.top-8))}))},[]),_=(0,i.useCallback)(e=>{let t=R.current;t?.pointerId===e.pointerId&&(e.currentTarget.releasePointerCapture(e.pointerId),R.current=null,T(!1))},[]),J=(0,i.useCallback)(()=>{d?.(),a()},[a,d]),K=(0,i.useCallback)(()=>{k(e=>({...e,maximized:!e.maximized}))},[]);if(!M)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??tH(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:A,onPointerMove:H,onPointerUp:F,onPointerCancel:F,style:{display:"flex",alignItems:"center",gap:8,padding:"8px 9px 8px 12px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",flexShrink:0,userSelect:"none",cursor:j.maximized?"default":w?"grabbing":"grab"},children:[(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,n.jsx)("span",{style:{fontSize:13,fontWeight:700,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u?.title??tH(e)}),(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:tA(E),flexShrink:0}}),(0,n.jsx)("span",{style:{fontSize:11,color:tA(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:!P||u?.status==="stopped",style:t_,title:"Reload",children:"Reload"}),(0,n.jsx)("button",{type:"button",onPointerDown:e=>e.stopPropagation(),onClick:()=>m(e=>!e),style:{...t_,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:t_,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:{...t_,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:tJ,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:tJ,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:a,"aria-label":"Close window",title:"Close window",style:tJ,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 ",tH(e),"..."]}):P&&u?.status!=="stopped"?(0,n.jsx)("iframe",{src:P,title:`${u?.title??tH(e)} - ${L}`,style:{width:"100%",height:"100%",border:"none",display:"block",background:"#fff"}},`${P}:${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:[tH(e)," is stopped."]}),t&&r&&(0,n.jsx)("button",{type:"button",onClick:()=>void B(),disabled:g,style:{height:32,padding:"0 12px",border:"none",borderRadius:6,background:"var(--accent)",color:"#fff",cursor:g?"not-allowed":"pointer",fontSize:12,fontWeight:650},children:"Start again"})]})}),v&&(0,n.jsxs)("div",{style:{width:360,borderLeft:"1px solid var(--border)",background:"var(--bg-panel)",display:"flex",flexDirection:"column",minHeight:0},children:[(0,n.jsx)("div",{style:{padding:"8px 10px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-muted)",fontWeight:650},children:"Process Logs"}),(0,n.jsx)("pre",{style:{flex:1,margin:0,padding:10,overflow:"auto",fontSize:11,lineHeight:1.45,color:"var(--text-muted)",fontFamily:"var(--font-mono)",whiteSpace:"pre-wrap"},children:$||"No logs yet."})]})]}),!j.maximized&&(0,n.jsx)("div",{role:"separator","aria-orientation":"horizontal","aria-label":"Resize explore window",title:"Resize",onPointerDown:U,onPointerMove: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 t_={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},tJ={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 tK(e){return"running"===e?"#22c55e":"starting"===e?"rgba(234,179,8,0.95)":"error"===e?"#ef4444":"var(--text-dim)"}function tV(e){return"waiting_model"===e?"rgba(234,179,8,0.95)":"running_tools"===e?"#38bdf8":"streaming"===e?"#22c55e":"compacting"===e?"#a78bfa":"var(--text-dim)"}function tY(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 tG(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),i=t%60;return r>0?`${r}h ${n}m`:n>0?`${n}m ${i}s`:`${i}s`}function tX({refreshKey:e=0,visibleAppId:t,cwd:r,onOpenApp:o,onAppChanged:l,onAppsChanged:a,agentRuntimeExtra:s}){let[d,c]=(0,i.useState)([]),[u,p]=(0,i.useState)(null),[h,x]=(0,i.useState)(null),[g,f]=(0,i.useState)(null),[v,m]=(0,i.useState)(null),[b,y]=(0,i.useState)(null),[j,k]=(0,i.useState)(null),[w,S]=(0,i.useState)(null),[C,T]=(0,i.useState)(null),[z,I]=(0,i.useState)(null),R=(0,i.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]),M=(0,i.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),a?.(t.apps),f(null)}catch(e){f(e instanceof Error?e.message:String(e))}},[a]),L=(0,i.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,i.useEffect)(()=>{M(),L()},[M,L,e]),(0,i.useEffect)(()=>{let e=window.setInterval(()=>{M(),L()},3e3);return()=>window.clearInterval(e)},[M,L]);let W=(0,i.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 M()}catch(e){f(e instanceof Error?e.message:String(e))}finally{S(null)}},[M,l]),E=(0,i.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]),$=(0,i.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})}),i=await n.json().catch(()=>({}));if(!n.ok)throw Error(i.error??`HTTP ${n.status}`);await L()}catch(e){y(e instanceof Error?e.message:String(e))}finally{k(null)}}},[r,L]),P=(0,i.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),B=u?.sessions??[],O=B.filter(e=>e.busy),A=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 ",tY(N)]})]}),(0,n.jsx)("button",{type:"button",onClick:()=>{M(),L()},style:t2,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)(tZ,{title:"Agent Runtime",subtitle:A.length>0?`${A.length} waiting for model first token`:`${O.length} active chat${1===O.length?"":"s"}`}),s,0===B.length?(0,n.jsx)(tQ,{label:"No agent runtime is active."}):(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:B.map(e=>{var t;let r=e.model?`${e.model.provider}/${e.model.id}`:"-",i=e.cwd?(0,tC.WP)(e.cwd)||e.cwd:"-",o=e.activeTools.map(e=>e.name).join(", ");return(0,n.jsxs)("div",{style:{border:`1px solid ${e.busy?"rgba(37,99,235,0.35)":"var(--border)"}`,borderRadius:8,background:e.busy?"var(--bg-selected)":"var(--bg-panel)",padding:10},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[(0,n.jsx)("span",{style:{width:8,height:8,borderRadius:"50%",background:tV(e.phase),marginTop:5,flexShrink:0}}),(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:7,minWidth:0},children:[(0,n.jsx)("span",{style:{fontSize:12,fontWeight:700,color:tV(e.phase),textTransform:"uppercase",flexShrink:0},children:"waiting_model"===(t=e.phase)?"waiting model":"running_tools"===t?"running tools":"streaming"===t?"streaming":"compacting"===t?"compacting":"idle"}),(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:r,children:r})]}),(0,n.jsxs)("div",{title:e.cwd??void 0,style:{marginTop:3,fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[i," \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)(t0,{label:"uptime",value:tG(e.uptimeMs)}),(0,n.jsx)(t0,{label:"wait",value:tG(e.waitingForModelMs),color:"waiting_model"===e.phase?tV(e.phase):void 0}),(0,n.jsx)(t0,{label:"pending",value:null===e.pendingMessageCount?"-":String(e.pendingMessageCount)}),(0,n.jsx)(t0,{label:"event",value:e.lastEventType??"-"}),(0,n.jsx)(t0,{label:"tools",value:o||"-"}),(0,n.jsx)(t0,{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:{...t2,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)(tZ,{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)(t0,{label:"fact",value:String(h.byType.fact)}),(0,n.jsx)(t0,{label:"context",value:String(h.byType.context)}),(0,n.jsx)(t0,{label:"decision",value:String(h.byType.decision)}),(0,n.jsx)(t0,{label:"preference",value:String(h.byType.preference)}),(0,n.jsx)(t0,{label:"note",value:String(h.byType.note)}),(0,n.jsx)(t0,{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,tC.qP)(h.filePath,r)})]}),(0,n.jsx)(t1,{title:"Promotion Candidates",emptyLabel:"No promotion candidates yet.",items:h.topCandidates,onPromote:$,onDismiss:P,busyAction:j}),(0,n.jsx)(t1,{title:"Recent Memory",emptyLabel:"No memory stored for this project.",items:h.recent})]}):(0,n.jsx)(tQ,{label:"Memory status unavailable."}):(0,n.jsx)(tQ,{label:"Select a project to inspect memory status."})]}),(0,n.jsxs)("section",{children:[(0,n.jsx)(tZ,{title:"Explore Tools",subtitle:`${D} running \xb7 ${tY(N)}`}),0===R.length?(0,n.jsx)(tQ,{label:"No explore tools are running."}):(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:R.map(e=>{let i,l=t===e.id,a=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:tK(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,tC.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:(i=r&&e.filePath.startsWith(r)?r:e.cwd,(0,tC.qP)(e.filePath,i))})]})]}),(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)(t0,{label:"status",value:e.status,color:tK(e.status)}),(0,n.jsx)(t0,{label:"pid",value:e.pid?String(e.pid):"-"}),(0,n.jsx)(t0,{label:"memory",value:tY(e.rssBytes)}),(0,n.jsx)(t0,{label:"uptime",value:tG(e.uptimeMs)}),(0,n.jsx)(t0,{label:"port",value:String(e.port)}),(0,n.jsx)(t0,{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:()=>o(e),style:t2,children:"Open"}),(0,n.jsx)("button",{type:"button",onClick:()=>I(t=>t===e.id?null:e.id),style:{...t2,background:a?"var(--bg-selected)":"var(--bg)"},children:"Logs"}),(0,n.jsx)("button",{type:"button",onClick:()=>void W(e),disabled:!e.running||w===e.id,style:{...t2,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"})]})]}),a&&(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 tZ({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 tQ({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 t0({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 t1({title:e,emptyLabel:t,items:r,onPromote:i,onDismiss:o,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}),(i||o)&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:[i&&(0,n.jsx)("button",{type:"button",disabled:e.promotedTo.includes("memory")||l===`${e.id}:memory`,onClick:()=>void i(e.id,"memory"),style:{...t2,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"}),o&&(0,n.jsx)("button",{type:"button",disabled:l===`dismiss:${e.id}`||l===`${e.id}:memory`,onClick:()=>void o(e.id),style:{...t2,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 t2={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 t5({tabs:e,activeTabId:t,onSelectTab:r,onCloseTab:o,onAskAI:l}){let[a,s]=(0,i.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 i=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:i?"var(--bg)":"var(--bg-panel)",cursor:"pointer",fontSize:12,color:i?"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:i?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"})}):tk(e.filePath??e.label,13)}),(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",flex:1,fontWeight:i?500:400},title:e.filePath??e.label,children:e.label}),d&&(0,n.jsxs)(n.Fragment,{children:[i&&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(),o(e.id)},onMouseEnter:()=>s(e.id),onMouseLeave:()=>s(null),style:{display:"flex",alignItems:"center",justifyContent:"center",width:16,height:16,background:a===e.id?"var(--bg-hover)":"transparent",border:"none",borderRadius:3,color:a===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 t4(e){let t=e,r=0;for(;1===t.children.length;)t=t.children[0],r++;return{node:t,skipped:r}}function t8({node:e,activePathIds:t,depth:r,isLast:i,parentLines:o,onSelect:l}){let{node:a,skipped:s}=t4(e),d=t.has(a.entry.id),c=t.has(e.entry.id)||t.has(a.entry.id),u=function(e){if("message"===e.type&&"message"in e){let t=e.message,r=t.content,n="";if("string"==typeof r?n=r:Array.isArray(r)&&(n=r.filter(e=>"text"===e.type).map(e=>e.text).join(" ")),n.length>40&&(n=n.slice(0,40)+"…"),n)return n;if("assistant"===t.role)return"[assistant]"}return e.type}(a.entry),p="message"===a.entry.type&&"message"in a.entry?a.entry.message.role:null;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",height:24,cursor:"pointer"},onClick:()=>l(a.entry.id),children:[o.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:d?"var(--accent)":c?"var(--text-muted)":"var(--border)",border:d?"none":"1px solid var(--text-dim)",marginRight:6,transition:"background 0.12s"}}),p&&(0,n.jsx)("span",{style:{fontSize:9,fontFamily:"var(--font-mono)",color:"user"===p?"var(--accent)":"var(--text-dim)",background:"user"===p?"rgba(37,99,235,0.08)":"var(--bg-hover)",border:`1px solid ${"user"===p?"rgba(37,99,235,0.2)":"var(--border)"}`,borderRadius:3,padding:"0 4px",marginRight:5,flexShrink:0,lineHeight:"16px"},children:"user"===p?"U":"A"}),s>0&&(0,n.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",marginRight:5,flexShrink:0},children:["+",s]}),(0,n.jsx)("span",{style:{fontSize:11,color:d?"var(--text)":c?"var(--text-muted)":"var(--text-dim)",fontWeight:d?500:400,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,minWidth:0},children:u})]}),a.children.map((e,s)=>(0,n.jsx)(t8,{node:e,activePathIds:t,depth:r+1,isLast:s===a.children.length-1,parentLines:[...o,!i],onSelect:l},e.entry.id))]})}function t3({tree:e,activeLeafId:t,onLeafChange:r,inline:o,containerRef:l,open:a,onToggle:s,hasSession:d,embedded:c}){let[u,p]=(0,i.useState)(!1),h=void 0!==a?a:u,x=(0,i.useRef)(null),[g,f]=(0,i.useState)(null);(0,i.useEffect)(()=>{if(!h||!o)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,o,l]);let v=(0,i.useMemo)(()=>t?new Set(function e(r,n){for(let i of r){let r=[...n,i.entry.id];if(i.entry.id===t)return r;let o=e(i.children,r);if(o)return o}return null}(e,[])??[]):new Set,[e,t]),m=(0,i.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?t4(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,t)=>(0,n.jsx)(t8,{node:e,activePathIds:v,depth:0,isLast:t===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"})]}):o?(0,n.jsxs)("div",{style:{height:"100%",display:"flex",alignItems:"stretch"},children:[(0,n.jsxs)("button",{ref:x,className:"topbar-branches-button",onClick:()=>s?s():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,t)=>(0,n.jsx)(t8,{node:e,activePathIds:v,depth:0,isLast:t===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,t)=>(0,n.jsx)(t8,{node:e,activePathIds:v,depth:0,isLast:t===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 t6(e,t="0 0 24 24"){let r=({size:r=24,style:i})=>(0,n.jsx)("svg",{width:r,height:r,viewBox:t,fill:"none",style:i,children:e});return r.displayName="ProviderIcon",r}let t7=t6((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"})),t9=t6((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"})),re=t6((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"})]})),rt=t6((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"})]})),rr=t6((0,n.jsx)("path",{d:"M4 4h16v16H4z",fill:"#F55036"}),"0 0 24 24"),rn=t6((0,n.jsx)("path",{d:"M4 4h5v5H4zm5.5 0h5v5h-5zM15 4h5v5h-5zM4 9.5h5v5H4zm5.5 5.5h5v5h-5zM15 9.5h5v5h-5z",fill:"#FA6F00"})),ri=t6((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),"0 0 24 24"),ro=t6((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"})]})),rl=t6((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",fill:"#FF5722"}),"0 0 24 24"),ra=t6((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"})),rs=t6((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"})]})),rd=t6((0,n.jsx)("path",{d:"M12 2l9 5v10l-9 5-9-5V7l9-5z",stroke:"currentColor",strokeWidth:"1.5",fill:"none"})),rc=t6((0,n.jsx)("path",{d:"M4 4l8 8 8-8M4 20l8-8 8 8",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})),ru=t6((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"})),rp={anthropic:{Icon:t7,hasColor:!1},openai:{Icon:t9,hasColor:!1},"openai-codex":{Icon:t9,hasColor:!1},google:{Icon:re,hasColor:!0},"google-vertex":{Icon:re,hasColor:!0},deepseek:{Icon:rt,hasColor:!0},groq:{Icon:rr,hasColor:!1},mistral:{Icon:rn,hasColor:!0},moonshotai:{Icon:ri,hasColor:!1},"moonshotai-cn":{Icon:ri,hasColor:!1},moonshot:{Icon:ri,hasColor:!1},minimax:{Icon:ro,hasColor:!0},"minimax-cn":{Icon:ro,hasColor:!0},fireworks:{Icon:rl,hasColor:!0},huggingface:{Icon:ra,hasColor:!0},cerebras:{Icon:rs,hasColor:!0},openrouter:{Icon:rd,hasColor:!1},xai:{Icon:rc,hasColor:!1},"cloudflare-ai-gateway":{Icon:ru,hasColor:!0},"cloudflare-workers-ai":{Icon:ru,hasColor:!0},"vercel-ai-gateway":{Icon:t6((0,n.jsx)("path",{d:"M12 2L22 20H2L12 2z",fill:"currentColor"})),hasColor:!1},"github-copilot":{Icon:t6((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),"0 0 24 24"),hasColor:!1},"amazon-bedrock":{Icon:t6((0,n.jsx)("path",{d:"M3 15h2l1-3h2l1 3h2V9H9v3L8 9H6l-1 3V9H3v6zm9 0h2v-2h2v-2h-2V9h-2v2h-2v2h2v2z",fill:"#FF9900"})),hasColor:!0},"azure-openai-responses":{Icon:t6((0,n.jsx)("path",{d:"M12 2L3 18h5l4-6 4 6h5L12 2z",fill:"#0078D4"})),hasColor:!0},"kimi-coding":{Icon:t6((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"3",fill:"#6C5CE7"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"white",fontSize:"10",fontWeight:"bold",fontFamily:"sans-serif",children:"Ki"})]})),hasColor:!0},qwen:{Icon:t6((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"3",fill:"#615CED"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"white",fontSize:"9",fontWeight:"bold",fontFamily:"sans-serif",children:"QW"})]})),hasColor:!0},zai:{Icon:t6((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"3",fill:"#3859FF"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"white",fontSize:"9",fontWeight:"bold",fontFamily:"sans-serif",children:"ZP"})]})),hasColor:!0},cohere:{Icon:t6((0,n.jsx)("path",{d:"M4 8h16v2H4zm0 4h12v2H4zm0 4h8v2H4z",fill:"#3059B1"})),hasColor:!0},perplexity:{Icon:t6((0,n.jsx)("path",{d:"M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5",stroke:"#1DB954",strokeWidth:"1.5",fill:"none",strokeLinejoin:"round"})),hasColor:!0},together:{Icon:t6((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",fill:"#0F6CBD"}),"0 0 24 24"),hasColor:!0},grok:{Icon:t6((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),"0 0 24 24"),hasColor:!1}},rh=["openai-completions","openai-responses","anthropic-messages","google-generative-ai"],rx="openai-completions",rg={off:"none",xhigh:"xhigh"};function rf(e){return e?.toLowerCase().replace(/\s+/g,"-")??""}function rv(e){return/(^|[^a-z0-9])gpt-5($|[.-])/.test(rf(e))}function rm(e){return/[.-](minimal|low|medium|high|xhigh)$/.test(rf(e))}function rb(e){return rv(e.id)||rv(e.name)}function ry(e,t=rx){if(!rb(e))return e;let r=e.api??("openai-responses"===t?void 0:"openai-responses");if(rb(e)&&(rm(e.id)||rm(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??rg}}function rj({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 rk={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 rw({value:e,onChange:t,placeholder:r,mono:i}){return(0,n.jsx)("input",{value:e,onChange:e=>t(e.target.value),placeholder:r,style:{...rk,fontFamily:i?"var(--font-mono)":"inherit"}})}function rS({value:e,onChange:t,placeholder:r,mono:o,onKeyDown:l,autoComplete:a="off",spellCheck:s=!1,style:d}){let[c,u]=(0,i.useState)(!1);return(0,i.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:{...rk,paddingRight:34,fontFamily:o?"var(--font-mono)":"inherit"},autoComplete:a,spellCheck:s}),(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 rC({value:e,onChange:t,placeholder:r}){return(0,n.jsx)("input",{type:"number",value:e,onChange:e=>t(e.target.value),placeholder:r,style:rk})}function rT({value:e,onChange:t,options:r,required:i}){return(0,n.jsxs)("select",{value:e,onChange:e=>t(e.target.value),style:{...rk,color:e?"var(--text)":"var(--text-dim)"},children:[!i&&(0,n.jsx)("option",{value:"",children:"— inherit / none —"}),r.map(e=>(0,n.jsx)("option",{value:e,children:e},e))]})}function rz({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 rI({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 rR({name:e,provider:t,onChange:r,onRename:o,onDelete:l}){let[a,s]=(0,i.useState)(e);(0,i.useEffect)(()=>s(e),[e]);let d=(e,n)=>r({...t,[e]:n});return(0,i.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)(rI,{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)(rj,{label:"Provider name",children:[(0,n.jsx)(rw,{value:a,onChange:s,placeholder:"provider-name",mono:!0}),a!==e&&a.trim()&&(0,n.jsx)("button",{onClick:()=>o(a.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)(rj,{label:"Base URL",children:(0,n.jsx)(rw,{value:t.baseUrl??"",onChange:e=>d("baseUrl",e||void 0),placeholder:"https://api.example.com/v1",mono:!0})}),(0,n.jsxs)(rj,{label:"API Key",children:[(0,n.jsx)(rS,{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)(rj,{label:"API",children:(0,n.jsx)(rT,{value:t.api??"openai-completions",onChange:e=>d("api",e),options:rh,required:!0})})]})}let rM=["off","minimal","low","medium","high","xhigh"],rL={off:"var(--text-dim)",minimal:"#6b7280",low:"#60a5fa",medium:"#a78bfa",high:"#f472b6",xhigh:"#fb923c"};function rW({value:e,onChange:t}){let r=e??{},i=(e,n)=>{let i={...r};"omit"===n?delete i[e]:i[e]=n,t(Object.keys(i).length?i:void 0)};return(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:2},children:rM.map(e=>{let t=r[e],o=e in r?null===t?"null":"string":"omit",l="string"==typeof t?t:"",a=rL[e],s={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:a,flexShrink:0,opacity:"null"===o?.3:1}}),(0,n.jsx)("span",{style:{fontSize:11,fontFamily:"var(--font-mono)",color:"null"===o?"var(--text-dim)":"var(--text-muted)",textDecoration:"null"===o?"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:()=>i(e,"omit"),style:{...s,..."omit"===o?d:{}},children:"Default"}),(0,n.jsx)("button",{onClick:()=>i(e,null),style:{...s,borderLeft:"1px solid var(--border)",..."null"===o?{background:"#ef4444",color:"#fff",fontWeight:600}:{}},children:"Disabled"})]}),(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,border:`1px solid ${"string"===o?"var(--accent)":"var(--border)"}`,overflow:"hidden",transition:"border-color 0.1s"},children:[(0,n.jsx)("button",{onClick:()=>i(e,l||e),style:{...s,..."string"===o?d:{},borderRight:"1px solid var(--border)",flexShrink:0},children:"Custom"}),(0,n.jsx)("input",{value:l,onChange:t=>i(e,t.target.value),onFocus:()=>{"string"!==o&&i(e,l||e)},placeholder:e,maxLength:10,style:{width:"12ch",background:"string"===o?"var(--bg)":"var(--bg-panel)",border:"none",outline:"none",color:"string"===o?"var(--text)":"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11,padding:"4px 7px",transition:"background 0.1s, color 0.1s"}})]})]},e)})})}let rE={thinkingFormat:"deepseek",requiresReasoningContentOnAssistantMessages:!0};function r$({providerName:e,provider:t,model:r,onChange:o,onDelete:l}){let[a,s]=(0,i.useState)({phase:"idle"}),d=(e,t)=>o({...r,[e]:t}),c=e=>{o(ry(e,t.api??rx))},u=(()=>{if("idle"===a.phase)return null;if("testing"===a.phase)return"Testing model connection...";let e=[void 0!==a.latencyMs?`${a.latencyMs}ms`:null,void 0!==a.status?`HTTP ${a.status}`:null].filter(Boolean);return"success"===a.phase?["Connected",...e,a.responseText||null].filter(Boolean).join(" \xb7 "):["Failed",...e,a.message].filter(Boolean).join(" \xb7 ")})();(0,i.useEffect)(()=>{s({phase:"idle"})},[e,t.baseUrl,t.api,t.apiKey,r.id,r.api]);let p=(0,i.useCallback)(async()=>{if(r.id.trim()&&"testing"!==a.phase){s({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})}),i=await n.json();if(!n.ok||!i.ok)return void s({phase:"error",message:i.error??`HTTP ${n.status}`,latencyMs:i.latencyMs,status:i.status});s({phase:"success",latencyMs:i.latencyMs,status:i.status,responseText:i.responseText})}catch(e){s({phase:"error",message:e instanceof Error?e.message:String(e)})}}},[r,t,e,a.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)(rI,{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"===a.phase?"#fecaca":"success"===a.phase?"#bbf7d0":"var(--border)"}`,borderRadius:4,background:"error"===a.phase?"#fee2e2":"success"===a.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"===a.phase,title:"Test model connection",style:{height:24,padding:"0 8px",background:"success"===a.phase?"#16a34a":"none",border:`1px solid ${"success"===a.phase?"#16a34a":"var(--border)"}`,borderRadius:4,color:"success"===a.phase?"#fff":r.id.trim()&&"testing"!==a.phase?"var(--text-muted)":"var(--text-dim)",cursor:r.id.trim()&&"testing"!==a.phase?"pointer":"not-allowed",fontSize:11,display:"inline-flex",alignItems:"center",justifyContent:"center",boxSizing:"border-box",gap:5},children:["success"===a.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"===a.phase?"Testing…":"success"===a.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)(rj,{label:"ID *",children:(0,n.jsx)(rw,{value:r.id,onChange:e=>c({...r,id:e}),placeholder:"model-id",mono:!0})}),(0,n.jsx)(rj,{label:"Name",children:(0,n.jsx)(rw,{value:r.name??"",onChange:e=>c({...r,name:e||void 0}),placeholder:"Display name"})})]}),(0,n.jsx)(rj,{label:"API override",children:(0,n.jsx)(rT,{value:r.api??"",onChange:e=>d("api",e||void 0),options:rh})}),(0,n.jsxs)("div",{style:{display:"flex",gap:20,flexWrap:"wrap"},children:[(0,n.jsx)(rz,{label:"Reasoning / thinking",checked:r.reasoning??!1,onChange:e=>d("reasoning",e||void 0)}),(0,n.jsx)(rz,{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)(rz,{label:"DeepSeek thinking compat",checked:r.compat?.thinkingFormat==="deepseek",onChange:e=>o(function(e,t){if(t)return{...e,compat:{...e.compat??{},...rE}};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)(rI,{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)(rW,{value:r.thinkingLevelMap,onChange:e=>d("thinkingLevelMap",e)})]})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[(0,n.jsx)(rj,{label:"Context window (tokens)",children:(0,n.jsx)(rC,{value:void 0!==r.contextWindow?String(r.contextWindow):"",onChange:e=>d("contextWindow",e?parseInt(e):void 0),placeholder:"128000"})}),(0,n.jsx)(rj,{label:"Max output tokens",children:(0,n.jsx)(rC,{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)(rI,{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)(rj,{label:e,children:(0,n.jsx)(rC,{value:r.cost?.[e]!==void 0?String(r.cost[e]):"",onChange:t=>{let n;return n=parseFloat(t),void o({...r,cost:{...r.cost??{},[e]:isNaN(n)?void 0:n}})},placeholder:"0"})},e))})]})]})}function rP({provider:e,onRefresh:t}){let[r,o]=(0,i.useState)({phase:"idle"}),[l,a]=(0,i.useState)(""),s=(0,i.useRef)(null),d=(0,i.useRef)(null);(0,i.useEffect)(()=>{("auth"===r.phase||"prompt"===r.phase)&&setTimeout(()=>d.current?.focus(),50)},[r.phase]),(0,i.useEffect)(()=>{o({phase:"idle"}),a(""),s.current?.close(),s.current=null},[e.id]),(0,i.useEffect)(()=>()=>{s.current?.close()},[]);let c=(0,i.useCallback)(()=>{s.current?.close(),o({phase:"connecting"}),a("");let r=new EventSource(`/api/auth/login/${encodeURIComponent(e.id)}`);s.current=r,r.onmessage=e=>{let n=JSON.parse(e.data);"auth"===n.type?(o({phase:"auth",url:n.url,instructions:n.instructions??null,token:n.token}),window.open(n.url,"_blank","noopener,noreferrer")):"device_code"===n.type?(o({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?o({phase:"prompt",message:n.message,placeholder:n.placeholder??null,token:n.token}):"select_request"===n.type?o({phase:"select",message:n.message,options:n.options??[],token:n.token}):"progress"===n.type?o({phase:"progress",message:n.message}):"success"===n.type?(r.close(),o({phase:"success"}),t()):"error"===n.type?(r.close(),o({phase:"error",message:n.message})):"cancelled"===n.type&&(r.close(),o({phase:"idle"}))},r.onerror=()=>{r.close(),o(e=>"success"===e.phase?e:{phase:"error",message:"Connection lost"})}},[e.id,t]),u=(0,i.useCallback)(async()=>{await fetch(`/api/auth/logout/${encodeURIComponent(e.id)}`,{method:"POST"}),o({phase:"idle"}),t()},[e.id,t]),p=(0,i.useCallback)(async(t,r)=>{if(r.trim()){o({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(()=>({}));o({phase:"error",message:e.error??`Server error ${n.status}`});return}a("")}catch(e){o({phase:"error",message:e instanceof Error?e.message:"Network error"})}}},[e.id]),h=(0,i.useCallback)(async(t,r)=>{o({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(()=>({}));o({phase:"error",message:e.error??`Server error ${n.status}`})}}catch(e){o({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)(rI,{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=>a(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:()=>{s.current?.close(),o({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 rD({provider:e,onRefresh:t}){let[r,o]=(0,i.useState)(""),[l,a]=(0,i.useState)(!1),[s,d]=(0,i.useState)(!1),[c,u]=(0,i.useState)(null),[p,h]=(0,i.useState)(!1);(0,i.useEffect)(()=>{o(""),u(null),h(!1)},[e.id]);let x=(0,i.useCallback)(async()=>{if(r.trim()){a(!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()})}),i=await n.json();!n.ok||i.error?u(i.error??`HTTP ${n.status}`):(o(""),h(!0),setTimeout(()=>h(!1),2e3),t())}catch(e){u(String(e))}finally{a(!1)}}},[r,e.id,t]),g=(0,i.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)(rI,{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)(rj,{label:"API Key",children:(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsx)(rS,{value:r,onChange:o,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:s,style:{alignSelf:"flex-start",padding:"5px 12px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:5,color:"#ef4444",cursor:s?"not-allowed":"pointer",fontSize:12},children:s?"Removing…":"Disconnect"})]})}function rN({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 rB({oauthProviders:e,apiKeyProviders:t,onSelectOAuth:r,onSelectApiKey:o,onAddCustom:l,onDiscover:a,onClose:s}){let[d,c]=(0,i.useState)(""),u=(0,i.useRef)(null);(0,i.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&&s()},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&&s()},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(),s()},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:()=>{a(),s()},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),s()},style:m,onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.background="var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:"OAuth"})]}),(0,n.jsx)(rN,{id:e.id,size:28})]},e.id)),x.length>0&&(0,n.jsx)("div",{style:{gridColumn:"1 / -1",paddingTop:6*(h.length>0),fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"API Key"}),x.map(e=>(0,n.jsxs)("button",{onClick:()=>{o(e.id),s()},style:m,onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.background="var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.displayName}),(0,n.jsxs)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:[e.modelCount," models"]})]}),(0,n.jsx)(rN,{id:e.id,size:28})]},e.id))]})})]})})}function rO({existingProviders:e,onImport:t,onClose:r}){let[o,l]=(0,i.useState)(""),[a,s]=(0,i.useState)(""),[d,c]=(0,i.useState)("custom-provider"),[u,p]=(0,i.useState)(new Set),[h,x]=(0,i.useState)({phase:"idle"}),g=(0,i.useCallback)(async()=>{let e=o.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:a,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)})}}},[a,o,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)(rj,{label:"Base URL",children:(0,n.jsx)(rw,{value:o,onChange:l,placeholder:"https://api.example.com",mono:!0})}),(0,n.jsx)(rj,{label:"API Key",children:(0,n.jsx)(rS,{value:a,onChange:s,placeholder:"optional for local providers",mono:!0})}),(0,n.jsx)(rj,{label:"Provider name",children:(0,n.jsx)(rw,{value:d,onChange:c,placeholder:"provider-name",mono:!0})}),(0,n.jsx)("button",{onClick:g,disabled:!o.trim()||"loading"===h.phase,style:{height:31,padding:"0 14px",background:o.trim()&&"loading"!==h.phase?"var(--accent)":"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:5,color:o.trim()&&"loading"!==h.phase?"#fff":"var(--text-dim)",cursor:o.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],i=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:i?"var(--bg-subtle)":"transparent",cursor:"pointer"},children:[(0,n.jsx)("input",{type:"checkbox",checked:i,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=o.trim().replace(/\/+$/,""),i=a.trim(),l=Object.entries(e).find(([,e])=>(e.baseUrl??"").replace(/\/+$/,"")===n&&(e.apiKey??"")===i),s=l?.[0]??d.trim(),c=e[s],p=new Map((c?.models??[]).map(e=>[e.id,e])),h=c?.api??rx,x=0;for(let e of f.piModels)u.has(e.id)&&!p.has(e.id)&&(p.set(e.id,ry(e,h)),x+=1);t(s,{...c??{},baseUrl:n,api:h,...i?{apiKey:i}:{},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 rA({onClose:e,embedded:t=!1}){let[r,o]=(0,i.useState)({providers:{}}),[l,a]=(0,i.useState)(!0),[s,d]=(0,i.useState)(!1),[c,u]=(0,i.useState)(null),[p,h]=(0,i.useState)(null),[x,g]=(0,i.useState)(!1),[f,v]=(0,i.useState)(null),[m,b]=(0,i.useState)([]),[y,j]=(0,i.useState)([]),[k,w]=(0,i.useState)(!1),[S,C]=(0,i.useState)(!1),T=(0,i.useCallback)(()=>{fetch("/api/auth/providers").then(e=>e.json()).then(e=>b(e.providers)).catch(()=>{})},[]),z=(0,i.useCallback)(()=>{fetch("/api/auth/all-providers").then(e=>e.json()).then(e=>j(e.providers)).catch(()=>{})},[]);(0,i.useEffect)(()=>{fetch("/api/models-config").then(e=>e.json()).then(e=>{let t=e.providers?e:{...e,providers:{}};o(t);let r=Object.keys(t.providers??{});r.length>0&&v({type:"provider",name:r[0]})}).catch(()=>o({providers:{}})).finally(()=>a(!1)),T(),z()},[T,z]);let I=(0,i.useCallback)(()=>{let e="new-provider",t=1;for(;r.providers?.[e];)e=`new-provider-${t++}`;o(t=>({...t,providers:{...t.providers??{},[e]:{api:"openai-completions"}}})),v({type:"provider",name:e})},[r.providers]),R=(0,i.useCallback)((e,t)=>{o(r=>({...r,providers:{...r.providers??{},[e]:t}}))},[]),M=(0,i.useCallback)((e,t)=>{o(r=>{let n=Object.entries(r.providers??{}),i=n.findIndex(([t])=>t===e);return -1===i?r:(n[i]=[t,n[i][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,i.useCallback)(e=>{o(t=>{let r={...t.providers??{}};return delete r[e],{...t,providers:r}}),o(e=>{let t=Object.keys(e.providers??{});return v(t.length>0?{type:"provider",name:t[0]}:null),e})},[]),W=(0,i.useCallback)(e=>{o(t=>{let r=t.providers?.[e]??{},n=[...r.models??[],{id:""}];return{...t,providers:{...t.providers??{},[e]:{...r,models:n}}}}),o(t=>{let r=(t.providers?.[e]?.models?.length??1)-1;return v({type:"model",providerName:e,index:r}),t})},[]),E=(0,i.useCallback)((e,t,r)=>{o(n=>{let i=n.providers?.[e]??{},o=[...i.models??[]];return o[t]=r,{...n,providers:{...n.providers??{},[e]:{...i,models:o}}}})},[]),$=(0,i.useCallback)((e,t)=>{o(r=>{let n=r.providers?.[e]??{},i=[...n.models??[]];return i.splice(t,1),{...r,providers:{...r.providers??{},[e]:{...n,models:i.length?i:void 0}}}}),v({type:"provider",name:e})},[]),P=(0,i.useCallback)((e,t,r)=>{o(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,i.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??{}),B=m.filter(e=>e.loggedIn),O=y.filter(e=>e.configured),A=(()=>{if(!f)return null;if("oauth"===f.type){let e=m.find(e=>e.id===f.providerId);return e?(0,n.jsx)(rP,{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)(rD,{provider:e,onRefresh:z},e.id):null}if("provider"===f.type){let e=r.providers?.[f.name];return e?(0,n.jsx)(rR,{name:f.name,provider:e,onChange:e=>R(f.name,e),onRename:e=>M(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)(r$,{providerName:f.providerName,provider:e,model:t,onChange:e=>E(f.providerName,f.index,e),onDelete:()=>$(f.providerName,f.index)},`${f.providerName}-${f.index}`):null})();return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{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:[B.map(e=>{let t=f?.type==="oauth"&&f.providerId===e.id;return(0,n.jsxs)("div",{onClick:()=>v({type:"oauth",providerId:e.id}),style:{display:"flex",alignItems:"center",gap:7,padding:"5px 8px",borderRadius:5,cursor:"pointer",background:t?"var(--bg-selected)":"none"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,n.jsx)(rN,{id:e.id,size:16}),(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name})]},e.id)}),O.map(e=>{let t=f?.type==="apikey"&&f.providerId===e.id;return(0,n.jsxs)("div",{onClick:()=>v({type:"apikey",providerId:e.id}),style:{display:"flex",alignItems:"center",gap:7,padding:"5px 8px",borderRadius:5,cursor:"pointer",background:t?"var(--bg-selected)":"none"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,n.jsx)(rN,{id:e.id,size:16}),(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.displayName})]},e.id)}),(B.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,i=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})]}),i.map((t,r)=>{let i=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:i?"var(--bg-selected)":"none"},onMouseEnter:e=>{i||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{i||(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:A??(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:"Select a provider or model"})})]}),(0,n.jsxs)("div",{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:s||x,style:{position:"relative",padding:"6px 16px",minWidth:92,background:x?"#16a34a":s?"var(--bg-panel)":"var(--accent)",border:"none",borderRadius:6,color:x?"#fff":s?"var(--text-muted)":"#fff",cursor:s||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":s?"Saving…":"Save"})]})]})]})}),k&&(0,n.jsx)(rB,{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)(rO,{existingProviders:r.providers??{},onImport:P,onClose:()=>C(!1)})]})}function rH(e){return`${e.scope}\0${e.package}`}function rF(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function rU(e){let t=e.sourceInfo?.source,r=e.sourceInfo?.scope;return"user"===r||"user"===t?"global":"project"===r||"project"===t?"project":"path"}function rq({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 r_({skill:e,cwd:t,onToggle:r,toggling:i,saveError:o,update:l,updating:a,updateError:s,onUpdate:d}){let c=rU(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 rF(e)}(e.filePath)}),(0,n.jsx)(rq,{enabled:u,loading:i,onToggle:()=>r(e)}),o&&(0,n.jsx)("span",{style:{fontSize:12,color:"#f87171",flexShrink:0},children:o})]}),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:a,style:{padding:"3px 10px",fontSize:12,borderRadius:5,border:"1px solid var(--border)",background:"rgba(217,119,6,0.12)",color:"#b45309",cursor:a?"wait":"pointer"},children:a?"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"}),s&&(0,n.jsx)("span",{style:{color:"#f87171",maxWidth:520,whiteSpace:"pre-wrap",wordBreak:"break-word",fontSize:11},children:s})]}),(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 rJ({cwd:e,onInstalled:t}){let[r,o]=(0,i.useState)(""),[l,a]=(0,i.useState)([]),[s,d]=(0,i.useState)(!1),[c,u]=(0,i.useState)(null),[p,h]=(0,i.useState)(null),[x,g]=(0,i.useState)(null),[f,v]=(0,i.useState)(null),[m,b]=(0,i.useState)([]),[y,j]=(0,i.useState)(new Set),[k,w]=(0,i.useState)("global"),S=(0,i.useRef)(null),C=(0,i.useRef)(null);(0,i.useEffect)(()=>{S.current?.focus()},[]),(0,i.useEffect)(()=>()=>{C.current?.abort()},[]);let T=(0,i.useCallback)(async e=>{if(e.trim()){d(!0),u(null),a([]);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);a(r.results??[]),0===(r.results??[]).length&&u("No skills found")}catch(e){u(String(e))}finally{d(!1)}}},[]),z=(0,i.useCallback)(async r=>{let n=new AbortController;C.current=n,h(r),g(null),v("Starting installer"),b(["Starting installer"]);try{let i=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(!i.ok||!i.body){let e=await i.json().catch(()=>null);g(e?.error??`HTTP ${i.status}`);return}let o=i.body.getReader(),l=new TextDecoder,a="",s=!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?(s=!0,v("Installed"),b(e=>[...e,"Installed"].slice(-8))):"error"===e.type&&g(e.error??"Install failed")};for(;;){let{value:e,done:t}=await o.read(),r=(a+=l.decode(e??new Uint8Array,{stream:!t})).split("\n");for(let e of(a=r.pop()??"",r))e.trim()&&d(JSON.parse(e));if(t)break}a.trim()&&d(JSON.parse(a)),s&&(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,i.useCallback)(()=>{C.current?.abort()},[]),R="global"===k?"~/.pi/agent/skills/":`${rF(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=>o(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:s||!r.trim(),style:{padding:"7px 16px",fontSize:13,borderRadius:6,border:"none",background:"var(--accent)",color:"#fff",cursor:s||!r.trim()?"not-allowed":"pointer",opacity:s||!r.trim()?.5:1,flexShrink:0},children:s?"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:["→ ",R]})]}),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,i=e.package.indexOf("@"),o=i>-1?e.package.slice(0,i):e.package,l=i>-1?e.package.slice(i+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??o}),(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:o}),(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&&!s&&(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 rK({cwd:e,onClose:t,embedded:r=!1}){let[o,l]=(0,i.useState)([]),[a,s]=(0,i.useState)(!0),[d,c]=(0,i.useState)(null),[u,p]=(0,i.useState)(null),[h,x]=(0,i.useState)(new Set),[g,f]=(0,i.useState)(null),[v,m]=(0,i.useState)(!1),[b,y]=(0,i.useState)({}),[j,k]=(0,i.useState)(!1),[w,S]=(0,i.useState)(!1),[C,T]=(0,i.useState)(null),[z,I]=(0,i.useState)(null),[R,M]=(0,i.useState)(null),L=(0,i.useCallback)(()=>{s(!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(()=>s(!1))},[e,u]);(0,i.useEffect)(()=>{y({}),S(!1),T(null),M(null),L()},[e]),(0,i.useEffect)(()=>{M(null)},[u]);let W=(0,i.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})}),i=await n.json();if(!n.ok||i.error)return void f(i.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,i.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]),$=(0,i.useCallback)(async t=>{let r=t.install;if(r){I(rH(r)),M(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 M(n.error??`HTTP ${t.status}`);let i=await fetch("/api/skills/check",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,package:r.package,scope:r.scope})}),o=await i.json(),l=o.updates?.[0];l&&y(e=>({...e,[rH(l)]:l})),await L()}catch(e){M(String(e))}finally{I(null)}}},[e,L]),P=o.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:rF(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:a?(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===o.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=o.filter(e=>rU(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,i=e.install?b[rH(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}),i?.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||a||0===o.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||a||0===o.length?"not-allowed":"pointer",opacity:a||0===o.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)(rJ,{cwd:e,onInstalled:()=>{L()}}):a?null:P?(0,n.jsx)(r_,{skill:P,cwd:e,onToggle:W,toggling:h.has(P.filePath),saveError:g,update:P.install?b[rH(P.install)]:void 0,updating:!!P.install&&z===rH(P.install),updateError:R,onUpdate:()=>$(P)},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 rV=[{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 rY(e){return e?e.replace(/^\/(?:Users|home)\/[^/]+/,"~"):""}function rG(e){if(e<=0)return"never";let t=e/60/1e3;if(t<60)return`${Math.round(t)}m`;let r=t/60;return Number.isInteger(r)?`${r}h`:`${r.toFixed(1)}h`}function rX(e){return{id:"",language:e,displayName:"",command:"python"===e?"python3":"R",argsText:JSON.stringify("python"===e?["-u"]:["--slave","--vanilla"]),envText:"{}"}}function rZ(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 rQ={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"},r0={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 r1({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 r2({cwd:e}){let[t,r]=(0,i.useState)("python"),[o,l]=(0,i.useState)(null),[a,s]=(0,i.useState)(!0),[d,c]=(0,i.useState)(null),[u,p]=(0,i.useState)(null),[h,x]=(0,i.useState)(null),[g,f]=(0,i.useState)([]),[v,m]=(0,i.useState)(null),[b,y]=(0,i.useState)("view"),[j,k]=(0,i.useState)(()=>rX("python")),[w,S]=(0,i.useState)(1728e5),[C,T]=(0,i.useState)("pdf"),[z,I]=(0,i.useState)(300),[R,M]=(0,i.useState)(800),[L,W]=(0,i.useState)(600),[E,$]=(0,i.useState)(!1),P=(0,i.useCallback)(async()=>{s(!0),p(null);try{let r=e?`?cwd=${encodeURIComponent(e)}`:"",n=await fetch(`/api/plot-kernels${r}`),i=await n.json();if(!n.ok||i.error)throw Error(i.error??`HTTP ${n.status}`);l(i),f([]),x(null),m(e=>{if(e&&i.kernels.some(t=>t.id===e))return e;let r=i.kernels.find(e=>e.language===t&&e.isEffective);return r?.id??i.kernels.find(e=>e.language===t)?.id??null})}catch(e){p(e instanceof Error?e.message:String(e))}finally{s(!1)}},[e,t]);(0,i.useEffect)(()=>{P()},[P]),(0,i.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),e||("string"==typeof t.settings?.saveFormat&&["pdf","png","svg"].includes(t.settings.saveFormat)&&T(t.settings.saveFormat),"number"==typeof t.settings?.saveDpi&&I(t.settings.saveDpi),"number"==typeof t.settings?.saveWidth&&M(t.settings.saveWidth),"number"==typeof t.settings?.saveHeight&&W(t.settings.saveHeight))}).catch(()=>{}),()=>{e=!0}},[]);let D=(0,i.useMemo)(()=>(o?.kernels??[]).filter(e=>e.language===t),[t,o?.kernels]),N=D.find(e=>e.id===v)??null;(0,i.useEffect)(()=>{if("new"===b)return void k(rX(t));let e=N??D.find(e=>e.isEffective)??D[0]??null;e?(v!==e.id&&m(e.id),k(rZ(e)),y("view")):(m(null),k(rX(t)),y("new"))},[t,o?.kernels]);let B=(0,i.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]),O=(0,i.useCallback)(async e=>{let t=await B({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`:""}.`)},[B]),A=(0,i.useCallback)(async e=>{await B({action:"select",language:e.language,kernelId:e.id},"select")&&x(`Selected ${e.displayName} for this project.`)},[B]),H=(0,i.useCallback)(async e=>{await B({action:"setDefault",language:e.language,kernelId:e.id},"default")&&x(`Set ${e.displayName} as global default.`)},[B]),F=(0,i.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 B({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,B]),U=(0,i.useCallback)(async e=>{let r=await B({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,B]),q=()=>{y("new"),m(null),k(rX(t)),p(null),x(null)},_=(0,i.useCallback)(async e=>{S(e),$(!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 ${rG(r.settings.plotIdleTimeoutMs)}.`))}catch(e){S(w),p(e instanceof Error?e.message:String(e))}finally{$(!1)}},[w]),J=(0,i.useCallback)(async()=>{$(!0),p(null);try{let e=await fetch("/api/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:{saveFormat:C,saveDpi:z,saveWidth:R,saveHeight:L}})}),t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);x("Save defaults updated.")}catch(e){p(e instanceof Error?e.message:String(e))}finally{$(!1)}},[C,z,R,L]);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 i=t===e;return(0,n.jsx)("button",{type:"button",onClick:()=>r(e),style:{height:26,padding:"0 12px",border:"none",borderRadius:5,background:i?"var(--bg)":"transparent",color:i?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:i?600:500},children:"python"===e?"Python":"R"},e)})}),(0,n.jsxs)("button",{type:"button",onClick:()=>void O(t),disabled:!!d,style:{...rQ,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 O("all"),disabled:!!d,style:{...rQ,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:rV.map(e=>{let t=w===e.value;return(0,n.jsx)("button",{type:"button",onClick:()=>{t||_(e.value)},disabled:E,title:`Close inactive kernels after ${rG(e.value)}`,style:{height:24,padding:"0 8px",border:"none",borderRadius:5,background:t?"var(--bg)":"transparent",color:t?"var(--accent)":"var(--text-muted)",cursor:E?"default":"pointer",fontSize:11,fontWeight:t?700:500,opacity:E?.65:1},children:e.label},e.label)})})]}),(0,n.jsxs)("button",{type:"button",onClick:q,style:{...rQ,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"]})]}),(0,n.jsxs)("div",{style:{flexShrink:0,padding:"10px 16px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,n.jsx)("span",{style:{fontSize:12,fontWeight:700,color:"var(--text)"},children:"Save defaults"}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:"Format"}),(0,n.jsx)("div",{style:{display:"flex",padding:2,border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-panel)"},children:["pdf","png","svg"].map(e=>{let t=C===e;return(0,n.jsx)("button",{type:"button",onClick:()=>T(e),style:{height:24,padding:"0 8px",border:"none",borderRadius:5,background:t?"var(--bg)":"transparent",color:t?"var(--accent)":"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:t?700:500},children:e.toUpperCase()},e)})}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:"DPI"}),(0,n.jsx)("input",{type:"number",value:z,onChange:e=>I(Number(e.target.value)||300),min:72,max:1200,style:{width:60,height:26,padding:"0 6px",fontSize:11,border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:"var(--text)"}}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:"W"}),(0,n.jsx)("input",{type:"number",value:R,onChange:e=>M(Number(e.target.value)||800),min:100,max:8e3,style:{width:65,height:26,padding:"0 6px",fontSize:11,border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:"var(--text)"}}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:"H"}),(0,n.jsx)("input",{type:"number",value:L,onChange:e=>W(Number(e.target.value)||600),min:100,max:8e3,style:{width:65,height:26,padding:"0 6px",fontSize:11,border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:"var(--text)"}}),(0,n.jsx)("button",{type:"button",onClick:()=>void J(),disabled:E,style:{...rQ,background:"var(--accent)",borderColor:"var(--accent)",color:"#fff",opacity:E?.6:1},children:E?"Saving...":"Save"})]}),(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:rY(o?.paths.global??"")})]}),e&&(0,n.jsxs)("div",{children:["Project: ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:rY(o?.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:a?(0,n.jsx)("div",{style:{padding:"10px 8px",color:"var(--text-muted)",fontSize:12},children:"Loading..."}):0===D.length?(0,n.jsx)("div",{style:{padding:"10px 8px",color:"var(--text-dim)",fontSize:12},children:"No kernels found"}):D.map(e=>{let t=v===e.id&&"new"!==b;return(0,n.jsxs)("button",{type:"button",onClick:()=>{m(e.id),y("view"),k(rZ(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()}(o?.scanCache?.lastScan)]})]}),(0,n.jsx)("div",{style:{flex:1,minWidth:0,minHeight:0,overflowY:"auto",padding:18},children:"view"===b&&N?(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:N.displayName}),N.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:N.id})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:12},children:[(0,n.jsx)(r1,{label:"Command",children:(0,n.jsx)("input",{readOnly:!0,value:N.command,style:{...r0,color:"var(--text-muted)"}})}),(0,n.jsx)(r1,{label:"Args",children:(0,n.jsx)("input",{readOnly:!0,value:JSON.stringify(N.args),style:{...r0,color:"var(--text-muted)"}})})]}),(0,n.jsx)(r1,{label:"Environment",children:(0,n.jsx)("textarea",{readOnly:!0,value:JSON.stringify(N.env,null,2),rows:5,style:{...r0,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 A(N),disabled:!e||"select"===d,style:{...rQ,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 H(N),disabled:"default"===d,style:{...rQ,opacity:"default"===d?.6:1},children:"Set default"}),(0,n.jsx)("button",{type:"button",onClick:()=>{y("edit"),m(N.id),k(rZ(N)),p(null),x(null)},style:rQ,children:"Edit"}),!N.id.startsWith("default-")&&(0,n.jsx)("button",{type:"button",onClick:()=>void U(N),disabled:"delete"===d,style:{...rQ,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)(r1,{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:{...r0,color:"edit"===b?"var(--text-muted)":"var(--text)"}})}),(0,n.jsx)(r1,{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:r0})})]}),(0,n.jsx)(r1,{label:"Command",children:(0,n.jsx)("input",{value:j.command,onChange:e=>k(t=>({...t,command:e.target.value})),placeholder:"/usr/bin/python3",style:r0})}),(0,n.jsx)(r1,{label:"Args JSON",children:(0,n.jsx)("input",{value:j.argsText,onChange:e=>k(t=>({...t,argsText:e.target.value})),style:r0})}),(0,n.jsx)(r1,{label:"Env JSON",children:(0,n.jsx)("textarea",{value:j.envText,onChange:e=>k(t=>({...t,envText:e.target.value})),rows:6,style:{...r0,resize:"vertical"}})}),(0,n.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,n.jsx)("button",{type:"button",onClick:()=>void F(),disabled:"save"===d,style:{...rQ,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=N??D.find(e=>e.isEffective)??D[0]??null;e?(m(e.id),k(rZ(e)),y("view")):q(),p(null)},style:rQ,children:"Cancel"})]})]})})]})]})}var r5=r(7834);function r4({text:e,label:t="Copy",title:r,onCopied:o,onError:l}){let[a,s]=(0,i.useState)(!1);(0,i.useEffect)(()=>{if(!a)return;let e=setTimeout(()=>s(!1),1500);return()=>clearTimeout(e)},[a]);let d=(0,i.useCallback)(async()=>{try{await (0,r5.D)(e),s(!0),o?.()}catch(e){l?.(e instanceof Error?e:Error(String(e)))}},[o,l,e]);return(0,n.jsx)("button",{type:"button",onClick:()=>void d(),title:r??(a?"Copied":t),style:{height:24,padding:"0 8px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg-hover)",color:a?"#22c55e":"var(--text-muted)",fontSize:10,fontWeight:600,cursor:"pointer",flexShrink:0},children:a?"Copied":t})}r(41463);let r8="annovibe-im-gateway";function r3({cwd:e,embedded:t=!1}){let[r,o]=(0,i.useState)(null),[l,a]=(0,i.useState)(null),[s,d]=(0,i.useState)(null),[c,u]=(0,i.useState)(""),[p,h]=(0,i.useState)(""),[x,g]=(0,i.useState)(!1),[f,v]=(0,i.useState)(""),[m,b]=(0,i.useState)(""),[y,j]=(0,i.useState)(!1),[k,w]=(0,i.useState)(!1),[S,C]=(0,i.useState)(!1),[T,z]=(0,i.useState)(null),[I,R]=(0,i.useState)(null),M=(0,i.useCallback)((e,t)=>{"success"===t?(R(e),z(null),setTimeout(()=>R(null),4500)):(z(e),R(null))},[]),L=(0,i.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,i.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}`);o(r),a(r.gatewayToken??null),u(r.botId),g(r.requireMentionInGroup),v(r.boundChatId??""),b(r.allowedUsers.join("\n")),h("")}catch(e){M(e instanceof Error?e.message:String(e),"error")}finally{j(!1)}},[e,M]);(0,i.useEffect)(()=>{W()},[W]),(0,i.useEffect)(()=>{if(!r?.enabled)return void d(null);L();let e=setInterval(()=>{L()},12e3);return()=>clearInterval(e)},[r?.enabled,L]);let E=(0,i.useCallback)(async t=>{w(!0),z(null),R(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}`);o(n),a(n.gatewayToken??null),h(""),M("IM settings saved.","success")}catch(e){M(e instanceof Error?e.message:String(e),"error")}finally{w(!1)}},[e,M]),$=(0,i.useCallback)(e=>{E({enabled:e,botId:c.trim(),botSecret:p.trim()||void 0,requireMentionInGroup:x,boundChatId:f.trim()||null,allowedUsers:ne(m)})},[c,p,x,f,m,E]),P=(0,i.useCallback)(()=>{E({enabled:r?.enabled??!1,botId:c.trim(),botSecret:p.trim()||void 0,requireMentionInGroup:x,boundChatId:f.trim()||null,allowedUsers:ne(m)})},[r?.enabled,c,p,x,f,m,E]),D=(0,i.useCallback)(()=>{E({regeneratePairingCode:!0})},[E]),N=(0,i.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}`);o(e=>e?{...e,sessionId:null}:null),M("IM thread reset.","success")}catch(e){M(e instanceof Error?e.message:String(e),"error")}finally{C(!1)}}},[r?.sessionId,e,M]);if(y&&!r)return(0,n.jsx)(nn,{label:"Loading IM settings..."});let B=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)(r9,{label:"WeCom bot for this project",description:B?"启动 im-gateway 后即可通过企业微信 AI bot 与此项目交互。":"关闭 — 开启后可绑定企业微信 bot 到此项目。",checked:B,disabled:k,onChange:$}),B?(0,n.jsxs)(n.Fragment,{children:[s?(0,n.jsx)(r6,{status:s}):null,(0,n.jsx)(nt,{label:"Bot ID",value:c,onChange:u,placeholder:"从企业微信 AI bot 控制台获取"}),(0,n.jsx)(nt,{label:r?.hasSecret?"Bot Secret(留空则不修改)":"Bot Secret",value:p,onChange:h,placeholder:r?.hasSecret?"留空保留现有 secret":"从企业微信 AI bot 控制台获取",secret:!0}),(0,n.jsx)(r9,{label:"群聊中需要 @提及 bot 才响应",description:"开启后,群聊中用户必须 @bot 才会被处理。",checked:x,disabled:k,compact:!0,onChange:g}),(0,n.jsx)(nt,{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:nl,placeholder:"用户也可通过配对码自助授权"})]}),(0,n.jsxs)("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[(0,n.jsx)(nr,{primary:!0,disabled:k,onClick:P,children:k?"保存中…":"保存 IM 配置"}),(0,n.jsx)(nr,{disabled:k,onClick:D,children:"重新生成配对码"})]})]}):null]}),B&&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)(r7,{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)(nr,{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)(r7,{label:"Gateway 启动命令",value:r8,copyLabel:"复制命令",mono:!0}),(0,n.jsxs)("div",{style:{lineHeight:1.55,color:"var(--text-dim)"},children:["启动 ",(0,n.jsx)("code",{style:ni,children:"annovibe"})," 后,在",(0,n.jsx)("strong",{style:{color:"var(--text-muted)",fontWeight:600},children:"同一 Linux 账户"}),"中运行"," ",(0,n.jsx)("code",{style:ni,children:r8}),"。 Gateway 通过本地 API 读取已启用的项目配置和 bot secret —— 无需手动复制文件。"]}),(0,n.jsxs)("div",{style:{lineHeight:1.55,color:"var(--text-dim)"},children:["配置文件: ",(0,n.jsxs)("code",{style:ni,children:["<project>","/.annovibe/im.json"]})," \xb7 Secrets: ",(0,n.jsx)("code",{style:ni,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 r6({status:e}){var t,r,i,o;let l=function(e){if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}(e.startedAt),a=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"===(i=e.tone)?"#22c55e":"stale"===i?"#f59e0b":"#f87171"}}),(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:11,fontWeight:650,color:"running"===(o=e.tone)?"#22c55e":"stale"===o?"#f59e0b":"#f87171"},children:e.label}),(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:3,lineHeight:1.45},children:a})]})]})}function r7({label:e,value:t,copyLabel:r,mono:i}){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:{...ni,...i?{wordBreak:"break-all"}:{}},children:t})]}),(0,n.jsx)(r4,{text:t,label:r})]})}function r9({label:e,description:t,checked:r,disabled:i,compact:o,onChange:l}){return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:o?"2px 0":"10px 12px",borderRadius:8*!o,border:o?"none":`1px solid ${r?"color-mix(in srgb, var(--accent) 35%, var(--border))":"var(--border)"}`,background:o?"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:o?11:13,fontWeight:o?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:i,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:i?"default":"pointer",opacity:i?.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 ne(e){return e.split(/\r?\n/).map(e=>e.trim()).filter(Boolean)}function nt({label:e,value:t,onChange:r,placeholder:i,secret:o}){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:o?"password":"text",value:t,onChange:e=>r(e.target.value),placeholder:i,style:no})]})}function nr({children:e,disabled:t,primary:r,danger:i,onClick:o}){return(0,n.jsx)("button",{type:"button",disabled:t,onClick:o,style:{height:28,padding:"0 10px",borderRadius:6,border:r?"none":i?"1px solid rgba(248,113,113,0.45)":"1px solid var(--border)",background:r?"var(--accent)":i?"rgba(248,113,113,0.08)":"var(--bg-hover)",color:r?"#fff":i?"#f87171":"var(--text)",fontSize:11,fontWeight:r?600:400,cursor:t?"default":"pointer",opacity:t?.55:1},children:e})}function nn({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 ni={fontFamily:"var(--font-mono)",fontSize:"0.95em"},no={height:30,padding:"0 8px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:12,fontFamily:"var(--font-mono)"},nl={padding:"8px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:12,fontFamily:"var(--font-mono)",resize:"vertical"},na={border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-panel)"},ns={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 nd({cwd:e}){let[t,r]=(0,i.useState)(null),[o,l]=(0,i.useState)(!0),[a,s]=(0,i.useState)(null),[d,c]=(0,i.useState)(null),u=(0,i.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,i.useEffect)(()=>{u()},[u]);let p=(0,i.useCallback)(async(t,n)=>{s(t),c(null);try{let i=await fetch("/api/plot-kernels",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"select",cwd:e,language:t,kernelId:n})}),o=await i.json().catch(()=>({}));if(!i.ok||o.error||!Array.isArray(o.kernels))throw Error(o.error??`HTTP ${i.status}`);r(o)}catch(e){c(e instanceof Error?e.message:String(e))}finally{s(null)}},[e]),h=e=>{let r=t?.kernels.filter(t=>t.language===e)??[],i=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:i?.id??"",disabled:o||a===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:o?"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:{...na,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 nc({activeCwd:e,onSelectProject:t,onProjectsChanged:r}){let[o,l]=(0,i.useState)([]),[a,s]=(0,i.useState)(e),[d,c]=(0,i.useState)(null),[u,p]=(0,i.useState)(!0),[h,x]=(0,i.useState)(null),[g,f]=(0,i.useState)(""),[v,m]=(0,i.useState)(!1),[y,j]=(0,i.useState)(null),[k,w]=(0,i.useState)(null),[S,C]=(0,i.useState)(""),[T,z]=(0,i.useState)(null),[I,R]=(0,i.useState)(null),M=(0,i.useRef)(null),L=o.find(e=>e.cwd===a)??o.find(t=>t.cwd===e)??o[0]??null,W=(0,i.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),s(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,i.useEffect)(()=>{W()},[W]),(0,i.useEffect)(()=>{e&&o.some(t=>t.cwd===e)&&s(e)},[e,o]);let E=(0,i.useMemo)(()=>({projects:o.length,chats:o.reduce((e,t)=>e+t.chatCount,0)}),[o]),$=(0,i.useCallback)(async()=>{let e=g.trim();if(e){j("add"),x(null);try{let n=await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e})}),i=await n.json();if(!n.ok||i.error)throw Error(i.error??`HTTP ${n.status}`);f(""),s(e),r?.(),t?.(e),W()}catch(e){x(e instanceof Error?e.message:String(e))}finally{j(null)}}},[W,r,t,g]),P=(0,i.useCallback)(async e=>{j("add"),x(null);try{let n=await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e})}),i=await n.json();if(!n.ok||i.error)throw Error(i.error??`HTTP ${n.status}`);f(""),m(!1),s(e),r?.(),t?.(e),W()}catch(e){x(e instanceof Error?e.message:String(e))}finally{j(null)}},[W,r,t]),D=(0,i.useCallback)(async e=>{j(`rename:${e}`),x(null);try{let t=await fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,name:S})}),n=await t.json();if(!t.ok||n.error)throw Error(n.error??`HTTP ${t.status}`);w(null),C(""),await W(),r?.()}catch(e){x(e instanceof Error?e.message:String(e))}finally{j(null)}},[W,r,S]),N=(0,i.useCallback)(async e=>{if(window.confirm("Remove this project from AnnoVibe? Sessions on disk will not be deleted.")){j(`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}`);s(t=>t===e?null:t),await W(),r?.()}catch(e){x(e instanceof Error?e.message:String(e))}finally{j(null)}}},[W,r]),B=(0,i.useCallback)(e=>{w(e.cwd),C(e.displayName),requestAnimationFrame(()=>M.current?.focus())},[]),O=(0,i.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]),A=(0,i.useCallback)((e,t)=>{"reorder"!==y&&(z(e),t.dataTransfer.effectAllowed="move",t.dataTransfer.setData("text/project-cwd",e))},[y]),H=(0,i.useCallback)((e,t)=>{t.preventDefault(),t.dataTransfer.dropEffect="move",R(e)},[]),F=(0,i.useCallback)(e=>{if(R(null),!T||T===e)return void z(null);let t=o.map(e=>e.cwd).filter(Boolean),r=t.indexOf(T),n=t.indexOf(e);r<0||n<0?z(null):(t.splice(r,1),t.splice(n,0,T),l(e=>{let r=new Map(e.map(e=>[e.cwd,e]));return t.map(e=>r.get(e)).filter(Boolean)}),z(null),O(t))},[T,O,o]),U=(0,i.useCallback)(()=>{z(null),R(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&&$()},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"===y,onClick:()=>void $(),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:{...ns,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:{...na,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===o.length?(0,n.jsx)("div",{style:{padding:12,color:"var(--text-muted)",fontSize:12},children:"No projects yet."}):o.map(t=>{var r;let i,o=t.cwd===e,l=t.cwd===L?.cwd,a=T===t.cwd,u=I===t.cwd&&T!==t.cwd,p=d===t.cwd&&!l;return(0,n.jsxs)("button",{type:"button",draggable:!0,onClick:()=>s(t.cwd),onDragStart:e=>A(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:a?.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}),o&&(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:(i=(r=t.cwd).split(/[\\/]/).filter(Boolean)).length<=3?r:`.../${i.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:{...na,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:[k===L.cwd?(0,n.jsx)("input",{ref:M,value:S,onChange:e=>C(e.target.value),onKeyDown:e=>{"Enter"===e.key&&D(L.cwd),"Escape"===e.key&&w(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),i=Math.floor(r/36e5),o=Math.floor(r/864e5);return n<1?"just now":n<60?`${n}m ago`:i<24?`${i}h ago`:o<7?`${o}d ago`:t.toLocaleDateString()}(L.lastAccessed??L.created??null),L.exists?"":" / path missing"]})]}),(0,n.jsx)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",justifyContent:"flex-end"},children:k===L.cwd?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",disabled:y===`rename:${L.cwd}`,onClick:()=>void D(L.cwd),style:{...ns,border:"none",background:"var(--accent)",color:"#fff"},children:"Save"}),(0,n.jsx)("button",{type:"button",onClick:()=>w(null),style:ns,children:"Cancel"})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:()=>t?.(L.cwd),style:{...ns,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:()=>B(L),style:ns,children:"Rename"}),(0,n.jsx)("button",{type:"button",disabled:y===`remove:${L.cwd}`,onClick:()=>void N(L.cwd),style:{...ns,border:"1px solid rgba(248,113,113,0.35)",background:"transparent",color:"#f87171"},children:"Remove"})]})})]})}),(0,n.jsx)(nd,{cwd:L.cwd}),(0,n.jsxs)("section",{style:{...na,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)(r3,{cwd:L.cwd,embedded:!0})]})]}):(0,n.jsx)("div",{style:{...na,padding:18,color:"var(--text-muted)",fontSize:12},children:"Select a project to edit settings."})})]}),(0,n.jsx)(b,{open:v,initialPath:e,onClose:()=>m(!1),onSelect:e=>void P(e)})]})}var nu=r(768);let np=["127.0.0.0/8","::1","10.0.0.0/8","172.16.0.0/12","192.168.0.0/16"];function nh({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 nx({label:e,description:t,checked:r,onChange:i}){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:i,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 ng(){let[e,t]=(0,i.useState)(null),[r,o]=(0,i.useState)(!0),[l,a]=(0,i.useState)(null),[s,d]=(0,i.useState)(null),[c,u]=(0,i.useState)(""),[p,h]=(0,i.useState)(""),[x,g]=(0,i.useState)(null),[f,v]=(0,i.useState)(null),[m,b]=(0,i.useState)(null),[y,j]=(0,i.useState)(!1),[k,w]=(0,i.useState)("always"),[S,C]=(0,i.useState)(!0),[T,z]=(0,i.useState)(np),[I,R]=(0,i.useState)(""),M=(0,i.useCallback)(async()=>{try{let e=await fetch("/api/auth/totp"),r=await e.json();t(r),w(r.requireMode??"always"),z(r.trustedNetworks??np),C(!1!==r.proxyHeaderTrusted)}catch{}finally{o(!1)}},[]);(0,i.useEffect)(()=>{M()},[M]);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:np}),h(""),a(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 nu.toDataURL(r.uri,{width:200,margin:1});a(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(""),a(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()=>{a(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:np})}catch{}},$=(0,i.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]),P=(0,i.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 i=parseInt(n[1],10);if(isNaN(i)||i<0||i>128)return void g("Invalid CIDR prefix length");g(null);let o=[...T,r];if(z(o),R(""),e?.status==="enabled")try{await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"set-trusted-networks",trustedNetworks:o})}),t(e=>e?{...e,trustedNetworks:o}:e)}catch{z(T)}},[I,T,e]),D=(0,i.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)(nh,{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}})}),s&&(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:s.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)(nx,{label:"Require on all networks",description:"TOTP code is always required during login, even from localhost or LAN.",checked:"always"===k,onChange:()=>$("always")}),(0,n.jsx)(nx,{label:"Skip on trusted networks",description:"TOTP code is only required when signing in from outside localhost or LAN.",checked:"untrusted"===k,onChange:()=>$("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=>R(e.target.value),onKeyDown:e=>{"Enter"===e.key&&P()},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:P,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 nf({cwd:e,embedded:t=!1}){let[r,o]=(0,i.useState)([]),[l,a]=(0,i.useState)(!0),[s,d]=(0,i.useState)(null),[c,u]=(0,i.useState)(null),[p,h]=(0,i.useState)(""),[x,g]=(0,i.useState)(!1),[f,v]=(0,i.useState)(null),m=(0,i.useCallback)(async()=>{a(!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}`);o(Array.isArray(n.packages)?n.packages:[]),d(null)}catch(e){d(e instanceof Error?e.message:String(e))}finally{a(!1)}},[e]);(0,i.useEffect)(()=>{m()},[m]);let b=(0,i.useCallback)(async(t,r,n)=>{if(!f){v(r),u(null);try{let i=await fetch("/api/plugins",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:t,source:r,cwd:e,local:n})}),o=await i.json();if(!i.ok||o.error)throw Error(o.error??`HTTP ${i.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,i.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)"]})]}),s&&(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:s}),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."})]})})}function nv({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 nm(){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"})]}):(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 ny({cwd:e,generativeUI:t,initialTab:r="projects",onGenerativeUIToggle:o,onClose:l,onModelsChanged:a,onProjectSelect:s,onProjectsChanged:d}){let[c,u]=(0,i.useState)(r);(0,i.useEffect)(()=>{u(r)},[r]),(0,i.useEffect)(()=>{let e=e=>{"Escape"===e.key&&l()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[l]);let p=[{id:"projects",label:"Project",description:e?"Overview and paths":"Add or select a project",icon: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:"kernels",label:"Kernels",description:e?"Project R / Python kernels":"Global R / Python kernels",icon:nb("kernels")}],h=p.find(e=>e.id===c)??p[0];return(0,n.jsx)("div",{className:"settings-dialog-backdrop",onClick:e=>{e.target===e.currentTarget&&l()},children:(0,n.jsxs)("div",{className:"settings-dialog-shell",children:[(0,n.jsxs)("div",{className:"settings-dialog-header",children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:9,minWidth:0},children:[(0,n.jsx)("span",{style:{color:"var(--text-muted)",display:"flex",alignItems:"center",justifyContent:"center"},children:(0,n.jsx)(nm,{})}),(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:15,fontWeight:700,color:"var(--text)",lineHeight:1.25},children:"Settings"}),(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:h.label})]})]}),(0,n.jsx)("button",{type:"button",onClick:l,title:"Close settings","aria-label":"Close settings",style:{width:30,height:30,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:"x"})]}),(0,n.jsxs)("div",{className:"settings-dialog-body",children:[(0,n.jsx)("div",{className:"settings-dialog-tabs",children:p.map(e=>{let t=c===e.id;return(0,n.jsxs)("button",{type:"button",disabled:e.disabled,onClick:()=>u(e.id),className:"settings-dialog-tab",style:{background:t?"var(--bg-selected)":"transparent",color:t?"var(--text)":"var(--text-muted)",opacity:e.disabled?.45:1,cursor:e.disabled?"not-allowed":"pointer"},onMouseEnter:r=>{t||e.disabled||(r.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="transparent")},children:[(0,n.jsx)("span",{style:{flexShrink:0,color:t?"var(--accent)":"currentColor",display:"flex"},children:e.icon}),(0,n.jsxs)("span",{style:{minWidth:0,flex:1},children:[(0,n.jsx)("span",{style:{display:"block",fontSize:12,fontWeight:t?700:600,lineHeight:1.25},children:e.label}),(0,n.jsx)("span",{style:{display:"block",marginTop:2,fontSize:10,color:"var(--text-dim)",lineHeight:1.25,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.description})]})]},e.id)})}),(0,n.jsxs)("div",{className:"settings-dialog-panel",children:["projects"===c&&(0,n.jsx)(nc,{activeCwd:e,onSelectProject:s,onProjectsChanged:d}),"models"===c&&(0,n.jsx)(rA,{embedded:!0,onClose:()=>{a?.(),l()}}),"authenticator"===c&&(0,n.jsx)(ng,{}),"skills"===c&&e&&(0,n.jsx)(rK,{cwd:e,embedded:!0,onClose:l}),"plugins"===c&&(0,n.jsx)(nf,{cwd:e,embedded:!0}),"generative-ui"===c&&(0,n.jsx)("div",{style:{height:"100%",overflowY:"auto",padding:20},children:(0,n.jsxs)("div",{style:{maxWidth:720,display:"flex",flexDirection:"column",gap:18},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:18,padding:16,border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)",lineHeight:1.35},children:"Generative UI"}),(0,n.jsx)("div",{style:{marginTop:5,fontSize:12,color:"var(--text-muted)",lineHeight:1.55},children:"Render structured widgets and safe visual code blocks directly in chat when the assistant produces UI content."})]}),(0,n.jsx)(nv,{checked:t,onChange:o})]}),(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"===c&&(0,n.jsx)(r2,{cwd:e})]})]})]})})}function nj({initialWidth:e,minWidth:t,maxWidth:r,storageKey:n,direction:o="right"}){let[l,a]=(0,i.useState)(e),[s,d]=(0,i.useState)(!1),c=(0,i.useRef)(e),u=(0,i.useCallback)(e=>{let i=Math.max(t,Math.min(r,e));a(i),c.current=i,document.documentElement.style.setProperty(n,`${i}px`)},[t,r,n]);(0,i.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,i.useCallback)(()=>{d(!0)},[]),h=(0,i.useCallback)(e=>{let t="left"===o?-1:1;u(c.current+e*t)},[u,o]);return{beginResize:p,endResize:(0,i.useCallback)(()=>{d(!1);try{localStorage.setItem(n,String(c.current))}catch{}},[n]),isResizing:s,resizeBy:h,width:l,widthRef:c}}let nk=new Set(["pdf","png","jpg","jpeg","gif","webp","svg","bmp","ico","avif"]);function nw(e){let t=e.toLowerCase();return t.endsWith(".rds")||t.endsWith(".qs")}function nS(e){return e.toLowerCase().endsWith(".h5ad")}function nC(e){let t=(e.split(/[\\/]/).pop()??e).toLowerCase().split(".").pop()??"";return nk.has(t)}function nT(){let e,t,r,l,a,s,d,c=(0,o.useRouter)(),u=(0,o.useSearchParams)(),{isDark:p,toggleTheme:h}=(0,tP.D)(),x=function(){let[e,t]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{let e=()=>t(window.innerWidth<=768);return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),e}(),[g,f]=(0,i.useState)(null),[v,m]=(0,i.useState)(null),[b,y]=(0,i.useState)(null),[j,k]=(0,i.useState)(0),[w,S]=(0,i.useState)(0),[C,T]=(0,i.useState)(0),[z,I]=(0,i.useState)(0),[R,M]=(0,i.useState)(!1),[L,W]=(0,i.useState)("projects"),[E,P]=(0,i.useState)({generativeUI:!0,forkEnabled:!0,forkSuggestTokens:18e4,forkAutoTokens:4e5,forkMinMessages:20}),[D,N]=(0,i.useState)(!0),B=nj({initialWidth:260,minWidth:180,maxWidth:500,storageKey:"--pi-sidebar-width"}),O=nj({initialWidth:500,minWidth:300,maxWidth:1200,storageKey:"--pi-right-panel-width",direction:"left"}),A=(0,i.useRef)(null),J=(0,i.useRef)(null),[K,V]=(0,i.useState)([]),[Y,G]=(0,i.useState)(null),X=(0,i.useRef)(null),Z=(0,i.useCallback)((e,t,r)=>{V(e),G(t),X.current=r},[]),Q=(0,i.useCallback)(e=>{X.current?.(e)},[]),[ee,et]=(0,i.useState)(!1),[er,en]=(0,i.useState)(""),ei=(0,i.useRef)(null),eo=(0,i.useRef)(!1),[el,ea]=(0,i.useState)({kind:"idle"}),es=(0,i.useRef)(null),ed=(0,i.useCallback)(async()=>{let e=g?.id;if(e&&"naming"!==el.kind){es.current&&clearTimeout(es.current),ea({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();k(e=>e+1),f(t=>t?.id===e?{...t,name:n}:t),ea({kind:"success"}),es.current=setTimeout(()=>ea({kind:"idle"}),1800)}catch(e){ea({kind:"error",message:e instanceof Error?e.message:String(e)}),es.current=setTimeout(()=>ea({kind:"idle"}),5e3)}}},[el.kind,g?.id]);(0,i.useEffect)(()=>{es.current&&clearTimeout(es.current),ea({kind:"idle"})},[g?.id]),(0,i.useEffect)(()=>{et(!1)},[g?.id]);let ec=(0,i.useCallback)(e=>e?e.name||e.firstMessage.slice(0,80)||e.id.slice(0,12):"",[]),eu=(0,i.useCallback)(()=>{g&&(eo.current=!1,en(g.name||ec(g)),et(!0),setTimeout(()=>ei.current?.select(),0))},[ec,g]),ep=(0,i.useCallback)(async()=>{if(eo.current){eo.current=!1,et(!1);return}if(!g)return void et(!1);let e=er.trim(),t=ec(g);if(et(!1),e!==(g.name??"")&&(g.name||e!==t))try{(await fetch(`/api/sessions/${encodeURIComponent(g.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e})})).ok&&(f(t=>t&&t.id===g.id?{...t,name:e}:t),k(e=>e+1))}catch{}},[ec,g,er]),eh=(0,i.useCallback)(e=>{"Enter"===e.key?(e.preventDefault(),ep()):"Escape"===e.key&&(eo.current=!0,et(!1))},[ep]);(0,i.useEffect)(()=>{let e=!1;return fetch("/api/settings").then(e=>e.ok?e.json():null).then(t=>{e||P(e=>({generativeUI:"boolean"==typeof t?.settings?.generativeUI?t.settings.generativeUI:e.generativeUI,forkEnabled:"boolean"==typeof t?.settings?.forkEnabled?t.settings.forkEnabled:e.forkEnabled,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(()=>{}),()=>{e=!0}},[]);let ex=(0,i.useCallback)(()=>{let e=!E.generativeUI;P(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=>{P(t=>({...t,..."boolean"==typeof e.settings?.generativeUI?{generativeUI:e.settings.generativeUI}:{}}))}).catch(()=>P(e=>({...e,generativeUI:!e.generativeUI})))},[E.generativeUI]),[eg,ef]=(0,i.useState)(null),ev=(0,i.useCallback)(e=>{ef(e)},[]),[em,eb]=(0,i.useState)(null),ey=(0,i.useCallback)(e=>{eb(e)},[]),[ej,ek]=(0,i.useState)(null);(0,i.useEffect)(()=>{let e=!1;return fetch("/api/version").then(e=>e.ok?e.json():null).then(t=>{!e&&t?.updateAvailable&&ek(t)}).catch(()=>{}),()=>{e=!0}},[]);let ew=ej?.updateAvailable&&ej.latest?{label:`Update ${ej.latest}`,title:`Current: v${ej.current}
21
- Latest: v${ej.latest}
22
- Run: ${ej.updateCommand}`}:null,[eS,eC]=(0,i.useState)([]),[eT,ez]=(0,i.useState)("files"),[eI,eR]=(0,i.useState)(!1),[eM,eL]=(0,i.useState)(null),[eW,eE]=(0,i.useState)(0),[e$,eP]=(0,i.useState)([]),eD=(0,i.useCallback)(e=>{A.current?.insertText("`"+e+"`")},[]),[eN]=(0,i.useState)(()=>u.get("session")),[eB,eO]=(0,i.useState)(null),[eA,eH]=(0,i.useState)(()=>!u.get("session")),eF=(0,i.useRef)(!1),eU=(0,i.useCallback)(e=>{eO(e),eL(null),e&&!eF.current&&(y(function(e,t=H()){if(!t||!e)return null;let r=F(e);return r?U(t)[r]??null:null}(e)),f(t=>t&&t.cwd!==e?null:t),m(t=>t&&t!==e?null:t),S(e=>e+1),T(e=>e+1),V([]),G(null),c.replace("/",{scroll:!1}))},[c]),eJ=(0,i.useCallback)((e,t)=>{eU(e),t?.closeDialog!==!1&&M(!1),k(e=>e+1)},[eU]),eV=(0,i.useCallback)((e,t=!1)=>{y(null),_(e.cwd,e.id),m(null),eO(e.cwd),f(e),S(e=>e+1),eH(!0),t&&(eF.current=!0,setTimeout(()=>{eF.current=!1},0)),t||c.replace(`?session=${encodeURIComponent(e.id)}`,{scroll:!1})},[c]),eG=(0,i.useCallback)((e,t)=>{y(null),f(null),m(t),eO(t),S(e=>e+1),V([]),G(null),c.replace("/",{scroll:!1})},[c]),eX=(0,i.useCallback)(e=>{y(null),_(e.cwd,e.id),m(null),eO(e.cwd),f(e),k(e=>e+1),c.replace(`?session=${encodeURIComponent(e.id)}`,{scroll:!1}),window.dispatchEvent(new CustomEvent("session-created"))},[c]),eZ=(0,i.useCallback)(()=>{k(e=>e+1),T(e=>e+1)},[]),eQ=(0,i.useCallback)(e=>{y(null),k(e=>e+1),S(e=>e+1),m(null),f(t=>{let r=t?.cwd??eB??"";return r&&_(r,e),{...t??{path:"",cwd:"",created:"",modified:"",messageCount:0,firstMessage:""},id:e}}),c.replace(`?session=${encodeURIComponent(e)}`,{scroll:!1})},[eB,c]),e0=(0,i.useCallback)(()=>{eH(!0)},[]),e1=(0,i.useCallback)(e=>{if(k(e=>e+1),g?.id===e){!function(e,t,r=H()){if(!r||!e)return;let n=F(e);if(!n)return;let i=U(r);n in i&&(t&&i[n]!==t||(delete i[n],q(r,i)))}(g.cwd,e);let t=g.cwd;f(null),m(t??null),S(e=>e+1),V([]),G(null),c.replace("/",{scroll:!1})}},[g,c]),e2=g?.cwd??v??eB??null,[e5,e4]=(0,i.useState)(null);(0,i.useEffect)(()=>{if(null!==e5){let e=setTimeout(()=>e4(null),500);return()=>clearTimeout(e)}},[e5]);let e8=(0,i.useCallback)((e,t)=>{if(nw(e)||nw(t))return void eL({mode:"start",appType:"stexp",filePath:e,cwd:e2,appId:null});if(nC(e)||nC(t)){let r=`preview:${e}`;eP(n=>{let i=n.find(e=>e.id===r),o=n.filter(e=>e.id!==r);return o.push(i?{...i,filePath:e,fileName:t}:{id:r,filePath:e,fileName:t}),o});return}let r=`file:${e}`;eC(n=>n.find(e=>e.id===r)?n:[...n,{id:r,label:t,filePath:e}]),ez(r),eR(!0)},[e2]),e3=(0,i.useCallback)((e,t)=>{eC(r=>r.map(r=>{if(r.id!==e)return r;let n=r.viewerState;return n&&n.scrollTop===t.scrollTop&&n.previewMode===t.previewMode&&n.viewMode===t.viewMode&&n.wrapLines===t.wrapLines?r:{...r,viewerState:t}}))},[]),e6=(0,i.useCallback)((e,t,r)=>{r&&r>0&&e4(r),e8(e,t)},[e8]),e7=(0,i.useCallback)((e,t)=>{(nS(e)||nS(t))&&eL({mode:"start",appType:"h5adexp",filePath:e,cwd:e2,appId:null})},[e2]),e9=(0,i.useCallback)(()=>{ez("tools"),eR(!0),eE(e=>e+1)},[]),te=(0,i.useCallback)(e=>{eL({mode:"existing",appType:e.appType,filePath:e.filePath,cwd:e.cwd,appId:e.id}),eE(e=>e+1)},[]),tt=(0,i.useCallback)(e=>{eE(e=>e+1),eL(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)},[]),tr=(0,i.useCallback)(e=>{eP(t=>t.filter(t=>t.id!==e))},[]),tn=(0,i.useCallback)(e=>{eP(t=>{let r=t.findIndex(t=>t.id===e);if(r<0||r===t.length-1)return t;let n=[...t],[i]=n.splice(r,1);return n.push(i),n})},[]),ti=(0,i.useCallback)(e=>{"files"!==e&&(eC(t=>t.filter(t=>t.id!==e)),ez(t=>{if(t!==e)return t;let r=eS.filter(t=>t.id!==e);return r.length>0?r[r.length-1].id:"files"}))},[eS]),to=v??(null===g&&eB?eB:null),tl=null!==g||null!==to,ta=eA&&!tl,ts=[{id:"files",label:"Files",closable:!1,icon:"files"},{id:"tools",label:"Status",closable:!1,icon:"tools"},...eS],td=eS.find(e=>e.id===eT)??null,tc=g?ec(g):to?"New chat":"No session",tu=g?.cwd??to??eB??"",tp=tu?tu.replace(/\/+$/,"").split(/[\\/]/).filter(Boolean).pop()||tu:"",th=(0,i.useCallback)((e="projects")=>{W(e),M(!0)},[]),tx=(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)($,{selectedSessionId:g?.id??null,onSelectSession:eV,onNewSession:eG,initialSessionId:eN,onInitialRestoreDone:e0,restoreSessionId:b,onRestoreSessionDone:()=>y(null),refreshKey:j,onSessionDeleted:e1,selectedCwd:g?.cwd??v??eB??null,onCwdChange:eU}),(0,n.jsx)("div",{style:{padding:"8px",flexShrink:0},children:(0,n.jsx)("button",{type:"button",onClick:()=>th("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:()=>N(!1),style:{position:"fixed",inset:0,zIndex:199,background:"rgba(0,0,0,0.4)",opacity:+!!D,pointerEvents:D?"auto":"none",transition:"opacity 0.25s ease"}}),(0,n.jsx)("div",{className:`sidebar-container${D?" sidebar-open":" sidebar-closed"}`,style:{background:"var(--bg-panel)",borderRight:"1px solid var(--border)",display:"flex",flexDirection:"column",flexShrink:0,zIndex:200,width:B.width,minWidth:B.width,transition:D||B.isResizing?"none":void 0},children:tx}),D&&(0,n.jsx)(tO,{side:"right",ariaLabel:"Resize sidebar",onResizeStart:B.beginResize,onResize:B.resizeBy,onResizeEnd:B.endResize}),(0,n.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden",minWidth:0},children:[(0,n.jsxs)("div",{ref:J,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:()=>N(e=>!e),title:D?"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:D?(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,n.jsx)("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]}):(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"3",y1:"6",x2:"21",y2:"6"}),(0,n.jsx)("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),(0,n.jsx)("line",{x1:"3",y1:"18",x2:"21",y2:"18"})]})}),(0,n.jsxs)("div",{className:"topbar-title-area",style:{display:"flex",alignItems:"center",gap:7,minWidth:0,flex:1},children:[(0,n.jsx)("div",{style:{minWidth:0,display:"flex",alignItems:"center",gap:6},children:ee&&g?(0,n.jsx)("input",{ref:ei,value:er,onChange:e=>en(e.target.value),onKeyDown:eh,onBlur:()=>void ep(),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:tc,style:{minWidth:0,maxWidth:"min(420px, 36vw)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:tl?"var(--text)":"var(--text-muted)",fontSize:14,fontWeight:600,lineHeight:1.2},children:tc}),g&&(0,n.jsx)("button",{type:"button",className:"topbar-rename-button",onClick:eu,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"})]})})]})}),tp&&(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:tu||tp,style:{minWidth:0,maxWidth:"min(280px, 24vw)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-muted)",fontSize:12,lineHeight:1.2},children:tp})]})]}),tl&&!x&&(0,n.jsxs)("div",{className:"topbar-chat-tools",style:{display:"flex",alignItems:"center",gap:6,height:28,flexShrink:0},children:[g&&(0,n.jsx)("a",{className:"topbar-export-button",href:`/api/sessions/${encodeURIComponent(g.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"})]})}),(e=!!(g&&g.messageCount>0),t="naming"===el.kind,r="success"===el.kind,l="error"===el.kind,a=!g||!e||t,s=t?"Naming…":r?"Title updated":l?"Title failed":"Auto title",d=g?e?l?el.message??"Title generation failed":t?"Generating a title from the conversation…":"Generate a title with the current model":"No messages yet":"No session selected",(0,n.jsxs)("button",{type:"button",className:"topbar-auto-title-button",onClick:()=>{ed()},disabled:a,title:d,"aria-label":s,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,height:28,padding:"0 9px",background:r?"rgba(34,197,94,0.10)":l?"rgba(239,68,68,0.10)":"var(--bg-panel)",border:`1px solid ${r?"rgba(34,197,94,0.45)":l?"rgba(239,68,68,0.45)":"var(--border)"}`,borderRadius:7,cursor:a?"not-allowed":"pointer",color:r?"rgba(34,197,94,0.95)":l?"#dc2626":a?"var(--text-dim)":"var(--text-muted)",fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s",opacity:a&&!t?.55:1},onMouseEnter:e=>{a||(e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{e.currentTarget.style.color=r?"rgba(34,197,94,0.95)":l?"#dc2626":"var(--text-muted)",e.currentTarget.style.background=r?"rgba(34,197,94,0.10)":l?"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:s})]}))]}),ew&&(0,n.jsx)("button",{type:"button",className:"topbar-update-button",title:ew.title,onClick:()=>navigator.clipboard?.writeText(ej?.updateCommand??"").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:ew.label}),tl&&(eg||em)&&(()=>{let e=eg?.tokens,t=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(0)}k`:String(e),r="var(--text-muted)",i=null;if(em?.contextWindow){let e=em.percent;null!==e&&e>90?r="#ef4444":null!==e&&e>70&&(r="rgba(234,179,8,0.95)"),i=null!==e?`${e.toFixed(0)}% / ${t(em.contextWindow)}`:`? / ${t(em.contextWindow)}`}let o=[];if(e&&(o.push(`in: ${e.input.toLocaleString()}`),o.push(`out: ${e.output.toLocaleString()}`),o.push(`cache read: ${e.cacheRead.toLocaleString()}`),o.push(`cache write: ${e.cacheWrite.toLocaleString()}`)),em?.contextWindow){let e=em.percent;o.push(`context: ${null!==e?e.toFixed(1)+"%":"unknown"} of ${em.contextWindow.toLocaleString()} tokens`)}let l=o.join(" | ");return(0,n.jsxs)("div",{className:"topbar-session-stats",title:l,style:{display:"flex",alignItems:"center",gap:10,padding:"0 8px",height:28,border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-panel)",fontSize:11,color:"var(--text-muted)",whiteSpace:"nowrap",cursor:"default",fontVariantNumeric:"tabular-nums"},children:[e&&e.input>0&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"5",y1:"8.5",x2:"5",y2:"1.5"}),(0,n.jsx)("polyline",{points:"2 4 5 1.5 8 4"})]}),t(e.input)]}),e&&e.output>0&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"5",y1:"1.5",x2:"5",y2:"8.5"}),(0,n.jsx)("polyline",{points:"2 6 5 8.5 8 6"})]}),t(e.output)]}),e&&e.cacheRead>0&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M8.5 5a3.5 3.5 0 1 1-1-2.45"}),(0,n.jsx)("polyline",{points:"6.5 1.5 8.5 2.5 7.5 4.5"})]}),t(e.cacheRead)]}),i&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4,color:r},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]})]})})(),(0,n.jsx)("button",{type:"button",className:"topbar-icon-button topbar-generate-ui-toggle",onClick:ex,title:`生成式 UI: ${E.generativeUI?"on":"off"}`,"aria-label":`生成式 UI: ${E.generativeUI?"on":"off"}`,style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:28,padding:0,background:E.generativeUI?"var(--bg-selected)":"var(--bg-panel)",border:`1px solid ${E.generativeUI?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,color:E.generativeUI?"var(--accent)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color=E.generativeUI?"var(--accent)":"var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color=E.generativeUI?"var(--accent)":"var(--text-muted)",e.currentTarget.style.background=E.generativeUI?"var(--bg-selected)":"var(--bg-panel)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),(0,n.jsx)("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),(0,n.jsx)("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),(0,n.jsx)("path",{d:"M16 17h5"}),(0,n.jsx)("path",{d:"M18.5 14.5v5"})]})}),(0,n.jsx)("button",{className:"topbar-icon-button topbar-theme-toggle",onClick:e=>{let t=e.currentTarget.getBoundingClientRect();h({x:t.left+t.width/2,y:t.top+t.height/2})},title:p?"Switch to light mode":"Switch to dark mode","aria-label":p?"Switch to light mode":"Switch to dark mode","aria-pressed":p,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:p?(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:()=>eR(e=>!e),title:eI?"Hide right panel":"Show right panel","aria-label":eI?"Hide right panel":"Show right panel",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:28,padding:0,background:eI?"var(--bg-selected)":"var(--bg-panel)",border:`1px solid ${eI?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,color:eI?"var(--accent)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color=eI?"var(--accent)":"var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color=eI?"var(--accent)":"var(--text-muted)",e.currentTarget.style.background=eI?"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"})]})})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"hidden",position:"relative"},children:tl?(0,n.jsx)(eq,{session:g,newSessionCwd:to,onAgentEnd:eZ,onSessionCreated:eX,onSessionForked:eQ,modelsRefreshKey:z,chatInputRef:A,onBranchDataChange:Z,onSessionStatsChange:ev,onContextUsageChange:ey,generativeUI:E.generativeUI,forkSettings:{enabled:E.forkEnabled,suggestTokens:E.forkSuggestTokens,autoTokens:E.forkAutoTokens,minMessages:E.forkMinMessages},activeFilePath:td?.filePath??null,onOpenFileAtLine:e6},w):ta?eB?(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})]}),eI&&(0,n.jsx)(tO,{side:"left",ariaLabel:"Resize right panel",onResizeStart:O.beginResize,onResize:O.resizeBy,onResizeEnd:O.endResize}),(0,n.jsxs)("div",{className:`right-panel-container${eI?" right-panel-open":" right-panel-closed"}`,style:{display:eI?"flex":"none",flexDirection:"column",borderLeft:"1px solid var(--border)",background:"var(--bg)",flexShrink:0,width:O.width,minWidth:O.width,transition:O.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:()=>eR(!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)(t5,{tabs:ts,activeTabId:eT,onSelectTab:ez,onCloseTab:ti,onAskAI:e=>{let t=`I'm looking at \`${e}\`. `;A?.current?.insertIfEmpty(t)}})})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"hidden"},children:"files"===eT?(0,n.jsx)(tE,{cwd:eB??g?.cwd??v??null,refreshKey:C,onOpenFile:e8,onExploreFile:e7,onAtMention:eD,watchEnabled:eI&&"files"===eT}):"tools"===eT?(0,n.jsx)(tX,{refreshKey:eW,visibleAppId:eM?.appId??null,cwd:eB??g?.cwd??v??null,onOpenApp:te,onAppChanged:tt,agentRuntimeExtra:(0,n.jsx)(t3,{tree:K,activeLeafId:Y,onLeafChange:Q,hasSession:!!g,embedded:!0})}):td?.filePath?td.filePath.startsWith("__")?(0,n.jsx)(tN,{filePath:td.filePath}):(0,n.jsx)(eK,{filePath:td.filePath,children:(0,n.jsx)(e_.h,{filePath:td.filePath,cwd:eB??void 0,onOpenFile:e8,scrollToLine:e5,viewerState:td.viewerState,onViewerStateChange:e=>e3(td.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"})})]})]}),R&&(0,n.jsx)(ny,{cwd:e2,generativeUI:E.generativeUI,initialTab:L,onGenerativeUIToggle:ex,onModelsChanged:()=>I(e=>e+1),onProjectSelect:eJ,onProjectsChanged:()=>k(e=>e+1),onClose:()=>{M(!1),I(e=>e+1)}}),(0,n.jsx)(tq,{appType:eM?.appType??"stexp",filePath:eM?.filePath??null,cwd:eM?.cwd??null,appId:eM?.appId??null,sessionId:g?.id??null,onClose:()=>eL(null),onAppChanged:tt,onOpenTools:e9}),e$.map((e,t)=>(0,n.jsx)(eY,{id:e.id,filePath:e.filePath,fileName:e.fileName,cwd:eB??g?.cwd??v??void 0,active:t===e$.length-1,stackIndex:t,zIndex:700+t,onClose:tr,onFocus:tn,onOpenFile:e8},e.id))]})}},43322:(e,t,r)=>{Promise.resolve().then(r.bind(r,20566))}},e=>{e.O(0,[7330,2941,2995,6079,2693,2254,4936,9867,2257,5618,8441,3794,7358],()=>e(e.s=43322)),_N_E=e.O()}]);