@seqyuan/annodex 0.1.44 → 0.1.46
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.
- package/.next/BUILD_ID +1 -1
- package/.next/app-path-routes-manifest.json +4 -4
- package/.next/build-manifest.json +2 -2
- package/.next/prerender-manifest.json +3 -3
- package/.next/required-server-files.js +1 -1
- package/.next/required-server-files.json +1 -1
- package/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/.next/server/app/_global-error.html +1 -1
- package/.next/server/app/_global-error.rsc +1 -1
- package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/.next/server/app/_not-found.html +1 -1
- package/.next/server/app/_not-found.rsc +2 -2
- package/.next/server/app/_not-found.segments/_full.segment.rsc +2 -2
- package/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_index.segment.rsc +2 -2
- package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
- package/.next/server/app/api/internal/runtime/route.js +1 -1
- package/.next/server/app/api/version/route.js +1 -1
- package/.next/server/app/index.html +1 -1
- package/.next/server/app/index.rsc +2 -2
- package/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/index.segments/_full.segment.rsc +2 -2
- package/.next/server/app/index.segments/_head.segment.rsc +1 -1
- package/.next/server/app/index.segments/_index.segment.rsc +2 -2
- package/.next/server/app/index.segments/_tree.segment.rsc +2 -2
- package/.next/server/app/login/page_client-reference-manifest.js +1 -1
- package/.next/server/app/login.html +1 -1
- package/.next/server/app/login.rsc +2 -2
- package/.next/server/app/login.segments/_full.segment.rsc +2 -2
- package/.next/server/app/login.segments/_head.segment.rsc +1 -1
- package/.next/server/app/login.segments/_index.segment.rsc +2 -2
- package/.next/server/app/login.segments/_tree.segment.rsc +2 -2
- package/.next/server/app/login.segments/login/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/login.segments/login.segment.rsc +1 -1
- package/.next/server/app/page_client-reference-manifest.js +1 -1
- package/.next/server/app/workspace/page.js +2 -2
- package/.next/server/app/workspace/page_client-reference-manifest.js +1 -1
- package/.next/server/app/workspace.html +1 -1
- package/.next/server/app/workspace.rsc +3 -3
- package/.next/server/app/workspace.segments/_full.segment.rsc +3 -3
- package/.next/server/app/workspace.segments/_head.segment.rsc +1 -1
- package/.next/server/app/workspace.segments/_index.segment.rsc +2 -2
- package/.next/server/app/workspace.segments/_tree.segment.rsc +2 -2
- package/.next/server/app/workspace.segments/workspace/__PAGE__.segment.rsc +2 -2
- package/.next/server/app/workspace.segments/workspace.segment.rsc +1 -1
- package/.next/server/app-paths-manifest.json +4 -4
- package/.next/server/chunks/402.js +2 -2
- package/.next/server/chunks/6429.js +2 -2
- package/.next/server/middleware-build-manifest.js +1 -1
- package/.next/server/pages/404.html +1 -1
- package/.next/server/pages/500.html +1 -1
- package/.next/server/server-reference-manifest.json +1 -1
- package/.next/static/chunks/app/workspace/{page-0aa93c39172b43af.js → page-cc13c7f808b313cf.js} +2 -2
- package/.next/static/css/96d45ba4e4b5ca90.css +1 -0
- package/package.json +1 -1
- package/.next/static/css/a3dc0b6797dcdda6.css +0 -1
- /package/.next/static/{PVU_t00kkXpJOsOTL-sx5 → WarldNaNwN0i4ByfXbp_K}/_buildManifest.js +0 -0
- /package/.next/static/{PVU_t00kkXpJOsOTL-sx5 → WarldNaNwN0i4ByfXbp_K}/_ssgManifest.js +0 -0
package/.next/static/chunks/app/workspace/{page-0aa93c39172b43af.js → page-cc13c7f808b313cf.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6364],{17865:(e,t,r)=>{"use strict";r.d(t,{AppShell:()=>oy});var n=r(95155),o=r(12115),i=r(73321);function l(e,t){let r=t&&e.startsWith(t)?"~"+e.slice(t.length):e,n=r.includes("/")?"/":"\\",o=r.split(n).filter(Boolean);return o.length<=2?r:"..."+n+o.slice(-2).join(n)}function s(e){let t=new Date(e);return Number.isNaN(t.getTime())?"":t.toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function a({open:e,cwd:t,homeDir:r,onClose:i,onSelectSession:d}){let[c,u]=(0,o.useState)(""),[p,h]=(0,o.useState)("current"),[x,g]=(0,o.useState)([]),[f,m]=(0,o.useState)(!1),[v,y]=(0,o.useState)(null),[b,j]=(0,o.useState)(!1),k=(0,o.useRef)(null);if((0,o.useEffect)(()=>{e&&(h(t?"current":"all"),setTimeout(()=>k.current?.focus(),0))},[e,t]),(0,o.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&i()};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,i]),(0,o.useEffect)(()=>{if(!e)return;let r=c.trim();if(r.length<2){g([]),m(!1),y(null),j(!1);return}let n=new AbortController,o=setTimeout(async()=>{m(!0),y(null);try{let e=new URLSearchParams({q:r,scope:p});t&&e.set("cwd",t);let o=await fetch(`/api/search?${e.toString()}`,{signal:n.signal});if(!o.ok)throw Error(`HTTP ${o.status}`);let i=await o.json();if(i.error)throw Error(i.error);g(i.results??[]),j(i.truncated??!1)}catch(e){"AbortError"!==e.name&&y(String(e))}finally{m(!1)}},180);return()=>{clearTimeout(o),n.abort()}},[e,c,p,t]),!e)return null;let w=c.trim(),S=x.reduce((e,t)=>e+t.matches.length,0);return(0,n.jsx)("div",{role:"dialog","aria-modal":"true","aria-label":"Search conversation history",style:{position:"fixed",inset:0,zIndex:500,display:"flex",alignItems:"flex-start",justifyContent:"center",padding:"8vh 16px 16px",background:"rgba(0,0,0,0.28)"},onMouseDown:e=>{e.target===e.currentTarget&&i()},children:(0,n.jsxs)("div",{style:{width:"min(760px, 100%)",maxHeight:"78vh",display:"flex",flexDirection:"column",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 16px 48px rgba(0,0,0,0.24)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:12,borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1,minWidth:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:8,padding:"0 10px"},children:[(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"7",cy:"7",r:"4.5"}),(0,n.jsx)("path",{d:"M10.5 10.5 13.5 13.5"})]}),(0,n.jsx)("input",{ref:k,value:c,onChange:e=>u(e.target.value),placeholder:"Search conversation history...",style:{flex:1,minWidth:0,height:38,background:"transparent",border:"none",outline:"none",color:"var(--text)",fontSize:14}})]}),(0,n.jsx)("button",{type:"button",onClick:i,title:"Close",style:{width:34,height:34,display:"inline-flex",alignItems:"center",justifyContent:"center",background:"none",border:"none",borderRadius:7,color:"var(--text-dim)",cursor:"pointer"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-dim)"},children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,n.jsx)("path",{d:"M4 4 12 12"}),(0,n.jsx)("path",{d:"M12 4 4 12"})]})})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:10},children:[(0,n.jsx)("div",{style:{display:"inline-flex",padding:2,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7},children:[{value:"current",label:"Current project",disabled:!t},{value:"all",label:"All history",disabled:!1}].map(e=>(0,n.jsx)("button",{type:"button",disabled:e.disabled,onClick:()=>h(e.value),style:{height:24,padding:"0 9px",background:p===e.value?"var(--bg-selected)":"transparent",border:"none",borderRadius:5,color:e.disabled?"var(--text-dim)":p===e.value?"var(--text)":"var(--text-muted)",cursor:e.disabled?"not-allowed":"pointer",fontSize:11,fontWeight:500},children:e.label},e.value))}),(0,n.jsx)("div",{style:{flex:1,minWidth:0,color:"var(--text-dim)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"current"===p&&t?l(t,r):"Searching every saved session"})]})]}),(0,n.jsxs)("div",{style:{flex:1,overflowY:"auto",minHeight:180},children:[w.length<2&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Type at least 2 characters to search saved conversations."}),w.length>=2&&f&&0===x.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Searching..."}),v&&(0,n.jsx)("div",{style:{padding:18,color:"#ef4444",fontSize:13},children:v}),w.length>=2&&!f&&!v&&0===x.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"No matching conversations found."}),x.map(e=>(0,n.jsxs)("div",{style:{borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{d(e.session),i()},style:{width:"100%",display:"flex",alignItems:"center",gap:10,padding:"10px 12px",background:"var(--bg-panel)",border:"none",borderBottom:"1px solid var(--border)",color:"var(--text)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13,fontWeight:600},children:e.session.name||e.session.firstMessage||"(no messages)"}),(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:11},children:s(e.session.modified)})]}),(0,n.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l(e.session.cwd,r)})]}),e.matchCount>e.matches.length&&(0,n.jsxs)("span",{style:{flexShrink:0,color:"var(--text-muted)",fontSize:11},children:[e.matchCount," matches"]})]}),e.matches.map(t=>(0,n.jsxs)("button",{type:"button",onClick:()=>{d(e.session),i()},style:{width:"100%",padding:"9px 14px 9px 28px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:3},children:[(0,n.jsx)("span",{style:{minWidth:54,color:"user"===t.role?"var(--accent)":"var(--text-dim)",fontSize:11,fontWeight:600,textTransform:"capitalize"},children:t.role}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:s(t.timestamp)})]}),(0,n.jsx)("div",{style:{fontSize:12,lineHeight:1.45,color:"var(--text-muted)"},children:function(e,t){let r=t.trim();if(!r)return e;let o=e.toLowerCase().indexOf(r.toLowerCase());return o<0?e:(0,n.jsxs)(n.Fragment,{children:[e.slice(0,o),(0,n.jsx)("mark",{style:{background:"rgba(37,99,235,0.16)",color:"var(--text)",borderRadius:3,padding:"0 2px"},children:e.slice(o,o+r.length)}),e.slice(o+r.length)]})}(t.snippet,w)})]},t.entryId))]},e.session.id))]}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",padding:"8px 12px",borderTop:"1px solid var(--border)",color:"var(--text-dim)",fontSize:11},children:[(0,n.jsx)("span",{children:S>0?`${S}${b?"+":""} results`:"Esc to close"}),f&&x.length>0&&(0,n.jsx)("span",{children:"Updating..."})]})]})})}function d({open:e,initialPath:t,onClose:r,onSelect:i,externalError:l,onPathInputChange:s}){let[a,c]=(0,o.useState)(""),[u,p]=(0,o.useState)(null),[h,x]=(0,o.useState)([]),[g,f]=(0,o.useState)([]),[m,v]=(0,o.useState)(""),[y,b]=(0,o.useState)(!1),[j,k]=(0,o.useState)(null),w=(0,o.useCallback)(async e=>{b(!0),k(null);try{let t=e?`/api/projects/browse?dir=${encodeURIComponent(e)}`:"/api/projects/browse",r=await fetch(t),n=await r.json();if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);c(n.current??""),p(n.parent??null),x(n.directories??[]),f(n.drives??[]),v(n.current??"")}catch(e){k(e instanceof Error?e.message:String(e))}finally{b(!1)}},[]);return((0,o.useEffect)(()=>{e&&w(t||void 0)},[w,t,e]),(0,o.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&r()};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[r,e]),e)?(0,n.jsx)("div",{onMouseDown:e=>{e.target===e.currentTarget&&r()},style:{position:"fixed",inset:0,zIndex:1200,display:"flex",alignItems:"center",justifyContent:"center",padding:18,background:"rgba(0,0,0,0.34)"},children:(0,n.jsxs)("div",{style:{width:"min(560px, 100%)",maxHeight:"min(720px, 88dvh)",display:"flex",flexDirection:"column",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 12px 40px rgba(0,0,0,0.25)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{height:48,padding:"0 14px",display:"flex",alignItems:"center",justifyContent:"space-between",borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:14,fontWeight:750},children:"Add project folder"}),(0,n.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:11},children:"Choose a folder or enter a path"})]}),(0,n.jsx)("button",{type:"button",onClick:r,"aria-label":"Close",title:"Close",style:{width:30,height:30,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:"x"})]}),(0,n.jsx)("div",{style:{padding:12,borderBottom:"1px solid var(--border)"},children:(0,n.jsxs)("form",{onSubmit:e=>{e.preventDefault(),m.trim()&&i(m.trim())},style:{display:"flex",flexDirection:"column",gap:7},children:[(0,n.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,n.jsx)("input",{value:m,onChange:e=>{v(e.target.value),s?.()},placeholder:"/path/to/project",style:{flex:1,minWidth:0,height:32,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:12,outline:"none"}}),(0,n.jsx)("button",{type:"button",onClick:()=>m.trim()&&void w(m.trim()),style:{height:32,padding:"0 11px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Browse"}),(0,n.jsx)("button",{type:"submit",disabled:!m.trim(),style:{height:32,padding:"0 12px",border:"none",borderRadius:6,background:m.trim()?"var(--accent)":"var(--bg-hover)",color:m.trim()?"#fff":"var(--text-dim)",cursor:m.trim()?"pointer":"default",fontSize:12,fontWeight:650},children:"Use path"})]}),l&&(0,n.jsx)("div",{style:{color:"#f87171",fontSize:11,lineHeight:1.4,overflowWrap:"anywhere"},children:l})]})}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"8px 12px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsx)("button",{type:"button",onClick:()=>u&&void w(u),disabled:!u,style:{width:28,height:28,border:"1px solid var(--border)",borderRadius:6,background:u?"var(--bg)":"transparent",color:u?"var(--text-muted)":"var(--text-dim)",cursor:u?"pointer":"default",padding:0},title:"Up",children:(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"2 6.5 5 3.5 8 6.5"})})}),g.length>0&&(0,n.jsxs)("select",{value:g.find(e=>a.toLowerCase().startsWith(e.toLowerCase()))??"",onChange:e=>{e.target.value&&w(e.target.value)},style:{height:28,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text-muted)",fontSize:12},children:[(0,n.jsx)("option",{value:"",children:"Drive"}),g.map(e=>(0,n.jsx)("option",{value:e,children:e},e))]}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11},title:a,children:a})]}),(0,n.jsx)("div",{style:{flex:1,minHeight:220,maxHeight:360,overflowY:"auto",padding:6},children:y?(0,n.jsx)("div",{style:{padding:18,color:"var(--text-muted)",fontSize:12},children:"Loading..."}):j?(0,n.jsx)("div",{style:{padding:18,color:"#f87171",fontSize:12},children:j}):0===h.length?(0,n.jsx)("div",{style:{padding:18,color:"var(--text-muted)",fontSize:12},children:"No subdirectories"}):h.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>void w(e.path),style:{width:"100%",display:"flex",alignItems:"center",gap:9,padding:"8px 9px",border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:12},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},title:e.path,children:[(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--accent)",flexShrink:0},children:(0,n.jsx)("path",{d:"M3 6.5A2.5 2.5 0 0 1 5.5 4H10l2 2.5h6.5A2.5 2.5 0 0 1 21 9v8.5A2.5 2.5 0 0 1 18.5 20h-13A2.5 2.5 0 0 1 3 17.5v-11Z"})}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0},children:(0,n.jsx)("polyline",{points:"3.5 2 6.5 5 3.5 8"})})]},e.path))}),(0,n.jsxs)("div",{style:{padding:12,borderTop:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",gap:10},children:[(0,n.jsx)("div",{style:{minWidth:0,color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:a,children:a}),(0,n.jsxs)("div",{style:{display:"flex",gap:7,flexShrink:0},children:[(0,n.jsx)("button",{type:"button",onClick:r,style:{height:32,padding:"0 12px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Cancel"}),(0,n.jsx)("button",{type:"button",onClick:()=>a&&i(a),disabled:!a,style:{height:32,padding:"0 12px",border:"none",borderRadius:6,background:a?"var(--accent)":"var(--bg-hover)",color:a?"#fff":"var(--text-dim)",cursor:a?"pointer":"default",fontSize:12,fontWeight:650},children:"Select"})]})]})]})}):null}var c=r(65673);let u="annodex:sidebar:collapsed-projects",p=["annovibe:sidebar:collapsed-projects","pidex:sidebar:collapsed-projects"],h="annodex:sidebar:collapsed-projects:init-v2";function x(e){window.localStorage.setItem(u,JSON.stringify([...e]))}async function g(e,t){let r=`${e}: HTTP ${t.status}`;try{let n=await t.json();return"string"==typeof n.error&&n.error?`${e}: ${n.error}`:r}catch{return r}}function f(e){let t=new Date(e),r=new Date().getTime()-t.getTime(),n=Math.floor(r/6e4),o=Math.floor(r/36e5),i=Math.floor(r/864e5);return n<1?"just now":n<60?`${n}m ago`:o<24?`${o}h ago`:i<7?`${i}d ago`:t.toLocaleDateString()}function m(e,t){let r,n,o;if(!e)return"No Project";let i=e.replace(/[\\/]+$/,""),l=i.includes("/")?"/":"\\";return i.split(l).filter(Boolean).pop()||(n=(r=t&&e.startsWith(t)?"~"+e.slice(t.length):e).includes("/")?"/":"\\",(o=r.split(n).filter(Boolean)).length<=2?r:"…/"+o.slice(-2).join(n))}function v(e){return e.lastAccessed??e.created??""}function y(e,t){let r=e.displayName.toLocaleLowerCase(),n=t.displayName.toLocaleLowerCase(),o=r.localeCompare(n,void 0,{numeric:!0,sensitivity:"base"});return 0!==o?o:e.cwd.localeCompare(t.cwd)}function b(e,t){let r=!0===e.pinned;if(r!==(!0===t.pinned))return r?-1:1;let n=Number.isFinite(e.sortOrder)?e.sortOrder:null,o=Number.isFinite(t.sortOrder)?t.sortOrder:null;return null!==n&&null!==o&&n!==o?n-o:null!==n&&null===o?-1:null===n&&null!==o?1:y(e,t)}let j="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";function k(){let[e,t]=(0,o.useState)(!1),[r,i]=(0,o.useState)(!1),l=(0,o.useRef)(null),s=function(e,t){let[r,n]=(0,o.useState)(e),i=(0,o.useRef)(null),l=(0,o.useRef)(0);return(0,o.useEffect)(()=>{if(!t)return void n(e);l.current=0;let r=4*e.length,o=()=>{l.current+=1;let t=Math.floor(l.current/r*e.length);n(e.split("").map((e,r)=>" "===e?" ":r<t?e:j[Math.floor(Math.random()*j.length)]).join("")),l.current<r?i.current=requestAnimationFrame(o):n(e)};return i.current=requestAnimationFrame(o),()=>{i.current&&cancelAnimationFrame(i.current)}},[e,t]),r}(e?"v0.1.44":c.C3,r),a=(0,o.useCallback)(e=>{t(e),i(!0),setTimeout(()=>i(!1),(e?6:8)*4*(1e3/60)+100)},[]),d=(0,o.useCallback)(()=>{l.current&&clearTimeout(l.current);let t=!e;a(t),t&&(l.current=setTimeout(()=>a(!1),3e3))},[e,a]);return(0,o.useEffect)(()=>()=>{l.current&&clearTimeout(l.current)},[]),(0,n.jsx)("button",{onClick:d,style:{background:"none",border:"none",padding:0,cursor:"default",fontWeight:700,fontSize:15,letterSpacing:"-0.01em",color:e?"var(--accent)":"var(--text)",fontFamily:"var(--font-mono)",minWidth:"9ch"},children:s})}function w({selectedSessionId:e,onSelectSession:t,onNewSession:r,initialSessionId:i,onInitialRestoreDone:l,refreshKey:s,onSessionDeleted:c,selectedCwd:j,onCwdChange:z}){let[T,I]=(0,o.useState)([]),[M,L]=(0,o.useState)({}),[R,W]=(0,o.useState)(!0),[E,$]=(0,o.useState)(!1),[A,B]=(0,o.useState)(null),[N,P]=(0,o.useState)(null),[D,O]=(0,o.useState)(""),[H,F]=(0,o.useState)(null),[_,U]=(0,o.useState)(!1),[V,q]=(0,o.useState)(!1),[K,J]=(0,o.useState)(new Set),[Z,Y]=(0,o.useState)(()=>(function(){try{for(let e of[u,...p]){let t=window.localStorage.getItem(e);if(t)return new Set(JSON.parse(t))}}catch{}return new Set})()),[G,X]=(0,o.useState)(null),[Q,ee]=(0,o.useState)(null),et=(0,o.useRef)(!1),er=(0,o.useRef)(!1),en=(0,o.useRef)(!1),eo=(0,o.useRef)(!1),[ei,el]=(0,o.useState)(!0),es=(0,o.useCallback)(async(e=!1)=>{try{e&&(B(null),W(!0));let t=new AbortController,r=setTimeout(()=>t.abort(),15e3),n=await fetch("/api/projects",{signal:t.signal});if(clearTimeout(r),!n.ok)throw Error(await g("projects",n));let o=await n.json();I(o.projects),B(null)}catch(e){B(String(e))}finally{e&&W(!1)}},[]),ea=(0,o.useCallback)(async(e,t=!1)=>{if(e){L(t=>({...t,[e]:{sessions:t[e]?.sessions??[],loaded:t[e]?.loaded??!1,error:null,loading:!0,stale:t[e]?.stale??!1}}));try{t&&W(!0);let r=new AbortController,n=setTimeout(()=>r.abort(),15e3),o=await fetch(`/api/sessions?cwd=${encodeURIComponent(e)}`,{signal:r.signal});if(clearTimeout(n),!o.ok)throw Error(await g("sessions",o));let i=await o.json();L(t=>({...t,[e]:{sessions:i.sessions,loaded:!0,loading:!1,error:null,stale:!1}}))}catch(r){let t=String(r);L(r=>({...r,[e]:{sessions:r[e]?.sessions??[],loaded:r[e]?.loaded??!1,loading:!1,error:t,stale:(r[e]?.sessions?.length??0)>0}}))}finally{t&&W(!1)}}},[]),ed=(0,o.useRef)(!1);(0,o.useEffect)(()=>{let e=!ed.current;ed.current=!0,es(e)},[es,s]),(0,o.useEffect)(()=>{fetch("/api/home").then(e=>e.json()).then(e=>{e.home&&O(e.home)}).catch(()=>{})},[]),(0,o.useEffect)(()=>{if(et.current){et.current=!1;return}if(er.current){er.current=!1;return}z?.(N)},[N,z]);let ec=(0,o.useCallback)(async(e,t=!1)=>{try{let r=await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,create:t})}),n=await r.json();if(!r.ok||n.error)return F(n.error??`HTTP ${r.status}`),!1;return es(!1),!0}catch(e){return F(e instanceof Error?e.message:String(e)),!1}},[es]),eu=(0,o.useCallback)(e=>{fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,touch:!0})}).catch(()=>{})},[]),ep=(0,o.useCallback)(async e=>{let t=await fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw Error(await g("projects",t));let r=await t.json();Array.isArray(r.projects)&&I(r.projects)},[]);(0,o.useEffect)(()=>{if(!i||eo.current)return;let e=!1;return fetch(`/api/sessions/${encodeURIComponent(i)}?infoOnly=1`).then(e=>e.ok?e.json():null).then(r=>{if(e||eo.current)return;let n=r?.info??null;n&&(eo.current=!0,P(n.cwd),Y(e=>{if(!e.has(n.cwd))return e;let t=new Set(e);return t.delete(n.cwd),x(t),t}),ea(n.cwd,!1),eu(n.cwd),t(n,!0))}).finally(()=>{e||eo.current||l?.()}),()=>{e=!0}},[i,ea,l,t,eu]);let eh=(0,o.useCallback)(e=>{er.current=!0,P(e),F(null),Y(t=>{if(!t.has(e))return t;let r=new Set(t);return r.delete(e),x(r),r}),z?.(e),eu(e),ea(e,!1)},[ea,z,eu]);(0,o.useEffect)(()=>{if(0!==T.length&&null===N&&!j){if(i&&!eo.current)return;let e=T[0]?.cwd;e&&(P(e),eu(e),ea(e,!1))}},[T,N,j,i,t,l,eu,ea]);let ex=(0,o.useCallback)(async e=>{await ec(e,!1)&&(eh(e),U(!1),F(null))},[eh,ec]),eg=j??N,ef=(0,o.useCallback)(async()=>{$(!0);try{await es(!1);let e=new Set([...Object.entries(M).filter(([,e])=>e.loaded||e.loading).map(([e])=>e),...eg?[eg]:[]]);await Promise.all([...e].map(e=>ea(e,!1)))}finally{$(!1)}},[eg,es,ea,M]);(0,o.useEffect)(()=>{eg&&(Y(e=>{if(!e.has(eg))return e;let t=new Set(e);return t.delete(eg),x(t),t}),ea(eg,!1))},[eg,ea,s]);let em=(0,o.useCallback)(e=>{if(!e){F(null),U(!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]),ev=(0,o.useCallback)(()=>{em(eg)},[em,eg]),ey=(0,o.useCallback)(()=>{F(null),U(!0)},[]),eb=(0,o.useMemo)(()=>[...eg&&!T.some(e=>e.cwd===eg)?[{cwd:eg,displayName:m(eg,D),chatCount:M[eg]?.sessions.length??0,lastAccessed:null,created:null,pinned:!1,sortOrder:null,exists:!0,source:"manual"}]:[],...T].sort(b),[eg,D,T,M]),ej=(0,o.useMemo)(()=>{let e=new Map([...eb].sort((e,t)=>{let r=v(e)||M[e.cwd]?.sessions[0]?.modified||"",n=v(t)||M[t.cwd]?.sessions[0]?.modified||"";return r!==n?n.localeCompare(r):y(e,t)}).map((e,t)=>[e.cwd,t]));return eb.filter(e=>e.cwd||e.chatCount>0||e.cwd===eg).map(t=>{let r=M[t.cwd],n=[...r?.sessions??[]].sort((e,t)=>t.modified.localeCompare(e.modified));return{project:t,cwd:t.cwd,displayName:t.displayName||m(t.cwd,D),sessions:n,sessionsState:r,lastAccessed:v(t)||n[0]?.modified||"",recentRank:e.get(t.cwd)??Number.MAX_SAFE_INTEGER}})},[eg,D,M,eb]);(0,o.useEffect)(()=>{if(0===ej.length||en.current)return;en.current=!0;let e=[...ej].sort((e,t)=>e.recentRank-t.recentRank)[0]?.cwd;if(!e||window.localStorage.getItem(h))return;let t=new Set(ej.filter(t=>t.cwd!==e).map(e=>e.cwd));Y(e=>!function(e,t){if(e.size!==t.size)return!1;for(let r of e)if(!t.has(r))return!1;return!0}(e,t)?(x(t),t):e),window.localStorage.setItem(h,"1")},[ej]),(0,o.useEffect)(()=>{if(0!==ej.length)for(let e of ej.filter(e=>!Z.has(e.cwd)).slice(0,3).map(e=>e.cwd)){let t=M[e];t?.loaded||t?.loading||ea(e,!1)}},[Z,ea,ej,M]);let ek=(0,o.useCallback)(e=>{Y(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),x(r),r});let t=M[e];t?.loaded||t?.loading||ea(e,!1)},[ea,M]),ew=(0,o.useCallback)(e=>{J(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),eS=(0,o.useCallback)(async(e,t)=>{I(r=>r.map(r=>r.cwd===e?{...r,pinned:t}:r).sort(b));try{await ep({cwd:e,pinned:t})}catch{es(!1)}},[es,ep]),eC=(0,o.useCallback)(e=>{X(e),ee(e)},[]),ez=(0,o.useCallback)(async e=>{if(!G||G===e){X(null),ee(null);return}let t=[...T].sort(b),r=t.findIndex(e=>e.cwd===G),n=t.findIndex(t=>t.cwd===e);if(r<0||n<0){X(null),ee(null);return}let o=(function(e,t,r){if(t===r)return e;let n=[...e],[o]=n.splice(t,1);return n.splice(r,0,o),n})(t,r,n).map((e,t)=>({...e,sortOrder:t}));I(o),X(null),ee(null);try{await ep({order:o.map(e=>e.cwd)})}catch{es(!1)}},[G,es,T,ep]),eT=(0,o.useCallback)(()=>{X(null),ee(null)},[]),eI=(0,o.useCallback)((e,r=!1)=>{e.cwd!==eg&&(et.current=!0,P(e.cwd)),Y(t=>{if(!t.has(e.cwd))return t;let r=new Set(t);return r.delete(e.cwd),x(r),r}),eu(e.cwd),t(e,r)},[t,eg,eu]);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"12px 10px 8px",borderBottom:"1px solid var(--border)",flexShrink:0},children:(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(k,{}),(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsxs)("button",{onClick:ev,disabled:!eg,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,background:"var(--bg-hover)",border:"1px solid var(--border)",color:eg?"var(--text-muted)":"var(--text-dim)",cursor:eg?"pointer":"not-allowed",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:eg?`New session in ${eg}`:"Select a project first",onMouseEnter:e=>{eg&&(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=eg?"var(--text-muted)":"var(--text-dim)",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"]}),(0,n.jsx)("button",{onClick:()=>q(!0),style:{display:"flex",alignItems:"center",justifyContent:"center",background:"var(--bg-hover)",border:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",width:32,height:32,borderRadius:7,padding:0,flexShrink:0,transition:"background 0.12s, color 0.12s, border-color 0.12s"},title:"Search conversations",onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-selected)",e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"7",cy:"7",r:"4.4"}),(0,n.jsx)("path",{d:"M10.4 10.4 13.2 13.2"})]})})]})]})}),(0,n.jsx)(a,{open:V,cwd:eg,homeDir:D,onClose:()=>q(!1),onSelectSession:e=>{eI(e)}}),(0,n.jsxs)("div",{style:{flex:"1 1 auto",overflowY:"auto",padding:"8px 8px 10px",minHeight:120},children:[(0,n.jsxs)("div",{style:{padding:"0 6px 6px 10px",display:"flex",alignItems:"center",justifyContent:"space-between",color:"var(--text-dim)"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>el(e=>!e),title:ei?"Collapse projects":"Expand projects","aria-expanded":ei,style:{display:"flex",alignItems:"center",gap:6,padding:"4px 0",background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:10,fontWeight:600,letterSpacing:"0.05em",textTransform:"uppercase",textAlign:"left"},children:[(0,n.jsx)("svg",{width:"9",height:"9",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:ei?"rotate(90deg)":"none",transition:"transform 0.15s",flexShrink:0},children:(0,n.jsx)("polyline",{points:"3 2 7 5 3 8"})}),"Projects"]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:5},children:[(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),ef()},disabled:E,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:E?"var(--accent)":"var(--text-dim)",cursor:E?"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:E?"spin 0.9s linear infinite":void 0},children:[(0,n.jsx)("path",{d:"M21 12a9 9 0 0 1-15.5 6.2"}),(0,n.jsx)("path",{d:"M3 12A9 9 0 0 1 18.5 5.8"}),(0,n.jsx)("path",{d:"M7 18H5.5v1.5"}),(0,n.jsx)("path",{d:"M17 6h1.5V4.5"})]})}),(0,n.jsxs)("button",{type:"button",onClick:ey,title:"Add project","aria-label":"Add project",style:{height:24,display:"flex",alignItems:"center",justifyContent:"center",gap:5,padding:"0 6px",border:"none",borderRadius:6,background:"transparent",color:"var(--text-dim)",cursor:"pointer",flexShrink:0,fontSize:11},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M1.5 4.5A1.5 1.5 0 0 1 3 3h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 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:"M8 7.5v3M6.5 9h3"})]}),"Add"]})]})]}),ei&&(0,n.jsxs)(n.Fragment,{children:[R&&0===ej.length&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Loading..."}),A&&(0,n.jsx)("div",{style:{padding:"12px 14px",color:"#f87171",fontSize:12},children:A}),!R&&!A&&0===ej.length&&(0,n.jsx)("button",{type:"button",onClick:ey,style:{width:"100%",padding:"12px 10px",border:"1px dashed var(--border)",borderRadius:8,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left"},children:"Add a project folder"}),!R&&!A&&ej.map(t=>{var r;let o=Z.has(t.cwd),i=t.cwd===eg,l=t.sessionsState,{visible:s,hiddenCount:a}=(r=function(e){let t=new Map;for(let r of e)t.set(r.id,{session:r,children:[]});let r=new Map;for(let t of e)t.parentSessionId&&r.set(t.id,t.parentSessionId);let n=[];for(let e of t.values()){let o=function(e){let n=r.get(e),o=new Set;for(;n&&!o.has(n);){if(o.add(n),t.has(n))return n;n=r.get(n)}return null}(e.session.id);o?t.get(o).children.push(e):n.push(e)}let o=e=>{e.sort((e,t)=>t.session.modified.localeCompare(e.session.modified)),e.forEach(e=>o(e.children))};return o(n),n}(t.sessions),K.has(t.cwd),{visible:r,hiddenCount:0});return(0,n.jsxs)("div",{style:{marginBottom:6},children:[(0,n.jsx)(S,{group:t,isCurrent:i,isCollapsed:o,isDragged:G===t.cwd,isDropTarget:Q===t.cwd&&G!==t.cwd,onToggle:()=>ek(t.cwd),onSelect:()=>eh(t.cwd),onTogglePinned:()=>void eS(t.cwd,!0!==t.project.pinned),onNewSession:e=>{e.stopPropagation(),eh(t.cwd),em(t.cwd)},onDragStart:()=>eC(t.cwd),onDragEnter:()=>{G&&G!==t.cwd&&ee(t.cwd)},onDrop:()=>void ez(t.cwd),onDragEnd:eT}),!o&&(0,n.jsxs)("div",{style:{marginTop:2,overflow:"hidden",borderRadius:7},children:[l?.loading&&(0,n.jsx)("div",{style:{padding:"8px 10px",color:"var(--text-dim)",fontSize:11},children:"Loading chats..."}),l?.error&&(0,n.jsx)("div",{style:{padding:"8px 10px",color:l.stale?"var(--text-dim)":"#f87171",fontSize:11},children:l.stale?`Showing cached chats. ${l.error}`:l.error}),!l?.loading&&!l?.error&&0===t.sessions.length&&l?.loaded?(0,n.jsx)("button",{type:"button",onClick:()=>{eh(t.cwd),em(t.cwd)},style:{width:"100%",padding:"10px 12px",background:"transparent",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:12},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:"Start a new session in this project"}):l?.loading||l?.error||!(t.sessions.length>0)?l?.loaded||l?.loading||l?.error?null:(0,n.jsx)("div",{style:{padding:"8px 10px",color:"var(--text-dim)",fontSize:11},children:t.lastAccessed?`Last active ${f(t.lastAccessed)}`:"No chats loaded"}):s.map(r=>(0,n.jsx)(C,{node:r,selectedSessionId:e,onSelectSession:eI,onRenamed:()=>void ea(t.cwd,!1),onSessionDeleted:e=>{c?.(e),ea(t.cwd,!1),es(!1)},depth:0},r.session.id)),a>0&&t.sessions.length>0&&(0,n.jsx)("button",{type:"button",onClick:()=>ew(t.cwd),style:{width:"100%",padding:"6px 10px",background:"transparent",border:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:11,textAlign:"center"},children:K.has(t.cwd)?"Show less":`Show ${Math.max(0,a)} more`})]})]},t.cwd||"__no_project")})]})]}),(0,n.jsx)(d,{open:_,initialPath:eg||D||null,onClose:()=>U(!1),onSelect:e=>void ex(e),externalError:H,onPathInputChange:()=>F(null)})]})}function S({group:e,isCurrent:t,isCollapsed:r,isDragged:i,isDropTarget:l,onToggle:s,onSelect:a,onTogglePinned:d,onNewSession:c,onDragStart:u,onDragEnter:p,onDrop:h,onDragEnd:x}){let[g,m]=(0,o.useState)(!1),v=e.lastAccessed,y=Math.max(0,e.project.chatCount??e.sessions.length??0),b=(0,o.useCallback)(()=>{t?s():a()},[t,a,s]);return(0,n.jsxs)("div",{draggable:!0,role:"button",tabIndex:0,onClick:b,onDragStart:t=>{t.dataTransfer.effectAllowed="move",t.dataTransfer.setData("text/plain",e.cwd),u()},onDragEnter:e=>{e.preventDefault(),p()},onDragOver:e=>{e.preventDefault(),e.dataTransfer.dropEffect="move"},onDrop:e=>{e.preventDefault(),e.stopPropagation(),h()},onDragEnd:x,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),b())},onMouseEnter:()=>m(!0),onMouseLeave:()=>m(!1),title:e.cwd,style:{width:"100%",height:32,display:"flex",alignItems:"center",gap:5,padding:"0 8px",background:t?"var(--bg-selected)":g?"var(--bg-hover)":"transparent",border:"none",borderRadius:6,boxShadow:l?"inset 0 0 0 1px rgba(37,99,235,0.45)":"none",color:"var(--text)",cursor:"grab",textAlign:"left",overflow:"hidden",transition:"background 0.12s, box-shadow 0.12s, opacity 0.12s",opacity:i?.55:1},children:[(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:r?"none":"rotate(90deg)",transition:"transform 0.15s",flexShrink:0,color:"var(--text-dim)"},children:(0,n.jsx)("polyline",{points:"3 2 7 5 3 8"})}),(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.35",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:t?"var(--accent)":"var(--text-dim)"},children:r?(0,n.jsx)("path",{d:"M1.5 4.5A1.5 1.5 0 0 1 3 3h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6v5A1.5 1.5 0 0 1 13 12.5H3A1.5 1.5 0 0 1 1.5 11V4.5Z"}):(0,n.jsx)("path",{d:"M1.5 5A1.5 1.5 0 0 1 3 3.5h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6.5L13.6 11A1.5 1.5 0 0 1 12.1 12.5H3A1.5 1.5 0 0 1 1.5 11V5Z"})}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13,fontWeight:t?650:560,color:"var(--text)"},children:e.displayName}),!e.project.exists&&(0,n.jsx)("span",{style:{flexShrink:0,color:"#f87171",fontSize:10},children:"missing"}),!g&&y>0&&(0,n.jsxs)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:[y," ",1===y?"chat":"chats"]}),!g&&v&&(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:f(v)}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),d()},title:e.project.pinned?"Unpin project":"Pin project",tabIndex:g||e.project.pinned?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,border:"none",borderRadius:5,background:e.project.pinned?"rgba(234,179,8,0.12)":"transparent",color:e.project.pinned?"#ca8a04":"var(--text-muted)",cursor:"pointer",flexShrink:0,opacity:g||e.project.pinned?1:0,pointerEvents:g||e.project.pinned?"auto":"none",transition:"opacity 0.12s, background 0.12s, color 0.12s"},onMouseEnter:t=>{e.project.pinned||(t.currentTarget.style.background="var(--bg-hover)",t.currentTarget.style.color="#ca8a04")},onMouseLeave:t=>{t.currentTarget.style.background=e.project.pinned?"rgba(234,179,8,0.12)":"transparent",t.currentTarget.style.color=e.project.pinned?"#ca8a04":"var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:e.project.pinned?"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"})]})}),(0,n.jsx)("button",{type:"button",onClick:c,title:"New chat in this project",tabIndex:g?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,border:"none",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,opacity:+!!g,pointerEvents:g?"auto":"none",transition:"opacity 0.12s, background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"6",y1:"1.5",x2:"6",y2:"10.5"}),(0,n.jsx)("line",{x1:"1.5",y1:"6",x2:"10.5",y2:"6"})]})})]})}function C({node:e,selectedSessionId:t,onSelectSession:r,onRenamed:i,onSessionDeleted:l,depth:s}){let[a,d]=(0,o.useState)(!1),c=e.children.length>0;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{position:"relative"},children:[s>0&&(0,n.jsx)("div",{style:{position:"absolute",left:12*s+6,top:0,bottom:0,width:1,background:"var(--border)",pointerEvents:"none"}}),(0,n.jsx)(z,{session:e.session,isSelected:e.session.id===t,onClick:()=>r(e.session),onRenamed:i,onDeleted:e=>l?.(e),depth:s,hasChildren:c,collapsed:a,onToggleCollapse:()=>d(e=>!e)})]}),c&&!a&&(0,n.jsx)("div",{children:e.children.map(e=>(0,n.jsx)(C,{node:e,selectedSessionId:t,onSelectSession:r,onRenamed:i,onSessionDeleted:l,depth:s+1},e.session.id))})]})}function z({session:e,isSelected:t,onClick:r,onRenamed:i,onDeleted:l,depth:s=0,hasChildren:a=!1,collapsed:d=!1,onToggleCollapse:c}){let[u,p]=(0,o.useState)(!1),[h,x]=(0,o.useState)(!1),[g,m]=(0,o.useState)(""),[v,y]=(0,o.useState)(!1),[b,j]=(0,o.useState)(!1),k=(0,o.useRef)(null),w=e.name||e.firstMessage.slice(0,50)||e.id.slice(0,12),S=(0,o.useCallback)(t=>{t.stopPropagation(),m(e.name??""),x(!0),setTimeout(()=>k.current?.select(),0)},[e.name]),C=(0,o.useCallback)(async()=>{let t=g.trim();if(x(!1),t!==(e.name??""))try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t})}),i?.()}catch{}},[g,e.id,e.name,i]),T=(0,o.useCallback)(e=>{e.stopPropagation(),y(!0)},[]),I=(0,o.useCallback)(async t=>{t.stopPropagation(),y(!1),j(!0);try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"DELETE"}),l?.(e.id)}catch{j(!1)}},[e.id,l]),M=(0,o.useCallback)(e=>{e.stopPropagation(),y(!1)},[]);return(0,n.jsx)("div",{onClick:v||h?void 0:r,onMouseEnter:()=>p(!0),onMouseLeave:()=>{p(!1)},style:{height:54,display:"flex",alignItems:"center",paddingLeft:s>0?12*s+14:14,paddingRight:8,cursor:v||h?"default":"pointer",background:v?"rgba(239,68,68,0.06)":t?"var(--bg-selected)":u?"var(--bg-hover)":"transparent",borderLeft:v?"2px solid #ef4444":t?"2px solid var(--accent)":"2px solid transparent",transition:"background 0.1s",opacity:b?.5:1,gap:6,overflow:"hidden"},children:v?(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:I,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,height:30,padding:"0 11px",background:"#ef4444",border:"none",borderRadius:6,color:"#fff",cursor:"pointer",fontSize:12,fontWeight:600,whiteSpace:"nowrap"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,n.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,n.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,n.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]}),"Delete"]}),(0,n.jsx)("button",{onClick:M,style:{display:"flex",alignItems:"center",justifyContent:"center",height:30,padding:"0 11px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:500,whiteSpace:"nowrap"},children:"Cancel"})]})]}):h?(0,n.jsx)("input",{ref:k,value:g,onChange:e=>m(e.target.value),onBlur:C,onKeyDown:e=>{"Enter"===e.key&&C(),"Escape"===e.key&&x(!1)},autoFocus:!0,style:{flex:1,fontSize:12,padding:"5px 8px",border:"1px solid var(--accent)",borderRadius:5,outline:"none",background:"var(--bg)",color:"var(--text)",height:30}}):(0,n.jsxs)(n.Fragment,{children:[s>0&&(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:t?500:400,lineHeight:1.4,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text)"},title:w,children:w}),(0,n.jsxs)("div",{style:{marginTop:2,display:"flex",gap:8,color:"var(--text-dim)",fontSize:11},children:[(0,n.jsx)("span",{title:e.modified,children:f(e.modified)}),(0,n.jsxs)("span",{children:[e.messageCount," msgs"]}),!1===e.cwdExists&&(0,n.jsx)("span",{title:`Project path missing: ${e.cwd}`,style:{color:"#f87171"},children:"missing path"})]})]}),a&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),c?.()},title:d?"Expand forks":"Collapse forks",style:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,flexShrink:0,background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",transform:d?"rotate(-90deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})}),u&&(0,n.jsxs)("div",{style:{display:"flex",gap:4,flexShrink:0},children:[(0,n.jsx)("button",{onClick: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",flexShrink:0,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",flexShrink:0,transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.08)",e.currentTarget.style.color="#ef4444",e.currentTarget.style.borderColor="rgba(239,68,68,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,n.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,n.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,n.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]})})]})]})})}var T=r(97031),I=r(97894),M=r(16764);let L=new Set;function R(e){return L.add(e),()=>{L.delete(e)}}function W(){return"u"<typeof document?"light":document.documentElement.classList.contains("dark")?"dark":"light"}function E(){return"light"}function $(){let e=(0,o.useSyncExternalStore)(R,W,E);return{theme:e,toggleTheme:(0,o.useCallback)(e=>{let t="dark"===W()?"light":"dark",r=()=>{"dark"===t?document.documentElement.classList.add("dark"):document.documentElement.classList.remove("dark");try{localStorage.setItem("annodex-theme",t)}catch{}L.forEach(e=>e())},n=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;if("function"!=typeof document.startViewTransition||n)return void r();let o=e?.x??window.innerWidth/2,i=e?.y??window.innerHeight/2,l=Math.hypot(Math.max(o,window.innerWidth-o),Math.max(i,window.innerHeight-i));document.startViewTransition(r).ready.then(()=>{document.documentElement.animate({clipPath:[`circle(0px at ${o}px ${i}px)`,`circle(${l}px at ${o}px ${i}px)`]},{duration:450,easing:"cubic-bezier(0.22, 0.61, 0.36, 1)",pseudoElement:"::view-transition-new(root)"})}).catch(()=>{})},[]),isDark:"dark"===e}}function A({chart:e}){let{isDark:t}=$(),[i,l]=(0,o.useState)(null),[s,a]=(0,o.useState)(null),d=(0,o.useRef)(`mermaid-${Math.random().toString(36).slice(2)}`);return((0,o.useEffect)(()=>{let n=!1,o=e.trim();return(l(null),a(null),o)?(Promise.all([r.e(2941),r.e(2995),r.e(3308)]).then(r.bind(r,43328)).then(({default:e})=>(e.initialize({startOnLoad:!1,securityLevel:"strict",theme:t?"dark":"default",suppressErrorRendering:!0}),e.parse(o,{suppressErrors:!0}).then(t=>{if(!t)throw Error("Invalid Mermaid syntax");return e.render(`${d.current}-${Date.now()}`,o)}))).then(e=>{n||l(e.svg)}).catch(e=>{n||a(e instanceof Error?e.message:String(e))}),()=>{n=!0}):void a("Empty Mermaid diagram")},[e,t]),s)?(0,n.jsxs)("div",{className:"mermaid-diagram mermaid-diagram-error",children:[(0,n.jsx)("div",{className:"mermaid-diagram-error-title",children:"Mermaid render failed"}),(0,n.jsx)("div",{className:"mermaid-diagram-error-message",children:s}),(0,n.jsx)("pre",{children:e})]}):(0,n.jsx)("div",{className:"mermaid-diagram",children:i?(0,n.jsx)("div",{className:"mermaid-diagram-canvas",dangerouslySetInnerHTML:{__html:i}}):(0,n.jsx)("div",{className:"mermaid-diagram-loading",children:"Rendering diagram..."})})}function B(e){let t,r=[],n=/`{1,3}show-widget`{0,3}\s*(?:\n\s*`{3}(?:json|html)?\s*)?\n?/g,o=0,i=!1;for(;null!==(t=n.exec(e));){i=!0;let l=e.slice(o,t.index).trim();l&&r.push({type:"text",content:l});let s=t.index+t[0].length,a=e.indexOf("```",s),d=e.indexOf("{",s);if(-1!==d&&d<=s+200&&(-1===a||d<a)){let t=function(e,t){let r=0,n=!1,o=!1;for(let i=t;i<e.length;i++){let t=e[i];if(o){o=!1;continue}if("\\"===t&&n){o=!0;continue}if('"'===t){n=!n;continue}if(!n&&("{"===t&&r++,"}"===t)&&0==--r)return i}return -1}(e,d);if(-1===t){let t=function(e){try{let t=N(e);if(t)return t}catch{}let t=e.indexOf('"widget_code"');if(-1===t)return null;let r=e.indexOf(":",t+13);if(-1===r)return null;let n=e.indexOf('"',r+1);if(-1===n)return null;let o=e.slice(n+1);(o=o.replace(/"\s*\}\s*$/,"")).endsWith("\\")&&(o=o.slice(0,-1));let i=e.match(/"title"\s*:\s*"([^"]*?)"/)?.[1],l=P(o.replace(/\\\\/g,"\0BACKSLASH\0").replace(/\\n/g,"\n").replace(/\\t/g," ").replace(/\\r/g,"\r").replace(/\\"/g,'"').replace(/\\u([0-9a-fA-F]{4})/g,(e,t)=>String.fromCharCode(parseInt(t,16))).replace(/\x00BACKSLASH\x00/g,"\\"));return l.code.trim()?{title:i,code:l.code,showOverlay:l.truncated}:null}(e.slice(d));t&&r.push({type:"widget",...t,partial:!0}),o=e.length;break}let i=N(e.slice(d,t+1).trim());i&&r.push({type:"widget",...i});let l=t+1,s=e.slice(l,l+16).match(/^\s*\n?`{1,3}\s*/);s&&(l+=s[0].length),o=l,n.lastIndex=l;continue}if(-1!==a){let t=e.slice(s,a).trim(),i=N(t);i?r.push({type:"widget",...i}):t&&r.push({type:"text",content:t}),n.lastIndex=o=a+3}else{let t=N(e.slice(s).trim());if(t){let e=P(t.code);r.push({type:"widget",title:t.title,code:e.code,partial:!0,showOverlay:e.truncated})}o=e.length;break}}let l=e.slice(o).trim();return l&&r.push({type:"text",content:l}),!i&&0===r.length&&e.trim()&&r.push({type:"text",content:e}),r}function N(e){if(e.startsWith("{")){if(!e.endsWith("}"))return null;try{let t=JSON.parse(e),r=t.widget_code??t.code;if(r)return{title:t.title,code:r}}catch{return null}}return/<(!DOCTYPE|html|svg|canvas|script|style|div)/i.test(e)?{code:e}:null}function P(e){let t=e.lastIndexOf("<script");if(-1===t)return{code:e,truncated:!1};let r=e.slice(t);return/<script[\s\S]*?<\/script>/i.test(r)?{code:e,truncated:!1}:{code:e.slice(0,t).trim(),truncated:!0}}let D=/<(iframe|object|embed|meta|link|base|form)[\s>][\s\S]*?<\/\1>/gi,O=/<(iframe|object|embed|meta|link|base)\b[^>]*\/?>/gi;function H(e){return e.replace(D,"").replace(O,"")}let F=["--bg","--bg-panel","--bg-hover","--bg-selected","--border","--text","--text-muted","--text-dim","--accent","--accent-hover"];function _(){if("u"<typeof document)return{};let e=getComputedStyle(document.documentElement),t={};for(let r of F){let n=e.getPropertyValue(r).trim();n&&(t[r]=n)}return t}let U=["--bg","--bg-panel","--bg-hover","--bg-selected","--border","--text","--text-muted","--text-dim","--accent","--accent-hover"];async function V(e){if(navigator.clipboard?.writeText)return void await navigator.clipboard.writeText(e);let t=document.createElement("textarea");t.value=e,t.style.position="fixed",t.style.inset="0",t.style.opacity="0",document.body.appendChild(t),t.focus(),t.select();let r=document.execCommand("copy");if(document.body.removeChild(t),!r)throw Error("Clipboard copy failed.")}async function q(e){let t=await K(e.code);if(t)return t;if(e.capture)return function(e){if(!e.html)throw Error("The widget did not provide capturable HTML.");let t=Y({width:e.bodyWidth||640,height:e.bodyHeight||360}),r=function(e){let t=document.createElement("template");t.innerHTML=H(e.html||"");let r=document.createElement("div");for(let n of(r.appendChild(t.content.cloneNode(!0)),Array.from(r.querySelectorAll("img[data-canvas-export]")))){let t=Number(n.getAttribute("data-canvas-export")),r=Number.isFinite(t)?e.canvases?.[t]:null;if(!r?.dataUrl){n.remove();continue}n.setAttribute("src",r.dataUrl),n.setAttribute("width",String(r.width)),n.setAttribute("height",String(r.height)),n.setAttribute("style",function(e,t){let r=new Map;for(let t of(e||"").split(";")){let[e,...n]=t.split(":");e?.trim()&&n.length>0&&r.set(e.trim(),n.join(":").trim())}for(let[e,n]of Object.entries(t))r.set(e,n);return Array.from(r.entries()).map(([e,t])=>e+":"+t).join(";")}(n.getAttribute("style"),{width:r.width+"px",height:r.height+"px",display:"block"}))}return J(r),Array.from(r.childNodes).map(e=>new XMLSerializer().serializeToString(e)).join("")}(e);if(!r.trim())throw Error("The widget capture was empty.");let n=[e.styles||"","#__widget_export_root{"+function(){if("u"<typeof document)return"";let e=getComputedStyle(document.documentElement);return U.map(t=>{let r=e.getPropertyValue(t).trim();return r?t+":"+r+";":""}).join("")}()+'font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",system-ui,sans-serif;font-size:14px;line-height:1.6;color:var(--text,#1a1a1a);background:transparent;}',"#__widget_export_root *{box-sizing:border-box;}\n#__widget_export_root svg{max-width:100%;height:auto;display:block;}"].join("\n");return X(Q('<svg xmlns="http://www.w3.org/2000/svg" width="'+t.width+'" height="'+t.height+'" viewBox="0 0 '+t.width+" "+t.height+'"><defs><style><![CDATA['+n.replace(/\]\]>/g,"]]]]><![CDATA[>")+']]></style></defs><foreignObject x="0" y="0" width="100%" height="100%">'+('<div xmlns="http://www.w3.org/1999/xhtml" id="__widget_export_root" style="width:'+t.width+"px;min-height:")+t.height+'px;overflow:visible;">'+r+"</div></foreignObject></svg>"),t.width,t.height)}(e.capture);throw Error("PNG export needs a rendered widget capture.")}async function K(e){var t;let r,n,o,i,l=function(e){let t=H(e).trim();if(!/^<\s*(style|svg)\b/i.test(t))return null;let r=new DOMParser().parseFromString(t,"text/html"),n=Array.from(r.body.children),o=n.filter(e=>"svg"===e.tagName.toLowerCase()),i=n.filter(e=>"style"!==e.tagName.toLowerCase());if(1!==o.length||1!==i.length)return null;let l=o[0].cloneNode(!0),s=Array.from(r.body.querySelectorAll("style")).map(e=>e.textContent||"").join("\n").trim();if(s){let e=document.createElementNS("http://www.w3.org/2000/svg","style");e.textContent=s,l.insertBefore(e,l.firstChild)}return l}(e);if(!l)return null;J(l),l.setAttribute("xmlns","http://www.w3.org/2000/svg");let s=Y((r=function(e){if(!e)return null;let t=e.trim().split(/[\s,]+/).map(Number);return 4!==t.length||t.some(e=>!Number.isFinite(e))||t[2]<=0||t[3]<=0?null:{width:t[2],height:t[3]}}((t=l).getAttribute("viewBox")),n=Z(t.getAttribute("width"))??r?.width??640,o=r?r.height/r.width:.5625,i=Z(t.getAttribute("height"))??r?.height??n*o,{width:n,height:i}));return l.setAttribute("width",String(s.width)),l.setAttribute("height",String(s.height)),l.getAttribute("viewBox")||l.setAttribute("viewBox","0 0 "+s.width+" "+s.height),X(Q(new XMLSerializer().serializeToString(l)),s.width,s.height)}function J(e){for(let t of Array.from(e.querySelectorAll("script, iframe, object, embed, meta, link, base, form")))t.remove();for(let t of[e,...Array.from(e.querySelectorAll("*"))])for(let e of Array.from(t.attributes)){let r=e.name.toLowerCase(),n=e.value.trim();if(r.startsWith("on")){t.removeAttribute(e.name);continue}("href"===r||"src"===r||r.endsWith(":href"))&&/^\s*(javascript|data:text\/html)/i.test(n)&&t.removeAttribute(e.name)}}function Z(e){if(!e||e.includes("%"))return null;let t=Number.parseFloat(e);return Number.isFinite(t)&&t>0?t:null}function Y(e){let t=G(Math.ceil(e.width||640),240,2e3),r=G(Math.ceil(e.height||360),80,4e3),n=t*r;if(n>8e6){let e=Math.sqrt(8e6/n);t=Math.max(240,Math.floor(t*e)),r=Math.max(80,Math.floor(r*e))}return{width:t,height:r}}function G(e,t,r){return Math.min(Math.max(e,t),r)}function X(e,t,r){return new Promise((n,o)=>{let i=new Image,l=URL.createObjectURL(new Blob([e],{type:"image/svg+xml;charset=utf-8"}));i.onload=()=>{URL.revokeObjectURL(l);try{let e=document.createElement("canvas"),l=Math.min(window.devicePixelRatio||1,2);e.width=Math.ceil(t*l),e.height=Math.ceil(r*l),e.style.width=t+"px",e.style.height=r+"px";let s=e.getContext("2d");if(!s)throw Error("Canvas is not available.");s.scale(l,l),s.drawImage(i,0,0,t,r),e.toBlob(e=>{e?n(e):o(Error("Canvas export returned no image."))},"image/png")}catch(e){o(e instanceof Error?e:Error("PNG export failed."))}},i.onerror=()=>{URL.revokeObjectURL(l),o(Error("The browser could not render this widget as PNG."))},i.src=l})}function Q(e){if("u"<typeof document)return e;let t=getComputedStyle(document.documentElement);return e.replace(/var\(\s*(--[a-zA-Z0-9_-]+)(?:\s*,\s*([^)]+))?\)/g,(e,r,n)=>t.getPropertyValue(r).trim()||n?.trim()||"#000")}let ee=/cdnjs\.cloudflare\.com|cdn\.jsdelivr\.net|unpkg\.com|esm\.sh/,et=new Map;function er(e){return e.slice(0,200)}function en({code:e,isStreaming:t,title:r,showOverlay:i,onSendMessage:l}){let{isDark:s}=$(),a=(0,o.useRef)(null),d=(0,o.useRef)(null),c=(0,o.useRef)(null),u=(0,o.useRef)(new Map),p=(0,o.useRef)(""),[h,x]=(0,o.useState)(!1),[g,f]=(0,o.useState)(()=>et.get(er(e))??0),[m,v]=(0,o.useState)(!1),[y,b]=(0,o.useState)(!1),[j,k]=(0,o.useState)(null),[w,S]=(0,o.useState)(!1),[C,z]=(0,o.useState)(!1),T=(0,o.useRef)(""),I=(0,o.useRef)((et.get(er(e))??0)>0),M=(0,o.useRef)(!1),L=(0,o.useRef)(s),R=(0,o.useMemo)(()=>ee.test(e),[e]),W=(0,o.useMemo)(()=>{let e;return function(e="",t=!1){return`<!DOCTYPE html>
|
|
1
|
+
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6364],{17865:(e,t,r)=>{"use strict";r.d(t,{AppShell:()=>oy});var n=r(95155),o=r(12115),i=r(73321);function l(e,t){let r=t&&e.startsWith(t)?"~"+e.slice(t.length):e,n=r.includes("/")?"/":"\\",o=r.split(n).filter(Boolean);return o.length<=2?r:"..."+n+o.slice(-2).join(n)}function s(e){let t=new Date(e);return Number.isNaN(t.getTime())?"":t.toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function a({open:e,cwd:t,homeDir:r,onClose:i,onSelectSession:d}){let[c,u]=(0,o.useState)(""),[p,h]=(0,o.useState)("current"),[x,g]=(0,o.useState)([]),[f,m]=(0,o.useState)(!1),[v,y]=(0,o.useState)(null),[b,j]=(0,o.useState)(!1),k=(0,o.useRef)(null);if((0,o.useEffect)(()=>{e&&(h(t?"current":"all"),setTimeout(()=>k.current?.focus(),0))},[e,t]),(0,o.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&i()};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,i]),(0,o.useEffect)(()=>{if(!e)return;let r=c.trim();if(r.length<2){g([]),m(!1),y(null),j(!1);return}let n=new AbortController,o=setTimeout(async()=>{m(!0),y(null);try{let e=new URLSearchParams({q:r,scope:p});t&&e.set("cwd",t);let o=await fetch(`/api/search?${e.toString()}`,{signal:n.signal});if(!o.ok)throw Error(`HTTP ${o.status}`);let i=await o.json();if(i.error)throw Error(i.error);g(i.results??[]),j(i.truncated??!1)}catch(e){"AbortError"!==e.name&&y(String(e))}finally{m(!1)}},180);return()=>{clearTimeout(o),n.abort()}},[e,c,p,t]),!e)return null;let w=c.trim(),S=x.reduce((e,t)=>e+t.matches.length,0);return(0,n.jsx)("div",{role:"dialog","aria-modal":"true","aria-label":"Search conversation history",style:{position:"fixed",inset:0,zIndex:500,display:"flex",alignItems:"flex-start",justifyContent:"center",padding:"8vh 16px 16px",background:"rgba(0,0,0,0.28)"},onMouseDown:e=>{e.target===e.currentTarget&&i()},children:(0,n.jsxs)("div",{style:{width:"min(760px, 100%)",maxHeight:"78vh",display:"flex",flexDirection:"column",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 16px 48px rgba(0,0,0,0.24)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:12,borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1,minWidth:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:8,padding:"0 10px"},children:[(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"7",cy:"7",r:"4.5"}),(0,n.jsx)("path",{d:"M10.5 10.5 13.5 13.5"})]}),(0,n.jsx)("input",{ref:k,value:c,onChange:e=>u(e.target.value),placeholder:"Search conversation history...",style:{flex:1,minWidth:0,height:38,background:"transparent",border:"none",outline:"none",color:"var(--text)",fontSize:14}})]}),(0,n.jsx)("button",{type:"button",onClick:i,title:"Close",style:{width:34,height:34,display:"inline-flex",alignItems:"center",justifyContent:"center",background:"none",border:"none",borderRadius:7,color:"var(--text-dim)",cursor:"pointer"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-dim)"},children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,n.jsx)("path",{d:"M4 4 12 12"}),(0,n.jsx)("path",{d:"M12 4 4 12"})]})})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:10},children:[(0,n.jsx)("div",{style:{display:"inline-flex",padding:2,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7},children:[{value:"current",label:"Current project",disabled:!t},{value:"all",label:"All history",disabled:!1}].map(e=>(0,n.jsx)("button",{type:"button",disabled:e.disabled,onClick:()=>h(e.value),style:{height:24,padding:"0 9px",background:p===e.value?"var(--bg-selected)":"transparent",border:"none",borderRadius:5,color:e.disabled?"var(--text-dim)":p===e.value?"var(--text)":"var(--text-muted)",cursor:e.disabled?"not-allowed":"pointer",fontSize:11,fontWeight:500},children:e.label},e.value))}),(0,n.jsx)("div",{style:{flex:1,minWidth:0,color:"var(--text-dim)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"current"===p&&t?l(t,r):"Searching every saved session"})]})]}),(0,n.jsxs)("div",{style:{flex:1,overflowY:"auto",minHeight:180},children:[w.length<2&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Type at least 2 characters to search saved conversations."}),w.length>=2&&f&&0===x.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Searching..."}),v&&(0,n.jsx)("div",{style:{padding:18,color:"#ef4444",fontSize:13},children:v}),w.length>=2&&!f&&!v&&0===x.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"No matching conversations found."}),x.map(e=>(0,n.jsxs)("div",{style:{borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{d(e.session),i()},style:{width:"100%",display:"flex",alignItems:"center",gap:10,padding:"10px 12px",background:"var(--bg-panel)",border:"none",borderBottom:"1px solid var(--border)",color:"var(--text)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13,fontWeight:600},children:e.session.name||e.session.firstMessage||"(no messages)"}),(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:11},children:s(e.session.modified)})]}),(0,n.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l(e.session.cwd,r)})]}),e.matchCount>e.matches.length&&(0,n.jsxs)("span",{style:{flexShrink:0,color:"var(--text-muted)",fontSize:11},children:[e.matchCount," matches"]})]}),e.matches.map(t=>(0,n.jsxs)("button",{type:"button",onClick:()=>{d(e.session),i()},style:{width:"100%",padding:"9px 14px 9px 28px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:3},children:[(0,n.jsx)("span",{style:{minWidth:54,color:"user"===t.role?"var(--accent)":"var(--text-dim)",fontSize:11,fontWeight:600,textTransform:"capitalize"},children:t.role}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:s(t.timestamp)})]}),(0,n.jsx)("div",{style:{fontSize:12,lineHeight:1.45,color:"var(--text-muted)"},children:function(e,t){let r=t.trim();if(!r)return e;let o=e.toLowerCase().indexOf(r.toLowerCase());return o<0?e:(0,n.jsxs)(n.Fragment,{children:[e.slice(0,o),(0,n.jsx)("mark",{style:{background:"rgba(37,99,235,0.16)",color:"var(--text)",borderRadius:3,padding:"0 2px"},children:e.slice(o,o+r.length)}),e.slice(o+r.length)]})}(t.snippet,w)})]},t.entryId))]},e.session.id))]}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",padding:"8px 12px",borderTop:"1px solid var(--border)",color:"var(--text-dim)",fontSize:11},children:[(0,n.jsx)("span",{children:S>0?`${S}${b?"+":""} results`:"Esc to close"}),f&&x.length>0&&(0,n.jsx)("span",{children:"Updating..."})]})]})})}function d({open:e,initialPath:t,onClose:r,onSelect:i,externalError:l,onPathInputChange:s}){let[a,c]=(0,o.useState)(""),[u,p]=(0,o.useState)(null),[h,x]=(0,o.useState)([]),[g,f]=(0,o.useState)([]),[m,v]=(0,o.useState)(""),[y,b]=(0,o.useState)(!1),[j,k]=(0,o.useState)(null),w=(0,o.useCallback)(async e=>{b(!0),k(null);try{let t=e?`/api/projects/browse?dir=${encodeURIComponent(e)}`:"/api/projects/browse",r=await fetch(t),n=await r.json();if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);c(n.current??""),p(n.parent??null),x(n.directories??[]),f(n.drives??[]),v(n.current??"")}catch(e){k(e instanceof Error?e.message:String(e))}finally{b(!1)}},[]);return((0,o.useEffect)(()=>{e&&w(t||void 0)},[w,t,e]),(0,o.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&r()};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[r,e]),e)?(0,n.jsx)("div",{onMouseDown:e=>{e.target===e.currentTarget&&r()},style:{position:"fixed",inset:0,zIndex:1200,display:"flex",alignItems:"center",justifyContent:"center",padding:18,background:"rgba(0,0,0,0.34)"},children:(0,n.jsxs)("div",{style:{width:"min(560px, 100%)",maxHeight:"min(720px, 88dvh)",display:"flex",flexDirection:"column",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 12px 40px rgba(0,0,0,0.25)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{height:48,padding:"0 14px",display:"flex",alignItems:"center",justifyContent:"space-between",borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:14,fontWeight:750},children:"Add project folder"}),(0,n.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:11},children:"Choose a folder or enter a path"})]}),(0,n.jsx)("button",{type:"button",onClick:r,"aria-label":"Close",title:"Close",style:{width:30,height:30,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:"x"})]}),(0,n.jsx)("div",{style:{padding:12,borderBottom:"1px solid var(--border)"},children:(0,n.jsxs)("form",{onSubmit:e=>{e.preventDefault(),m.trim()&&i(m.trim())},style:{display:"flex",flexDirection:"column",gap:7},children:[(0,n.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,n.jsx)("input",{value:m,onChange:e=>{v(e.target.value),s?.()},placeholder:"/path/to/project",style:{flex:1,minWidth:0,height:32,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:12,outline:"none"}}),(0,n.jsx)("button",{type:"button",onClick:()=>m.trim()&&void w(m.trim()),style:{height:32,padding:"0 11px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Browse"}),(0,n.jsx)("button",{type:"submit",disabled:!m.trim(),style:{height:32,padding:"0 12px",border:"none",borderRadius:6,background:m.trim()?"var(--accent)":"var(--bg-hover)",color:m.trim()?"#fff":"var(--text-dim)",cursor:m.trim()?"pointer":"default",fontSize:12,fontWeight:650},children:"Use path"})]}),l&&(0,n.jsx)("div",{style:{color:"#f87171",fontSize:11,lineHeight:1.4,overflowWrap:"anywhere"},children:l})]})}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"8px 12px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsx)("button",{type:"button",onClick:()=>u&&void w(u),disabled:!u,style:{width:28,height:28,border:"1px solid var(--border)",borderRadius:6,background:u?"var(--bg)":"transparent",color:u?"var(--text-muted)":"var(--text-dim)",cursor:u?"pointer":"default",padding:0},title:"Up",children:(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"2 6.5 5 3.5 8 6.5"})})}),g.length>0&&(0,n.jsxs)("select",{value:g.find(e=>a.toLowerCase().startsWith(e.toLowerCase()))??"",onChange:e=>{e.target.value&&w(e.target.value)},style:{height:28,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text-muted)",fontSize:12},children:[(0,n.jsx)("option",{value:"",children:"Drive"}),g.map(e=>(0,n.jsx)("option",{value:e,children:e},e))]}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11},title:a,children:a})]}),(0,n.jsx)("div",{style:{flex:1,minHeight:220,maxHeight:360,overflowY:"auto",padding:6},children:y?(0,n.jsx)("div",{style:{padding:18,color:"var(--text-muted)",fontSize:12},children:"Loading..."}):j?(0,n.jsx)("div",{style:{padding:18,color:"#f87171",fontSize:12},children:j}):0===h.length?(0,n.jsx)("div",{style:{padding:18,color:"var(--text-muted)",fontSize:12},children:"No subdirectories"}):h.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>void w(e.path),style:{width:"100%",display:"flex",alignItems:"center",gap:9,padding:"8px 9px",border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:12},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},title:e.path,children:[(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--accent)",flexShrink:0},children:(0,n.jsx)("path",{d:"M3 6.5A2.5 2.5 0 0 1 5.5 4H10l2 2.5h6.5A2.5 2.5 0 0 1 21 9v8.5A2.5 2.5 0 0 1 18.5 20h-13A2.5 2.5 0 0 1 3 17.5v-11Z"})}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0},children:(0,n.jsx)("polyline",{points:"3.5 2 6.5 5 3.5 8"})})]},e.path))}),(0,n.jsxs)("div",{style:{padding:12,borderTop:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",gap:10},children:[(0,n.jsx)("div",{style:{minWidth:0,color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:a,children:a}),(0,n.jsxs)("div",{style:{display:"flex",gap:7,flexShrink:0},children:[(0,n.jsx)("button",{type:"button",onClick:r,style:{height:32,padding:"0 12px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Cancel"}),(0,n.jsx)("button",{type:"button",onClick:()=>a&&i(a),disabled:!a,style:{height:32,padding:"0 12px",border:"none",borderRadius:6,background:a?"var(--accent)":"var(--bg-hover)",color:a?"#fff":"var(--text-dim)",cursor:a?"pointer":"default",fontSize:12,fontWeight:650},children:"Select"})]})]})]})}):null}var c=r(65673);let u="annodex:sidebar:collapsed-projects",p=["annovibe:sidebar:collapsed-projects","pidex:sidebar:collapsed-projects"],h="annodex:sidebar:collapsed-projects:init-v2";function x(e){window.localStorage.setItem(u,JSON.stringify([...e]))}async function g(e,t){let r=`${e}: HTTP ${t.status}`;try{let n=await t.json();return"string"==typeof n.error&&n.error?`${e}: ${n.error}`:r}catch{return r}}function f(e){let t=new Date(e),r=new Date().getTime()-t.getTime(),n=Math.floor(r/6e4),o=Math.floor(r/36e5),i=Math.floor(r/864e5);return n<1?"just now":n<60?`${n}m ago`:o<24?`${o}h ago`:i<7?`${i}d ago`:t.toLocaleDateString()}function m(e,t){let r,n,o;if(!e)return"No Project";let i=e.replace(/[\\/]+$/,""),l=i.includes("/")?"/":"\\";return i.split(l).filter(Boolean).pop()||(n=(r=t&&e.startsWith(t)?"~"+e.slice(t.length):e).includes("/")?"/":"\\",(o=r.split(n).filter(Boolean)).length<=2?r:"…/"+o.slice(-2).join(n))}function v(e){return e.lastAccessed??e.created??""}function y(e,t){let r=e.displayName.toLocaleLowerCase(),n=t.displayName.toLocaleLowerCase(),o=r.localeCompare(n,void 0,{numeric:!0,sensitivity:"base"});return 0!==o?o:e.cwd.localeCompare(t.cwd)}function b(e,t){let r=!0===e.pinned;if(r!==(!0===t.pinned))return r?-1:1;let n=Number.isFinite(e.sortOrder)?e.sortOrder:null,o=Number.isFinite(t.sortOrder)?t.sortOrder:null;return null!==n&&null!==o&&n!==o?n-o:null!==n&&null===o?-1:null===n&&null!==o?1:y(e,t)}let j="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";function k(){let[e,t]=(0,o.useState)(!1),[r,i]=(0,o.useState)(!1),l=(0,o.useRef)(null),s=function(e,t){let[r,n]=(0,o.useState)(e),i=(0,o.useRef)(null),l=(0,o.useRef)(0);return(0,o.useEffect)(()=>{if(!t)return void n(e);l.current=0;let r=4*e.length,o=()=>{l.current+=1;let t=Math.floor(l.current/r*e.length);n(e.split("").map((e,r)=>" "===e?" ":r<t?e:j[Math.floor(Math.random()*j.length)]).join("")),l.current<r?i.current=requestAnimationFrame(o):n(e)};return i.current=requestAnimationFrame(o),()=>{i.current&&cancelAnimationFrame(i.current)}},[e,t]),r}(e?"v0.1.46":c.C3,r),a=(0,o.useCallback)(e=>{t(e),i(!0),setTimeout(()=>i(!1),(e?6:8)*4*(1e3/60)+100)},[]),d=(0,o.useCallback)(()=>{l.current&&clearTimeout(l.current);let t=!e;a(t),t&&(l.current=setTimeout(()=>a(!1),3e3))},[e,a]);return(0,o.useEffect)(()=>()=>{l.current&&clearTimeout(l.current)},[]),(0,n.jsx)("button",{onClick:d,style:{background:"none",border:"none",padding:0,cursor:"default",fontWeight:700,fontSize:15,letterSpacing:"-0.01em",color:e?"var(--accent)":"var(--text)",fontFamily:"var(--font-mono)",minWidth:"9ch"},children:s})}function w({selectedSessionId:e,onSelectSession:t,onNewSession:r,initialSessionId:i,onInitialRestoreDone:l,refreshKey:s,onSessionDeleted:c,selectedCwd:j,onCwdChange:z}){let[T,I]=(0,o.useState)([]),[M,L]=(0,o.useState)({}),[R,W]=(0,o.useState)(!0),[E,$]=(0,o.useState)(!1),[A,B]=(0,o.useState)(null),[N,P]=(0,o.useState)(null),[D,O]=(0,o.useState)(""),[H,F]=(0,o.useState)(null),[_,U]=(0,o.useState)(!1),[V,q]=(0,o.useState)(!1),[K,J]=(0,o.useState)(new Set),[Z,Y]=(0,o.useState)(()=>(function(){try{for(let e of[u,...p]){let t=window.localStorage.getItem(e);if(t)return new Set(JSON.parse(t))}}catch{}return new Set})()),[G,X]=(0,o.useState)(null),[Q,ee]=(0,o.useState)(null),et=(0,o.useRef)(!1),er=(0,o.useRef)(!1),en=(0,o.useRef)(!1),eo=(0,o.useRef)(!1),[ei,el]=(0,o.useState)(!0),es=(0,o.useCallback)(async(e=!1)=>{try{e&&(B(null),W(!0));let t=new AbortController,r=setTimeout(()=>t.abort(),15e3),n=await fetch("/api/projects",{signal:t.signal});if(clearTimeout(r),!n.ok)throw Error(await g("projects",n));let o=await n.json();I(o.projects),B(null)}catch(e){B(String(e))}finally{e&&W(!1)}},[]),ea=(0,o.useCallback)(async(e,t=!1)=>{if(e){L(t=>({...t,[e]:{sessions:t[e]?.sessions??[],loaded:t[e]?.loaded??!1,error:null,loading:!0,stale:t[e]?.stale??!1}}));try{t&&W(!0);let r=new AbortController,n=setTimeout(()=>r.abort(),15e3),o=await fetch(`/api/sessions?cwd=${encodeURIComponent(e)}`,{signal:r.signal});if(clearTimeout(n),!o.ok)throw Error(await g("sessions",o));let i=await o.json();L(t=>({...t,[e]:{sessions:i.sessions,loaded:!0,loading:!1,error:null,stale:!1}}))}catch(r){let t=String(r);L(r=>({...r,[e]:{sessions:r[e]?.sessions??[],loaded:r[e]?.loaded??!1,loading:!1,error:t,stale:(r[e]?.sessions?.length??0)>0}}))}finally{t&&W(!1)}}},[]),ed=(0,o.useRef)(!1);(0,o.useEffect)(()=>{let e=!ed.current;ed.current=!0,es(e)},[es,s]),(0,o.useEffect)(()=>{fetch("/api/home").then(e=>e.json()).then(e=>{e.home&&O(e.home)}).catch(()=>{})},[]),(0,o.useEffect)(()=>{if(et.current){et.current=!1;return}if(er.current){er.current=!1;return}z?.(N)},[N,z]);let ec=(0,o.useCallback)(async(e,t=!1)=>{try{let r=await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,create:t})}),n=await r.json();if(!r.ok||n.error)return F(n.error??`HTTP ${r.status}`),!1;return es(!1),!0}catch(e){return F(e instanceof Error?e.message:String(e)),!1}},[es]),eu=(0,o.useCallback)(e=>{fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,touch:!0})}).catch(()=>{})},[]),ep=(0,o.useCallback)(async e=>{let t=await fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw Error(await g("projects",t));let r=await t.json();Array.isArray(r.projects)&&I(r.projects)},[]);(0,o.useEffect)(()=>{if(!i||eo.current)return;let e=!1;return fetch(`/api/sessions/${encodeURIComponent(i)}?infoOnly=1`).then(e=>e.ok?e.json():null).then(r=>{if(e||eo.current)return;let n=r?.info??null;n&&(eo.current=!0,P(n.cwd),Y(e=>{if(!e.has(n.cwd))return e;let t=new Set(e);return t.delete(n.cwd),x(t),t}),ea(n.cwd,!1),eu(n.cwd),t(n,!0))}).finally(()=>{e||eo.current||l?.()}),()=>{e=!0}},[i,ea,l,t,eu]);let eh=(0,o.useCallback)(e=>{er.current=!0,P(e),F(null),Y(t=>{if(!t.has(e))return t;let r=new Set(t);return r.delete(e),x(r),r}),z?.(e),eu(e),ea(e,!1)},[ea,z,eu]);(0,o.useEffect)(()=>{if(0!==T.length&&null===N&&!j){if(i&&!eo.current)return;let e=T[0]?.cwd;e&&(P(e),eu(e),ea(e,!1))}},[T,N,j,i,t,l,eu,ea]);let ex=(0,o.useCallback)(async e=>{await ec(e,!1)&&(eh(e),U(!1),F(null))},[eh,ec]),eg=j??N,ef=(0,o.useCallback)(async()=>{$(!0);try{await es(!1);let e=new Set([...Object.entries(M).filter(([,e])=>e.loaded||e.loading).map(([e])=>e),...eg?[eg]:[]]);await Promise.all([...e].map(e=>ea(e,!1)))}finally{$(!1)}},[eg,es,ea,M]);(0,o.useEffect)(()=>{eg&&(Y(e=>{if(!e.has(eg))return e;let t=new Set(e);return t.delete(eg),x(t),t}),ea(eg,!1))},[eg,ea,s]);let em=(0,o.useCallback)(e=>{if(!e){F(null),U(!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]),ev=(0,o.useCallback)(()=>{em(eg)},[em,eg]),ey=(0,o.useCallback)(()=>{F(null),U(!0)},[]),eb=(0,o.useMemo)(()=>[...eg&&!T.some(e=>e.cwd===eg)?[{cwd:eg,displayName:m(eg,D),chatCount:M[eg]?.sessions.length??0,lastAccessed:null,created:null,pinned:!1,sortOrder:null,exists:!0,source:"manual"}]:[],...T].sort(b),[eg,D,T,M]),ej=(0,o.useMemo)(()=>{let e=new Map([...eb].sort((e,t)=>{let r=v(e)||M[e.cwd]?.sessions[0]?.modified||"",n=v(t)||M[t.cwd]?.sessions[0]?.modified||"";return r!==n?n.localeCompare(r):y(e,t)}).map((e,t)=>[e.cwd,t]));return eb.filter(e=>e.cwd||e.chatCount>0||e.cwd===eg).map(t=>{let r=M[t.cwd],n=[...r?.sessions??[]].sort((e,t)=>t.modified.localeCompare(e.modified));return{project:t,cwd:t.cwd,displayName:t.displayName||m(t.cwd,D),sessions:n,sessionsState:r,lastAccessed:v(t)||n[0]?.modified||"",recentRank:e.get(t.cwd)??Number.MAX_SAFE_INTEGER}})},[eg,D,M,eb]);(0,o.useEffect)(()=>{if(0===ej.length||en.current)return;en.current=!0;let e=[...ej].sort((e,t)=>e.recentRank-t.recentRank)[0]?.cwd;if(!e||window.localStorage.getItem(h))return;let t=new Set(ej.filter(t=>t.cwd!==e).map(e=>e.cwd));Y(e=>!function(e,t){if(e.size!==t.size)return!1;for(let r of e)if(!t.has(r))return!1;return!0}(e,t)?(x(t),t):e),window.localStorage.setItem(h,"1")},[ej]),(0,o.useEffect)(()=>{if(0!==ej.length)for(let e of ej.filter(e=>!Z.has(e.cwd)).slice(0,3).map(e=>e.cwd)){let t=M[e];t?.loaded||t?.loading||ea(e,!1)}},[Z,ea,ej,M]);let ek=(0,o.useCallback)(e=>{Y(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),x(r),r});let t=M[e];t?.loaded||t?.loading||ea(e,!1)},[ea,M]),ew=(0,o.useCallback)(e=>{J(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),eS=(0,o.useCallback)(async(e,t)=>{I(r=>r.map(r=>r.cwd===e?{...r,pinned:t}:r).sort(b));try{await ep({cwd:e,pinned:t})}catch{es(!1)}},[es,ep]),eC=(0,o.useCallback)(e=>{X(e),ee(e)},[]),ez=(0,o.useCallback)(async e=>{if(!G||G===e){X(null),ee(null);return}let t=[...T].sort(b),r=t.findIndex(e=>e.cwd===G),n=t.findIndex(t=>t.cwd===e);if(r<0||n<0){X(null),ee(null);return}let o=(function(e,t,r){if(t===r)return e;let n=[...e],[o]=n.splice(t,1);return n.splice(r,0,o),n})(t,r,n).map((e,t)=>({...e,sortOrder:t}));I(o),X(null),ee(null);try{await ep({order:o.map(e=>e.cwd)})}catch{es(!1)}},[G,es,T,ep]),eT=(0,o.useCallback)(()=>{X(null),ee(null)},[]),eI=(0,o.useCallback)((e,r=!1)=>{e.cwd!==eg&&(et.current=!0,P(e.cwd)),Y(t=>{if(!t.has(e.cwd))return t;let r=new Set(t);return r.delete(e.cwd),x(r),r}),eu(e.cwd),t(e,r)},[t,eg,eu]);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"12px 10px 8px",borderBottom:"1px solid var(--border)",flexShrink:0},children:(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(k,{}),(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsxs)("button",{onClick:ev,disabled:!eg,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,background:"var(--bg-hover)",border:"1px solid var(--border)",color:eg?"var(--text-muted)":"var(--text-dim)",cursor:eg?"pointer":"not-allowed",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:eg?`New session in ${eg}`:"Select a project first",onMouseEnter:e=>{eg&&(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=eg?"var(--text-muted)":"var(--text-dim)",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"]}),(0,n.jsx)("button",{onClick:()=>q(!0),style:{display:"flex",alignItems:"center",justifyContent:"center",background:"var(--bg-hover)",border:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",width:32,height:32,borderRadius:7,padding:0,flexShrink:0,transition:"background 0.12s, color 0.12s, border-color 0.12s"},title:"Search conversations",onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-selected)",e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"7",cy:"7",r:"4.4"}),(0,n.jsx)("path",{d:"M10.4 10.4 13.2 13.2"})]})})]})]})}),(0,n.jsx)(a,{open:V,cwd:eg,homeDir:D,onClose:()=>q(!1),onSelectSession:e=>{eI(e)}}),(0,n.jsxs)("div",{style:{flex:"1 1 auto",overflowY:"auto",padding:"8px 8px 10px",minHeight:120},children:[(0,n.jsxs)("div",{style:{padding:"0 6px 6px 10px",display:"flex",alignItems:"center",justifyContent:"space-between",color:"var(--text-dim)"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>el(e=>!e),title:ei?"Collapse projects":"Expand projects","aria-expanded":ei,style:{display:"flex",alignItems:"center",gap:6,padding:"4px 0",background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:10,fontWeight:600,letterSpacing:"0.05em",textTransform:"uppercase",textAlign:"left"},children:[(0,n.jsx)("svg",{width:"9",height:"9",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:ei?"rotate(90deg)":"none",transition:"transform 0.15s",flexShrink:0},children:(0,n.jsx)("polyline",{points:"3 2 7 5 3 8"})}),"Projects"]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:5},children:[(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),ef()},disabled:E,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:E?"var(--accent)":"var(--text-dim)",cursor:E?"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:E?"spin 0.9s linear infinite":void 0},children:[(0,n.jsx)("path",{d:"M21 12a9 9 0 0 1-15.5 6.2"}),(0,n.jsx)("path",{d:"M3 12A9 9 0 0 1 18.5 5.8"}),(0,n.jsx)("path",{d:"M7 18H5.5v1.5"}),(0,n.jsx)("path",{d:"M17 6h1.5V4.5"})]})}),(0,n.jsxs)("button",{type:"button",onClick:ey,title:"Add project","aria-label":"Add project",style:{height:24,display:"flex",alignItems:"center",justifyContent:"center",gap:5,padding:"0 6px",border:"none",borderRadius:6,background:"transparent",color:"var(--text-dim)",cursor:"pointer",flexShrink:0,fontSize:11},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M1.5 4.5A1.5 1.5 0 0 1 3 3h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 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:"M8 7.5v3M6.5 9h3"})]}),"Add"]})]})]}),ei&&(0,n.jsxs)(n.Fragment,{children:[R&&0===ej.length&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Loading..."}),A&&(0,n.jsx)("div",{style:{padding:"12px 14px",color:"#f87171",fontSize:12},children:A}),!R&&!A&&0===ej.length&&(0,n.jsx)("button",{type:"button",onClick:ey,style:{width:"100%",padding:"12px 10px",border:"1px dashed var(--border)",borderRadius:8,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left"},children:"Add a project folder"}),!R&&!A&&ej.map(t=>{var r;let o=Z.has(t.cwd),i=t.cwd===eg,l=t.sessionsState,{visible:s,hiddenCount:a}=(r=function(e){let t=new Map;for(let r of e)t.set(r.id,{session:r,children:[]});let r=new Map;for(let t of e)t.parentSessionId&&r.set(t.id,t.parentSessionId);let n=[];for(let e of t.values()){let o=function(e){let n=r.get(e),o=new Set;for(;n&&!o.has(n);){if(o.add(n),t.has(n))return n;n=r.get(n)}return null}(e.session.id);o?t.get(o).children.push(e):n.push(e)}let o=e=>{e.sort((e,t)=>t.session.modified.localeCompare(e.session.modified)),e.forEach(e=>o(e.children))};return o(n),n}(t.sessions),K.has(t.cwd),{visible:r,hiddenCount:0});return(0,n.jsxs)("div",{style:{marginBottom:6},children:[(0,n.jsx)(S,{group:t,isCurrent:i,isCollapsed:o,isDragged:G===t.cwd,isDropTarget:Q===t.cwd&&G!==t.cwd,onToggle:()=>ek(t.cwd),onSelect:()=>eh(t.cwd),onTogglePinned:()=>void eS(t.cwd,!0!==t.project.pinned),onNewSession:e=>{e.stopPropagation(),eh(t.cwd),em(t.cwd)},onDragStart:()=>eC(t.cwd),onDragEnter:()=>{G&&G!==t.cwd&&ee(t.cwd)},onDrop:()=>void ez(t.cwd),onDragEnd:eT}),!o&&(0,n.jsxs)("div",{style:{marginTop:2,overflow:"hidden",borderRadius:7},children:[l?.loading&&(0,n.jsx)("div",{style:{padding:"8px 10px",color:"var(--text-dim)",fontSize:11},children:"Loading chats..."}),l?.error&&(0,n.jsx)("div",{style:{padding:"8px 10px",color:l.stale?"var(--text-dim)":"#f87171",fontSize:11},children:l.stale?`Showing cached chats. ${l.error}`:l.error}),!l?.loading&&!l?.error&&0===t.sessions.length&&l?.loaded?(0,n.jsx)("button",{type:"button",onClick:()=>{eh(t.cwd),em(t.cwd)},style:{width:"100%",padding:"10px 12px",background:"transparent",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:12},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:"Start a new session in this project"}):l?.loading||l?.error||!(t.sessions.length>0)?l?.loaded||l?.loading||l?.error?null:(0,n.jsx)("div",{style:{padding:"8px 10px",color:"var(--text-dim)",fontSize:11},children:t.lastAccessed?`Last active ${f(t.lastAccessed)}`:"No chats loaded"}):s.map(r=>(0,n.jsx)(C,{node:r,selectedSessionId:e,onSelectSession:eI,onRenamed:()=>void ea(t.cwd,!1),onSessionDeleted:e=>{c?.(e),ea(t.cwd,!1),es(!1)},depth:0},r.session.id)),a>0&&t.sessions.length>0&&(0,n.jsx)("button",{type:"button",onClick:()=>ew(t.cwd),style:{width:"100%",padding:"6px 10px",background:"transparent",border:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:11,textAlign:"center"},children:K.has(t.cwd)?"Show less":`Show ${Math.max(0,a)} more`})]})]},t.cwd||"__no_project")})]})]}),(0,n.jsx)(d,{open:_,initialPath:eg||D||null,onClose:()=>U(!1),onSelect:e=>void ex(e),externalError:H,onPathInputChange:()=>F(null)})]})}function S({group:e,isCurrent:t,isCollapsed:r,isDragged:i,isDropTarget:l,onToggle:s,onSelect:a,onTogglePinned:d,onNewSession:c,onDragStart:u,onDragEnter:p,onDrop:h,onDragEnd:x}){let[g,m]=(0,o.useState)(!1),v=e.lastAccessed,y=Math.max(0,e.project.chatCount??e.sessions.length??0),b=(0,o.useCallback)(()=>{t?s():a()},[t,a,s]);return(0,n.jsxs)("div",{draggable:!0,role:"button",tabIndex:0,onClick:b,onDragStart:t=>{t.dataTransfer.effectAllowed="move",t.dataTransfer.setData("text/plain",e.cwd),u()},onDragEnter:e=>{e.preventDefault(),p()},onDragOver:e=>{e.preventDefault(),e.dataTransfer.dropEffect="move"},onDrop:e=>{e.preventDefault(),e.stopPropagation(),h()},onDragEnd:x,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),b())},onMouseEnter:()=>m(!0),onMouseLeave:()=>m(!1),title:e.cwd,style:{width:"100%",height:32,display:"flex",alignItems:"center",gap:5,padding:"0 8px",background:t?"var(--bg-selected)":g?"var(--bg-hover)":"transparent",border:"none",borderRadius:6,boxShadow:l?"inset 0 0 0 1px rgba(37,99,235,0.45)":"none",color:"var(--text)",cursor:"grab",textAlign:"left",overflow:"hidden",transition:"background 0.12s, box-shadow 0.12s, opacity 0.12s",opacity:i?.55:1},children:[(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:r?"none":"rotate(90deg)",transition:"transform 0.15s",flexShrink:0,color:"var(--text-dim)"},children:(0,n.jsx)("polyline",{points:"3 2 7 5 3 8"})}),(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.35",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:t?"var(--accent)":"var(--text-dim)"},children:r?(0,n.jsx)("path",{d:"M1.5 4.5A1.5 1.5 0 0 1 3 3h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6v5A1.5 1.5 0 0 1 13 12.5H3A1.5 1.5 0 0 1 1.5 11V4.5Z"}):(0,n.jsx)("path",{d:"M1.5 5A1.5 1.5 0 0 1 3 3.5h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6.5L13.6 11A1.5 1.5 0 0 1 12.1 12.5H3A1.5 1.5 0 0 1 1.5 11V5Z"})}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13,fontWeight:t?650:560,color:"var(--text)"},children:e.displayName}),!e.project.exists&&(0,n.jsx)("span",{style:{flexShrink:0,color:"#f87171",fontSize:10},children:"missing"}),!g&&y>0&&(0,n.jsxs)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:[y," ",1===y?"chat":"chats"]}),!g&&v&&(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:f(v)}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),d()},title:e.project.pinned?"Unpin project":"Pin project",tabIndex:g||e.project.pinned?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,border:"none",borderRadius:5,background:e.project.pinned?"rgba(234,179,8,0.12)":"transparent",color:e.project.pinned?"#ca8a04":"var(--text-muted)",cursor:"pointer",flexShrink:0,opacity:g||e.project.pinned?1:0,pointerEvents:g||e.project.pinned?"auto":"none",transition:"opacity 0.12s, background 0.12s, color 0.12s"},onMouseEnter:t=>{e.project.pinned||(t.currentTarget.style.background="var(--bg-hover)",t.currentTarget.style.color="#ca8a04")},onMouseLeave:t=>{t.currentTarget.style.background=e.project.pinned?"rgba(234,179,8,0.12)":"transparent",t.currentTarget.style.color=e.project.pinned?"#ca8a04":"var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:e.project.pinned?"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"})]})}),(0,n.jsx)("button",{type:"button",onClick:c,title:"New chat in this project",tabIndex:g?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,border:"none",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,opacity:+!!g,pointerEvents:g?"auto":"none",transition:"opacity 0.12s, background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"6",y1:"1.5",x2:"6",y2:"10.5"}),(0,n.jsx)("line",{x1:"1.5",y1:"6",x2:"10.5",y2:"6"})]})})]})}function C({node:e,selectedSessionId:t,onSelectSession:r,onRenamed:i,onSessionDeleted:l,depth:s}){let[a,d]=(0,o.useState)(!1),c=e.children.length>0;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{position:"relative"},children:[s>0&&(0,n.jsx)("div",{style:{position:"absolute",left:12*s+6,top:0,bottom:0,width:1,background:"var(--border)",pointerEvents:"none"}}),(0,n.jsx)(z,{session:e.session,isSelected:e.session.id===t,onClick:()=>r(e.session),onRenamed:i,onDeleted:e=>l?.(e),depth:s,hasChildren:c,collapsed:a,onToggleCollapse:()=>d(e=>!e)})]}),c&&!a&&(0,n.jsx)("div",{children:e.children.map(e=>(0,n.jsx)(C,{node:e,selectedSessionId:t,onSelectSession:r,onRenamed:i,onSessionDeleted:l,depth:s+1},e.session.id))})]})}function z({session:e,isSelected:t,onClick:r,onRenamed:i,onDeleted:l,depth:s=0,hasChildren:a=!1,collapsed:d=!1,onToggleCollapse:c}){let[u,p]=(0,o.useState)(!1),[h,x]=(0,o.useState)(!1),[g,m]=(0,o.useState)(""),[v,y]=(0,o.useState)(!1),[b,j]=(0,o.useState)(!1),k=(0,o.useRef)(null),w=e.name||e.firstMessage.slice(0,50)||e.id.slice(0,12),S=(0,o.useCallback)(t=>{t.stopPropagation(),m(e.name??""),x(!0),setTimeout(()=>k.current?.select(),0)},[e.name]),C=(0,o.useCallback)(async()=>{let t=g.trim();if(x(!1),t!==(e.name??""))try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t})}),i?.()}catch{}},[g,e.id,e.name,i]),T=(0,o.useCallback)(e=>{e.stopPropagation(),y(!0)},[]),I=(0,o.useCallback)(async t=>{t.stopPropagation(),y(!1),j(!0);try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"DELETE"}),l?.(e.id)}catch{j(!1)}},[e.id,l]),M=(0,o.useCallback)(e=>{e.stopPropagation(),y(!1)},[]);return(0,n.jsx)("div",{onClick:v||h?void 0:r,onMouseEnter:()=>p(!0),onMouseLeave:()=>{p(!1)},style:{height:54,display:"flex",alignItems:"center",paddingLeft:s>0?12*s+14:14,paddingRight:8,cursor:v||h?"default":"pointer",background:v?"rgba(239,68,68,0.06)":t?"var(--bg-selected)":u?"var(--bg-hover)":"transparent",borderLeft:v?"2px solid #ef4444":t?"2px solid var(--accent)":"2px solid transparent",transition:"background 0.1s",opacity:b?.5:1,gap:6,overflow:"hidden"},children:v?(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:I,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,height:30,padding:"0 11px",background:"#ef4444",border:"none",borderRadius:6,color:"#fff",cursor:"pointer",fontSize:12,fontWeight:600,whiteSpace:"nowrap"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,n.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,n.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,n.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]}),"Delete"]}),(0,n.jsx)("button",{onClick:M,style:{display:"flex",alignItems:"center",justifyContent:"center",height:30,padding:"0 11px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:500,whiteSpace:"nowrap"},children:"Cancel"})]})]}):h?(0,n.jsx)("input",{ref:k,value:g,onChange:e=>m(e.target.value),onBlur:C,onKeyDown:e=>{"Enter"===e.key&&C(),"Escape"===e.key&&x(!1)},autoFocus:!0,style:{flex:1,fontSize:12,padding:"5px 8px",border:"1px solid var(--accent)",borderRadius:5,outline:"none",background:"var(--bg)",color:"var(--text)",height:30}}):(0,n.jsxs)(n.Fragment,{children:[s>0&&(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:t?500:400,lineHeight:1.4,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text)"},title:w,children:w}),(0,n.jsxs)("div",{style:{marginTop:2,display:"flex",gap:8,color:"var(--text-dim)",fontSize:11},children:[(0,n.jsx)("span",{title:e.modified,children:f(e.modified)}),(0,n.jsxs)("span",{children:[e.messageCount," msgs"]}),!1===e.cwdExists&&(0,n.jsx)("span",{title:`Project path missing: ${e.cwd}`,style:{color:"#f87171"},children:"missing path"})]})]}),a&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),c?.()},title:d?"Expand forks":"Collapse forks",style:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,flexShrink:0,background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",transform:d?"rotate(-90deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})}),u&&(0,n.jsxs)("div",{style:{display:"flex",gap:4,flexShrink:0},children:[(0,n.jsx)("button",{onClick: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",flexShrink:0,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",flexShrink:0,transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.08)",e.currentTarget.style.color="#ef4444",e.currentTarget.style.borderColor="rgba(239,68,68,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,n.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,n.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,n.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]})})]})]})})}var T=r(97031),I=r(97894),M=r(16764);let L=new Set;function R(e){return L.add(e),()=>{L.delete(e)}}function W(){return"u"<typeof document?"light":document.documentElement.classList.contains("dark")?"dark":"light"}function E(){return"light"}function $(){let e=(0,o.useSyncExternalStore)(R,W,E);return{theme:e,toggleTheme:(0,o.useCallback)(e=>{let t="dark"===W()?"light":"dark",r=()=>{"dark"===t?document.documentElement.classList.add("dark"):document.documentElement.classList.remove("dark");try{localStorage.setItem("annodex-theme",t)}catch{}L.forEach(e=>e())},n=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;if("function"!=typeof document.startViewTransition||n)return void r();let o=e?.x??window.innerWidth/2,i=e?.y??window.innerHeight/2,l=Math.hypot(Math.max(o,window.innerWidth-o),Math.max(i,window.innerHeight-i));document.startViewTransition(r).ready.then(()=>{document.documentElement.animate({clipPath:[`circle(0px at ${o}px ${i}px)`,`circle(${l}px at ${o}px ${i}px)`]},{duration:450,easing:"cubic-bezier(0.22, 0.61, 0.36, 1)",pseudoElement:"::view-transition-new(root)"})}).catch(()=>{})},[]),isDark:"dark"===e}}function A({chart:e}){let{isDark:t}=$(),[i,l]=(0,o.useState)(null),[s,a]=(0,o.useState)(null),d=(0,o.useRef)(`mermaid-${Math.random().toString(36).slice(2)}`);return((0,o.useEffect)(()=>{let n=!1,o=e.trim();return(l(null),a(null),o)?(Promise.all([r.e(2941),r.e(2995),r.e(3308)]).then(r.bind(r,43328)).then(({default:e})=>(e.initialize({startOnLoad:!1,securityLevel:"strict",theme:t?"dark":"default",suppressErrorRendering:!0}),e.parse(o,{suppressErrors:!0}).then(t=>{if(!t)throw Error("Invalid Mermaid syntax");return e.render(`${d.current}-${Date.now()}`,o)}))).then(e=>{n||l(e.svg)}).catch(e=>{n||a(e instanceof Error?e.message:String(e))}),()=>{n=!0}):void a("Empty Mermaid diagram")},[e,t]),s)?(0,n.jsxs)("div",{className:"mermaid-diagram mermaid-diagram-error",children:[(0,n.jsx)("div",{className:"mermaid-diagram-error-title",children:"Mermaid render failed"}),(0,n.jsx)("div",{className:"mermaid-diagram-error-message",children:s}),(0,n.jsx)("pre",{children:e})]}):(0,n.jsx)("div",{className:"mermaid-diagram",children:i?(0,n.jsx)("div",{className:"mermaid-diagram-canvas",dangerouslySetInnerHTML:{__html:i}}):(0,n.jsx)("div",{className:"mermaid-diagram-loading",children:"Rendering diagram..."})})}function B(e){let t,r=[],n=/`{1,3}show-widget`{0,3}\s*(?:\n\s*`{3}(?:json|html)?\s*)?\n?/g,o=0,i=!1;for(;null!==(t=n.exec(e));){i=!0;let l=e.slice(o,t.index).trim();l&&r.push({type:"text",content:l});let s=t.index+t[0].length,a=e.indexOf("```",s),d=e.indexOf("{",s);if(-1!==d&&d<=s+200&&(-1===a||d<a)){let t=function(e,t){let r=0,n=!1,o=!1;for(let i=t;i<e.length;i++){let t=e[i];if(o){o=!1;continue}if("\\"===t&&n){o=!0;continue}if('"'===t){n=!n;continue}if(!n&&("{"===t&&r++,"}"===t)&&0==--r)return i}return -1}(e,d);if(-1===t){let t=function(e){try{let t=N(e);if(t)return t}catch{}let t=e.indexOf('"widget_code"');if(-1===t)return null;let r=e.indexOf(":",t+13);if(-1===r)return null;let n=e.indexOf('"',r+1);if(-1===n)return null;let o=e.slice(n+1);(o=o.replace(/"\s*\}\s*$/,"")).endsWith("\\")&&(o=o.slice(0,-1));let i=e.match(/"title"\s*:\s*"([^"]*?)"/)?.[1],l=P(o.replace(/\\\\/g,"\0BACKSLASH\0").replace(/\\n/g,"\n").replace(/\\t/g," ").replace(/\\r/g,"\r").replace(/\\"/g,'"').replace(/\\u([0-9a-fA-F]{4})/g,(e,t)=>String.fromCharCode(parseInt(t,16))).replace(/\x00BACKSLASH\x00/g,"\\"));return l.code.trim()?{title:i,code:l.code,showOverlay:l.truncated}:null}(e.slice(d));t&&r.push({type:"widget",...t,partial:!0}),o=e.length;break}let i=N(e.slice(d,t+1).trim());i&&r.push({type:"widget",...i});let l=t+1,s=e.slice(l,l+16).match(/^\s*\n?`{1,3}\s*/);s&&(l+=s[0].length),o=l,n.lastIndex=l;continue}if(-1!==a){let t=e.slice(s,a).trim(),i=N(t);i?r.push({type:"widget",...i}):t&&r.push({type:"text",content:t}),n.lastIndex=o=a+3}else{let t=N(e.slice(s).trim());if(t){let e=P(t.code);r.push({type:"widget",title:t.title,code:e.code,partial:!0,showOverlay:e.truncated})}o=e.length;break}}let l=e.slice(o).trim();return l&&r.push({type:"text",content:l}),!i&&0===r.length&&e.trim()&&r.push({type:"text",content:e}),r}function N(e){if(e.startsWith("{")){if(!e.endsWith("}"))return null;try{let t=JSON.parse(e),r=t.widget_code??t.code;if(r)return{title:t.title,code:r}}catch{return null}}return/<(!DOCTYPE|html|svg|canvas|script|style|div)/i.test(e)?{code:e}:null}function P(e){let t=e.lastIndexOf("<script");if(-1===t)return{code:e,truncated:!1};let r=e.slice(t);return/<script[\s\S]*?<\/script>/i.test(r)?{code:e,truncated:!1}:{code:e.slice(0,t).trim(),truncated:!0}}let D=/<(iframe|object|embed|meta|link|base|form)[\s>][\s\S]*?<\/\1>/gi,O=/<(iframe|object|embed|meta|link|base)\b[^>]*\/?>/gi;function H(e){return e.replace(D,"").replace(O,"")}let F=["--bg","--bg-panel","--bg-hover","--bg-selected","--border","--text","--text-muted","--text-dim","--accent","--accent-hover"];function _(){if("u"<typeof document)return{};let e=getComputedStyle(document.documentElement),t={};for(let r of F){let n=e.getPropertyValue(r).trim();n&&(t[r]=n)}return t}let U=["--bg","--bg-panel","--bg-hover","--bg-selected","--border","--text","--text-muted","--text-dim","--accent","--accent-hover"];async function V(e){if(navigator.clipboard?.writeText)return void await navigator.clipboard.writeText(e);let t=document.createElement("textarea");t.value=e,t.style.position="fixed",t.style.inset="0",t.style.opacity="0",document.body.appendChild(t),t.focus(),t.select();let r=document.execCommand("copy");if(document.body.removeChild(t),!r)throw Error("Clipboard copy failed.")}async function q(e){let t=await K(e.code);if(t)return t;if(e.capture)return function(e){if(!e.html)throw Error("The widget did not provide capturable HTML.");let t=Y({width:e.bodyWidth||640,height:e.bodyHeight||360}),r=function(e){let t=document.createElement("template");t.innerHTML=H(e.html||"");let r=document.createElement("div");for(let n of(r.appendChild(t.content.cloneNode(!0)),Array.from(r.querySelectorAll("img[data-canvas-export]")))){let t=Number(n.getAttribute("data-canvas-export")),r=Number.isFinite(t)?e.canvases?.[t]:null;if(!r?.dataUrl){n.remove();continue}n.setAttribute("src",r.dataUrl),n.setAttribute("width",String(r.width)),n.setAttribute("height",String(r.height)),n.setAttribute("style",function(e,t){let r=new Map;for(let t of(e||"").split(";")){let[e,...n]=t.split(":");e?.trim()&&n.length>0&&r.set(e.trim(),n.join(":").trim())}for(let[e,n]of Object.entries(t))r.set(e,n);return Array.from(r.entries()).map(([e,t])=>e+":"+t).join(";")}(n.getAttribute("style"),{width:r.width+"px",height:r.height+"px",display:"block"}))}return J(r),Array.from(r.childNodes).map(e=>new XMLSerializer().serializeToString(e)).join("")}(e);if(!r.trim())throw Error("The widget capture was empty.");let n=[e.styles||"","#__widget_export_root{"+function(){if("u"<typeof document)return"";let e=getComputedStyle(document.documentElement);return U.map(t=>{let r=e.getPropertyValue(t).trim();return r?t+":"+r+";":""}).join("")}()+'font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",system-ui,sans-serif;font-size:14px;line-height:1.6;color:var(--text,#1a1a1a);background:transparent;}',"#__widget_export_root *{box-sizing:border-box;}\n#__widget_export_root svg{max-width:100%;height:auto;display:block;}"].join("\n");return X(Q('<svg xmlns="http://www.w3.org/2000/svg" width="'+t.width+'" height="'+t.height+'" viewBox="0 0 '+t.width+" "+t.height+'"><defs><style><![CDATA['+n.replace(/\]\]>/g,"]]]]><![CDATA[>")+']]></style></defs><foreignObject x="0" y="0" width="100%" height="100%">'+('<div xmlns="http://www.w3.org/1999/xhtml" id="__widget_export_root" style="width:'+t.width+"px;min-height:")+t.height+'px;overflow:visible;">'+r+"</div></foreignObject></svg>"),t.width,t.height)}(e.capture);throw Error("PNG export needs a rendered widget capture.")}async function K(e){var t;let r,n,o,i,l=function(e){let t=H(e).trim();if(!/^<\s*(style|svg)\b/i.test(t))return null;let r=new DOMParser().parseFromString(t,"text/html"),n=Array.from(r.body.children),o=n.filter(e=>"svg"===e.tagName.toLowerCase()),i=n.filter(e=>"style"!==e.tagName.toLowerCase());if(1!==o.length||1!==i.length)return null;let l=o[0].cloneNode(!0),s=Array.from(r.body.querySelectorAll("style")).map(e=>e.textContent||"").join("\n").trim();if(s){let e=document.createElementNS("http://www.w3.org/2000/svg","style");e.textContent=s,l.insertBefore(e,l.firstChild)}return l}(e);if(!l)return null;J(l),l.setAttribute("xmlns","http://www.w3.org/2000/svg");let s=Y((r=function(e){if(!e)return null;let t=e.trim().split(/[\s,]+/).map(Number);return 4!==t.length||t.some(e=>!Number.isFinite(e))||t[2]<=0||t[3]<=0?null:{width:t[2],height:t[3]}}((t=l).getAttribute("viewBox")),n=Z(t.getAttribute("width"))??r?.width??640,o=r?r.height/r.width:.5625,i=Z(t.getAttribute("height"))??r?.height??n*o,{width:n,height:i}));return l.setAttribute("width",String(s.width)),l.setAttribute("height",String(s.height)),l.getAttribute("viewBox")||l.setAttribute("viewBox","0 0 "+s.width+" "+s.height),X(Q(new XMLSerializer().serializeToString(l)),s.width,s.height)}function J(e){for(let t of Array.from(e.querySelectorAll("script, iframe, object, embed, meta, link, base, form")))t.remove();for(let t of[e,...Array.from(e.querySelectorAll("*"))])for(let e of Array.from(t.attributes)){let r=e.name.toLowerCase(),n=e.value.trim();if(r.startsWith("on")){t.removeAttribute(e.name);continue}("href"===r||"src"===r||r.endsWith(":href"))&&/^\s*(javascript|data:text\/html)/i.test(n)&&t.removeAttribute(e.name)}}function Z(e){if(!e||e.includes("%"))return null;let t=Number.parseFloat(e);return Number.isFinite(t)&&t>0?t:null}function Y(e){let t=G(Math.ceil(e.width||640),240,2e3),r=G(Math.ceil(e.height||360),80,4e3),n=t*r;if(n>8e6){let e=Math.sqrt(8e6/n);t=Math.max(240,Math.floor(t*e)),r=Math.max(80,Math.floor(r*e))}return{width:t,height:r}}function G(e,t,r){return Math.min(Math.max(e,t),r)}function X(e,t,r){return new Promise((n,o)=>{let i=new Image,l=URL.createObjectURL(new Blob([e],{type:"image/svg+xml;charset=utf-8"}));i.onload=()=>{URL.revokeObjectURL(l);try{let e=document.createElement("canvas"),l=Math.min(window.devicePixelRatio||1,2);e.width=Math.ceil(t*l),e.height=Math.ceil(r*l),e.style.width=t+"px",e.style.height=r+"px";let s=e.getContext("2d");if(!s)throw Error("Canvas is not available.");s.scale(l,l),s.drawImage(i,0,0,t,r),e.toBlob(e=>{e?n(e):o(Error("Canvas export returned no image."))},"image/png")}catch(e){o(e instanceof Error?e:Error("PNG export failed."))}},i.onerror=()=>{URL.revokeObjectURL(l),o(Error("The browser could not render this widget as PNG."))},i.src=l})}function Q(e){if("u"<typeof document)return e;let t=getComputedStyle(document.documentElement);return e.replace(/var\(\s*(--[a-zA-Z0-9_-]+)(?:\s*,\s*([^)]+))?\)/g,(e,r,n)=>t.getPropertyValue(r).trim()||n?.trim()||"#000")}let ee=/cdnjs\.cloudflare\.com|cdn\.jsdelivr\.net|unpkg\.com|esm\.sh/,et=new Map;function er(e){return e.slice(0,200)}function en({code:e,isStreaming:t,title:r,showOverlay:i,onSendMessage:l}){let{isDark:s}=$(),a=(0,o.useRef)(null),d=(0,o.useRef)(null),c=(0,o.useRef)(null),u=(0,o.useRef)(new Map),p=(0,o.useRef)(""),[h,x]=(0,o.useState)(!1),[g,f]=(0,o.useState)(()=>et.get(er(e))??0),[m,v]=(0,o.useState)(!1),[y,b]=(0,o.useState)(!1),[j,k]=(0,o.useState)(null),[w,S]=(0,o.useState)(!1),[C,z]=(0,o.useState)(!1),T=(0,o.useRef)(""),I=(0,o.useRef)((et.get(er(e))??0)>0),M=(0,o.useRef)(!1),L=(0,o.useRef)(s),R=(0,o.useMemo)(()=>ee.test(e),[e]),W=(0,o.useMemo)(()=>{let e;return function(e="",t=!1){return`<!DOCTYPE html>
|
|
2
2
|
<html class="${t?"dark":""}">
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="utf-8">
|
|
@@ -257,6 +257,6 @@ Attached document text:
|
|
|
257
257
|
|
|
258
258
|
${a}`:e:a?`Attached document text:
|
|
259
259
|
|
|
260
|
-
${a}`:"",c=o?.map(e=>({type:"image",source:{type:"base64",media_type:e.mimeType,data:e.data}})),p={role:"user",content:c?.length?[...d.trim()?[{type:"text",text:d}]:[],...c]:d,timestamp:Date.now()};ey.current=!0,y(e=>[...e,p]),ed(null),ew.current=!0;let h=o?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType})),x=()=>{ev.current||(ev.current=!0,T(!0),es({kind:"waiting_model"}),w({type:"start"}),C({type:"reset"}))};try{if(u&&n){B&&et(B);let{PRESET_NONE:t,PRESET_DEFAULT:o,PRESET_FULL:i}=await r.e(8451).then(r.bind(r,48451)),s="none"===P?t:"default"===P?o:i,a=await fetch("/api/agent/new",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:n,toolNames:s,...B?{provider:B.provider,modelId:B.modelId}:{},..."auto"!==O?{thinkingLevel:O}:{},sandboxMode:F})}),c=await a.json().catch(()=>({}));if(!a.ok||c.error||!c.sessionId)throw Error(c.error??`HTTP ${a.status}`);let u=c.sessionId;em.current=u,await eH(u,1e4,!0),x(),await tB(u,{type:"prompt",message:d,toolNames:s,...h?.length?{images:h}:{}}),ez.current=!0,l?.({id:u,path:"",cwd:n,name:void 0,created:new Date().toISOString(),modified:new Date().toISOString(),messageCount:1,firstMessage:e})}else if(t){let{PRESET_NONE:e,PRESET_DEFAULT:n,PRESET_FULL:o}=await r.e(8451).then(r.bind(r,48451));await eH(t.id,1e4,!0),x();let i=await tB(t.id,{type:"prompt",message:d,toolNames:"none"===P?e:"default"===P?n:o,...h?.length?{images:h}:{}});i?.__sessionId&&i.__sessionId!==t.id&&(em.current=i.__sessionId,eD(i.__sessionId),s?.(i.__sessionId))}}catch(t){console.error("Failed to send message:",t);let e=t instanceof Error?t.message:String(t);ed(`Send failed: ${e}`),T(!1),ev.current=!1,es(null),w({type:"end"})}finally{ey.current=!1}},[u,n,B,P,O,F,t,z,eH,l,s,eD,eR]),e_=(0,o.useCallback)(async()=>{let e=em.current;if(e){ev.current=!1,ed(null),T(!1),es(null),w({type:"end"}),ex.current?.close(),ex.current=null,ef.current=null;try{await tB(e,{type:"abort"}),await eA(e)}catch(t){console.error("Failed to abort:",t),await eA(e)}}},[eA]),eU=(0,o.useCallback)(async e=>{let t=em.current;if(t){G(e);try{let{cancelled:r,newSessionId:n}=await tB(t,{type:"fork",entryId:e})??{};!r&&n&&s?.(n)}catch(e){console.error("Fork failed:",e)}finally{G(null)}}},[s]),eV=(0,o.useCallback)(async(e,t)=>{if(u)return void eT({provider:e,modelId:t});let r=em.current;if(r)try{let n=await tB(r,{type:"set_model",provider:e,modelId:t}),o=n.newSessionId??n.__sessionId;o&&o!==r&&(em.current=o,s?.(o)),Q({provider:n?.provider??e,modelId:n?.id??t})}catch(e){console.error("Failed to set model:",e)}},[u,s,eT]),eq=(0,o.useCallback)(async()=>{let e=em.current;if(e&&!er){en(!0),ei(null);try{await tB(e,{type:"compact"}),await eA(e,!0)}catch(e){ei(e instanceof Error?e.message:String(e))}finally{en(!1)}}},[er,eA]),eK=(0,o.useCallback)(async()=>{let e=em.current;if(e)try{await tB(e,{type:"abort_compaction"})}catch(e){console.error("Failed to abort compaction:",e)}},[]),eJ=(0,o.useCallback)(async e=>{if(H(e),"auto"===e)return;let t=em.current;if(t)try{await tB(t,{type:"set_thinking_level",level:e})}catch(e){console.error("Failed to set thinking level:",e)}},[]),eZ=(0,o.useCallback)(async e=>{_(e);let t=em.current;if(t&&!u)try{await tB(t,{type:"set_sandbox_mode",mode:e})}catch(e){console.error("Failed to set sandbox mode:",e)}},[u]),eY=(0,o.useCallback)(async(e,t,r)=>{let n=em.current;n&&(await tB(n,{type:"resolve_approval",requestId:e,decision:t,...r?.permissions!==void 0?{permissions:r.permissions}:{},...r?.scope?{scope:r.scope}:{}}),eh(t=>t?.requestId===e?null:t))},[]),eG=(0,o.useCallback)(async e=>{let{PRESET_NONE:t,PRESET_DEFAULT:n,PRESET_FULL:o}=await r.e(8451).then(r.bind(r,48451));eI(e);let i=em.current;if(i)try{await tB(i,{type:"set_tools",toolNames:"none"===e?t:"default"===e?n:o})}catch(e){console.error("Failed to set tools:",e)}},[eI]),eX=(0,o.useCallback)((e="smooth")=>{eS.current?.scrollIntoView({behavior:e})},[]),eQ=(0,o.useCallback)(()=>{let e=eC.current,t=ek.current;if(!e||!t)return;let r=t.getBoundingClientRect().top-e.getBoundingClientRect().top+e.scrollTop;e.scrollTo({top:r-16,behavior:"smooth"})},[]);return(0,o.useEffect)(()=>ez.current?(ez.current=!1,()=>{c&&eN(c)}):(c&&(em.current=c,eA(c,!0,!0).then(e=>{e?.running?(e$(c),eB(c),T(!0),es({kind:"waiting_model"}),w({type:"start"}),C({type:"reset"}),eD(c),eP(c,"resume-running",!0)):e$(c),e?.state&&(void 0!==e.state.isCompacting&&en(e.state.isCompacting),void 0!==e.state.contextUsage&&K(e.state.contextUsage??null),void 0!==e.state.systemPrompt&&Z(e.state.systemPrompt??null),void 0!==e.state.thinkingLevel&&H(e.state.thinkingLevel??"auto"),void 0!==e.state.sandboxMode&&_(e.state.sandboxMode??"danger-full-access"))})),()=>{c&&eN(c)}),[c,eN,eD,e$,eA,eB,eP]),(0,o.useEffect)(()=>{d?.(J)},[J,d]),(0,o.useEffect)(()=>{v.length>0&&(ew.current?(ew.current=!1,ej.current=!0,eQ()):ej.current?ev.current||eX("smooth"):(ej.current=!0,eX("instant")))},[v.length,z,eX,eQ]),(0,o.useEffect)(()=>{fetch("/api/models").then(e=>e.json()).then(e=>{if(M(e.models),e.thinkingLevels&&E(e.thinkingLevels),e.thinkingLevelMaps&&A(e.thinkingLevelMaps),e.modelList&&(R(e.modelList),u)){let t=e.defaultModel,r=t&&e.modelList.find(e=>e.id===t.modelId&&e.provider===t.provider);eT(r?{provider:r.provider,modelId:r.id}:t??null)}}).catch(()=>{})},[u,a,eT]),(0,o.useEffect)(()=>{u&&fetch("/api/settings").then(e=>e.json()).then(e=>{_("danger-full-access")}).catch(()=>{})},[u]),(0,o.useEffect)(()=>{if(!eo)return;let e=setTimeout(()=>ei(null),3e3);return()=>clearTimeout(e)},[eo]),(0,o.useEffect)(()=>()=>{eg.current&&clearTimeout(eg.current)},[]),(0,o.useEffect)(()=>{if(!z||!em.current)return;let e=em.current,t=setInterval(()=>{eP(e,"running-reconcile",!1)},1e4);return()=>clearInterval(t)},[z,eP]),{data:p,loading:x,error:f,messages:v,entryIds:b,streamState:k,streamingProcessState:S,agentRunning:z,modelNames:I,modelList:L,modelThinkingLevels:W,modelThinkingLevelMaps:$,newSessionModel:B,toolPreset:P,thinkingLevel:O,sandboxMode:F,retryInfo:U,contextUsage:q,systemPrompt:J,forkingEntryId:Y,isCompacting:er,compactError:eo,currentModel:eM,displayModel:eL,sessionStats:eE,agentPhase:el,agentError:ea,subagentRuns:ec,pendingApproval:ep,isNew:u,sessionIdRef:em,eventSourceRef:ex,messagesEndRef:eS,scrollContainerRef:eC,lastUserMsgRef:ek,pendingScrollToUserRef:ew,initialScrollDoneRef:ej,handleSend:eF,handleAbort:e_,handleFork:eU,handleModelChange:eV,handleCompact:eq,handleAbortCompaction:eK,handleToolPresetChange:eG,handleThinkingLevelChange:eJ,handleSandboxModeChange:eZ,handleResolveApproval:eY,loadTools:eB,setData:h,setMessages:y,dispatch:w,setAgentRunning:T,setForkingEntryId:G,handleAgentEventRef:eb}}({session:e,newSessionCwd:t,onAgentEnd:i,onSessionCreated:l,onSessionForked:s,modelsRefreshKey:d,onSystemPromptChange:p}),{soundEnabled:ei,onSoundToggle:el,playDoneSound:es}=function(){let[e,t]=(0,o.useState)(()=>{let e=localStorage.getItem("annodex-sound-enabled");return null===e||"true"===e}),r=(0,o.useRef)(e);return(0,o.useEffect)(()=>{r.current=e},[e]),{soundEnabled:e,onSoundToggle:(0,o.useCallback)(()=>{t(e=>{let t=!e;return localStorage.setItem("annodex-sound-enabled",String(t)),t})},[]),playDoneSound:(0,o.useCallback)(()=>{if(r.current)try{let e=new AudioContext,t=e.currentTime;[523.25,659.25].forEach((r,n)=>{let o=e.createOscillator(),i=e.createGain();o.connect(i),i.connect(e.destination),o.type="sine",o.frequency.value=r;let l=t+.18*n;i.gain.setValueAtTime(0,l),i.gain.linearRampToValueAtTime(.18,l+.02),i.gain.exponentialRampToValueAtTime(.001,l+.45),o.start(l),o.stop(l+.45)}),setTimeout(()=>e.close(),1200)}catch{}},[]),soundEnabledRef:r}}(),ea=(0,o.useRef)(es);ea.current=es;let ed=(0,o.useRef)(ei);ed.current=ei;let ec=eo.current;(0,o.useEffect)(()=>{eo.current=e=>{"agent_end"===e.type&&ed.current&&ea.current(),ec?.(e)}},[ec,eo]);let eu=D?`${D.tokens.input}|${D.tokens.output}|${D.tokens.cacheRead}|${D.tokens.cacheWrite}|${D.cost??0}`:null,ep=(0,o.useRef)(D);ep.current=D,(0,o.useEffect)(()=>{h?.(ep.current)},[eu,h]),(0,o.useEffect)(()=>()=>{h?.(null)},[h]);let eh=$?`${$.percent??"null"}|${$.contextWindow}|${$.tokens??"null"}`:null,ex=(0,o.useRef)($);ex.current=$,(0,o.useEffect)(()=>{x?.(ex.current)},[eh,x]),(0,o.useEffect)(()=>()=>{x?.(null)},[x]);let{isDragOver:eg,handleDragEnter:ef,handleDragOver:em,handleDragLeave:ev,handleDrop:ey}=function(e){let[t,r]=(0,o.useState)(!1),n=(0,o.useRef)(0),i=(0,o.useCallback)(e=>{Array.from(e.dataTransfer.items).some(tF)&&(e.preventDefault(),n.current+=1,r(!0))},[]),l=(0,o.useCallback)(e=>{Array.from(e.dataTransfer.items).some(tF)&&e.preventDefault()},[]);return{isDragOver:t,handleDragEnter:i,handleDragOver:l,handleDragLeave:(0,o.useCallback)(()=>{n.current-=1,n.current<=0&&(n.current=0,r(!1))},[]),handleDrop:(0,o.useCallback)(t=>{t.preventDefault(),n.current=0,r(!1),e(Array.from(t.dataTransfer.files))},[e])}}((0,o.useCallback)(e=>{u?.current?.addFiles(e)},[u])),eb=(f=j.filter(e=>"user"===e.role||"assistant"===e.role).length,(m=(0,o.useRef)([])).current=Array(f).fill(null).map((e,t)=>m.current[t]??null),m),ej=U&&0===j.length&&!w.isStreaming&&!C,ek=function(e=768){let[t,r]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{let t=window.matchMedia(`(max-width: ${e-1}px)`),n=()=>r(t.matches);return(n(),"function"==typeof t.addEventListener)?(t.addEventListener("change",n),()=>t.removeEventListener("change",n)):(t.addListener(n),()=>t.removeListener(n))},[e]),t}(),[ew,eS]=(0,o.useState)(!1),eC=tW(tE(j),F),ez=eC.filter(e=>"running"===e.status||"pending"===e.status).length;(0,o.useEffect)(()=>{0===eC.length&&ew&&eS(!1)},[eC.length,ew]),(0,o.useEffect)(()=>{ek&&ew&&eS(!1)},[ek,ew]);let eT=P?I[`${P.provider}:${P.modelId}`]??null:null,eI=P?M[`${P.provider}:${P.modelId}`]??null:null,eM=(0,n.jsx)(tC,{ref:u,onSend:J,onAbort:Z,isStreaming:C,model:P,modelNames:z,modelList:T,onModelChange:G,onCompact:e||U?X:void 0,onAbortCompaction:Q,isCompacting:B,compactError:N,toolPreset:L,onToolPresetChange:e||U?ee:void 0,thinkingLevel:R,onThinkingLevelChange:e||U?et:void 0,availableThinkingLevels:eT,thinkingLevelMap:eI,sandboxMode:W,onSandboxModeChange:e||U?er:void 0,retryInfo:E,soundEnabled:ei,onSoundToggle:el}),eL=(0,o.useCallback)(e=>{C?u?.current?.insertText(e):J(e)},[C,u,J]);return y?(0,n.jsx)("div",{className:"flex h-full items-center justify-center text-text-muted",children:"Loading session..."}):b?(0,n.jsx)("div",{className:"flex h-full items-center justify-center text-red-400",children:b}):(0,n.jsxs)("div",{className:"relative flex h-full flex-col overflow-hidden",onDragEnter:ef,onDragOver:em,onDragLeave:ev,onDrop:ey,children:[_&&(0,n.jsx)(tq,{request:_,onApprove:()=>void en(_.requestId,(_.method,"accept"),"item/permissions/requestApproval"===_.method?{permissions:_.params?.permissions??{},scope:"turn"}:void 0),onApproveSession:()=>void en(_.requestId,"item/permissions/requestApproval"===_.method?"accept":"acceptForSession","item/permissions/requestApproval"===_.method?{permissions:_.params?.permissions??{},scope:"session"}:void 0),onDeny:()=>void en(_.requestId,(_.method,"decline"),"item/permissions/requestApproval"===_.method?{permissions:{},scope:"turn"}:void 0)}),eg&&(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"})]})]})]}),ej?(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",alignItems:"center",justifyContent:"space-between",gap:12,marginLeft:16,marginRight:52,fontFamily:"var(--font-mono)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10,minWidth:0,flex:1,lineHeight:1.4},children:[(0,n.jsx)("span",{style:{fontSize:23,color:"var(--text)",fontWeight:750,letterSpacing:0},children:c.C3}),(0,n.jsx)("span",{style:{fontSize:14,minWidth:0,overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"},children:(0,n.jsx)(tU,{phrases:t_})})]}),(0,n.jsx)("div",{style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"flex-end",minHeight:22},children:(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-dim)",whiteSpace:"nowrap"},children:["v","0.1.44"]})})]}),eM]})}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"relative flex flex-1 overflow-hidden",children:[(0,n.jsx)("div",{ref:q,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:ek?{paddingBottom:"calc(env(safe-area-inset-bottom, 0px) + 128px)"}:void 0,children:[(()=>{let r=new Map;for(let e of j)"toolResult"===e.role&&r.set(e.toolCallId,e);let o=-1;for(let e=j.length-1;e>=0;e--)if("user"===j[e].role){o=e;break}let i=0;return j.map((l,s)=>{let d="user"===l.role||"assistant"===l.role,c=d?i++:-1,u=!1;if("assistant"===l.role){u=!0;let e=j.slice(s+1).find(e=>"user"===e.role||"assistant"===e.role);e?.role==="assistant"&&(u=!1),u&&w.isStreaming&&s===j.length-1&&(u=!1)}let p=(0,n.jsx)(ta,{message:l,toolResults:r,modelNames:z,entryId:k[s],onFork:C||U||0===s&&"user"===l.role?void 0:Y,forking:A===k[s],onSendMessage:eL,onOpenImage:a,showTimestamp:u,prevTimestamp:s>0?j[s-1].timestamp:void 0,renderVisualCodeBlocks:!!g,cwd:v?.info?.cwd??e?.cwd??t??void 0},s);return d?(0,n.jsx)("div",{ref:e=>{eb.current[c]=e,s===o&&(K.current=e)},children:p},s):p})})(),w.isStreaming&&w.streamingMessage&&(0,n.jsx)(ta,{message:w.streamingMessage,isStreaming:!0,modelNames:z,onSendMessage:eL,onOpenImage:a,renderVisualCodeBlocks:!!g,cwd:v?.info?.cwd??e?.cwd??t??void 0,streamingProcessState:S}),C&&!w.streamingMessage&&(0,n.jsx)("div",{className:"py-2 text-[13px] text-text-muted",children:(0,n.jsx)("span",{className:"animate-[pulse_1.5s_infinite]",children:function(e){if(e?.kind==="running_tools"){let t=e.tools.map(e=>e.name);return 0===t.length?"Running tool...":1===t.length?`Running ${t[0]}...`:t.length<=3?`Running ${t.join(", ")}...`:`Running ${t.slice(0,2).join(", ")} (+${t.length-2})...`}return e?.kind==="waiting_model"?"Waiting for model...":"Thinking..."}(O)})}),v?.info?.cwd&&!1===v.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:v.info.cwd})]}),H&&(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:H}),C&&(0,n.jsx)("div",{style:{height:q.current?q.current.clientHeight:"80vh"}}),(0,n.jsx)("div",{ref:V})]})}),!ek&&(0,n.jsx)(tT,{messages:j,streamingMessage:w.streamingMessage,scrollContainer:q,messageRefs:eb}),eC.length>0&&(0,n.jsxs)("button",{onClick:()=>eS(e=>!e),title:ew?"Hide agent runs":"Show agent runs",style:{position:"absolute",right:ek?8:ew?260:40,top:8,minWidth:28,height:28,display:"flex",alignItems:"center",justifyContent:"center",gap:6,padding:ez>0||eC.length>1?"0 8px":0,background:ew?"var(--bg-selected)":"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:ew?"var(--accent)":"var(--text-dim)",cursor:"pointer",zIndex:30,fontSize:12,transition:"right 0.2s ease, background 0.12s"},onMouseEnter:e=>{ew||(e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{ew||(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"})]}),(ez>0||eC.length>1)&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4,fontSize:10,fontWeight:700,color:ez>0?"var(--accent)":"var(--text-dim)"},children:[ez>0&&(0,n.jsxs)("span",{children:[ez," active"]}),(0,n.jsx)("span",{children:eC.length})]})]}),ew&&eC.length>0&&(0,n.jsxs)("div",{style:{position:"absolute",right:ek?8:48,top:4,bottom:4,width:ek?"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:"Agent Runs"}),(0,n.jsx)(t$,{runs:eC})]})]}),(0,n.jsx)("div",{className:"relative",children:eM})]})]})}function tq({request:e,onApprove:t,onApproveSession:r,onDeny:o}){let i=e.params??{},l="string"==typeof i.command?i.command:Array.isArray(i.command)?i.command.join(" "):null,s="string"==typeof i.cwd?i.cwd:null,a="string"==typeof i.reason&&i.reason.trim()?i.reason.trim():null,d="item/permissions/requestApproval"===e.method?JSON.stringify(i.permissions??{},null,2):null,c="item/fileChange/requestApproval"===e.method?"请求文件写入权限":"item/permissions/requestApproval"===e.method?"请求额外权限":"请求执行权限";return(0,n.jsx)("div",{style:{position:"absolute",inset:0,zIndex:120,background:"rgba(0,0,0,0.22)",display:"flex",alignItems:"center",justifyContent:"center",padding:20},children:(0,n.jsxs)("div",{style:{width:"min(720px, calc(100vw - 40px))",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 20px 60px rgba(0,0,0,0.28)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:"14px 16px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",gap:10},children:[(0,n.jsx)("div",{style:{color:"#f59e0b",display:"flex",alignItems:"center"},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)("path",{d:"M12 9v4"}),(0,n.jsx)("path",{d:"M12 17h.01"}),(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.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)"},children:c}),(0,n.jsx)("div",{style:{marginTop:2,fontSize:12,color:"var(--text-dim)"},children:"默认权限模式下,此操作需要你的确认"})]})]}),(0,n.jsxs)("div",{style:{padding:16,display:"flex",flexDirection:"column",gap:12},children:[a&&(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.6},children:a}),s&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:11,fontWeight:700,color:"var(--text-dim)",marginBottom:4},children:"cwd"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:s})]}),l&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:11,fontWeight:700,color:"var(--text-dim)",marginBottom:4},children:"command"}),(0,n.jsx)("pre",{style:{margin:0,padding:"10px 12px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",fontSize:12,lineHeight:1.55,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"var(--font-mono)"},children:l})]}),d&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:11,fontWeight:700,color:"var(--text-dim)",marginBottom:4},children:"permissions"}),(0,n.jsx)("pre",{style:{margin:0,padding:"10px 12px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",fontSize:12,lineHeight:1.55,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"var(--font-mono)"},children:d})]})]}),(0,n.jsxs)("div",{style:{padding:"12px 16px",borderTop:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"flex-end",gap:8},children:[(0,n.jsx)("button",{type:"button",onClick:o,style:{padding:"7px 12px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:600},children:"拒绝"}),(0,n.jsx)("button",{type:"button",onClick:t,style:{padding:"7px 12px",borderRadius:6,border:"1px solid rgba(37,99,235,0.36)",background:"var(--bg-selected)",color:"var(--text)",cursor:"pointer",fontSize:12,fontWeight:600},children:"仅这次允许"}),(0,n.jsx)("button",{type:"button",onClick:r,style:{padding:"7px 12px",borderRadius:6,border:"1px solid var(--accent)",background:"var(--accent)",color:"#fff",cursor:"pointer",fontSize:12,fontWeight:600},children:"本会话允许"})]})]})})}let tK="var(--text-dim)";function tJ({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:tK}),(0,n.jsx)("path",{d:"M1 6h14.5L14 13H2L1 6Z",stroke:tK,strokeWidth:"1",fill:tK,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:tK,strokeWidth:"1",fill:tK,fillOpacity:"0.1"})})}function tZ({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:tK,strokeWidth:"1",fill:tK,fillOpacity:"0.08"}),(0,n.jsx)("path",{d:"M10 2v3h3",stroke:tK,strokeWidth:"1",fill:"none",strokeLinejoin:"round"})]})}function tY({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:tK,strokeWidth:"0.9",fill:tK,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:tK,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:tK,letterSpacing:"0",children:e})]})}function tG({size:e=14}){return(0,n.jsx)(tY,{label:"TS",size:e})}function tX({size:e=14}){return(0,n.jsx)(tY,{label:"TSX",size:e})}function tQ({size:e=14}){return(0,n.jsx)(tY,{label:"JS",size:e})}function t0({size:e=14}){return(0,n.jsx)(tY,{label:"JSX",size:e})}function t1({size:e=14}){return(0,n.jsx)(tY,{label:"PY",size:e})}function t2({size:e=14}){return(0,n.jsx)(tY,{label:"{}",size:e})}function t4({size:e=14}){return(0,n.jsx)(tY,{label:"CSS",size:e})}function t5({size:e=14}){return(0,n.jsx)(tY,{label:"SC",size:e})}function t6({size:e=14}){return(0,n.jsx)(tY,{label:"HTM",size:e})}function t3({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:tK,strokeWidth:"0.9",fill:tK,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:tK,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M3.5 9.5V7l1.5 1.5L6.5 7v2.5",stroke:tK,strokeWidth:"0.9",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,n.jsx)("path",{d:"M8 7v2.5M7 9l1 1.5 1-1.5",stroke:tK,strokeWidth:"0.9",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]})}function t8({size:e=14}){return(0,n.jsx)(tY,{label:"YML",size:e})}function t7({size:e=14}){return(0,n.jsx)(tY,{label:"TOM",size:e})}function t9({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:tK,strokeWidth:"0.9",fill:tK,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:tK,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M4 7.5l2 1.5-2 1.5",stroke:tK,strokeWidth:"0.95",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,n.jsx)("path",{d:"M7.5 10.5h2.5",stroke:tK,strokeWidth:"0.95",strokeLinecap:"round"})]})}function re({size:e=14}){return(0,n.jsx)(tY,{label:"RS",size:e})}function rt({size:e=14}){return(0,n.jsx)(tY,{label:"GO",size:e})}function rr({size:e=14}){return(0,n.jsx)(tY,{label:"SQL",size:e})}function rn({size:e=14}){return(0,n.jsx)(tY,{label:"GQL",size:e})}function ro({size:e=14}){return(0,n.jsx)(tY,{label:"TF",size:e})}function ri({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:tK,strokeWidth:"0.9",fill:tK,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:tK,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:tK,strokeWidth:"0.8"}),(0,n.jsx)("rect",{x:"6",y:"6.5",width:"2",height:"1.5",rx:"0.3",stroke:tK,strokeWidth:"0.8"}),(0,n.jsx)("rect",{x:"3.5",y:"8.5",width:"2",height:"1.5",rx:"0.3",stroke:tK,strokeWidth:"0.8"})]})}function rl({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:tK,strokeWidth:"0.9",fill:tK,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:tK,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"5.5",cy:"8.5",r:"1.5",stroke:tK,strokeWidth:"0.9"}),(0,n.jsx)("path",{d:"M7 8.5h2.5M8.5 8.5v1.5",stroke:tK,strokeWidth:"0.9",strokeLinecap:"round"})]})}function rs({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:tK,strokeWidth:"0.9",fill:tK,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:tK,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"5",cy:"6.5",r:"1",stroke:tK,strokeWidth:"0.85"}),(0,n.jsx)("circle",{cx:"9",cy:"6.5",r:"1",stroke:tK,strokeWidth:"0.85"}),(0,n.jsx)("circle",{cx:"5",cy:"10",r:"1",stroke:tK,strokeWidth:"0.85"}),(0,n.jsx)("path",{d:"M5 7.5V9",stroke:tK,strokeWidth:"0.85",strokeLinecap:"round"}),(0,n.jsx)("path",{d:"M9 7.5v.5a2 2 0 0 1-2 2H6",stroke:tK,strokeWidth:"0.85",strokeLinecap:"round",fill:"none"})]})}function ra({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:tK,strokeWidth:"0.9",fill:tK,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:tK,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:tK,strokeWidth:"0.9"}),(0,n.jsx)("path",{d:"M5.5 8.5V7.5a1.5 1.5 0 0 1 3 0v1",stroke:tK,strokeWidth:"0.9",strokeLinecap:"round",fill:"none"})]})}function rd({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:tK,strokeWidth:"0.9",fill:tK,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:tK,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"7",cy:"8.5",r:"1.3",stroke:tK,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:tK,strokeWidth:"0.8",strokeLinecap:"round"})]})}function rc(e,t=14){let r=e.toLowerCase(),o=r.split(".").pop()??"";if("dockerfile"===r||r.startsWith("dockerfile."))return(0,n.jsx)(ri,{size:t});if(".env"===r||r.startsWith(".env."))return(0,n.jsx)(rl,{size:t});if(".gitignore"===r||".gitattributes"===r||".gitmodules"===r)return(0,n.jsx)(rs,{size:t});if("package-lock.json"===r||"yarn.lock"===r||"bun.lock"===r||"pnpm-lock.yaml"===r||"cargo.lock"===r)return(0,n.jsx)(ra,{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)(rd,{size:t});switch(o){case"ts":return(0,n.jsx)(tG,{size:t});case"tsx":return(0,n.jsx)(tX,{size:t});case"js":case"mjs":case"cjs":return(0,n.jsx)(tQ,{size:t});case"jsx":return(0,n.jsx)(t0,{size:t});case"py":return(0,n.jsx)(t1,{size:t});case"json":case"jsonl":return(0,n.jsx)(t2,{size:t});case"css":case"less":return(0,n.jsx)(t4,{size:t});case"scss":return(0,n.jsx)(t5,{size:t});case"html":case"htm":return(0,n.jsx)(t6,{size:t});case"md":case"mdx":return(0,n.jsx)(t3,{size:t});case"yaml":case"yml":return(0,n.jsx)(t8,{size:t});case"toml":return(0,n.jsx)(t7,{size:t});case"sh":case"bash":case"zsh":case"fish":return(0,n.jsx)(t9,{size:t});case"rs":return(0,n.jsx)(re,{size:t});case"go":return(0,n.jsx)(rt,{size:t});case"sql":return(0,n.jsx)(rr,{size:t});case"graphql":case"gql":return(0,n.jsx)(rn,{size:t});case"tf":case"hcl":return(0,n.jsx)(ro,{size:t});case"lock":return(0,n.jsx)(ra,{size:t});default:return(0,n.jsx)(tZ,{size:t})}}async function ru(e){let t=ed(e),r=await fetch(`/api/files/${t}?type=list`);return r.ok?((await r.json()).entries??[]).map(t=>{var r;return{name:t.name,fullPath:(r=t.name,`${ea(e).replace(/\/$/,"")}/${r}`),isDir:t.isDir,size:t.size,children:t.isDir?[]:void 0,loaded:!t.isDir}}):[]}function rp(e,t){let r=t.trim().toLowerCase();return!!(!r||e.name.toLowerCase().includes(r))||(e.children??[]).some(e=>rp(e,r))}function rh(e){return!!Array.from(e.types).includes("Files")||Array.from(e.items).some(e=>"file"===e.kind)}function rx(e){return Array.from(e.files).filter(e=>!!e.name)}function rg(e,t){return e===t?".":eu(e,t)}function rf({node:e,depth:t,cwd:r,onOpenFile:i,onAtMention:l,expandedPaths:s,onToggleExpanded:a,onUploadFiles:d,uploadTargetPath:c,refreshKey:u,searchQuery:p}){let h=!!p?.trim(),x=h?e.isDir:s.has(e.fullPath),[g,f]=(0,o.useState)(e.children??[]),[m,v]=(0,o.useState)(e.loaded??!1),[y,b]=(0,o.useState)(!1),[j,k]=(0,o.useState)(!1),[w,S]=(0,o.useState)(!1),C=e.isDir&&(w||c===e.fullPath),z=h?g.filter(e=>rp(e,p??"")):g,T=(0,o.useCallback)(async(t=!1)=>{if(!m||t){b(!0);try{let t=await ru(e.fullPath);f(t),v(!0)}catch{}finally{b(!1)}}},[m,e.fullPath]),I=(0,o.useRef)(m);(0,o.useEffect)(()=>{I.current=m}),(0,o.useEffect)(()=>{x&&m&&T(!0)},[u]);let M=(0,o.useCallback)(()=>{if(e.isDir){let t=!x;a(e.fullPath,t),t&&!m&&T()}else i(e.fullPath,e.name)},[e.isDir,e.fullPath,e.name,m,x,T,i,a]),L=(0,o.useCallback)(t=>{e.isDir&&rh(t.dataTransfer)&&(t.preventDefault(),t.stopPropagation(),t.dataTransfer.dropEffect="copy",S(!0))},[e.isDir]),R=(0,o.useCallback)(t=>{e.isDir&&rh(t.dataTransfer)&&(t.preventDefault(),t.stopPropagation(),t.dataTransfer.dropEffect="copy")},[e.isDir]),W=(0,o.useCallback)(t=>{if(!e.isDir)return;let r=t.relatedTarget;r instanceof Node&&t.currentTarget.contains(r)||S(!1)},[e.isDir]),E=(0,o.useCallback)(t=>{if(!e.isDir||!rh(t.dataTransfer))return;t.preventDefault(),t.stopPropagation(),S(!1);let r=rx(t.dataTransfer);r.length>0&&(d(r,e.fullPath),x||a(e.fullPath,!0),m||T())},[T,m,e.fullPath,e.isDir,a,d,x]);return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{onClick:M,onMouseEnter:()=>k(!0),onMouseLeave:()=>k(!1),onDragEnter:L,onDragOver:R,onDragLeave:W,onDrop:E,style:{position:"relative",display:"flex",alignItems:"center",gap:4,paddingLeft:8+14*t,paddingRight:8,height:24,cursor:"pointer",background:C?"rgba(37,99,235,0.14)":j?"var(--bg-hover)":"transparent",outline:C?"1px solid rgba(37,99,235,0.42)":"none",outlineOffset:-1,borderRadius:4,userSelect:"none",transition:"background 0.12s, outline-color 0.12s"},children:[e.isDir&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:x?"rotate(90deg)":"none",transition:"transform 0.1s"},children:(0,n.jsx)("polyline",{points:"3 2 7 5 3 8"})}),!e.isDir&&(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flexShrink:0,display:"flex",alignItems:"center"},children:e.isDir?(0,n.jsx)(tJ,{size:14,open:x}):rc(e.name,14)}),(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},title:e.fullPath,children:e.name}),y&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",children:(0,n.jsx)("path",{d:"M12 2v4M12 18v4M4.93 4.93l2.83 2.83M16.24 16.24l2.83 2.83M2 12h4M18 12h4"})}),l&&j&&(0,n.jsxs)("button",{onClick:t=>{t.stopPropagation(),l(eu(e.fullPath,r))},title:"Insert path into chat",style:{position:"absolute",right:4,top:"50%",transform:"translateY(-50%)",display:"flex",alignItems:"center",justifyContent:"center",gap:4,padding:"0 8px",height:20,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:4,color:"var(--accent)",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"4"}),(0,n.jsx)("path",{d:"M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8"})]}),"mention"]})]}),e.isDir&&x&&(0,n.jsxs)("div",{children:[z.map(e=>(0,n.jsx)(rf,{node:e,depth:t+1,cwd:r,onOpenFile:i,onAtMention:l,expandedPaths:s,onToggleExpanded:a,onUploadFiles:d,uploadTargetPath:c,refreshKey:u,searchQuery:p},e.fullPath)),0===z.length&&m&&!h&&(0,n.jsx)("div",{style:{paddingLeft:8+(t+1)*14,fontSize:11,color:"var(--text-dim)",height:22,display:"flex",alignItems:"center"},children:"empty"})]})]})}function rm({cwd:e,onOpenFile:t,refreshKey:r,onAtMention:i,searchQuery:l="",onSearchChange:s}){let[a,d]=(0,o.useState)([]),[c,u]=(0,o.useState)(!0),[p,h]=(0,o.useState)(null),[x,g]=(0,o.useState)(new Set),[f,m]=(0,o.useState)(!1),[v,y]=(0,o.useState)(null),[b,j]=(0,o.useState)(null),k=(0,o.useRef)(null),w=(0,o.useRef)(null),S=(0,o.useRef)(0),C=(0,o.useCallback)((e,t)=>(u(t),h(null),ru(e).then(e=>d(e)).catch(e=>h(String(e))).finally(()=>u(!1))),[]),z=(0,o.useCallback)((e,t)=>{g(r=>{let n=new Set(r);return t?n.add(e):n.delete(e),n})},[]);(0,o.useEffect)(()=>{let t=k.current!==e;k.current=e,t&&g(new Set),C(e,t)},[e,r,C]),(0,o.useEffect)(()=>()=>{w.current&&clearTimeout(w.current)},[]);let T=(0,o.useCallback)(()=>{C(e,0===a.length)},[e,a.length,C]),I=(0,o.useCallback)(()=>{w.current&&clearTimeout(w.current),w.current=setTimeout(()=>j(null),5e3)},[]),M=(0,o.useCallback)((t,r)=>{if(0===t.length)return;S.current=0,m(!1),w.current&&clearTimeout(w.current);let n=t.reduce((e,t)=>e+t.size,0),o=rg(r,e);y(r),j({phase:"uploading",targetPath:r,fileCount:t.length,loaded:0,total:n,message:`Uploading ${t.length} file${1===t.length?"":"s"} to ${o}`});let i=new FormData;t.forEach(e=>i.append("files",e,e.name));let l=new XMLHttpRequest,s=ed(r);l.open("POST",`/api/files/${s}?type=upload`),l.upload.onprogress=e=>{e.lengthComputable&&j(t=>t?{...t,loaded:e.loaded,total:e.total}:t)},l.onload=()=>{y(null);let e={};try{e=JSON.parse(l.responseText)}catch{e={}}if(l.status>=200&&l.status<300){let i=e.uploaded??[],l=e.failed??[],s=[...i.filter(e=>e.name!==e.originalName).slice(0,3).map(e=>`${e.originalName} saved as ${e.name}`),...l.slice(0,3).map(e=>`${e.name}: ${e.error}`)];j({phase:l.length>0?"warning":"success",targetPath:r,fileCount:t.length,loaded:n,total:n,message:l.length>0?`Uploaded ${i.length}, ${l.length} failed`:`Uploaded ${i.length} file${1===i.length?"":"s"} to ${o}`,details:s}),T(),I()}else{let o=e.error??`Upload failed (HTTP ${l.status})`;j({phase:(l.status,"error"),targetPath:r,fileCount:t.length,loaded:0,total:n,message:o,details:403===l.status?["Check directory write permission or project access."]:void 0}),I()}},l.onerror=()=>{y(null),j({phase:"error",targetPath:r,fileCount:t.length,loaded:0,total:n,message:"Upload failed due to a network error"}),I()},l.onabort=()=>{y(null),j({phase:"error",targetPath:r,fileCount:t.length,loaded:0,total:n,message:"Upload canceled"}),I()},l.send(i)},[e,T,I]),L=(0,o.useCallback)(e=>{rh(e.dataTransfer)&&(e.preventDefault(),S.current+=1,m(!0))},[]),R=(0,o.useCallback)(e=>{rh(e.dataTransfer)&&(e.preventDefault(),e.dataTransfer.dropEffect="copy")},[]),W=(0,o.useCallback)(()=>{S.current-=1,S.current<=0&&(S.current=0,m(!1))},[]),E=(0,o.useCallback)(t=>{if(!rh(t.dataTransfer))return;t.preventDefault(),S.current=0,m(!1);let r=rx(t.dataTransfer);r.length>0&&M(r,e)},[e,M]),$=l.trim()?a.filter(e=>rp(e,l)):a,A=l.trim().length>0;return c?(0,n.jsx)(rv,{cwd:e,isDraggingFiles:f,uploadState:b,onDragEnter:L,onDragOver:R,onDragLeave:W,onDrop:E,children:(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:"Loading files..."})}):p?(0,n.jsx)(rv,{cwd:e,isDraggingFiles:f,uploadState:b,onDragEnter:L,onDragOver:R,onDragLeave:W,onDrop:E,children:(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"#f87171"},children:p})}):(0,n.jsx)(rv,{cwd:e,isDraggingFiles:f,uploadState:b,onDragEnter:L,onDragOver:R,onDragLeave:W,onDrop:E,children:(0,n.jsxs)("div",{style:{padding:"2px 4px"},children:[$.map(o=>(0,n.jsx)(rf,{node:o,depth:0,cwd:e,onOpenFile:t,onAtMention:i,expandedPaths:x,onToggleExpanded:z,onUploadFiles:M,uploadTargetPath:v,refreshKey:r,searchQuery:l},o.fullPath)),0===$.length&&(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:A?"No matching files":"No files found"})]})})}function rv({cwd:e,isDraggingFiles:t,uploadState:r,onDragEnter:o,onDragOver:i,onDragLeave:l,onDrop:s,children:a}){let d=r&&r.total>0?Math.max(0,Math.min(100,Math.round(r.loaded/r.total*100))):r?.phase==="uploading"?8:100,c=r?.phase==="success"?"#22c55e":r?.phase==="warning"?"#f59e0b":r?.phase==="error"?"#ef4444":"var(--accent)";return(0,n.jsxs)("div",{onDragEnter:o,onDragOver:i,onDragLeave:l,onDrop:s,style:{position:"relative",display:"flex",flexDirection:"column",minHeight:"100%",outline:t?"1px solid rgba(37,99,235,0.45)":"none",outlineOffset:-1,background:t?"rgba(37,99,235,0.04)":void 0,transition:"background 0.12s, outline-color 0.12s"},children:[(0,n.jsx)("div",{style:{flex:1,minHeight:0},children:a}),t&&(0,n.jsx)("div",{style:{pointerEvents:"none",position:"absolute",inset:6,top:42,border:"1px dashed rgba(37,99,235,0.62)",borderRadius:8,background:"rgba(37,99,235,0.07)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:2},children:(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"7px 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",fontSize:12,boxShadow:"0 8px 24px rgba(0,0,0,0.16)"},children:[(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,n.jsx)("polyline",{points:"17 8 12 3 7 8"}),(0,n.jsx)("line",{x1:"12",y1:"3",x2:"12",y2:"15"})]}),"Drop to upload into ",rg(e,e)]})}),r&&(0,n.jsxs)("div",{style:{margin:"6px",padding:"7px 8px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",boxShadow:"0 8px 24px rgba(0,0,0,0.12)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:7,minWidth:0},children:[(0,n.jsx)("span",{style:{width:8,height:8,borderRadius:999,background:c,flexShrink:0}}),(0,n.jsx)("span",{title:r.message,style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text)",fontSize:11,fontWeight:600},children:r.message}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,flexShrink:0},children:"uploading"===r.phase?`${d}%`:function(e){if(!Number.isFinite(e)||e<=0)return"0 B";let t=["B","KB","MB","GB"],r=e,n=0;for(;r>=1024&&n<t.length-1;)r/=1024,n+=1;return`${r>=10||0===n?Math.round(r):r.toFixed(1)} ${t[n]}`}(r.total)})]}),(0,n.jsx)("div",{style:{marginTop:6,height:3,borderRadius:999,background:"var(--bg)",overflow:"hidden"},children:(0,n.jsx)("div",{style:{width:`${d}%`,height:"100%",borderRadius:999,background:c,transition:"width 0.15s ease"}})}),r.details&&r.details.length>0&&(0,n.jsx)("div",{style:{marginTop:5,display:"grid",gap:2},children:r.details.map(e=>(0,n.jsx)("div",{title:e,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontSize:10},children:e},e))})]})]})}function ry({fileName:e,pageInfo:t,onZoomIn:r,onZoomOut:o,zoom:i,extra:l}){return(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,minHeight:32},children:[e&&(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:300},title:e,children:e}),(0,n.jsx)("span",{style:{marginLeft:"auto"}}),t&&(0,n.jsx)("span",{children:t}),void 0!==i&&o&&r&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsx)("button",{onClick:o,title:"Zoom out",style:rb,children:(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:(0,n.jsx)("line",{x1:"2",y1:"5",x2:"8",y2:"5"})})}),(0,n.jsxs)("span",{style:{minWidth:36,textAlign:"center",fontVariantNumeric:"tabular-nums"},children:[Math.round(100*i),"%"]}),(0,n.jsx)("button",{onClick:r,title:"Zoom in",style:rb,children:(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"5",y1:"2",x2:"5",y2:"8"}),(0,n.jsx)("line",{x1:"2",y1:"5",x2:"8",y2:"5"})]})})]}),l]})}let rb={display:"flex",alignItems:"center",justifyContent:"center",width:24,height:24,padding:0,background:"none",border:"1px solid var(--border)",borderRadius:4,color:"var(--text-muted)",cursor:"pointer"},rj=null;function rk({arrayBuffer:e,fileName:t}){let i=(0,o.useRef)(null),[l,s]=(0,o.useState)(!0),[a,d]=(0,o.useState)(null),[c,u]=(0,o.useState)(0),[p,h]=(0,o.useState)(1),[x,g]=(0,o.useState)(1),f=(0,o.useRef)(x);f.current=x;let m=(0,o.useRef)(null),v=(0,o.useRef)(null),y=(0,o.useCallback)(async e=>{if(!rj||!m.current)return;let t=m.current;if(!(e<1)&&!(e>t.numPages)){v.current&&(v.current.cancel(),v.current=null);try{let r=await t.getPage(e),n=r.getViewport({scale:f.current*(window.devicePixelRatio||1)}),o=i.current;if(!o)return;let l=o.querySelector("canvas");if(l||((l=document.createElement("canvas")).style.display="block",l.style.margin="0 auto",o.innerHTML="",o.appendChild(l)),l.width=n.width,l.height=n.height,l.style.width=`${n.width/(window.devicePixelRatio||1)}px`,l.style.height=`${n.height/(window.devicePixelRatio||1)}px`,!l.getContext("2d"))return;let s=r.render({canvas:l,viewport:n});v.current=s,await s.promise,v.current=null}catch(e){"RenderingCancelledException"!==e.name&&console.error("PDF render error:",e)}}},[]);return(0,o.useEffect)(()=>{let t=!1;return async function(){s(!0),d(null);try{rj||((rj=await Promise.all([r.e(2213),r.e(2619)]).then(r.bind(r,12810))).GlobalWorkerOptions.workerSrc=new r.U(r(53228)).toString());let n=await rj.getDocument({data:e}).promise;if(t)return;m.current=n,u(n.numPages),h(1),s(!1)}catch(e){t||(d(String(e)),s(!1))}}(),()=>{t=!0,v.current&&(v.current.cancel(),v.current=null)}},[e]),(0,o.useEffect)(()=>{!l&&c>0&&y(p)},[l,p,c,y]),(0,o.useEffect)(()=>{!l&&c>0&&y(p)},[x]),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsx)(ry,{fileName:t,pageInfo:c>0?`Page ${p} / ${c}`:void 0,zoom:x,onZoomIn:()=>g(e=>Math.min(e+.25,3)),onZoomOut:()=>g(e=>Math.max(e-.25,.25)),extra:c>1&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsx)("button",{onClick:()=>h(e=>Math.max(e-1,1)),disabled:p<=1,style:{...rw,opacity:p<=1?.4:1},children:(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:(0,n.jsx)("polyline",{points:"6 2 3 5 6 8"})})}),(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-dim)",minWidth:28,textAlign:"center"},children:[p,"/",c]}),(0,n.jsx)("button",{onClick:()=>h(e=>Math.min(e+1,c)),disabled:p>=c,style:{...rw,opacity:p>=c?.4:1},children:(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:(0,n.jsx)("polyline",{points:"4 2 7 5 4 8"})})})]})}),(0,n.jsxs)("div",{style:{flex:1,overflow:"auto",background:"#525659",display:"flex",justifyContent:"center",padding:16},children:[l&&(0,n.jsx)("div",{style:{color:"#ccc",fontSize:13,display:"flex",alignItems:"center",gap:6,alignSelf:"flex-start",marginTop:40},children:"Loading PDF..."}),a&&(0,n.jsx)("div",{style:{color:"#f87171",fontSize:13,alignSelf:"flex-start",marginTop:40},children:a}),(0,n.jsx)("div",{ref:i,style:{visibility:l?"hidden":"visible"}})]})]})}let rw={display:"flex",alignItems:"center",justifyContent:"center",width:24,height:24,padding:0,background:"none",border:"1px solid var(--border)",borderRadius:4,color:"var(--text-muted)",cursor:"pointer"};function rS({arrayBuffer:e,fileName:t}){let i=(0,o.useRef)(null),[l,s]=(0,o.useState)(!0),[a,d]=(0,o.useState)(null);return(0,o.useEffect)(()=>{let t=!1;return async function(){s(!0),d(null);try{let{renderAsync:n}=await Promise.all([r.e(2619),r.e(4453),r.e(2274)]).then(r.bind(r,52274)),o=i.current;if(!o||t)return;o.innerHTML="",await n(e,o,void 0,{className:"docx-preview",inWrapper:!0,ignoreWidth:!1,ignoreHeight:!1,ignoreFonts:!1,breakPages:!0,ignoreLastRenderedPageBreak:!1,experimental:!1,trimXmlDeclaration:!0,useBase64URL:!1,renderChanges:!1,renderHeaders:!0,renderFooters:!0,renderFootnotes:!0,renderEndnotes:!0}),t||s(!1)}catch(e){t||(console.error("DOCX render error:",e),d(String(e)),s(!1))}}(),()=>{t=!0}},[e]),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsx)(ry,{fileName:t}),(0,n.jsxs)("div",{style:{flex:1,overflow:"auto",background:"#e8e8e8",padding:"24px 0"},children:[l&&(0,n.jsx)("div",{style:{color:"var(--text-muted)",fontSize:13,padding:"40px 16px",textAlign:"center"},children:"Loading document..."}),a&&(0,n.jsx)("div",{style:{color:"#f87171",fontSize:13,padding:"40px 16px",textAlign:"center"},children:a}),(0,n.jsx)("div",{ref:i,style:{maxWidth:816,margin:"0 auto",background:"#fff",boxShadow:"0 1px 4px rgba(0,0,0,0.12)",minHeight:100,visibility:l?"hidden":"visible"},className:"docx-preview-container"})]})]})}function rC({arrayBuffer:e,fileName:t}){let[i,l]=(0,o.useState)(!0),[s,a]=(0,o.useState)(null),[d,c]=(0,o.useState)([]),[u,p]=(0,o.useState)(0),h=(0,o.useRef)(null),[x,g]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{let t=!1;return async function(){l(!0),a(null);try{let n=await Promise.all([r.e(3524),r.e(8436)]).then(r.bind(r,15967)),o=n.read(e,{type:"array"}),i=o.SheetNames.map(e=>{let t=o.Sheets[e],r=n.utils.sheet_to_html(t,{editable:!1});return{name:e,html:r}});t||(c(i),p(0),l(!1))}catch(e){t||(console.error("XLSX parse error:",e),a(String(e)),l(!1))}}(),()=>{t=!0}},[e]),(0,o.useEffect)(()=>{let e=h.current;if(!e)return;let t=e.querySelector("table");if(!t)return;let r=()=>{g(t.querySelectorAll("colgroup col, thead tr:first-child th, tbody tr:first-child td").length>8)};r();let n=new ResizeObserver(r);return n.observe(e),()=>n.disconnect()},[u,d]),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsx)(ry,{fileName:t,extra:d.length>1&&(0,n.jsx)("div",{style:{display:"flex",alignItems:"center",gap:2},children:d.map((e,t)=>(0,n.jsx)("button",{onClick:()=>p(t),style:{padding:"2px 10px",fontSize:11,border:"1px solid var(--border)",borderBottom:t===u?"2px solid var(--accent)":"1px solid var(--border)",borderRadius:"4px 4px 0 0",background:t===u?"var(--bg-selected)":"none",color:t===u?"var(--text)":"var(--text-muted)",cursor:"pointer",fontWeight:t===u?600:400,transition:"background 0.12s"},onMouseEnter:e=>{t!==u&&(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t!==u&&(e.currentTarget.style.background="none")},children:e.name},t))})}),(0,n.jsxs)("div",{style:{flex:1,overflow:"auto",background:"var(--bg-panel)"},children:[i&&(0,n.jsx)("div",{style:{color:"var(--text-muted)",fontSize:13,padding:"40px 16px",textAlign:"center"},children:"Loading spreadsheet..."}),s&&(0,n.jsx)("div",{style:{color:"#f87171",fontSize:13,padding:"40px 16px",textAlign:"center"},children:s}),!i&&!s&&d.length>0&&(0,n.jsx)("div",{ref:h,style:{padding:"0 16px 16px",overflow:x?"auto":"visible"},dangerouslySetInnerHTML:{__html:d[u]?.html??""},className:"xlsx-preview"})]})]})}function rz({arrayBuffer:e,fileName:t}){let[i,l]=(0,o.useState)(!0),[s,a]=(0,o.useState)(null),[d,c]=(0,o.useState)([]),[u,p]=(0,o.useState)(0);(0,o.useEffect)(()=>{let t=!1;return async function(){l(!0),a(null);try{let n=(await Promise.all([r.e(2619),r.e(4453)]).then(r.t.bind(r,54453,23))).default,o=await n.loadAsync(e),i=[];o.forEach(e=>{let t=/^ppt\/slides\/slide(\d+)\.xml$/i.exec(e);t&&i.push({name:e,index:parseInt(t[1],10)})}),i.sort((e,t)=>e.index-t.index);let s=[];for(let e of i){let r;if(t)return;let n=await o.file(e.name).async("string"),i=/<a:t[^>]*>([^<]*)<\/a:t>/g,l=[];for(;null!==(r=i.exec(n));){let e=r[1].trim();e&&l.push(e)}s.push({index:e.index,texts:l})}t||(c(s),l(!1))}catch(e){t||(console.error("PPTX parse error:",e),a(String(e)),l(!1))}}(),()=>{t=!0}},[e]);let h=d[u],x=d.length;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsx)(ry,{fileName:t,pageInfo:x>0?`Slide ${u+1} / ${x}`:void 0,extra:x>1&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsx)("button",{onClick:()=>p(e=>Math.max(e-1,0)),disabled:u<=0,style:{...rT,opacity:u<=0?.4:1},children:(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:(0,n.jsx)("polyline",{points:"6 2 3 5 6 8"})})}),(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-dim)",minWidth:28,textAlign:"center"},children:[u+1,"/",x]}),(0,n.jsx)("button",{onClick:()=>p(e=>Math.min(e+1,x-1)),disabled:u>=x-1,style:{...rT,opacity:u>=x-1?.4:1},children:(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:(0,n.jsx)("polyline",{points:"4 2 7 5 4 8"})})})]})}),(0,n.jsxs)("div",{style:{flex:1,overflow:"auto",background:"var(--bg-panel)",display:"flex",justifyContent:"center",alignItems:"flex-start",padding:24},children:[i&&(0,n.jsx)("div",{style:{color:"var(--text-muted)",fontSize:13,padding:"40px 16px",textAlign:"center"},children:"Loading presentation..."}),s&&(0,n.jsx)("div",{style:{color:"#f87171",fontSize:13,padding:"40px 16px",textAlign:"center"},children:s}),!i&&!s&&h&&(0,n.jsxs)("div",{style:{width:"100%",maxWidth:800},children:[(0,n.jsxs)("div",{style:{background:"#fff",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 2px 8px rgba(0,0,0,0.08)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:"8px 16px",background:"var(--bg)",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:["Slide ",h.index]}),(0,n.jsx)("div",{style:{padding:"24px 32px 40px",minHeight:200},children:0===h.texts.length?(0,n.jsx)("div",{style:{color:"var(--text-dim)",fontStyle:"italic",fontSize:13},children:"(No text content)"}):(0,n.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none"},children:h.texts.map((e,t)=>(0,n.jsx)("li",{style:{padding:"4px 0",fontSize:14,lineHeight:1.6,color:"var(--text)",borderBottom:t<h.texts.length-1?"1px solid var(--bg-panel)":"none"},children:e},t))})})]}),x>1&&(0,n.jsxs)("div",{style:{marginTop:24},children:[(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)",marginBottom:8},children:"All slides"}),(0,n.jsx)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(140px, 1fr))",gap:8},children:d.map((e,t)=>(0,n.jsxs)("button",{onClick:()=>p(t),style:{padding:"10px 12px",background:t===u?"var(--bg-selected)":"var(--bg)",border:t===u?"2px solid var(--accent)":"1px solid var(--border)",borderRadius:6,cursor:"pointer",textAlign:"left",fontSize:11,color:"var(--text-muted)",transition:"border-color 0.12s, background 0.12s"},onMouseEnter:e=>{t!==u&&(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t!==u&&(e.currentTarget.style.background="var(--bg)")},children:[(0,n.jsxs)("div",{style:{fontWeight:600,marginBottom:2,color:"var(--text)"},children:["Slide ",e.index]}),(0,n.jsx)("div",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.texts[0]||"(empty)"})]},e.index))})]})]})]})]})}let rT={display:"flex",alignItems:"center",justifyContent:"center",width:24,height:24,padding:0,background:"none",border:"1px solid var(--border)",borderRadius:4,color:"var(--text-muted)",cursor:"pointer"};var rI=r(27071),rM=r(89561),rL=r(82228),rR=r(46732),rW=r(74059),rE=r(13307),r$=r(53689),rA=r(14097),rB=r(25460),rN=r(20144),rP=r(82774),rD=r(62733),rO=r(77482),rH=r(55135),rF=r(11209),r_=r(88198),rU=r(4238),rV=r(44542);function rq({initialContent:e,language:t,isDark:r,onChange:i,onSave:l}){let s=(0,o.useRef)(null),a=(0,o.useRef)(null),d=(0,o.useRef)(i),c=(0,o.useRef)(l);return d.current=i,c.current=l,(0,o.useEffect)(()=>{let n=s.current;if(!n)return;let o=function(e){switch(e){case"javascript":case"typescript":return(0,rE.Q2)({typescript:"typescript"===e});case"python":return(0,r$.Hg)();case"sql":return(0,rA.ll)();case"json":return(0,rB.Pq)();case"html":return(0,rN.qy)();case"css":case"scss":case"less":return(0,rP.AH)();case"markdown":return(0,rD.wD)();case"xml":case"yaml":case"toml":return(0,rO._n)();case"rust":return(0,rH.T)();case"go":return(0,rF.go)();case"java":return(0,r_.J)();default:return null}}(t),i=l?rM.w4.of([{key:"Mod-s",run:()=>(c.current?.(),!0),preventDefault:!0}]):[],u=rI.$t.create({doc:e,extensions:[(0,rM.$K)(),(0,rM.dz)(),(0,rL.b6)(),(0,rR.y9)(rR.Zt),rM.w4.of([...rL.pw,...rL.cL,...rV.OO,...rU.Eo]),i,(0,rV.yU)(),...r?[rW.bM]:[],...o?[o]:[],rM.Lz.updateListener.of(e=>{e.docChanged&&d.current?.(e.state.doc.toString())}),rM.Lz.theme({"&":{height:"100%",fontSize:"13px"},".cm-scroller":{overflow:"auto",fontFamily:"var(--font-mono)"},".cm-content":{padding:"8px 0"},".cm-gutters":{borderRight:"1px solid var(--border)",background:"var(--bg)",color:"var(--text-dim)"},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground":{background:r?"#3a3d4e":"#b4d5fe"}})]}),p=new rM.Lz({state:u,parent:n});return a.current=p,()=>{p.destroy(),a.current=null}},[t,r]),(0,o.useEffect)(()=>{let t=a.current;t&&t.state.doc.toString()!==e&&t.dispatch({changes:{from:0,to:t.state.doc.length,insert:e}})},[e]),(0,n.jsx)("div",{ref:s,style:{height:"100%",overflow:"hidden"}})}function rK({dir:e}){return(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:"asc"===e?(0,n.jsx)("polyline",{points:"2 6 5 3 8 6"}):(0,n.jsx)("polyline",{points:"2 4 5 7 8 4"})})}function rJ(e,t,r){let n=new Blob([e],{type:r}),o=URL.createObjectURL(n),i=document.createElement("a");i.href=o,i.download=t,document.body.appendChild(i),i.click(),document.body.removeChild(i),setTimeout(()=>URL.revokeObjectURL(o),1e3)}function rZ({content:e,delimiter:t,fileName:r="table"}){let[i,l]=(0,o.useState)(null),[s,a]=(0,o.useState)("asc"),{header:d,rows:c}=(0,o.useMemo)(()=>(function(e,t){let r=e.replace(/\r\n/g,"\n").replace(/\r/g,"\n"),n=[],o=[],i="",l=!1;for(let e=0;e<r.length;e+=1){let s=r[e];if('"'===s){l&&'"'===r[e+1]?(i+='"',e+=1):l=!l;continue}if(s===t&&!l){o.push(i),i="";continue}if("\n"===s&&!l){o.push(i),o.some(e=>e.length>0)&&n.push(o),o=[],i="";continue}i+=s}o.push(i),o.some(e=>e.length>0)&&n.push(o);let s=n[0]??[],a=s.length;return{header:s,rows:n.slice(1).map(e=>{let t=[...e];for(;t.length<a;)t.push("");return t.slice(0,a)})}})(e,t),[e,t]),u=(0,o.useMemo)(()=>{if(null===i)return c;let e=[...c];return e.sort((e,t)=>{let r=e[i]??"",n=t[i]??"",o=Number(r),l=Number(n),a=""===r||""===n||Number.isNaN(o)||Number.isNaN(l)?r.localeCompare(n):o-l;return"asc"===s?a:-a}),e},[c,s,i]);return 0===d.length&&0===c.length?(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:"No tabular data to display"}):(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,padding:"8px 12px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",flexShrink:0},children:[(0,n.jsxs)("div",{style:{fontSize:11,color:"var(--text-dim)"},children:[c.length," rows, ",d.length," columns"]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,n.jsxs)("button",{onClick:()=>{rJ(e,r," "===t?"text/tab-separated-values;charset=utf-8":"text/csv;charset=utf-8")},style:{padding:"2px 8px",fontSize:11,cursor:"pointer",background:"var(--bg-hover)",color:"var(--text-muted)",border:"1px solid var(--border)",borderRadius:5},children:["Export "," "===t?"TSV":"CSV"]}),(0,n.jsx)("button",{onClick:()=>{rJ(JSON.stringify(u.map(e=>Object.fromEntries(d.map((t,r)=>[t||`column_${r+1}`,e[r]??""]))),null,2),r.replace(/\.[^.]+$/,"")+".json","application/json;charset=utf-8")},style:{padding:"2px 8px",fontSize:11,cursor:"pointer",background:"var(--bg-hover)",color:"var(--text-muted)",border:"1px solid var(--border)",borderRadius:5},children:"Export JSON"})]})]}),(0,n.jsx)("div",{style:{minHeight:0,flex:1,overflow:"auto",background:"var(--bg)"},children:(0,n.jsxs)("table",{style:{width:"100%",borderCollapse:"collapse",tableLayout:"fixed",fontSize:12},children:[(0,n.jsx)("thead",{style:{position:"sticky",top:0,zIndex:1,background:"var(--bg-panel)"},children:(0,n.jsx)("tr",{children:d.map((e,t)=>(0,n.jsx)("th",{onClick:()=>{i===t?a(e=>"asc"===e?"desc":"asc"):(l(t),a("asc"))},title:e,style:{padding:"8px 10px",borderBottom:"1px solid var(--border)",textAlign:"left",color:"var(--text-muted)",fontWeight:600,cursor:"pointer",userSelect:"none",fontSize:11,whiteSpace:"nowrap"},children:(0,n.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:6,minWidth:0},children:[(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis"},children:e||`column_${t+1}`}),i===t&&(0,n.jsx)("span",{style:{color:"var(--accent)",display:"inline-flex",flexShrink:0},children:(0,n.jsx)(rK,{dir:s})})]})},`${e}-${t}`))})}),(0,n.jsx)("tbody",{children:u.map((e,t)=>(0,n.jsx)("tr",{style:{borderBottom:"1px solid rgba(127,127,127,0.14)",background:t%2==1?"var(--bg-subtle)":"transparent"},children:d.map((r,o)=>(0,n.jsx)("td",{title:e[o]??"",style:{padding:"6px 10px",color:"var(--text)",fontFamily:"var(--font-mono)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:0},children:e[o]??""},`${r}-${t}-${o}`))},t))})]})})]})}let rY=new Set(["png","jpg","jpeg","gif","webp","svg","bmp","ico","avif"]),rG=new Set(["mp3","wav","ogg","oga","opus","m4a","aac","flac","weba","webm"]),rX=new Set(["pdf","docx","xlsx","pptx","doc","xls","ppt"]);function rQ(e){let t=ec(e).toLowerCase().split(".").pop()??"";return"csv"===t?",":"tsv"===t?" ":null}function r0(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function r1({oldContent:e,newContent:t}){let r=function(e,t){let r=e.length,n=t.length,o=r+n,i=Array(2*o+1).fill(0),l=[];for(let s=0;s<=o;s++){l.push([...i]);for(let a=-s;a<=s;a+=2){let d,c=(d=a===-s||a!==s&&i[a-1+o]<i[a+1+o]?i[a+1+o]:i[a-1+o]+1)-a;for(;d<r&&c<n&&e[d]===t[c];)d++,c++;if(i[a+o]=d,d>=r&&c>=n){let i=[],a=r,d=n;for(let r=s;r>0;r--){let n,s=l[r-1],c=a-d;n=c===-r||c!==r&&s[c-1+o]<s[c+1+o]?c+1:c-1;let u=s[n+o],p=u-n;for(;a>u&&d>p;)a--,d--,i.unshift({type:"unchanged",text:e[a],lineNo:a+1});r>0&&(a>u?(a--,i.unshift({type:"removed",text:e[a],lineNo:a+1})):(d--,i.unshift({type:"added",text:t[d],lineNo:d+1})))}for(;a>0&&d>0;)a--,d--,i.unshift({type:"unchanged",text:e[a],lineNo:a+1});return i}}}return[...e.map((e,t)=>({type:"removed",text:e,lineNo:t+1})),...t.map((e,t)=>({type:"added",text:e,lineNo:t+1}))]}(e.split("\n"),t.split("\n"));if(!r.some(e=>"unchanged"!==e.type))return(0,n.jsx)("div",{style:{padding:"12px 16px",fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:"No changes"});let o=new Set(r.flatMap((e,t)=>"unchanged"!==e.type?[t]:[])),i=new Set;for(let e of o)for(let t=Math.max(0,e-3);t<=Math.min(r.length-1,e+3);t++)i.add(t);let l=[],s=0;for(;s<r.length;)if(i.has(s)){let e=[];for(;s<r.length&&i.has(s);)e.push(r[s]),s++;l.push({hidden:!1,lines:e})}else{let e=0;for(;s<r.length&&!i.has(s);)e++,s++;l.push({hidden:!0,count:e})}let a=[],d=1;for(let e of r)"removed"===e.type?a.push(0):a.push(d++);let c=0;return(0,n.jsx)("div",{style:{fontFamily:"var(--font-mono)",fontSize:13,lineHeight:1.6},children:l.map((e,t)=>{if(e.hidden){let r=(0,n.jsxs)("div",{style:{padding:"2px 16px",color:"var(--text-dim)",background:"var(--bg-panel)",fontSize:11,borderTop:"1px solid var(--border)",borderBottom:"1px solid var(--border)"},children:["... ",e.count," unchanged lines ..."]},t);return c+=e.count,r}let r=e.lines.map((e,t)=>{let r=a[c+t],o="added"===e.type?"rgba(0,200,80,0.12)":"removed"===e.type?"rgba(240,60,60,0.14)":"transparent",i="added"===e.type?"+":"removed"===e.type?"-":" ",l="added"===e.type?"#4ade80":"removed"===e.type?"#f87171":"var(--text-dim)";return(0,n.jsxs)("div",{style:{display:"flex",background:o,borderLeft:"added"===e.type?"3px solid #4ade80":"removed"===e.type?"3px solid #f87171":"3px solid transparent"},children:[(0,n.jsx)("span",{style:{minWidth:44,padding:"0 8px 0 16px",textAlign:"right",color:"var(--text-dim)",userSelect:"none",fontSize:11,lineHeight:1.6,borderRight:"1px solid var(--border)",background:"var(--bg-panel)",flexShrink:0},children:"removed"===e.type?e.lineNo:r||""}),(0,n.jsx)("span",{style:{minWidth:16,padding:"0 6px",color:l,userSelect:"none",flexShrink:0,fontWeight:600},children:i}),(0,n.jsx)("span",{style:{flex:1,padding:"0 8px 0 0",whiteSpace:"pre",color:"var(--text)",overflowX:"auto"},children:e.text||"\xa0"})]},t)});return c+=e.lines.length,(0,n.jsx)("div",{children:r},t)})})}function r2({filePath:e,cwd:t}){let[r,i]=(0,o.useState)(!1),[l,s]=(0,o.useState)(0),[a,d]=(0,o.useState)(null),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(null),[x,g]=(0,o.useState)(100),f=(0,o.useRef)(null),m=ec(e).toLowerCase().split(".").pop()??"";(0,o.useEffect)(()=>{s(0),d(null),u(null),h(null),i(!1),g(100),f.current&&(f.current.close(),f.current=null);let t=ed(e),r=new EventSource(`/api/files/${t}?type=watch`);return f.current=r,r.addEventListener("connected",()=>i(!0)),r.addEventListener("change",e=>{try{let t=JSON.parse(e.data);"number"==typeof t.size&&d(t.size)}catch{}s(e=>e+1)}),r.addEventListener("error",()=>i(!1)),r.onerror=()=>i(!1),()=>{r.close(),f.current=null}},[e]);let v=ed(e),y=`/api/files/${v}?type=read${l?`&v=${l}`:""}`,b=null!=a?r0(a):null,j=e=>g(Math.max(10,Math.min(500,e)));return(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:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)"},title:e,children:eu(e,t)}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4,flexShrink:0},children:[(0,n.jsx)("button",{onClick:()=>j(x-25),title:"Zoom out",style:{width:24,height:22,border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:13,lineHeight:1},children:"-"}),(0,n.jsx)("select",{value:x,onChange:e=>j(Number(e.target.value)),title:"Image zoom",style:{height:22,border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:"var(--text)",fontSize:11,fontFamily:"var(--font-mono)",outline:"none",cursor:"pointer"},children:[25,50,75,100,125,150,200,300].map(e=>(0,n.jsxs)("option",{value:e,children:[e,"%"]},e))}),(0,n.jsx)("button",{onClick:()=>j(x+25),title:"Zoom in",style:{width:24,height:22,border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:13,lineHeight:1},children:"+"})]}),(0,n.jsx)("span",{style:{flexShrink:0},children:m||"image"}),c&&(0,n.jsxs)("span",{children:[c.w," \xd7 ",c.h]}),b&&(0,n.jsx)("span",{children:b}),(0,n.jsxs)("span",{title:r?"Live sync active":"Not watching",style:{display:"flex",alignItems:"center",gap:4,color:r?"#4ade80":"var(--text-dim)"},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:r?"#4ade80":"var(--border)",display:"inline-block",boxShadow:r?"0 0 4px #4ade80":"none"}}),r?"live":"static"]})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"auto",background:"var(--bg-panel)",WebkitOverflowScrolling:"touch",overscrollBehavior:"contain",backgroundImage:"linear-gradient(45deg, var(--bg) 25%, transparent 25%), linear-gradient(-45deg, var(--bg) 25%, transparent 25%), linear-gradient(45deg, transparent 75%, var(--bg) 75%), linear-gradient(-45deg, transparent 75%, var(--bg) 75%)",backgroundSize:"16px 16px",backgroundPosition:"0 0, 0 8px, 8px -8px, -8px 0px"},children:p?(0,n.jsx)("div",{style:{minWidth:"100%",minHeight:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#f87171",fontSize:13},children:p}):(0,n.jsx)("div",{style:{minWidth:"100%",minHeight:"100%",width:"max-content",height:"max-content",boxSizing:"border-box",display:"flex",alignItems:"flex-start",justifyContent:"flex-start",padding:16},children:(0,n.jsx)("img",{src:y,alt:e,onLoad:e=>{let t=e.currentTarget;u({w:t.naturalWidth,h:t.naturalHeight})},onError:()=>h("Failed to load image"),style:{width:c?Math.max(1,Math.round(c.w*x/100)):"auto",height:c?Math.max(1,Math.round(c.h*x/100)):"auto",maxWidth:"none",maxHeight:"none",objectFit:"contain",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"}})})})]})}function r4({filePath:e,cwd:t}){let[r,i]=(0,o.useState)(!1),[l,s]=(0,o.useState)(0),[a,d]=(0,o.useState)(null),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(null),x=(0,o.useRef)(null),g=ec(e).toLowerCase().split(".").pop()??"";(0,o.useEffect)(()=>{s(0),d(null),u(null),h(null),i(!1),x.current&&(x.current.close(),x.current=null);let t=ed(e),r=new EventSource(`/api/files/${t}?type=watch`);return x.current=r,r.addEventListener("connected",()=>i(!0)),r.addEventListener("change",e=>{try{let t=JSON.parse(e.data);"number"==typeof t.size&&d(t.size)}catch{}u(null),h(null),s(e=>e+1)}),r.addEventListener("error",()=>i(!1)),r.onerror=()=>i(!1),()=>{r.close(),x.current=null}},[e]);let f=ed(e),m=`/api/files/${f}?type=read${l?`&v=${l}`:""}`;return(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)"},title:e,children:eu(e,t)}),(0,n.jsx)("span",{style:{marginLeft:"auto"},children:g||"audio"}),null!=c&&(0,n.jsx)("span",{children:function(e){if(!Number.isFinite(e))return"";let t=Math.round(e),r=Math.floor(t/60);return`${r}:${String(t%60).padStart(2,"0")}`}(c)}),null!=a&&(0,n.jsx)("span",{children:r0(a)}),(0,n.jsxs)("span",{title:r?"Live sync active":"Not watching",style:{display:"flex",alignItems:"center",gap:4,color:r?"#4ade80":"var(--text-dim)"},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:r?"#4ade80":"var(--border)",display:"inline-block",boxShadow:r?"0 0 4px #4ade80":"none"}}),r?"live":"static"]})]}),(0,n.jsx)("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",padding:24,background:"var(--bg-panel)"},children:(0,n.jsxs)("div",{style:{width:"min(680px, 100%)"},children:[p&&(0,n.jsx)("div",{style:{color:"#f87171",fontSize:13,marginBottom:12,textAlign:"center"},children:p}),(0,n.jsx)("audio",{controls:!0,preload:"metadata",src:m,onLoadedMetadata:e=>u(e.currentTarget.duration),onError:()=>h("Failed to load audio"),style:{width:"100%"}},m)]})})]})}function r5({filePath:e,cwd:t,onOpenFile:r}){let o,i,l;return(o=ec(e).toLowerCase().split(".").pop()??"",rY.has(o))?(0,n.jsx)(r2,{filePath:e,cwd:t}):(i=ec(e).toLowerCase().split(".").pop()??"",rG.has(i))?(0,n.jsx)(r4,{filePath:e,cwd:t}):(l=ec(e).toLowerCase().split(".").pop()??"",rX.has(l))?(0,n.jsx)(r6,{filePath:e,cwd:t}):(0,n.jsx)(r3,{filePath:e,cwd:t,onOpenFile:r})}function r6({filePath:e,cwd:t}){let r,[i,l]=(0,o.useState)(null),[s,a]=(0,o.useState)(!0),[d,c]=(0,o.useState)(null),u=(0,o.useRef)(null),p=(0,o.useRef)(0),h="pdf"===(r=ec(e).toLowerCase().split(".").pop()??"")?"pdf":"docx"===r||"doc"===r?"docx":"xlsx"===r||"xls"===r?"xlsx":"pptx"===r||"ppt"===r?"pptx":"other",x=ec(e).toLowerCase().split(".").pop()??"",g=(0,o.useCallback)(async e=>{try{let t=ed(e),r=p.current?`&v=${p.current}`:"",n=await fetch(`/api/files/${t}?type=read${r}`);if(!n.ok){let e=await n.json().catch(()=>({error:String(n.status)}));c(e.error??`HTTP ${n.status}`);return}let o=await n.arrayBuffer();l(o),c(null)}catch(e){c(String(e))}},[]);if((0,o.useEffect)(()=>{a(!0),c(null),l(null),p.current=0,u.current&&(u.current.close(),u.current=null),g(e).finally(()=>a(!1));let t=ed(e),r=new EventSource(`/api/files/${t}?type=watch`);return u.current=r,r.addEventListener("connected",()=>{}),r.addEventListener("change",()=>{p.current+=1,g(e)}),r.addEventListener("error",()=>{}),r.onerror=()=>{},()=>{r.close(),u.current=null}},[e,g]),s&&!i)return(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:"Loading..."});if(d&&!i)return(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#f87171",fontSize:13},children:d});if(!i)return null;let f=eu(e,t);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:["pdf"===h&&(0,n.jsx)(rk,{arrayBuffer:i,fileName:f}),"docx"===h&&(0,n.jsx)(rS,{arrayBuffer:i,fileName:f}),"xlsx"===h&&(0,n.jsx)(rC,{arrayBuffer:i,fileName:f}),"pptx"===h&&(0,n.jsx)(rz,{arrayBuffer:i,fileName:f}),"other"===h&&(0,n.jsxs)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:["Unsupported document format: .",x]})]})}function r3({filePath:e,cwd:t,onOpenFile:r}){let{isDark:i}=$(),[l,s]=(0,o.useState)(null),[a,d]=(0,o.useState)(null),[c,u]=(0,o.useState)(!0),[p,h]=(0,o.useState)(null),[x,g]=(0,o.useState)(null),[f,m]=(0,o.useState)(!1),[v,y]=(0,o.useState)("source"),[b,j]=(0,o.useState)(!1),[k,w]=(0,o.useState)(!1),[S,C]=(0,o.useState)(0),[z,T]=(0,o.useState)(!1),[I,L]=(0,o.useState)(""),[R,W]=(0,o.useState)(!1),[E,A]=(0,o.useState)(!1),[B,N]=(0,o.useState)(!1),[P,D]=(0,o.useState)(null),O=(0,o.useRef)(null),H=(0,o.useRef)(!1);H.current=z,(0,o.useRef)(null).current=l;let F=(0,o.useCallback)((e,t=!1)=>{let r=ed(e);return fetch(`/api/files/${r}?type=read`).then(e=>e.json()).then(e=>e.error?(h(e.error),null):(t?(s(t=>(t&&d(t.content),e)),C(e=>e+1)):s(e),h(null),e)).catch(e=>(h(String(e)),null))},[]);(0,o.useEffect)(()=>{u(!0),h(null),s(null),d(null),m(!1),y("source"),j(!1),C(0),w(!1),O.current&&(O.current.close(),O.current=null),F(e).then(t=>{(t?.language==="markdown"||rQ(e))&&m(!0)}).finally(()=>u(!1));let t=ed(e),r=new EventSource(`/api/files/${t}?type=watch`);return O.current=r,r.addEventListener("connected",()=>{w(!0)}),r.addEventListener("change",()=>{H.current?A(!0):F(e,!0)}),r.addEventListener("error",()=>{w(!1)}),r.onerror=()=>{w(!1)},()=>{r.close(),O.current=null}},[e,F]);let _=(0,o.useCallback)(()=>{l&&(T(!0),L(l.content),D(l.mtime??null),N(!1),g(null),A(!1),m(!1),y("source"))},[l]),U=(0,o.useCallback)(async(t=!1)=>{let r=ed(e);W(!0),N(!1),g(null);try{let n=await fetch(`/api/files/${r}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:I,...t||!P?{}:{baseMtime:P}})});if(409===n.status){let e=await n.json().catch(()=>({error:"File changed on disk since it was opened"}));throw N(!0),A(!0),Error(e.error??"File changed on disk since it was opened")}if(!n.ok){let e=await n.json().catch(()=>({error:String(n.status)}));throw Error(e.error??`HTTP ${n.status}`)}let o=await F(e,!0);D(o?.mtime??null),T(!1),A(!1),N(!1)}catch(e){g(e instanceof Error?e.message:String(e))}finally{W(!1)}},[e,I,P,F]),V=(0,o.useCallback)(()=>{T(!1),A(!1),N(!1),g(null),D(null)},[]),q=(0,o.useCallback)(async()=>{let t=await F(e,!0);t&&(L(t.content),D(t.mtime??null),A(!1),N(!1),g(null),h(null))},[F,e]);if(c)return(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:"Loading..."});if(p)return(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#f87171",fontSize:13},children:p});if(!l)return null;let K="html"===l.language,J="markdown"===l.language,Z=rQ(e),Y=null!==Z,G=l.content.split("\n"),X=null!==a&&a!==l.content;return(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)"},title:e,children:eu(e,t)}),(0,n.jsx)("span",{style:{marginLeft:"auto"},children:l.language}),"source"===v&&(0,n.jsxs)("span",{children:[G.length," lines"]}),(0,n.jsx)("span",{children:r0(l.size)}),(0,n.jsxs)("span",{title:k?"Live sync active":"Not watching",style:{display:"flex",alignItems:"center",gap:4,color:k?"#4ade80":"var(--text-dim)"},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:k?"#4ade80":"var(--border)",display:"inline-block",boxShadow:k?"0 0 4px #4ade80":"none"}}),k?"live":"static"]}),z?(0,n.jsxs)(n.Fragment,{children:[(E||B||x)&&(0,n.jsxs)("span",{title:"File changed on disk while editing",style:{padding:"2px 8px",fontSize:11,background:"rgba(234,179,8,0.1)",color:"#b8860b",border:"1px solid rgba(234,179,8,0.3)",borderRadius:5,display:"flex",alignItems:"center",gap:4},children:[(0,n.jsxs)("svg",{width:"10",height:"10",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:"10"}),(0,n.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,n.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),x??"External change",(E||B)&&(0,n.jsx)("button",{onClick:q,style:{marginLeft:4,padding:"1px 6px",fontSize:10,cursor:"pointer",background:"rgba(234,179,8,0.2)",color:"#b8860b",border:"1px solid rgba(234,179,8,0.3)",borderRadius:3,fontWeight:600},children:"Reload"}),B&&(0,n.jsx)("button",{onClick:()=>void U(!0),disabled:R,style:{marginLeft:4,padding:"1px 6px",fontSize:10,cursor:R?"not-allowed":"pointer",background:"rgba(239,68,68,0.12)",color:"#ef4444",border:"1px solid rgba(239,68,68,0.3)",borderRadius:3,fontWeight:600},children:"Overwrite"})]}),(0,n.jsx)("button",{onClick:()=>void U(),disabled:R,title:"Save file (Ctrl+S)",style:{padding:"2px 10px",fontSize:11,cursor:R?"not-allowed":"pointer",background:"var(--accent)",color:"#fff",border:"1px solid var(--accent)",borderRadius:5,fontWeight:600,opacity:R?.6:1},children:R?"Saving…":"Save"}),(0,n.jsx)("button",{onClick:V,title:"Cancel editing",style:{padding:"2px 10px",fontSize:11,cursor:"pointer",background:"var(--bg-hover)",color:"var(--text-muted)",border:"1px solid var(--border)",borderRadius:5,fontWeight:600},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.1)",e.currentTarget.style.color="#ef4444",e.currentTarget.style.borderColor="rgba(239,68,68,0.3)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:"Cancel"})]}):(0,n.jsx)("button",{onClick:_,title:"Edit file",style:{padding:"2px 10px",fontSize:11,cursor:"pointer",background:"var(--bg-hover)",color:"var(--text-muted)",border:"1px solid var(--border)",borderRadius:5,fontWeight:600},onMouseEnter:e=>{e.currentTarget.style.background="var(--accent)",e.currentTarget.style.color="#fff",e.currentTarget.style.borderColor="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:"Edit"}),X&&(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,overflow:"hidden",border:"1px solid var(--border)"},children:[(0,n.jsx)("button",{onClick:()=>y("source"),style:{padding:"2px 8px",fontSize:11,border:"none",cursor:"pointer",background:"source"===v?"var(--bg-selected)":"var(--bg-hover)",color:"source"===v?"var(--text)":"var(--text-muted)",fontWeight:"source"===v?600:400},children:"Source"}),(0,n.jsxs)("button",{onClick:()=>y("diff"),style:{padding:"2px 8px",fontSize:11,border:"none",borderLeft:"1px solid var(--border)",cursor:"pointer",background:"diff"===v?"var(--bg-selected)":"var(--bg-hover)",color:"diff"===v?"var(--text)":"var(--text-muted)",fontWeight:"diff"===v?600:400},children:["Diff ",S>0&&(0,n.jsxs)("span",{style:{color:"#4ade80",marginLeft:2},children:["+",S]})]})]}),"source"===v&&!f&&(0,n.jsx)("button",{onClick:()=>j(e=>!e),title:b?"Disable word wrap":"Enable word wrap",style:{padding:"2px 8px",fontSize:11,cursor:"pointer",background:b?"var(--bg-selected)":"var(--bg-hover)",color:b?"var(--text)":"var(--text-muted)",border:"1px solid var(--border)",borderRadius:5,fontWeight:b?600:400},children:"wrap"}),K&&"source"===v&&(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,overflow:"hidden",border:"1px solid var(--border)"},children:[(0,n.jsx)("button",{onClick:()=>m(!1),style:{padding:"2px 8px",fontSize:11,border:"none",cursor:"pointer",background:f?"var(--bg-hover)":"var(--bg-selected)",color:f?"var(--text-muted)":"var(--text)",fontWeight:f?400:600},children:"Code"}),(0,n.jsx)("button",{onClick:()=>m(!0),style:{padding:"2px 8px",fontSize:11,border:"none",borderLeft:"1px solid var(--border)",cursor:"pointer",background:f?"var(--bg-selected)":"var(--bg-hover)",color:f?"var(--text)":"var(--text-muted)",fontWeight:f?600:400},children:"Preview"})]}),J&&"source"===v&&(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,overflow:"hidden",border:"1px solid var(--border)"},children:[(0,n.jsx)("button",{onClick:()=>m(!0),style:{padding:"2px 8px",fontSize:11,border:"none",cursor:"pointer",background:f?"var(--bg-selected)":"var(--bg-hover)",color:f?"var(--text)":"var(--text-muted)",fontWeight:f?600:400},children:"Preview"}),(0,n.jsx)("button",{onClick:()=>m(!1),style:{padding:"2px 8px",fontSize:11,border:"none",borderLeft:"1px solid var(--border)",cursor:"pointer",background:f?"var(--bg-hover)":"var(--bg-selected)",color:f?"var(--text-muted)":"var(--text)",fontWeight:f?400:600},children:z?"Edit":"Raw"})]}),Y&&"source"===v&&(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,overflow:"hidden",border:"1px solid var(--border)"},children:[(0,n.jsx)("button",{onClick:()=>m(!0),style:{padding:"2px 8px",fontSize:11,border:"none",cursor:"pointer",background:f?"var(--bg-selected)":"var(--bg-hover)",color:f?"var(--text)":"var(--text-muted)",fontWeight:f?600:400},children:"Table"}),(0,n.jsx)("button",{onClick:()=>m(!1),style:{padding:"2px 8px",fontSize:11,border:"none",borderLeft:"1px solid var(--border)",cursor:"pointer",background:f?"var(--bg-hover)":"var(--bg-selected)",color:f?"var(--text-muted)":"var(--text)",fontWeight:f?400:600},children:"Raw"})]})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"auto",background:"var(--bg)"},children:z&&!(J&&f)?(0,n.jsx)(rq,{initialContent:I,language:l.language,isDark:i,onChange:L,onSave:()=>void U()}):z&&J&&f?(0,n.jsx)(em,{content:I,className:"markdown-body markdown-file-preview",codeBlockVariant:"file",baseFilePath:e,onOpenLocalFile:r,style:{padding:"28px 36px",maxWidth:920,margin:"0 auto"}}):"diff"===v&&X?(0,n.jsx)(r1,{oldContent:a,newContent:l.content,language:l.language}):K&&f?(0,n.jsx)("iframe",{srcDoc:l.content,sandbox:"allow-scripts",style:{width:"100%",height:"100%",border:"none",background:"var(--bg)"},title:"HTML preview"}):J&&f?(0,n.jsx)(em,{content:l.content,className:"markdown-body markdown-file-preview",codeBlockVariant:"file",baseFilePath:e,onOpenLocalFile:r,style:{padding:"28px 36px",maxWidth:920,margin:"0 auto"}}):Y&&f&&Z?(0,n.jsx)(rZ,{content:l.content,delimiter:Z,fileName:ec(e)}):(0,n.jsx)(M.A,{language:"text"===l.language||"csv"===l.language||"tsv"===l.language?"plaintext":l.language,style:es(i),showLineNumbers:!0,lineNumberStyle:{color:"var(--text-dim)",fontStyle:"normal",minWidth:"3em",paddingRight:"1em"},customStyle:{margin:0,padding:"12px 0",background:"var(--bg)",fontSize:13,lineHeight:1.6,fontFamily:"var(--font-mono)",minHeight:"100%"},codeTagProps:{style:{fontFamily:"var(--font-mono)"}},wrapLongLines:b,children:l.content})})]})}function r8(e,t,r){return Math.min(Math.max(e,t),r)}function r7({src:e,alt:t}){return(0,n.jsx)("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",background:"var(--bg)",overflow:"auto",padding:12},children:(0,n.jsx)("img",{src:e,alt:t,style:{display:"block",maxWidth:"100%",maxHeight:"100%",objectFit:"contain",margin:"auto",boxShadow:"0 10px 30px rgba(0,0,0,0.22)"}})})}function r9({id:e,filePath:t,fileName:r,cwd:i,galleryItems:l,galleryIndex:s=0,active:a,stackIndex:d,zIndex:c,onClose:u,onFocus:p,onOpenFile:h,onOpenImage:x}){let[g,f]=(0,o.useState)(()=>{let e,t,r,n,o,i,l;return e=window.innerWidth,t=window.innerHeight,n=(r=e<720||t<560)?8:36,i=Math.max(320,e-2*n-(o=r?0:d%6*28)),l=Math.max(260,t-2*n-o),{left:n+o,top:n+o,width:r?i:Math.min(1180,i),height:r?l:Math.min(820,l),maximized:!1}}),[m,v]=(0,o.useState)(!1),[y,b]=(0,o.useState)(!1),j=(0,o.useRef)(null),k=(0,o.useRef)(null),w=(0,o.useRef)(null),S=!!x&&!!l&&l.length>1,C=/^data:image\//i.test(t)||/^(https?:)?\/\//i.test(t),z=S?l[(s-1+l.length)%l.length]:null,T=S?l[(s+1)%l.length]:null,I=(0,o.useCallback)(e=>{if(!S||!x||!l)return;let t=e<0?(s-1+l.length)%l.length:(s+1)%l.length,r=l[t];r&&x(r.src,r.title,l)},[S,s,l,x]);(0,o.useEffect)(()=>{a&&j.current?.focus({preventScroll:!0})},[a]),(0,o.useEffect)(()=>{let e=()=>{f(e=>{if(e.maximized)return e;let t=Math.max(320,window.innerWidth-16),r=Math.max(260,window.innerHeight-16),n=Math.min(e.width,t),o=Math.min(e.height,r);return{...e,width:n,height:o,left:r8(e.left,8,Math.max(8,window.innerWidth-n-8)),top:r8(e.top,8,Math.max(8,window.innerHeight-o-8))}})};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]);let M=(0,o.useCallback)(t=>{p(e),0!==t.button||g.maximized||(t.preventDefault(),t.currentTarget.setPointerCapture(t.pointerId),k.current={pointerId:t.pointerId,startX:t.clientX,startY:t.clientY,left:g.left,top:g.top},v(!0))},[g.left,g.maximized,g.top,e,p]),L=(0,o.useCallback)(e=>{let t=k.current;if(!t||t.pointerId!==e.pointerId)return;let r=t.left+e.clientX-t.startX,n=t.top+e.clientY-t.startY;f(e=>({...e,left:r8(r,8,Math.max(8,window.innerWidth-120)),top:r8(n,8,Math.max(8,window.innerHeight-48))}))},[]),R=(0,o.useCallback)(e=>{let t=k.current;t?.pointerId===e.pointerId&&(e.currentTarget.releasePointerCapture(e.pointerId),k.current=null,v(!1))},[]),W=(0,o.useCallback)(()=>{p(e),f(e=>({...e,maximized:!e.maximized}))},[e,p]),E=(0,o.useCallback)(t=>{p(e),0!==t.button||g.maximized||(t.preventDefault(),t.stopPropagation(),t.currentTarget.setPointerCapture(t.pointerId),w.current={pointerId:t.pointerId,startX:t.clientX,startY:t.clientY,width:g.width,height:g.height},b(!0))},[g.height,g.maximized,g.width,e,p]),$=(0,o.useCallback)(e=>{let t=w.current;if(!t||t.pointerId!==e.pointerId)return;let r=t.width+e.clientX-t.startX,n=t.height+e.clientY-t.startY;f(e=>({...e,width:r8(r,360,Math.max(360,window.innerWidth-e.left-8)),height:r8(n,280,Math.max(280,window.innerHeight-e.top-8))}))},[]),A=(0,o.useCallback)(e=>{let t=w.current;t?.pointerId===e.pointerId&&(e.currentTarget.releasePointerCapture(e.pointerId),w.current=null,b(!1))},[]),B=g.maximized?{position:"fixed",inset:12,zIndex:c}:{position:"fixed",left:g.left,top:g.top,width:g.width,height:g.height,zIndex:c};return(0,n.jsxs)("div",{ref:j,role:"dialog","aria-label":`Preview ${r}`,tabIndex:-1,onPointerDown:()=>p(e),onKeyDown:t=>{"Escape"===t.key&&u(e),"ArrowLeft"===t.key&&(t.preventDefault(),I(-1)),"ArrowRight"===t.key&&(t.preventDefault(),I(1))},style:{...B,display:"flex",flexDirection:"column",minWidth:g.maximized?void 0:360,minHeight:g.maximized?void 0:280,background:"var(--bg)",border:a?"1px solid rgba(37,99,235,0.55)":"1px solid var(--border)",borderRadius:8,boxShadow:a?"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:M,onPointerMove:L,onPointerUp:R,onPointerCancel:R,style:{height:34,display:"flex",alignItems:"center",gap:8,padding:"0 8px 0 12px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",cursor:g.maximized?"default":m?"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})}),S&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4,flexShrink:0},children:[(0,n.jsx)("button",{type:"button",onPointerDown:e=>e.stopPropagation(),onClick:()=>I(-1),title:z?.title?`Previous: ${z.title}`:"Previous image","aria-label":"Previous image",style:ne,children:(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,n.jsx)("polyline",{points:"10 3 5 8 10 13"})})}),(0,n.jsxs)("span",{style:{minWidth:40,textAlign:"center",fontSize:11,color:"var(--text-dim)",fontVariantNumeric:"tabular-nums"},children:[s+1,"/",l?.length]}),(0,n.jsx)("button",{type:"button",onPointerDown:e=>e.stopPropagation(),onClick:()=>I(1),title:T?.title?`Next: ${T.title}`:"Next image","aria-label":"Next image",style:ne,children:(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,n.jsx)("polyline",{points:"6 3 11 8 6 13"})})})]}),(0,n.jsx)("button",{type:"button",onPointerDown:e=>e.stopPropagation(),onClick:W,title:g.maximized?"Restore preview":"Maximize preview","aria-label":g.maximized?"Restore preview":"Maximize preview",style:ne,children:g.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:()=>u(e),title:"Close preview","aria-label":"Close preview",style:ne,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:C?(0,n.jsx)(r7,{src:t,alt:r}):(0,n.jsx)(r5,{filePath:t,cwd:i,onOpenFile:h})}),!g.maximized&&(0,n.jsx)("div",{role:"separator","aria-orientation":"horizontal","aria-label":"Resize preview",title:"Resize preview",onPointerDown:E,onPointerMove:$,onPointerUp:A,onPointerCancel:A,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 ne={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},nt={__soul__:{apiPath:"/api/soul",title:"SOUL.md"},__harness__:{apiPath:"/api/harness",title:"HARNESS.md"}};function nr({filePath:e}){let t=nt[e],{isDark:r}=$(),[i,l]=(0,o.useState)(""),[s,a]=(0,o.useState)(!0),[d,c]=(0,o.useState)(null),[u,p]=(0,o.useState)(!1),[h,x]=(0,o.useState)(!1);(0,o.useEffect)(()=>{t&&(a(!0),fetch(t.apiPath).then(e=>e.json()).then(e=>l(e.content??"")).catch(e=>c(String(e))).finally(()=>a(!1)))},[t]);let g=(0,o.useCallback)(async()=>{if(t){p(!0);try{await fetch(t.apiPath,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:i})}),x(!0),setTimeout(()=>x(!1),2e3)}catch(e){c(String(e))}finally{p(!1)}}},[t,i]);return t?s?(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:"Loading…"}):d?(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#f87171",fontSize:13},children:d}):(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"4px 16px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",background:"var(--bg)",flexShrink:0},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontWeight:600,color:"var(--text)"},children:t.title}),(0,n.jsx)("span",{style:{marginLeft:"auto",fontSize:10,color:"var(--text-dim)"},children:"Global"}),h&&(0,n.jsx)("span",{style:{color:"#4ade80",fontWeight:600,animation:"saved-pop 0.3s ease"},children:"✓ Saved"}),(0,n.jsx)("button",{onClick:g,disabled:u,title:"Save (Ctrl+S)",style:{padding:"2px 10px",fontSize:11,cursor:u?"not-allowed":"pointer",background:"var(--accent)",color:"#fff",border:"1px solid var(--accent)",borderRadius:5,fontWeight:600,opacity:u?.6:1},children:u?"Saving…":"Save"})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"hidden"},children:(0,n.jsx)(rq,{initialContent:i,language:"markdown",isDark:r,onChange:l,onSave:g})})]}):null}function nn(){document.body.style.cursor="",document.body.style.userSelect=""}function no({side:e,onResize:t,onResizeStart:r,onResizeEnd:i,ariaLabel:l}){let s=(0,o.useRef)(null),a=(0,o.useRef)(!1),d=(0,o.useRef)(0),[c,u]=(0,o.useState)(!1),p=(0,o.useCallback)(e=>{if(!a.current)return;a.current=!1,u(!1);let t=s.current;t&&void 0!==e&&t.hasPointerCapture(e)&&t.releasePointerCapture(e),nn(),i?.()},[i]),h=(0,o.useCallback)(e=>{0===e.button&&e.isPrimary&&(e.preventDefault(),a.current=!0,d.current=e.clientX,u(!0),r?.(),e.currentTarget.setPointerCapture(e.pointerId),document.body.style.cursor="col-resize",document.body.style.userSelect="none")},[r]),x=(0,o.useCallback)(e=>{if(!a.current)return;e.preventDefault();let r=e.clientX-d.current;d.current=e.clientX,t(r)},[t]),g=(0,o.useCallback)(e=>{e.preventDefault(),p(e.pointerId)},[p]),f=(0,o.useCallback)(e=>{p(e.pointerId)},[p]);return(0,o.useEffect)(()=>()=>{a.current&&(a.current=!1,nn(),i?.())},[i]),(0,n.jsx)("div",{ref:s,role:"separator","aria-label":l??"Resize panel","aria-orientation":"vertical",className:`resize-handle${c?" resize-handle-dragging":""}`,"data-side":e,onPointerDown:h,onPointerMove:x,onPointerUp:g,onPointerCancel:f,style:{alignSelf:"stretch",cursor:"col-resize",display:"flex",flexShrink:0,justifyContent:"center",marginLeft:-5,marginRight:-5,position:"relative",touchAction:"none",width:10,zIndex:250},children:(0,n.jsx)("div",{className:"resize-handle-line"})})}function ni({tabs:e,activeTabId:t,onSelectTab:r,onCloseTab:i}){let[l,s]=(0,o.useState)(null);return(0,n.jsx)("div",{style:{display:"flex",alignItems:"flex-end",background:"var(--bg-panel)",overflowX:"auto",flexShrink:0,height:36},children:e.map(e=>{let o=e.id===t,a=!1!==e.closable;return(0,n.jsxs)("div",{onClick:()=>r(e.id),style:{display:"flex",alignItems:"center",gap:6,height:36,paddingLeft:12,paddingRight:6,borderRight:"1px solid var(--border)",background:o?"var(--bg)":"var(--bg-panel)",cursor:"pointer",fontSize:12,color:o?"var(--text)":"var(--text-muted)",whiteSpace:"nowrap",maxWidth:180,minWidth:80,flexShrink:0,userSelect:"none",transition:"background 0.1s, color 0.1s"},children:[(0,n.jsx)("span",{style:{flexShrink:0,opacity:o?1:.7,display:"flex",alignItems:"center"},children:"files"===e.icon?(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 6a2 2 0 0 1 2-2h5l2 2h7a2 2 0 0 1 2 2v3"}),(0,n.jsx)("path",{d:"M3 6v12a2 2 0 0 0 2 2h8"}),(0,n.jsx)("path",{d:"M17 13v7"}),(0,n.jsx)("path",{d:"M14 16h6"}),(0,n.jsx)("path",{d:"M14 20h6"})]}):"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.1a5 5 0 0 1-6.6 6.6L7.3 19.7a2.1 2.1 0 0 1-3-3l6.9-6.9a5 5 0 0 1 6.6-6.6l-3.1 3.1Z"})}):rc(e.filePath??e.label,13)}),(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",flex:1,fontWeight:o?500:400},title:e.filePath??e.label,children:e.label}),a&&(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),i(e.id)},onMouseEnter:()=>s(e.id),onMouseLeave:()=>s(null),style:{display:"flex",alignItems:"center",justifyContent:"center",width:16,height:16,background:l===e.id?"var(--bg-hover)":"transparent",border:"none",borderRadius:3,color:l===e.id?"var(--text)":"var(--text-dim)",cursor:"pointer",padding:0,flexShrink:0,transition:"background 0.1s, color 0.1s"},title:"Close",children:(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"2",y1:"2",x2:"8",y2:"8"}),(0,n.jsx)("line",{x1:"8",y1:"2",x2:"2",y2:"8"})]})})]},e.id)})})}function nl(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 ns(e){if(!e||!Number.isFinite(e))return"-";let t=Math.max(0,Math.floor(e/1e3)),r=Math.floor(t/3600),n=Math.floor(t%3600/60),o=t%60;return r>0?`${r}h ${n}m`:n>0?`${n}m ${o}s`:`${o}s`}function na(e){return e?ec(e)||e:"-"}function nd({refreshKey:e=0,cwd:t}){let[r,i]=(0,o.useState)(null),[l,s]=(0,o.useState)(null),[a,d]=(0,o.useState)(null),c=(0,o.useCallback)(async()=>{try{let e=await fetch("/api/agent/runtime",{cache:"no-store"}),t=await e.json();if(!e.ok||!Array.isArray(t.sessions))throw Error(t.error??`HTTP ${e.status}`);i(t),s(null)}catch(e){s(e instanceof Error?e.message:String(e))}},[]);(0,o.useEffect)(()=>{c()},[c,e]),(0,o.useEffect)(()=>{let e=window.setInterval(()=>{c()},3e3);return()=>window.clearInterval(e)},[c]);let u=(0,o.useCallback)(async e=>{d(e.sessionId),s(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 c()}catch(e){s(e instanceof Error?e.message:String(e))}finally{d(null)}},[c]),p=(0,o.useMemo)(()=>[...r?.sessions??[]].sort((e,t)=>{let r=+!!e.busy,n=+!!t.busy;return r!==n?n-r:Date.parse(t.lastEventAt??t.runStartedAt??"0")-Date.parse(e.lastEventAt??e.runStartedAt??"0")}),[r]),h=p.filter(e=>e.busy),x=h.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",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Tools"}),(0,n.jsxs)("div",{style:{marginTop:3,fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[h.length," agent running \xb7 ",r?.activeSessions??0," active",t?` \xb7 ${na(t)}`:""]})]}),(0,n.jsx)("button",{type:"button",onClick:()=>void c(),style:nh,title:"Refresh runtime",children:"Refresh"})]}),l&&(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:l})]}),(0,n.jsxs)("div",{style:{flex:1,overflow:"auto",padding:10},children:[(0,n.jsx)(nc,{title:"Agent Runtime",subtitle:x.length>0?`${x.length} waiting for first token`:`${h.length} active chat${1===h.length?"":"s"}`}),0===p.length?(0,n.jsx)(nu,{label:"No agent runtime is active."}):(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:p.map(e=>{var t;let r=e.model?`${e.model.provider}/${e.model.id}`:"-",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:nl(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:nl(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:[na(e.cwd)," \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)(np,{label:"uptime",value:ns(e.uptimeMs)}),(0,n.jsx)(np,{label:"wait",value:ns(e.waitingForModelMs),color:"waiting_model"===e.phase?nl(e.phase):void 0}),(0,n.jsx)(np,{label:"pending",value:null===e.pendingMessageCount?"-":String(e.pendingMessageCount)}),(0,n.jsx)(np,{label:"event",value:e.lastEventType??"-"}),(0,n.jsx)(np,{label:"tools",value:o||"-"}),(0,n.jsx)(np,{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. This usually means the upstream provider or gateway is still queueing the turn."}),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 u(e),disabled:!e.busy||a===e.sessionId,style:{...nh,border:"1px solid rgba(239,68,68,0.35)",color:"#ef4444",background:"rgba(239,68,68,0.08)",opacity:e.busy&&a!==e.sessionId?1:.55},children:"Abort"})})]},e.sessionId)})})]})]})}function nc({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 nu({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 np({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})]})}let nh={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},nx=["openai-responses","openai-completions"],ng=[/\/chat\/completions(?:$|[?#])/i,/deepseek/i,/moonshot|kimi/i,/dashscope|aliyun|qwen/i,/zhipu|bigmodel|chatglm|glm/i,/siliconflow/i,/volcengine|ark\.cn|doubao/i,/baichuan/i,/minimax/i,/stepfun|step-api/i,/lingyiwanwu|yi-api/i],nf=[/api\.openai\.com/i,/\/responses(?:$|[?#])/i];function nm(e,t,r="openai-responses"){let n=`${t??""} ${e??""}`.toLowerCase();return n.trim()?nf.some(e=>e.test(n))?"openai-responses":ng.some(e=>e.test(n))?"openai-completions":r:r}function nv(e,t="0 0 24 24"){let r=({size:r=24,style:o})=>(0,n.jsx)("svg",{width:r,height:r,viewBox:t,fill:"none",style:o,children:e});return r.displayName="ProviderIcon",r}let ny=nv((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"})),nb=nv((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"})),nj=nv((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"})]})),nk=nv((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"})]})),nw=nv((0,n.jsx)("path",{d:"M4 4h16v16H4z",fill:"#F55036"}),"0 0 24 24"),nS=nv((0,n.jsx)("path",{d:"M4 4h5v5H4zm5.5 0h5v5h-5zM15 4h5v5h-5zM4 9.5h5v5H4zm5.5 5.5h5v5h-5zM15 9.5h5v5h-5z",fill:"#FA6F00"})),nC=nv((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),"0 0 24 24"),nz=nv((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"})]})),nT=nv((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",fill:"#FF5722"}),"0 0 24 24"),nI=nv((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"})),nM=nv((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"})]})),nL=nv((0,n.jsx)("path",{d:"M12 2l9 5v10l-9 5-9-5V7l9-5z",stroke:"currentColor",strokeWidth:"1.5",fill:"none"})),nR=nv((0,n.jsx)("path",{d:"M4 4l8 8 8-8M4 20l8-8 8 8",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})),nW=nv((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"})),nE=nv((0,n.jsx)("path",{d:"M12 2L22 20H2L12 2z",fill:"currentColor"})),n$=nv((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),"0 0 24 24"),nA=nv((0,n.jsx)("path",{d:"M3 15h2l1-3h2l1 3h2V9H9v3L8 9H6l-1 3V9H3v6zm9 0h2v-2h2v-2h-2V9h-2v2h-2v2h2v2z",fill:"#FF9900"})),nB=nv((0,n.jsx)("path",{d:"M12 2L3 18h5l4-6 4 6h5L12 2z",fill:"#0078D4"})),nN=nv((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"})]})),nP=nv((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"})]})),nD=nv((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"})]})),nO=nv((0,n.jsx)("path",{d:"M4 8h16v2H4zm0 4h12v2H4zm0 4h8v2H4z",fill:"#3059B1"})),nH=nv((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"})),nF=nv((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",fill:"#0F6CBD"}),"0 0 24 24"),n_=nv((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),"0 0 24 24"),nU=[{id:"deepseek",displayName:"DeepSeek",baseUrl:"https://api.deepseek.com",api:"openai-completions",description:"Affordable, great for everyday coding and analysis tasks.",models:[{id:"deepseek-chat",contextWindow:1048576,maxTokens:8192},{id:"deepseek-reasoner",reasoning:!0,contextWindow:1048576,maxTokens:8192}]},{id:"moonshotai",displayName:"Moonshot AI",baseUrl:"https://api.moonshot.cn/v1",api:"openai-completions",description:"Kimi series — strong Chinese-language and long-context performance.",models:[{id:"moonshot-v1-auto",contextWindow:1048576,maxTokens:8192},{id:"kimi-k2",reasoning:!0,contextWindow:1048576,maxTokens:8192}]},{id:"zai",displayName:"Zhipu AI (GLM)",baseUrl:"https://open.bigmodel.cn/api/paas/v4",api:"openai-completions",description:"GLM-4 series — solid general-purpose models with competitive pricing.",models:[{id:"glm-4-plus",contextWindow:128e3,maxTokens:4096},{id:"glm-4-flash",contextWindow:128e3,maxTokens:4096}]},{id:"minimax",displayName:"MiniMax",baseUrl:"https://api.minimaxi.com/v1",api:"openai-completions",description:"Strong creative and conversational models at low cost.",models:[{id:"abab7-chat",contextWindow:1048576,maxTokens:8192},{id:"minimax-m1",reasoning:!0,contextWindow:1048576,maxTokens:8192}]},{id:"openrouter",displayName:"OpenRouter",baseUrl:"https://openrouter.ai/api/v1",api:"openai-responses",description:"Access 300+ models through a single API. Use Discover to browse available models.",models:[]}],nV={anthropic:{Icon:ny,hasColor:!1},openai:{Icon:nb,hasColor:!1},"openai-codex":{Icon:nb,hasColor:!1},google:{Icon:nj,hasColor:!0},"google-vertex":{Icon:nj,hasColor:!0},deepseek:{Icon:nk,hasColor:!0},groq:{Icon:nw,hasColor:!1},mistral:{Icon:nS,hasColor:!0},moonshotai:{Icon:nC,hasColor:!1},"moonshotai-cn":{Icon:nC,hasColor:!1},moonshot:{Icon:nC,hasColor:!1},minimax:{Icon:nz,hasColor:!0},"minimax-cn":{Icon:nz,hasColor:!0},fireworks:{Icon:nT,hasColor:!0},huggingface:{Icon:nI,hasColor:!0},cerebras:{Icon:nM,hasColor:!0},openrouter:{Icon:nL,hasColor:!1},xai:{Icon:nR,hasColor:!1},"cloudflare-ai-gateway":{Icon:nW,hasColor:!0},"cloudflare-workers-ai":{Icon:nW,hasColor:!0},"vercel-ai-gateway":{Icon:nE,hasColor:!1},"github-copilot":{Icon:n$,hasColor:!1},"amazon-bedrock":{Icon:nA,hasColor:!0},"azure-openai-responses":{Icon:nB,hasColor:!0},"kimi-coding":{Icon:nN,hasColor:!0},qwen:{Icon:nP,hasColor:!0},zai:{Icon:nD,hasColor:!0},cohere:{Icon:nO,hasColor:!0},perplexity:{Icon:nH,hasColor:!0},together:{Icon:nF,hasColor:!0},grok:{Icon:n_,hasColor:!1}};function nq(e){return nU.find(t=>t.id===e)}let nK=[{value:"openai-responses",label:"OpenAI Responses",description:"OpenAI / deeprouter GPT relay"},{value:"openai-completions",label:"Chat Completions",description:"DeepSeek / Kimi / Qwen via compat proxy"}];function nJ({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 nZ={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 nY({value:e,onChange:t,placeholder:r,mono:o,onKeyDown:i,style:l}){return(0,n.jsx)("input",{value:e,onChange:e=>t(e.target.value),onKeyDown:i,placeholder:r,style:{...nZ,fontFamily:o?"var(--font-mono)":"inherit",...l}})}function nG({value:e,onChange:t,placeholder:r,mono:i,onKeyDown:l,autoComplete:s="off",spellCheck:a=!1,style:d}){let[c,u]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{e||u(!1)},[e]),(0,n.jsxs)("div",{style:{position:"relative",width:"100%",...d},children:[(0,n.jsx)("input",{type:c?"text":"password",value:e,onChange:e=>t(e.target.value),onKeyDown:l,placeholder:r,style:{...nZ,paddingRight:34,fontFamily:i?"var(--font-mono)":"inherit"},autoComplete:s,spellCheck:a}),(0,n.jsx)("button",{type:"button",onClick:()=>u(e=>!e),"aria-label":c?"Hide API key":"Show API key",title:c?"Hide API key":"Show API key",style:{position:"absolute",right:5,top:"50%",transform:"translateY(-50%)",width:24,height:24,padding:0,border:"none",background:"transparent",color:"var(--text-dim)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},children:c?(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M17.94 17.94A10.94 10.94 0 0 1 12 20C7 20 2.73 16.89 1 12a18.45 18.45 0 0 1 5.06-6.94"}),(0,n.jsx)("path",{d:"M9.9 4.24A10.94 10.94 0 0 1 12 4c5 0 9.27 3.11 11 8a18.5 18.5 0 0 1-2.16 3.19"}),(0,n.jsx)("path",{d:"M14.12 14.12A3 3 0 0 1 9.88 9.88"}),(0,n.jsx)("path",{d:"M1 1l22 22"})]}):(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8S1 12 1 12Z"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})})]})}function nX({value:e,onChange:t,placeholder:r}){return(0,n.jsx)("input",{type:"number",value:e,onChange:e=>t(e.target.value),placeholder:r,style:nZ})}function nQ({value:e,onChange:t,required:r}){return(0,n.jsxs)("select",{value:e,onChange:e=>{let r=e.target.value;t("string"==typeof r&&nx.includes(r)?r:"")},style:{...nZ,color:e?"var(--text)":"var(--text-dim)"},children:[!r&&(0,n.jsx)("option",{value:"",children:"— inherit / none —"}),nK.map(e=>(0,n.jsx)("option",{value:e.value,children:e.label},e.value))]})}function n0({api:e}){let t=nK.find(t=>t.value===e);return(0,n.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:t?t.description:"Leave empty to inherit the provider protocol."})}function n1({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 n2({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 n4({name:e,provider:t,onChange:r,onRename:i,onDelete:l}){let[s,a]=(0,o.useState)(e),[d,c]=(0,o.useState)(""),u="codex"===t.source;(0,o.useEffect)(()=>a(e),[e]);let p=(e,n)=>r({...t,[e]:n}),h=()=>{if(u)return;let e=d.trim();if(!e)return;let n=t.models??[];n.some(t=>t.id===e)||r({...t,models:[...n,{id:e,name:e}]}),c("")};return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(n2,{children:"Provider"}),(0,n.jsx)("button",{onClick:()=>!u&&l(),disabled:u,style:{padding:"3px 8px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:4,color:"#ef4444",cursor:u?"not-allowed":"pointer",fontSize:11,opacity:u?.45:1},children:"Delete"})]}),u&&(0,n.jsx)("div",{style:{padding:"7px 10px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-dim)",fontSize:12},children:"Loaded from ~/.codex/config.toml and auth.json. Add a UI provider to override it."}),(0,n.jsxs)(nJ,{label:"Provider name",children:[(0,n.jsx)(nY,{value:s,onChange:e=>!u&&a(e),placeholder:"provider-name",mono:!0}),!u&&s!==e&&s.trim()&&(0,n.jsx)("button",{onClick:()=>i(s.trim()),style:{marginTop:4,padding:"3px 10px",background:"var(--accent)",border:"none",borderRadius:4,color:"#fff",cursor:"pointer",fontSize:11,alignSelf:"flex-start"},children:"Rename"})]}),(0,n.jsx)(nJ,{label:"Base URL",children:(0,n.jsx)(nY,{value:t.baseUrl??"",onChange:e=>!u&&p("baseUrl",e||void 0),placeholder:"https://api.example.com/v1",mono:!0})}),(0,n.jsxs)(nJ,{label:"API Key",children:[(0,n.jsx)(nG,{value:t.apiKey??"",onChange:e=>!u&&p("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.jsxs)(nJ,{label:"Protocol",children:[(0,n.jsx)(nQ,{value:t.api??nm(t.baseUrl,e),onChange:e=>!u&&p("api",e||void 0),required:!0}),(0,n.jsx)(n0,{api:t.api??nm(t.baseUrl,e)})]}),(0,n.jsxs)(nJ,{label:"Model ID",children:[(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsx)(nY,{value:d,onChange:e=>!u&&c(e),onKeyDown:e=>{"Enter"!==e.key||u||h()},placeholder:"gpt-5.5",mono:!0,style:{flex:1}}),(0,n.jsx)("button",{type:"button",onClick:h,disabled:u||!d.trim(),style:{padding:"0 12px",border:"none",borderRadius:5,background:!u&&d.trim()?"var(--accent)":"var(--bg-panel)",color:!u&&d.trim()?"#fff":"var(--text-dim)",cursor:!u&&d.trim()?"pointer":"not-allowed",fontSize:12,fontWeight:600,flexShrink:0},children:"Add"})]}),(0,n.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:"Fetching the model list is optional. Add the model ID your provider supports, then save."})]})]})}let n5=["off","minimal","low","medium","high","xhigh"],n6={off:"var(--text-dim)",minimal:"#6b7280",low:"#60a5fa",medium:"#a78bfa",high:"#f472b6",xhigh:"#fb923c"};function n3({value:e,onChange:t}){let r=e??{},o=(e,n)=>{let o={...r};"omit"===n?delete o[e]:o[e]=n,t(Object.keys(o).length?o:void 0)};return(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:2},children:n5.map(e=>{let t=r[e],i=e in r?null===t?"null":"string":"omit",l="string"==typeof t?t:"",s=n6[e],a={padding:"4px 10px",fontSize:10,border:"none",cursor:"pointer",fontWeight:400,transition:"background 0.1s, color 0.1s",whiteSpace:"nowrap",background:"var(--bg-panel)",color:"var(--text-dim)"},d={background:"var(--accent)",color:"#fff",fontWeight:600};return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"5px 4px",borderRadius:6,background:"transparent",border:"1px solid transparent"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:5,width:68,flexShrink:0},children:[(0,n.jsx)("span",{style:{width:6,height:6,borderRadius:"50%",background:s,flexShrink:0,opacity:"null"===i?.3:1}}),(0,n.jsx)("span",{style:{fontSize:11,fontFamily:"var(--font-mono)",color:"null"===i?"var(--text-dim)":"var(--text-muted)",textDecoration:"null"===i?"line-through":"none"},children:e})]}),(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,border:"1px solid var(--border)",overflow:"hidden",flexShrink:0},children:[(0,n.jsx)("button",{onClick:()=>o(e,"omit"),style:{...a,..."omit"===i?d:{}},children:"Default"}),(0,n.jsx)("button",{onClick:()=>o(e,null),style:{...a,borderLeft:"1px solid var(--border)",..."null"===i?{background:"#ef4444",color:"#fff",fontWeight:600}:{}},children:"Disabled"})]}),(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,border:`1px solid ${"string"===i?"var(--accent)":"var(--border)"}`,overflow:"hidden",transition:"border-color 0.1s"},children:[(0,n.jsx)("button",{onClick:()=>o(e,l||e),style:{...a,..."string"===i?d:{},borderRight:"1px solid var(--border)",flexShrink:0},children:"Custom"}),(0,n.jsx)("input",{value:l,onChange:t=>o(e,t.target.value),onFocus:()=>{"string"!==i&&o(e,l||e)},placeholder:e,maxLength:10,style:{width:"12ch",background:"string"===i?"var(--bg)":"var(--bg-panel)",border:"none",outline:"none",color:"string"===i?"var(--text)":"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11,padding:"4px 7px",transition:"background 0.1s, color 0.1s"}})]})]},e)})})}let n8={thinkingFormat:"deepseek",requiresReasoningContentOnAssistantMessages:!0};function n7({providerName:e,provider:t,model:r,onChange:i,onDelete:l}){let[s,a]=(0,o.useState)({phase:"idle"}),d=(e,t)=>i({...r,[e]:t}),c=(()=>{if("idle"===s.phase)return null;if("testing"===s.phase)return"Testing model connection...";let e=[void 0!==s.latencyMs?`${s.latencyMs}ms`:null,void 0!==s.status?`HTTP ${s.status}`:null].filter(Boolean);return"success"===s.phase?["Connected",...e,s.responseText||null].filter(Boolean).join(" \xb7 "):["Failed",...e,s.message].filter(Boolean).join(" \xb7 ")})();(0,o.useEffect)(()=>{a({phase:"idle"})},[e,t.baseUrl,t.api,t.apiKey,r.id,r.api]);let u=(0,o.useCallback)(async()=>{if(r.id.trim()&&"testing"!==s.phase){a({phase:"testing"});try{let n=await fetch("/api/models-config/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerName:e,provider:t,model:r})}),o=await n.json();if(!n.ok||!o.ok)return void a({phase:"error",message:o.error??`HTTP ${n.status}`,latencyMs:o.latencyMs,status:o.status});a({phase:"success",latencyMs:o.latencyMs,status:o.status,responseText:o.responseText})}catch(e){a({phase:"error",message:e instanceof Error?e.message:String(e)})}}},[r,t,e,s.phase]);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(n2,{children:"Model"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[c&&(0,n.jsx)("span",{title:c,style:{maxWidth:260,height:24,padding:"0 8px",border:`1px solid ${"error"===s.phase?"#fecaca":"success"===s.phase?"#bbf7d0":"var(--border)"}`,borderRadius:4,background:"error"===s.phase?"#fee2e2":"success"===s.phase?"#dcfce7":"#e5e7eb",color:"#111827",fontSize:11,display:"inline-flex",alignItems:"center",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",boxSizing:"border-box"},children:c}),(0,n.jsxs)("button",{onClick:u,disabled:!r.id.trim()||"testing"===s.phase,title:"Test model connection",style:{height:24,padding:"0 8px",background:"success"===s.phase?"#16a34a":"none",border:`1px solid ${"success"===s.phase?"#16a34a":"var(--border)"}`,borderRadius:4,color:"success"===s.phase?"#fff":r.id.trim()&&"testing"!==s.phase?"var(--text-muted)":"var(--text-dim)",cursor:r.id.trim()&&"testing"!==s.phase?"pointer":"not-allowed",fontSize:11,display:"inline-flex",alignItems:"center",justifyContent:"center",boxSizing:"border-box",gap:5},children:["success"===s.phase&&(0,n.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}),"testing"===s.phase?"Testing…":"success"===s.phase?"OK":"Test"]}),(0,n.jsx)("button",{onClick:l,style:{height:24,padding:"0 8px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:4,color:"#ef4444",cursor:"pointer",fontSize:11,boxSizing:"border-box"},children:"Remove"})]})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[(0,n.jsx)(nJ,{label:"ID *",children:(0,n.jsx)(nY,{value:r.id,onChange:e=>d("id",e),placeholder:"model-id",mono:!0})}),(0,n.jsx)(nJ,{label:"Name",children:(0,n.jsx)(nY,{value:r.name??"",onChange:e=>d("name",e||void 0),placeholder:"Display name"})})]}),(0,n.jsxs)(nJ,{label:"API override",children:[(0,n.jsx)(nQ,{value:r.api??"",onChange:e=>d("api",e||void 0)}),(0,n.jsx)(n0,{api:r.api??""})]}),(0,n.jsxs)("div",{style:{display:"flex",gap:20,flexWrap:"wrap"},children:[(0,n.jsx)(n1,{label:"Reasoning / thinking",checked:r.reasoning??!1,onChange:e=>d("reasoning",e||void 0)}),(0,n.jsx)(n1,{label:"Image input",checked:r.input?.includes("image")??!1,onChange:e=>d("input",e?["text","image"]:void 0)})]}),r.reasoning&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(n1,{label:"DeepSeek thinking compat",checked:r.compat?.thinkingFormat==="deepseek",onChange:e=>i(function(e,t){if(t)return{...e,compat:{...e.compat??{},...n8}};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)(n2,{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)(n3,{value:r.thinkingLevelMap,onChange:e=>d("thinkingLevelMap",e)})]})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[(0,n.jsx)(nJ,{label:"Context window (tokens)",children:(0,n.jsx)(nX,{value:void 0!==r.contextWindow?String(r.contextWindow):"",onChange:e=>d("contextWindow",e?parseInt(e):void 0),placeholder:"128000"})}),(0,n.jsx)(nJ,{label:"Max output tokens",children:(0,n.jsx)(nX,{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)(n2,{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)(nJ,{label:e,children:(0,n.jsx)(nX,{value:r.cost?.[e]!==void 0?String(r.cost[e]):"",onChange:t=>{let n;return n=parseFloat(t),void i({...r,cost:{...r.cost??{},[e]:isNaN(n)?void 0:n}})},placeholder:"0"})},e))})]})]})}function n9({provider:e,onRefresh:t}){let[r,i]=(0,o.useState)({phase:"idle"}),[l,s]=(0,o.useState)(""),a=(0,o.useRef)(null),d=(0,o.useRef)(null);(0,o.useEffect)(()=>{("auth"===r.phase||"prompt"===r.phase)&&setTimeout(()=>d.current?.focus(),50)},[r.phase]),(0,o.useEffect)(()=>{i({phase:"idle"}),s(""),a.current?.close(),a.current=null},[e.id]),(0,o.useEffect)(()=>()=>{a.current?.close()},[]);let c=(0,o.useCallback)(()=>{a.current?.close(),i({phase:"connecting"}),s("");let r=new EventSource(`/api/auth/login/${encodeURIComponent(e.id)}`);a.current=r,r.onmessage=e=>{let n=JSON.parse(e.data);"auth"===n.type?(i({phase:"auth",url:n.url,instructions:n.instructions??null,token:n.token}),window.open(n.url,"_blank","noopener,noreferrer")):"device_code"===n.type?(i({phase:"device_code",userCode:n.userCode,verificationUri:n.verificationUri,intervalSeconds:n.intervalSeconds??null,expiresInSeconds:n.expiresInSeconds??null}),window.open(n.verificationUri,"_blank","noopener,noreferrer")):"prompt_request"===n.type?i({phase:"prompt",message:n.message,placeholder:n.placeholder??null,token:n.token}):"select_request"===n.type?i({phase:"select",message:n.message,options:n.options??[],token:n.token}):"progress"===n.type?i({phase:"progress",message:n.message}):"success"===n.type?(r.close(),i({phase:"success"}),t()):"error"===n.type?(r.close(),i({phase:"error",message:n.message})):"cancelled"===n.type&&(r.close(),i({phase:"idle"}))},r.onerror=()=>{r.close(),i(e=>"success"===e.phase?e:{phase:"error",message:"Connection lost"})}},[e.id,t]),u=(0,o.useCallback)(async()=>{await fetch(`/api/auth/logout/${encodeURIComponent(e.id)}`,{method:"POST"}),i({phase:"idle"}),t()},[e.id,t]),p=(0,o.useCallback)(async(t,r)=>{if(r.trim()){i({phase:"progress",message:"Verifying…"});try{let n=await fetch(`/api/auth/login/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:t,code:r.trim()})});if(!n.ok){let e=await n.json().catch(()=>({}));i({phase:"error",message:e.error??`Server error ${n.status}`});return}s("")}catch(e){i({phase:"error",message:e instanceof Error?e.message:"Network error"})}}},[e.id]),h=(0,o.useCallback)(async(t,r)=>{i({phase:"progress",message:"Continuing…"});try{let n=await fetch(`/api/auth/login/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:t,code:r})});if(!n.ok){let e=await n.json().catch(()=>({}));i({phase:"error",message:e.error??`Server error ${n.status}`})}}catch(e){i({phase:"error",message:e instanceof Error?e.message:"Network error"})}},[e.id]),x="connecting"===r.phase||"progress"===r.phase||"auth"===r.phase||"device_code"===r.phase||"prompt"===r.phase||"select"===r.phase;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(n2,{children:"Subscription"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:e.loggedIn?"#4ade80":"var(--border)",display:"inline-block"}}),(0,n.jsx)("span",{style:{fontSize:11,color:e.loggedIn?"#4ade80":"var(--text-dim)"},children:e.loggedIn?"connected":"not connected"})]})]}),(0,n.jsxs)("div",{style:{minHeight:48},children:["idle"===r.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:e.loggedIn?"Already connected. You can re-login or disconnect.":`Connect your ${e.name} account.`}),"connecting"===r.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)"},children:"Opening browser…"}),"select"===r.phase&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:r.message}),(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:r.options.map(e=>(0,n.jsx)("button",{onClick:()=>h(r.token,e.id),style:{padding:"6px 9px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",cursor:"pointer",fontSize:12,textAlign:"left"},children:e.label},e.id))})]}),("auth"===r.phase||"prompt"===r.phase)&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:"auth"===r.phase?"Complete sign-in in the browser, then copy the redirect URL from the address bar and paste it below.":r.message}),"auth"===r.phase&&(0,n.jsxs)("p",{style:{margin:0,fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:["If the browser window did not open,"," ",(0,n.jsx)("a",{href:r.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)",wordBreak:"break-all"},children:"click here to open the login page"}),"."]}),(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsx)("input",{ref:d,value:l,onChange:e=>s(e.target.value),onKeyDown:e=>{"Enter"===e.key&&p(r.token,l)},placeholder:"auth"===r.phase?"http://localhost:1455/auth/callback?code=…":r.placeholder??"Enter value…",style:{flex:1,padding:"6px 9px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",fontSize:12,outline:"none",fontFamily:"var(--font-mono)",boxSizing:"border-box"}}),(0,n.jsx)("button",{onClick:()=>p(r.token,l),disabled:!l.trim(),style:{padding:"6px 12px",background:l.trim()?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:5,color:l.trim()?"#fff":"var(--text-dim)",cursor:l.trim()?"pointer":"not-allowed",fontSize:12,fontWeight:600,flexShrink:0},children:"Submit"})]})]}),"device_code"===r.phase&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:"Open the verification page and enter this code:"}),(0,n.jsx)("div",{style:{padding:"8px 10px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",fontSize:16,fontWeight:700,fontFamily:"var(--font-mono)",letterSpacing:0},children:r.userCode}),(0,n.jsxs)("p",{style:{margin:0,fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:[(0,n.jsx)("a",{href:r.verificationUri,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)",wordBreak:"break-all"},children:r.verificationUri}),r.expiresInSeconds?` Expires in ${Math.ceil(r.expiresInSeconds/60)} minutes.`:""]})]}),"progress"===r.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)"},children:r.message}),"success"===r.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"#4ade80"},children:"Connected successfully."}),"error"===r.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"#f87171"},children:r.message})]}),(0,n.jsx)("div",{style:{display:"flex",gap:8},children:x?(0,n.jsx)("button",{onClick:()=>{a.current?.close(),i({phase:"idle"})},style:{padding:"5px 12px",background:"none",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Cancel"}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:c,style:{padding:"5px 14px",background:"var(--accent)",border:"none",borderRadius:5,color:"#fff",cursor:"pointer",fontSize:12,fontWeight:600},children:e.loggedIn?"Re-login":"Login"}),e.loggedIn&&(0,n.jsx)("button",{onClick:u,style:{padding:"5px 12px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:5,color:"#ef4444",cursor:"pointer",fontSize:12},children:"Disconnect"})]})})]})}function oe({provider:e,onRefresh:t}){let[r,i]=(0,o.useState)(""),[l,s]=(0,o.useState)(!1),[a,d]=(0,o.useState)(!1),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(!1);(0,o.useEffect)(()=>{i(""),u(null),h(!1)},[e.id]);let x=(0,o.useCallback)(async()=>{if(r.trim()){s(!0),u(null),h(!1);try{let n=await fetch(`/api/auth/api-key/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:r.trim()})}),o=await n.json();!n.ok||o.error?u(o.error??`HTTP ${n.status}`):(i(""),h(!0),setTimeout(()=>h(!1),2e3),t())}catch(e){u(String(e))}finally{s(!1)}}},[r,e.id,t]),g=(0,o.useCallback)(async()=>{d(!0),u(null);try{let r=await fetch(`/api/auth/api-key/${encodeURIComponent(e.id)}`,{method:"DELETE"}),n=await r.json();!r.ok||n.error?u(n.error??`HTTP ${r.status}`):t()}catch(e){u(String(e))}finally{d(!1)}},[e.id,t]);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(n2,{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)(nJ,{label:"API Key",children:(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsx)(nG,{value:r,onChange:i,onKeyDown:e=>{"Enter"===e.key&&r.trim()&&x()},placeholder:e.configured?"Enter new key to replace…":"sk-…",style:{flex:1},autoComplete:"off",spellCheck:!1,mono:!0}),(0,n.jsxs)("button",{onClick:x,disabled:l||!r.trim()||p,style:{padding:"6px 12px",background:p?"#16a34a":r.trim()?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:5,color:r.trim()||p?"#fff":"var(--text-dim)",cursor:l||!r.trim()||p?"not-allowed":"pointer",fontSize:12,fontWeight:600,flexShrink:0,display:"flex",alignItems:"center",gap:5},children:[p&&(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}),p?"Saved":l?"Saving…":"Save"]})]})}),c&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"#f87171"},children:c}),e.configured&&(0,n.jsx)("button",{onClick:g,disabled:a,style:{alignSelf:"flex-start",padding:"5px 12px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:5,color:"#ef4444",cursor:a?"not-allowed":"pointer",fontSize:12},children:a?"Removing…":"Disconnect"})]})}function ot({id:e,size:t}){let r=nV[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 or({oauthProviders:e,apiKeyProviders:t,onSelectOAuth:r,onSelectApiKey:i,onAddCustom:l,onDiscover:s,onAddPreset:a,configuredProviderIds:d,onClose:c}){let[u,p]=(0,o.useState)(""),[h,x]=(0,o.useState)({}),[g,f]=(0,o.useState)(null),[m,v]=(0,o.useState)(null),y=(0,o.useRef)(null);(0,o.useEffect)(()=>{setTimeout(()=>y.current?.focus(),30)},[]);let b=u.trim().toLowerCase(),j=nU.filter(e=>!d.has(e.id)&&(!b||e.displayName.toLowerCase().includes(b)||e.id.toLowerCase().includes(b))),k=e.filter(e=>!e.loggedIn&&(!b||e.name.toLowerCase().includes(b))),w=t.filter(e=>!e.configured&&(!b||e.displayName.toLowerCase().includes(b)||e.id.toLowerCase().includes(b))),S=!b||"custom".includes(b)||"openai-compatible".includes(b)||"deepseek".includes(b)||"deeprouter".includes(b),C=!b||"discover".includes(b)||"base url".includes(b)||"model import".includes(b),z=j.length+k.length+w.length+ +!!S+ +!!C,T=async e=>{let t=(h[e]??"").trim(),r=nq(e);if(!t)return void v(`Enter an API key for ${r?.displayName??e}`);if(!r)return void v(`Unknown preset: ${e}`);f(e),v(null);try{await a(e,t),c()}catch(e){v(e instanceof Error?e.message:String(e))}finally{f(null)}},I={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&&c()},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:y,value:u,onChange:e=>p(e.target.value),onKeyDown:e=>{"Escape"===e.key&&c()},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===z?(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:[j.length>0&&(0,n.jsx)("div",{style:{gridColumn:"1 / -1",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Quick Setup — just enter your API key"}),j.map(e=>{let t=h[e.id]??"",r=g===e.id;return(0,n.jsxs)("div",{style:{...I,flexDirection:"column",alignItems:"stretch",gap:8,padding:"12px 14px"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,n.jsx)(ot,{id:e.id,size:22}),(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:1},children:[e.models.length," models preset \xb7 ",e.description]})]})]}),(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsx)("input",{value:t,onChange:t=>{x(r=>({...r,[e.id]:t.target.value})),m&&v(null)},onKeyDown:r=>{"Enter"===r.key&&t.trim()&&T(e.id)},placeholder:"sk-…",type:"password",autoComplete:"off",spellCheck:!1,style:{flex:1,padding:"5px 8px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:4,color:"var(--text)",fontSize:11,fontFamily:"var(--font-mono)",outline:"none",boxSizing:"border-box"}}),(0,n.jsx)("button",{onClick:()=>T(e.id),disabled:r||!t.trim(),style:{padding:"5px 10px",background:r?"var(--bg-panel)":t.trim()?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:4,color:r?"var(--text-dim)":t.trim()?"#fff":"var(--text-dim)",cursor:r||!t.trim()?"not-allowed":"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap",flexShrink:0},children:r?"Adding…":"Add"})]})]},e.id)}),m&&(0,n.jsx)("div",{style:{gridColumn:"1 / -1",fontSize:11,color:"#f87171",padding:"2px 0"},children:m}),S&&(0,n.jsx)("div",{style:{gridColumn:"1 / -1",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Custom"}),S&&(0,n.jsxs)("button",{onClick:()=>{l(),c()},style:I,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-compatible endpoint"}),(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:"DeepSeek, deeprouter, Kimi, Qwen"})]}),(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"})]})})]}),C&&(0,n.jsxs)("button",{onClick:()=>{s(),c()},style:I,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:"Optional 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"})]})})]}),k.length>0&&(0,n.jsx)("div",{style:{gridColumn:"1 / -1",paddingTop:6*!!S,fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Subscriptions"}),k.map(e=>(0,n.jsxs)("button",{onClick:()=>{r(e.id),c()},style:I,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)(ot,{id:e.id,size:28})]},e.id)),w.length>0&&(0,n.jsx)("div",{style:{gridColumn:"1 / -1",paddingTop:6*(k.length>0),fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"API Key"}),w.map(e=>(0,n.jsxs)("button",{onClick:()=>{i(e.id),c()},style:I,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)(ot,{id:e.id,size:28})]},e.id))]})})]})})}function on({existingProviders:e,onImport:t,onClose:r}){let[i,l]=(0,o.useState)(""),[s,a]=(0,o.useState)(""),[d,c]=(0,o.useState)("custom-provider"),[u,p]=(0,o.useState)(new Set),[h,x]=(0,o.useState)({phase:"idle"}),g=(0,o.useCallback)(async()=>{let e=i.trim();if(e&&"loading"!==h.phase){x({phase:"loading"});try{let t=await fetch("/api/models-config/discover",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:e,apiKey:s,provider:d,enrich:!1})}),r=await t.json();if(!t.ok||!r.ok||!r.models||!r.piModels||!r.endpoint)return void x({phase:"error",message:r.error??`HTTP ${t.status}`});x({phase:"success",endpoint:r.endpoint,models:r.models,piModels:r.piModels}),p(new Set(r.piModels.map(e=>e.id)))}catch(e){x({phase:"error",message:e instanceof Error?e.message:String(e)})}}},[s,i,d,h.phase]),f="success"===h.phase?h:null,m=u.size,v=!!(f&&d.trim()&&m>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:"Optional: fetch a 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)(nJ,{label:"Base URL",children:(0,n.jsx)(nY,{value:i,onChange:l,placeholder:"https://api.example.com",mono:!0})}),(0,n.jsx)(nJ,{label:"API Key",children:(0,n.jsx)(nG,{value:s,onChange:a,placeholder:"optional for local providers",mono:!0})}),(0,n.jsx)(nJ,{label:"Provider name",children:(0,n.jsx)(nY,{value:d,onChange:c,placeholder:"provider-name",mono:!0})}),(0,n.jsx)("button",{onClick:g,disabled:!i.trim()||"loading"===h.phase,style:{height:31,padding:"0 14px",background:i.trim()&&"loading"!==h.phase?"var(--accent)":"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:5,color:i.trim()&&"loading"!==h.phase?"#fff":"var(--text-dim)",cursor:i.trim()&&"loading"!==h.phase?"pointer":"not-allowed",fontSize:12,fontWeight:600,whiteSpace:"nowrap"},children:"loading"===h.phase?"Fetching...":"Fetch models"})]}),(0,n.jsxs)("div",{style:{flex:1,overflow:"hidden",display:"flex",flexDirection:"column"},children:["idle"===h.phase&&(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:"Enter a Base URL to discover available models."}),"loading"===h.phase&&(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:"Fetching model catalog..."}),"error"===h.phase&&(0,n.jsx)("div",{style:{padding:18,color:"#f87171",fontSize:12,lineHeight:1.6},children:h.message}),f&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"8px 16px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-dim)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[f.piModels.length," models from ",f.endpoint]}),(0,n.jsx)("button",{onClick:()=>{if(f){if(u.size===f.piModels.length)return void p(new Set);p(new Set(f.piModels.map(e=>e.id)))}},style:{padding:"2px 8px",fontSize:11,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-muted)",cursor:"pointer"},children:u.size===f.piModels.length?"Clear":"Select all"})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"auto"},children:f.piModels.map((e,t)=>{let r=f.models[t],o=u.has(e.id);return(0,n.jsxs)("label",{style:{display:"grid",gridTemplateColumns:"24px minmax(0, 1fr) 90px 90px 90px 70px",gap:10,alignItems:"center",padding:"8px 16px",borderBottom:"1px solid rgba(127,127,127,0.12)",background:o?"var(--bg-subtle)":"transparent",cursor:"pointer"},children:[(0,n.jsx)("input",{type:"checkbox",checked:o,onChange:()=>{var t;return t=e.id,void p(e=>{let r=new Set(e);return r.has(t)?r.delete(t):r.add(t),r})},style:{width:14,height:14,accentColor:"var(--accent)"}}),(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontFamily:"var(--font-mono)",fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.id}),(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r?.ownedBy??"unknown"})]}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:e.contextWindow}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:e.maxTokens}),(0,n.jsx)("span",{style:{fontSize:10,color:e.reasoning?"var(--accent)":"var(--text-dim)"},children:e.reasoning?"reasoning":""}),(0,n.jsx)("span",{style:{fontSize:10,color:e.input?.includes("image")?"var(--accent)":"var(--text-dim)"},children:e.input?.includes("image")?"image":""})]},e.id)})})]})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:10,padding:"10px 16px",borderTop:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:[m," 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||!v)return;let n=i.trim().replace(/\/+$/,""),o=s.trim(),l=Object.entries(e).find(([,e])=>(e.baseUrl??"").replace(/\/+$/,"")===n&&(e.apiKey??"")===o),a=l?.[0]??d.trim(),c=e[a],p=new Map((c?.models??[]).map(e=>[e.id,e])),h=0;for(let e of f.piModels)u.has(e.id)&&!p.has(e.id)&&(p.set(e.id,e),h+=1);t(a,{...c??{},baseUrl:n,api:c?.api??nm(n,a),...o?{apiKey:o}:{},models:Array.from(p.values())},h),r()},disabled:!v,style:{padding:"6px 16px",background:v?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:6,color:v?"#fff":"var(--text-dim)",cursor:v?"pointer":"not-allowed",fontSize:13,fontWeight:600},children:"Import selected"})]})]})]})})}function oo({onClose:e,embedded:t=!1}){let[r,i]=(0,o.useState)({providers:{}}),[l,s]=(0,o.useState)(!0),[a,d]=(0,o.useState)(!1),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(null),[x,g]=(0,o.useState)(!1),[f,m]=(0,o.useState)(null),[v,y]=(0,o.useState)([]),[b,j]=(0,o.useState)([]),[k,w]=(0,o.useState)(!1),[S,C]=(0,o.useState)(!1),z=(0,o.useCallback)(()=>{fetch("/api/auth/providers").then(e=>e.json()).then(e=>y(e.providers)).catch(()=>{})},[]),T=(0,o.useCallback)(()=>{fetch("/api/auth/all-providers").then(e=>e.json()).then(e=>j(e.providers)).catch(()=>{})},[]);(0,o.useEffect)(()=>{fetch("/api/models-config").then(e=>e.json()).then(e=>{let t=e.providers?e:{...e,providers:{}};i(t);let r=Object.keys(t.providers??{});r.length>0&&m({type:"provider",name:r[0]})}).catch(()=>i({providers:{}})).finally(()=>s(!1)),z(),T()},[z,T]);let I=(0,o.useCallback)(()=>{let e="custom",t=1;for(;r.providers?.[e];)e=`custom-${t++}`;i(t=>({...t,providers:{...t.providers??{},[e]:{baseUrl:""}}})),m({type:"provider",name:e})},[r.providers]),M=(0,o.useCallback)(async(e,t)=>{let r=nq(e);if(!r)throw Error(`Unknown preset: ${e}`);i(n=>{var o;let i,l={...n.providers??{}};return l[e]=(o=l[e],i=o?.source!=="codex"?o:void 0,{baseUrl:r.baseUrl,api:r.api,apiKey:t,source:"annodex",requiresOpenAiAuth:i?.requiresOpenAiAuth,headers:i?.headers,compat:i?.compat,modelOverrides:i?.modelOverrides,models:function(e,t){let r=[...t??[]],n=new Set(r.map(e=>e.id));for(let t of e.models)n.has(t.id)||r.push({id:t.id,name:t.name??t.id,reasoning:t.reasoning,contextWindow:t.contextWindow,maxTokens:t.maxTokens});return r}(r,i?.models)}),{...n,providers:l}}),m({type:"provider",name:e}),g(!1),u(null),h(`Discovering models from ${r.displayName} API…`);try{let n=await fetch("/api/models-config/discover",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:r.baseUrl,apiKey:t,provider:e})}),o=await n.json();o.ok&&o.piModels?.length?(i(t=>{let r={...t.providers??{}},n=r[e];return n&&(r[e]={...n,models:o.piModels}),{...t,providers:r}}),h(`${r.displayName}: found ${o.piModels.length} models via API. Click Save.`)):o.error?h(`${r.displayName} preset added with defaults (API: ${o.error}). Click Save.`):h(`${r.displayName} preset added with default models. Click Save.`)}catch{h(`${r.displayName} preset added with default models (API unreachable). Click Save.`)}},[]),L=new Set(Object.entries(r.providers??{}).filter(([,e])=>"codex"!==e.source).map(([e])=>e)),R=(0,o.useCallback)((e,t)=>{i(r=>({...r,providers:{...r.providers??{},[e]:t}}))},[]),W=(0,o.useCallback)((e,t)=>{i(r=>{let n=Object.entries(r.providers??{}),o=n.findIndex(([t])=>t===e);return -1===o?r:(n[o]=[t,n[o][1]],{...r,providers:Object.fromEntries(n)})}),m(r=>r?"provider"===r.type&&r.name===e?{type:"provider",name:t}:"model"===r.type&&r.providerName===e?{...r,providerName:t}:r:r)},[]),E=(0,o.useCallback)(e=>{i(t=>{let r={...t.providers??{}};return delete r[e],{...t,providers:r}}),i(e=>{let t=Object.keys(e.providers??{});return m(t.length>0?{type:"provider",name:t[0]}:null),e})},[]),$=(0,o.useCallback)(e=>{i(t=>{let r=t.providers?.[e]??{},n=[...r.models??[],{id:""}];return{...t,providers:{...t.providers??{},[e]:{...r,models:n}}}}),i(t=>{let r=(t.providers?.[e]?.models?.length??1)-1;return m({type:"model",providerName:e,index:r}),t})},[]),A=(0,o.useCallback)((e,t,r)=>{i(n=>{let o=n.providers?.[e]??{},i=[...o.models??[]];return i[t]=r,{...n,providers:{...n.providers??{},[e]:{...o,models:i}}}})},[]),B=(0,o.useCallback)((e,t)=>{i(r=>{let n=r.providers?.[e]??{},o=[...n.models??[]];return o.splice(t,1),{...r,providers:{...r.providers??{},[e]:{...n,models:o.length?o:void 0}}}}),m({type:"provider",name:e})},[]),N=(0,o.useCallback)((e,t,r)=>{i(r=>({...r,providers:{...r.providers??{},[e]:t}})),m({type:"provider",name:e}),g(!1),u(null),h(`${r} model${1===r?"":"s"} imported. Click Save to write providers.json.`)},[]),P=(0,o.useCallback)(async()=>{d(!0),u(null),h(null),g(!1);try{let e=await fetch("/api/models-config",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({providers:r.providers??{}})}),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]),D=Object.entries(r.providers??{}),O=v.filter(e=>e.loggedIn),H=b.filter(e=>e.configured),F=(()=>{if(!f)return null;if("oauth"===f.type){let e=v.find(e=>e.id===f.providerId);return e?(0,n.jsx)(n9,{provider:e,onRefresh:z},e.id):null}if("apikey"===f.type){let e=b.find(e=>e.id===f.providerId);return e?(0,n.jsx)(oe,{provider:e,onRefresh:T},e.id):null}if("provider"===f.type){let e=r.providers?.[f.name];return e?(0,n.jsx)(n4,{name:f.name,provider:e,onChange:e=>R(f.name,e),onRename:e=>W(f.name,e),onDelete:()=>E(f.name)},f.name):null}let e=r.providers?.[f.providerName],t=e?.models?.[f.index];return t?(0,n.jsx)(n7,{providerName:f.providerName,provider:e,model:t,onChange:e=>A(f.providerName,f.index,e),onDelete:()=>B(f.providerName,f.index)},`${f.providerName}-${f.index}`):null})();return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:t?{height:"100%",minHeight:0,display:"flex",alignItems:"stretch",justifyContent:"stretch"}:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:r=>{t||r.target!==r.currentTarget||e()},children:(0,n.jsxs)("div",{style:{width:t?"100%":860,height:t?"100%":"78vh",background:"var(--bg)",border:t?"none":"1px solid var(--border)",borderRadius:10*!t,display:"flex",flexDirection:"column",boxShadow:t?"none":"0 8px 32px rgba(0,0,0,0.18)",overflow:"hidden"},children:[!t&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 18px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10},children:[(0,n.jsx)("span",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:"Models"}),(0,n.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:"~/.config/annodex/providers.json"})]}),(0,n.jsx)("button",{onClick:e,style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),(0,n.jsxs)("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{width:210,borderRight:"1px solid var(--border)",display:"flex",flexDirection:"column",flexShrink:0,background:"var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,overflowY:"auto",padding:"8px 6px"},children:[O.map(e=>{let t=f?.type==="oauth"&&f.providerId===e.id;return(0,n.jsxs)("div",{onClick:()=>m({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)(ot,{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)}),H.map(e=>{let t=f?.type==="apikey"&&f.providerId===e.id;return(0,n.jsxs)("div",{onClick:()=>m({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)(ot,{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)}),(O.length>0||H.length>0)&&D.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…"}):D.map(([e,t])=>{let r=f?.type==="provider"&&f.name===e,o=t.models??[];return(0,n.jsxs)("div",{style:{marginBottom:2},children:[(0,n.jsxs)("div",{onClick:()=>m({type:"provider",name:e}),style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,cursor:"pointer",background:r?"var(--bg-selected)":"none"},onMouseEnter:e=>{r||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{r||(e.currentTarget.style.background="none")},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0},children:[(0,n.jsx)("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),(0,n.jsx)("rect",{x:"9",y:"9",width:"6",height:"6"}),(0,n.jsx)("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),(0,n.jsx)("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),(0,n.jsx)("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),(0,n.jsx)("line",{x1:"15",y1:"20",x2:"15",y2:"23"}),(0,n.jsx)("line",{x1:"20",y1:"9",x2:"23",y2:"9"}),(0,n.jsx)("line",{x1:"20",y1:"14",x2:"23",y2:"14"}),(0,n.jsx)("line",{x1:"1",y1:"9",x2:"4",y2:"9"}),(0,n.jsx)("line",{x1:"1",y1:"14",x2:"4",y2:"14"})]}),(0,n.jsx)("span",{style:{fontSize:12,fontWeight:r?600:400,color:"var(--text)",fontFamily:"var(--font-mono)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e})]}),o.map((t,r)=>{let o=f?.type==="model"&&f.providerName===e&&f.index===r;return(0,n.jsxs)("div",{onClick:()=>m({type:"model",providerName:e,index:r}),style:{display:"flex",alignItems:"center",gap:6,padding:"5px 8px 5px 26px",borderRadius:5,cursor:"pointer",background:o?"var(--bg-selected)":"none"},onMouseEnter:e=>{o||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{o||(e.currentTarget.style.background="none")},children:[(0,n.jsx)("span",{style:{fontSize:11,fontFamily:"var(--font-mono)",color:t.id?"var(--text-muted)":"var(--text-dim)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.id||"new model"}),t.reasoning&&(0,n.jsx)("span",{style:{fontSize:9,padding:"1px 4px",background:"rgba(99,102,241,0.12)",color:"rgba(99,102,241,0.8)",borderRadius:3,flexShrink:0},children:"T"})]},r)}),(0,n.jsx)("div",{onClick:t=>{t.stopPropagation(),$(e)},style:{display:"flex",alignItems:"center",gap:4,padding:"4px 8px 4px 26px",borderRadius:5,cursor:"pointer",color:"var(--text-dim)"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)",e.currentTarget.style.background="none"},children:(0,n.jsx)("span",{style:{fontSize:11},children:"+ model"})})]},e)})]}),(0,n.jsx)("div",{style:{borderTop:"1px solid var(--border)",padding:"8px 6px"},children:(0,n.jsx)("button",{onClick:()=>w(!0),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,width:"100%",padding:"6px 0",background:"none",border:"1px dashed var(--border)",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",fontSize:12},onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.color="var(--text-muted)"},children:"+ Add provider"})})]}),(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:l?null:F??(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:"Select a provider or model"})})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:10,padding:"10px 18px",borderTop:"1px solid var(--border)",flexShrink:0},children:[c?(0,n.jsx)("span",{style:{fontSize:12,color:"#f87171",flex:1},children:c}):p?(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",flex:1},children:p}):null,(0,n.jsx)("button",{onClick:e,style:{padding:"6px 14px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:13},children:"Cancel"}),(0,n.jsxs)("button",{onClick:P,disabled:a||x,style:{position:"relative",padding:"6px 16px",minWidth:92,background:x?"#16a34a":a?"var(--bg-panel)":"var(--accent)",border:"none",borderRadius:6,color:x?"#fff":a?"var(--text-muted)":"#fff",cursor:a||x?"default":"pointer",fontSize:13,fontWeight:600,display:"inline-flex",alignItems:"center",justifyContent:"center",gap:6,transition:"background-color 0.2s ease, color 0.2s ease",animation:x?"saved-pop 0.45s ease":void 0},children:[x&&(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",style:{strokeDasharray:18,animation:"saved-check-draw 0.35s ease forwards",flexShrink:0},children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}),(0,n.jsx)("span",{children:x?"Saved":a?"Saving…":"Save"})]})]})]})}),k&&(0,n.jsx)(or,{oauthProviders:v,apiKeyProviders:b,onSelectOAuth:e=>m({type:"oauth",providerId:e}),onSelectApiKey:e=>m({type:"apikey",providerId:e}),onAddCustom:I,onDiscover:()=>C(!0),onAddPreset:M,configuredProviderIds:L,onClose:()=>w(!1)}),S&&(0,n.jsx)(on,{existingProviders:r.providers??{},onImport:N,onClose:()=>C(!1)})]})}function oi(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function ol(e){let t=e.sourceInfo?.source,r=e.sourceInfo?.scope;return"user"===r||"user"===t?"global":"project"===r||"project"===t?"project":"path"}function os({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 oa({skill:e,cwd:t,onToggle:r,toggling:o,saveError:i}){let l=ol(e),s=!e.disableModelInvocation;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:20},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:7},children:[(0,n.jsx)("span",{style:{fontSize:10,padding:"1px 5px",borderRadius:3,flexShrink:0,background:"project"===l?"rgba(99,102,241,0.12)":"rgba(120,120,120,0.12)",color:"project"===l?"rgba(99,102,241,0.8)":"var(--text-dim)"},children:l}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:function(e){if("project"===l&&e.startsWith(t)){let r=e.slice(t.length).replace(/^[/\\]/,"");return`./${r}`}return oi(e)}(e.filePath)}),(0,n.jsx)(os,{enabled:s,loading:o,onToggle:()=>r(e)}),i&&(0,n.jsx)("span",{style:{fontSize:12,color:"#f87171",flexShrink:0},children:i})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:"Name"}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:14,color:"var(--text)"},children:e.name})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:"Description"}),(0,n.jsx)("span",{style:{fontSize:14,color:"var(--text-muted)",lineHeight:1.6},children:e.description})]})]})}function od({cwd:e,onInstalled:t}){let[r,i]=(0,o.useState)(""),[l,s]=(0,o.useState)([]),[a,d]=(0,o.useState)(!1),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(null),[x,g]=(0,o.useState)(null),[f,m]=(0,o.useState)(null),[v,y]=(0,o.useState)([]),[b,j]=(0,o.useState)(new Set),[k,w]=(0,o.useState)("global"),S=(0,o.useRef)(null),C=(0,o.useRef)(null);(0,o.useEffect)(()=>{S.current?.focus()},[]),(0,o.useEffect)(()=>()=>{C.current?.abort()},[]);let z=(0,o.useCallback)(async e=>{if(e.trim()){d(!0),u(null),s([]);try{let t=await fetch("/api/skills/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:e.trim()})}),r=await t.json();if(r.error)return void u(r.error);s(r.results??[]),0===(r.results??[]).length&&u("No skills found")}catch(e){u(String(e))}finally{d(!1)}}},[]),T=(0,o.useCallback)(async r=>{let n=new AbortController;C.current=n,h(r),g(null),m("Starting installer"),y(["Starting installer"]);try{let o=await fetch("/api/skills/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({package:r,scope:k,cwd:e,stream:!0}),signal:n.signal});if(!o.ok||!o.body){let e=await o.json().catch(()=>null);g(e?.error??`HTTP ${o.status}`);return}let i=o.body.getReader(),l=new TextDecoder,s="",a=!1,d=e=>{"progress"===e.type?(e.stage&&m(e.stage),e.line&&y(t=>(t.at(-1)===e.line?t:[...t,e.line]).slice(-8))):"done"===e.type&&e.success?(a=!0,m("Installed"),y(e=>[...e,"Installed"].slice(-8))):"error"===e.type&&g(e.error??"Install failed")};for(;;){let{value:e,done:t}=await i.read(),r=(s+=l.decode(e??new Uint8Array,{stream:!t})).split("\n");for(let e of(s=r.pop()??"",r))e.trim()&&d(JSON.parse(e));if(t)break}s.trim()&&d(JSON.parse(s)),a&&(j(e=>new Set(e).add(r)),t())}catch(e){n.signal.aborted?(m("Canceled"),y(e=>[...e,"Canceled"].slice(-8))):g(String(e))}finally{C.current===n&&(C.current=null),h(null)}},[t,k,e]),I=(0,o.useCallback)(()=>{C.current?.abort()},[]),M="global"===k?"~/.codex/skills/":`${oi(e)}/.codex/skills/`;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,marginBottom:20},children:[(0,n.jsx)("div",{style:{fontSize:14,fontWeight:600,color:"var(--text)"},children:"Add Skill"}),(0,n.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,n.jsx)("input",{ref:S,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{"Enter"===e.key&&z(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:()=>z(r),disabled:a||!r.trim(),style:{padding:"7px 16px",fontSize:13,borderRadius:6,border:"none",background:"var(--accent)",color:"#fff",cursor:a||!r.trim()?"not-allowed":"pointer",opacity:a||!r.trim()?.5:1,flexShrink:0},children:a?"Searching…":"Search"})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10},children:[(0,n.jsx)("div",{style:{display:"flex",borderRadius:5,border:"1px solid var(--border)",overflow:"hidden",fontSize:12,flexShrink:0},children:["global","project"].map(e=>(0,n.jsx)("button",{onClick:()=>w(e),style:{padding:"3px 10px",border:"none",cursor:"pointer",background:k===e?"var(--bg-selected)":"none",color:k===e?"var(--text)":"var(--text-dim)",fontWeight:k===e?600:400,borderRight:"global"===e?"1px solid var(--border)":"none"},children:e},e))}),(0,n.jsxs)("span",{style:{fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["→ ",M]})]}),c&&(0,n.jsx)("div",{style:{fontSize:12,color:"#f87171"},children:c}),x&&(0,n.jsx)("div",{style:{fontSize:12,color:"#f87171",wordBreak:"break-word"},children:x}),p&&(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",padding:10,display:"flex",flexDirection:"column",gap:8},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10},children:[(0,n.jsx)("div",{style:{width:10,height:10,borderRadius:"50%",border:"2px solid var(--border)",borderTopColor:"var(--accent)",animation:"spin 0.8s linear infinite",flexShrink:0}}),(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:f??"Installing"}),(0,n.jsx)("div",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:p})]}),(0,n.jsx)("button",{onClick:I,style:{padding:"4px 9px",fontSize:12,borderRadius:5,border:"1px solid var(--border)",background:"none",color:"var(--text-muted)",cursor:"pointer",flexShrink:0},children:"Cancel"})]}),v.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:v.map((e,t)=>(0,n.jsx)("div",{children:e},`${t}-${e}`))})]})]}),l.length>0?(0,n.jsx)("div",{style:{flex:1,overflowY:"auto"},children:l.map(e=>{let t=b.has(e.package),r=p===e.package,o=e.package.indexOf("@"),i=o>-1?e.package.slice(0,o):e.package,l=o>-1?e.package.slice(o+1):null;return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:14,padding:"12px 0",borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)",marginBottom:3},children:l??i}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)"},children:i}),(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:e.installs}),e.url&&(0,n.jsx)("a",{href:e.url,target:"_blank",rel:"noreferrer",style:{fontSize:12,color:"var(--accent)",textDecoration:"none"},children:"skills.sh ↗"})]})]}),(0,n.jsx)("button",{onClick:()=>{t||null!==p||T(e.package)},disabled:t||null!==p,style:{flexShrink:0,padding:"5px 14px",fontSize:12,fontWeight:500,borderRadius:5,border:"1px solid var(--border)",cursor:r?"wait":t||null!==p?"not-allowed":"pointer",background:t?"rgba(34,197,94,0.1)":r?"rgba(59,130,246,0.08)":"none",color:t?"#16a34a":r?"var(--accent)":"var(--text-muted)",transition:"color 0.12s"},children:t?"✓ Installed":r?"Installing":"Install"})]},e.package)})}):!c&&!a&&(0,n.jsxs)("div",{style:{fontSize:13,color:"var(--text-dim)",lineHeight:1.8},children:["Search"," ",(0,n.jsx)("a",{href:"https://skills.sh",target:"_blank",rel:"noreferrer",style:{color:"var(--accent)",textDecoration:"none"},children:"skills.sh"})," ","to discover and install skills for your agent."]})]})}function oc({cwd:e,onClose:t,embedded:r=!1}){let[i,l]=(0,o.useState)([]),[s,a]=(0,o.useState)(!0),[d,c]=(0,o.useState)(null),[u,p]=(0,o.useState)(null),[h,x]=(0,o.useState)(new Set),[g,f]=(0,o.useState)(null),[m,v]=(0,o.useState)(!1),y=(0,o.useCallback)(()=>{a(!0),c(null),fetch(`/api/skills?cwd=${encodeURIComponent(e)}`).then(e=>e.json()).then(e=>{if(e.error)return void c(e.error);let t=e.skills??[];l(t),t.length>0&&!u&&p(t[0].filePath)}).catch(e=>c(String(e))).finally(()=>a(!1))},[e,u]);(0,o.useEffect)(()=>{y()},[e]);let b=(0,o.useCallback)(async e=>{let t=!e.disableModelInvocation;x(t=>new Set(t).add(e.filePath)),f(null);try{let r=await fetch("/api/skills",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({filePath:e.filePath,disableModelInvocation:t})}),n=await r.json();if(!r.ok||n.error)return void f(n.error??`HTTP ${r.status}`);l(r=>r.map(r=>r.filePath===e.filePath?{...r,disableModelInvocation:t}:r))}catch(e){f(String(e))}finally{x(t=>{let r=new Set(t);return r.delete(e.filePath),r})}},[]),j=i.find(e=>e.filePath===u)??null;return(0,n.jsx)("div",{style:r?{height:"100%",minHeight:0,display:"flex",alignItems:"stretch",justifyContent:"stretch"}:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:e=>{r||e.target!==e.currentTarget||t()},children:(0,n.jsxs)("div",{style:{width:r?"100%":860,height:r?"100%":"78vh",background:"var(--bg)",border:r?"none":"1px solid var(--border)",borderRadius:10*!r,display:"flex",flexDirection:"column",boxShadow:r?"none":"0 8px 32px rgba(0,0,0,0.18)",overflow:"hidden"},children:[!r&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 18px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10},children:[(0,n.jsx)("span",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:"Skills"}),(0,n.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)",maxWidth:320,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:oi(e)})]}),(0,n.jsx)("button",{onClick:t,style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),(0,n.jsxs)("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{width:210,borderRight:"1px solid var(--border)",display:"flex",flexDirection:"column",flexShrink:0,background:"var(--bg-panel)"},children:[(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",padding:"8px 6px"},children:s?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:"Loading…"}):d?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"#f87171"},children:d}):0===i.length?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"var(--text-dim)"},children:"No skills found"}):(()=>{let e=[];for(let t of["project","global","path"]){let r=i.filter(e=>ol(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=!m&&u===e.filePath,r=e.disableModelInvocation;return(0,n.jsxs)("div",{onClick:()=>{p(e.filePath),v(!1)},style:{display:"flex",alignItems:"center",gap:7,padding:"8px 8px",borderRadius:5,cursor:"pointer",background:t?"var(--bg-selected)":"none"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,n.jsx)("span",{style:{flexShrink:0,width:7,height:7,borderRadius:"50%",background:r?"var(--border)":"var(--accent)",boxShadow:r?"none":"0 0 4px var(--accent)",transition:"background 0.15s, box-shadow 0.15s"}}),(0,n.jsx)("span",{style:{fontSize:12,fontWeight:t?600:400,color:r?"var(--text-dim)":"var(--text)",fontFamily:"var(--font-mono)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name})]},e.filePath)})]},e))})()}),(0,n.jsx)("div",{style:{padding:"8px 6px",borderTop:"1px solid var(--border)",flexShrink:0},children:(0,n.jsxs)("div",{onClick:()=>v(!0),style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,cursor:"pointer",background:m?"var(--bg-selected)":"none",color:m?"var(--accent)":"var(--text-dim)",fontSize:12},onMouseEnter:e=>{m||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{m||(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:m?(0,n.jsx)(od,{cwd:e,onInstalled:()=>{y()}}):s?null:j?(0,n.jsx)(oa,{skill:j,cwd:e,onToggle:b,toggling:h.has(j.filePath),saveError:g},j.filePath):(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:"Select a skill"})})]}),(0,n.jsx)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",padding:"10px 18px",borderTop:"1px solid var(--border)",flexShrink:0},children:(0,n.jsx)("button",{onClick:t,style:{padding:"6px 14px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:13},children:"Close"})})]})})}function ou({activeCwd:e,onSelectProject:t,onProjectsChanged:r}){let[i,l]=(0,o.useState)([]),[s,a]=(0,o.useState)(!0),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(""),[x,g]=(0,o.useState)(!1),[f,m]=(0,o.useState)(null),[v,y]=(0,o.useState)(null),[b,j]=(0,o.useState)(""),k=(0,o.useRef)(null),w=(0,o.useCallback)(async()=>{try{a(!0);let e=await fetch("/api/projects"),t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);l(t.projects??[]),u(null)}catch(e){u(e instanceof Error?e.message:String(e))}finally{a(!1)}},[]);(0,o.useEffect)(()=>{w()},[w]);let S=(0,o.useMemo)(()=>({projects:i.length,chats:i.reduce((e,t)=>e+t.chatCount,0)}),[i]),C=(0,o.useCallback)(async()=>{let e=p.trim();if(e){m("add"),u(null);try{let n=await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e})}),o=await n.json();if(!n.ok||o.error)throw Error(o.error??`HTTP ${n.status}`);h(""),r?.(),t?.(e),w()}catch(e){u(e instanceof Error?e.message:String(e))}finally{m(null)}}},[w,r,t,p]),z=(0,o.useCallback)(async e=>{m("add"),u(null);try{let n=await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e})}),o=await n.json();if(!n.ok||o.error)throw Error(o.error??`HTTP ${n.status}`);h(""),g(!1),r?.(),t?.(e),w()}catch(e){u(e instanceof Error?e.message:String(e))}finally{m(null)}},[w,r,t]),T=(0,o.useCallback)(async e=>{m(`rename:${e}`),u(null);try{let t=await fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,name:b})}),n=await t.json();if(!t.ok||n.error)throw Error(n.error??`HTTP ${t.status}`);y(null),j(""),await w(),r?.()}catch(e){u(e instanceof Error?e.message:String(e))}finally{m(null)}},[w,r,b]),I=(0,o.useCallback)(async e=>{m(`remove:${e}`),u(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}`);await w(),r?.()}catch(e){u(e instanceof Error?e.message:String(e))}finally{m(null)}},[w,r]),M=(0,o.useCallback)(e=>{y(e.cwd),j(e.name??e.displayName),window.setTimeout(()=>k.current?.select(),0)},[]);return(0,n.jsxs)("div",{style:{height:"100%",overflowY:"auto",padding:20},children:[(0,n.jsxs)("div",{style:{maxWidth:900,display:"flex",flexDirection:"column",gap:14},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:15,fontWeight:750,color:"var(--text)"},children:"Projects"}),(0,n.jsxs)("div",{style:{marginTop:4,fontSize:12,color:"var(--text-muted)"},children:[S.projects," projects / ",S.chats," chats"]})]}),(0,n.jsx)("button",{type:"button",onClick:()=>void w(),style:{height:30,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Refresh"})]}),(0,n.jsx)("div",{style:{border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",padding:12},children:(0,n.jsxs)("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[(0,n.jsx)("input",{value:p,onChange:e=>h(e.target.value),onKeyDown:e=>{"Enter"===e.key&&C()},placeholder:"/path/to/project",style:{flex:1,minWidth:0,height:32,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:12,outline:"none"}}),(0,n.jsx)("button",{type:"button",onClick:()=>g(!0),style:{height:32,padding:"0 12px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Browse"}),(0,n.jsx)("button",{type:"button",disabled:!p.trim()||"add"===f,onClick:()=>void C(),style:{height:32,padding:"0 12px",border:"none",borderRadius:6,background:p.trim()?"var(--accent)":"var(--bg-hover)",color:p.trim()?"#fff":"var(--text-dim)",cursor:p.trim()?"pointer":"default",fontSize:12,fontWeight:650},children:"Add"})]})}),c&&(0,n.jsx)("div",{style:{padding:"9px 11px",border:"1px solid rgba(248,113,113,0.35)",borderRadius:7,color:"#f87171",background:"rgba(248,113,113,0.08)",fontSize:12},children:c}),(0,n.jsx)("div",{style:{border:"1px solid var(--border)",borderRadius:8,overflow:"hidden"},children:s?(0,n.jsx)("div",{style:{padding:16,color:"var(--text-muted)",fontSize:12},children:"Loading..."}):0===i.length?(0,n.jsx)("div",{style:{padding:16,color:"var(--text-muted)",fontSize:12},children:"No projects yet."}):i.map(r=>{var o;let i,l=r.cwd===e,s=v===r.cwd,a=r.lastAccessed??r.created??null;return(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) auto",gap:12,alignItems:"center",padding:"12px 14px",borderBottom:"1px solid var(--border)",background:l?"var(--bg-selected)":"var(--bg)"},children:[(0,n.jsxs)("div",{style:{minWidth:0},children:[s?(0,n.jsx)("input",{ref:k,value:b,onChange:e=>j(e.target.value),onKeyDown:e=>{"Enter"===e.key&&T(r.cwd),"Escape"===e.key&&y(null)},style:{width:"min(360px, 100%)",height:30,padding:"0 9px",border:"1px solid var(--accent)",borderRadius:6,background:"var(--bg)",color:"var(--text)",fontSize:13,outline:"none"}}):(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:13,fontWeight:l?750:650,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r.displayName}),(0,n.jsx)("div",{style:{marginTop:4,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:r.cwd,children:(i=(o=r.cwd).split(/[\\/]/).filter(Boolean)).length<=3?o:`.../${i.slice(-3).join("/")}`}),(0,n.jsxs)("div",{style:{marginTop:5,color:"var(--text-muted)",fontSize:11},children:[r.chatCount," chats / last ",function(e){if(!e)return"Never";let t=new Date(e),r=new Date().getTime()-t.getTime(),n=Math.floor(r/6e4),o=Math.floor(r/36e5),i=Math.floor(r/864e5);return n<1?"just now":n<60?`${n}m ago`:o<24?`${o}h ago`:i<7?`${i}d ago`:t.toLocaleDateString()}(a),r.exists?"":" / path missing"]})]}),(0,n.jsx)("div",{style:{display:"flex",alignItems:"center",gap:6},children:s?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",disabled:f===`rename:${r.cwd}`,onClick:()=>void T(r.cwd),style:{height:28,padding:"0 9px",border:"none",borderRadius:6,background:"var(--accent)",color:"#fff",cursor:"pointer",fontSize:12},children:"Save"}),(0,n.jsx)("button",{type:"button",onClick:()=>y(null),style:{height:28,padding:"0 9px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Cancel"})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:()=>t?.(r.cwd),style:{height:28,padding:"0 9px",border:"1px solid var(--border)",borderRadius:6,background:l?"var(--accent)":"var(--bg-panel)",color:l?"#fff":"var(--text-muted)",cursor:"pointer",fontSize:12},children:l?"Current":"Switch"}),(0,n.jsx)("button",{type:"button",onClick:()=>M(r),style:{height:28,padding:"0 9px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Rename"}),(0,n.jsx)("button",{type:"button",disabled:f===`remove:${r.cwd}`,onClick:()=>void I(r.cwd),style:{height:28,padding:"0 9px",border:"1px solid rgba(248,113,113,0.35)",borderRadius:6,background:"transparent",color:"#f87171",cursor:"pointer",fontSize:12},children:"Remove"})]})})]},r.cwd)})})]}),(0,n.jsx)(d,{open:x,initialPath:e,onClose:()=>g(!1),onSelect:e=>void z(e)})]})}function op({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 oh(){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 ox(e){return"projects"===e?(0,n.jsx)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M3 6.5A2.5 2.5 0 0 1 5.5 4H10l2 2.5h6.5A2.5 2.5 0 0 1 21 9v8.5A2.5 2.5 0 0 1 18.5 20h-13A2.5 2.5 0 0 1 3 17.5v-11Z"})}):"models"===e?(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),(0,n.jsx)("rect",{x:"9",y:"9",width:"6",height:"6"}),(0,n.jsx)("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),(0,n.jsx)("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),(0,n.jsx)("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),(0,n.jsx)("line",{x1:"15",y1:"20",x2:"15",y2:"23"})]}):"skills"===e?(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),(0,n.jsx)("path",{d:"M2 17l10 5 10-5"}),(0,n.jsx)("path",{d:"M2 12l10 5 10-5"})]}):"generative-ui"===e?(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),(0,n.jsx)("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),(0,n.jsx)("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),(0,n.jsx)("path",{d:"M16 17h5"}),(0,n.jsx)("path",{d:"M18.5 14.5v5"})]}):(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 3v18h18"}),(0,n.jsx)("path",{d:"m19 9-5 5-4-4-3 3"}),(0,n.jsx)("path",{d:"M14 9h5v5"})]})}function og({cwd:e,generativeUI:t,initialTab:r="projects",onGenerativeUIToggle:i,onClose:l,onModelsChanged:s,onProjectSelect:a,onProjectsChanged:d}){let[c,u]=(0,o.useState)(r);(0,o.useEffect)(()=>{u(r)},[r]),(0,o.useEffect)(()=>{let e=e=>{"Escape"===e.key&&l()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[l]);let p=[{id:"projects",label:"Project",description:e?"Overview and paths":"Add or select a project",icon:ox("projects")},{id:"models",label:"Models",description:"~/.config/annodex/providers.json",icon:ox("models")},{id:"skills",label:"Skills",description:e?"Project and global skills":"Select a project first",disabled:!e,icon:ox("skills")},{id:"generative-ui",label:"Generative UI",description:t?"Enabled":"Disabled",icon:ox("generative-ui")}],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)(oh,{})}),(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)(ou,{activeCwd:e,onSelectProject:a,onProjectsChanged:d}),"models"===c&&(0,n.jsx)(oo,{embedded:!0,onClose:()=>{s?.(),l()}}),"skills"===c&&e&&(0,n.jsx)(oc,{cwd:e,embedded:!0,onClose:l}),"generative-ui"===c&&(0,n.jsx)("div",{style:{height:"100%",overflowY:"auto",padding:20},children:(0,n.jsxs)("div",{style:{maxWidth:720,display:"flex",flexDirection:"column",gap:18},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:18,padding:16,border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)",lineHeight:1.35},children:"Generative UI"}),(0,n.jsx)("div",{style:{marginTop:5,fontSize:12,color:"var(--text-muted)",lineHeight:1.55},children:"Render structured widgets and safe visual code blocks directly in chat when the assistant produces UI content."})]}),(0,n.jsx)(op,{checked:t,onChange:i})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:12},children:[(0,n.jsxs)("div",{style:{padding:14,border:"1px solid var(--border)",borderRadius:8},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:700,color:"var(--text)",marginBottom:5},children:"When enabled"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.6},children:"The agent prompt favors compact visual artifacts for icons, forms, dashboards, and small interactive UI when useful."})]}),(0,n.jsxs)("div",{style:{padding:14,border:"1px solid var(--border)",borderRadius:8},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:700,color:"var(--text)",marginBottom:5},children:"Fallback rendering"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.6},children:"Assistant SVG and safe HTML code blocks can be previewed instead of appearing only as source text."})]})]})]})})]})]})]})})}function of({initialWidth:e,minWidth:t,maxWidth:r,storageKey:n,direction:i="right"}){let[l,s]=(0,o.useState)(e),[a,d]=(0,o.useState)(!1),c=(0,o.useRef)(e),u=(0,o.useCallback)(e=>{let o=Math.max(t,Math.min(r,e));s(o),c.current=o,document.documentElement.style.setProperty(n,`${o}px`)},[t,r,n]);(0,o.useEffect)(()=>{try{let e=localStorage.getItem(n);if(e){let n=parseInt(e,10);if(!isNaN(n)&&n>=t&&n<=r)return void u(n)}}catch{}u(c.current)},[n,t,r,u]);let p=(0,o.useCallback)(()=>{d(!0)},[]),h=(0,o.useCallback)(e=>{let t="left"===i?-1:1;u(c.current+e*t)},[u,i]);return{beginResize:p,endResize:(0,o.useCallback)(()=>{d(!1);try{localStorage.setItem(n,String(c.current))}catch{}},[n]),isResizing:a,resizeBy:h,width:l,widthRef:c}}let om=new Set(["pdf","png","jpg","jpeg","gif","webp","svg","bmp","ico","avif"]);function ov(e){let t=(e.replace(/[?#].*$/,"").replace(/[\\/]+$/,"").split(/[\\/]/).pop()??e).toLowerCase().split(".").pop()??"";return om.has(t)}function oy(){let e=(0,i.useRouter)(),t=(0,i.useSearchParams)(),{isDark:r,toggleTheme:l}=$(),[s,a]=(0,o.useState)(null),[d,c]=(0,o.useState)(null),[u,p]=(0,o.useState)(0),[h,x]=(0,o.useState)(0),[g,f]=(0,o.useState)(0),[m,v]=(0,o.useState)(0),[y,b]=(0,o.useState)(!1),[j,k]=(0,o.useState)("projects"),[S,C]=(0,o.useState)({generativeUI:!0,autoRestart:!0}),[z,T]=(0,o.useState)(null),[I,M]=(0,o.useState)(!0),L=of({initialWidth:260,minWidth:180,maxWidth:500,storageKey:"--annodex-sidebar-width"}),R=of({initialWidth:500,minWidth:300,maxWidth:1200,storageKey:"--annodex-right-panel-width",direction:"left"}),W=(0,o.useRef)(null),E=(0,o.useRef)(null),[A,B]=(0,o.useState)(null),N=(0,o.useRef)(null),[P,D]=(0,o.useState)(!1),[O,H]=(0,o.useState)(""),F=(0,o.useRef)(null),_=(0,o.useRef)(!1),U=(0,o.useCallback)(e=>{B(e)},[]);(0,o.useEffect)(()=>{D(!1)},[s?.id]);let V=(0,o.useCallback)(e=>e?e.name||e.firstMessage.slice(0,80)||e.id.slice(0,12):"",[]),q=(0,o.useCallback)(()=>{s&&(_.current=!1,H(s.name||V(s)),D(!0),setTimeout(()=>F.current?.select(),0))},[V,s]),K=(0,o.useCallback)(async()=>{if(_.current){_.current=!1,D(!1);return}if(!s)return void D(!1);let e=O.trim(),t=V(s);if(D(!1),e!==(s.name??"")&&(s.name||e!==t))try{(await fetch(`/api/sessions/${encodeURIComponent(s.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e})})).ok&&(a(t=>t&&t.id===s.id?{...t,name:e}:t),p(e=>e+1))}catch{}},[V,s,O]),J=(0,o.useCallback)(e=>{"Enter"===e.key?(e.preventDefault(),K()):"Escape"===e.key&&(_.current=!0,D(!1))},[K]);(0,o.useEffect)(()=>{let e=!1;return fetch("/api/settings").then(e=>e.ok?e.json():null).then(t=>{e||C(e=>({generativeUI:"boolean"==typeof t?.settings?.generativeUI?t.settings.generativeUI:e.generativeUI,autoRestart:"boolean"==typeof t?.settings?.autoRestart?t.settings.autoRestart:e.autoRestart}))}).catch(()=>{}),()=>{e=!0}},[]),(0,o.useEffect)(()=>{let e=!1,t=!1,r=()=>{t||(t=!0,fetch("/api/version").then(e=>e.ok?e.json():null).then(t=>{e||T(t)}).catch(()=>{}).finally(()=>{t=!1}))};r();let n=window.setInterval(r,6e4);return()=>{e=!0,window.clearInterval(n)}},[]);let Z=(0,o.useCallback)(()=>{let e=!S.generativeUI;C(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=>{C(t=>({...t,..."boolean"==typeof e.settings?.generativeUI?{generativeUI:e.settings.generativeUI}:{}}))}).catch(()=>C(e=>({...e,generativeUI:!e.generativeUI})))},[S.generativeUI]),[Y,G]=(0,o.useState)(null),X=(0,o.useCallback)(e=>{G(e)},[]),[Q,ee]=(0,o.useState)(null),et=(0,o.useCallback)(e=>{ee(e)},[]),[er,en]=(0,o.useState)(null),[eo,ei]=(0,o.useState)(null),el=(0,o.useCallback)(e=>{en(t=>t===e?null:e)},[]);(0,o.useEffect)(()=>{if(!er||!E.current)return;let e=()=>{let e=E.current.getBoundingClientRect();ei({top:e.bottom,left:e.left,width:e.width})};e();let t=new ResizeObserver(e);return t.observe(E.current),()=>t.disconnect()},[er]);let[es,ea]=(0,o.useState)([]),[ed,ec]=(0,o.useState)("files"),[eu,ep]=(0,o.useState)(!1),[eh,ex]=(0,o.useState)(""),[eg,ef]=(0,o.useState)([]),[em,ev]=(0,o.useState)(0),ey=(0,o.useCallback)(e=>{W.current?.insertText("`"+e+"`")},[]),[eb]=(0,o.useState)(()=>t.get("session")),[ej,ek]=(0,o.useState)(null),[ew,eS]=(0,o.useState)(()=>!t.get("session")),eC=(0,o.useRef)(!1),ez=(0,o.useCallback)(t=>{ek(t),t&&!eC.current&&(a(e=>e&&e.cwd!==t?null:e),c(e=>e&&e!==t?null:e),x(e=>e+1),f(e=>e+1),B(null),en(null),e.replace("/workspace",{scroll:!1}))},[e]),eT=(0,o.useCallback)(e=>{ez(e),b(!1),p(e=>e+1)},[ez]),eI=(0,o.useCallback)((t,r=!1)=>{c(null),ek(t.cwd),a(t),x(e=>e+1),B(null),eS(!0),r&&(eC.current=!0,setTimeout(()=>{eC.current=!1},0)),r||e.replace(`?session=${encodeURIComponent(t.id)}`,{scroll:!1})},[e]),eM=(0,o.useCallback)((t,r)=>{a(null),c(r),ek(r),x(e=>e+1),B(null),en(null),e.replace("/workspace",{scroll:!1})},[e]),eL=(0,o.useCallback)(t=>{c(null),ek(t.cwd),a(t),p(e=>e+1),e.replace(`?session=${encodeURIComponent(t.id)}`,{scroll:!1})},[e]),eR=(0,o.useCallback)(()=>{p(e=>e+1),f(e=>e+1),ev(e=>e+1)},[]),eW=(0,o.useCallback)(t=>{p(e=>e+1),c(null),a(e=>({...e??{path:"",cwd:"",created:"",modified:"",messageCount:0,firstMessage:""},id:t})),e.replace(`?session=${encodeURIComponent(t)}`,{scroll:!1})},[e]),eE=(0,o.useCallback)(()=>{eS(!0)},[]),e$=(0,o.useCallback)(t=>{if(p(e=>e+1),s?.id===t){let t=s.cwd;a(null),c(t??null),x(e=>e+1),B(null),en(null),e.replace("/workspace",{scroll:!1})}},[s,e]),eA=(0,o.useCallback)(e=>{ef(t=>t.filter(t=>t.id!==e))},[]),eB=(0,o.useCallback)(e=>{ef(t=>{let r=t.find(t=>t.id===e);return r&&t[t.length-1]?.id!==e?[...t.filter(t=>t.id!==e),r]:t})},[]),eN=(0,o.useCallback)((e,t)=>{if(ov(e)||ov(t)){let r=`preview:${e}`;ef(n=>{let o=n.find(e=>e.id===r);return o?[...n.filter(e=>e.id!==r),o]:[...n,{id:r,filePath:e,fileName:t}]});return}let r=`file:${e}`;ea(n=>n.find(e=>e.id===r)?n:[...n,{id:r,label:t,filePath:e}]),ec(r),ep(!0)},[]),eP=(0,o.useCallback)((e,t,r)=>{let n=r&&r.length>0?r:[{src:e,title:t}],o=Math.max(0,n.findIndex(t=>t.src===e)),i=n[o]??{src:e,title:t},l=`image-preview:${i.src}`,s=i.title?.trim()||i.src.split(/[/?#]/).filter(Boolean).pop()||"Image";ef(e=>{let t=e.find(e=>e.id===l),r={id:l,filePath:i.src,fileName:s,imageSrc:i.src,galleryItems:n,galleryIndex:o};return t?[...e.filter(e=>e.id!==l),{...t,...r}]:[...e,r]})},[]),eD=(0,o.useCallback)(e=>{"files"!==e&&"tools"!==e&&(ea(t=>t.filter(t=>t.id!==e)),ec(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]),eO=d??(null===s&&ej?ej:null),eH=null!==s||null!==eO,eF=ew&&!eH,e_=[{id:"files",label:"Files",closable:!1,icon:"files"},{id:"tools",label:"Tools",closable:!1,icon:"tools"},...es],eU=es.find(e=>e.id===ed)??null,eV=s?V(s):eO?"New chat":"No session",eq=s?.cwd??eO??ej??"",eK=eq?eq.replace(/\/+$/,"").split(/[\\/]/).filter(Boolean).pop()||eq:"",eJ=s?.cwd??ej??eO??void 0,eZ=ej??s?.cwd??d??null,eY=(()=>{let e=z?.runtime,t=e?.installedVersion??z?.latest;if(e?.restartPending&&t){let r=!!e.restartStartedAt;return{label:`${r?"Restarting":"Restart queued"} ${t}`,title:[`Current runtime: v${e.version??z?.current??"unknown"}`,`Installed: v${t}`,r?"A replacement server is starting.":"annodex will restart after active sessions become idle."].join("\n"),active:!0}}return z?.updateAvailable&&z.latest?{label:`Update ${z.latest}`,title:`Current: v${z.current}
|
|
260
|
+
${a}`:"",c=o?.map(e=>({type:"image",source:{type:"base64",media_type:e.mimeType,data:e.data}})),p={role:"user",content:c?.length?[...d.trim()?[{type:"text",text:d}]:[],...c]:d,timestamp:Date.now()};ey.current=!0,y(e=>[...e,p]),ed(null),ew.current=!0;let h=o?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType})),x=()=>{ev.current||(ev.current=!0,T(!0),es({kind:"waiting_model"}),w({type:"start"}),C({type:"reset"}))};try{if(u&&n){B&&et(B);let{PRESET_NONE:t,PRESET_DEFAULT:o,PRESET_FULL:i}=await r.e(8451).then(r.bind(r,48451)),s="none"===P?t:"default"===P?o:i,a=await fetch("/api/agent/new",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:n,toolNames:s,...B?{provider:B.provider,modelId:B.modelId}:{},..."auto"!==O?{thinkingLevel:O}:{},sandboxMode:F})}),c=await a.json().catch(()=>({}));if(!a.ok||c.error||!c.sessionId)throw Error(c.error??`HTTP ${a.status}`);let u=c.sessionId;em.current=u,await eH(u,1e4,!0),x(),await tB(u,{type:"prompt",message:d,toolNames:s,...h?.length?{images:h}:{}}),ez.current=!0,l?.({id:u,path:"",cwd:n,name:void 0,created:new Date().toISOString(),modified:new Date().toISOString(),messageCount:1,firstMessage:e})}else if(t){let{PRESET_NONE:e,PRESET_DEFAULT:n,PRESET_FULL:o}=await r.e(8451).then(r.bind(r,48451));await eH(t.id,1e4,!0),x();let i=await tB(t.id,{type:"prompt",message:d,toolNames:"none"===P?e:"default"===P?n:o,...h?.length?{images:h}:{}});i?.__sessionId&&i.__sessionId!==t.id&&(em.current=i.__sessionId,eD(i.__sessionId),s?.(i.__sessionId))}}catch(t){console.error("Failed to send message:",t);let e=t instanceof Error?t.message:String(t);ed(`Send failed: ${e}`),T(!1),ev.current=!1,es(null),w({type:"end"})}finally{ey.current=!1}},[u,n,B,P,O,F,t,z,eH,l,s,eD,eR]),e_=(0,o.useCallback)(async()=>{let e=em.current;if(e){ev.current=!1,ed(null),T(!1),es(null),w({type:"end"}),ex.current?.close(),ex.current=null,ef.current=null;try{await tB(e,{type:"abort"}),await eA(e)}catch(t){console.error("Failed to abort:",t),await eA(e)}}},[eA]),eU=(0,o.useCallback)(async e=>{let t=em.current;if(t){G(e);try{let{cancelled:r,newSessionId:n}=await tB(t,{type:"fork",entryId:e})??{};!r&&n&&s?.(n)}catch(e){console.error("Fork failed:",e)}finally{G(null)}}},[s]),eV=(0,o.useCallback)(async(e,t)=>{if(u)return void eT({provider:e,modelId:t});let r=em.current;if(r)try{let n=await tB(r,{type:"set_model",provider:e,modelId:t}),o=n.newSessionId??n.__sessionId;o&&o!==r&&(em.current=o,s?.(o)),Q({provider:n?.provider??e,modelId:n?.id??t})}catch(e){console.error("Failed to set model:",e)}},[u,s,eT]),eq=(0,o.useCallback)(async()=>{let e=em.current;if(e&&!er){en(!0),ei(null);try{await tB(e,{type:"compact"}),await eA(e,!0)}catch(e){ei(e instanceof Error?e.message:String(e))}finally{en(!1)}}},[er,eA]),eK=(0,o.useCallback)(async()=>{let e=em.current;if(e)try{await tB(e,{type:"abort_compaction"})}catch(e){console.error("Failed to abort compaction:",e)}},[]),eJ=(0,o.useCallback)(async e=>{if(H(e),"auto"===e)return;let t=em.current;if(t)try{await tB(t,{type:"set_thinking_level",level:e})}catch(e){console.error("Failed to set thinking level:",e)}},[]),eZ=(0,o.useCallback)(async e=>{_(e);let t=em.current;if(t&&!u)try{await tB(t,{type:"set_sandbox_mode",mode:e})}catch(e){console.error("Failed to set sandbox mode:",e)}},[u]),eY=(0,o.useCallback)(async(e,t,r)=>{let n=em.current;n&&(await tB(n,{type:"resolve_approval",requestId:e,decision:t,...r?.permissions!==void 0?{permissions:r.permissions}:{},...r?.scope?{scope:r.scope}:{}}),eh(t=>t?.requestId===e?null:t))},[]),eG=(0,o.useCallback)(async e=>{let{PRESET_NONE:t,PRESET_DEFAULT:n,PRESET_FULL:o}=await r.e(8451).then(r.bind(r,48451));eI(e);let i=em.current;if(i)try{await tB(i,{type:"set_tools",toolNames:"none"===e?t:"default"===e?n:o})}catch(e){console.error("Failed to set tools:",e)}},[eI]),eX=(0,o.useCallback)((e="smooth")=>{eS.current?.scrollIntoView({behavior:e})},[]),eQ=(0,o.useCallback)(()=>{let e=eC.current,t=ek.current;if(!e||!t)return;let r=t.getBoundingClientRect().top-e.getBoundingClientRect().top+e.scrollTop;e.scrollTo({top:r-16,behavior:"smooth"})},[]);return(0,o.useEffect)(()=>ez.current?(ez.current=!1,()=>{c&&eN(c)}):(c&&(em.current=c,eA(c,!0,!0).then(e=>{e?.running?(e$(c),eB(c),T(!0),es({kind:"waiting_model"}),w({type:"start"}),C({type:"reset"}),eD(c),eP(c,"resume-running",!0)):e$(c),e?.state&&(void 0!==e.state.isCompacting&&en(e.state.isCompacting),void 0!==e.state.contextUsage&&K(e.state.contextUsage??null),void 0!==e.state.systemPrompt&&Z(e.state.systemPrompt??null),void 0!==e.state.thinkingLevel&&H(e.state.thinkingLevel??"auto"),void 0!==e.state.sandboxMode&&_(e.state.sandboxMode??"danger-full-access"))})),()=>{c&&eN(c)}),[c,eN,eD,e$,eA,eB,eP]),(0,o.useEffect)(()=>{d?.(J)},[J,d]),(0,o.useEffect)(()=>{v.length>0&&(ew.current?(ew.current=!1,ej.current=!0,eQ()):ej.current?ev.current||eX("smooth"):(ej.current=!0,eX("instant")))},[v.length,z,eX,eQ]),(0,o.useEffect)(()=>{fetch("/api/models").then(e=>e.json()).then(e=>{if(M(e.models),e.thinkingLevels&&E(e.thinkingLevels),e.thinkingLevelMaps&&A(e.thinkingLevelMaps),e.modelList&&(R(e.modelList),u)){let t=e.defaultModel,r=t&&e.modelList.find(e=>e.id===t.modelId&&e.provider===t.provider);eT(r?{provider:r.provider,modelId:r.id}:t??null)}}).catch(()=>{})},[u,a,eT]),(0,o.useEffect)(()=>{u&&fetch("/api/settings").then(e=>e.json()).then(e=>{_("danger-full-access")}).catch(()=>{})},[u]),(0,o.useEffect)(()=>{if(!eo)return;let e=setTimeout(()=>ei(null),3e3);return()=>clearTimeout(e)},[eo]),(0,o.useEffect)(()=>()=>{eg.current&&clearTimeout(eg.current)},[]),(0,o.useEffect)(()=>{if(!z||!em.current)return;let e=em.current,t=setInterval(()=>{eP(e,"running-reconcile",!1)},1e4);return()=>clearInterval(t)},[z,eP]),{data:p,loading:x,error:f,messages:v,entryIds:b,streamState:k,streamingProcessState:S,agentRunning:z,modelNames:I,modelList:L,modelThinkingLevels:W,modelThinkingLevelMaps:$,newSessionModel:B,toolPreset:P,thinkingLevel:O,sandboxMode:F,retryInfo:U,contextUsage:q,systemPrompt:J,forkingEntryId:Y,isCompacting:er,compactError:eo,currentModel:eM,displayModel:eL,sessionStats:eE,agentPhase:el,agentError:ea,subagentRuns:ec,pendingApproval:ep,isNew:u,sessionIdRef:em,eventSourceRef:ex,messagesEndRef:eS,scrollContainerRef:eC,lastUserMsgRef:ek,pendingScrollToUserRef:ew,initialScrollDoneRef:ej,handleSend:eF,handleAbort:e_,handleFork:eU,handleModelChange:eV,handleCompact:eq,handleAbortCompaction:eK,handleToolPresetChange:eG,handleThinkingLevelChange:eJ,handleSandboxModeChange:eZ,handleResolveApproval:eY,loadTools:eB,setData:h,setMessages:y,dispatch:w,setAgentRunning:T,setForkingEntryId:G,handleAgentEventRef:eb}}({session:e,newSessionCwd:t,onAgentEnd:i,onSessionCreated:l,onSessionForked:s,modelsRefreshKey:d,onSystemPromptChange:p}),{soundEnabled:ei,onSoundToggle:el,playDoneSound:es}=function(){let[e,t]=(0,o.useState)(()=>{let e=localStorage.getItem("annodex-sound-enabled");return null===e||"true"===e}),r=(0,o.useRef)(e);return(0,o.useEffect)(()=>{r.current=e},[e]),{soundEnabled:e,onSoundToggle:(0,o.useCallback)(()=>{t(e=>{let t=!e;return localStorage.setItem("annodex-sound-enabled",String(t)),t})},[]),playDoneSound:(0,o.useCallback)(()=>{if(r.current)try{let e=new AudioContext,t=e.currentTime;[523.25,659.25].forEach((r,n)=>{let o=e.createOscillator(),i=e.createGain();o.connect(i),i.connect(e.destination),o.type="sine",o.frequency.value=r;let l=t+.18*n;i.gain.setValueAtTime(0,l),i.gain.linearRampToValueAtTime(.18,l+.02),i.gain.exponentialRampToValueAtTime(.001,l+.45),o.start(l),o.stop(l+.45)}),setTimeout(()=>e.close(),1200)}catch{}},[]),soundEnabledRef:r}}(),ea=(0,o.useRef)(es);ea.current=es;let ed=(0,o.useRef)(ei);ed.current=ei;let ec=eo.current;(0,o.useEffect)(()=>{eo.current=e=>{"agent_end"===e.type&&ed.current&&ea.current(),ec?.(e)}},[ec,eo]);let eu=D?`${D.tokens.input}|${D.tokens.output}|${D.tokens.cacheRead}|${D.tokens.cacheWrite}|${D.cost??0}`:null,ep=(0,o.useRef)(D);ep.current=D,(0,o.useEffect)(()=>{h?.(ep.current)},[eu,h]),(0,o.useEffect)(()=>()=>{h?.(null)},[h]);let eh=$?`${$.percent??"null"}|${$.contextWindow}|${$.tokens??"null"}`:null,ex=(0,o.useRef)($);ex.current=$,(0,o.useEffect)(()=>{x?.(ex.current)},[eh,x]),(0,o.useEffect)(()=>()=>{x?.(null)},[x]);let{isDragOver:eg,handleDragEnter:ef,handleDragOver:em,handleDragLeave:ev,handleDrop:ey}=function(e){let[t,r]=(0,o.useState)(!1),n=(0,o.useRef)(0),i=(0,o.useCallback)(e=>{Array.from(e.dataTransfer.items).some(tF)&&(e.preventDefault(),n.current+=1,r(!0))},[]),l=(0,o.useCallback)(e=>{Array.from(e.dataTransfer.items).some(tF)&&e.preventDefault()},[]);return{isDragOver:t,handleDragEnter:i,handleDragOver:l,handleDragLeave:(0,o.useCallback)(()=>{n.current-=1,n.current<=0&&(n.current=0,r(!1))},[]),handleDrop:(0,o.useCallback)(t=>{t.preventDefault(),n.current=0,r(!1),e(Array.from(t.dataTransfer.files))},[e])}}((0,o.useCallback)(e=>{u?.current?.addFiles(e)},[u])),eb=(f=j.filter(e=>"user"===e.role||"assistant"===e.role).length,(m=(0,o.useRef)([])).current=Array(f).fill(null).map((e,t)=>m.current[t]??null),m),ej=U&&0===j.length&&!w.isStreaming&&!C,ek=function(e=768){let[t,r]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{let t=window.matchMedia(`(max-width: ${e-1}px)`),n=()=>r(t.matches);return(n(),"function"==typeof t.addEventListener)?(t.addEventListener("change",n),()=>t.removeEventListener("change",n)):(t.addListener(n),()=>t.removeListener(n))},[e]),t}(),[ew,eS]=(0,o.useState)(!1),eC=tW(tE(j),F),ez=eC.filter(e=>"running"===e.status||"pending"===e.status).length;(0,o.useEffect)(()=>{0===eC.length&&ew&&eS(!1)},[eC.length,ew]),(0,o.useEffect)(()=>{ek&&ew&&eS(!1)},[ek,ew]);let eT=P?I[`${P.provider}:${P.modelId}`]??null:null,eI=P?M[`${P.provider}:${P.modelId}`]??null:null,eM=(0,n.jsx)(tC,{ref:u,onSend:J,onAbort:Z,isStreaming:C,model:P,modelNames:z,modelList:T,onModelChange:G,onCompact:e||U?X:void 0,onAbortCompaction:Q,isCompacting:B,compactError:N,toolPreset:L,onToolPresetChange:e||U?ee:void 0,thinkingLevel:R,onThinkingLevelChange:e||U?et:void 0,availableThinkingLevels:eT,thinkingLevelMap:eI,sandboxMode:W,onSandboxModeChange:e||U?er:void 0,retryInfo:E,soundEnabled:ei,onSoundToggle:el}),eL=(0,o.useCallback)(e=>{C?u?.current?.insertText(e):J(e)},[C,u,J]);return y?(0,n.jsx)("div",{className:"flex h-full items-center justify-center text-text-muted",children:"Loading session..."}):b?(0,n.jsx)("div",{className:"flex h-full items-center justify-center text-red-400",children:b}):(0,n.jsxs)("div",{className:"relative flex h-full flex-col overflow-hidden",onDragEnter:ef,onDragOver:em,onDragLeave:ev,onDrop:ey,children:[_&&(0,n.jsx)(tq,{request:_,onApprove:()=>void en(_.requestId,(_.method,"accept"),"item/permissions/requestApproval"===_.method?{permissions:_.params?.permissions??{},scope:"turn"}:void 0),onApproveSession:()=>void en(_.requestId,"item/permissions/requestApproval"===_.method?"accept":"acceptForSession","item/permissions/requestApproval"===_.method?{permissions:_.params?.permissions??{},scope:"session"}:void 0),onDeny:()=>void en(_.requestId,(_.method,"decline"),"item/permissions/requestApproval"===_.method?{permissions:{},scope:"turn"}:void 0)}),eg&&(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"})]})]})]}),ej?(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",alignItems:"center",justifyContent:"space-between",gap:12,marginLeft:16,marginRight:52,fontFamily:"var(--font-mono)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10,minWidth:0,flex:1,lineHeight:1.4},children:[(0,n.jsx)("span",{style:{fontSize:23,color:"var(--text)",fontWeight:750,letterSpacing:0},children:c.C3}),(0,n.jsx)("span",{style:{fontSize:14,minWidth:0,overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"},children:(0,n.jsx)(tU,{phrases:t_})})]}),(0,n.jsx)("div",{style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"flex-end",minHeight:22},children:(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-dim)",whiteSpace:"nowrap"},children:["v","0.1.46"]})})]}),eM]})}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"relative flex flex-1 overflow-hidden",children:[(0,n.jsx)("div",{ref:q,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:ek?{paddingBottom:"calc(env(safe-area-inset-bottom, 0px) + 128px)"}:void 0,children:[(()=>{let r=new Map;for(let e of j)"toolResult"===e.role&&r.set(e.toolCallId,e);let o=-1;for(let e=j.length-1;e>=0;e--)if("user"===j[e].role){o=e;break}let i=0;return j.map((l,s)=>{let d="user"===l.role||"assistant"===l.role,c=d?i++:-1,u=!1;if("assistant"===l.role){u=!0;let e=j.slice(s+1).find(e=>"user"===e.role||"assistant"===e.role);e?.role==="assistant"&&(u=!1),u&&w.isStreaming&&s===j.length-1&&(u=!1)}let p=(0,n.jsx)(ta,{message:l,toolResults:r,modelNames:z,entryId:k[s],onFork:C||U||0===s&&"user"===l.role?void 0:Y,forking:A===k[s],onSendMessage:eL,onOpenImage:a,showTimestamp:u,prevTimestamp:s>0?j[s-1].timestamp:void 0,renderVisualCodeBlocks:!!g,cwd:v?.info?.cwd??e?.cwd??t??void 0},s);return d?(0,n.jsx)("div",{ref:e=>{eb.current[c]=e,s===o&&(K.current=e)},children:p},s):p})})(),w.isStreaming&&w.streamingMessage&&(0,n.jsx)(ta,{message:w.streamingMessage,isStreaming:!0,modelNames:z,onSendMessage:eL,onOpenImage:a,renderVisualCodeBlocks:!!g,cwd:v?.info?.cwd??e?.cwd??t??void 0,streamingProcessState:S}),C&&!w.streamingMessage&&(0,n.jsx)("div",{className:"py-2 text-[13px] text-text-muted",children:(0,n.jsx)("span",{className:"animate-[pulse_1.5s_infinite]",children:function(e){if(e?.kind==="running_tools"){let t=e.tools.map(e=>e.name);return 0===t.length?"Running tool...":1===t.length?`Running ${t[0]}...`:t.length<=3?`Running ${t.join(", ")}...`:`Running ${t.slice(0,2).join(", ")} (+${t.length-2})...`}return e?.kind==="waiting_model"?"Waiting for model...":"Thinking..."}(O)})}),v?.info?.cwd&&!1===v.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:v.info.cwd})]}),H&&(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:H}),C&&(0,n.jsx)("div",{style:{height:q.current?q.current.clientHeight:"80vh"}}),(0,n.jsx)("div",{ref:V})]})}),!ek&&(0,n.jsx)(tT,{messages:j,streamingMessage:w.streamingMessage,scrollContainer:q,messageRefs:eb}),eC.length>0&&(0,n.jsxs)("button",{onClick:()=>eS(e=>!e),title:ew?"Hide agent runs":"Show agent runs",style:{position:"absolute",right:ek?8:ew?260:40,top:8,minWidth:28,height:28,display:"flex",alignItems:"center",justifyContent:"center",gap:6,padding:ez>0||eC.length>1?"0 8px":0,background:ew?"var(--bg-selected)":"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:ew?"var(--accent)":"var(--text-dim)",cursor:"pointer",zIndex:30,fontSize:12,transition:"right 0.2s ease, background 0.12s"},onMouseEnter:e=>{ew||(e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{ew||(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"})]}),(ez>0||eC.length>1)&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4,fontSize:10,fontWeight:700,color:ez>0?"var(--accent)":"var(--text-dim)"},children:[ez>0&&(0,n.jsxs)("span",{children:[ez," active"]}),(0,n.jsx)("span",{children:eC.length})]})]}),ew&&eC.length>0&&(0,n.jsxs)("div",{style:{position:"absolute",right:ek?8:48,top:4,bottom:4,width:ek?"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:"Agent Runs"}),(0,n.jsx)(t$,{runs:eC})]})]}),(0,n.jsx)("div",{className:"relative",children:eM})]})]})}function tq({request:e,onApprove:t,onApproveSession:r,onDeny:o}){let i=e.params??{},l="string"==typeof i.command?i.command:Array.isArray(i.command)?i.command.join(" "):null,s="string"==typeof i.cwd?i.cwd:null,a="string"==typeof i.reason&&i.reason.trim()?i.reason.trim():null,d="item/permissions/requestApproval"===e.method?JSON.stringify(i.permissions??{},null,2):null,c="item/fileChange/requestApproval"===e.method?"请求文件写入权限":"item/permissions/requestApproval"===e.method?"请求额外权限":"请求执行权限";return(0,n.jsx)("div",{style:{position:"absolute",inset:0,zIndex:120,background:"rgba(0,0,0,0.22)",display:"flex",alignItems:"center",justifyContent:"center",padding:20},children:(0,n.jsxs)("div",{style:{width:"min(720px, calc(100vw - 40px))",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 20px 60px rgba(0,0,0,0.28)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:"14px 16px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",gap:10},children:[(0,n.jsx)("div",{style:{color:"#f59e0b",display:"flex",alignItems:"center"},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)("path",{d:"M12 9v4"}),(0,n.jsx)("path",{d:"M12 17h.01"}),(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.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)"},children:c}),(0,n.jsx)("div",{style:{marginTop:2,fontSize:12,color:"var(--text-dim)"},children:"默认权限模式下,此操作需要你的确认"})]})]}),(0,n.jsxs)("div",{style:{padding:16,display:"flex",flexDirection:"column",gap:12},children:[a&&(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.6},children:a}),s&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:11,fontWeight:700,color:"var(--text-dim)",marginBottom:4},children:"cwd"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:s})]}),l&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:11,fontWeight:700,color:"var(--text-dim)",marginBottom:4},children:"command"}),(0,n.jsx)("pre",{style:{margin:0,padding:"10px 12px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",fontSize:12,lineHeight:1.55,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"var(--font-mono)"},children:l})]}),d&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:11,fontWeight:700,color:"var(--text-dim)",marginBottom:4},children:"permissions"}),(0,n.jsx)("pre",{style:{margin:0,padding:"10px 12px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",fontSize:12,lineHeight:1.55,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"var(--font-mono)"},children:d})]})]}),(0,n.jsxs)("div",{style:{padding:"12px 16px",borderTop:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"flex-end",gap:8},children:[(0,n.jsx)("button",{type:"button",onClick:o,style:{padding:"7px 12px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:600},children:"拒绝"}),(0,n.jsx)("button",{type:"button",onClick:t,style:{padding:"7px 12px",borderRadius:6,border:"1px solid rgba(37,99,235,0.36)",background:"var(--bg-selected)",color:"var(--text)",cursor:"pointer",fontSize:12,fontWeight:600},children:"仅这次允许"}),(0,n.jsx)("button",{type:"button",onClick:r,style:{padding:"7px 12px",borderRadius:6,border:"1px solid var(--accent)",background:"var(--accent)",color:"#fff",cursor:"pointer",fontSize:12,fontWeight:600},children:"本会话允许"})]})]})})}let tK="var(--text-dim)";function tJ({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:tK}),(0,n.jsx)("path",{d:"M1 6h14.5L14 13H2L1 6Z",stroke:tK,strokeWidth:"1",fill:tK,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:tK,strokeWidth:"1",fill:tK,fillOpacity:"0.1"})})}function tZ({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:tK,strokeWidth:"1",fill:tK,fillOpacity:"0.08"}),(0,n.jsx)("path",{d:"M10 2v3h3",stroke:tK,strokeWidth:"1",fill:"none",strokeLinejoin:"round"})]})}function tY({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:tK,strokeWidth:"0.9",fill:tK,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:tK,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:tK,letterSpacing:"0",children:e})]})}function tG({size:e=14}){return(0,n.jsx)(tY,{label:"TS",size:e})}function tX({size:e=14}){return(0,n.jsx)(tY,{label:"TSX",size:e})}function tQ({size:e=14}){return(0,n.jsx)(tY,{label:"JS",size:e})}function t0({size:e=14}){return(0,n.jsx)(tY,{label:"JSX",size:e})}function t1({size:e=14}){return(0,n.jsx)(tY,{label:"PY",size:e})}function t2({size:e=14}){return(0,n.jsx)(tY,{label:"{}",size:e})}function t4({size:e=14}){return(0,n.jsx)(tY,{label:"CSS",size:e})}function t5({size:e=14}){return(0,n.jsx)(tY,{label:"SC",size:e})}function t6({size:e=14}){return(0,n.jsx)(tY,{label:"HTM",size:e})}function t3({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:tK,strokeWidth:"0.9",fill:tK,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:tK,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M3.5 9.5V7l1.5 1.5L6.5 7v2.5",stroke:tK,strokeWidth:"0.9",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,n.jsx)("path",{d:"M8 7v2.5M7 9l1 1.5 1-1.5",stroke:tK,strokeWidth:"0.9",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]})}function t8({size:e=14}){return(0,n.jsx)(tY,{label:"YML",size:e})}function t7({size:e=14}){return(0,n.jsx)(tY,{label:"TOM",size:e})}function t9({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:tK,strokeWidth:"0.9",fill:tK,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:tK,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M4 7.5l2 1.5-2 1.5",stroke:tK,strokeWidth:"0.95",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,n.jsx)("path",{d:"M7.5 10.5h2.5",stroke:tK,strokeWidth:"0.95",strokeLinecap:"round"})]})}function re({size:e=14}){return(0,n.jsx)(tY,{label:"RS",size:e})}function rt({size:e=14}){return(0,n.jsx)(tY,{label:"GO",size:e})}function rr({size:e=14}){return(0,n.jsx)(tY,{label:"SQL",size:e})}function rn({size:e=14}){return(0,n.jsx)(tY,{label:"GQL",size:e})}function ro({size:e=14}){return(0,n.jsx)(tY,{label:"TF",size:e})}function ri({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:tK,strokeWidth:"0.9",fill:tK,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:tK,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:tK,strokeWidth:"0.8"}),(0,n.jsx)("rect",{x:"6",y:"6.5",width:"2",height:"1.5",rx:"0.3",stroke:tK,strokeWidth:"0.8"}),(0,n.jsx)("rect",{x:"3.5",y:"8.5",width:"2",height:"1.5",rx:"0.3",stroke:tK,strokeWidth:"0.8"})]})}function rl({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:tK,strokeWidth:"0.9",fill:tK,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:tK,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"5.5",cy:"8.5",r:"1.5",stroke:tK,strokeWidth:"0.9"}),(0,n.jsx)("path",{d:"M7 8.5h2.5M8.5 8.5v1.5",stroke:tK,strokeWidth:"0.9",strokeLinecap:"round"})]})}function rs({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:tK,strokeWidth:"0.9",fill:tK,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:tK,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"5",cy:"6.5",r:"1",stroke:tK,strokeWidth:"0.85"}),(0,n.jsx)("circle",{cx:"9",cy:"6.5",r:"1",stroke:tK,strokeWidth:"0.85"}),(0,n.jsx)("circle",{cx:"5",cy:"10",r:"1",stroke:tK,strokeWidth:"0.85"}),(0,n.jsx)("path",{d:"M5 7.5V9",stroke:tK,strokeWidth:"0.85",strokeLinecap:"round"}),(0,n.jsx)("path",{d:"M9 7.5v.5a2 2 0 0 1-2 2H6",stroke:tK,strokeWidth:"0.85",strokeLinecap:"round",fill:"none"})]})}function ra({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:tK,strokeWidth:"0.9",fill:tK,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:tK,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:tK,strokeWidth:"0.9"}),(0,n.jsx)("path",{d:"M5.5 8.5V7.5a1.5 1.5 0 0 1 3 0v1",stroke:tK,strokeWidth:"0.9",strokeLinecap:"round",fill:"none"})]})}function rd({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:tK,strokeWidth:"0.9",fill:tK,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:tK,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"7",cy:"8.5",r:"1.3",stroke:tK,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:tK,strokeWidth:"0.8",strokeLinecap:"round"})]})}function rc(e,t=14){let r=e.toLowerCase(),o=r.split(".").pop()??"";if("dockerfile"===r||r.startsWith("dockerfile."))return(0,n.jsx)(ri,{size:t});if(".env"===r||r.startsWith(".env."))return(0,n.jsx)(rl,{size:t});if(".gitignore"===r||".gitattributes"===r||".gitmodules"===r)return(0,n.jsx)(rs,{size:t});if("package-lock.json"===r||"yarn.lock"===r||"bun.lock"===r||"pnpm-lock.yaml"===r||"cargo.lock"===r)return(0,n.jsx)(ra,{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)(rd,{size:t});switch(o){case"ts":return(0,n.jsx)(tG,{size:t});case"tsx":return(0,n.jsx)(tX,{size:t});case"js":case"mjs":case"cjs":return(0,n.jsx)(tQ,{size:t});case"jsx":return(0,n.jsx)(t0,{size:t});case"py":return(0,n.jsx)(t1,{size:t});case"json":case"jsonl":return(0,n.jsx)(t2,{size:t});case"css":case"less":return(0,n.jsx)(t4,{size:t});case"scss":return(0,n.jsx)(t5,{size:t});case"html":case"htm":return(0,n.jsx)(t6,{size:t});case"md":case"mdx":return(0,n.jsx)(t3,{size:t});case"yaml":case"yml":return(0,n.jsx)(t8,{size:t});case"toml":return(0,n.jsx)(t7,{size:t});case"sh":case"bash":case"zsh":case"fish":return(0,n.jsx)(t9,{size:t});case"rs":return(0,n.jsx)(re,{size:t});case"go":return(0,n.jsx)(rt,{size:t});case"sql":return(0,n.jsx)(rr,{size:t});case"graphql":case"gql":return(0,n.jsx)(rn,{size:t});case"tf":case"hcl":return(0,n.jsx)(ro,{size:t});case"lock":return(0,n.jsx)(ra,{size:t});default:return(0,n.jsx)(tZ,{size:t})}}async function ru(e){let t=ed(e),r=await fetch(`/api/files/${t}?type=list`);return r.ok?((await r.json()).entries??[]).map(t=>{var r;return{name:t.name,fullPath:(r=t.name,`${ea(e).replace(/\/$/,"")}/${r}`),isDir:t.isDir,size:t.size,children:t.isDir?[]:void 0,loaded:!t.isDir}}):[]}function rp(e,t){let r=t.trim().toLowerCase();return!!(!r||e.name.toLowerCase().includes(r))||(e.children??[]).some(e=>rp(e,r))}function rh(e){return!!Array.from(e.types).includes("Files")||Array.from(e.items).some(e=>"file"===e.kind)}function rx(e){return Array.from(e.files).filter(e=>!!e.name)}function rg(e,t){return e===t?".":eu(e,t)}function rf({node:e,depth:t,cwd:r,onOpenFile:i,onAtMention:l,expandedPaths:s,onToggleExpanded:a,onUploadFiles:d,uploadTargetPath:c,refreshKey:u,searchQuery:p}){let h=!!p?.trim(),x=h?e.isDir:s.has(e.fullPath),[g,f]=(0,o.useState)(e.children??[]),[m,v]=(0,o.useState)(e.loaded??!1),[y,b]=(0,o.useState)(!1),[j,k]=(0,o.useState)(!1),[w,S]=(0,o.useState)(!1),C=e.isDir&&(w||c===e.fullPath),z=h?g.filter(e=>rp(e,p??"")):g,T=(0,o.useCallback)(async(t=!1)=>{if(!m||t){b(!0);try{let t=await ru(e.fullPath);f(t),v(!0)}catch{}finally{b(!1)}}},[m,e.fullPath]),I=(0,o.useRef)(m);(0,o.useEffect)(()=>{I.current=m}),(0,o.useEffect)(()=>{x&&m&&T(!0)},[u]);let M=(0,o.useCallback)(()=>{if(e.isDir){let t=!x;a(e.fullPath,t),t&&!m&&T()}else i(e.fullPath,e.name)},[e.isDir,e.fullPath,e.name,m,x,T,i,a]),L=(0,o.useCallback)(t=>{e.isDir&&rh(t.dataTransfer)&&(t.preventDefault(),t.stopPropagation(),t.dataTransfer.dropEffect="copy",S(!0))},[e.isDir]),R=(0,o.useCallback)(t=>{e.isDir&&rh(t.dataTransfer)&&(t.preventDefault(),t.stopPropagation(),t.dataTransfer.dropEffect="copy")},[e.isDir]),W=(0,o.useCallback)(t=>{if(!e.isDir)return;let r=t.relatedTarget;r instanceof Node&&t.currentTarget.contains(r)||S(!1)},[e.isDir]),E=(0,o.useCallback)(t=>{if(!e.isDir||!rh(t.dataTransfer))return;t.preventDefault(),t.stopPropagation(),S(!1);let r=rx(t.dataTransfer);r.length>0&&(d(r,e.fullPath),x||a(e.fullPath,!0),m||T())},[T,m,e.fullPath,e.isDir,a,d,x]);return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{onClick:M,onMouseEnter:()=>k(!0),onMouseLeave:()=>k(!1),onDragEnter:L,onDragOver:R,onDragLeave:W,onDrop:E,style:{position:"relative",display:"flex",alignItems:"center",gap:4,paddingLeft:8+14*t,paddingRight:8,height:24,cursor:"pointer",background:C?"rgba(37,99,235,0.14)":j?"var(--bg-hover)":"transparent",outline:C?"1px solid rgba(37,99,235,0.42)":"none",outlineOffset:-1,borderRadius:4,userSelect:"none",transition:"background 0.12s, outline-color 0.12s"},children:[e.isDir&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:x?"rotate(90deg)":"none",transition:"transform 0.1s"},children:(0,n.jsx)("polyline",{points:"3 2 7 5 3 8"})}),!e.isDir&&(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flexShrink:0,display:"flex",alignItems:"center"},children:e.isDir?(0,n.jsx)(tJ,{size:14,open:x}):rc(e.name,14)}),(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},title:e.fullPath,children:e.name}),y&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",children:(0,n.jsx)("path",{d:"M12 2v4M12 18v4M4.93 4.93l2.83 2.83M16.24 16.24l2.83 2.83M2 12h4M18 12h4"})}),l&&j&&(0,n.jsxs)("button",{onClick:t=>{t.stopPropagation(),l(eu(e.fullPath,r))},title:"Insert path into chat",style:{position:"absolute",right:4,top:"50%",transform:"translateY(-50%)",display:"flex",alignItems:"center",justifyContent:"center",gap:4,padding:"0 8px",height:20,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:4,color:"var(--accent)",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"4"}),(0,n.jsx)("path",{d:"M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8"})]}),"mention"]})]}),e.isDir&&x&&(0,n.jsxs)("div",{children:[z.map(e=>(0,n.jsx)(rf,{node:e,depth:t+1,cwd:r,onOpenFile:i,onAtMention:l,expandedPaths:s,onToggleExpanded:a,onUploadFiles:d,uploadTargetPath:c,refreshKey:u,searchQuery:p},e.fullPath)),0===z.length&&m&&!h&&(0,n.jsx)("div",{style:{paddingLeft:8+(t+1)*14,fontSize:11,color:"var(--text-dim)",height:22,display:"flex",alignItems:"center"},children:"empty"})]})]})}function rm({cwd:e,onOpenFile:t,refreshKey:r,onAtMention:i,searchQuery:l="",onSearchChange:s}){let[a,d]=(0,o.useState)([]),[c,u]=(0,o.useState)(!0),[p,h]=(0,o.useState)(null),[x,g]=(0,o.useState)(new Set),[f,m]=(0,o.useState)(!1),[v,y]=(0,o.useState)(null),[b,j]=(0,o.useState)(null),k=(0,o.useRef)(null),w=(0,o.useRef)(null),S=(0,o.useRef)(0),C=(0,o.useCallback)((e,t)=>(u(t),h(null),ru(e).then(e=>d(e)).catch(e=>h(String(e))).finally(()=>u(!1))),[]),z=(0,o.useCallback)((e,t)=>{g(r=>{let n=new Set(r);return t?n.add(e):n.delete(e),n})},[]);(0,o.useEffect)(()=>{let t=k.current!==e;k.current=e,t&&g(new Set),C(e,t)},[e,r,C]),(0,o.useEffect)(()=>()=>{w.current&&clearTimeout(w.current)},[]);let T=(0,o.useCallback)(()=>{C(e,0===a.length)},[e,a.length,C]),I=(0,o.useCallback)(()=>{w.current&&clearTimeout(w.current),w.current=setTimeout(()=>j(null),5e3)},[]),M=(0,o.useCallback)((t,r)=>{if(0===t.length)return;S.current=0,m(!1),w.current&&clearTimeout(w.current);let n=t.reduce((e,t)=>e+t.size,0),o=rg(r,e);y(r),j({phase:"uploading",targetPath:r,fileCount:t.length,loaded:0,total:n,message:`Uploading ${t.length} file${1===t.length?"":"s"} to ${o}`});let i=new FormData;t.forEach(e=>i.append("files",e,e.name));let l=new XMLHttpRequest,s=ed(r);l.open("POST",`/api/files/${s}?type=upload`),l.upload.onprogress=e=>{e.lengthComputable&&j(t=>t?{...t,loaded:e.loaded,total:e.total}:t)},l.onload=()=>{y(null);let e={};try{e=JSON.parse(l.responseText)}catch{e={}}if(l.status>=200&&l.status<300){let i=e.uploaded??[],l=e.failed??[],s=[...i.filter(e=>e.name!==e.originalName).slice(0,3).map(e=>`${e.originalName} saved as ${e.name}`),...l.slice(0,3).map(e=>`${e.name}: ${e.error}`)];j({phase:l.length>0?"warning":"success",targetPath:r,fileCount:t.length,loaded:n,total:n,message:l.length>0?`Uploaded ${i.length}, ${l.length} failed`:`Uploaded ${i.length} file${1===i.length?"":"s"} to ${o}`,details:s}),T(),I()}else{let o=e.error??`Upload failed (HTTP ${l.status})`;j({phase:(l.status,"error"),targetPath:r,fileCount:t.length,loaded:0,total:n,message:o,details:403===l.status?["Check directory write permission or project access."]:void 0}),I()}},l.onerror=()=>{y(null),j({phase:"error",targetPath:r,fileCount:t.length,loaded:0,total:n,message:"Upload failed due to a network error"}),I()},l.onabort=()=>{y(null),j({phase:"error",targetPath:r,fileCount:t.length,loaded:0,total:n,message:"Upload canceled"}),I()},l.send(i)},[e,T,I]),L=(0,o.useCallback)(e=>{rh(e.dataTransfer)&&(e.preventDefault(),S.current+=1,m(!0))},[]),R=(0,o.useCallback)(e=>{rh(e.dataTransfer)&&(e.preventDefault(),e.dataTransfer.dropEffect="copy")},[]),W=(0,o.useCallback)(()=>{S.current-=1,S.current<=0&&(S.current=0,m(!1))},[]),E=(0,o.useCallback)(t=>{if(!rh(t.dataTransfer))return;t.preventDefault(),S.current=0,m(!1);let r=rx(t.dataTransfer);r.length>0&&M(r,e)},[e,M]),$=l.trim()?a.filter(e=>rp(e,l)):a,A=l.trim().length>0;return c?(0,n.jsx)(rv,{cwd:e,isDraggingFiles:f,uploadState:b,onDragEnter:L,onDragOver:R,onDragLeave:W,onDrop:E,children:(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:"Loading files..."})}):p?(0,n.jsx)(rv,{cwd:e,isDraggingFiles:f,uploadState:b,onDragEnter:L,onDragOver:R,onDragLeave:W,onDrop:E,children:(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"#f87171"},children:p})}):(0,n.jsx)(rv,{cwd:e,isDraggingFiles:f,uploadState:b,onDragEnter:L,onDragOver:R,onDragLeave:W,onDrop:E,children:(0,n.jsxs)("div",{style:{padding:"2px 4px"},children:[$.map(o=>(0,n.jsx)(rf,{node:o,depth:0,cwd:e,onOpenFile:t,onAtMention:i,expandedPaths:x,onToggleExpanded:z,onUploadFiles:M,uploadTargetPath:v,refreshKey:r,searchQuery:l},o.fullPath)),0===$.length&&(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:A?"No matching files":"No files found"})]})})}function rv({cwd:e,isDraggingFiles:t,uploadState:r,onDragEnter:o,onDragOver:i,onDragLeave:l,onDrop:s,children:a}){let d=r&&r.total>0?Math.max(0,Math.min(100,Math.round(r.loaded/r.total*100))):r?.phase==="uploading"?8:100,c=r?.phase==="success"?"#22c55e":r?.phase==="warning"?"#f59e0b":r?.phase==="error"?"#ef4444":"var(--accent)";return(0,n.jsxs)("div",{onDragEnter:o,onDragOver:i,onDragLeave:l,onDrop:s,style:{position:"relative",display:"flex",flexDirection:"column",minHeight:"100%",outline:t?"1px solid rgba(37,99,235,0.45)":"none",outlineOffset:-1,background:t?"rgba(37,99,235,0.04)":void 0,transition:"background 0.12s, outline-color 0.12s"},children:[(0,n.jsx)("div",{style:{flex:1,minHeight:0},children:a}),t&&(0,n.jsx)("div",{style:{pointerEvents:"none",position:"absolute",inset:6,top:42,border:"1px dashed rgba(37,99,235,0.62)",borderRadius:8,background:"rgba(37,99,235,0.07)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:2},children:(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"7px 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",fontSize:12,boxShadow:"0 8px 24px rgba(0,0,0,0.16)"},children:[(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,n.jsx)("polyline",{points:"17 8 12 3 7 8"}),(0,n.jsx)("line",{x1:"12",y1:"3",x2:"12",y2:"15"})]}),"Drop to upload into ",rg(e,e)]})}),r&&(0,n.jsxs)("div",{style:{margin:"6px",padding:"7px 8px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",boxShadow:"0 8px 24px rgba(0,0,0,0.12)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:7,minWidth:0},children:[(0,n.jsx)("span",{style:{width:8,height:8,borderRadius:999,background:c,flexShrink:0}}),(0,n.jsx)("span",{title:r.message,style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text)",fontSize:11,fontWeight:600},children:r.message}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,flexShrink:0},children:"uploading"===r.phase?`${d}%`:function(e){if(!Number.isFinite(e)||e<=0)return"0 B";let t=["B","KB","MB","GB"],r=e,n=0;for(;r>=1024&&n<t.length-1;)r/=1024,n+=1;return`${r>=10||0===n?Math.round(r):r.toFixed(1)} ${t[n]}`}(r.total)})]}),(0,n.jsx)("div",{style:{marginTop:6,height:3,borderRadius:999,background:"var(--bg)",overflow:"hidden"},children:(0,n.jsx)("div",{style:{width:`${d}%`,height:"100%",borderRadius:999,background:c,transition:"width 0.15s ease"}})}),r.details&&r.details.length>0&&(0,n.jsx)("div",{style:{marginTop:5,display:"grid",gap:2},children:r.details.map(e=>(0,n.jsx)("div",{title:e,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontSize:10},children:e},e))})]})]})}function ry({fileName:e,pageInfo:t,onZoomIn:r,onZoomOut:o,zoom:i,extra:l}){return(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,minHeight:32},children:[e&&(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:300},title:e,children:e}),(0,n.jsx)("span",{style:{marginLeft:"auto"}}),t&&(0,n.jsx)("span",{children:t}),void 0!==i&&o&&r&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsx)("button",{onClick:o,title:"Zoom out",style:rb,children:(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:(0,n.jsx)("line",{x1:"2",y1:"5",x2:"8",y2:"5"})})}),(0,n.jsxs)("span",{style:{minWidth:36,textAlign:"center",fontVariantNumeric:"tabular-nums"},children:[Math.round(100*i),"%"]}),(0,n.jsx)("button",{onClick:r,title:"Zoom in",style:rb,children:(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"5",y1:"2",x2:"5",y2:"8"}),(0,n.jsx)("line",{x1:"2",y1:"5",x2:"8",y2:"5"})]})})]}),l]})}let rb={display:"flex",alignItems:"center",justifyContent:"center",width:24,height:24,padding:0,background:"none",border:"1px solid var(--border)",borderRadius:4,color:"var(--text-muted)",cursor:"pointer"},rj=null;function rk({arrayBuffer:e,fileName:t}){let i=(0,o.useRef)(null),[l,s]=(0,o.useState)(!0),[a,d]=(0,o.useState)(null),[c,u]=(0,o.useState)(0),[p,h]=(0,o.useState)(1),[x,g]=(0,o.useState)(1),f=(0,o.useRef)(x);f.current=x;let m=(0,o.useRef)(null),v=(0,o.useRef)(null),y=(0,o.useCallback)(async e=>{if(!rj||!m.current)return;let t=m.current;if(!(e<1)&&!(e>t.numPages)){v.current&&(v.current.cancel(),v.current=null);try{let r=await t.getPage(e),n=r.getViewport({scale:f.current*(window.devicePixelRatio||1)}),o=i.current;if(!o)return;let l=o.querySelector("canvas");if(l||((l=document.createElement("canvas")).style.display="block",l.style.margin="0 auto",o.innerHTML="",o.appendChild(l)),l.width=n.width,l.height=n.height,l.style.width=`${n.width/(window.devicePixelRatio||1)}px`,l.style.height=`${n.height/(window.devicePixelRatio||1)}px`,!l.getContext("2d"))return;let s=r.render({canvas:l,viewport:n});v.current=s,await s.promise,v.current=null}catch(e){"RenderingCancelledException"!==e.name&&console.error("PDF render error:",e)}}},[]);return(0,o.useEffect)(()=>{let t=!1;return async function(){s(!0),d(null);try{rj||((rj=await Promise.all([r.e(2213),r.e(2619)]).then(r.bind(r,12810))).GlobalWorkerOptions.workerSrc=new r.U(r(53228)).toString());let n=await rj.getDocument({data:e}).promise;if(t)return;m.current=n,u(n.numPages),h(1),s(!1)}catch(e){t||(d(String(e)),s(!1))}}(),()=>{t=!0,v.current&&(v.current.cancel(),v.current=null)}},[e]),(0,o.useEffect)(()=>{!l&&c>0&&y(p)},[l,p,c,y]),(0,o.useEffect)(()=>{!l&&c>0&&y(p)},[x]),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsx)(ry,{fileName:t,pageInfo:c>0?`Page ${p} / ${c}`:void 0,zoom:x,onZoomIn:()=>g(e=>Math.min(e+.25,3)),onZoomOut:()=>g(e=>Math.max(e-.25,.25)),extra:c>1&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsx)("button",{onClick:()=>h(e=>Math.max(e-1,1)),disabled:p<=1,style:{...rw,opacity:p<=1?.4:1},children:(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:(0,n.jsx)("polyline",{points:"6 2 3 5 6 8"})})}),(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-dim)",minWidth:28,textAlign:"center"},children:[p,"/",c]}),(0,n.jsx)("button",{onClick:()=>h(e=>Math.min(e+1,c)),disabled:p>=c,style:{...rw,opacity:p>=c?.4:1},children:(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:(0,n.jsx)("polyline",{points:"4 2 7 5 4 8"})})})]})}),(0,n.jsxs)("div",{style:{flex:1,overflow:"auto",background:"#525659",display:"flex",justifyContent:"center",padding:16},children:[l&&(0,n.jsx)("div",{style:{color:"#ccc",fontSize:13,display:"flex",alignItems:"center",gap:6,alignSelf:"flex-start",marginTop:40},children:"Loading PDF..."}),a&&(0,n.jsx)("div",{style:{color:"#f87171",fontSize:13,alignSelf:"flex-start",marginTop:40},children:a}),(0,n.jsx)("div",{ref:i,style:{visibility:l?"hidden":"visible"}})]})]})}let rw={display:"flex",alignItems:"center",justifyContent:"center",width:24,height:24,padding:0,background:"none",border:"1px solid var(--border)",borderRadius:4,color:"var(--text-muted)",cursor:"pointer"};function rS({arrayBuffer:e,fileName:t}){let i=(0,o.useRef)(null),[l,s]=(0,o.useState)(!0),[a,d]=(0,o.useState)(null);return(0,o.useEffect)(()=>{let t=!1;return async function(){s(!0),d(null);try{let{renderAsync:n}=await Promise.all([r.e(2619),r.e(4453),r.e(2274)]).then(r.bind(r,52274)),o=i.current;if(!o||t)return;o.innerHTML="",await n(e,o,void 0,{className:"docx-preview",inWrapper:!0,ignoreWidth:!1,ignoreHeight:!1,ignoreFonts:!1,breakPages:!0,ignoreLastRenderedPageBreak:!1,experimental:!1,trimXmlDeclaration:!0,useBase64URL:!1,renderChanges:!1,renderHeaders:!0,renderFooters:!0,renderFootnotes:!0,renderEndnotes:!0}),t||s(!1)}catch(e){t||(console.error("DOCX render error:",e),d(String(e)),s(!1))}}(),()=>{t=!0}},[e]),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsx)(ry,{fileName:t}),(0,n.jsxs)("div",{style:{flex:1,overflow:"auto",background:"#e8e8e8",padding:"24px 0"},children:[l&&(0,n.jsx)("div",{style:{color:"var(--text-muted)",fontSize:13,padding:"40px 16px",textAlign:"center"},children:"Loading document..."}),a&&(0,n.jsx)("div",{style:{color:"#f87171",fontSize:13,padding:"40px 16px",textAlign:"center"},children:a}),(0,n.jsx)("div",{ref:i,style:{maxWidth:816,margin:"0 auto",background:"#fff",boxShadow:"0 1px 4px rgba(0,0,0,0.12)",minHeight:100,visibility:l?"hidden":"visible"},className:"docx-preview-container"})]})]})}function rC({arrayBuffer:e,fileName:t}){let[i,l]=(0,o.useState)(!0),[s,a]=(0,o.useState)(null),[d,c]=(0,o.useState)([]),[u,p]=(0,o.useState)(0),h=(0,o.useRef)(null),[x,g]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{let t=!1;return async function(){l(!0),a(null);try{let n=await Promise.all([r.e(3524),r.e(8436)]).then(r.bind(r,15967)),o=n.read(e,{type:"array"}),i=o.SheetNames.map(e=>{let t=o.Sheets[e],r=n.utils.sheet_to_html(t,{editable:!1});return{name:e,html:r}});t||(c(i),p(0),l(!1))}catch(e){t||(console.error("XLSX parse error:",e),a(String(e)),l(!1))}}(),()=>{t=!0}},[e]),(0,o.useEffect)(()=>{let e=h.current;if(!e)return;let t=e.querySelector("table");if(!t)return;let r=()=>{g(t.querySelectorAll("colgroup col, thead tr:first-child th, tbody tr:first-child td").length>8)};r();let n=new ResizeObserver(r);return n.observe(e),()=>n.disconnect()},[u,d]),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsx)(ry,{fileName:t,extra:d.length>1&&(0,n.jsx)("div",{style:{display:"flex",alignItems:"center",gap:2},children:d.map((e,t)=>(0,n.jsx)("button",{onClick:()=>p(t),style:{padding:"2px 10px",fontSize:11,border:"1px solid var(--border)",borderBottom:t===u?"2px solid var(--accent)":"1px solid var(--border)",borderRadius:"4px 4px 0 0",background:t===u?"var(--bg-selected)":"none",color:t===u?"var(--text)":"var(--text-muted)",cursor:"pointer",fontWeight:t===u?600:400,transition:"background 0.12s"},onMouseEnter:e=>{t!==u&&(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t!==u&&(e.currentTarget.style.background="none")},children:e.name},t))})}),(0,n.jsxs)("div",{style:{flex:1,overflow:"auto",background:"var(--bg-panel)"},children:[i&&(0,n.jsx)("div",{style:{color:"var(--text-muted)",fontSize:13,padding:"40px 16px",textAlign:"center"},children:"Loading spreadsheet..."}),s&&(0,n.jsx)("div",{style:{color:"#f87171",fontSize:13,padding:"40px 16px",textAlign:"center"},children:s}),!i&&!s&&d.length>0&&(0,n.jsx)("div",{ref:h,style:{padding:"0 16px 16px",overflow:x?"auto":"visible"},dangerouslySetInnerHTML:{__html:d[u]?.html??""},className:"xlsx-preview"})]})]})}function rz({arrayBuffer:e,fileName:t}){let[i,l]=(0,o.useState)(!0),[s,a]=(0,o.useState)(null),[d,c]=(0,o.useState)([]),[u,p]=(0,o.useState)(0);(0,o.useEffect)(()=>{let t=!1;return async function(){l(!0),a(null);try{let n=(await Promise.all([r.e(2619),r.e(4453)]).then(r.t.bind(r,54453,23))).default,o=await n.loadAsync(e),i=[];o.forEach(e=>{let t=/^ppt\/slides\/slide(\d+)\.xml$/i.exec(e);t&&i.push({name:e,index:parseInt(t[1],10)})}),i.sort((e,t)=>e.index-t.index);let s=[];for(let e of i){let r;if(t)return;let n=await o.file(e.name).async("string"),i=/<a:t[^>]*>([^<]*)<\/a:t>/g,l=[];for(;null!==(r=i.exec(n));){let e=r[1].trim();e&&l.push(e)}s.push({index:e.index,texts:l})}t||(c(s),l(!1))}catch(e){t||(console.error("PPTX parse error:",e),a(String(e)),l(!1))}}(),()=>{t=!0}},[e]);let h=d[u],x=d.length;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsx)(ry,{fileName:t,pageInfo:x>0?`Slide ${u+1} / ${x}`:void 0,extra:x>1&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsx)("button",{onClick:()=>p(e=>Math.max(e-1,0)),disabled:u<=0,style:{...rT,opacity:u<=0?.4:1},children:(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:(0,n.jsx)("polyline",{points:"6 2 3 5 6 8"})})}),(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-dim)",minWidth:28,textAlign:"center"},children:[u+1,"/",x]}),(0,n.jsx)("button",{onClick:()=>p(e=>Math.min(e+1,x-1)),disabled:u>=x-1,style:{...rT,opacity:u>=x-1?.4:1},children:(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:(0,n.jsx)("polyline",{points:"4 2 7 5 4 8"})})})]})}),(0,n.jsxs)("div",{style:{flex:1,overflow:"auto",background:"var(--bg-panel)",display:"flex",justifyContent:"center",alignItems:"flex-start",padding:24},children:[i&&(0,n.jsx)("div",{style:{color:"var(--text-muted)",fontSize:13,padding:"40px 16px",textAlign:"center"},children:"Loading presentation..."}),s&&(0,n.jsx)("div",{style:{color:"#f87171",fontSize:13,padding:"40px 16px",textAlign:"center"},children:s}),!i&&!s&&h&&(0,n.jsxs)("div",{style:{width:"100%",maxWidth:800},children:[(0,n.jsxs)("div",{style:{background:"#fff",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 2px 8px rgba(0,0,0,0.08)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:"8px 16px",background:"var(--bg)",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:["Slide ",h.index]}),(0,n.jsx)("div",{style:{padding:"24px 32px 40px",minHeight:200},children:0===h.texts.length?(0,n.jsx)("div",{style:{color:"var(--text-dim)",fontStyle:"italic",fontSize:13},children:"(No text content)"}):(0,n.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none"},children:h.texts.map((e,t)=>(0,n.jsx)("li",{style:{padding:"4px 0",fontSize:14,lineHeight:1.6,color:"var(--text)",borderBottom:t<h.texts.length-1?"1px solid var(--bg-panel)":"none"},children:e},t))})})]}),x>1&&(0,n.jsxs)("div",{style:{marginTop:24},children:[(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)",marginBottom:8},children:"All slides"}),(0,n.jsx)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(140px, 1fr))",gap:8},children:d.map((e,t)=>(0,n.jsxs)("button",{onClick:()=>p(t),style:{padding:"10px 12px",background:t===u?"var(--bg-selected)":"var(--bg)",border:t===u?"2px solid var(--accent)":"1px solid var(--border)",borderRadius:6,cursor:"pointer",textAlign:"left",fontSize:11,color:"var(--text-muted)",transition:"border-color 0.12s, background 0.12s"},onMouseEnter:e=>{t!==u&&(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t!==u&&(e.currentTarget.style.background="var(--bg)")},children:[(0,n.jsxs)("div",{style:{fontWeight:600,marginBottom:2,color:"var(--text)"},children:["Slide ",e.index]}),(0,n.jsx)("div",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.texts[0]||"(empty)"})]},e.index))})]})]})]})]})}let rT={display:"flex",alignItems:"center",justifyContent:"center",width:24,height:24,padding:0,background:"none",border:"1px solid var(--border)",borderRadius:4,color:"var(--text-muted)",cursor:"pointer"};var rI=r(27071),rM=r(89561),rL=r(82228),rR=r(46732),rW=r(74059),rE=r(13307),r$=r(53689),rA=r(14097),rB=r(25460),rN=r(20144),rP=r(82774),rD=r(62733),rO=r(77482),rH=r(55135),rF=r(11209),r_=r(88198),rU=r(4238),rV=r(44542);function rq({initialContent:e,language:t,isDark:r,onChange:i,onSave:l}){let s=(0,o.useRef)(null),a=(0,o.useRef)(null),d=(0,o.useRef)(i),c=(0,o.useRef)(l);return d.current=i,c.current=l,(0,o.useEffect)(()=>{let n=s.current;if(!n)return;let o=function(e){switch(e){case"javascript":case"typescript":return(0,rE.Q2)({typescript:"typescript"===e});case"python":return(0,r$.Hg)();case"sql":return(0,rA.ll)();case"json":return(0,rB.Pq)();case"html":return(0,rN.qy)();case"css":case"scss":case"less":return(0,rP.AH)();case"markdown":return(0,rD.wD)();case"xml":case"yaml":case"toml":return(0,rO._n)();case"rust":return(0,rH.T)();case"go":return(0,rF.go)();case"java":return(0,r_.J)();default:return null}}(t),i=l?rM.w4.of([{key:"Mod-s",run:()=>(c.current?.(),!0),preventDefault:!0}]):[],u=rI.$t.create({doc:e,extensions:[(0,rM.$K)(),(0,rM.dz)(),(0,rL.b6)(),(0,rR.y9)(rR.Zt),rM.w4.of([...rL.pw,...rL.cL,...rV.OO,...rU.Eo]),i,(0,rV.yU)(),...r?[rW.bM]:[],...o?[o]:[],rM.Lz.updateListener.of(e=>{e.docChanged&&d.current?.(e.state.doc.toString())}),rM.Lz.theme({"&":{height:"100%",fontSize:"13px"},".cm-scroller":{overflow:"auto",fontFamily:"var(--font-mono)"},".cm-content":{padding:"8px 0"},".cm-gutters":{borderRight:"1px solid var(--border)",background:"var(--bg)",color:"var(--text-dim)"},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground":{background:r?"#3a3d4e":"#b4d5fe"}})]}),p=new rM.Lz({state:u,parent:n});return a.current=p,()=>{p.destroy(),a.current=null}},[t,r]),(0,o.useEffect)(()=>{let t=a.current;t&&t.state.doc.toString()!==e&&t.dispatch({changes:{from:0,to:t.state.doc.length,insert:e}})},[e]),(0,n.jsx)("div",{ref:s,style:{height:"100%",overflow:"hidden"}})}function rK({dir:e}){return(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:"asc"===e?(0,n.jsx)("polyline",{points:"2 6 5 3 8 6"}):(0,n.jsx)("polyline",{points:"2 4 5 7 8 4"})})}function rJ(e,t,r){let n=new Blob([e],{type:r}),o=URL.createObjectURL(n),i=document.createElement("a");i.href=o,i.download=t,document.body.appendChild(i),i.click(),document.body.removeChild(i),setTimeout(()=>URL.revokeObjectURL(o),1e3)}function rZ({content:e,delimiter:t,fileName:r="table"}){let[i,l]=(0,o.useState)(null),[s,a]=(0,o.useState)("asc"),{header:d,rows:c}=(0,o.useMemo)(()=>(function(e,t){let r=e.replace(/\r\n/g,"\n").replace(/\r/g,"\n"),n=[],o=[],i="",l=!1;for(let e=0;e<r.length;e+=1){let s=r[e];if('"'===s){l&&'"'===r[e+1]?(i+='"',e+=1):l=!l;continue}if(s===t&&!l){o.push(i),i="";continue}if("\n"===s&&!l){o.push(i),o.some(e=>e.length>0)&&n.push(o),o=[],i="";continue}i+=s}o.push(i),o.some(e=>e.length>0)&&n.push(o);let s=n[0]??[],a=s.length;return{header:s,rows:n.slice(1).map(e=>{let t=[...e];for(;t.length<a;)t.push("");return t.slice(0,a)})}})(e,t),[e,t]),u=(0,o.useMemo)(()=>{if(null===i)return c;let e=[...c];return e.sort((e,t)=>{let r=e[i]??"",n=t[i]??"",o=Number(r),l=Number(n),a=""===r||""===n||Number.isNaN(o)||Number.isNaN(l)?r.localeCompare(n):o-l;return"asc"===s?a:-a}),e},[c,s,i]);return 0===d.length&&0===c.length?(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:"No tabular data to display"}):(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,padding:"8px 12px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",flexShrink:0},children:[(0,n.jsxs)("div",{style:{fontSize:11,color:"var(--text-dim)"},children:[c.length," rows, ",d.length," columns"]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,n.jsxs)("button",{onClick:()=>{rJ(e,r," "===t?"text/tab-separated-values;charset=utf-8":"text/csv;charset=utf-8")},style:{padding:"2px 8px",fontSize:11,cursor:"pointer",background:"var(--bg-hover)",color:"var(--text-muted)",border:"1px solid var(--border)",borderRadius:5},children:["Export "," "===t?"TSV":"CSV"]}),(0,n.jsx)("button",{onClick:()=>{rJ(JSON.stringify(u.map(e=>Object.fromEntries(d.map((t,r)=>[t||`column_${r+1}`,e[r]??""]))),null,2),r.replace(/\.[^.]+$/,"")+".json","application/json;charset=utf-8")},style:{padding:"2px 8px",fontSize:11,cursor:"pointer",background:"var(--bg-hover)",color:"var(--text-muted)",border:"1px solid var(--border)",borderRadius:5},children:"Export JSON"})]})]}),(0,n.jsx)("div",{style:{minHeight:0,flex:1,overflow:"auto",background:"var(--bg)"},children:(0,n.jsxs)("table",{style:{width:"100%",borderCollapse:"collapse",tableLayout:"fixed",fontSize:12},children:[(0,n.jsx)("thead",{style:{position:"sticky",top:0,zIndex:1,background:"var(--bg-panel)"},children:(0,n.jsx)("tr",{children:d.map((e,t)=>(0,n.jsx)("th",{onClick:()=>{i===t?a(e=>"asc"===e?"desc":"asc"):(l(t),a("asc"))},title:e,style:{padding:"8px 10px",borderBottom:"1px solid var(--border)",textAlign:"left",color:"var(--text-muted)",fontWeight:600,cursor:"pointer",userSelect:"none",fontSize:11,whiteSpace:"nowrap"},children:(0,n.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:6,minWidth:0},children:[(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis"},children:e||`column_${t+1}`}),i===t&&(0,n.jsx)("span",{style:{color:"var(--accent)",display:"inline-flex",flexShrink:0},children:(0,n.jsx)(rK,{dir:s})})]})},`${e}-${t}`))})}),(0,n.jsx)("tbody",{children:u.map((e,t)=>(0,n.jsx)("tr",{style:{borderBottom:"1px solid rgba(127,127,127,0.14)",background:t%2==1?"var(--bg-subtle)":"transparent"},children:d.map((r,o)=>(0,n.jsx)("td",{title:e[o]??"",style:{padding:"6px 10px",color:"var(--text)",fontFamily:"var(--font-mono)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:0},children:e[o]??""},`${r}-${t}-${o}`))},t))})]})})]})}let rY=new Set(["png","jpg","jpeg","gif","webp","svg","bmp","ico","avif"]),rG=new Set(["mp3","wav","ogg","oga","opus","m4a","aac","flac","weba","webm"]),rX=new Set(["pdf","docx","xlsx","pptx","doc","xls","ppt"]);function rQ(e){let t=ec(e).toLowerCase().split(".").pop()??"";return"csv"===t?",":"tsv"===t?" ":null}function r0(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function r1({oldContent:e,newContent:t}){let r=function(e,t){let r=e.length,n=t.length,o=r+n,i=Array(2*o+1).fill(0),l=[];for(let s=0;s<=o;s++){l.push([...i]);for(let a=-s;a<=s;a+=2){let d,c=(d=a===-s||a!==s&&i[a-1+o]<i[a+1+o]?i[a+1+o]:i[a-1+o]+1)-a;for(;d<r&&c<n&&e[d]===t[c];)d++,c++;if(i[a+o]=d,d>=r&&c>=n){let i=[],a=r,d=n;for(let r=s;r>0;r--){let n,s=l[r-1],c=a-d;n=c===-r||c!==r&&s[c-1+o]<s[c+1+o]?c+1:c-1;let u=s[n+o],p=u-n;for(;a>u&&d>p;)a--,d--,i.unshift({type:"unchanged",text:e[a],lineNo:a+1});r>0&&(a>u?(a--,i.unshift({type:"removed",text:e[a],lineNo:a+1})):(d--,i.unshift({type:"added",text:t[d],lineNo:d+1})))}for(;a>0&&d>0;)a--,d--,i.unshift({type:"unchanged",text:e[a],lineNo:a+1});return i}}}return[...e.map((e,t)=>({type:"removed",text:e,lineNo:t+1})),...t.map((e,t)=>({type:"added",text:e,lineNo:t+1}))]}(e.split("\n"),t.split("\n"));if(!r.some(e=>"unchanged"!==e.type))return(0,n.jsx)("div",{style:{padding:"12px 16px",fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:"No changes"});let o=new Set(r.flatMap((e,t)=>"unchanged"!==e.type?[t]:[])),i=new Set;for(let e of o)for(let t=Math.max(0,e-3);t<=Math.min(r.length-1,e+3);t++)i.add(t);let l=[],s=0;for(;s<r.length;)if(i.has(s)){let e=[];for(;s<r.length&&i.has(s);)e.push(r[s]),s++;l.push({hidden:!1,lines:e})}else{let e=0;for(;s<r.length&&!i.has(s);)e++,s++;l.push({hidden:!0,count:e})}let a=[],d=1;for(let e of r)"removed"===e.type?a.push(0):a.push(d++);let c=0;return(0,n.jsx)("div",{style:{fontFamily:"var(--font-mono)",fontSize:13,lineHeight:1.6},children:l.map((e,t)=>{if(e.hidden){let r=(0,n.jsxs)("div",{style:{padding:"2px 16px",color:"var(--text-dim)",background:"var(--bg-panel)",fontSize:11,borderTop:"1px solid var(--border)",borderBottom:"1px solid var(--border)"},children:["... ",e.count," unchanged lines ..."]},t);return c+=e.count,r}let r=e.lines.map((e,t)=>{let r=a[c+t],o="added"===e.type?"rgba(0,200,80,0.12)":"removed"===e.type?"rgba(240,60,60,0.14)":"transparent",i="added"===e.type?"+":"removed"===e.type?"-":" ",l="added"===e.type?"#4ade80":"removed"===e.type?"#f87171":"var(--text-dim)";return(0,n.jsxs)("div",{style:{display:"flex",background:o,borderLeft:"added"===e.type?"3px solid #4ade80":"removed"===e.type?"3px solid #f87171":"3px solid transparent"},children:[(0,n.jsx)("span",{style:{minWidth:44,padding:"0 8px 0 16px",textAlign:"right",color:"var(--text-dim)",userSelect:"none",fontSize:11,lineHeight:1.6,borderRight:"1px solid var(--border)",background:"var(--bg-panel)",flexShrink:0},children:"removed"===e.type?e.lineNo:r||""}),(0,n.jsx)("span",{style:{minWidth:16,padding:"0 6px",color:l,userSelect:"none",flexShrink:0,fontWeight:600},children:i}),(0,n.jsx)("span",{style:{flex:1,padding:"0 8px 0 0",whiteSpace:"pre",color:"var(--text)",overflowX:"auto"},children:e.text||"\xa0"})]},t)});return c+=e.lines.length,(0,n.jsx)("div",{children:r},t)})})}function r2({filePath:e,cwd:t}){let[r,i]=(0,o.useState)(!1),[l,s]=(0,o.useState)(0),[a,d]=(0,o.useState)(null),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(null),[x,g]=(0,o.useState)(100),f=(0,o.useRef)(null),m=ec(e).toLowerCase().split(".").pop()??"";(0,o.useEffect)(()=>{s(0),d(null),u(null),h(null),i(!1),g(100),f.current&&(f.current.close(),f.current=null);let t=ed(e),r=new EventSource(`/api/files/${t}?type=watch`);return f.current=r,r.addEventListener("connected",()=>i(!0)),r.addEventListener("change",e=>{try{let t=JSON.parse(e.data);"number"==typeof t.size&&d(t.size)}catch{}s(e=>e+1)}),r.addEventListener("error",()=>i(!1)),r.onerror=()=>i(!1),()=>{r.close(),f.current=null}},[e]);let v=ed(e),y=`/api/files/${v}?type=read${l?`&v=${l}`:""}`,b=null!=a?r0(a):null,j=e=>g(Math.max(10,Math.min(500,e)));return(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:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)"},title:e,children:eu(e,t)}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4,flexShrink:0},children:[(0,n.jsx)("button",{onClick:()=>j(x-25),title:"Zoom out",style:{width:24,height:22,border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:13,lineHeight:1},children:"-"}),(0,n.jsx)("select",{value:x,onChange:e=>j(Number(e.target.value)),title:"Image zoom",style:{height:22,border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:"var(--text)",fontSize:11,fontFamily:"var(--font-mono)",outline:"none",cursor:"pointer"},children:[25,50,75,100,125,150,200,300].map(e=>(0,n.jsxs)("option",{value:e,children:[e,"%"]},e))}),(0,n.jsx)("button",{onClick:()=>j(x+25),title:"Zoom in",style:{width:24,height:22,border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:13,lineHeight:1},children:"+"})]}),(0,n.jsx)("span",{style:{flexShrink:0},children:m||"image"}),c&&(0,n.jsxs)("span",{children:[c.w," \xd7 ",c.h]}),b&&(0,n.jsx)("span",{children:b}),(0,n.jsxs)("span",{title:r?"Live sync active":"Not watching",style:{display:"flex",alignItems:"center",gap:4,color:r?"#4ade80":"var(--text-dim)"},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:r?"#4ade80":"var(--border)",display:"inline-block",boxShadow:r?"0 0 4px #4ade80":"none"}}),r?"live":"static"]})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"auto",background:"var(--bg-panel)",WebkitOverflowScrolling:"touch",overscrollBehavior:"contain",backgroundImage:"linear-gradient(45deg, var(--bg) 25%, transparent 25%), linear-gradient(-45deg, var(--bg) 25%, transparent 25%), linear-gradient(45deg, transparent 75%, var(--bg) 75%), linear-gradient(-45deg, transparent 75%, var(--bg) 75%)",backgroundSize:"16px 16px",backgroundPosition:"0 0, 0 8px, 8px -8px, -8px 0px"},children:p?(0,n.jsx)("div",{style:{minWidth:"100%",minHeight:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#f87171",fontSize:13},children:p}):(0,n.jsx)("div",{style:{minWidth:"100%",minHeight:"100%",width:"max-content",height:"max-content",boxSizing:"border-box",display:"flex",alignItems:"flex-start",justifyContent:"flex-start",padding:16},children:(0,n.jsx)("img",{src:y,alt:e,onLoad:e=>{let t=e.currentTarget;u({w:t.naturalWidth,h:t.naturalHeight})},onError:()=>h("Failed to load image"),style:{width:c?Math.max(1,Math.round(c.w*x/100)):"auto",height:c?Math.max(1,Math.round(c.h*x/100)):"auto",maxWidth:"none",maxHeight:"none",objectFit:"contain",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"}})})})]})}function r4({filePath:e,cwd:t}){let[r,i]=(0,o.useState)(!1),[l,s]=(0,o.useState)(0),[a,d]=(0,o.useState)(null),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(null),x=(0,o.useRef)(null),g=ec(e).toLowerCase().split(".").pop()??"";(0,o.useEffect)(()=>{s(0),d(null),u(null),h(null),i(!1),x.current&&(x.current.close(),x.current=null);let t=ed(e),r=new EventSource(`/api/files/${t}?type=watch`);return x.current=r,r.addEventListener("connected",()=>i(!0)),r.addEventListener("change",e=>{try{let t=JSON.parse(e.data);"number"==typeof t.size&&d(t.size)}catch{}u(null),h(null),s(e=>e+1)}),r.addEventListener("error",()=>i(!1)),r.onerror=()=>i(!1),()=>{r.close(),x.current=null}},[e]);let f=ed(e),m=`/api/files/${f}?type=read${l?`&v=${l}`:""}`;return(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)"},title:e,children:eu(e,t)}),(0,n.jsx)("span",{style:{marginLeft:"auto"},children:g||"audio"}),null!=c&&(0,n.jsx)("span",{children:function(e){if(!Number.isFinite(e))return"";let t=Math.round(e),r=Math.floor(t/60);return`${r}:${String(t%60).padStart(2,"0")}`}(c)}),null!=a&&(0,n.jsx)("span",{children:r0(a)}),(0,n.jsxs)("span",{title:r?"Live sync active":"Not watching",style:{display:"flex",alignItems:"center",gap:4,color:r?"#4ade80":"var(--text-dim)"},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:r?"#4ade80":"var(--border)",display:"inline-block",boxShadow:r?"0 0 4px #4ade80":"none"}}),r?"live":"static"]})]}),(0,n.jsx)("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",padding:24,background:"var(--bg-panel)"},children:(0,n.jsxs)("div",{style:{width:"min(680px, 100%)"},children:[p&&(0,n.jsx)("div",{style:{color:"#f87171",fontSize:13,marginBottom:12,textAlign:"center"},children:p}),(0,n.jsx)("audio",{controls:!0,preload:"metadata",src:m,onLoadedMetadata:e=>u(e.currentTarget.duration),onError:()=>h("Failed to load audio"),style:{width:"100%"}},m)]})})]})}function r5({filePath:e,cwd:t,onOpenFile:r}){let o,i,l;return(o=ec(e).toLowerCase().split(".").pop()??"",rY.has(o))?(0,n.jsx)(r2,{filePath:e,cwd:t}):(i=ec(e).toLowerCase().split(".").pop()??"",rG.has(i))?(0,n.jsx)(r4,{filePath:e,cwd:t}):(l=ec(e).toLowerCase().split(".").pop()??"",rX.has(l))?(0,n.jsx)(r6,{filePath:e,cwd:t}):(0,n.jsx)(r3,{filePath:e,cwd:t,onOpenFile:r})}function r6({filePath:e,cwd:t}){let r,[i,l]=(0,o.useState)(null),[s,a]=(0,o.useState)(!0),[d,c]=(0,o.useState)(null),u=(0,o.useRef)(null),p=(0,o.useRef)(0),h="pdf"===(r=ec(e).toLowerCase().split(".").pop()??"")?"pdf":"docx"===r||"doc"===r?"docx":"xlsx"===r||"xls"===r?"xlsx":"pptx"===r||"ppt"===r?"pptx":"other",x=ec(e).toLowerCase().split(".").pop()??"",g=(0,o.useCallback)(async e=>{try{let t=ed(e),r=p.current?`&v=${p.current}`:"",n=await fetch(`/api/files/${t}?type=read${r}`);if(!n.ok){let e=await n.json().catch(()=>({error:String(n.status)}));c(e.error??`HTTP ${n.status}`);return}let o=await n.arrayBuffer();l(o),c(null)}catch(e){c(String(e))}},[]);if((0,o.useEffect)(()=>{a(!0),c(null),l(null),p.current=0,u.current&&(u.current.close(),u.current=null),g(e).finally(()=>a(!1));let t=ed(e),r=new EventSource(`/api/files/${t}?type=watch`);return u.current=r,r.addEventListener("connected",()=>{}),r.addEventListener("change",()=>{p.current+=1,g(e)}),r.addEventListener("error",()=>{}),r.onerror=()=>{},()=>{r.close(),u.current=null}},[e,g]),s&&!i)return(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:"Loading..."});if(d&&!i)return(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#f87171",fontSize:13},children:d});if(!i)return null;let f=eu(e,t);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:["pdf"===h&&(0,n.jsx)(rk,{arrayBuffer:i,fileName:f}),"docx"===h&&(0,n.jsx)(rS,{arrayBuffer:i,fileName:f}),"xlsx"===h&&(0,n.jsx)(rC,{arrayBuffer:i,fileName:f}),"pptx"===h&&(0,n.jsx)(rz,{arrayBuffer:i,fileName:f}),"other"===h&&(0,n.jsxs)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:["Unsupported document format: .",x]})]})}function r3({filePath:e,cwd:t,onOpenFile:r}){let{isDark:i}=$(),[l,s]=(0,o.useState)(null),[a,d]=(0,o.useState)(null),[c,u]=(0,o.useState)(!0),[p,h]=(0,o.useState)(null),[x,g]=(0,o.useState)(null),[f,m]=(0,o.useState)(!1),[v,y]=(0,o.useState)("source"),[b,j]=(0,o.useState)(!1),[k,w]=(0,o.useState)(!1),[S,C]=(0,o.useState)(0),[z,T]=(0,o.useState)(!1),[I,L]=(0,o.useState)(""),[R,W]=(0,o.useState)(!1),[E,A]=(0,o.useState)(!1),[B,N]=(0,o.useState)(!1),[P,D]=(0,o.useState)(null),O=(0,o.useRef)(null),H=(0,o.useRef)(!1);H.current=z,(0,o.useRef)(null).current=l;let F=(0,o.useCallback)((e,t=!1)=>{let r=ed(e);return fetch(`/api/files/${r}?type=read`).then(e=>e.json()).then(e=>e.error?(h(e.error),null):(t?(s(t=>(t&&d(t.content),e)),C(e=>e+1)):s(e),h(null),e)).catch(e=>(h(String(e)),null))},[]);(0,o.useEffect)(()=>{u(!0),h(null),s(null),d(null),m(!1),y("source"),j(!1),C(0),w(!1),O.current&&(O.current.close(),O.current=null),F(e).then(t=>{(t?.language==="markdown"||rQ(e))&&m(!0)}).finally(()=>u(!1));let t=ed(e),r=new EventSource(`/api/files/${t}?type=watch`);return O.current=r,r.addEventListener("connected",()=>{w(!0)}),r.addEventListener("change",()=>{H.current?A(!0):F(e,!0)}),r.addEventListener("error",()=>{w(!1)}),r.onerror=()=>{w(!1)},()=>{r.close(),O.current=null}},[e,F]);let _=(0,o.useCallback)(()=>{l&&(T(!0),L(l.content),D(l.mtime??null),N(!1),g(null),A(!1),m(!1),y("source"))},[l]),U=(0,o.useCallback)(async(t=!1)=>{let r=ed(e);W(!0),N(!1),g(null);try{let n=await fetch(`/api/files/${r}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:I,...t||!P?{}:{baseMtime:P}})});if(409===n.status){let e=await n.json().catch(()=>({error:"File changed on disk since it was opened"}));throw N(!0),A(!0),Error(e.error??"File changed on disk since it was opened")}if(!n.ok){let e=await n.json().catch(()=>({error:String(n.status)}));throw Error(e.error??`HTTP ${n.status}`)}let o=await F(e,!0);D(o?.mtime??null),T(!1),A(!1),N(!1)}catch(e){g(e instanceof Error?e.message:String(e))}finally{W(!1)}},[e,I,P,F]),V=(0,o.useCallback)(()=>{T(!1),A(!1),N(!1),g(null),D(null)},[]),q=(0,o.useCallback)(async()=>{let t=await F(e,!0);t&&(L(t.content),D(t.mtime??null),A(!1),N(!1),g(null),h(null))},[F,e]);if(c)return(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:"Loading..."});if(p)return(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#f87171",fontSize:13},children:p});if(!l)return null;let K="html"===l.language,J="markdown"===l.language,Z=rQ(e),Y=null!==Z,G=l.content.split("\n"),X=null!==a&&a!==l.content;return(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)"},title:e,children:eu(e,t)}),(0,n.jsx)("span",{style:{marginLeft:"auto"},children:l.language}),"source"===v&&(0,n.jsxs)("span",{children:[G.length," lines"]}),(0,n.jsx)("span",{children:r0(l.size)}),(0,n.jsxs)("span",{title:k?"Live sync active":"Not watching",style:{display:"flex",alignItems:"center",gap:4,color:k?"#4ade80":"var(--text-dim)"},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:k?"#4ade80":"var(--border)",display:"inline-block",boxShadow:k?"0 0 4px #4ade80":"none"}}),k?"live":"static"]}),z?(0,n.jsxs)(n.Fragment,{children:[(E||B||x)&&(0,n.jsxs)("span",{title:"File changed on disk while editing",style:{padding:"2px 8px",fontSize:11,background:"rgba(234,179,8,0.1)",color:"#b8860b",border:"1px solid rgba(234,179,8,0.3)",borderRadius:5,display:"flex",alignItems:"center",gap:4},children:[(0,n.jsxs)("svg",{width:"10",height:"10",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:"10"}),(0,n.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,n.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),x??"External change",(E||B)&&(0,n.jsx)("button",{onClick:q,style:{marginLeft:4,padding:"1px 6px",fontSize:10,cursor:"pointer",background:"rgba(234,179,8,0.2)",color:"#b8860b",border:"1px solid rgba(234,179,8,0.3)",borderRadius:3,fontWeight:600},children:"Reload"}),B&&(0,n.jsx)("button",{onClick:()=>void U(!0),disabled:R,style:{marginLeft:4,padding:"1px 6px",fontSize:10,cursor:R?"not-allowed":"pointer",background:"rgba(239,68,68,0.12)",color:"#ef4444",border:"1px solid rgba(239,68,68,0.3)",borderRadius:3,fontWeight:600},children:"Overwrite"})]}),(0,n.jsx)("button",{onClick:()=>void U(),disabled:R,title:"Save file (Ctrl+S)",style:{padding:"2px 10px",fontSize:11,cursor:R?"not-allowed":"pointer",background:"var(--accent)",color:"#fff",border:"1px solid var(--accent)",borderRadius:5,fontWeight:600,opacity:R?.6:1},children:R?"Saving…":"Save"}),(0,n.jsx)("button",{onClick:V,title:"Cancel editing",style:{padding:"2px 10px",fontSize:11,cursor:"pointer",background:"var(--bg-hover)",color:"var(--text-muted)",border:"1px solid var(--border)",borderRadius:5,fontWeight:600},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.1)",e.currentTarget.style.color="#ef4444",e.currentTarget.style.borderColor="rgba(239,68,68,0.3)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:"Cancel"})]}):(0,n.jsx)("button",{onClick:_,title:"Edit file",style:{padding:"2px 10px",fontSize:11,cursor:"pointer",background:"var(--bg-hover)",color:"var(--text-muted)",border:"1px solid var(--border)",borderRadius:5,fontWeight:600},onMouseEnter:e=>{e.currentTarget.style.background="var(--accent)",e.currentTarget.style.color="#fff",e.currentTarget.style.borderColor="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:"Edit"}),X&&(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,overflow:"hidden",border:"1px solid var(--border)"},children:[(0,n.jsx)("button",{onClick:()=>y("source"),style:{padding:"2px 8px",fontSize:11,border:"none",cursor:"pointer",background:"source"===v?"var(--bg-selected)":"var(--bg-hover)",color:"source"===v?"var(--text)":"var(--text-muted)",fontWeight:"source"===v?600:400},children:"Source"}),(0,n.jsxs)("button",{onClick:()=>y("diff"),style:{padding:"2px 8px",fontSize:11,border:"none",borderLeft:"1px solid var(--border)",cursor:"pointer",background:"diff"===v?"var(--bg-selected)":"var(--bg-hover)",color:"diff"===v?"var(--text)":"var(--text-muted)",fontWeight:"diff"===v?600:400},children:["Diff ",S>0&&(0,n.jsxs)("span",{style:{color:"#4ade80",marginLeft:2},children:["+",S]})]})]}),"source"===v&&!f&&(0,n.jsx)("button",{onClick:()=>j(e=>!e),title:b?"Disable word wrap":"Enable word wrap",style:{padding:"2px 8px",fontSize:11,cursor:"pointer",background:b?"var(--bg-selected)":"var(--bg-hover)",color:b?"var(--text)":"var(--text-muted)",border:"1px solid var(--border)",borderRadius:5,fontWeight:b?600:400},children:"wrap"}),K&&"source"===v&&(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,overflow:"hidden",border:"1px solid var(--border)"},children:[(0,n.jsx)("button",{onClick:()=>m(!1),style:{padding:"2px 8px",fontSize:11,border:"none",cursor:"pointer",background:f?"var(--bg-hover)":"var(--bg-selected)",color:f?"var(--text-muted)":"var(--text)",fontWeight:f?400:600},children:"Code"}),(0,n.jsx)("button",{onClick:()=>m(!0),style:{padding:"2px 8px",fontSize:11,border:"none",borderLeft:"1px solid var(--border)",cursor:"pointer",background:f?"var(--bg-selected)":"var(--bg-hover)",color:f?"var(--text)":"var(--text-muted)",fontWeight:f?600:400},children:"Preview"})]}),J&&"source"===v&&(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,overflow:"hidden",border:"1px solid var(--border)"},children:[(0,n.jsx)("button",{onClick:()=>m(!0),style:{padding:"2px 8px",fontSize:11,border:"none",cursor:"pointer",background:f?"var(--bg-selected)":"var(--bg-hover)",color:f?"var(--text)":"var(--text-muted)",fontWeight:f?600:400},children:"Preview"}),(0,n.jsx)("button",{onClick:()=>m(!1),style:{padding:"2px 8px",fontSize:11,border:"none",borderLeft:"1px solid var(--border)",cursor:"pointer",background:f?"var(--bg-hover)":"var(--bg-selected)",color:f?"var(--text-muted)":"var(--text)",fontWeight:f?400:600},children:z?"Edit":"Raw"})]}),Y&&"source"===v&&(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,overflow:"hidden",border:"1px solid var(--border)"},children:[(0,n.jsx)("button",{onClick:()=>m(!0),style:{padding:"2px 8px",fontSize:11,border:"none",cursor:"pointer",background:f?"var(--bg-selected)":"var(--bg-hover)",color:f?"var(--text)":"var(--text-muted)",fontWeight:f?600:400},children:"Table"}),(0,n.jsx)("button",{onClick:()=>m(!1),style:{padding:"2px 8px",fontSize:11,border:"none",borderLeft:"1px solid var(--border)",cursor:"pointer",background:f?"var(--bg-hover)":"var(--bg-selected)",color:f?"var(--text-muted)":"var(--text)",fontWeight:f?400:600},children:"Raw"})]})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"auto",background:"var(--bg)"},children:z&&!(J&&f)?(0,n.jsx)(rq,{initialContent:I,language:l.language,isDark:i,onChange:L,onSave:()=>void U()}):z&&J&&f?(0,n.jsx)(em,{content:I,className:"markdown-body markdown-file-preview",codeBlockVariant:"file",baseFilePath:e,onOpenLocalFile:r,style:{padding:"28px 36px",maxWidth:920,margin:"0 auto"}}):"diff"===v&&X?(0,n.jsx)(r1,{oldContent:a,newContent:l.content,language:l.language}):K&&f?(0,n.jsx)("iframe",{srcDoc:l.content,sandbox:"allow-scripts",style:{width:"100%",height:"100%",border:"none",background:"var(--bg)"},title:"HTML preview"}):J&&f?(0,n.jsx)(em,{content:l.content,className:"markdown-body markdown-file-preview",codeBlockVariant:"file",baseFilePath:e,onOpenLocalFile:r,style:{padding:"28px 36px",maxWidth:920,margin:"0 auto"}}):Y&&f&&Z?(0,n.jsx)(rZ,{content:l.content,delimiter:Z,fileName:ec(e)}):(0,n.jsx)(M.A,{language:"text"===l.language||"csv"===l.language||"tsv"===l.language?"plaintext":l.language,style:es(i),showLineNumbers:!0,lineNumberStyle:{color:"var(--text-dim)",fontStyle:"normal",minWidth:"3em",paddingRight:"1em"},customStyle:{margin:0,padding:"12px 0",background:"var(--bg)",fontSize:13,lineHeight:1.6,fontFamily:"var(--font-mono)",minHeight:"100%"},codeTagProps:{style:{fontFamily:"var(--font-mono)"}},wrapLongLines:b,children:l.content})})]})}function r8(e,t,r){return Math.min(Math.max(e,t),r)}function r7({src:e,alt:t}){return(0,n.jsx)("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",background:"var(--bg)",overflow:"auto",padding:12},children:(0,n.jsx)("img",{src:e,alt:t,style:{display:"block",maxWidth:"100%",maxHeight:"100%",objectFit:"contain",margin:"auto",boxShadow:"0 10px 30px rgba(0,0,0,0.22)"}})})}function r9({id:e,filePath:t,fileName:r,cwd:i,galleryItems:l,galleryIndex:s=0,active:a,stackIndex:d,zIndex:c,onClose:u,onFocus:p,onOpenFile:h,onOpenImage:x}){let[g,f]=(0,o.useState)(()=>{let e,t,r,n,o,i,l;return e=window.innerWidth,t=window.innerHeight,n=(r=e<720||t<560)?8:36,i=Math.max(320,e-2*n-(o=r?0:d%6*28)),l=Math.max(260,t-2*n-o),{left:n+o,top:n+o,width:r?i:Math.min(1180,i),height:r?l:Math.min(820,l),maximized:!1}}),[m,v]=(0,o.useState)(!1),[y,b]=(0,o.useState)(!1),j=(0,o.useRef)(null),k=(0,o.useRef)(null),w=(0,o.useRef)(null),S=!!x&&!!l&&l.length>1,C=/^data:image\//i.test(t)||/^(https?:)?\/\//i.test(t),z=S?l[(s-1+l.length)%l.length]:null,T=S?l[(s+1)%l.length]:null,I=(0,o.useCallback)(e=>{if(!S||!x||!l)return;let t=e<0?(s-1+l.length)%l.length:(s+1)%l.length,r=l[t];r&&x(r.src,r.title,l)},[S,s,l,x]);(0,o.useEffect)(()=>{a&&j.current?.focus({preventScroll:!0})},[a]),(0,o.useEffect)(()=>{let e=()=>{f(e=>{if(e.maximized)return e;let t=Math.max(320,window.innerWidth-16),r=Math.max(260,window.innerHeight-16),n=Math.min(e.width,t),o=Math.min(e.height,r);return{...e,width:n,height:o,left:r8(e.left,8,Math.max(8,window.innerWidth-n-8)),top:r8(e.top,8,Math.max(8,window.innerHeight-o-8))}})};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]);let M=(0,o.useCallback)(t=>{p(e),0!==t.button||g.maximized||(t.preventDefault(),t.currentTarget.setPointerCapture(t.pointerId),k.current={pointerId:t.pointerId,startX:t.clientX,startY:t.clientY,left:g.left,top:g.top},v(!0))},[g.left,g.maximized,g.top,e,p]),L=(0,o.useCallback)(e=>{let t=k.current;if(!t||t.pointerId!==e.pointerId)return;let r=t.left+e.clientX-t.startX,n=t.top+e.clientY-t.startY;f(e=>({...e,left:r8(r,8,Math.max(8,window.innerWidth-120)),top:r8(n,8,Math.max(8,window.innerHeight-48))}))},[]),R=(0,o.useCallback)(e=>{let t=k.current;t?.pointerId===e.pointerId&&(e.currentTarget.releasePointerCapture(e.pointerId),k.current=null,v(!1))},[]),W=(0,o.useCallback)(()=>{p(e),f(e=>({...e,maximized:!e.maximized}))},[e,p]),E=(0,o.useCallback)(t=>{p(e),0!==t.button||g.maximized||(t.preventDefault(),t.stopPropagation(),t.currentTarget.setPointerCapture(t.pointerId),w.current={pointerId:t.pointerId,startX:t.clientX,startY:t.clientY,width:g.width,height:g.height},b(!0))},[g.height,g.maximized,g.width,e,p]),$=(0,o.useCallback)(e=>{let t=w.current;if(!t||t.pointerId!==e.pointerId)return;let r=t.width+e.clientX-t.startX,n=t.height+e.clientY-t.startY;f(e=>({...e,width:r8(r,360,Math.max(360,window.innerWidth-e.left-8)),height:r8(n,280,Math.max(280,window.innerHeight-e.top-8))}))},[]),A=(0,o.useCallback)(e=>{let t=w.current;t?.pointerId===e.pointerId&&(e.currentTarget.releasePointerCapture(e.pointerId),w.current=null,b(!1))},[]),B=g.maximized?{position:"fixed",inset:12,zIndex:c}:{position:"fixed",left:g.left,top:g.top,width:g.width,height:g.height,zIndex:c};return(0,n.jsxs)("div",{ref:j,role:"dialog","aria-label":`Preview ${r}`,tabIndex:-1,onPointerDown:()=>p(e),onKeyDown:t=>{"Escape"===t.key&&u(e),"ArrowLeft"===t.key&&(t.preventDefault(),I(-1)),"ArrowRight"===t.key&&(t.preventDefault(),I(1))},style:{...B,display:"flex",flexDirection:"column",minWidth:g.maximized?void 0:360,minHeight:g.maximized?void 0:280,background:"var(--bg)",border:a?"1px solid rgba(37,99,235,0.55)":"1px solid var(--border)",borderRadius:8,boxShadow:a?"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:M,onPointerMove:L,onPointerUp:R,onPointerCancel:R,style:{height:34,display:"flex",alignItems:"center",gap:8,padding:"0 8px 0 12px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",cursor:g.maximized?"default":m?"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})}),S&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4,flexShrink:0},children:[(0,n.jsx)("button",{type:"button",onPointerDown:e=>e.stopPropagation(),onClick:()=>I(-1),title:z?.title?`Previous: ${z.title}`:"Previous image","aria-label":"Previous image",style:ne,children:(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,n.jsx)("polyline",{points:"10 3 5 8 10 13"})})}),(0,n.jsxs)("span",{style:{minWidth:40,textAlign:"center",fontSize:11,color:"var(--text-dim)",fontVariantNumeric:"tabular-nums"},children:[s+1,"/",l?.length]}),(0,n.jsx)("button",{type:"button",onPointerDown:e=>e.stopPropagation(),onClick:()=>I(1),title:T?.title?`Next: ${T.title}`:"Next image","aria-label":"Next image",style:ne,children:(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,n.jsx)("polyline",{points:"6 3 11 8 6 13"})})})]}),(0,n.jsx)("button",{type:"button",onPointerDown:e=>e.stopPropagation(),onClick:W,title:g.maximized?"Restore preview":"Maximize preview","aria-label":g.maximized?"Restore preview":"Maximize preview",style:ne,children:g.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:()=>u(e),title:"Close preview","aria-label":"Close preview",style:ne,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:C?(0,n.jsx)(r7,{src:t,alt:r}):(0,n.jsx)(r5,{filePath:t,cwd:i,onOpenFile:h})}),!g.maximized&&(0,n.jsx)("div",{role:"separator","aria-orientation":"horizontal","aria-label":"Resize preview",title:"Resize preview",onPointerDown:E,onPointerMove:$,onPointerUp:A,onPointerCancel:A,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 ne={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},nt={__soul__:{apiPath:"/api/soul",title:"SOUL.md"},__harness__:{apiPath:"/api/harness",title:"HARNESS.md"}};function nr({filePath:e}){let t=nt[e],{isDark:r}=$(),[i,l]=(0,o.useState)(""),[s,a]=(0,o.useState)(!0),[d,c]=(0,o.useState)(null),[u,p]=(0,o.useState)(!1),[h,x]=(0,o.useState)(!1);(0,o.useEffect)(()=>{t&&(a(!0),fetch(t.apiPath).then(e=>e.json()).then(e=>l(e.content??"")).catch(e=>c(String(e))).finally(()=>a(!1)))},[t]);let g=(0,o.useCallback)(async()=>{if(t){p(!0);try{await fetch(t.apiPath,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:i})}),x(!0),setTimeout(()=>x(!1),2e3)}catch(e){c(String(e))}finally{p(!1)}}},[t,i]);return t?s?(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:"Loading…"}):d?(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#f87171",fontSize:13},children:d}):(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"4px 16px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",background:"var(--bg)",flexShrink:0},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontWeight:600,color:"var(--text)"},children:t.title}),(0,n.jsx)("span",{style:{marginLeft:"auto",fontSize:10,color:"var(--text-dim)"},children:"Global"}),h&&(0,n.jsx)("span",{style:{color:"#4ade80",fontWeight:600,animation:"saved-pop 0.3s ease"},children:"✓ Saved"}),(0,n.jsx)("button",{onClick:g,disabled:u,title:"Save (Ctrl+S)",style:{padding:"2px 10px",fontSize:11,cursor:u?"not-allowed":"pointer",background:"var(--accent)",color:"#fff",border:"1px solid var(--accent)",borderRadius:5,fontWeight:600,opacity:u?.6:1},children:u?"Saving…":"Save"})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"hidden"},children:(0,n.jsx)(rq,{initialContent:i,language:"markdown",isDark:r,onChange:l,onSave:g})})]}):null}function nn(){document.body.style.cursor="",document.body.style.userSelect=""}function no({side:e,onResize:t,onResizeStart:r,onResizeEnd:i,ariaLabel:l}){let s=(0,o.useRef)(null),a=(0,o.useRef)(!1),d=(0,o.useRef)(0),[c,u]=(0,o.useState)(!1),p=(0,o.useCallback)(e=>{if(!a.current)return;a.current=!1,u(!1);let t=s.current;t&&void 0!==e&&t.hasPointerCapture(e)&&t.releasePointerCapture(e),nn(),i?.()},[i]),h=(0,o.useCallback)(e=>{0===e.button&&e.isPrimary&&(e.preventDefault(),a.current=!0,d.current=e.clientX,u(!0),r?.(),e.currentTarget.setPointerCapture(e.pointerId),document.body.style.cursor="col-resize",document.body.style.userSelect="none")},[r]),x=(0,o.useCallback)(e=>{if(!a.current)return;e.preventDefault();let r=e.clientX-d.current;d.current=e.clientX,t(r)},[t]),g=(0,o.useCallback)(e=>{e.preventDefault(),p(e.pointerId)},[p]),f=(0,o.useCallback)(e=>{p(e.pointerId)},[p]);return(0,o.useEffect)(()=>()=>{a.current&&(a.current=!1,nn(),i?.())},[i]),(0,n.jsx)("div",{ref:s,role:"separator","aria-label":l??"Resize panel","aria-orientation":"vertical",className:`resize-handle${c?" resize-handle-dragging":""}`,"data-side":e,onPointerDown:h,onPointerMove:x,onPointerUp:g,onPointerCancel:f,style:{alignSelf:"stretch",cursor:"col-resize",display:"flex",flexShrink:0,justifyContent:"center",marginLeft:-5,marginRight:-5,position:"relative",touchAction:"none",width:10,zIndex:250},children:(0,n.jsx)("div",{className:"resize-handle-line"})})}function ni({tabs:e,activeTabId:t,onSelectTab:r,onCloseTab:i}){let[l,s]=(0,o.useState)(null);return(0,n.jsx)("div",{style:{display:"flex",alignItems:"flex-end",background:"var(--bg-panel)",overflowX:"auto",flexShrink:0,height:36},children:e.map(e=>{let o=e.id===t,a=!1!==e.closable;return(0,n.jsxs)("div",{onClick:()=>r(e.id),style:{display:"flex",alignItems:"center",gap:6,height:36,paddingLeft:12,paddingRight:6,borderRight:"1px solid var(--border)",background:o?"var(--bg)":"var(--bg-panel)",cursor:"pointer",fontSize:12,color:o?"var(--text)":"var(--text-muted)",whiteSpace:"nowrap",maxWidth:180,minWidth:80,flexShrink:0,userSelect:"none",transition:"background 0.1s, color 0.1s"},children:[(0,n.jsx)("span",{style:{flexShrink:0,opacity:o?1:.7,display:"flex",alignItems:"center"},children:"files"===e.icon?(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 6a2 2 0 0 1 2-2h5l2 2h7a2 2 0 0 1 2 2v3"}),(0,n.jsx)("path",{d:"M3 6v12a2 2 0 0 0 2 2h8"}),(0,n.jsx)("path",{d:"M17 13v7"}),(0,n.jsx)("path",{d:"M14 16h6"}),(0,n.jsx)("path",{d:"M14 20h6"})]}):"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.1a5 5 0 0 1-6.6 6.6L7.3 19.7a2.1 2.1 0 0 1-3-3l6.9-6.9a5 5 0 0 1 6.6-6.6l-3.1 3.1Z"})}):rc(e.filePath??e.label,13)}),(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",flex:1,fontWeight:o?500:400},title:e.filePath??e.label,children:e.label}),a&&(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),i(e.id)},onMouseEnter:()=>s(e.id),onMouseLeave:()=>s(null),style:{display:"flex",alignItems:"center",justifyContent:"center",width:16,height:16,background:l===e.id?"var(--bg-hover)":"transparent",border:"none",borderRadius:3,color:l===e.id?"var(--text)":"var(--text-dim)",cursor:"pointer",padding:0,flexShrink:0,transition:"background 0.1s, color 0.1s"},title:"Close",children:(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"2",y1:"2",x2:"8",y2:"8"}),(0,n.jsx)("line",{x1:"8",y1:"2",x2:"2",y2:"8"})]})})]},e.id)})})}function nl(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 ns(e){if(!e||!Number.isFinite(e))return"-";let t=Math.max(0,Math.floor(e/1e3)),r=Math.floor(t/3600),n=Math.floor(t%3600/60),o=t%60;return r>0?`${r}h ${n}m`:n>0?`${n}m ${o}s`:`${o}s`}function na(e){return e?ec(e)||e:"-"}function nd({refreshKey:e=0,cwd:t}){let[r,i]=(0,o.useState)(null),[l,s]=(0,o.useState)(null),[a,d]=(0,o.useState)(null),c=(0,o.useCallback)(async()=>{try{let e=await fetch("/api/agent/runtime",{cache:"no-store"}),t=await e.json();if(!e.ok||!Array.isArray(t.sessions))throw Error(t.error??`HTTP ${e.status}`);i(t),s(null)}catch(e){s(e instanceof Error?e.message:String(e))}},[]);(0,o.useEffect)(()=>{c()},[c,e]),(0,o.useEffect)(()=>{let e=window.setInterval(()=>{c()},3e3);return()=>window.clearInterval(e)},[c]);let u=(0,o.useCallback)(async e=>{d(e.sessionId),s(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 c()}catch(e){s(e instanceof Error?e.message:String(e))}finally{d(null)}},[c]),p=(0,o.useMemo)(()=>[...r?.sessions??[]].sort((e,t)=>{let r=+!!e.busy,n=+!!t.busy;return r!==n?n-r:Date.parse(t.lastEventAt??t.runStartedAt??"0")-Date.parse(e.lastEventAt??e.runStartedAt??"0")}),[r]),h=p.filter(e=>e.busy),x=h.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",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Tools"}),(0,n.jsxs)("div",{style:{marginTop:3,fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[h.length," agent running \xb7 ",r?.activeSessions??0," active",t?` \xb7 ${na(t)}`:""]})]}),(0,n.jsx)("button",{type:"button",onClick:()=>void c(),style:nh,title:"Refresh runtime",children:"Refresh"})]}),l&&(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:l})]}),(0,n.jsxs)("div",{style:{flex:1,overflow:"auto",padding:10},children:[(0,n.jsx)(nc,{title:"Agent Runtime",subtitle:x.length>0?`${x.length} waiting for first token`:`${h.length} active chat${1===h.length?"":"s"}`}),0===p.length?(0,n.jsx)(nu,{label:"No agent runtime is active."}):(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:p.map(e=>{var t;let r=e.model?`${e.model.provider}/${e.model.id}`:"-",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:nl(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:nl(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:[na(e.cwd)," \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)(np,{label:"uptime",value:ns(e.uptimeMs)}),(0,n.jsx)(np,{label:"wait",value:ns(e.waitingForModelMs),color:"waiting_model"===e.phase?nl(e.phase):void 0}),(0,n.jsx)(np,{label:"pending",value:null===e.pendingMessageCount?"-":String(e.pendingMessageCount)}),(0,n.jsx)(np,{label:"event",value:e.lastEventType??"-"}),(0,n.jsx)(np,{label:"tools",value:o||"-"}),(0,n.jsx)(np,{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. This usually means the upstream provider or gateway is still queueing the turn."}),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 u(e),disabled:!e.busy||a===e.sessionId,style:{...nh,border:"1px solid rgba(239,68,68,0.35)",color:"#ef4444",background:"rgba(239,68,68,0.08)",opacity:e.busy&&a!==e.sessionId?1:.55},children:"Abort"})})]},e.sessionId)})})]})]})}function nc({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 nu({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 np({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})]})}let nh={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},nx=["openai-responses","openai-completions"],ng=[/\/chat\/completions(?:$|[?#])/i,/deepseek/i,/moonshot|kimi/i,/dashscope|aliyun|qwen/i,/zhipu|bigmodel|chatglm|glm/i,/siliconflow/i,/volcengine|ark\.cn|doubao/i,/baichuan/i,/minimax/i,/stepfun|step-api/i,/lingyiwanwu|yi-api/i],nf=[/api\.openai\.com/i,/\/responses(?:$|[?#])/i];function nm(e,t,r="openai-responses"){let n=`${t??""} ${e??""}`.toLowerCase();return n.trim()?nf.some(e=>e.test(n))?"openai-responses":ng.some(e=>e.test(n))?"openai-completions":r:r}function nv(e,t="0 0 24 24"){let r=({size:r=24,style:o})=>(0,n.jsx)("svg",{width:r,height:r,viewBox:t,fill:"none",style:o,children:e});return r.displayName="ProviderIcon",r}let ny=nv((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"})),nb=nv((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"})),nj=nv((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"})]})),nk=nv((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"})]})),nw=nv((0,n.jsx)("path",{d:"M4 4h16v16H4z",fill:"#F55036"}),"0 0 24 24"),nS=nv((0,n.jsx)("path",{d:"M4 4h5v5H4zm5.5 0h5v5h-5zM15 4h5v5h-5zM4 9.5h5v5H4zm5.5 5.5h5v5h-5zM15 9.5h5v5h-5z",fill:"#FA6F00"})),nC=nv((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),"0 0 24 24"),nz=nv((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"})]})),nT=nv((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",fill:"#FF5722"}),"0 0 24 24"),nI=nv((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"})),nM=nv((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"})]})),nL=nv((0,n.jsx)("path",{d:"M12 2l9 5v10l-9 5-9-5V7l9-5z",stroke:"currentColor",strokeWidth:"1.5",fill:"none"})),nR=nv((0,n.jsx)("path",{d:"M4 4l8 8 8-8M4 20l8-8 8 8",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})),nW=nv((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"})),nE=nv((0,n.jsx)("path",{d:"M12 2L22 20H2L12 2z",fill:"currentColor"})),n$=nv((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),"0 0 24 24"),nA=nv((0,n.jsx)("path",{d:"M3 15h2l1-3h2l1 3h2V9H9v3L8 9H6l-1 3V9H3v6zm9 0h2v-2h2v-2h-2V9h-2v2h-2v2h2v2z",fill:"#FF9900"})),nB=nv((0,n.jsx)("path",{d:"M12 2L3 18h5l4-6 4 6h5L12 2z",fill:"#0078D4"})),nN=nv((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"})]})),nP=nv((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"})]})),nD=nv((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"})]})),nO=nv((0,n.jsx)("path",{d:"M4 8h16v2H4zm0 4h12v2H4zm0 4h8v2H4z",fill:"#3059B1"})),nH=nv((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"})),nF=nv((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",fill:"#0F6CBD"}),"0 0 24 24"),n_=nv((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),"0 0 24 24"),nU=[{id:"deepseek",displayName:"DeepSeek",baseUrl:"https://api.deepseek.com",api:"openai-completions",description:"Affordable, great for everyday coding and analysis tasks.",models:[{id:"deepseek-chat",contextWindow:1048576,maxTokens:8192},{id:"deepseek-reasoner",reasoning:!0,contextWindow:1048576,maxTokens:8192}]},{id:"moonshotai",displayName:"Moonshot AI",baseUrl:"https://api.moonshot.cn/v1",api:"openai-completions",description:"Kimi series — strong Chinese-language and long-context performance.",models:[{id:"moonshot-v1-auto",contextWindow:1048576,maxTokens:8192},{id:"kimi-k2",reasoning:!0,contextWindow:1048576,maxTokens:8192}]},{id:"zai",displayName:"Zhipu AI (GLM)",baseUrl:"https://open.bigmodel.cn/api/paas/v4",api:"openai-completions",description:"GLM-4 series — solid general-purpose models with competitive pricing.",models:[{id:"glm-4-plus",contextWindow:128e3,maxTokens:4096},{id:"glm-4-flash",contextWindow:128e3,maxTokens:4096}]},{id:"minimax",displayName:"MiniMax",baseUrl:"https://api.minimaxi.com/v1",api:"openai-completions",description:"Strong creative and conversational models at low cost.",models:[{id:"abab7-chat",contextWindow:1048576,maxTokens:8192},{id:"minimax-m1",reasoning:!0,contextWindow:1048576,maxTokens:8192}]},{id:"openrouter",displayName:"OpenRouter",baseUrl:"https://openrouter.ai/api/v1",api:"openai-responses",description:"Access 300+ models through a single API. Use Discover to browse available models.",models:[]}],nV={anthropic:{Icon:ny,hasColor:!1},openai:{Icon:nb,hasColor:!1},"openai-codex":{Icon:nb,hasColor:!1},google:{Icon:nj,hasColor:!0},"google-vertex":{Icon:nj,hasColor:!0},deepseek:{Icon:nk,hasColor:!0},groq:{Icon:nw,hasColor:!1},mistral:{Icon:nS,hasColor:!0},moonshotai:{Icon:nC,hasColor:!1},"moonshotai-cn":{Icon:nC,hasColor:!1},moonshot:{Icon:nC,hasColor:!1},minimax:{Icon:nz,hasColor:!0},"minimax-cn":{Icon:nz,hasColor:!0},fireworks:{Icon:nT,hasColor:!0},huggingface:{Icon:nI,hasColor:!0},cerebras:{Icon:nM,hasColor:!0},openrouter:{Icon:nL,hasColor:!1},xai:{Icon:nR,hasColor:!1},"cloudflare-ai-gateway":{Icon:nW,hasColor:!0},"cloudflare-workers-ai":{Icon:nW,hasColor:!0},"vercel-ai-gateway":{Icon:nE,hasColor:!1},"github-copilot":{Icon:n$,hasColor:!1},"amazon-bedrock":{Icon:nA,hasColor:!0},"azure-openai-responses":{Icon:nB,hasColor:!0},"kimi-coding":{Icon:nN,hasColor:!0},qwen:{Icon:nP,hasColor:!0},zai:{Icon:nD,hasColor:!0},cohere:{Icon:nO,hasColor:!0},perplexity:{Icon:nH,hasColor:!0},together:{Icon:nF,hasColor:!0},grok:{Icon:n_,hasColor:!1}};function nq(e){return nU.find(t=>t.id===e)}let nK=[{value:"openai-responses",label:"OpenAI Responses",description:"OpenAI / deeprouter GPT relay"},{value:"openai-completions",label:"Chat Completions",description:"DeepSeek / Kimi / Qwen via compat proxy"}];function nJ({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 nZ={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 nY({value:e,onChange:t,placeholder:r,mono:o,onKeyDown:i,style:l}){return(0,n.jsx)("input",{value:e,onChange:e=>t(e.target.value),onKeyDown:i,placeholder:r,style:{...nZ,fontFamily:o?"var(--font-mono)":"inherit",...l}})}function nG({value:e,onChange:t,placeholder:r,mono:i,onKeyDown:l,autoComplete:s="off",spellCheck:a=!1,style:d}){let[c,u]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{e||u(!1)},[e]),(0,n.jsxs)("div",{style:{position:"relative",width:"100%",...d},children:[(0,n.jsx)("input",{type:c?"text":"password",value:e,onChange:e=>t(e.target.value),onKeyDown:l,placeholder:r,style:{...nZ,paddingRight:34,fontFamily:i?"var(--font-mono)":"inherit"},autoComplete:s,spellCheck:a}),(0,n.jsx)("button",{type:"button",onClick:()=>u(e=>!e),"aria-label":c?"Hide API key":"Show API key",title:c?"Hide API key":"Show API key",style:{position:"absolute",right:5,top:"50%",transform:"translateY(-50%)",width:24,height:24,padding:0,border:"none",background:"transparent",color:"var(--text-dim)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},children:c?(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M17.94 17.94A10.94 10.94 0 0 1 12 20C7 20 2.73 16.89 1 12a18.45 18.45 0 0 1 5.06-6.94"}),(0,n.jsx)("path",{d:"M9.9 4.24A10.94 10.94 0 0 1 12 4c5 0 9.27 3.11 11 8a18.5 18.5 0 0 1-2.16 3.19"}),(0,n.jsx)("path",{d:"M14.12 14.12A3 3 0 0 1 9.88 9.88"}),(0,n.jsx)("path",{d:"M1 1l22 22"})]}):(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8S1 12 1 12Z"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})})]})}function nX({value:e,onChange:t,placeholder:r}){return(0,n.jsx)("input",{type:"number",value:e,onChange:e=>t(e.target.value),placeholder:r,style:nZ})}function nQ({value:e,onChange:t,required:r}){return(0,n.jsxs)("select",{value:e,onChange:e=>{let r=e.target.value;t("string"==typeof r&&nx.includes(r)?r:"")},style:{...nZ,color:e?"var(--text)":"var(--text-dim)"},children:[!r&&(0,n.jsx)("option",{value:"",children:"— inherit / none —"}),nK.map(e=>(0,n.jsx)("option",{value:e.value,children:e.label},e.value))]})}function n0({api:e}){let t=nK.find(t=>t.value===e);return(0,n.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:t?t.description:"Leave empty to inherit the provider protocol."})}function n1({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 n2({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 n4({name:e,provider:t,onChange:r,onRename:i,onDelete:l}){let[s,a]=(0,o.useState)(e),[d,c]=(0,o.useState)(""),u="codex"===t.source;(0,o.useEffect)(()=>a(e),[e]);let p=(e,n)=>r({...t,[e]:n}),h=()=>{if(u)return;let e=d.trim();if(!e)return;let n=t.models??[];n.some(t=>t.id===e)||r({...t,models:[...n,{id:e,name:e}]}),c("")};return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(n2,{children:"Provider"}),(0,n.jsx)("button",{onClick:()=>!u&&l(),disabled:u,style:{padding:"3px 8px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:4,color:"#ef4444",cursor:u?"not-allowed":"pointer",fontSize:11,opacity:u?.45:1},children:"Delete"})]}),u&&(0,n.jsx)("div",{style:{padding:"7px 10px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-dim)",fontSize:12},children:"Loaded from ~/.codex/config.toml and auth.json. Add a UI provider to override it."}),(0,n.jsxs)(nJ,{label:"Provider name",children:[(0,n.jsx)(nY,{value:s,onChange:e=>!u&&a(e),placeholder:"provider-name",mono:!0}),!u&&s!==e&&s.trim()&&(0,n.jsx)("button",{onClick:()=>i(s.trim()),style:{marginTop:4,padding:"3px 10px",background:"var(--accent)",border:"none",borderRadius:4,color:"#fff",cursor:"pointer",fontSize:11,alignSelf:"flex-start"},children:"Rename"})]}),(0,n.jsx)(nJ,{label:"Base URL",children:(0,n.jsx)(nY,{value:t.baseUrl??"",onChange:e=>!u&&p("baseUrl",e||void 0),placeholder:"https://api.example.com/v1",mono:!0})}),(0,n.jsxs)(nJ,{label:"API Key",children:[(0,n.jsx)(nG,{value:t.apiKey??"",onChange:e=>!u&&p("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.jsxs)(nJ,{label:"Protocol",children:[(0,n.jsx)(nQ,{value:t.api??nm(t.baseUrl,e),onChange:e=>!u&&p("api",e||void 0),required:!0}),(0,n.jsx)(n0,{api:t.api??nm(t.baseUrl,e)})]}),(0,n.jsxs)(nJ,{label:"Model ID",children:[(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsx)(nY,{value:d,onChange:e=>!u&&c(e),onKeyDown:e=>{"Enter"!==e.key||u||h()},placeholder:"gpt-5.5",mono:!0,style:{flex:1}}),(0,n.jsx)("button",{type:"button",onClick:h,disabled:u||!d.trim(),style:{padding:"0 12px",border:"none",borderRadius:5,background:!u&&d.trim()?"var(--accent)":"var(--bg-panel)",color:!u&&d.trim()?"#fff":"var(--text-dim)",cursor:!u&&d.trim()?"pointer":"not-allowed",fontSize:12,fontWeight:600,flexShrink:0},children:"Add"})]}),(0,n.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:"Fetching the model list is optional. Add the model ID your provider supports, then save."})]})]})}let n5=["off","minimal","low","medium","high","xhigh"],n6={off:"var(--text-dim)",minimal:"#6b7280",low:"#60a5fa",medium:"#a78bfa",high:"#f472b6",xhigh:"#fb923c"};function n3({value:e,onChange:t}){let r=e??{},o=(e,n)=>{let o={...r};"omit"===n?delete o[e]:o[e]=n,t(Object.keys(o).length?o:void 0)};return(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:2},children:n5.map(e=>{let t=r[e],i=e in r?null===t?"null":"string":"omit",l="string"==typeof t?t:"",s=n6[e],a={padding:"4px 10px",fontSize:10,border:"none",cursor:"pointer",fontWeight:400,transition:"background 0.1s, color 0.1s",whiteSpace:"nowrap",background:"var(--bg-panel)",color:"var(--text-dim)"},d={background:"var(--accent)",color:"#fff",fontWeight:600};return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"5px 4px",borderRadius:6,background:"transparent",border:"1px solid transparent"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:5,width:68,flexShrink:0},children:[(0,n.jsx)("span",{style:{width:6,height:6,borderRadius:"50%",background:s,flexShrink:0,opacity:"null"===i?.3:1}}),(0,n.jsx)("span",{style:{fontSize:11,fontFamily:"var(--font-mono)",color:"null"===i?"var(--text-dim)":"var(--text-muted)",textDecoration:"null"===i?"line-through":"none"},children:e})]}),(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,border:"1px solid var(--border)",overflow:"hidden",flexShrink:0},children:[(0,n.jsx)("button",{onClick:()=>o(e,"omit"),style:{...a,..."omit"===i?d:{}},children:"Default"}),(0,n.jsx)("button",{onClick:()=>o(e,null),style:{...a,borderLeft:"1px solid var(--border)",..."null"===i?{background:"#ef4444",color:"#fff",fontWeight:600}:{}},children:"Disabled"})]}),(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,border:`1px solid ${"string"===i?"var(--accent)":"var(--border)"}`,overflow:"hidden",transition:"border-color 0.1s"},children:[(0,n.jsx)("button",{onClick:()=>o(e,l||e),style:{...a,..."string"===i?d:{},borderRight:"1px solid var(--border)",flexShrink:0},children:"Custom"}),(0,n.jsx)("input",{value:l,onChange:t=>o(e,t.target.value),onFocus:()=>{"string"!==i&&o(e,l||e)},placeholder:e,maxLength:10,style:{width:"12ch",background:"string"===i?"var(--bg)":"var(--bg-panel)",border:"none",outline:"none",color:"string"===i?"var(--text)":"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11,padding:"4px 7px",transition:"background 0.1s, color 0.1s"}})]})]},e)})})}let n8={thinkingFormat:"deepseek",requiresReasoningContentOnAssistantMessages:!0};function n7({providerName:e,provider:t,model:r,onChange:i,onDelete:l}){let[s,a]=(0,o.useState)({phase:"idle"}),d=(e,t)=>i({...r,[e]:t}),c=(()=>{if("idle"===s.phase)return null;if("testing"===s.phase)return"Testing model connection...";let e=[void 0!==s.latencyMs?`${s.latencyMs}ms`:null,void 0!==s.status?`HTTP ${s.status}`:null].filter(Boolean);return"success"===s.phase?["Connected",...e,s.responseText||null].filter(Boolean).join(" \xb7 "):["Failed",...e,s.message].filter(Boolean).join(" \xb7 ")})();(0,o.useEffect)(()=>{a({phase:"idle"})},[e,t.baseUrl,t.api,t.apiKey,r.id,r.api]);let u=(0,o.useCallback)(async()=>{if(r.id.trim()&&"testing"!==s.phase){a({phase:"testing"});try{let n=await fetch("/api/models-config/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerName:e,provider:t,model:r})}),o=await n.json();if(!n.ok||!o.ok)return void a({phase:"error",message:o.error??`HTTP ${n.status}`,latencyMs:o.latencyMs,status:o.status});a({phase:"success",latencyMs:o.latencyMs,status:o.status,responseText:o.responseText})}catch(e){a({phase:"error",message:e instanceof Error?e.message:String(e)})}}},[r,t,e,s.phase]);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(n2,{children:"Model"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[c&&(0,n.jsx)("span",{title:c,style:{maxWidth:260,height:24,padding:"0 8px",border:`1px solid ${"error"===s.phase?"#fecaca":"success"===s.phase?"#bbf7d0":"var(--border)"}`,borderRadius:4,background:"error"===s.phase?"#fee2e2":"success"===s.phase?"#dcfce7":"#e5e7eb",color:"#111827",fontSize:11,display:"inline-flex",alignItems:"center",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",boxSizing:"border-box"},children:c}),(0,n.jsxs)("button",{onClick:u,disabled:!r.id.trim()||"testing"===s.phase,title:"Test model connection",style:{height:24,padding:"0 8px",background:"success"===s.phase?"#16a34a":"none",border:`1px solid ${"success"===s.phase?"#16a34a":"var(--border)"}`,borderRadius:4,color:"success"===s.phase?"#fff":r.id.trim()&&"testing"!==s.phase?"var(--text-muted)":"var(--text-dim)",cursor:r.id.trim()&&"testing"!==s.phase?"pointer":"not-allowed",fontSize:11,display:"inline-flex",alignItems:"center",justifyContent:"center",boxSizing:"border-box",gap:5},children:["success"===s.phase&&(0,n.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}),"testing"===s.phase?"Testing…":"success"===s.phase?"OK":"Test"]}),(0,n.jsx)("button",{onClick:l,style:{height:24,padding:"0 8px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:4,color:"#ef4444",cursor:"pointer",fontSize:11,boxSizing:"border-box"},children:"Remove"})]})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[(0,n.jsx)(nJ,{label:"ID *",children:(0,n.jsx)(nY,{value:r.id,onChange:e=>d("id",e),placeholder:"model-id",mono:!0})}),(0,n.jsx)(nJ,{label:"Name",children:(0,n.jsx)(nY,{value:r.name??"",onChange:e=>d("name",e||void 0),placeholder:"Display name"})})]}),(0,n.jsxs)(nJ,{label:"API override",children:[(0,n.jsx)(nQ,{value:r.api??"",onChange:e=>d("api",e||void 0)}),(0,n.jsx)(n0,{api:r.api??""})]}),(0,n.jsxs)("div",{style:{display:"flex",gap:20,flexWrap:"wrap"},children:[(0,n.jsx)(n1,{label:"Reasoning / thinking",checked:r.reasoning??!1,onChange:e=>d("reasoning",e||void 0)}),(0,n.jsx)(n1,{label:"Image input",checked:r.input?.includes("image")??!1,onChange:e=>d("input",e?["text","image"]:void 0)})]}),r.reasoning&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(n1,{label:"DeepSeek thinking compat",checked:r.compat?.thinkingFormat==="deepseek",onChange:e=>i(function(e,t){if(t)return{...e,compat:{...e.compat??{},...n8}};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)(n2,{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)(n3,{value:r.thinkingLevelMap,onChange:e=>d("thinkingLevelMap",e)})]})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[(0,n.jsx)(nJ,{label:"Context window (tokens)",children:(0,n.jsx)(nX,{value:void 0!==r.contextWindow?String(r.contextWindow):"",onChange:e=>d("contextWindow",e?parseInt(e):void 0),placeholder:"128000"})}),(0,n.jsx)(nJ,{label:"Max output tokens",children:(0,n.jsx)(nX,{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)(n2,{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)(nJ,{label:e,children:(0,n.jsx)(nX,{value:r.cost?.[e]!==void 0?String(r.cost[e]):"",onChange:t=>{let n;return n=parseFloat(t),void i({...r,cost:{...r.cost??{},[e]:isNaN(n)?void 0:n}})},placeholder:"0"})},e))})]})]})}function n9({provider:e,onRefresh:t}){let[r,i]=(0,o.useState)({phase:"idle"}),[l,s]=(0,o.useState)(""),a=(0,o.useRef)(null),d=(0,o.useRef)(null);(0,o.useEffect)(()=>{("auth"===r.phase||"prompt"===r.phase)&&setTimeout(()=>d.current?.focus(),50)},[r.phase]),(0,o.useEffect)(()=>{i({phase:"idle"}),s(""),a.current?.close(),a.current=null},[e.id]),(0,o.useEffect)(()=>()=>{a.current?.close()},[]);let c=(0,o.useCallback)(()=>{a.current?.close(),i({phase:"connecting"}),s("");let r=new EventSource(`/api/auth/login/${encodeURIComponent(e.id)}`);a.current=r,r.onmessage=e=>{let n=JSON.parse(e.data);"auth"===n.type?(i({phase:"auth",url:n.url,instructions:n.instructions??null,token:n.token}),window.open(n.url,"_blank","noopener,noreferrer")):"device_code"===n.type?(i({phase:"device_code",userCode:n.userCode,verificationUri:n.verificationUri,intervalSeconds:n.intervalSeconds??null,expiresInSeconds:n.expiresInSeconds??null}),window.open(n.verificationUri,"_blank","noopener,noreferrer")):"prompt_request"===n.type?i({phase:"prompt",message:n.message,placeholder:n.placeholder??null,token:n.token}):"select_request"===n.type?i({phase:"select",message:n.message,options:n.options??[],token:n.token}):"progress"===n.type?i({phase:"progress",message:n.message}):"success"===n.type?(r.close(),i({phase:"success"}),t()):"error"===n.type?(r.close(),i({phase:"error",message:n.message})):"cancelled"===n.type&&(r.close(),i({phase:"idle"}))},r.onerror=()=>{r.close(),i(e=>"success"===e.phase?e:{phase:"error",message:"Connection lost"})}},[e.id,t]),u=(0,o.useCallback)(async()=>{await fetch(`/api/auth/logout/${encodeURIComponent(e.id)}`,{method:"POST"}),i({phase:"idle"}),t()},[e.id,t]),p=(0,o.useCallback)(async(t,r)=>{if(r.trim()){i({phase:"progress",message:"Verifying…"});try{let n=await fetch(`/api/auth/login/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:t,code:r.trim()})});if(!n.ok){let e=await n.json().catch(()=>({}));i({phase:"error",message:e.error??`Server error ${n.status}`});return}s("")}catch(e){i({phase:"error",message:e instanceof Error?e.message:"Network error"})}}},[e.id]),h=(0,o.useCallback)(async(t,r)=>{i({phase:"progress",message:"Continuing…"});try{let n=await fetch(`/api/auth/login/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:t,code:r})});if(!n.ok){let e=await n.json().catch(()=>({}));i({phase:"error",message:e.error??`Server error ${n.status}`})}}catch(e){i({phase:"error",message:e instanceof Error?e.message:"Network error"})}},[e.id]),x="connecting"===r.phase||"progress"===r.phase||"auth"===r.phase||"device_code"===r.phase||"prompt"===r.phase||"select"===r.phase;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(n2,{children:"Subscription"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:e.loggedIn?"#4ade80":"var(--border)",display:"inline-block"}}),(0,n.jsx)("span",{style:{fontSize:11,color:e.loggedIn?"#4ade80":"var(--text-dim)"},children:e.loggedIn?"connected":"not connected"})]})]}),(0,n.jsxs)("div",{style:{minHeight:48},children:["idle"===r.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:e.loggedIn?"Already connected. You can re-login or disconnect.":`Connect your ${e.name} account.`}),"connecting"===r.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)"},children:"Opening browser…"}),"select"===r.phase&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:r.message}),(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:r.options.map(e=>(0,n.jsx)("button",{onClick:()=>h(r.token,e.id),style:{padding:"6px 9px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",cursor:"pointer",fontSize:12,textAlign:"left"},children:e.label},e.id))})]}),("auth"===r.phase||"prompt"===r.phase)&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:"auth"===r.phase?"Complete sign-in in the browser, then copy the redirect URL from the address bar and paste it below.":r.message}),"auth"===r.phase&&(0,n.jsxs)("p",{style:{margin:0,fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:["If the browser window did not open,"," ",(0,n.jsx)("a",{href:r.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)",wordBreak:"break-all"},children:"click here to open the login page"}),"."]}),(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsx)("input",{ref:d,value:l,onChange:e=>s(e.target.value),onKeyDown:e=>{"Enter"===e.key&&p(r.token,l)},placeholder:"auth"===r.phase?"http://localhost:1455/auth/callback?code=…":r.placeholder??"Enter value…",style:{flex:1,padding:"6px 9px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",fontSize:12,outline:"none",fontFamily:"var(--font-mono)",boxSizing:"border-box"}}),(0,n.jsx)("button",{onClick:()=>p(r.token,l),disabled:!l.trim(),style:{padding:"6px 12px",background:l.trim()?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:5,color:l.trim()?"#fff":"var(--text-dim)",cursor:l.trim()?"pointer":"not-allowed",fontSize:12,fontWeight:600,flexShrink:0},children:"Submit"})]})]}),"device_code"===r.phase&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:"Open the verification page and enter this code:"}),(0,n.jsx)("div",{style:{padding:"8px 10px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",fontSize:16,fontWeight:700,fontFamily:"var(--font-mono)",letterSpacing:0},children:r.userCode}),(0,n.jsxs)("p",{style:{margin:0,fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:[(0,n.jsx)("a",{href:r.verificationUri,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)",wordBreak:"break-all"},children:r.verificationUri}),r.expiresInSeconds?` Expires in ${Math.ceil(r.expiresInSeconds/60)} minutes.`:""]})]}),"progress"===r.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)"},children:r.message}),"success"===r.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"#4ade80"},children:"Connected successfully."}),"error"===r.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"#f87171"},children:r.message})]}),(0,n.jsx)("div",{style:{display:"flex",gap:8},children:x?(0,n.jsx)("button",{onClick:()=>{a.current?.close(),i({phase:"idle"})},style:{padding:"5px 12px",background:"none",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Cancel"}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:c,style:{padding:"5px 14px",background:"var(--accent)",border:"none",borderRadius:5,color:"#fff",cursor:"pointer",fontSize:12,fontWeight:600},children:e.loggedIn?"Re-login":"Login"}),e.loggedIn&&(0,n.jsx)("button",{onClick:u,style:{padding:"5px 12px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:5,color:"#ef4444",cursor:"pointer",fontSize:12},children:"Disconnect"})]})})]})}function oe({provider:e,onRefresh:t}){let[r,i]=(0,o.useState)(""),[l,s]=(0,o.useState)(!1),[a,d]=(0,o.useState)(!1),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(!1);(0,o.useEffect)(()=>{i(""),u(null),h(!1)},[e.id]);let x=(0,o.useCallback)(async()=>{if(r.trim()){s(!0),u(null),h(!1);try{let n=await fetch(`/api/auth/api-key/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:r.trim()})}),o=await n.json();!n.ok||o.error?u(o.error??`HTTP ${n.status}`):(i(""),h(!0),setTimeout(()=>h(!1),2e3),t())}catch(e){u(String(e))}finally{s(!1)}}},[r,e.id,t]),g=(0,o.useCallback)(async()=>{d(!0),u(null);try{let r=await fetch(`/api/auth/api-key/${encodeURIComponent(e.id)}`,{method:"DELETE"}),n=await r.json();!r.ok||n.error?u(n.error??`HTTP ${r.status}`):t()}catch(e){u(String(e))}finally{d(!1)}},[e.id,t]);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(n2,{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)(nJ,{label:"API Key",children:(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsx)(nG,{value:r,onChange:i,onKeyDown:e=>{"Enter"===e.key&&r.trim()&&x()},placeholder:e.configured?"Enter new key to replace…":"sk-…",style:{flex:1},autoComplete:"off",spellCheck:!1,mono:!0}),(0,n.jsxs)("button",{onClick:x,disabled:l||!r.trim()||p,style:{padding:"6px 12px",background:p?"#16a34a":r.trim()?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:5,color:r.trim()||p?"#fff":"var(--text-dim)",cursor:l||!r.trim()||p?"not-allowed":"pointer",fontSize:12,fontWeight:600,flexShrink:0,display:"flex",alignItems:"center",gap:5},children:[p&&(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}),p?"Saved":l?"Saving…":"Save"]})]})}),c&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"#f87171"},children:c}),e.configured&&(0,n.jsx)("button",{onClick:g,disabled:a,style:{alignSelf:"flex-start",padding:"5px 12px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:5,color:"#ef4444",cursor:a?"not-allowed":"pointer",fontSize:12},children:a?"Removing…":"Disconnect"})]})}function ot({id:e,size:t}){let r=nV[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 or({oauthProviders:e,apiKeyProviders:t,onSelectOAuth:r,onSelectApiKey:i,onAddCustom:l,onDiscover:s,onAddPreset:a,configuredProviderIds:d,onClose:c}){let[u,p]=(0,o.useState)(""),[h,x]=(0,o.useState)({}),[g,f]=(0,o.useState)(null),[m,v]=(0,o.useState)(null),y=(0,o.useRef)(null);(0,o.useEffect)(()=>{setTimeout(()=>y.current?.focus(),30)},[]);let b=u.trim().toLowerCase(),j=nU.filter(e=>!d.has(e.id)&&(!b||e.displayName.toLowerCase().includes(b)||e.id.toLowerCase().includes(b))),k=e.filter(e=>!e.loggedIn&&(!b||e.name.toLowerCase().includes(b))),w=t.filter(e=>!e.configured&&(!b||e.displayName.toLowerCase().includes(b)||e.id.toLowerCase().includes(b))),S=!b||"custom".includes(b)||"openai-compatible".includes(b)||"deepseek".includes(b)||"deeprouter".includes(b),C=!b||"discover".includes(b)||"base url".includes(b)||"model import".includes(b),z=j.length+k.length+w.length+ +!!S+ +!!C,T=async e=>{let t=(h[e]??"").trim(),r=nq(e);if(!t)return void v(`Enter an API key for ${r?.displayName??e}`);if(!r)return void v(`Unknown preset: ${e}`);f(e),v(null);try{await a(e,t),c()}catch(e){v(e instanceof Error?e.message:String(e))}finally{f(null)}},I={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&&c()},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:y,value:u,onChange:e=>p(e.target.value),onKeyDown:e=>{"Escape"===e.key&&c()},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===z?(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:[j.length>0&&(0,n.jsx)("div",{style:{gridColumn:"1 / -1",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Quick Setup — just enter your API key"}),j.map(e=>{let t=h[e.id]??"",r=g===e.id;return(0,n.jsxs)("div",{style:{...I,flexDirection:"column",alignItems:"stretch",gap:8,padding:"12px 14px"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,n.jsx)(ot,{id:e.id,size:22}),(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:1},children:[e.models.length," models preset \xb7 ",e.description]})]})]}),(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsx)("input",{value:t,onChange:t=>{x(r=>({...r,[e.id]:t.target.value})),m&&v(null)},onKeyDown:r=>{"Enter"===r.key&&t.trim()&&T(e.id)},placeholder:"sk-…",type:"password",autoComplete:"off",spellCheck:!1,style:{flex:1,padding:"5px 8px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:4,color:"var(--text)",fontSize:11,fontFamily:"var(--font-mono)",outline:"none",boxSizing:"border-box"}}),(0,n.jsx)("button",{onClick:()=>T(e.id),disabled:r||!t.trim(),style:{padding:"5px 10px",background:r?"var(--bg-panel)":t.trim()?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:4,color:r?"var(--text-dim)":t.trim()?"#fff":"var(--text-dim)",cursor:r||!t.trim()?"not-allowed":"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap",flexShrink:0},children:r?"Adding…":"Add"})]})]},e.id)}),m&&(0,n.jsx)("div",{style:{gridColumn:"1 / -1",fontSize:11,color:"#f87171",padding:"2px 0"},children:m}),S&&(0,n.jsx)("div",{style:{gridColumn:"1 / -1",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Custom"}),S&&(0,n.jsxs)("button",{onClick:()=>{l(),c()},style:I,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-compatible endpoint"}),(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:"DeepSeek, deeprouter, Kimi, Qwen"})]}),(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"})]})})]}),C&&(0,n.jsxs)("button",{onClick:()=>{s(),c()},style:I,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:"Optional 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"})]})})]}),k.length>0&&(0,n.jsx)("div",{style:{gridColumn:"1 / -1",paddingTop:6*!!S,fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Subscriptions"}),k.map(e=>(0,n.jsxs)("button",{onClick:()=>{r(e.id),c()},style:I,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)(ot,{id:e.id,size:28})]},e.id)),w.length>0&&(0,n.jsx)("div",{style:{gridColumn:"1 / -1",paddingTop:6*(k.length>0),fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"API Key"}),w.map(e=>(0,n.jsxs)("button",{onClick:()=>{i(e.id),c()},style:I,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)(ot,{id:e.id,size:28})]},e.id))]})})]})})}function on({existingProviders:e,onImport:t,onClose:r}){let[i,l]=(0,o.useState)(""),[s,a]=(0,o.useState)(""),[d,c]=(0,o.useState)("custom-provider"),[u,p]=(0,o.useState)(new Set),[h,x]=(0,o.useState)({phase:"idle"}),g=(0,o.useCallback)(async()=>{let e=i.trim();if(e&&"loading"!==h.phase){x({phase:"loading"});try{let t=await fetch("/api/models-config/discover",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:e,apiKey:s,provider:d,enrich:!1})}),r=await t.json();if(!t.ok||!r.ok||!r.models||!r.piModels||!r.endpoint)return void x({phase:"error",message:r.error??`HTTP ${t.status}`});x({phase:"success",endpoint:r.endpoint,models:r.models,piModels:r.piModels}),p(new Set(r.piModels.map(e=>e.id)))}catch(e){x({phase:"error",message:e instanceof Error?e.message:String(e)})}}},[s,i,d,h.phase]),f="success"===h.phase?h:null,m=u.size,v=!!(f&&d.trim()&&m>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:"Optional: fetch a 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)(nJ,{label:"Base URL",children:(0,n.jsx)(nY,{value:i,onChange:l,placeholder:"https://api.example.com",mono:!0})}),(0,n.jsx)(nJ,{label:"API Key",children:(0,n.jsx)(nG,{value:s,onChange:a,placeholder:"optional for local providers",mono:!0})}),(0,n.jsx)(nJ,{label:"Provider name",children:(0,n.jsx)(nY,{value:d,onChange:c,placeholder:"provider-name",mono:!0})}),(0,n.jsx)("button",{onClick:g,disabled:!i.trim()||"loading"===h.phase,style:{height:31,padding:"0 14px",background:i.trim()&&"loading"!==h.phase?"var(--accent)":"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:5,color:i.trim()&&"loading"!==h.phase?"#fff":"var(--text-dim)",cursor:i.trim()&&"loading"!==h.phase?"pointer":"not-allowed",fontSize:12,fontWeight:600,whiteSpace:"nowrap"},children:"loading"===h.phase?"Fetching...":"Fetch models"})]}),(0,n.jsxs)("div",{style:{flex:1,overflow:"hidden",display:"flex",flexDirection:"column"},children:["idle"===h.phase&&(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:"Enter a Base URL to discover available models."}),"loading"===h.phase&&(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:"Fetching model catalog..."}),"error"===h.phase&&(0,n.jsx)("div",{style:{padding:18,color:"#f87171",fontSize:12,lineHeight:1.6},children:h.message}),f&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"8px 16px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-dim)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[f.piModels.length," models from ",f.endpoint]}),(0,n.jsx)("button",{onClick:()=>{if(f){if(u.size===f.piModels.length)return void p(new Set);p(new Set(f.piModels.map(e=>e.id)))}},style:{padding:"2px 8px",fontSize:11,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-muted)",cursor:"pointer"},children:u.size===f.piModels.length?"Clear":"Select all"})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"auto"},children:f.piModels.map((e,t)=>{let r=f.models[t],o=u.has(e.id);return(0,n.jsxs)("label",{style:{display:"grid",gridTemplateColumns:"24px minmax(0, 1fr) 90px 90px 90px 70px",gap:10,alignItems:"center",padding:"8px 16px",borderBottom:"1px solid rgba(127,127,127,0.12)",background:o?"var(--bg-subtle)":"transparent",cursor:"pointer"},children:[(0,n.jsx)("input",{type:"checkbox",checked:o,onChange:()=>{var t;return t=e.id,void p(e=>{let r=new Set(e);return r.has(t)?r.delete(t):r.add(t),r})},style:{width:14,height:14,accentColor:"var(--accent)"}}),(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontFamily:"var(--font-mono)",fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.id}),(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r?.ownedBy??"unknown"})]}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:e.contextWindow}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:e.maxTokens}),(0,n.jsx)("span",{style:{fontSize:10,color:e.reasoning?"var(--accent)":"var(--text-dim)"},children:e.reasoning?"reasoning":""}),(0,n.jsx)("span",{style:{fontSize:10,color:e.input?.includes("image")?"var(--accent)":"var(--text-dim)"},children:e.input?.includes("image")?"image":""})]},e.id)})})]})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:10,padding:"10px 16px",borderTop:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:[m," 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||!v)return;let n=i.trim().replace(/\/+$/,""),o=s.trim(),l=Object.entries(e).find(([,e])=>(e.baseUrl??"").replace(/\/+$/,"")===n&&(e.apiKey??"")===o),a=l?.[0]??d.trim(),c=e[a],p=new Map((c?.models??[]).map(e=>[e.id,e])),h=0;for(let e of f.piModels)u.has(e.id)&&!p.has(e.id)&&(p.set(e.id,e),h+=1);t(a,{...c??{},baseUrl:n,api:c?.api??nm(n,a),...o?{apiKey:o}:{},models:Array.from(p.values())},h),r()},disabled:!v,style:{padding:"6px 16px",background:v?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:6,color:v?"#fff":"var(--text-dim)",cursor:v?"pointer":"not-allowed",fontSize:13,fontWeight:600},children:"Import selected"})]})]})]})})}function oo({onClose:e,embedded:t=!1}){let[r,i]=(0,o.useState)({providers:{}}),[l,s]=(0,o.useState)(!0),[a,d]=(0,o.useState)(!1),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(null),[x,g]=(0,o.useState)(!1),[f,m]=(0,o.useState)(null),[v,y]=(0,o.useState)([]),[b,j]=(0,o.useState)([]),[k,w]=(0,o.useState)(!1),[S,C]=(0,o.useState)(!1),z=(0,o.useCallback)(()=>{fetch("/api/auth/providers").then(e=>e.json()).then(e=>y(e.providers)).catch(()=>{})},[]),T=(0,o.useCallback)(()=>{fetch("/api/auth/all-providers").then(e=>e.json()).then(e=>j(e.providers)).catch(()=>{})},[]);(0,o.useEffect)(()=>{fetch("/api/models-config").then(e=>e.json()).then(e=>{let t=e.providers?e:{...e,providers:{}};i(t);let r=Object.keys(t.providers??{});r.length>0&&m({type:"provider",name:r[0]})}).catch(()=>i({providers:{}})).finally(()=>s(!1)),z(),T()},[z,T]);let I=(0,o.useCallback)(()=>{let e="custom",t=1;for(;r.providers?.[e];)e=`custom-${t++}`;i(t=>({...t,providers:{...t.providers??{},[e]:{baseUrl:""}}})),m({type:"provider",name:e})},[r.providers]),M=(0,o.useCallback)(async(e,t)=>{let r=nq(e);if(!r)throw Error(`Unknown preset: ${e}`);i(n=>{var o;let i,l={...n.providers??{}};return l[e]=(o=l[e],i=o?.source!=="codex"?o:void 0,{baseUrl:r.baseUrl,api:r.api,apiKey:t,source:"annodex",requiresOpenAiAuth:i?.requiresOpenAiAuth,headers:i?.headers,compat:i?.compat,modelOverrides:i?.modelOverrides,models:function(e,t){let r=[...t??[]],n=new Set(r.map(e=>e.id));for(let t of e.models)n.has(t.id)||r.push({id:t.id,name:t.name??t.id,reasoning:t.reasoning,contextWindow:t.contextWindow,maxTokens:t.maxTokens});return r}(r,i?.models)}),{...n,providers:l}}),m({type:"provider",name:e}),g(!1),u(null),h(`Discovering models from ${r.displayName} API…`);try{let n=await fetch("/api/models-config/discover",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:r.baseUrl,apiKey:t,provider:e})}),o=await n.json();o.ok&&o.piModels?.length?(i(t=>{let r={...t.providers??{}},n=r[e];return n&&(r[e]={...n,models:o.piModels}),{...t,providers:r}}),h(`${r.displayName}: found ${o.piModels.length} models via API. Click Save.`)):o.error?h(`${r.displayName} preset added with defaults (API: ${o.error}). Click Save.`):h(`${r.displayName} preset added with default models. Click Save.`)}catch{h(`${r.displayName} preset added with default models (API unreachable). Click Save.`)}},[]),L=new Set(Object.entries(r.providers??{}).filter(([,e])=>"codex"!==e.source).map(([e])=>e)),R=(0,o.useCallback)((e,t)=>{i(r=>({...r,providers:{...r.providers??{},[e]:t}}))},[]),W=(0,o.useCallback)((e,t)=>{i(r=>{let n=Object.entries(r.providers??{}),o=n.findIndex(([t])=>t===e);return -1===o?r:(n[o]=[t,n[o][1]],{...r,providers:Object.fromEntries(n)})}),m(r=>r?"provider"===r.type&&r.name===e?{type:"provider",name:t}:"model"===r.type&&r.providerName===e?{...r,providerName:t}:r:r)},[]),E=(0,o.useCallback)(e=>{i(t=>{let r={...t.providers??{}};return delete r[e],{...t,providers:r}}),i(e=>{let t=Object.keys(e.providers??{});return m(t.length>0?{type:"provider",name:t[0]}:null),e})},[]),$=(0,o.useCallback)(e=>{i(t=>{let r=t.providers?.[e]??{},n=[...r.models??[],{id:""}];return{...t,providers:{...t.providers??{},[e]:{...r,models:n}}}}),i(t=>{let r=(t.providers?.[e]?.models?.length??1)-1;return m({type:"model",providerName:e,index:r}),t})},[]),A=(0,o.useCallback)((e,t,r)=>{i(n=>{let o=n.providers?.[e]??{},i=[...o.models??[]];return i[t]=r,{...n,providers:{...n.providers??{},[e]:{...o,models:i}}}})},[]),B=(0,o.useCallback)((e,t)=>{i(r=>{let n=r.providers?.[e]??{},o=[...n.models??[]];return o.splice(t,1),{...r,providers:{...r.providers??{},[e]:{...n,models:o.length?o:void 0}}}}),m({type:"provider",name:e})},[]),N=(0,o.useCallback)((e,t,r)=>{i(r=>({...r,providers:{...r.providers??{},[e]:t}})),m({type:"provider",name:e}),g(!1),u(null),h(`${r} model${1===r?"":"s"} imported. Click Save to write providers.json.`)},[]),P=(0,o.useCallback)(async()=>{d(!0),u(null),h(null),g(!1);try{let e=await fetch("/api/models-config",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({providers:r.providers??{}})}),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]),D=Object.entries(r.providers??{}),O=v.filter(e=>e.loggedIn),H=b.filter(e=>e.configured),F=(()=>{if(!f)return null;if("oauth"===f.type){let e=v.find(e=>e.id===f.providerId);return e?(0,n.jsx)(n9,{provider:e,onRefresh:z},e.id):null}if("apikey"===f.type){let e=b.find(e=>e.id===f.providerId);return e?(0,n.jsx)(oe,{provider:e,onRefresh:T},e.id):null}if("provider"===f.type){let e=r.providers?.[f.name];return e?(0,n.jsx)(n4,{name:f.name,provider:e,onChange:e=>R(f.name,e),onRename:e=>W(f.name,e),onDelete:()=>E(f.name)},f.name):null}let e=r.providers?.[f.providerName],t=e?.models?.[f.index];return t?(0,n.jsx)(n7,{providerName:f.providerName,provider:e,model:t,onChange:e=>A(f.providerName,f.index,e),onDelete:()=>B(f.providerName,f.index)},`${f.providerName}-${f.index}`):null})();return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:t?{height:"100%",minHeight:0,display:"flex",alignItems:"stretch",justifyContent:"stretch"}:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:r=>{t||r.target!==r.currentTarget||e()},children:(0,n.jsxs)("div",{style:{width:t?"100%":860,height:t?"100%":"78vh",background:"var(--bg)",border:t?"none":"1px solid var(--border)",borderRadius:10*!t,display:"flex",flexDirection:"column",boxShadow:t?"none":"0 8px 32px rgba(0,0,0,0.18)",overflow:"hidden"},children:[!t&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 18px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10},children:[(0,n.jsx)("span",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:"Models"}),(0,n.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:"~/.config/annodex/providers.json"})]}),(0,n.jsx)("button",{onClick:e,style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),(0,n.jsxs)("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{width:210,borderRight:"1px solid var(--border)",display:"flex",flexDirection:"column",flexShrink:0,background:"var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,overflowY:"auto",padding:"8px 6px"},children:[O.map(e=>{let t=f?.type==="oauth"&&f.providerId===e.id;return(0,n.jsxs)("div",{onClick:()=>m({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)(ot,{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)}),H.map(e=>{let t=f?.type==="apikey"&&f.providerId===e.id;return(0,n.jsxs)("div",{onClick:()=>m({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)(ot,{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)}),(O.length>0||H.length>0)&&D.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…"}):D.map(([e,t])=>{let r=f?.type==="provider"&&f.name===e,o=t.models??[];return(0,n.jsxs)("div",{style:{marginBottom:2},children:[(0,n.jsxs)("div",{onClick:()=>m({type:"provider",name:e}),style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,cursor:"pointer",background:r?"var(--bg-selected)":"none"},onMouseEnter:e=>{r||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{r||(e.currentTarget.style.background="none")},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0},children:[(0,n.jsx)("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),(0,n.jsx)("rect",{x:"9",y:"9",width:"6",height:"6"}),(0,n.jsx)("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),(0,n.jsx)("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),(0,n.jsx)("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),(0,n.jsx)("line",{x1:"15",y1:"20",x2:"15",y2:"23"}),(0,n.jsx)("line",{x1:"20",y1:"9",x2:"23",y2:"9"}),(0,n.jsx)("line",{x1:"20",y1:"14",x2:"23",y2:"14"}),(0,n.jsx)("line",{x1:"1",y1:"9",x2:"4",y2:"9"}),(0,n.jsx)("line",{x1:"1",y1:"14",x2:"4",y2:"14"})]}),(0,n.jsx)("span",{style:{fontSize:12,fontWeight:r?600:400,color:"var(--text)",fontFamily:"var(--font-mono)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e})]}),o.map((t,r)=>{let o=f?.type==="model"&&f.providerName===e&&f.index===r;return(0,n.jsxs)("div",{onClick:()=>m({type:"model",providerName:e,index:r}),style:{display:"flex",alignItems:"center",gap:6,padding:"5px 8px 5px 26px",borderRadius:5,cursor:"pointer",background:o?"var(--bg-selected)":"none"},onMouseEnter:e=>{o||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{o||(e.currentTarget.style.background="none")},children:[(0,n.jsx)("span",{style:{fontSize:11,fontFamily:"var(--font-mono)",color:t.id?"var(--text-muted)":"var(--text-dim)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.id||"new model"}),t.reasoning&&(0,n.jsx)("span",{style:{fontSize:9,padding:"1px 4px",background:"rgba(99,102,241,0.12)",color:"rgba(99,102,241,0.8)",borderRadius:3,flexShrink:0},children:"T"})]},r)}),(0,n.jsx)("div",{onClick:t=>{t.stopPropagation(),$(e)},style:{display:"flex",alignItems:"center",gap:4,padding:"4px 8px 4px 26px",borderRadius:5,cursor:"pointer",color:"var(--text-dim)"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)",e.currentTarget.style.background="none"},children:(0,n.jsx)("span",{style:{fontSize:11},children:"+ model"})})]},e)})]}),(0,n.jsx)("div",{style:{borderTop:"1px solid var(--border)",padding:"8px 6px"},children:(0,n.jsx)("button",{onClick:()=>w(!0),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,width:"100%",padding:"6px 0",background:"none",border:"1px dashed var(--border)",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",fontSize:12},onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.color="var(--text-muted)"},children:"+ Add provider"})})]}),(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:l?null:F??(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:"Select a provider or model"})})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:10,padding:"10px 18px",borderTop:"1px solid var(--border)",flexShrink:0},children:[c?(0,n.jsx)("span",{style:{fontSize:12,color:"#f87171",flex:1},children:c}):p?(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",flex:1},children:p}):null,(0,n.jsx)("button",{onClick:e,style:{padding:"6px 14px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:13},children:"Cancel"}),(0,n.jsxs)("button",{onClick:P,disabled:a||x,style:{position:"relative",padding:"6px 16px",minWidth:92,background:x?"#16a34a":a?"var(--bg-panel)":"var(--accent)",border:"none",borderRadius:6,color:x?"#fff":a?"var(--text-muted)":"#fff",cursor:a||x?"default":"pointer",fontSize:13,fontWeight:600,display:"inline-flex",alignItems:"center",justifyContent:"center",gap:6,transition:"background-color 0.2s ease, color 0.2s ease",animation:x?"saved-pop 0.45s ease":void 0},children:[x&&(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",style:{strokeDasharray:18,animation:"saved-check-draw 0.35s ease forwards",flexShrink:0},children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}),(0,n.jsx)("span",{children:x?"Saved":a?"Saving…":"Save"})]})]})]})}),k&&(0,n.jsx)(or,{oauthProviders:v,apiKeyProviders:b,onSelectOAuth:e=>m({type:"oauth",providerId:e}),onSelectApiKey:e=>m({type:"apikey",providerId:e}),onAddCustom:I,onDiscover:()=>C(!0),onAddPreset:M,configuredProviderIds:L,onClose:()=>w(!1)}),S&&(0,n.jsx)(on,{existingProviders:r.providers??{},onImport:N,onClose:()=>C(!1)})]})}function oi(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function ol(e){let t=e.sourceInfo?.source,r=e.sourceInfo?.scope;return"user"===r||"user"===t?"global":"project"===r||"project"===t?"project":"path"}function os({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 oa({skill:e,cwd:t,onToggle:r,toggling:o,saveError:i}){let l=ol(e),s=!e.disableModelInvocation;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:20},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:7},children:[(0,n.jsx)("span",{style:{fontSize:10,padding:"1px 5px",borderRadius:3,flexShrink:0,background:"project"===l?"rgba(99,102,241,0.12)":"rgba(120,120,120,0.12)",color:"project"===l?"rgba(99,102,241,0.8)":"var(--text-dim)"},children:l}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:function(e){if("project"===l&&e.startsWith(t)){let r=e.slice(t.length).replace(/^[/\\]/,"");return`./${r}`}return oi(e)}(e.filePath)}),(0,n.jsx)(os,{enabled:s,loading:o,onToggle:()=>r(e)}),i&&(0,n.jsx)("span",{style:{fontSize:12,color:"#f87171",flexShrink:0},children:i})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:"Name"}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:14,color:"var(--text)"},children:e.name})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:"Description"}),(0,n.jsx)("span",{style:{fontSize:14,color:"var(--text-muted)",lineHeight:1.6},children:e.description})]})]})}function od({cwd:e,onInstalled:t}){let[r,i]=(0,o.useState)(""),[l,s]=(0,o.useState)([]),[a,d]=(0,o.useState)(!1),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(null),[x,g]=(0,o.useState)(null),[f,m]=(0,o.useState)(null),[v,y]=(0,o.useState)([]),[b,j]=(0,o.useState)(new Set),[k,w]=(0,o.useState)("global"),S=(0,o.useRef)(null),C=(0,o.useRef)(null);(0,o.useEffect)(()=>{S.current?.focus()},[]),(0,o.useEffect)(()=>()=>{C.current?.abort()},[]);let z=(0,o.useCallback)(async e=>{if(e.trim()){d(!0),u(null),s([]);try{let t=await fetch("/api/skills/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:e.trim()})}),r=await t.json();if(r.error)return void u(r.error);s(r.results??[]),0===(r.results??[]).length&&u("No skills found")}catch(e){u(String(e))}finally{d(!1)}}},[]),T=(0,o.useCallback)(async r=>{let n=new AbortController;C.current=n,h(r),g(null),m("Starting installer"),y(["Starting installer"]);try{let o=await fetch("/api/skills/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({package:r,scope:k,cwd:e,stream:!0}),signal:n.signal});if(!o.ok||!o.body){let e=await o.json().catch(()=>null);g(e?.error??`HTTP ${o.status}`);return}let i=o.body.getReader(),l=new TextDecoder,s="",a=!1,d=e=>{"progress"===e.type?(e.stage&&m(e.stage),e.line&&y(t=>(t.at(-1)===e.line?t:[...t,e.line]).slice(-8))):"done"===e.type&&e.success?(a=!0,m("Installed"),y(e=>[...e,"Installed"].slice(-8))):"error"===e.type&&g(e.error??"Install failed")};for(;;){let{value:e,done:t}=await i.read(),r=(s+=l.decode(e??new Uint8Array,{stream:!t})).split("\n");for(let e of(s=r.pop()??"",r))e.trim()&&d(JSON.parse(e));if(t)break}s.trim()&&d(JSON.parse(s)),a&&(j(e=>new Set(e).add(r)),t())}catch(e){n.signal.aborted?(m("Canceled"),y(e=>[...e,"Canceled"].slice(-8))):g(String(e))}finally{C.current===n&&(C.current=null),h(null)}},[t,k,e]),I=(0,o.useCallback)(()=>{C.current?.abort()},[]),M="global"===k?"~/.codex/skills/":`${oi(e)}/.codex/skills/`;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,marginBottom:20},children:[(0,n.jsx)("div",{style:{fontSize:14,fontWeight:600,color:"var(--text)"},children:"Add Skill"}),(0,n.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,n.jsx)("input",{ref:S,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{"Enter"===e.key&&z(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:()=>z(r),disabled:a||!r.trim(),style:{padding:"7px 16px",fontSize:13,borderRadius:6,border:"none",background:"var(--accent)",color:"#fff",cursor:a||!r.trim()?"not-allowed":"pointer",opacity:a||!r.trim()?.5:1,flexShrink:0},children:a?"Searching…":"Search"})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10},children:[(0,n.jsx)("div",{style:{display:"flex",borderRadius:5,border:"1px solid var(--border)",overflow:"hidden",fontSize:12,flexShrink:0},children:["global","project"].map(e=>(0,n.jsx)("button",{onClick:()=>w(e),style:{padding:"3px 10px",border:"none",cursor:"pointer",background:k===e?"var(--bg-selected)":"none",color:k===e?"var(--text)":"var(--text-dim)",fontWeight:k===e?600:400,borderRight:"global"===e?"1px solid var(--border)":"none"},children:e},e))}),(0,n.jsxs)("span",{style:{fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["→ ",M]})]}),c&&(0,n.jsx)("div",{style:{fontSize:12,color:"#f87171"},children:c}),x&&(0,n.jsx)("div",{style:{fontSize:12,color:"#f87171",wordBreak:"break-word"},children:x}),p&&(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",padding:10,display:"flex",flexDirection:"column",gap:8},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10},children:[(0,n.jsx)("div",{style:{width:10,height:10,borderRadius:"50%",border:"2px solid var(--border)",borderTopColor:"var(--accent)",animation:"spin 0.8s linear infinite",flexShrink:0}}),(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:f??"Installing"}),(0,n.jsx)("div",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:p})]}),(0,n.jsx)("button",{onClick:I,style:{padding:"4px 9px",fontSize:12,borderRadius:5,border:"1px solid var(--border)",background:"none",color:"var(--text-muted)",cursor:"pointer",flexShrink:0},children:"Cancel"})]}),v.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:v.map((e,t)=>(0,n.jsx)("div",{children:e},`${t}-${e}`))})]})]}),l.length>0?(0,n.jsx)("div",{style:{flex:1,overflowY:"auto"},children:l.map(e=>{let t=b.has(e.package),r=p===e.package,o=e.package.indexOf("@"),i=o>-1?e.package.slice(0,o):e.package,l=o>-1?e.package.slice(o+1):null;return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:14,padding:"12px 0",borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)",marginBottom:3},children:l??i}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)"},children:i}),(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:e.installs}),e.url&&(0,n.jsx)("a",{href:e.url,target:"_blank",rel:"noreferrer",style:{fontSize:12,color:"var(--accent)",textDecoration:"none"},children:"skills.sh ↗"})]})]}),(0,n.jsx)("button",{onClick:()=>{t||null!==p||T(e.package)},disabled:t||null!==p,style:{flexShrink:0,padding:"5px 14px",fontSize:12,fontWeight:500,borderRadius:5,border:"1px solid var(--border)",cursor:r?"wait":t||null!==p?"not-allowed":"pointer",background:t?"rgba(34,197,94,0.1)":r?"rgba(59,130,246,0.08)":"none",color:t?"#16a34a":r?"var(--accent)":"var(--text-muted)",transition:"color 0.12s"},children:t?"✓ Installed":r?"Installing":"Install"})]},e.package)})}):!c&&!a&&(0,n.jsxs)("div",{style:{fontSize:13,color:"var(--text-dim)",lineHeight:1.8},children:["Search"," ",(0,n.jsx)("a",{href:"https://skills.sh",target:"_blank",rel:"noreferrer",style:{color:"var(--accent)",textDecoration:"none"},children:"skills.sh"})," ","to discover and install skills for your agent."]})]})}function oc({cwd:e,onClose:t,embedded:r=!1}){let[i,l]=(0,o.useState)([]),[s,a]=(0,o.useState)(!0),[d,c]=(0,o.useState)(null),[u,p]=(0,o.useState)(null),[h,x]=(0,o.useState)(new Set),[g,f]=(0,o.useState)(null),[m,v]=(0,o.useState)(!1),y=(0,o.useCallback)(()=>{a(!0),c(null),fetch(`/api/skills?cwd=${encodeURIComponent(e)}`).then(e=>e.json()).then(e=>{if(e.error)return void c(e.error);let t=e.skills??[];l(t),t.length>0&&!u&&p(t[0].filePath)}).catch(e=>c(String(e))).finally(()=>a(!1))},[e,u]);(0,o.useEffect)(()=>{y()},[e]);let b=(0,o.useCallback)(async e=>{let t=!e.disableModelInvocation;x(t=>new Set(t).add(e.filePath)),f(null);try{let r=await fetch("/api/skills",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({filePath:e.filePath,disableModelInvocation:t})}),n=await r.json();if(!r.ok||n.error)return void f(n.error??`HTTP ${r.status}`);l(r=>r.map(r=>r.filePath===e.filePath?{...r,disableModelInvocation:t}:r))}catch(e){f(String(e))}finally{x(t=>{let r=new Set(t);return r.delete(e.filePath),r})}},[]),j=i.find(e=>e.filePath===u)??null;return(0,n.jsx)("div",{style:r?{height:"100%",minHeight:0,display:"flex",alignItems:"stretch",justifyContent:"stretch"}:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:e=>{r||e.target!==e.currentTarget||t()},children:(0,n.jsxs)("div",{style:{width:r?"100%":860,height:r?"100%":"78vh",background:"var(--bg)",border:r?"none":"1px solid var(--border)",borderRadius:10*!r,display:"flex",flexDirection:"column",boxShadow:r?"none":"0 8px 32px rgba(0,0,0,0.18)",overflow:"hidden"},children:[!r&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 18px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10},children:[(0,n.jsx)("span",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:"Skills"}),(0,n.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)",maxWidth:320,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:oi(e)})]}),(0,n.jsx)("button",{onClick:t,style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),(0,n.jsxs)("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{width:210,borderRight:"1px solid var(--border)",display:"flex",flexDirection:"column",flexShrink:0,background:"var(--bg-panel)"},children:[(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",padding:"8px 6px"},children:s?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:"Loading…"}):d?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"#f87171"},children:d}):0===i.length?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"var(--text-dim)"},children:"No skills found"}):(()=>{let e=[];for(let t of["project","global","path"]){let r=i.filter(e=>ol(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=!m&&u===e.filePath,r=e.disableModelInvocation;return(0,n.jsxs)("div",{onClick:()=>{p(e.filePath),v(!1)},style:{display:"flex",alignItems:"center",gap:7,padding:"8px 8px",borderRadius:5,cursor:"pointer",background:t?"var(--bg-selected)":"none"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,n.jsx)("span",{style:{flexShrink:0,width:7,height:7,borderRadius:"50%",background:r?"var(--border)":"var(--accent)",boxShadow:r?"none":"0 0 4px var(--accent)",transition:"background 0.15s, box-shadow 0.15s"}}),(0,n.jsx)("span",{style:{fontSize:12,fontWeight:t?600:400,color:r?"var(--text-dim)":"var(--text)",fontFamily:"var(--font-mono)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name})]},e.filePath)})]},e))})()}),(0,n.jsx)("div",{style:{padding:"8px 6px",borderTop:"1px solid var(--border)",flexShrink:0},children:(0,n.jsxs)("div",{onClick:()=>v(!0),style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,cursor:"pointer",background:m?"var(--bg-selected)":"none",color:m?"var(--accent)":"var(--text-dim)",fontSize:12},onMouseEnter:e=>{m||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{m||(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:m?(0,n.jsx)(od,{cwd:e,onInstalled:()=>{y()}}):s?null:j?(0,n.jsx)(oa,{skill:j,cwd:e,onToggle:b,toggling:h.has(j.filePath),saveError:g},j.filePath):(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:"Select a skill"})})]}),(0,n.jsx)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",padding:"10px 18px",borderTop:"1px solid var(--border)",flexShrink:0},children:(0,n.jsx)("button",{onClick:t,style:{padding:"6px 14px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:13},children:"Close"})})]})})}function ou({activeCwd:e,onSelectProject:t,onProjectsChanged:r}){let[i,l]=(0,o.useState)([]),[s,a]=(0,o.useState)(!0),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(""),[x,g]=(0,o.useState)(!1),[f,m]=(0,o.useState)(null),[v,y]=(0,o.useState)(null),[b,j]=(0,o.useState)(""),k=(0,o.useRef)(null),w=(0,o.useCallback)(async()=>{try{a(!0);let e=await fetch("/api/projects"),t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);l(t.projects??[]),u(null)}catch(e){u(e instanceof Error?e.message:String(e))}finally{a(!1)}},[]);(0,o.useEffect)(()=>{w()},[w]);let S=(0,o.useMemo)(()=>({projects:i.length,chats:i.reduce((e,t)=>e+t.chatCount,0)}),[i]),C=(0,o.useCallback)(async()=>{let e=p.trim();if(e){m("add"),u(null);try{let n=await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e})}),o=await n.json();if(!n.ok||o.error)throw Error(o.error??`HTTP ${n.status}`);h(""),r?.(),t?.(e),w()}catch(e){u(e instanceof Error?e.message:String(e))}finally{m(null)}}},[w,r,t,p]),z=(0,o.useCallback)(async e=>{m("add"),u(null);try{let n=await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e})}),o=await n.json();if(!n.ok||o.error)throw Error(o.error??`HTTP ${n.status}`);h(""),g(!1),r?.(),t?.(e),w()}catch(e){u(e instanceof Error?e.message:String(e))}finally{m(null)}},[w,r,t]),T=(0,o.useCallback)(async e=>{m(`rename:${e}`),u(null);try{let t=await fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,name:b})}),n=await t.json();if(!t.ok||n.error)throw Error(n.error??`HTTP ${t.status}`);y(null),j(""),await w(),r?.()}catch(e){u(e instanceof Error?e.message:String(e))}finally{m(null)}},[w,r,b]),I=(0,o.useCallback)(async e=>{m(`remove:${e}`),u(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}`);await w(),r?.()}catch(e){u(e instanceof Error?e.message:String(e))}finally{m(null)}},[w,r]),M=(0,o.useCallback)(e=>{y(e.cwd),j(e.name??e.displayName),window.setTimeout(()=>k.current?.select(),0)},[]);return(0,n.jsxs)("div",{style:{height:"100%",overflowY:"auto",padding:20},children:[(0,n.jsxs)("div",{style:{maxWidth:900,display:"flex",flexDirection:"column",gap:14},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:15,fontWeight:750,color:"var(--text)"},children:"Projects"}),(0,n.jsxs)("div",{style:{marginTop:4,fontSize:12,color:"var(--text-muted)"},children:[S.projects," projects / ",S.chats," chats"]})]}),(0,n.jsx)("button",{type:"button",onClick:()=>void w(),style:{height:30,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Refresh"})]}),(0,n.jsx)("div",{style:{border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",padding:12},children:(0,n.jsxs)("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[(0,n.jsx)("input",{value:p,onChange:e=>h(e.target.value),onKeyDown:e=>{"Enter"===e.key&&C()},placeholder:"/path/to/project",style:{flex:1,minWidth:0,height:32,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:12,outline:"none"}}),(0,n.jsx)("button",{type:"button",onClick:()=>g(!0),style:{height:32,padding:"0 12px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Browse"}),(0,n.jsx)("button",{type:"button",disabled:!p.trim()||"add"===f,onClick:()=>void C(),style:{height:32,padding:"0 12px",border:"none",borderRadius:6,background:p.trim()?"var(--accent)":"var(--bg-hover)",color:p.trim()?"#fff":"var(--text-dim)",cursor:p.trim()?"pointer":"default",fontSize:12,fontWeight:650},children:"Add"})]})}),c&&(0,n.jsx)("div",{style:{padding:"9px 11px",border:"1px solid rgba(248,113,113,0.35)",borderRadius:7,color:"#f87171",background:"rgba(248,113,113,0.08)",fontSize:12},children:c}),(0,n.jsx)("div",{style:{border:"1px solid var(--border)",borderRadius:8,overflow:"hidden"},children:s?(0,n.jsx)("div",{style:{padding:16,color:"var(--text-muted)",fontSize:12},children:"Loading..."}):0===i.length?(0,n.jsx)("div",{style:{padding:16,color:"var(--text-muted)",fontSize:12},children:"No projects yet."}):i.map(r=>{var o;let i,l=r.cwd===e,s=v===r.cwd,a=r.lastAccessed??r.created??null;return(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) auto",gap:12,alignItems:"center",padding:"12px 14px",borderBottom:"1px solid var(--border)",background:l?"var(--bg-selected)":"var(--bg)"},children:[(0,n.jsxs)("div",{style:{minWidth:0},children:[s?(0,n.jsx)("input",{ref:k,value:b,onChange:e=>j(e.target.value),onKeyDown:e=>{"Enter"===e.key&&T(r.cwd),"Escape"===e.key&&y(null)},style:{width:"min(360px, 100%)",height:30,padding:"0 9px",border:"1px solid var(--accent)",borderRadius:6,background:"var(--bg)",color:"var(--text)",fontSize:13,outline:"none"}}):(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:13,fontWeight:l?750:650,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r.displayName}),(0,n.jsx)("div",{style:{marginTop:4,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:r.cwd,children:(i=(o=r.cwd).split(/[\\/]/).filter(Boolean)).length<=3?o:`.../${i.slice(-3).join("/")}`}),(0,n.jsxs)("div",{style:{marginTop:5,color:"var(--text-muted)",fontSize:11},children:[r.chatCount," chats / last ",function(e){if(!e)return"Never";let t=new Date(e),r=new Date().getTime()-t.getTime(),n=Math.floor(r/6e4),o=Math.floor(r/36e5),i=Math.floor(r/864e5);return n<1?"just now":n<60?`${n}m ago`:o<24?`${o}h ago`:i<7?`${i}d ago`:t.toLocaleDateString()}(a),r.exists?"":" / path missing"]})]}),(0,n.jsx)("div",{style:{display:"flex",alignItems:"center",gap:6},children:s?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",disabled:f===`rename:${r.cwd}`,onClick:()=>void T(r.cwd),style:{height:28,padding:"0 9px",border:"none",borderRadius:6,background:"var(--accent)",color:"#fff",cursor:"pointer",fontSize:12},children:"Save"}),(0,n.jsx)("button",{type:"button",onClick:()=>y(null),style:{height:28,padding:"0 9px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Cancel"})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:()=>t?.(r.cwd),style:{height:28,padding:"0 9px",border:"1px solid var(--border)",borderRadius:6,background:l?"var(--accent)":"var(--bg-panel)",color:l?"#fff":"var(--text-muted)",cursor:"pointer",fontSize:12},children:l?"Current":"Switch"}),(0,n.jsx)("button",{type:"button",onClick:()=>M(r),style:{height:28,padding:"0 9px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Rename"}),(0,n.jsx)("button",{type:"button",disabled:f===`remove:${r.cwd}`,onClick:()=>void I(r.cwd),style:{height:28,padding:"0 9px",border:"1px solid rgba(248,113,113,0.35)",borderRadius:6,background:"transparent",color:"#f87171",cursor:"pointer",fontSize:12},children:"Remove"})]})})]},r.cwd)})})]}),(0,n.jsx)(d,{open:x,initialPath:e,onClose:()=>g(!1),onSelect:e=>void z(e)})]})}function op({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 oh(){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 ox(e){return"projects"===e?(0,n.jsx)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M3 6.5A2.5 2.5 0 0 1 5.5 4H10l2 2.5h6.5A2.5 2.5 0 0 1 21 9v8.5A2.5 2.5 0 0 1 18.5 20h-13A2.5 2.5 0 0 1 3 17.5v-11Z"})}):"models"===e?(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),(0,n.jsx)("rect",{x:"9",y:"9",width:"6",height:"6"}),(0,n.jsx)("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),(0,n.jsx)("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),(0,n.jsx)("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),(0,n.jsx)("line",{x1:"15",y1:"20",x2:"15",y2:"23"})]}):"skills"===e?(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),(0,n.jsx)("path",{d:"M2 17l10 5 10-5"}),(0,n.jsx)("path",{d:"M2 12l10 5 10-5"})]}):"generative-ui"===e?(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),(0,n.jsx)("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),(0,n.jsx)("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),(0,n.jsx)("path",{d:"M16 17h5"}),(0,n.jsx)("path",{d:"M18.5 14.5v5"})]}):(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 3v18h18"}),(0,n.jsx)("path",{d:"m19 9-5 5-4-4-3 3"}),(0,n.jsx)("path",{d:"M14 9h5v5"})]})}function og({cwd:e,generativeUI:t,initialTab:r="projects",onGenerativeUIToggle:i,onClose:l,onModelsChanged:s,onProjectSelect:a,onProjectsChanged:d}){let[c,u]=(0,o.useState)(r);(0,o.useEffect)(()=>{u(r)},[r]),(0,o.useEffect)(()=>{let e=e=>{"Escape"===e.key&&l()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[l]);let p=[{id:"projects",label:"Project",description:e?"Overview and paths":"Add or select a project",icon:ox("projects")},{id:"models",label:"Models",description:"~/.config/annodex/providers.json",icon:ox("models")},{id:"skills",label:"Skills",description:e?"Project and global skills":"Select a project first",disabled:!e,icon:ox("skills")},{id:"generative-ui",label:"Generative UI",description:t?"Enabled":"Disabled",icon:ox("generative-ui")}],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)(oh,{})}),(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)(ou,{activeCwd:e,onSelectProject:a,onProjectsChanged:d}),"models"===c&&(0,n.jsx)(oo,{embedded:!0,onClose:()=>{s?.(),l()}}),"skills"===c&&e&&(0,n.jsx)(oc,{cwd:e,embedded:!0,onClose:l}),"generative-ui"===c&&(0,n.jsx)("div",{style:{height:"100%",overflowY:"auto",padding:20},children:(0,n.jsxs)("div",{style:{maxWidth:720,display:"flex",flexDirection:"column",gap:18},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:18,padding:16,border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)",lineHeight:1.35},children:"Generative UI"}),(0,n.jsx)("div",{style:{marginTop:5,fontSize:12,color:"var(--text-muted)",lineHeight:1.55},children:"Render structured widgets and safe visual code blocks directly in chat when the assistant produces UI content."})]}),(0,n.jsx)(op,{checked:t,onChange:i})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:12},children:[(0,n.jsxs)("div",{style:{padding:14,border:"1px solid var(--border)",borderRadius:8},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:700,color:"var(--text)",marginBottom:5},children:"When enabled"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.6},children:"The agent prompt favors compact visual artifacts for icons, forms, dashboards, and small interactive UI when useful."})]}),(0,n.jsxs)("div",{style:{padding:14,border:"1px solid var(--border)",borderRadius:8},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:700,color:"var(--text)",marginBottom:5},children:"Fallback rendering"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.6},children:"Assistant SVG and safe HTML code blocks can be previewed instead of appearing only as source text."})]})]})]})})]})]})]})})}function of({initialWidth:e,minWidth:t,maxWidth:r,storageKey:n,direction:i="right"}){let[l,s]=(0,o.useState)(e),[a,d]=(0,o.useState)(!1),c=(0,o.useRef)(e),u=(0,o.useCallback)(e=>{let o=Math.max(t,Math.min(r,e));s(o),c.current=o,document.documentElement.style.setProperty(n,`${o}px`)},[t,r,n]);(0,o.useEffect)(()=>{try{let e=localStorage.getItem(n);if(e){let n=parseInt(e,10);if(!isNaN(n)&&n>=t&&n<=r)return void u(n)}}catch{}u(c.current)},[n,t,r,u]);let p=(0,o.useCallback)(()=>{d(!0)},[]),h=(0,o.useCallback)(e=>{let t="left"===i?-1:1;u(c.current+e*t)},[u,i]);return{beginResize:p,endResize:(0,o.useCallback)(()=>{d(!1);try{localStorage.setItem(n,String(c.current))}catch{}},[n]),isResizing:a,resizeBy:h,width:l,widthRef:c}}let om=new Set(["pdf","png","jpg","jpeg","gif","webp","svg","bmp","ico","avif"]);function ov(e){let t=(e.replace(/[?#].*$/,"").replace(/[\\/]+$/,"").split(/[\\/]/).pop()??e).toLowerCase().split(".").pop()??"";return om.has(t)}function oy(){let e=(0,i.useRouter)(),t=(0,i.useSearchParams)(),{isDark:r,toggleTheme:l}=$(),[s,a]=(0,o.useState)(null),[d,c]=(0,o.useState)(null),[u,p]=(0,o.useState)(0),[h,x]=(0,o.useState)(0),[g,f]=(0,o.useState)(0),[m,v]=(0,o.useState)(0),[y,b]=(0,o.useState)(!1),[j,k]=(0,o.useState)("projects"),[S,C]=(0,o.useState)({generativeUI:!0,autoRestart:!0}),[z,T]=(0,o.useState)(null),[I,M]=(0,o.useState)(!0),L=of({initialWidth:260,minWidth:180,maxWidth:500,storageKey:"--annodex-sidebar-width"}),R=of({initialWidth:500,minWidth:300,maxWidth:1200,storageKey:"--annodex-right-panel-width",direction:"left"}),W=(0,o.useRef)(null),E=(0,o.useRef)(null),[A,B]=(0,o.useState)(null),N=(0,o.useRef)(null),[P,D]=(0,o.useState)(!1),[O,H]=(0,o.useState)(""),F=(0,o.useRef)(null),_=(0,o.useRef)(!1),U=(0,o.useCallback)(e=>{B(e)},[]);(0,o.useEffect)(()=>{D(!1)},[s?.id]);let V=(0,o.useCallback)(e=>e?e.name||e.firstMessage.slice(0,80)||e.id.slice(0,12):"",[]),q=(0,o.useCallback)(()=>{s&&(_.current=!1,H(s.name||V(s)),D(!0),setTimeout(()=>F.current?.select(),0))},[V,s]),K=(0,o.useCallback)(async()=>{if(_.current){_.current=!1,D(!1);return}if(!s)return void D(!1);let e=O.trim(),t=V(s);if(D(!1),e!==(s.name??"")&&(s.name||e!==t))try{(await fetch(`/api/sessions/${encodeURIComponent(s.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e})})).ok&&(a(t=>t&&t.id===s.id?{...t,name:e}:t),p(e=>e+1))}catch{}},[V,s,O]),J=(0,o.useCallback)(e=>{"Enter"===e.key?(e.preventDefault(),K()):"Escape"===e.key&&(_.current=!0,D(!1))},[K]);(0,o.useEffect)(()=>{let e=!1;return fetch("/api/settings").then(e=>e.ok?e.json():null).then(t=>{e||C(e=>({generativeUI:"boolean"==typeof t?.settings?.generativeUI?t.settings.generativeUI:e.generativeUI,autoRestart:"boolean"==typeof t?.settings?.autoRestart?t.settings.autoRestart:e.autoRestart}))}).catch(()=>{}),()=>{e=!0}},[]),(0,o.useEffect)(()=>{let e=!1,t=!1,r=()=>{t||(t=!0,fetch("/api/version").then(e=>e.ok?e.json():null).then(t=>{e||T(t)}).catch(()=>{}).finally(()=>{t=!1}))};r();let n=window.setInterval(r,6e4);return()=>{e=!0,window.clearInterval(n)}},[]);let Z=(0,o.useCallback)(()=>{let e=!S.generativeUI;C(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=>{C(t=>({...t,..."boolean"==typeof e.settings?.generativeUI?{generativeUI:e.settings.generativeUI}:{}}))}).catch(()=>C(e=>({...e,generativeUI:!e.generativeUI})))},[S.generativeUI]),[Y,G]=(0,o.useState)(null),X=(0,o.useCallback)(e=>{G(e)},[]),[Q,ee]=(0,o.useState)(null),et=(0,o.useCallback)(e=>{ee(e)},[]),[er,en]=(0,o.useState)(null),[eo,ei]=(0,o.useState)(null),el=(0,o.useCallback)(e=>{en(t=>t===e?null:e)},[]);(0,o.useEffect)(()=>{if(!er||!E.current)return;let e=()=>{let e=E.current.getBoundingClientRect();ei({top:e.bottom,left:e.left,width:e.width})};e();let t=new ResizeObserver(e);return t.observe(E.current),()=>t.disconnect()},[er]);let[es,ea]=(0,o.useState)([]),[ed,ec]=(0,o.useState)("files"),[eu,ep]=(0,o.useState)(!1),[eh,ex]=(0,o.useState)(""),[eg,ef]=(0,o.useState)([]),[em,ev]=(0,o.useState)(0),ey=(0,o.useCallback)(e=>{W.current?.insertText("`"+e+"`")},[]),[eb]=(0,o.useState)(()=>t.get("session")),[ej,ek]=(0,o.useState)(null),[ew,eS]=(0,o.useState)(()=>!t.get("session")),eC=(0,o.useRef)(!1),ez=(0,o.useCallback)(t=>{ek(t),t&&!eC.current&&(a(e=>e&&e.cwd!==t?null:e),c(e=>e&&e!==t?null:e),x(e=>e+1),f(e=>e+1),B(null),en(null),e.replace("/workspace",{scroll:!1}))},[e]),eT=(0,o.useCallback)(e=>{ez(e),b(!1),p(e=>e+1)},[ez]),eI=(0,o.useCallback)((t,r=!1)=>{c(null),ek(t.cwd),a(t),x(e=>e+1),B(null),eS(!0),r&&(eC.current=!0,setTimeout(()=>{eC.current=!1},0)),r||e.replace(`?session=${encodeURIComponent(t.id)}`,{scroll:!1})},[e]),eM=(0,o.useCallback)((t,r)=>{a(null),c(r),ek(r),x(e=>e+1),B(null),en(null),e.replace("/workspace",{scroll:!1})},[e]),eL=(0,o.useCallback)(t=>{c(null),ek(t.cwd),a(t),p(e=>e+1),e.replace(`?session=${encodeURIComponent(t.id)}`,{scroll:!1})},[e]),eR=(0,o.useCallback)(()=>{p(e=>e+1),f(e=>e+1),ev(e=>e+1)},[]),eW=(0,o.useCallback)(t=>{p(e=>e+1),c(null),a(e=>({...e??{path:"",cwd:"",created:"",modified:"",messageCount:0,firstMessage:""},id:t})),e.replace(`?session=${encodeURIComponent(t)}`,{scroll:!1})},[e]),eE=(0,o.useCallback)(()=>{eS(!0)},[]),e$=(0,o.useCallback)(t=>{if(p(e=>e+1),s?.id===t){let t=s.cwd;a(null),c(t??null),x(e=>e+1),B(null),en(null),e.replace("/workspace",{scroll:!1})}},[s,e]),eA=(0,o.useCallback)(e=>{ef(t=>t.filter(t=>t.id!==e))},[]),eB=(0,o.useCallback)(e=>{ef(t=>{let r=t.find(t=>t.id===e);return r&&t[t.length-1]?.id!==e?[...t.filter(t=>t.id!==e),r]:t})},[]),eN=(0,o.useCallback)((e,t)=>{if(ov(e)||ov(t)){let r=`preview:${e}`;ef(n=>{let o=n.find(e=>e.id===r);return o?[...n.filter(e=>e.id!==r),o]:[...n,{id:r,filePath:e,fileName:t}]});return}let r=`file:${e}`;ea(n=>n.find(e=>e.id===r)?n:[...n,{id:r,label:t,filePath:e}]),ec(r),ep(!0)},[]),eP=(0,o.useCallback)((e,t,r)=>{let n=r&&r.length>0?r:[{src:e,title:t}],o=Math.max(0,n.findIndex(t=>t.src===e)),i=n[o]??{src:e,title:t},l=`image-preview:${i.src}`,s=i.title?.trim()||i.src.split(/[/?#]/).filter(Boolean).pop()||"Image";ef(e=>{let t=e.find(e=>e.id===l),r={id:l,filePath:i.src,fileName:s,imageSrc:i.src,galleryItems:n,galleryIndex:o};return t?[...e.filter(e=>e.id!==l),{...t,...r}]:[...e,r]})},[]),eD=(0,o.useCallback)(e=>{"files"!==e&&"tools"!==e&&(ea(t=>t.filter(t=>t.id!==e)),ec(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]),eO=d??(null===s&&ej?ej:null),eH=null!==s||null!==eO,eF=ew&&!eH,e_=[{id:"files",label:"Files",closable:!1,icon:"files"},{id:"tools",label:"Tools",closable:!1,icon:"tools"},...es],eU=es.find(e=>e.id===ed)??null,eV=s?V(s):eO?"New chat":"No session",eq=s?.cwd??eO??ej??"",eK=eq?eq.replace(/\/+$/,"").split(/[\\/]/).filter(Boolean).pop()||eq:"",eJ=s?.cwd??ej??eO??void 0,eZ=ej??s?.cwd??d??null,eY=(()=>{let e=z?.runtime,t=e?.installedVersion??z?.latest;if(e?.restartPending&&t){let r=!!e.restartStartedAt;return{label:`${r?"Restarting":"Restart queued"} ${t}`,title:[`Current runtime: v${e.version??z?.current??"unknown"}`,`Installed: v${t}`,r?"A replacement server is starting.":"annodex will restart after active sessions become idle."].join("\n"),active:!0}}return z?.updateAvailable&&z.latest?{label:`Update ${z.latest}`,title:`Current: v${z.current}
|
|
261
261
|
Latest: v${z.latest}
|
|
262
262
|
Run: ${z.updateCommand}`,active:!1}:null})(),eG=(0,o.useCallback)((e="projects")=>{k(e),b(!0)},[]),eX=(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(w,{selectedSessionId:s?.id??null,onSelectSession:eI,onNewSession:eM,initialSessionId:eb,onInitialRestoreDone:eE,refreshKey:u,onSessionDeleted:e$,selectedCwd:s?.cwd??d??ej??null,onCwdChange:ez}),(0,n.jsx)("div",{style:{padding:"8px",flexShrink:0},children:(0,n.jsx)("button",{type:"button",onClick:()=>eG("projects"),title:"Settings","aria-label":"Settings",style:{width:34,display:"flex",alignItems:"center",justifyContent:"center",height:34,padding:0,background:"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:"pointer",fontSize:12,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.38a2 2 0 0 0-.73-2.73l-.15-.09a2 2 0 0 1-1-1.74v-.51a2 2 0 0 1 1-1.72l.15-.1a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2Z"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})})})]});return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{style:{display:"flex",height:"100dvh",overflow:"hidden",background:"var(--bg)"},children:[(0,n.jsx)("div",{className:"sidebar-overlay-backdrop",onClick:()=>M(!1),style:{position:"fixed",inset:0,zIndex:199,background:"rgba(0,0,0,0.4)",opacity:+!!I,pointerEvents:I?"auto":"none",transition:"opacity 0.25s ease"}}),(0,n.jsx)("div",{className:`sidebar-container${I?" sidebar-open":" sidebar-closed"}`,style:{background:"var(--bg-panel)",borderRight:"1px solid var(--border)",display:"flex",flexDirection:"column",flexShrink:0,zIndex:200,width:L.width,minWidth:L.width,transition:I||L.isResizing?"none":void 0},children:eX}),I&&(0,n.jsx)(no,{side:"right",ariaLabel:"Resize sidebar",onResizeStart:L.beginResize,onResize:L.resizeBy,onResizeEnd:L.endResize}),(0,n.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden",minWidth:0},children:[(0,n.jsxs)("div",{ref:E,className:"app-topbar",style:{display:"flex",alignItems:"center",gap:8,flexShrink:0,borderBottom:"1px solid var(--border)",height:48,padding:"0 8px",background:"var(--bg)"},children:[(0,n.jsx)("button",{className:"topbar-sidebar-toggle",onClick:()=>M(e=>!e),title:I?"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:I?(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:P&&s?(0,n.jsx)("input",{ref:F,value:O,onChange:e=>H(e.target.value),onKeyDown:J,onBlur:()=>void K(),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:eV,style:{minWidth:0,maxWidth:"min(420px, 36vw)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:eH?"var(--text)":"var(--text-muted)",fontSize:14,fontWeight:600,lineHeight:1.2},children:eV}),s&&(0,n.jsx)("button",{type:"button",className:"topbar-rename-button",onClick:q,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"})]})})]})}),eK&&(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:eq||eK,style:{minWidth:0,maxWidth:"min(280px, 24vw)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-muted)",fontSize:12,lineHeight:1.2},children:eK})]})]}),eH&&(0,n.jsx)("div",{className:"topbar-chat-tools",style:{display:"flex",alignItems:"center",gap:6,height:28,flexShrink:0},children:(0,n.jsxs)("button",{ref:N,className:"topbar-system-button",onClick:()=>el("system"),title:"System prompt","aria-label":"System prompt",style:{display:"flex",alignItems:"center",gap:6,height:28,padding:"0 9px",background:"system"===er?"var(--bg-selected)":"var(--bg-panel)",border:`1px solid ${"system"===er?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,cursor:"pointer",color:"system"===er?"var(--text)":"var(--text-muted)",fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="system"===er?"var(--text)":"var(--text-muted)",e.currentTarget.style.background="system"===er?"var(--bg-selected)":"var(--bg-panel)"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:A?"var(--accent)":"var(--text-dim)",flexShrink:0},children:[(0,n.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,n.jsx)("polyline",{points:"14 2 14 8 20 8"}),(0,n.jsx)("line",{x1:"8",y1:"13",x2:"16",y2:"13"}),(0,n.jsx)("line",{x1:"8",y1:"17",x2:"13",y2:"17"})]}),(0,n.jsx)("span",{className:"topbar-system-label",children:"System"})]})}),eH&&(Y||Q)&&(()=>{let e=Y?.tokens,t=Y?.cost??0,r=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(0)}k`:String(e),o=t>0?t>=.01?`$${t.toFixed(2)}`:"<$0.01":null,i="var(--text-muted)",l=null;if(Q?.contextWindow){let e=Q.percent,t=Q.tokens;null!==e&&e>90?i="#ef4444":null!==e&&e>70&&(i="rgba(234,179,8,0.95)"),l=null!==t?`${r(t)} / ${r(Q.contextWindow)}`:`? / ${r(Q.contextWindow)}`}let s=[];if(e&&(s.push(`in: ${e.input.toLocaleString()}`),s.push(`out: ${e.output.toLocaleString()}`),s.push(`cache read: ${e.cacheRead.toLocaleString()}`),s.push(`cache write: ${e.cacheWrite.toLocaleString()}`),t>0&&s.push(`cost: $${t.toFixed(4)}`)),Q?.contextWindow){let e=Q.percent;s.push(`context: ${null!==Q.tokens?Q.tokens.toLocaleString():"unknown"} of ${Q.contextWindow.toLocaleString()} tokens${null!==e?` (${e.toFixed(1)}%)`:""}`)}let a=s.join(" | ");return(0,n.jsxs)("div",{className:"topbar-session-stats",title:a,style:{display:"flex",alignItems:"center",gap:10,padding:"0 8px",height:28,border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-panel)",fontSize:11,color:"var(--text-muted)",whiteSpace:"nowrap",cursor:"default",fontVariantNumeric:"tabular-nums"},children:[e&&e.input>0&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"5",y1:"8.5",x2:"5",y2:"1.5"}),(0,n.jsx)("polyline",{points:"2 4 5 1.5 8 4"})]}),r(e.input)]}),e&&e.output>0&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"5",y1:"1.5",x2:"5",y2:"8.5"}),(0,n.jsx)("polyline",{points:"2 6 5 8.5 8 6"})]}),r(e.output)]}),e&&e.cacheRead>0&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M8.5 5a3.5 3.5 0 1 1-1-2.45"}),(0,n.jsx)("polyline",{points:"6.5 1.5 8.5 2.5 7.5 4.5"})]}),r(e.cacheRead)]}),o&&(0,n.jsx)("span",{style:{display:"flex",alignItems:"center",color:"var(--text)",fontWeight:500},children:o}),l&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4,color:i},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M1 9 L1 5 Q1 1 5 1 Q9 1 9 5 L9 9"}),(0,n.jsx)("line",{x1:"1",y1:"9",x2:"9",y2:"9"})]}),l]})]})})(),eY&&(0,n.jsxs)("div",{className:"topbar-update-status",title:eY.title,style:{display:"flex",alignItems:"center",gap:6,height:28,padding:"0 8px",border:`1px solid ${eY.active?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,background:eY.active?"var(--bg-selected)":"var(--bg-panel)",color:eY.active?"var(--accent)":"var(--text-muted)",fontSize:11,whiteSpace:"nowrap",flexShrink:0,fontVariantNumeric:"tabular-nums"},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:"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)("span",{children:eY.label})]}),(0,n.jsx)("button",{type:"button",className:"topbar-icon-button topbar-generate-ui-toggle",onClick:Z,title:`生成式 UI: ${S.generativeUI?"on":"off"}`,"aria-label":`生成式 UI: ${S.generativeUI?"on":"off"}`,style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:28,padding:0,background:S.generativeUI?"var(--bg-selected)":"var(--bg-panel)",border:`1px solid ${S.generativeUI?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,color:S.generativeUI?"var(--accent)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color=S.generativeUI?"var(--accent)":"var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color=S.generativeUI?"var(--accent)":"var(--text-muted)",e.currentTarget.style.background=S.generativeUI?"var(--bg-selected)":"var(--bg-panel)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),(0,n.jsx)("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),(0,n.jsx)("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),(0,n.jsx)("path",{d:"M16 17h5"}),(0,n.jsx)("path",{d:"M18.5 14.5v5"})]})}),(0,n.jsx)("button",{className:"topbar-icon-button topbar-theme-toggle",onClick:e=>{let t=e.currentTarget.getBoundingClientRect();l({x:t.left+t.width/2,y:t.top+t.height/2})},title:r?"Switch to light mode":"Switch to dark mode","aria-label":r?"Switch to light mode":"Switch to dark mode","aria-pressed":r,style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:28,padding:0,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="var(--bg-panel)"},children:r?(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"5"}),(0,n.jsx)("line",{x1:"12",y1:"1",x2:"12",y2:"3"}),(0,n.jsx)("line",{x1:"12",y1:"21",x2:"12",y2:"23"}),(0,n.jsx)("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"}),(0,n.jsx)("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"}),(0,n.jsx)("line",{x1:"1",y1:"12",x2:"3",y2:"12"}),(0,n.jsx)("line",{x1:"21",y1:"12",x2:"23",y2:"12"}),(0,n.jsx)("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"}),(0,n.jsx)("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"})]}):(0,n.jsx)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"})})}),(0,n.jsx)("button",{className:"topbar-icon-button topbar-right-panel-toggle",onClick:()=>ep(e=>!e),title:eu?"Hide right panel":"Show right panel","aria-label":eu?"Hide right panel":"Show right panel",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:28,padding:0,background:eu?"var(--bg-selected)":"var(--bg-panel)",border:`1px solid ${eu?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,color:eu?"var(--accent)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color=eu?"var(--accent)":"var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color=eu?"var(--accent)":"var(--text-muted)",e.currentTarget.style.background=eu?"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"})]})}),er&&eo&&(0,n.jsx)("div",{style:{position:"fixed",top:eo.top,left:eo.left,width:eo.width,zIndex:500},children:"system"===er&&(0,n.jsx)("div",{style:{background:"var(--bg-panel)",borderBottom:"1px solid var(--border)"},children:A?(0,n.jsx)("div",{style:{maxHeight:"min(600px, 75vh)",overflowY:"auto",padding:"12px 16px",color:"var(--text-muted)",fontSize:12,lineHeight:1.6,whiteSpace:"pre-wrap",fontFamily:"var(--font-mono)"},children:A}):""===A?(0,n.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:"System prompt is empty (tools are disabled)"}):(0,n.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:"Send a message to load the system prompt"})})})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"hidden",position:"relative"},children:eH?(0,n.jsx)(tV,{session:s,newSessionCwd:eO,onAgentEnd:eR,onSessionCreated:eL,onSessionForked:eW,onOpenImage:eP,modelsRefreshKey:m,chatInputRef:W,onSystemPromptChange:U,onSessionStatsChange:X,onContextUsageChange:et,generativeUI:S.generativeUI},h):eF?ej?(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:15},children:"Select a session from the sidebar"}):(0,n.jsxs)("div",{style:{position:"absolute",top:12,left:12,display:"flex",alignItems:"flex-start",gap:8,userSelect:"none",pointerEvents:"none"},children:[(0,n.jsxs)("svg",{width:"44",height:"44",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:.7,flexShrink:0},children:[(0,n.jsx)("line",{x1:"20",y1:"12",x2:"4",y2:"12"}),(0,n.jsx)("polyline",{points:"10 6 4 12 10 18"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:18,fontWeight:600,color:"var(--text)",marginBottom:8},children:"Get Started"}),(0,n.jsxs)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.8},children:[(0,n.jsx)("span",{style:{color:"var(--text-dim)",marginRight:6},children:"1."}),"Select a project directory from the sidebar",(0,n.jsx)("br",{}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",marginRight:6},children:"2."}),"Add models via the ",(0,n.jsx)("strong",{style:{color:"var(--text)"},children:"Models"})," button at the bottom"]})]})]}):null})]}),eu&&(0,n.jsx)(no,{side:"left",ariaLabel:"Resize right panel",onResizeStart:R.beginResize,onResize:R.resizeBy,onResizeEnd:R.endResize}),(0,n.jsxs)("div",{className:`right-panel-container${eu?" right-panel-open":" right-panel-closed"}`,style:{display:eu?"flex":"none",flexDirection:"column",borderLeft:"1px solid var(--border)",background:"var(--bg)",flexShrink:0,width:R.width,minWidth:R.width,transition:R.isResizing?"none":void 0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",flexShrink:0,background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",height:36},children:[(0,n.jsxs)("button",{type:"button",className:"right-panel-back-button",onClick:()=>ep(!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)(ni,{tabs:e_,activeTabId:ed,onSelectTab:ec,onCloseTab:eD})})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"hidden"},children:"files"===ed?eJ?(0,n.jsxs)("div",{style:{height:"100%",display:"flex",flexDirection:"column",overflow:"hidden"},children:[(0,n.jsx)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"8px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",flexShrink:0},children:(0,n.jsxs)("div",{style:{position:"relative",flex:1,minWidth:0},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"},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:eh,onChange:e=>ex(e.target.value),placeholder:"Filter files...",style:{width:"100%",height:28,boxSizing:"border-box",padding:"0 26px 0 26px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:12,outline:"none"}}),eh&&(0,n.jsx)("button",{type:"button",onClick:()=>ex(""),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",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,overflowY:"auto",overflowX:"hidden",minHeight:0},children:(0,n.jsx)(rm,{cwd:eJ,onOpenFile:eN,refreshKey:g,onAtMention:ey,searchQuery:eh,onSearchChange:ex})})]}):(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:12},children:"No project selected"}):"tools"===ed?(0,n.jsx)(nd,{refreshKey:em,cwd:eJ??null}):eU?.filePath?eU.filePath.startsWith("__")?(0,n.jsx)(nr,{filePath:eU.filePath}):(0,n.jsx)(r5,{filePath:eU.filePath,cwd:ej??void 0,onOpenFile:eN}):(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:12},children:"No file open"})})]})]}),eg.map((e,t)=>(0,n.jsx)(r9,{id:e.id,filePath:e.imageSrc??e.filePath,fileName:e.fileName,cwd:eJ,galleryItems:e.galleryItems,galleryIndex:e.galleryIndex,active:t===eg.length-1,stackIndex:t,zIndex:700+t,onClose:eA,onFocus:eB,onOpenFile:eN,onOpenImage:eP},e.id)),y&&(0,n.jsx)(og,{cwd:eZ,generativeUI:S.generativeUI,initialTab:j,onGenerativeUIToggle:Z,onModelsChanged:()=>v(e=>e+1),onProjectSelect:eT,onProjectsChanged:()=>p(e=>e+1),onClose:()=>{b(!1),v(e=>e+1)}})]})}},65673:(e,t,r)=>{"use strict";r.d(t,{C3:()=>n});let n="annodex"},70704:(e,t,r)=>{Promise.resolve().then(r.bind(r,17865))}},e=>{e.O(0,[6079,7627,9211,8441,3794,7358],()=>e(e.s=70704)),_N_E=e.O()}]);
|