@seqyuan/annodex 0.1.88 → 0.1.90
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 +11 -11
- 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 +1 -1
- package/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
- 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 +1 -1
- 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/docs/changelog/page_client-reference-manifest.js +1 -1
- package/.next/server/app/docs/changelog.html +2 -2
- package/.next/server/app/docs/changelog.rsc +1 -1
- package/.next/server/app/docs/changelog.segments/_full.segment.rsc +1 -1
- package/.next/server/app/docs/changelog.segments/_head.segment.rsc +1 -1
- package/.next/server/app/docs/changelog.segments/_index.segment.rsc +1 -1
- package/.next/server/app/docs/changelog.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/docs/changelog.segments/docs/changelog/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/docs/changelog.segments/docs/changelog.segment.rsc +1 -1
- package/.next/server/app/docs/changelog.segments/docs.segment.rsc +1 -1
- package/.next/server/app/index.html +1 -1
- package/.next/server/app/index.rsc +1 -1
- package/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/index.segments/_full.segment.rsc +1 -1
- package/.next/server/app/index.segments/_head.segment.rsc +1 -1
- package/.next/server/app/index.segments/_index.segment.rsc +1 -1
- package/.next/server/app/index.segments/_tree.segment.rsc +1 -1
- 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 +1 -1
- package/.next/server/app/login.segments/_full.segment.rsc +1 -1
- package/.next/server/app/login.segments/_head.segment.rsc +1 -1
- package/.next/server/app/login.segments/_index.segment.rsc +1 -1
- package/.next/server/app/login.segments/_tree.segment.rsc +1 -1
- 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 +6 -6
- 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 +2 -2
- package/.next/server/app/workspace.segments/_full.segment.rsc +2 -2
- package/.next/server/app/workspace.segments/_head.segment.rsc +1 -1
- package/.next/server/app/workspace.segments/_index.segment.rsc +1 -1
- package/.next/server/app/workspace.segments/_tree.segment.rsc +1 -1
- 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 +11 -11
- package/.next/server/chunks/6983.js +1 -1
- 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-2c593e6c2b9d5950.js +265 -0
- package/package.json +1 -1
- package/.next/static/chunks/app/workspace/page-50fd55888d1ba01d.js +0 -265
- /package/.next/static/{SuzSKFPuqg3ZLKCnXB9R_ → SDOFq_E7ojxmkJsbWnwQx}/_buildManifest.js +0 -0
- /package/.next/static/{SuzSKFPuqg3ZLKCnXB9R_ → SDOFq_E7ojxmkJsbWnwQx}/_ssgManifest.js +0 -0
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6364],{936:(e,t,r)=>{"use strict";r.d(t,{AppShell:()=>ij});var n=r(95155),o=r(12115),i=r(73321),l=r(46653);function s(e,t){let r=t&&e.startsWith(t)?"~"+e.slice(t.length):e,n=r.includes("/")?"/":"\\",o=r.split(n).filter(Boolean);return o.length<=2?r:"..."+n+o.slice(-2).join(n)}function a(e){let t=new Date(e);return Number.isNaN(t.getTime())?"":t.toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function d({open:e,cwd:t,homeDir:r,onClose:i,onSelectSession:c}){let{pushToast:u}=(0,l.d)(),[p,h]=(0,o.useState)(""),[x,g]=(0,o.useState)("current"),[f,m]=(0,o.useState)([]),[v,y]=(0,o.useState)(!1),[b,j]=(0,o.useState)(!1),k=(0,o.useRef)(null),w=(0,o.useRef)(null);if((0,o.useEffect)(()=>{e&&(g(t?"current":"all"),setTimeout(()=>w.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=p.trim();if(r.length<2){m([]),y(!1),k.current=null,j(!1);return}let n=new AbortController,o=setTimeout(async()=>{y(!0);try{let e=new URLSearchParams({q:r,scope:x});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);m(i.results??[]),j(i.truncated??!1),k.current=null}catch(e){if("AbortError"!==e.name){let t=String(e);k.current!==t&&(k.current=t,u(t,"error")),m([])}}finally{y(!1)}},180);return()=>{clearTimeout(o),n.abort()}},[e,p,x,t,u]),!e)return null;let S=p.trim(),C=f.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:w,value:p,onChange:e=>h(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:()=>g(e.value),style:{height:24,padding:"0 9px",background:x===e.value?"var(--bg-selected)":"transparent",border:"none",borderRadius:5,color:e.disabled?"var(--text-dim)":x===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"===x&&t?s(t,r):"Searching every saved session"})]})]}),(0,n.jsxs)("div",{style:{flex:1,overflowY:"auto",minHeight:180},children:[S.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."}),S.length>=2&&v&&0===f.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Searching..."}),S.length>=2&&!v&&0===f.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"No matching conversations found."}),f.map(e=>(0,n.jsxs)("div",{style:{borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{c(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:a(e.session.modified)})]}),(0,n.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:s(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:()=>{c(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:a(t.timestamp)})]}),(0,n.jsx)("div",{style:{fontSize:12,lineHeight:1.45,color:"var(--text-muted)"},children:function(e,t){let r=t.trim();if(!r)return e;let 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,S)})]},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:C>0?`${C}${b?"+":""} results`:"Esc to close"}),v&&f.length>0&&(0,n.jsx)("span",{children:"Updating..."})]})]})})}function c({open:e,initialPath:t,onClose:r,onSelect:i,onPathInputChange:s}){let{pushToast:a}=(0,l.d)(),[d,u]=(0,o.useState)(""),[p,h]=(0,o.useState)(null),[x,g]=(0,o.useState)([]),[f,m]=(0,o.useState)([]),[v,y]=(0,o.useState)(""),[b,j]=(0,o.useState)(!1),[k,w]=(0,o.useState)(!1),S=(0,o.useCallback)(async e=>{j(!0),w(!1);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}`);u(n.current??""),h(n.parent??null),g(n.directories??[]),m(n.drives??[]),y(n.current??"")}catch(e){w(!0),a(e instanceof Error?e.message:String(e),"error")}finally{j(!1)}},[a]);return((0,o.useEffect)(()=>{e&&S(t||void 0)},[S,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.jsx)("form",{onSubmit:e=>{e.preventDefault(),v.trim()&&i(v.trim())},style:{display:"flex",flexDirection:"column",gap:7},children:(0,n.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,n.jsx)("input",{value:v,onChange:e=>{y(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:()=>v.trim()&&void S(v.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:!v.trim(),style:{height:32,padding:"0 12px",border:"none",borderRadius:6,background:v.trim()?"var(--accent)":"var(--bg-hover)",color:v.trim()?"#fff":"var(--text-dim)",cursor:v.trim()?"pointer":"default",fontSize:12,fontWeight:650},children:"Use path"})]})})}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"8px 12px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsx)("button",{type:"button",onClick:()=>p&&void S(p),disabled:!p,style:{width:28,height:28,border:"1px solid var(--border)",borderRadius:6,background:p?"var(--bg)":"transparent",color:p?"var(--text-muted)":"var(--text-dim)",cursor:p?"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"})})}),f.length>0&&(0,n.jsxs)("select",{value:f.find(e=>d.toLowerCase().startsWith(e.toLowerCase()))??"",onChange:e=>{e.target.value&&S(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"}),f.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:d,children:d})]}),(0,n.jsx)("div",{style:{flex:1,minHeight:220,maxHeight:360,overflowY:"auto",padding:6},children:b?(0,n.jsx)("div",{style:{padding:18,color:"var(--text-muted)",fontSize:12},children:"Loading..."}):k?(0,n.jsx)("div",{style:{padding:18,color:"var(--text-dim)",fontSize:12},children:"Could not browse this folder"}):0===x.length?(0,n.jsx)("div",{style:{padding:18,color:"var(--text-muted)",fontSize:12},children:"No subdirectories"}):x.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>void S(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:d,children:d}),(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:()=>d&&i(d),disabled:!d,style:{height:32,padding:"0 12px",border:"none",borderRadius:6,background:d?"var(--accent)":"var(--bg-hover)",color:d?"#fff":"var(--text-dim)",cursor:d?"pointer":"default",fontSize:12,fontWeight:650},children:"Select"})]})]})]})}):null}var u=r(65673);let p="annodex:sidebar:collapsed-projects",h=["annovibe:sidebar:collapsed-projects","pidex:sidebar:collapsed-projects"];function x(e){window.localStorage.setItem(p,JSON.stringify([...e]))}function g(e){return new DOMException(e,"TimeoutError")}function f(e,t){return e instanceof DOMException&&("AbortError"===e.name||"TimeoutError"===e.name)||e instanceof Error&&/aborted without reason|AbortError/i.test(e.message)?t:e instanceof Error?e.message:String(e)}async function m(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 v(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 y(e,t){let r=t&&e.startsWith(t)?"~"+e.slice(t.length):e,n=r.includes("/")?"/":"\\",o=r.split(n).filter(Boolean);return o.length<=2?r:"…/"+o.slice(-2).join(n)}function b(e,t){if(!e)return"No Project";let r=e.replace(/[\\/]+$/,""),n=r.includes("/")?"/":"\\";return r.split(n).filter(Boolean).pop()||y(e,t)}function j(e){return e.lastAccessed??e.created??""}function k(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 w(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:k(e,t)}let S="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";function C(){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:S[Math.floor(Math.random()*S.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.88":u.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 T({selectedSessionId:e,onSelectSession:t,onNewSession:r,initialSessionId:i,onInitialRestoreDone:s,refreshKey:a,onSessionDeleted:u,selectedCwd:S,onCwdChange:R}){let{pushToast:W}=(0,l.d)(),[E,$]=(0,o.useState)([]),[P,A]=(0,o.useState)({}),[B,N]=(0,o.useState)(!0),[D,O]=(0,o.useState)(!1),[H,F]=(0,o.useState)(!1),[_,U]=(0,o.useState)(null),[q,V]=(0,o.useState)(""),[J,G]=(0,o.useState)(!1),[K,Y]=(0,o.useState)(!1),Z=(0,o.useRef)(null),X=(0,o.useRef)(new Map),[Q,ee]=(0,o.useState)(new Set),[et,er]=(0,o.useState)(()=>(function(){try{for(let e of[p,...h]){let t=window.localStorage.getItem(e);if(t)return new Set(JSON.parse(t))}}catch{}return new Set})()),[en,eo]=(0,o.useState)(!1),ei=(0,o.useRef)(null),[el,es]=(0,o.useState)(null),[ea,ed]=(0,o.useState)(null),[ec,eu]=(0,o.useState)(()=>new Set),ep=(0,o.useRef)(!1),eh=(0,o.useRef)(!1),ex=(0,o.useRef)(!1),eg=(0,o.useCallback)(async(e=!1)=>{try{e&&(F(!1),N(!0));let t=new AbortController,r=setTimeout(()=>t.abort(g("Project loading timed out")),3e4),n=await fetch("/api/projects",{signal:t.signal});if(clearTimeout(r),!n.ok)throw Error(await m("projects",n));let o=await n.json();$(o.projects),F(!1),Z.current=null}catch(t){let e=f(t,"Loading projects timed out. Codex may still be starting; click Refresh to retry.");F(!0),Z.current!==e&&(Z.current=e,W(e,"error"))}finally{e&&N(!1)}},[W]),ef=(0,o.useCallback)(async()=>{try{let e=await fetch("/api/im/session-ids",{cache:"no-store"});if(!e.ok)return;let t=await e.json();eu(new Set((t.sessionIds??[]).filter(Boolean)))}catch{}},[]),em=(0,o.useCallback)(async(e,t=!1)=>{if(e){A(t=>({...t,[e]:{sessions:t[e]?.sessions??[],loaded:t[e]?.loaded??!1,error:null,loading:!0,stale:t[e]?.stale??!1}}));try{t&&N(!0);let r=new AbortController,n=setTimeout(()=>r.abort(g("Chat loading timed out")),3e4),o=await fetch(`/api/sessions?cwd=${encodeURIComponent(e)}`,{signal:r.signal});if(clearTimeout(n),!o.ok)throw Error(await m("sessions",o));let i=await o.json();A(t=>({...t,[e]:{sessions:i.sessions,loaded:!0,loading:!1,error:null,stale:!1}})),X.current.delete(e)}catch(r){let t=f(r,"Loading chats timed out. Codex may still be starting; click Refresh to retry.");A(r=>{let n=(r[e]?.sessions?.length??0)>0;return X.current.get(e)!==t&&(X.current.set(e,t),W(n?`Showing cached chats. ${t}`:t,"error")),{...r,[e]:{sessions:r[e]?.sessions??[],loaded:r[e]?.loaded??!1,loading:!1,error:t,stale:n}}})}finally{t&&N(!1)}}},[W]),ev=(0,o.useRef)(!1);(0,o.useEffect)(()=>{let e=!ev.current;ev.current=!0,eg(e),ef()},[eg,ef,a]),(0,o.useEffect)(()=>{fetch("/api/home").then(e=>e.json()).then(e=>{e.home&&V(e.home)}).catch(()=>{})},[]),(0,o.useEffect)(()=>{if(ep.current){ep.current=!1;return}if(eh.current){eh.current=!1;return}R?.(_)},[_,R]);let ey=(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 W(n.error??`HTTP ${r.status}`,"error"),!1;return eg(!1),!0}catch(e){return W(e instanceof Error?e.message:String(e),"error"),!1}},[eg,W]),eb=(0,o.useCallback)(e=>{fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,touch:!0})}).catch(()=>{})},[]),ej=(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 m("projects",t));let r=await t.json();Array.isArray(r.projects)&&$(r.projects)},[]);(0,o.useEffect)(()=>{if(!i||ex.current)return;let e=!1;return fetch(`/api/sessions/${encodeURIComponent(i)}?infoOnly=1`).then(e=>e.ok?e.json():null).then(r=>{if(e||ex.current)return;let n=r?.info??null;n&&(ex.current=!0,U(n.cwd),em(n.cwd,!1),eb(n.cwd),t(n,!0))}).finally(()=>{e||ex.current||s?.()}),()=>{e=!0}},[i,em,s,t,eb]);let ek=(0,o.useCallback)(e=>{eh.current=!0,U(e),eo(!1),er(t=>{if(!t.has(e))return t;let r=new Set(t);return r.delete(e),x(r),r}),R?.(e),eb(e),em(e,!1)},[em,R,eb]);(0,o.useEffect)(()=>{if(0!==E.length&&null===_&&!S){if(i&&!ex.current)return;let e=[...E].sort((e,t)=>{let r=j(e),n=j(t);return r!==n?n.localeCompare(r):k(e,t)}),t=e[0]?.cwd;t&&(U(t),eb(t),em(t,!1))}},[E,_,S,i,eb,em]);let ew=(0,o.useCallback)(async e=>{await ey(e,!1)&&(ek(e),G(!1))},[ek,ey]),eS=S??_,eC=(0,o.useCallback)(async()=>{O(!0);try{await eg(!1);let e=new Set([...E.filter(e=>!0===e.pinned).map(e=>e.cwd),...eS?[eS]:[]]);await Promise.all([...[...e].map(e=>em(e,!1)),ef()])}finally{O(!1)}},[eS,ef,eg,em,E]);(0,o.useEffect)(()=>{if(!en)return;let e=e=>{ei.current&&!ei.current.contains(e.target)&&eo(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[en]);let eT=(0,o.useCallback)(e=>{if(!e)return void G(!0);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]),eI=(0,o.useCallback)(()=>{eT(eS)},[eT,eS]),ez=(0,o.useCallback)(()=>{G(!0)},[]),eM=(0,o.useMemo)(()=>[...eS&&!E.some(e=>e.cwd===eS)?[{cwd:eS,displayName:b(eS,q),chatCount:P[eS]?.sessions.length??0,lastAccessed:null,created:null,pinned:!1,sortOrder:null,exists:!0,source:"manual"}]:[],...E].sort(w),[eS,q,E,P]),eL=(0,o.useMemo)(()=>eM.filter(e=>!0!==e.pinned),[eM]),eR=(0,o.useMemo)(()=>eM.find(e=>e.cwd===eS)??null,[eM,eS]),eW=(0,o.useMemo)(()=>{let e=e=>{let t=P[e.cwd],r=[...t?.sessions??[]].sort((e,t)=>t.modified.localeCompare(e.modified));return{project:e,cwd:e.cwd,displayName:e.displayName||b(e.cwd,q),sessions:r,sessionsState:t,lastAccessed:j(e)||r[0]?.modified||""}},t=eM.filter(e=>!0===e.pinned).map(e);if(eS){let r=eM.find(e=>e.cwd===eS);r&&!0!==r.pinned&&t.push(e(r))}return t},[eS,q,P,eM]);(0,o.useEffect)(()=>{eS&&(er(e=>{if(!e.has(eS))return e;let t=new Set(e);return t.delete(eS),x(t),t}),em(eS,!1))},[eS,em,a]),(0,o.useEffect)(()=>{for(let e of eW){if(et.has(e.cwd))continue;let t=P[e.cwd];t?.loaded||t?.loading||em(e.cwd,!1)}},[et,em,eW,P]);let eE=(0,o.useCallback)(e=>{er(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),x(r),r});let t=P[e];t?.loaded||t?.loading||em(e,!1)},[em,P]),e$=(0,o.useCallback)(e=>{ee(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),eP=(0,o.useCallback)(async(e,t)=>{$(r=>r.map(r=>r.cwd===e?{...r,pinned:t}:r).sort(w)),t&&(er(t=>{if(!t.has(e))return t;let r=new Set(t);return r.delete(e),x(r),r}),em(e,!1));try{await ej({cwd:e,pinned:t})}catch{eg(!1)}},[eg,em,ej]),eA=(0,o.useCallback)(e=>{es(e),ed(e)},[]),eB=(0,o.useCallback)(async e=>{if(!el||el===e){es(null),ed(null);return}let t=[...E].filter(e=>!0===e.pinned).sort(w),r=t.findIndex(e=>e.cwd===el),n=t.findIndex(t=>t.cwd===e);if(r<0||n<0){es(null),ed(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}));$(e=>{let t=new Map(e.map(e=>[e.cwd,e]));for(let e of o){let r=t.get(e.cwd);r&&t.set(e.cwd,{...r,sortOrder:e.sortOrder})}return[...t.values()].sort(w)}),es(null),ed(null);try{await ej({order:o.map(e=>e.cwd)})}catch{eg(!1)}},[el,eg,E,ej]),eN=(0,o.useCallback)(()=>{es(null),ed(null)},[]),eD=(0,o.useCallback)((e,r=!1)=>{e.cwd!==eS&&(ep.current=!0,U(e.cwd)),er(t=>{if(!t.has(e.cwd))return t;let r=new Set(t);return r.delete(e.cwd),x(r),r}),eb(e.cwd),t(e,r)},[t,eS,eb]);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsxs)("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)(C,{}),(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsxs)("button",{onClick:eI,disabled:!eS,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,background:"var(--bg-hover)",border:"1px solid var(--border)",color:eS?"var(--text-muted)":"var(--text-dim)",cursor:eS?"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:eS?`New session in ${eS}`:"Select a project first",onMouseEnter:e=>{eS&&(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=eS?"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:()=>Y(!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.jsxs)("div",{ref:ei,style:{position:"relative",marginTop:8,display:"flex",alignItems:"stretch",gap:4},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>eo(e=>!e),style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:6,padding:"6px 10px",background:eS?"var(--bg-hover)":"rgba(37,99,235,0.06)",border:eS?"1px solid var(--border)":"1px solid rgba(37,99,235,0.4)",borderRadius:7,cursor:"pointer",fontSize:12,color:"var(--text)",textAlign:"left"},title:eS??"Select project",children:[(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.35",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:"var(--accent)"},children:(0,n.jsx)("path",{d:"M1.5 5A1.5 1.5 0 0 1 3 3.5h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6.5L13.6 11A1.5 1.5 0 0 1 12.1 12.5H3A1.5 1.5 0 0 1 1.5 11V5Z"})}),(0,n.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)",fontSize:11,color:eS?"var(--text)":"var(--text-dim)"},children:eS?eR?.displayName??y(eS,q):"Select project…"}),(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:en?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),eS&&(0,n.jsx)(I,{pinned:eR?.pinned===!0,onToggle:()=>void eP(eS,eR?.pinned!==!0)}),en&&(0,n.jsxs)("div",{style:{position:"absolute",top:"calc(100% + 4px)",left:0,right:0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 6px 20px rgba(0,0,0,0.10)",overflow:"hidden",maxHeight:280,overflowY:"auto"},children:[0===eL.length&&(0,n.jsx)("div",{style:{padding:"10px 12px",color:"var(--text-dim)",fontSize:11},children:"No projects yet"}),eL.map(e=>{let t=e.cwd===eS;return(0,n.jsx)(z,{project:e,homeDir:q,isCurrent:t,onSelect:()=>ek(e.cwd),onTogglePinned:()=>void eP(e.cwd,!0)},e.cwd)}),(0,n.jsxs)("button",{type:"button",onClick:()=>{eo(!1),ez()},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",borderTop:eL.length>0?"1px solid var(--border)":"none",color:"var(--accent)",cursor:"pointer",textAlign:"left",fontSize:11},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"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"})]}),"Add project…"]})]})]})]}),(0,n.jsx)(d,{open:K,cwd:eS,homeDir:q,onClose:()=>Y(!1),onSelectSession:e=>{eD(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.jsx)("span",{style:{fontSize:10,fontWeight:600,letterSpacing:"0.05em",textTransform:"uppercase"},children:"Projects"}),(0,n.jsx)("button",{type:"button",onClick:()=>void eC(),disabled:D,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:D?"var(--accent)":"var(--text-dim)",cursor:D?"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:D?"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"})]})})]}),B&&0===eW.length&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Loading..."}),!B&&H&&0===eW.length&&(0,n.jsx)("div",{style:{padding:"12px 14px",color:"var(--text-dim)",fontSize:12},children:"Could not load projects"}),!B&&!H&&0===eW.length&&(0,n.jsx)("div",{style:{padding:"12px 14px",color:"var(--text-muted)",fontSize:12},children:"Pin a project or select one from the switcher above to view chats."}),!B&&eW.map(t=>{var r;let o=et.has(t.cwd),i=t.cwd===eS,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),Q.has(t.cwd),{visible:r,hiddenCount:0}),d=!0===t.project.pinned;return(0,n.jsxs)("div",{style:{marginBottom:6},children:[(0,n.jsx)(M,{group:t,isCurrent:i,isCollapsed:o,draggable:d,isDragged:el===t.cwd,isDropTarget:d&&ea===t.cwd&&el!==t.cwd,onToggle:()=>eE(t.cwd),onSelect:()=>ek(t.cwd),onTogglePinned:()=>void eP(t.cwd,!d),onNewSession:e=>{e.stopPropagation(),ek(t.cwd),eT(t.cwd)},onDragStart:()=>eA(t.cwd),onDragEnter:()=>{d&&el&&el!==t.cwd&&ed(t.cwd)},onDrop:()=>void eB(t.cwd),onDragEnd:eN}),!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?.loading&&(!l?.error||l?.stale)&&0===t.sessions.length&&l?.loaded?(0,n.jsx)("button",{type:"button",onClick:()=>{ek(t.cwd),eT(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 chat"}):!l?.loading&&(!l?.error||l?.stale)&&t.sessions.length>0?s.map(r=>(0,n.jsx)(L,{node:r,selectedSessionId:e,onSelectSession:eD,onRenamed:()=>void em(t.cwd,!1),onSessionDeleted:e=>{u?.(e),em(t.cwd,!1),eg(!1),ef()},imSessionIds:ec,depth:0},r.session.id)):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 ${v(t.lastAccessed)}`:"No chats loaded"}),a>0&&t.sessions.length>0&&(0,n.jsx)("button",{type:"button",onClick:()=>e$(t.cwd),style:{width:"100%",padding:"6px 10px",background:"transparent",border:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:11,textAlign:"center"},children:Q.has(t.cwd)?"Show less":`Show ${Math.max(0,a)} more`})]})]},t.cwd)})]}),(0,n.jsx)(c,{open:J,initialPath:eS||q||null,onClose:()=>G(!1),onSelect:e=>void ew(e)})]})}function I({pinned:e,onToggle:t}){return(0,n.jsx)("button",{type:"button",onClick:t,title:e?"Unpin project":"Pin project to sidebar",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:"auto",padding:0,border:"1px solid var(--border)",borderRadius:7,background:e?"rgba(234,179,8,0.12)":"var(--bg-hover)",color:e?"#ca8a04":"var(--text-muted)",cursor:"pointer",flexShrink:0},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:e?"currentColor":"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})})}function z({project:e,homeDir:t,isCurrent:r,onSelect:i,onTogglePinned:l}){let[s,a]=(0,o.useState)(!1),d=e.displayName||b(e.cwd,t);return(0,n.jsxs)("div",{onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),style:{display:"flex",alignItems:"center",gap:4,background:r?"var(--bg-selected)":s?"var(--bg-hover)":"none",borderBottom:"1px solid var(--border)"},children:[(0,n.jsx)("span",{style:{width:10,marginLeft:6,flexShrink:0}}),(0,n.jsxs)("button",{type:"button",onClick:i,title:e.cwd,style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:7,padding:"8px 10px 8px 0",background:"none",border:"none",color:r?"var(--text)":"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11,fontFamily:"var(--font-mono)"},children:[r?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d}),!e.exists&&(0,n.jsx)("span",{style:{flexShrink:0,color:"#f87171",fontSize:10},children:"missing"})]}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),l()},title:"Pin project to sidebar",tabIndex:s?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,marginRight:4,padding:0,border:"none",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,opacity:+!!s,pointerEvents:s?"auto":"none"},children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})})]})}function M({group:e,isCurrent:t,isCollapsed:r,draggable:i,isDragged:l,isDropTarget:s,onToggle:a,onSelect:d,onTogglePinned:c,onNewSession:u,onDragStart:p,onDragEnter:h,onDrop:x,onDragEnd:g}){let[f,m]=(0,o.useState)(!1),y=e.lastAccessed,b=Math.max(0,e.project.chatCount??e.sessions.length??0),j=!0===e.project.pinned,k=(0,o.useCallback)(()=>{t?a():d()},[t,d,a]);return(0,n.jsxs)("div",{draggable:i,role:"button",tabIndex:0,onClick:k,onDragStart:t=>{i?(t.dataTransfer.effectAllowed="move",t.dataTransfer.setData("text/plain",e.cwd),p()):t.preventDefault()},onDragEnter:e=>{i&&(e.preventDefault(),h())},onDragOver:e=>{i&&(e.preventDefault(),e.dataTransfer.dropEffect="move")},onDrop:e=>{i&&(e.preventDefault(),e.stopPropagation(),x())},onDragEnd:g,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),k())},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)":f?"var(--bg-hover)":"transparent",border:"none",borderRadius:6,boxShadow:s?"inset 0 0 0 1px rgba(37,99,235,0.45)":"none",color:"var(--text)",cursor:i?"grab":"pointer",textAlign:"left",overflow:"hidden",transition:"background 0.12s, box-shadow 0.12s, opacity 0.12s",opacity:l?.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"}),!f&&b>0&&(0,n.jsxs)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:[b," ",1===b?"chat":"chats"]}),!f&&y&&(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:v(y)}),j&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),c()},title:"Unpin project",tabIndex:f?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,border:"none",borderRadius:5,background:"rgba(234,179,8,0.12)",color:"#ca8a04",cursor:"pointer",flexShrink:0,opacity:f?1:.85,pointerEvents:f?"auto":"none",transition:"opacity 0.12s"},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"currentColor",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})}),!j&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),c()},title:"Pin project to sidebar",tabIndex:f?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:+!!f,pointerEvents:f?"auto":"none",transition:"opacity 0.12s, background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="#ca8a04"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})}),(0,n.jsx)("button",{type:"button",onClick:u,title:"New chat in this project",tabIndex:f?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:+!!f,pointerEvents:f?"auto":"none",transition:"opacity 0.12s, background 0.12s, 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 L({node:e,selectedSessionId:t,onSelectSession:r,onRenamed:i,onSessionDeleted:l,imSessionIds:s,depth:a}){let[d,c]=(0,o.useState)(!1),u=e.children.length>0;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{position:"relative"},children:[a>0&&(0,n.jsx)("div",{style:{position:"absolute",left:12*a+6,top:0,bottom:0,width:1,background:"var(--border)",pointerEvents:"none"}}),(0,n.jsx)(R,{session:e.session,isSelected:e.session.id===t,isImSession:s.has(e.session.id),onClick:()=>r(e.session),onRenamed:i,onDeleted:e=>l?.(e),depth:a,hasChildren:u,collapsed:d,onToggleCollapse:()=>c(e=>!e)})]}),u&&!d&&(0,n.jsx)("div",{children:e.children.map(e=>(0,n.jsx)(L,{node:e,selectedSessionId:t,onSelectSession:r,onRenamed:i,onSessionDeleted:l,imSessionIds:s,depth:a+1},e.session.id))})]})}function R({session:e,isSelected:t,isImSession:r=!1,onClick:i,onRenamed:l,onDeleted:s,depth:a=0,hasChildren:d=!1,collapsed:c=!1,onToggleCollapse:u}){let[p,h]=(0,o.useState)(!1),[x,g]=(0,o.useState)(!1),[f,m]=(0,o.useState)(""),[y,b]=(0,o.useState)(!1),[j,k]=(0,o.useState)(!1),w=(0,o.useRef)(null),S=e.name||e.firstMessage.slice(0,50)||e.id.slice(0,12),C=(0,o.useCallback)(t=>{t.stopPropagation(),m(e.name??""),g(!0),setTimeout(()=>w.current?.select(),0)},[e.name]),T=(0,o.useCallback)(async()=>{let t=f.trim();if(g(!1),t!==(e.name??""))try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t})}),l?.()}catch{}},[f,e.id,e.name,l]),I=(0,o.useCallback)(e=>{e.stopPropagation(),b(!0)},[]),z=(0,o.useCallback)(async t=>{t.stopPropagation(),b(!1),k(!0);try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"DELETE"}),s?.(e.id)}catch{k(!1)}},[e.id,s]),M=(0,o.useCallback)(e=>{e.stopPropagation(),b(!1)},[]);return(0,n.jsx)("div",{onClick:y||x?void 0:i,onMouseEnter:()=>h(!0),onMouseLeave:()=>{h(!1)},style:{height:54,display:"flex",alignItems:"center",paddingLeft:a>0?12*a+14:14,paddingRight:8,cursor:y||x?"default":"pointer",background:y?"rgba(239,68,68,0.06)":t?"var(--bg-selected)":p?"var(--bg-hover)":"transparent",borderLeft:y?"2px solid #ef4444":t?"2px solid var(--accent)":"2px solid transparent",transition:"background 0.1s",opacity:j?.5:1,gap:6,overflow:"hidden"},children:y?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0,fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["Delete ",(0,n.jsxs)("span",{style:{fontWeight:600},children:["“",S.slice(0,22),S.length>22?"…":"","”"]}),"?"]}),(0,n.jsxs)("div",{style:{display:"flex",gap:5,flexShrink:0},children:[(0,n.jsxs)("button",{onClick:z,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,height:30,padding:"0 11px",background:"#ef4444",border:"none",borderRadius:6,color:"#fff",cursor:"pointer",fontSize:12,fontWeight:600,whiteSpace:"nowrap"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,n.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,n.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,n.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]}),"Delete"]}),(0,n.jsx)("button",{onClick: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"})]})]}):x?(0,n.jsx)("input",{ref:w,value:f,onChange:e=>m(e.target.value),onBlur:T,onKeyDown:e=>{"Enter"===e.key&&T(),"Escape"===e.key&&g(!1)},autoFocus:!0,style:{flex:1,fontSize:12,padding:"5px 8px",border:"1px solid var(--accent)",borderRadius:5,outline:"none",background:"var(--bg)",color:"var(--text)",height:30}}):(0,n.jsxs)(n.Fragment,{children:[a>0&&(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,minWidth:0},children:[r?(0,n.jsx)("span",{title:"WeCom IM thread",style:{flexShrink:0,fontSize:9,fontWeight:700,letterSpacing:"0.03em",lineHeight:1,padding:"2px 5px",borderRadius:4,background:"color-mix(in srgb, var(--accent) 14%, transparent)",color:"var(--accent)",border:"1px solid color-mix(in srgb, var(--accent) 28%, transparent)"},children:"[IM]"}):null,(0,n.jsx)("div",{style:{flex:1,minWidth:0,fontSize:12,fontWeight:t?500:400,lineHeight:1.4,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text)"},title:S,children:S})]}),(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:v(e.modified)}),(0,n.jsxs)("span",{children:[e.messageCount," msgs"]}),!1===e.cwdExists&&(0,n.jsx)("span",{title:`Project path missing: ${e.cwd}`,style:{color:"#f87171"},children:"missing path"})]})]}),d&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u?.()},title:c?"Expand forks":"Collapse forks",style:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,flexShrink:0,background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",transform:c?"rotate(-90deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})}),p&&(0,n.jsxs)("div",{style:{display:"flex",gap:4,flexShrink:0},children:[(0,n.jsx)("button",{onClick:C,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:I,title:"Delete",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",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"})]})})]})]})})}function W(e){if("user"!==e.role)return"";let t=e.content;return"string"==typeof t?t.trim():t.filter(e=>"object"==typeof e&&null!==e&&"type"in e&&"text"===e.type).map(e=>e.text).join("\n").trim()}let E=new Map;function $(e){e&&E.set(e,{cursor:-1,draftSnapshot:""})}var P=r(97031),A=r(97894),B=r(16764);let N=new Set;function D(e){return N.add(e),()=>{N.delete(e)}}function O(){return"u"<typeof document?"light":document.documentElement.classList.contains("dark")?"dark":"light"}function H(){return"light"}function F(){let e=(0,o.useSyncExternalStore)(D,O,H);return{theme:e,toggleTheme:(0,o.useCallback)(e=>{let t="dark"===O()?"light":"dark",r=()=>{"dark"===t?document.documentElement.classList.add("dark"):document.documentElement.classList.remove("dark");try{localStorage.setItem("annodex-theme",t)}catch{}N.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 _({chart:e}){let{isDark:t}=F(),[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 U(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=q(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=V(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=q(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=q(t);i?r.push({type:"widget",...i}):t&&r.push({type:"text",content:t}),n.lastIndex=o=a+3}else{let t=q(e.slice(s).trim());if(t){let e=V(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 q(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 V(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 J=/<(iframe|object|embed|meta|link|base|form)[\s>][\s\S]*?<\/\1>/gi,G=/<(iframe|object|embed|meta|link|base)\b[^>]*\/?>/gi;function K(e){return e.replace(J,"").replace(G,"")}let Y=["--bg","--bg-panel","--bg-hover","--bg-selected","--border","--text","--text-muted","--text-dim","--accent","--accent-hover"];function Z(){if("u"<typeof document)return{};let e=getComputedStyle(document.documentElement),t={};for(let r of Y){let n=e.getPropertyValue(r).trim();n&&(t[r]=n)}return t}let X=["--bg","--bg-panel","--bg-hover","--bg-selected","--border","--text","--text-muted","--text-dim","--accent","--accent-hover"];async function Q(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.")}function ee(e,t){let r=URL.createObjectURL(e),n=document.createElement("a");n.href=r,n.download=t,document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(r)}async function et(e){let t=await er(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=ei({width:e.bodyWidth||640,height:e.bodyHeight||360}),r=function(e){let t=document.createElement("template");t.innerHTML=K(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 en(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 X.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 es(ea('<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 er(e){var t;let r,n,o,i,l=function(e){let t=K(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;en(l),l.setAttribute("xmlns","http://www.w3.org/2000/svg");let s=ei((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=eo(t.getAttribute("width"))??r?.width??640,o=r?r.height/r.width:.5625,i=eo(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),es(ea(new XMLSerializer().serializeToString(l)),s.width,s.height)}function en(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 eo(e){if(!e||e.includes("%"))return null;let t=Number.parseFloat(e);return Number.isFinite(t)&&t>0?t:null}function ei(e){let t=el(Math.ceil(e.width||640),240,2e3),r=el(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 el(e,t,r){return Math.min(Math.max(e,t),r)}function es(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 ea(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 ed=/cdnjs\.cloudflare\.com|cdn\.jsdelivr\.net|unpkg\.com|esm\.sh/,ec=new Map;function eu(e){return e.slice(0,200)}function ep({code:e,isStreaming:t,title:r,showOverlay:i,onSendMessage:l}){let{isDark:s}=F(),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)(()=>ec.get(eu(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,T]=(0,o.useState)(!1),I=(0,o.useRef)(""),z=(0,o.useRef)((ec.get(eu(e))??0)>0),M=(0,o.useRef)(!1),L=(0,o.useRef)(s),R=(0,o.useMemo)(()=>ed.test(e),[e]),W=(0,o.useMemo)(()=>{let e;return function(e="",t=!1){return`<!DOCTYPE html>
|
|
2
|
-
<html class="${t?"dark":""}">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
6
|
-
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'unsafe-inline' https://cdnjs.cloudflare.com https://cdn.jsdelivr.net https://unpkg.com https://esm.sh; style-src 'unsafe-inline'; img-src * data: blob:; font-src * data:; connect-src 'none'">
|
|
7
|
-
<style>
|
|
8
|
-
${e}
|
|
9
|
-
</style>
|
|
10
|
-
</head>
|
|
11
|
-
<body>
|
|
12
|
-
<div id="__root" style="height:fit-content;"></div>
|
|
13
|
-
<script>
|
|
14
|
-
(function() {
|
|
15
|
-
var root = document.getElementById("__root");
|
|
16
|
-
var timer = null;
|
|
17
|
-
var first = true;
|
|
18
|
-
var lastHeight = 0;
|
|
19
|
-
|
|
20
|
-
function notifyReady() {
|
|
21
|
-
parent.postMessage({ type: "widget:ready" }, "*");
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function reportHeight() {
|
|
25
|
-
if (timer) clearTimeout(timer);
|
|
26
|
-
timer = setTimeout(function() {
|
|
27
|
-
var rect = root.getBoundingClientRect();
|
|
28
|
-
var h = Math.ceil(Math.max(rect.height, document.body.scrollHeight, document.documentElement.scrollHeight));
|
|
29
|
-
if (h > 0 && h !== lastHeight) {
|
|
30
|
-
lastHeight = h;
|
|
31
|
-
parent.postMessage({ type: "widget:resize", height: h, first: first }, "*");
|
|
32
|
-
}
|
|
33
|
-
first = false;
|
|
34
|
-
}, 60);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function handleUpdate(html) {
|
|
38
|
-
root.innerHTML = html;
|
|
39
|
-
reportHeight();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function handleFinalize(html) {
|
|
43
|
-
var tmp = document.createElement("div");
|
|
44
|
-
tmp.innerHTML = html;
|
|
45
|
-
var nodes = tmp.querySelectorAll("script");
|
|
46
|
-
var scripts = [];
|
|
47
|
-
for (var i = 0; i < nodes.length; i++) {
|
|
48
|
-
var item = { src: nodes[i].src || "", text: nodes[i].textContent || "", attrs: [] };
|
|
49
|
-
for (var j = 0; j < nodes[i].attributes.length; j++) {
|
|
50
|
-
var attr = nodes[i].attributes[j];
|
|
51
|
-
if (attr.name !== "src" && attr.name !== "onload") item.attrs.push({ name: attr.name, value: attr.value });
|
|
52
|
-
}
|
|
53
|
-
scripts.push(item);
|
|
54
|
-
nodes[i].remove();
|
|
55
|
-
}
|
|
56
|
-
var visualHtml = tmp.innerHTML;
|
|
57
|
-
if (root.innerHTML !== visualHtml) root.innerHTML = visualHtml;
|
|
58
|
-
|
|
59
|
-
var cdnScripts = scripts.filter(function(s) { return !!s.src; });
|
|
60
|
-
var inlineScripts = scripts.filter(function(s) { return !s.src && s.text; });
|
|
61
|
-
function appendInline() {
|
|
62
|
-
for (var k = 0; k < inlineScripts.length; k++) {
|
|
63
|
-
var s = document.createElement("script");
|
|
64
|
-
s.textContent = inlineScripts[k].text;
|
|
65
|
-
for (var a = 0; a < inlineScripts[k].attrs.length; a++) {
|
|
66
|
-
s.setAttribute(inlineScripts[k].attrs[a].name, inlineScripts[k].attrs[a].value);
|
|
67
|
-
}
|
|
68
|
-
root.appendChild(s);
|
|
69
|
-
}
|
|
70
|
-
reportHeight();
|
|
71
|
-
setTimeout(function() { parent.postMessage({ type: "widget:scriptsReady" }, "*"); }, 50);
|
|
72
|
-
}
|
|
73
|
-
if (cdnScripts.length === 0) {
|
|
74
|
-
appendInline();
|
|
75
|
-
} else {
|
|
76
|
-
var pending = cdnScripts.length;
|
|
77
|
-
function done() { pending--; if (pending <= 0) appendInline(); }
|
|
78
|
-
for (var c = 0; c < cdnScripts.length; c++) {
|
|
79
|
-
var n = document.createElement("script");
|
|
80
|
-
n.src = cdnScripts[c].src;
|
|
81
|
-
n.onload = done;
|
|
82
|
-
n.onerror = done;
|
|
83
|
-
for (var d = 0; d < cdnScripts[c].attrs.length; d++) {
|
|
84
|
-
n.setAttribute(cdnScripts[c].attrs[d].name, cdnScripts[c].attrs[d].value);
|
|
85
|
-
}
|
|
86
|
-
root.appendChild(n);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
reportHeight();
|
|
90
|
-
setTimeout(reportHeight, 150);
|
|
91
|
-
setTimeout(reportHeight, 600);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function handleTheme(vars) {
|
|
95
|
-
Object.entries(vars || {}).forEach(function(_a) {
|
|
96
|
-
var key = _a[0], val = _a[1];
|
|
97
|
-
document.documentElement.style.setProperty(key, val);
|
|
98
|
-
});
|
|
99
|
-
if (typeof arguments[1] === "boolean") {
|
|
100
|
-
document.documentElement.className = arguments[1] ? "dark" : "";
|
|
101
|
-
}
|
|
102
|
-
reportHeight();
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function captureRenderedWidget(requestId) {
|
|
106
|
-
try {
|
|
107
|
-
var html = root.innerHTML;
|
|
108
|
-
var styles = "";
|
|
109
|
-
var styleEls = document.querySelectorAll("style");
|
|
110
|
-
for (var si = 0; si < styleEls.length; si++) {
|
|
111
|
-
styles += styleEls[si].textContent || "";
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
var canvases = document.querySelectorAll("canvas");
|
|
115
|
-
var snapshots = [];
|
|
116
|
-
var placeholders = [];
|
|
117
|
-
var hidden = [];
|
|
118
|
-
for (var ci = 0; ci < canvases.length; ci++) {
|
|
119
|
-
try {
|
|
120
|
-
var canvas = canvases[ci];
|
|
121
|
-
var placeholder = document.createElement("img");
|
|
122
|
-
placeholder.setAttribute("data-canvas-export", String(ci));
|
|
123
|
-
placeholder.style.cssText = "width:" + canvas.offsetWidth + "px;height:" + canvas.offsetHeight + "px;display:block;";
|
|
124
|
-
canvas.parentNode.insertBefore(placeholder, canvas);
|
|
125
|
-
placeholders.push(placeholder);
|
|
126
|
-
hidden.push({ node: canvas, display: canvas.style.display });
|
|
127
|
-
canvas.style.display = "none";
|
|
128
|
-
snapshots.push({
|
|
129
|
-
dataUrl: canvas.toDataURL("image/png"),
|
|
130
|
-
width: canvas.offsetWidth,
|
|
131
|
-
height: canvas.offsetHeight,
|
|
132
|
-
});
|
|
133
|
-
} catch (_err) {
|
|
134
|
-
snapshots.push(null);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
html = root.innerHTML;
|
|
139
|
-
|
|
140
|
-
for (var pi = 0; pi < placeholders.length; pi++) {
|
|
141
|
-
placeholders[pi].remove();
|
|
142
|
-
}
|
|
143
|
-
for (var hi = 0; hi < hidden.length; hi++) {
|
|
144
|
-
hidden[hi].node.style.display = hidden[hi].display;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
parent.postMessage({
|
|
148
|
-
type: "widget:captured",
|
|
149
|
-
requestId: requestId,
|
|
150
|
-
html: html,
|
|
151
|
-
styles: styles,
|
|
152
|
-
canvases: snapshots,
|
|
153
|
-
bodyWidth: document.body.scrollWidth,
|
|
154
|
-
bodyHeight: document.body.scrollHeight,
|
|
155
|
-
}, "*");
|
|
156
|
-
} catch (_err) {
|
|
157
|
-
parent.postMessage({ type: "widget:captured", requestId: requestId, html: null }, "*");
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
var ro = new ResizeObserver(reportHeight);
|
|
162
|
-
ro.observe(root);
|
|
163
|
-
|
|
164
|
-
window.addEventListener("message", function(e) {
|
|
165
|
-
if (!e.data || typeof e.data.type !== "string") return;
|
|
166
|
-
switch (e.data.type) {
|
|
167
|
-
case "widget:update": handleUpdate(e.data.html || ""); break;
|
|
168
|
-
case "widget:finalize": handleFinalize(e.data.html || ""); break;
|
|
169
|
-
case "widget:theme": handleTheme(e.data.vars, e.data.isDark); break;
|
|
170
|
-
case "widget:capture": captureRenderedWidget(e.data.requestId); break;
|
|
171
|
-
case "widget:crossFilter":
|
|
172
|
-
window.dispatchEvent(new CustomEvent("widget-filter", { detail: e.data.payload }));
|
|
173
|
-
break;
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
document.addEventListener("click", function(e) {
|
|
178
|
-
var a = e.target && e.target.closest ? e.target.closest("a[href]") : null;
|
|
179
|
-
if (!a) return;
|
|
180
|
-
var href = a.getAttribute("href");
|
|
181
|
-
if (!href || href.charAt(0) === "#") return;
|
|
182
|
-
e.preventDefault();
|
|
183
|
-
parent.postMessage({ type: "widget:link", href: href }, "*");
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
window.__widgetSendMessage = function(text) {
|
|
187
|
-
if (typeof text === "string" && text.length <= 500) {
|
|
188
|
-
parent.postMessage({ type: "widget:sendMessage", text: text }, "*");
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
window.__widgetPublish = function(topic, data) {
|
|
193
|
-
if (typeof topic === "string") {
|
|
194
|
-
parent.postMessage({ type: "widget:publish", topic: topic, data: data }, "*");
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
notifyReady();
|
|
199
|
-
})();
|
|
200
|
-
</script>
|
|
201
|
-
</body>
|
|
202
|
-
</html>`}((e=Object.entries({"--bg":"#ffffff","--bg-panel":"#f5f5f5","--bg-hover":"#eeeeee","--bg-selected":"#e8e8e8","--border":"#e0e0e0","--text":"#1a1a1a","--text-muted":"#6b7280","--text-dim":"#9ca3af","--accent":"#2563eb","--accent-hover":"#1d4ed8",..."u"<typeof document?{}:Z(),"--font-mono":"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace"}).map(([e,t])=>` ${e}: ${t};`).join("\n"),`
|
|
203
|
-
:root {
|
|
204
|
-
${e}
|
|
205
|
-
}
|
|
206
|
-
.dark { color-scheme: dark; }
|
|
207
|
-
body {
|
|
208
|
-
--color-background-primary: var(--bg, #fff);
|
|
209
|
-
--color-background-secondary: var(--bg-panel, #f5f5f5);
|
|
210
|
-
--color-background-tertiary: var(--bg-hover, #eee);
|
|
211
|
-
--color-text-primary: var(--text, #1a1a1a);
|
|
212
|
-
--color-text-secondary: var(--text-muted, #6b7280);
|
|
213
|
-
--color-text-tertiary: var(--text-dim, #9ca3af);
|
|
214
|
-
--color-border-tertiary: var(--border, #e0e0e0);
|
|
215
|
-
--color-border-secondary: var(--border, #e0e0e0);
|
|
216
|
-
--color-border-primary: var(--accent, #2563eb);
|
|
217
|
-
--font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
|
|
218
|
-
--border-radius-md: 8px;
|
|
219
|
-
--border-radius-lg: 12px;
|
|
220
|
-
margin: 0;
|
|
221
|
-
padding: 0;
|
|
222
|
-
font-family: var(--font-sans);
|
|
223
|
-
font-size: 14px;
|
|
224
|
-
line-height: 1.6;
|
|
225
|
-
color: var(--color-text-primary);
|
|
226
|
-
background: transparent;
|
|
227
|
-
}
|
|
228
|
-
* { box-sizing: border-box; }
|
|
229
|
-
svg { max-width: 100%; height: auto; display: block; }
|
|
230
|
-
a { color: var(--accent, #2563eb); }
|
|
231
|
-
button, input, select, textarea { font: inherit; }
|
|
232
|
-
button {
|
|
233
|
-
border: 1px solid var(--color-border-tertiary);
|
|
234
|
-
border-radius: var(--border-radius-md);
|
|
235
|
-
background: var(--color-background-secondary);
|
|
236
|
-
color: var(--color-text-primary);
|
|
237
|
-
padding: 5px 10px;
|
|
238
|
-
cursor: pointer;
|
|
239
|
-
}
|
|
240
|
-
button:hover { background: var(--color-background-tertiary); }
|
|
241
|
-
input[type="range"] { accent-color: var(--accent, #2563eb); }
|
|
242
|
-
`),L.current)},[]);(0,o.useEffect)(()=>{function t(t){if(t.data&&"string"==typeof t.data.type&&(!a.current||t.source===a.current.contentWindow))switch(t.data.type){case"widget:ready":x(!0);break;case"widget:captured":{let e=String(t.data.requestId??""),r=u.current.get(e);if(!r)break;clearTimeout(r.timeout),u.current.delete(e),r.resolve({html:"string"==typeof t.data.html?t.data.html:null,styles:"string"==typeof t.data.styles?t.data.styles:"",canvases:Array.isArray(t.data.canvases)?t.data.canvases:[],bodyWidth:"number"==typeof t.data.bodyWidth?t.data.bodyWidth:void 0,bodyHeight:"number"==typeof t.data.bodyHeight?t.data.bodyHeight:void 0});break}case"widget:resize":if("number"==typeof t.data.height&&t.data.height>0){let r=Math.min(t.data.height+2,2e3),n=eu(e);if(M.current){f(e=>{let t=Math.max(e,r);return ec.set(n,t),t});break}if(ec.set(n,r),z.current)f(r);else{z.current=!0;let e=a.current;e&&(e.style.transition="none",e.offsetHeight),f(r),requestAnimationFrame(()=>{e&&(e.style.transition="height 0.2s ease-out")})}}break;case"widget:link":{let e=String(t.data.href??"");e&&!/^\s*(javascript|data)\s*:/i.test(e)&&window.open(e,"_blank","noopener,noreferrer");break}case"widget:sendMessage":{let e=String(t.data.text??"");e&&e.length<=500&&l?.(e);break}case"widget:publish":window.dispatchEvent(new CustomEvent("widget-cross-publish",{detail:{topic:t.data.topic,data:t.data.data,sourceIframe:a.current}}))}}return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[e,l]),(0,o.useEffect)(()=>{let e=u.current;return()=>{for(let t of(c.current&&clearTimeout(c.current),e.values()))clearTimeout(t.timeout),t.reject(Error("Widget renderer unmounted."));e.clear()}},[]),(0,o.useEffect)(()=>{function e(e){let t=e.detail;a.current?.contentWindow&&t?.sourceIframe!==a.current&&a.current.contentWindow.postMessage({type:"widget:crossFilter",payload:{topic:t?.topic,data:t?.data}},"*")}return window.addEventListener("widget-cross-publish",e),()=>window.removeEventListener("widget-cross-publish",e)},[]);let E=(0,o.useCallback)(e=>{let t=a.current;t?.contentWindow&&e!==p.current&&(p.current=e,t.contentWindow.postMessage({type:"widget:update",html:e},"*"))},[]);(0,o.useEffect)(()=>{if(!t||!h)return;let r=K(e).replace(/\s+on[a-z]+\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>"']*)/gi,"").replace(/<script[\s\S]*?<\/script>/gi,"").replace(/<script\b[^>]*\/?>/gi,"").replace(/\s+(href|src|action)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>"']*))/gi,(e,t,r,n,o)=>{let i=(r??n??o??"").trim();return/^\s*(javascript|data)\s*:/i.test(i)?"":e});return d.current&&clearTimeout(d.current),d.current=setTimeout(()=>E(r),120),()=>{d.current&&clearTimeout(d.current)}},[e,t,h,E]),(0,o.useEffect)(()=>{if(t||!h||I.current===e)return;let r=K(e),n=a.current;if(!n?.contentWindow)return;I.current=e,p.current=r,M.current=!0,T(!1),n.contentWindow.postMessage({type:"widget:finalize",html:r},"*");let o=setTimeout(()=>{M.current=!1,T(!0)},450);return()=>clearTimeout(o)},[t,h,e]),(0,o.useEffect)(()=>{if(!h)return;let e=()=>{a.current?.contentWindow?.postMessage({type:"widget:theme",vars:Z(),isDark:s},"*")};e();let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>t.disconnect()},[h,s]),(0,o.useEffect)(()=>{if(!y)return;let e=document.body.style.overflow;document.body.style.overflow="hidden";let t=e=>{"Escape"===e.key&&b(!1)};return window.addEventListener("keydown",t),()=>{document.body.style.overflow=e,window.removeEventListener("keydown",t)}},[y]);let $=(0,o.useCallback)(e=>{c.current&&clearTimeout(c.current),k(e),c.current=setTimeout(()=>k(null),1800)},[]),P=(0,o.useCallback)(()=>{let e=a.current?.contentWindow;return e?new Promise((t,r)=>{let n=`${Date.now()}-${Math.random().toString(36).slice(2)}`,o=setTimeout(()=>{u.current.delete(n),r(Error("Timed out waiting for widget capture."))},2500);u.current.set(n,{resolve:t,reject:r,timeout:o}),e.postMessage({type:"widget:capture",requestId:n},"*")}):Promise.reject(Error("Widget iframe is not ready."))},[]),A=(0,o.useCallback)(async()=>{try{let t;await Q((t={widget_code:e},r?.trim()&&(t.title=r.trim()),"```show-widget\n"+JSON.stringify(t,null,2)+"\n```")),$("Copied source")}catch{$("Copy failed")}},[e,r,$]),B=(0,o.useCallback)(async()=>{try{await Q(e),$("Copied HTML/SVG")}catch{$("Copy failed")}},[e,$]),N=(0,o.useCallback)(async()=>{if(!t&&!w){S(!0),$("Exporting PNG...");try{let t;try{t=await et({code:e})}catch{let r=await P();t=await et({code:e,capture:r})}ee(t,`${((r||"widget").trim()||"widget").replace(/[^a-zA-Z0-9._-]+/g,"_").replace(/^_+|_+$/g,"")||"widget"}.png`),$("Downloaded PNG")}catch(e){console.warn("[WidgetRenderer] PNG export failed:",e),$("PNG export unavailable")}finally{S(!1)}}},[e,r,t,w,P,$]),D=i||R&&!t&&h&&!C,O={width:24,height:22,padding:0,background:"var(--bg-hover)",color:"var(--text-dim)",border:"1px solid var(--border)",borderRadius:3,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},H={...O,width:48,fontSize:10,whiteSpace:"nowrap"};return(0,n.jsxs)("div",{className:"widget-frame",style:{position:y?"fixed":"relative",inset:y?12:void 0,zIndex:y?1e3:void 0,marginTop:4*!y,marginBottom:4*!y,borderRadius:y?8:6,background:y?"var(--bg)":void 0,boxShadow:y?"0 24px 80px rgba(0, 0, 0, 0.35)":void 0,display:y?"flex":void 0,flexDirection:y?"column":void 0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"4px 10px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderBottom:"none",borderRadius:`${y?8:6}px ${y?8:6}px 0 0`,fontSize:11,color:"var(--text-dim)",minHeight:26,flexShrink:0},children:[(0,n.jsx)("span",{style:{fontWeight:600,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r||"Widget"}),t&&(0,n.jsx)("span",{style:{fontSize:10,color:"var(--accent)",animation:"pulse 1.5s infinite",flexShrink:0},children:"streaming…"}),j&&(0,n.jsx)("span",{"aria-live":"polite",style:{marginLeft:"auto",fontSize:10,color:"var(--text-muted)",flexShrink:0},children:j}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4,marginLeft:j?0:"auto",flexShrink:0},children:[(0,n.jsx)("button",{onClick:A,title:"Copy show-widget source","aria-label":"Copy show-widget source",style:O,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:"16 18 22 12 16 6"}),(0,n.jsx)("polyline",{points:"8 6 2 12 8 18"})]})}),(0,n.jsx)("button",{onClick:B,title:"Copy widget HTML/SVG","aria-label":"Copy widget HTML/SVG",style:O,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)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),(0,n.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})}),(0,n.jsx)("button",{onClick:N,disabled:t||w,title:t?"PNG export is available after streaming finishes":"Export widget as PNG","aria-label":"Export widget as PNG",style:{...O,...t||w?{opacity:.45,cursor:"not-allowed"}:null},children:w?(0,n.jsx)("span",{style:{fontSize:9},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:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,n.jsx)("polyline",{points:"7 10 12 15 17 10"}),(0,n.jsx)("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})}),(0,n.jsx)("button",{onClick:()=>b(e=>!e),title:y?"Exit full screen":"View full screen","aria-label":y?"Exit full screen":"View full screen",style:O,children:y?(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:"4 14 10 14 10 20"}),(0,n.jsx)("polyline",{points:"20 10 14 10 14 4"}),(0,n.jsx)("line",{x1:"14",y1:"10",x2:"21",y2:"3"}),(0,n.jsx)("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]}):(0,n.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:"15 3 21 3 21 9"}),(0,n.jsx)("polyline",{points:"9 21 3 21 3 15"}),(0,n.jsx)("line",{x1:"21",y1:"3",x2:"14",y2:"10"}),(0,n.jsx)("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]})}),(0,n.jsx)("button",{onClick:()=>v(e=>!e),title:m?"Show widget preview":"Show widget code",style:H,children:m?"Preview":"Code"})]})]}),m&&(0,n.jsx)("pre",{style:{margin:0,padding:"8px 10px",fontSize:11,fontFamily:"var(--font-mono)",color:"var(--text-muted)",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:"0 0 6px 6px",overflow:"auto",maxHeight:y?"none":400,flex:y?1:void 0,whiteSpace:"pre-wrap"},children:e}),(0,n.jsx)("iframe",{ref:a,sandbox:"allow-scripts",srcDoc:W,title:r||"Widget",onLoad:()=>x(!0),style:{width:"100%",height:y?"calc(100vh - 50px)":g,minHeight:g>0?void 0:80,border:"1px solid var(--border)",borderRadius:`0 0 ${y?8:6}px ${y?8:6}px`,display:m?"none":"block",overflow:"hidden",background:"transparent",flex:y?1:void 0,transition:z.current?"height 0.2s ease-out":"none"}}),D&&!m&&(0,n.jsx)("div",{className:"widget-shimmer",style:{position:"absolute",inset:0,top:26,pointerEvents:"none",borderRadius:"0 0 6px 6px"}})]})}var eh=r(7644);let ex={light:eh.vs,dark:eh.xJ},eg={light:eh.vs,dark:eh.bM};function ef(e,t="default"){let r=function(e="default"){return"compact"===e?eg:ex}(t);return e?r.dark:r.light}function em(e){return/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith("\\\\")?e.replace(/\\/g,"/"):e}function ev(e){return em(e).split("/").filter(Boolean).map(encodeURIComponent).join("/")}function ey(e){let t=em(e).replace(/\/+$/,"");return t.split("/").pop()??t}function eb(e,t){if(!t)return e;let r=em(e),n=em(t).replace(/\/$/,"");return r.startsWith(n+"/")?r.slice(n.length+1):e}function ej(e){return/^[a-z][a-z\d+.-]*:/i.test(e)||e.startsWith("//")}function ek(e){let t=em(e),r=t.startsWith("/")||/^[a-zA-Z]:\//.test(t),n=[];for(let e of t.split("/"))if(e&&"."!==e){if(".."===e){n.length>0&&".."!==n[n.length-1]?n.pop():r||n.push(e);continue}n.push(e)}return`${r?"/":""}${n.join("/")}`}function ew(e,t,r){let n;if(!r||r.startsWith("#")||ej(r))return null;let o=(n=/^([^?#]*)(.*)$/.exec(r),n?.[1]??r);if(!o)return null;let i=em((function(e){try{return decodeURI(e)}catch{return e}})(o).replace(/^file:\/\//i,""));if(i.startsWith("~/")){let e=t?.match(/^(\/Users\/[^/]+|\/home\/[^/]+)(?:\/|$)/);return e?ek(`${e[1]}/${i.slice(2)}`):null}if(/^[a-zA-Z]:\//.test(i)||i.startsWith("/"))return ek(i);if(e){let t,r;return ek(`${(r=(t=em(e)).lastIndexOf("/"))>=0?t.slice(0,r):""}/${i}`)}return t?ek(`${t.replace(/\/+$/,"")}/${i.replace(/^\.?\//,"")}`):null}function eS(e){return`/api/files/${ev(e)}?type=read`}function eC({code:e,language:t,variant:r}){let{isDark:i}=F(),[l,s]=(0,o.useState)(!1);return(0,n.jsxs)("div",{className:`markdown-code-block markdown-code-block-${r}`,style:{position:"relative",marginTop:"file"===r?12:4,marginBottom:"file"===r?12:4,borderRadius:6,overflow:"hidden",border:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{style:{padding:"3px 10px",background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[(0,n.jsx)("span",{children:t||"text"}),(0,n.jsx)("button",{onClick:()=>{(function(e){if(navigator.clipboard?.writeText)return navigator.clipboard.writeText(e);try{let t=document.createElement("textarea");return t.value=e,t.style.position="fixed",t.style.opacity="0",document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t),Promise.resolve()}catch{return Promise.reject()}})(e).then(()=>{s(!0),setTimeout(()=>s(!1),1500)})},style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:11},children:l?"copied":"copy"})]}),(0,n.jsx)(B.A,{language:t||"text",style:ef(i),showLineNumbers:"chat"===r,lineNumberStyle:{color:"var(--text-dim)",fontStyle:"normal"},customStyle:{margin:0,padding:"file"===r?"12px 16px":"10px 12px",fontSize:"file"===r?13:12.5,lineHeight:1.6,borderRadius:0,background:"var(--bg)"},codeTagProps:{style:{fontFamily:"var(--font-mono)"}},children:e})]})}function eT({content:e,className:t="markdown-body",style:r,codeBlockVariant:o="chat",baseFilePath:i,cwd:l,onOpenLocalFile:s,onOpenImage:a,onWidgetSendMessage:d,renderVisualCodeBlocks:c=!1}){let u=e?[...e.matchAll(/!\[([^\]]*)]\(([^)]+)\)/g)].flatMap(e=>{let t=e[1]?.trim()||void 0,r=e[2]?.trim();return r?[{src:r,title:t}]:[]}):[],p=u.flatMap(e=>{let t=ew(i,l,e.src);return t?[{src:t,title:e.title??ey(t)}]:[]});return(0,n.jsx)("div",{className:t,style:r,children:(0,n.jsx)(P.oz,{remarkPlugins:[A.A],components:{code({className:e,children:t,node:r,...i}){let l,s,a,u=e?.replace(/^language-/,"").trim()??"",p=String(t),h=p.replace(/\n$/,""),x=e?.includes("language-")||p.includes("\n");if(x&&("mermaid"===(l=u.trim().toLowerCase())||"mmd"===l))return(0,n.jsx)(_,{chart:h});if(x&&"show-widget"===u.trim().toLowerCase()){let e,t=(e=U(`\`\`\`show-widget
|
|
243
|
-
${h}
|
|
244
|
-
\`\`\``).find(e=>"widget"===e.type),e?.type==="widget"?{title:e.title,code:e.code}:null);if(t)return(0,n.jsx)(ep,{code:t.code,isStreaming:!1,title:t.title,onSendMessage:d})}return x&&c&&(s=u.trim().toLowerCase(),(a=h.trim())&&("svg"===s||"xml"===s&&/^<svg[\s>]/i.test(a)?/^<svg[\s>]/i.test(a):!("html"!==s||/<!doctype|<html[\s>]|<head[\s>]|<body[\s>]/i.test(a))&&/^<(style|svg|div|section|article|main|figure|canvas)\b/i.test(a)))?(0,n.jsx)(ep,{code:h,isStreaming:!1,title:`${u||"visual"} preview`,onSendMessage:d}):x?(0,n.jsx)(eC,{code:h,language:u,variant:o}):(0,n.jsx)("code",{style:{background:"var(--bg-selected)",padding:"1px 4px",borderRadius:3,fontFamily:"var(--font-mono)",fontSize:"0.9em"},...i,children:t})},pre:({children:e})=>(0,n.jsx)(n.Fragment,{children:e}),a({href:e,children:t,node:r,...o}){let a=ew(i,l,e),d=!!a,c=!!e&&ej(e);return(0,n.jsx)("a",{...o,href:d?eS(a):e,target:c?"_blank":void 0,rel:c?"noreferrer":void 0,onClick:e=>{a&&s&&(e.preventDefault(),s(a,ey(a)))},title:d?a:o.title,children:t})},img({src:e,alt:t,node:r,...o}){let d="string"==typeof e?e:void 0,c=ew(i,l,d),h=c?eS(c):d,x=c?eS(c):d;return(0,n.jsx)("a",{href:x,target:"_blank",rel:"noreferrer",title:c??o.title??"Open image",style:{display:"inline-block",maxWidth:"100%"},onClick:e=>{c&&s?(e.preventDefault(),a&&p.length>0)?a(c,t??o.title??ey(c),p):s(c,ey(c)):!c&&d&&a&&(e.preventDefault(),a(d,t??o.title??void 0,u))},children:(0,n.jsx)("img",{...o,src:h,alt:t??"",loading:"lazy",title:c??o.title,style:{...o.style??{},cursor:"zoom-in"}})})}},children:e})})}let eI="smoke-reduced-motion-change";function ez(){if("u"<typeof document)return null;let e=document.documentElement.dataset.smokeReducedMotion;return"true"===e||"false"!==e&&null}function eM({children:e,duration:t=2,style:r,...i}){let[l,s]=(0,o.useState)(!1);return((0,o.useEffect)(()=>{let e=window.matchMedia("(prefers-reduced-motion: reduce)"),t=()=>{s(ez()??e.matches)};t();let r=e=>{null===ez()&&s(e.matches)},n=()=>t();return e.addEventListener("change",r),window.addEventListener(eI,n),()=>{e.removeEventListener("change",r),window.removeEventListener(eI,n)}},[]),l)?(0,n.jsx)("span",{...i,children:e}):(0,n.jsx)("span",{style:{display:"inline-block",backgroundImage:"linear-gradient(90deg, var(--text-dim) 25%, var(--text-muted) 50%, var(--text-dim) 75%)",backgroundSize:"200% 100%",backgroundClip:"text",WebkitBackgroundClip:"text",WebkitTextFillColor:"transparent",color:"transparent",animation:`text-shimmer ${t}s linear infinite`,...r},...i,children:e})}function eL({className:e,style:t,height:r=80}){let[i,l]=(0,o.useState)(!1);(0,o.useEffect)(()=>{let e=window.matchMedia("(prefers-reduced-motion: reduce)"),t=()=>{l(ez()??e.matches)};t();let r=e=>{null===ez()&&l(e.matches)},n=()=>t();return e.addEventListener("change",r),window.addEventListener(eI,n),()=>{e.removeEventListener("change",r),window.removeEventListener(eI,n)}},[]);let s={borderRadius:6,background:"var(--bg-panel)",overflow:"hidden",height:r,...t};return i?(0,n.jsx)("div",{className:e,style:s}):(0,n.jsx)("div",{className:e,style:s,children:(0,n.jsx)("div",{style:{width:"100%",height:"100%",background:"linear-gradient(90deg, transparent 0%, var(--bg-hover) 50%, transparent 100%)",backgroundSize:"200% 100%",animation:"surface-shimmer 1.5s ease-in-out infinite"}})})}function eR({children:e,style:t,kind:r}){return(0,n.jsx)("div",{"data-disclosure-surface":"panel","data-disclosure-kind":r,style:{border:"1px solid var(--border)",borderRadius:6,overflow:"hidden",background:"var(--bg-panel)",...t},children:e})}function eW({children:e,style:t}){return(0,n.jsx)("div",{"data-disclosure-surface":"body",style:{borderTop:"1px solid var(--border)",...t},children:e})}function eE({expanded:e,onToggle:t,children:r,title:o,buttonStyle:i,chevronColor:l="var(--text-dim)",chevronStyle:s}){return(0,n.jsxs)("button",{type:"button",onClick:t,"aria-expanded":e,title:o,style:i,children:[r,(0,n.jsx)("span",{style:{display:"inline-flex",color:l,transform:e?"rotate(180deg)":"none",transition:"transform 0.15s",flexShrink:0,...s},children:(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})})]})}function e$({expanded:e,onToggle:t,durationLabel:r,isStreaming:o=!1,leading:i,label:l="Thinking",buttonStyle:s,labelStyle:a,durationStyle:d}){return(0,n.jsxs)(eE,{expanded:e,onToggle:t,buttonStyle:{width:"100%",display:"flex",alignItems:"center",gap:7,minWidth:0,textAlign:"left",cursor:"pointer",border:"none",background:"transparent",color:"var(--text-muted)",...s},children:[i,(0,n.jsx)("span",{style:{fontSize:12,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0,flex:1,...a},children:o?(0,n.jsx)(eM,{children:l}):l}),r&&(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",fontVariantNumeric:"tabular-nums",flexShrink:0,...d},children:r})]})}function eP({content:e,contentStyle:t}){return(0,n.jsx)(eW,{style:{color:"var(--text-muted)",fontSize:12,lineHeight:1.6,whiteSpace:"pre-wrap",wordBreak:"break-word",...t},children:(0,n.jsx)("div",{style:{padding:"8px 10px"},children:e})})}function eA({content:e,durationLabel:t,isStreaming:r=!1,leading:i,label:l="Thinking",containerStyle:s,buttonStyle:a,labelStyle:d,durationStyle:c,contentStyle:u}){let[p,h]=(0,o.useState)(!1);return(0,n.jsxs)(eR,{kind:"thinking",style:s,children:[(0,n.jsx)(e$,{expanded:p,onToggle:()=>h(e=>!e),durationLabel:t,isStreaming:r,leading:i,label:l,buttonStyle:a,labelStyle:d,durationStyle:c}),p&&(0,n.jsx)(eP,{content:e,contentStyle:u})]})}function eB(e,t){return e?.isError?"error":e?"success":t?"running":"unknown"}function eN(e){return"success"===e?"#16a34a":"error"===e?"#f87171":"running"===e?"#f59e0b":"var(--text-dim)"}function eD(e){return"success"===e?"Done":"error"===e?"Error":"running"===e?"Running":"Unknown"}function eO({status:e}){return"running"===e?(0,n.jsx)("span",{style:{width:6,height:6,borderRadius:999,background:eN(e),animation:"pulse 1.2s ease-in-out infinite"}}):"success"===e?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}):"error"===e?(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("path",{d:"m18 6-12 12"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]}):(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,n.jsx)("path",{d:"M12 8v5"}),(0,n.jsx)("path",{d:"M12 16h.01"})]})}function eH({status:e}){let t=eN(e);return(0,n.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:5,minHeight:18,padding:"0 6px",borderRadius:999,border:`1px solid color-mix(in srgb, ${t} 35%, transparent)`,background:`color-mix(in srgb, ${t} 10%, transparent)`,color:t,fontSize:10,fontWeight:600,whiteSpace:"nowrap",flexShrink:0},title:eD(e),children:[(0,n.jsx)(eO,{status:e}),(0,n.jsx)("span",{children:eD(e)})]})}function eF({expanded:e,onToggle:t,status:r,title:o,summary:i,durationLabel:l,leading:s,titleTooltip:a,summaryTooltip:d,buttonStyle:c,titleStyle:u,summaryStyle:p,durationStyle:h}){return(0,n.jsxs)(eE,{expanded:e,onToggle:t,buttonStyle:c,children:[s,(0,n.jsx)("span",{title:a??o,style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)",fontWeight:600,fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flexShrink:+!i,minWidth:0,flex:i?void 0:1,...u},children:"running"===r?(0,n.jsx)(eM,{children:o}):o}),i?(0,n.jsx)("span",{title:d??i,style:{color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,minWidth:0,...p},children:"running"===r?(0,n.jsx)(eM,{children:i}):i}):(0,n.jsx)("span",{style:{flex:1,minWidth:0}}),(0,n.jsx)(eH,{status:r}),l?(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",fontVariantNumeric:"tabular-nums",flexShrink:0,...h},children:l}):null]})}function e_({text:e,maxHeight:t=400,collapsible:r=!1,textColor:i="var(--text-muted)",background:l="var(--bg)",empty:s=!1}){let[a,d]=(0,o.useState)(!1),c=(0,o.useMemo)(()=>e.split(/\r?\n/),[e]),u=r&&c.length>20,p=!u||a?e:c.slice(0,20).join("\n");return(0,n.jsxs)("div",{style:{background:l},children:[(0,n.jsx)("pre",{style:{margin:0,padding:"8px 10px",color:i,fontSize:12,lineHeight:1.5,overflow:"auto",maxHeight:t,background:l,whiteSpace:"pre-wrap",wordBreak:"break-all",fontStyle:s?"italic":"normal",opacity:s?.6:1},children:p}),u&&(0,n.jsx)("button",{type:"button",onClick:()=>d(e=>!e),style:{width:"100%",border:"none",borderTop:"1px solid var(--border)",background:l,color:"var(--text-dim)",cursor:"pointer",fontSize:11,padding:"6px 10px",textAlign:"center"},children:a?"Show less":`Show ${c.length-20} more lines`})]})}let eU=/(?:file:\/\/)?(?:(?:[A-Za-z]:[\\/])|\/|~\/|\.{1,2}[\\/]|[A-Za-z0-9_.-]+[\\/])[^`"'<>|\s{}\[\]]+?\.(?:png|jpe?g|webp|gif|svg|bmp|avif|pdf)(?=$|[\s`"'<>|{}\[\]),.;:!?])/gi,eq=/\.(?:png|jpe?g|webp|gif|svg|bmp|avif)$/i,eV=/\.pdf$/i,eJ=/^[A-Za-z]:[\\/]/;function eG(e){return e.path?eK(e.path):e.source?.type==="base64"&&e.source.data?`data:${e.source.media_type??"image/png"};base64,${e.source.data}`:e.source?.type==="url"&&e.source.url?e.source.url:e.data?`data:${e.mimeType??"image/png"};base64,${e.data}`:null}function eK(e){return`/api/files/${ev(e)}?type=read`}function eY(e){let t=em(e),r=t.startsWith("/")||eJ.test(t);if(eJ.test(t))return t;let n=[];for(let e of t.split("/"))if(e&&"."!==e){if(".."===e){n.length>0&&".."!==n[n.length-1]?n.pop():r||n.push(e);continue}n.push(e)}return`${r?"/":""}${n.join("/")}`}function eZ(e,t){if(!e)return[];let r=[],n=new Set,o=new Set;for(let t of e.matchAll(/!\[[^\]]*]\(([^)]+)\)/g))t[1]&&o.add(t[1].trim());let i=e=>{!e||n.has(e)||r.length>=24||(n.add(e),r.push(e))};for(let r of(eU.lastIndex=0,e.matchAll(eU))){let n=r[0];if(/^[a-z][a-z\d+.-]*:\/\//i.test(n)&&!/^file:\/\//i.test(n))continue;let l=e.slice(Math.max(0,r.index-12),r.index);if(/[A-Za-z][A-Za-z\d+.-]*:\/?$/.test(l)||n.startsWith("//")||o.has(n))continue;let s=function(e,t){let r=e.trim().replace(/^file:\/\//i,"").replace(/[),.;:!?]+$/g,"");if(!r||r.startsWith("//"))return null;if((r=em(r)).startsWith("/")||eJ.test(r))return eY(r);if(r.startsWith("~/")){let e=t?.match(/^(\/Users\/[^/]+|\/home\/[^/]+)(?:\/|$)/);return e?eY(`${e[1]}/${r.slice(2)}`):null}return t?eY(`${t.replace(/\/+$/,"")}/${r.replace(/^\.?\//,"")}`):null}(n,t);s&&(eq.test(s)?i(s):eV.test(s)&&i(s.replace(eV,".png")))}return r}function eX({images:e,maxHeight:t=360,onOpenImage:r,galleryItems:o}){if(0===e.length)return null;let i=o&&o.length>0?o:e.flatMap(e=>{let t=eG(e);return t?[{src:t}]:[]});return(0,n.jsx)("div",{style:{display:"grid",gridTemplateColumns:1===e.length?"minmax(0, 1fr)":"repeat(auto-fit, minmax(180px, 1fr))",gap:8,minWidth:0},children:e.map((e,o)=>{let l=eG(e);return l?(0,n.jsx)("a",{href:l,target:r?void 0:"_blank",rel:r?void 0:"noreferrer",title:"Open image",onClick:e=>{if(!r)return;e.preventDefault();let t=i.find(e=>e.src===l)?.title;r(l,t,i)},style:{display:"block",minWidth:0,border:"1px solid var(--border)",borderRadius:6,overflow:"hidden",background:"var(--bg)"},children:(0,n.jsx)("img",{src:l,alt:"",loading:"lazy",style:{display:"block",width:"100%",maxHeight:t,objectFit:"contain"}})},o):null})})}function eQ({imagePaths:e,maxHeight:t=360,onOpenImage:r}){let[i,l]=(0,o.useState)(()=>new Set),s=(0,o.useRef)(new Map),a=e.join("\0");(0,o.useEffect)(()=>{let t=new Set(e);s.current=new Map([...s.current].filter(([e])=>t.has(e))),l(e=>{let r=new Set([...e].filter(e=>t.has(e)));return r.size===e.size?e:r})},[e,a]),(0,o.useEffect)(()=>{if(![...i].some(e=>(s.current.get(e)??0)<3))return;let e=window.setTimeout(()=>{l(e=>{let t=new Set(e);for(let r of e)(s.current.get(r)??0)<3&&t.delete(r);return t})},2500);return()=>window.clearTimeout(e)},[i]);let d=e.filter(e=>!i.has(e));if(0===d.length)return null;let c=d.map(e=>({src:e,title:ey(e)}));return(0,n.jsx)("div",{style:{display:"grid",gridTemplateColumns:1===d.length?"minmax(0, 1fr)":"repeat(auto-fit, minmax(180px, 1fr))",gap:8,minWidth:0},children:d.map(e=>{let o=eK(e),i=ey(e);return(0,n.jsxs)("a",{href:o,target:r?void 0:"_blank",rel:r?void 0:"noreferrer",title:e,onClick:t=>{r&&(t.preventDefault(),r(e,i,c))},style:{display:"block",minWidth:0,border:"1px solid var(--border)",borderRadius:6,overflow:"hidden",background:"var(--bg)"},children:[(0,n.jsx)("img",{src:o,alt:i,loading:"lazy",onError:()=>{s.current.set(e,(s.current.get(e)??0)+1),l(t=>{let r=new Set(t);return r.add(e),r})},style:{display:"block",width:"100%",maxHeight:t,objectFit:"contain"}}),(0,n.jsx)("div",{style:{padding:"4px 6px",borderTop:"1px solid var(--border)",color:"var(--text-dim)",fontSize:10,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i})]},e)})})}function e0({text:e,isEmpty:t,isError:r,images:o,imagePaths:i,onOpenImage:l}){let s=!t||e.trim().length>0;return(0,n.jsxs)("div",{style:{borderTop:`1px solid ${r?"rgba(248,113,113,0.3)":"rgba(34,197,94,0.15)"}`,background:r?"rgba(248,113,113,0.04)":"var(--bg-subtle)"},children:[o.length>0&&(0,n.jsx)("div",{style:{padding:"10px 10px 0",background:"var(--bg)"},children:(0,n.jsx)(eX,{images:o,onOpenImage:l})}),i.length>0&&(0,n.jsx)("div",{style:{padding:"10px 10px 0",background:"var(--bg)"},children:(0,n.jsx)(eQ,{imagePaths:i,onOpenImage:l})}),s&&(0,n.jsx)(e_,{text:t?"(no output)":e,maxHeight:400,collapsible:!0,textColor:r?"#f87171":t?"var(--text-dim)":"var(--text-muted)",background:"var(--bg)",empty:t})]})}function e1({model:e,background:t="transparent",maxHeight:r=280,onOpenImage:o}){return 0===e.resultImages.length&&0===e.collapsedPreviewPaths.length?null:(0,n.jsxs)("div",{style:{padding:"0 10px 10px",background:t},children:[e.resultImages.length>0&&(0,n.jsx)(eX,{images:e.resultImages,maxHeight:r,onOpenImage:o}),e.collapsedPreviewPaths.length>0&&(0,n.jsx)(eQ,{imagePaths:e.collapsedPreviewPaths,maxHeight:r,onOpenImage:o})]})}function e2({model:e,inputMaxHeight:t=280,inputBackground:r="var(--bg-subtle)",inputTextColor:o="var(--text-muted)",showBorderTop:i=!1}){let l=(0,n.jsx)(e_,{text:e.inputText,maxHeight:t,collapsible:!0,textColor:o,background:r});return i?(0,n.jsx)("div",{style:{borderTop:"1px solid var(--border)"},children:l}):l}function e4({model:e,result:t,showUnavailableWhenMissing:r=!1,unavailableLabel:o="Result not available",onOpenImage:i}){return t?(0,n.jsx)(e0,{text:e.displayResultText??"",isEmpty:e.resultIsEmpty,isError:t.isError??!1,images:e.resultImages,imagePaths:e.mergedImagePaths,onOpenImage:i}):r?(0,n.jsx)("div",{style:{padding:"8px 10px",borderTop:"1px solid var(--border)",color:"var(--text-dim)",fontSize:12,fontStyle:"italic"},children:o}):null}function e5(e,t){for(let r of t){let t=e[r];if(null!=t&&""!==t)return String(t)}return null}function e6(e,t=60){let r=e.replace(/\s+/g," ").trim();return r.length<=t?r:`${r.slice(0,Math.max(0,t-3))}...`}function e3(e){let t=e.toLowerCase().split("__").filter(Boolean);return t[t.length-1]??e.toLowerCase()}function e8({tool:e,status:t,result:r,cwd:i,durationLabel:l,title:s,summary:a,titleTooltip:d,summaryTooltip:c,leading:u,collapsedPreviewBackground:p="transparent",showCollapsedPreview:h=!0,showUnavailableWhenMissing:x=!1,unavailableLabel:g="Result not available",showInputBorderTop:f=!1,titleStyle:m,buttonStyle:v,containerStyle:y,onOpenImage:b}){let[j,k]=(0,o.useState)(!1),w=(0,o.useMemo)(()=>(function({input:e,result:t,cwd:r}){var n;let o=JSON.stringify(e??{},null,2),i=t?t.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n"):null,l=t?t.content.filter(e=>"image"===e.type):[],s=(n=l.length>0,i&&n?i.replace(/\n?\[Current model does not support images\. The image will be omitted from this request\.\]\s*/g,"").trim():i),a=null!==s&&("(no output)"===s.trim()||""===s.trim()),d=eZ(o,r),c=eZ(s,r),u=function(e){let t=new Set,r=[];for(let n of e)t.has(n)||(t.add(n),r.push(n));return r}([...c,...d]),p=c.length>0?c:d;return{inputText:o,displayResultText:s,resultImages:l,resultIsEmpty:a,inputImagePaths:d,resultImagePaths:c,mergedImagePaths:u,collapsedPreviewPaths:p}})({input:e.input,result:r,cwd:i}),[i,r,e.input]);return(0,n.jsxs)(eR,{kind:"tool-call",style:{fontSize:12,minWidth:0,...y},children:[(0,n.jsx)(eF,{expanded:j,onToggle:()=>k(e=>!e),status:t,title:s??e.toolName,summary:a??function(e,t=120){let r=Object.keys(e);return 0===r.length?"":"command"in e?String(e.command).slice(0,t):"cmd"in e?String(e.cmd).slice(0,t):"path"in e?String(e.path).slice(0,t):"file_path"in e?String(e.file_path).slice(0,t):"pattern"in e?String(e.pattern).slice(0,t):"query"in e?String(e.query).slice(0,t):String(e[r[0]]).slice(0,t)}(e.input),durationLabel:l,leading:u,titleTooltip:d,summaryTooltip:c,buttonStyle:v,titleStyle:m}),j?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e2,{model:w,showBorderTop:f}),(0,n.jsx)(e4,{model:w,result:r,showUnavailableWhenMissing:x,unavailableLabel:g,onOpenImage:b})]}):h?(0,n.jsx)(e1,{model:w,background:p,onOpenImage:b}):null]})}function e7({block:e,toolResults:t,isStreaming:r,streamingDuration:o,toolCallDurations:i,onSendMessage:l,onOpenImage:s,renderVisualCodeBlocks:a,cwd:d}){if("text"===e.type)return(0,n.jsx)(e9,{block:e,isStreaming:r,onSendMessage:l,onOpenImage:s,renderVisualCodeBlocks:a,cwd:d});if("image"===e.type)return(0,n.jsx)(eX,{images:[e],onOpenImage:s});if("thinking"===e.type)return(0,n.jsx)(tr,{block:e,duration:o,isStreaming:r});let c=t?.get(e.toolCallId),u=i?.get(e.toolCallId);return(0,n.jsx)(tn,{block:e,result:c,duration:u,isStreaming:r,cwd:d,onOpenImage:s})}function e9({block:e,isStreaming:t,onSendMessage:r,onOpenImage:o,renderVisualCodeBlocks:i,cwd:l}){let s=U(e.text);if(!s.some(e=>"widget"===e.type)){var a;if(t&&(a=e.text,/`{1,3}show-widget/.test(a))){let e=s.filter(e=>"text"===e.type).map(e=>e.content).join("\n\n");return(0,n.jsxs)(n.Fragment,{children:[e&&(0,n.jsx)(te,{text:e,onSendMessage:r,onOpenImage:o,renderVisualCodeBlocks:i,cwd:l}),(0,n.jsx)(tt,{})]})}return(0,n.jsx)(te,{text:e.text,onSendMessage:r,onOpenImage:o,renderVisualCodeBlocks:i,cwd:l})}return(0,n.jsx)(n.Fragment,{children:s.map((e,t)=>"text"===e.type?(0,n.jsx)(te,{text:e.content,onSendMessage:r,onOpenImage:o,renderVisualCodeBlocks:i,cwd:l},t):(0,n.jsx)(ep,{code:e.code,isStreaming:!!e.partial,title:e.title,showOverlay:e.showOverlay,onSendMessage:r},t))})}function te({text:e,onSendMessage:t,onOpenImage:r,renderVisualCodeBlocks:i,cwd:l}){let s=(0,o.useMemo)(()=>eZ(e,l),[l,e]);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8*(s.length>0)},children:[(0,n.jsx)(eT,{content:e,cwd:l,onOpenLocalFile:r?(e,t)=>r(e,t,[{src:e,title:t}]):void 0,onOpenImage:r,onWidgetSendMessage:t,renderVisualCodeBlocks:i}),s.length>0&&(0,n.jsx)(eQ,{imagePaths:s,onOpenImage:r})]})}function tt(){return(0,n.jsx)(eL,{height:88,style:{border:"1px solid var(--border)"}})}function tr({block:e,duration:t,isStreaming:r}){return(0,n.jsx)(eA,{content:e.thinking,durationLabel:void 0!==t?`${t}s`:null,isStreaming:r,buttonStyle:{width:"100%",padding:"6px 10px",fontSize:12},contentStyle:{background:"var(--bg-panel)"}})}function tn({block:e,result:t,duration:r,isStreaming:o,cwd:i,onOpenImage:l}){let s=eB(t,o),a=eN(s);return(0,n.jsx)(e8,{tool:e,result:t,status:s,durationLabel:void 0!==r?`${r}s`:null,cwd:i,titleStyle:{color:a},onOpenImage:l})}function to({children:e,style:t,...r}){return(0,n.jsx)("div",{...r,style:{borderLeft:"2px solid var(--border)",paddingLeft:8,minWidth:0,...t},children:e})}function ti({children:e,style:t,...r}){return(0,n.jsx)("div",{...r,style:{display:"flex",flexDirection:"column",gap:4,paddingTop:6,...t},children:e})}function tl({name:e}){let t={width:13,height:13,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.8,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0};return"terminal"===e?(0,n.jsxs)("svg",{...t,children:[(0,n.jsx)("polyline",{points:"4 7 10 12 4 17"}),(0,n.jsx)("line",{x1:"12",y1:"17",x2:"20",y2:"17"})]}):"edit"===e?(0,n.jsxs)("svg",{...t,children:[(0,n.jsx)("path",{d:"M12 20h9"}),(0,n.jsx)("path",{d:"M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z"})]}):"read"===e?(0,n.jsxs)("svg",{...t,children:[(0,n.jsx)("path",{d:"M4 19.5V5a2 2 0 0 1 2-2h11.5a1.5 1.5 0 0 1 0 3H6"}),(0,n.jsx)("path",{d:"M6 6v15h12"})]}):"search"===e?(0,n.jsxs)("svg",{...t,children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"7"}),(0,n.jsx)("path",{d:"m20 20-4-4"})]}):"agent"===e?(0,n.jsxs)("svg",{...t,children:[(0,n.jsx)("path",{d:"M12 8V4"}),(0,n.jsx)("rect",{x:"5",y:"8",width:"14",height:"11",rx:"3"}),(0,n.jsx)("path",{d:"M9 13h.01"}),(0,n.jsx)("path",{d:"M15 13h.01"}),(0,n.jsx)("path",{d:"M10 17h4"})]}):"thinking"===e?(0,n.jsxs)("svg",{...t,children:[(0,n.jsx)("path",{d:"M9 18h6"}),(0,n.jsx)("path",{d:"M10 22h4"}),(0,n.jsx)("path",{d:"M8.5 14.5a6 6 0 1 1 7 0c-.8.6-1.5 1.6-1.5 2.5h-4c0-.9-.7-1.9-1.5-2.5Z"})]}):"success"===e?(0,n.jsx)("svg",{...t,children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}):"error"===e?(0,n.jsxs)("svg",{...t,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,n.jsx)("path",{d:"m15 9-6 6"}),(0,n.jsx)("path",{d:"m9 9 6 6"})]}):"unknown"===e?(0,n.jsxs)("svg",{...t,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,n.jsx)("path",{d:"M9.5 9a2.8 2.8 0 0 1 5 1.8c0 1.8-2.5 2.1-2.5 3.7"}),(0,n.jsx)("path",{d:"M12 18h.01"})]}):"chevron"===e?(0,n.jsx)("svg",{...t,children:(0,n.jsx)("polyline",{points:"8 10 12 14 16 10"})}):"running"===e?(0,n.jsxs)("svg",{...t,style:{animation:"spin 0.8s linear infinite"},children:[(0,n.jsx)("path",{d:"M21 12a9 9 0 0 1-9 9"}),(0,n.jsx)("path",{d:"M3 12a9 9 0 0 1 9-9"})]}):(0,n.jsxs)("svg",{...t,children:[(0,n.jsx)("path",{d:"M12 3v18"}),(0,n.jsx)("path",{d:"M3 12h18"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})}function ts(e){if(void 0===e)return null;if(e<60)return`~${e}s`;let t=Math.floor(e/60),r=e%60;return`~${t}m${r?` ${r}s`:""}`}function ta({expanded:e,total:t,summary:r,runningDescription:o,debugLabel:i,onToggle:l,isStreaming:s=!1,title:a,badgeLabel:d}){let c=d??(s?"xs":String(t));return(0,n.jsxs)("button",{type:"button",onClick:l,"aria-expanded":e,title:e?"Collapse process":"Expand process",style:{width:"100%",minHeight:30,display:"flex",alignItems:"center",gap:8,border:"1px solid var(--border)",borderRadius:6,background:e?"var(--bg-panel)":"transparent",color:s?"var(--text)":"var(--text-muted)",padding:"5px 8px",cursor:"pointer",textAlign:"left",minWidth:0},children:[(0,n.jsx)("span",{style:{display:"inline-flex",alignItems:"center",justifyContent:"center",minWidth:22,height:18,borderRadius:5,background:s?"rgba(59,130,246,0.12)":"var(--bg-selected)",color:s?"var(--accent)":"var(--text-muted)",fontSize:11,fontFamily:"var(--font-mono)",flexShrink:0},children:c}),(0,n.jsxs)("span",{style:{display:"flex",flexDirection:"column",minWidth:0,flex:1},children:[(0,n.jsx)("span",{style:{fontSize:12,fontWeight:500,color:s?"var(--text)":"var(--text-muted)"},children:a??(s?"Working":"Process")}),(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0,fontSize:11,color:"var(--text-dim)"},children:r}),i&&(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0,fontSize:10,color:"var(--text-dim)"},children:i})]}),o&&(0,n.jsx)("span",{title:o,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:220,minWidth:0,fontSize:11,flexShrink:1,color:s?"var(--text-muted)":"var(--text-dim)"},children:o}),(0,n.jsx)("span",{style:{display:"inline-flex",color:"var(--text-dim)",flexShrink:0,transform:e?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)(tl,{name:"chevron"})})]})}function td({item:e,isStreaming:t=!1}){let r=ts(e.duration);return(0,n.jsx)(eA,{content:e.content,durationLabel:r,isStreaming:t,leading:(0,n.jsx)("span",{style:{display:"inline-flex",color:"var(--text-dim)",flexShrink:0},children:(0,n.jsx)(tl,{name:"thinking"})}),buttonStyle:{minHeight:28,padding:"5px 8px"}})}function tc({item:e,cwd:t,onOpenImage:r}){let[i,l]=(0,o.useState)(!1),s=e.tools.some(e=>"running"===e.status),a=e.tools.some(e=>"error"===e.status),d=e.tools.every(e=>"unknown"===e.status),c=s?"running":a?"error":d?"unknown":"success";return(0,n.jsxs)(eR,{kind:"context-group",children:[(0,n.jsx)(eF,{expanded:i,onToggle:()=>l(e=>!e),status:c,title:`${s?"Gathering context":"Gathered context"} (${e.tools.length})`,leading:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{style:{display:"inline-flex",color:eN(c),flexShrink:0},children:(0,n.jsx)(tl,{name:c})}),(0,n.jsx)("span",{style:{display:"inline-flex",color:"var(--text-dim)",flexShrink:0},children:(0,n.jsx)(tl,{name:"read"})})]}),buttonStyle:{width:"100%",minHeight:28,display:"flex",alignItems:"center",gap:7,padding:"5px 8px",border:"none",background:"transparent",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",minWidth:0},titleStyle:{fontFamily:"inherit",fontWeight:400,fontSize:12}}),i&&(0,n.jsx)(eW,{children:(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:4,padding:"4px 6px 6px"},children:e.tools.map(e=>(0,n.jsx)(tu,{item:e,cwd:t,nested:!0,onOpenImage:r},e.tool.toolCallId))})})]})}function tu({item:e,cwd:t,nested:r,onOpenImage:o}){let i=ts(e.duration);return(0,n.jsx)(e8,{tool:e.tool,result:e.result,status:e.status,durationLabel:i,cwd:t,title:e.meta.label,summary:e.meta.summary,titleTooltip:e.tool.toolName,summaryTooltip:e.meta.summary,leading:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{style:{display:"inline-flex",color:eN(e.status),flexShrink:0},children:(0,n.jsx)(tl,{name:e.status})}),(0,n.jsx)("span",{style:{display:"inline-flex",color:"var(--text-dim)",flexShrink:0},children:(0,n.jsx)(tl,{name:e.meta.kind})})]}),showCollapsedPreview:!1,showUnavailableWhenMissing:"unknown"===e.status,showInputBorderTop:!0,onOpenImage:o,buttonStyle:{width:"100%",minHeight:28,display:"flex",alignItems:"center",gap:7,padding:"5px 8px",border:"none",background:"transparent",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",minWidth:0},titleStyle:{color:"error"===e.status?"#f87171":"var(--text-muted)",maxWidth:120},containerStyle:{border:r?"1px solid color-mix(in srgb, var(--border) 70%, transparent)":"1px solid var(--border)",background:r?"var(--bg)":"var(--bg-panel)"}})}let tp=new Set(["read","read_file","readfile","search","grep","glob","find","find_files","ls","list","list_files"]),th=[];function tx({tools:e,results:t,durations:r,thinkingBlocks:i=th,isStreaming:l,startedAt:s,reconnectCount:a=0,lastSyncReason:d=null,statusText:c=null,showWaitingShell:u=!1,cwd:p,onOpenImage:h}){let x,g,f,m,v=function(e=768){let[t,r]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{let t=window.matchMedia(`(max-width: ${e}px)`),n=()=>r(t.matches);return n(),t.addEventListener?.("change",n),()=>t.removeEventListener?.("change",n)},[e]),t}(),y=(0,o.useMemo)(()=>{let n=[];return i.forEach((e,t)=>{n.push({type:"thinking",key:`thinking-${t}`,content:e.content,duration:e.duration})}),e.forEach(e=>{let o,i=t?.get(e.toolCallId);n.push({type:"tool",tool:e,result:i,status:eB(i,l),duration:r?.get(e.toolCallId),meta:{label:(o=function(e){let t=e.toolName||"tool",r=e3(t),n=e.input??{};if(["bash","execute","run","shell","exec_command","execute_command"].includes(r))return{canonicalName:r,kind:"terminal",label:"Shell",summary:e6(e5(n,["command","cmd"])??t,60)};if(["read","readfile","read_file"].includes(r))return{canonicalName:r,kind:"read",label:"Read",summary:e6(e5(n,["file_path","path"])??t,60)};if(["write","edit","write_file","create_file","notebook_edit"].includes(r)){let e,o=e5(n,["file_path","path","notebook_path","filename"]);return{canonicalName:r,kind:"edit",label:"Edit",summary:e6(o?(e=o.split(/[\\/]/).filter(Boolean))[e.length-1]??o:t,60)}}if(["search","grep","glob","find","find_files","websearch"].includes(r))return{canonicalName:r,kind:"search",label:"Search",summary:e6(e5(n,["pattern","query","glob"])??t,60)};if(["subagent","agent"].includes(r))return{canonicalName:r,kind:"agent",label:"Agent",summary:e6([e5(n,["agent","name","agentName"]),e5(n,["prompt","task","message"])].filter(Boolean).join(": ")||t,60)};let o=e5(n,["command","cmd","path","file_path","pattern","query","glob","prompt","description"])??function(e){try{return JSON.stringify(e)}catch{return String(e)}}(n)??t;return{canonicalName:r,kind:"tool",label:e6(t,60),summary:e6(o,60)}}(e)).label,summary:o.summary,kind:o.kind}})}),n},[r,l,t,i,e]),b=(0,o.useMemo)(()=>(function(e,t){let r=[],n=[],o=()=>{n.length>=3?r.push({type:"contextGroup",key:n.map(e=>e.tool.toolCallId).join(":"),tools:n}):r.push(...n),n=[]};for(let l of e){var i;if("tool"===l.type&&(i=l.tool,tp.has(e3(i.toolName)))&&(!t||"running"!==l.status)){n.push(l);continue}o(),r.push(l)}return o(),r})(y,l),[l,y]),j=y.filter(e=>"tool"===e.type),k=j.filter(e=>"running"===e.status),w=k.length>0,[S,C]=(0,o.useState)(null),T=!v&&(!!l||w),I=S??T,z=j.length+i.length,M=k[k.length-1],L=c??M?.meta.summary??(l?i.length>0?"Analyzing…":j.length>0?"Finishing tool results…":"Generating response…":void 0),[R,W]=(0,o.useState)(0);if((0,o.useEffect)(()=>{if(!l||!s)return void W(0);let e=()=>{W(Math.max(0,Math.floor((Date.now()-s)/1e3)))};e();let t=setInterval(e,1e3);return()=>clearInterval(t)},[l,s]),0===z&&!(u&&l))return null;let E=z>0?(x=j.filter(e=>"running"===e.status),g=j.filter(e=>"success"===e.status).length,f=j.filter(e=>"error"===e.status).length,m=j.filter(e=>"unknown"===e.status).length,[j.length>0?`${j.length} ${1===j.length?"tool":"tools"}`:null,i.length>0?`${i.length} ${1===i.length?"thought":"thoughts"}`:null,x.length>0?`${x.length} running`:null,g>0?`${g} completed`:null,f>0?`${f} failed`:null,m>0?`${m} unknown`:null].filter(Boolean)):[L??"Working…"],$=[a>0?`reconnect \xd7${a}`:null,d?`sync: ${d}`:null].filter(e=>!!e);return(0,n.jsxs)(to,{children:[(0,n.jsx)(ta,{expanded:I,total:z,summary:E.join(" \xb7 "),runningDescription:L,isStreaming:!!l,title:l?"Working":"Process",badgeLabel:l?function(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);return`${t}m ${String(e%60).padStart(2,"0")}s`}(R):String(z),debugLabel:l&&$.length>0?$.join(" \xb7 "):void 0,onToggle:()=>C(e=>!(e??T))}),I&&(0,n.jsx)(ti,{children:b.map(e=>"thinking"===e.type?(0,n.jsx)(td,{item:e,isStreaming:!!l},e.key):"contextGroup"===e.type?(0,n.jsx)(tc,{item:e,cwd:p,onOpenImage:h},e.key):(0,n.jsx)(tu,{item:e,cwd:p,onOpenImage:h},e.tool.toolCallId))})]})}function tg(e){if(!e)return null;let t=new Date(e),r=new Date,n=t.getFullYear()===r.getFullYear()&&t.getMonth()===r.getMonth()&&t.getDate()===r.getDate(),o=t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});if(n)return o;let i=t.toLocaleDateString([],{month:"short",day:"numeric",year:t.getFullYear()!==r.getFullYear()?"numeric":void 0});return`${i} ${o}`}function tf(e){if(navigator.clipboard?.writeText)return navigator.clipboard.writeText(e);try{let t=document.createElement("textarea");return t.value=e,t.style.position="fixed",t.style.opacity="0",document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t),Promise.resolve()}catch{return Promise.reject()}}function tm(e=768){let[t,r]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{let t=window.matchMedia(`(max-width: ${e}px)`),n=()=>r(t.matches);return n(),t.addEventListener?.("change",n),()=>t.removeEventListener?.("change",n)},[e]),t}function tv({message:e,isStreaming:t,toolResults:r,modelNames:o,entryId:i,onFork:l,forking:s,onSendMessage:a,showTimestamp:d,prevTimestamp:c,renderVisualCodeBlocks:u,cwd:p,onOpenImage:h,streamingProcessState:x,showWaitingShell:g}){return"user"===e.role?(0,n.jsx)(ty,{message:e,entryId:i,onFork:l,forking:s,onOpenImage:h}):"assistant"===e.role?(0,n.jsx)(tb,{message:e,isStreaming:t,toolResults:r,modelNames:o,onSendMessage:a,onOpenImage:h,showTimestamp:d,prevTimestamp:c,renderVisualCodeBlocks:u,cwd:p,streamingProcessState:x,showWaitingShell:g}):"toolResult"===e.role?null:"custom"===e.role?(0,n.jsx)(tj,{message:e,showTimestamp:d}):null}function ty({message:e,entryId:t,onFork:r,forking:i,onOpenImage:l}){let[s,a]=(0,o.useState)(!1),[d,c]=(0,o.useState)(!1),u=tm(),p="string"==typeof e.content?e.content:e.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n"),h="string"==typeof e.content?[]:e.content.filter(e=>"image"===e.type),x=tg(e.timestamp),g=h.flatMap(e=>{let t=eG(e);return t?[{src:t}]:[]});return(0,n.jsxs)("div",{style:{marginBottom:u?12:16,display:"flex",flexDirection:"column",alignItems:"flex-end"},onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),children:[(0,n.jsx)("div",{style:{display:"flex",alignItems:"flex-end",gap:u?4:6,maxWidth:u?"92%":"85%"},children:(0,n.jsxs)("div",{style:{flex:1,minWidth:0,background:"var(--user-bg)",border:"1px solid rgba(59,130,246,0.2)",borderRadius:12,padding:u?"7px 10px":"8px 12px",fontSize:14,lineHeight:1.6,color:"var(--text)",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:[h.length>0&&(0,n.jsx)("div",{style:{display:"flex",gap:u?4:6,flexWrap:"wrap",marginBottom:p?u?6:8:0},children:h.map((e,t)=>{let r=eG(e);return r?(0,n.jsx)("a",{href:r,target:"_blank",rel:"noreferrer",title:"Open image",style:{display:"block"},onClick:e=>{l&&(e.preventDefault(),l(r,void 0,g))},children:(0,n.jsx)("img",{src:r,alt:"",style:{maxWidth:240,maxHeight:240,borderRadius:6,objectFit:"contain",display:"block",border:"1px solid rgba(59,130,246,0.15)",cursor:"zoom-in"}})},t):null})}),p]})}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:u?4:6,marginTop:3},children:[(0,n.jsx)("div",{style:{display:"flex",gap:3,opacity:u?1:+!!s,pointerEvents:u||s?"auto":"none",transition:"opacity 0.12s"},children:(0,n.jsxs)("button",{onClick:()=>{tf(p).then(()=>{c(!0),setTimeout(()=>c(!1),1500)})},title:"Copy message",style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",height:22,background:"none",border:"none",borderRadius:5,color:d?"var(--accent)":"var(--text-dim)",cursor:"pointer",fontSize:11,fontWeight:400,whiteSpace:"nowrap",transition:"color 0.12s"},onMouseEnter:e=>{d||(e.currentTarget.style.color="var(--accent)")},onMouseLeave:e=>{d||(e.currentTarget.style.color="var(--text-dim)")},children:[d?(0,n.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,n.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),(0,n.jsx)("span",{style:u?{display:"none"}:void 0,children:d?"Copied":"Copy"})]})}),!!t&&!!r&&(0,n.jsx)("div",{style:{display:"flex",gap:3,opacity:u||s||i?1:0,pointerEvents:u||s||i?"auto":"none",transition:"opacity 0.12s"},children:(0,n.jsxs)("button",{onClick:()=>{r(t)},disabled:i,title:i?"Creating new session...":"New session - creates an independent copy from here",style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",height:22,background:"none",border:"none",borderRadius:5,color:i?"var(--accent)":"var(--text-dim)",cursor:i?"not-allowed":"pointer",fontSize:11,fontWeight:400,whiteSpace:"nowrap",transition:"color 0.12s"},onMouseEnter:e=>{i||(e.currentTarget.style.color="var(--accent)")},onMouseLeave:e=>{i||(e.currentTarget.style.color="var(--text-dim)")},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),(0,n.jsx)("span",{style:u?{display:"none"}:void 0,children:i?"Creating...":"New session"})]})}),x&&(0,n.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)"},children:x})]})]})}function tb({message:e,isStreaming:t,toolResults:r,modelNames:i,onSendMessage:l,onOpenImage:s,showTimestamp:a,streamingProcessState:d,prevTimestamp:c,renderVisualCodeBlocks:u,cwd:p,showWaitingShell:h}){var x;let g,f,m,v=a??!0?tg(e.timestamp):null,y=(0,o.useMemo)(()=>e.content??[],[e.content]),[b,j]=(0,o.useState)(!1),[k,w]=(0,o.useState)(!1),S=tm(),C=(0,o.useRef)(null),[T,I]=(0,o.useState)(null),z=(0,o.useRef)(y);z.current=y;let M=(0,o.useRef)(new Map),[L,R]=(0,o.useState)(new Map),W=(0,o.useMemo)(()=>{if(!e.timestamp||!c)return;let t=Math.round((e.timestamp-c)/1e3);return t>0?t:void 0},[e.timestamp,c]),E=(0,o.useMemo)(()=>{let t=new Map;if(!r||!e.timestamp)return t;for(let[n,o]of r)if(o.timestamp&&e.timestamp){let r=Math.round((o.timestamp-e.timestamp)/1e3);r>0&&t.set(n,r)}return t},[r,e.timestamp]),$=(0,o.useMemo)(()=>t&&d?d.thinkingBlocks.map(e=>({content:e.content,duration:W})):y.flatMap((e,t)=>"thinking"!==e.type?[]:[{content:e.thinking,duration:L.get(t)??W}]),[y,t,L,d,W]),P=(0,o.useMemo)(()=>t&&d?d.toolCalls:y.filter(e=>"toolCall"===e.type),[y,t,d]),A=y.filter(e=>"text"===e.type).map(e=>e.text).join("\n"),B=(0,o.useMemo)(()=>t&&d?y.filter(e=>"text"===e.type||"image"===e.type):y,[y,t,d]);(0,o.useEffect)(()=>{if(!t){let e=Date.now();R(t=>{let r=new Map(t);for(let[t,n]of M.current)r.has(t)||r.set(t,Math.round((e-n)/1e3));return r}),C.current=null,I(null);return}let e=setInterval(()=>{let e=z.current,t=Date.now();e.forEach((e,r)=>{M.current.has(r)||M.current.set(r,t)}),R(r=>{let n=!1,o=new Map(r);for(let r=0;r<e.length-1;r++)if(!o.has(r)&&M.current.has(r)){let e=M.current.get(r),i=M.current.get(r+1)??t;o.set(r,Math.round((i-e)/1e3)),n=!0}return n?o:r});let r=0;for(let t of e)"text"===t.type?r+=t.text?.length??0:"thinking"===t.type?r+=t.thinking?.length??0:"toolCall"===t.type&&(r+=JSON.stringify(t.input??{}).length);if(0===r)return;null===C.current&&(C.current=t);let n=(t-C.current)/1e3;n>.5&&I(r/4/n)},300);return()=>clearInterval(e)},[t]);let N=(f=e.provider?.trim(),m=e.model?.trim(),f&&m&&"unknown"!==m?i?.[`${f}:${m}`]??i?.[m]??m:f&&"codex"!==f&&"unknown"!==f?f:m&&"unknown"!==m?i?.[m]??m:null);return(0,n.jsxs)("div",{style:{marginBottom:S?12:16},onMouseEnter:()=>j(!0),onMouseLeave:()=>j(!1),children:[(0,n.jsxs)("div",{style:{fontSize:11,color:"var(--text-dim)",marginBottom:4,display:"flex",alignItems:"center",gap:S?4:6},children:[N&&(0,n.jsx)("span",{children:N}),t&&(()=>{let e,t=0;for(let e of y)"text"===e.type?t+=e.text?.length??0:"thinking"===e.type?t+=e.thinking?.length??0:"toolCall"===e.type&&(t+=JSON.stringify(e.input??{}).length);let r=Math.round(t/4);return(0,n.jsx)(n.Fragment,{children:r>0&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4,color:"var(--text)"},title:"预估 token 数(流式接收中)",children:[(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:2,fontSize:11,fontWeight:400},children:[(0,n.jsxs)("svg",{width:"10",height:"10",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]}),null!==T&&(e=T>=50?"#53b3cb":T>=30?"#9bc53d":T>=15?"#f9c22e":"#e01a4f",(0,n.jsxs)("span",{style:{marginLeft:6,padding:"1px 6px",borderRadius:4,background:e,color:"#fff",fontSize:11,fontWeight:400},children:[T.toFixed(1)," t/s"]}))]})})})()]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:S?6:8},children:[(P.length>0||$.length>0||h)&&(0,n.jsx)(tx,{tools:P,results:r,durations:E,thinkingBlocks:$,isStreaming:t,startedAt:t?d?.startedAt??e.timestamp??null:e.timestamp??null,reconnectCount:d?.reconnectCount??0,lastSyncReason:d?.lastSyncReason??null,statusText:d?.statusText??null,showWaitingShell:h,cwd:p,onOpenImage:s}),B.map((e,o)=>(0,n.jsx)(e7,{block:e,toolResults:r,isStreaming:t,streamingDuration:L.get(o)??("thinking"===e.type?W:void 0),toolCallDurations:E,onSendMessage:l,onOpenImage:s,renderVisualCodeBlocks:u,cwd:p},o))]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:S?6:8,marginTop:4},children:[e.usage&&!t&&(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)"},children:(x=e.usage,g=[],x.input&&g.push(`${x.input.toLocaleString()} in`),x.output&&g.push(`${x.output.toLocaleString()} out`),x.cacheRead&&g.push(`${x.cacheRead.toLocaleString()} cache`),x.cost?.total&&g.push(`$${x.cost.total.toFixed(4)}`),g.join(" \xb7 "))}),A&&!t&&(0,n.jsxs)("button",{onClick:()=>{tf(A).then(()=>{w(!0),setTimeout(()=>w(!1),1500)})},title:"Copy message",style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",height:22,background:"none",border:"none",borderRadius:5,color:k?"var(--accent)":"var(--text-dim)",cursor:"pointer",fontSize:11,fontWeight:400,whiteSpace:"nowrap",opacity:S?1:+!!b,pointerEvents:S||b?"auto":"none",transition:"opacity 0.12s, color 0.12s"},onMouseEnter:e=>{k||(e.currentTarget.style.color="var(--accent)")},onMouseLeave:e=>{k||(e.currentTarget.style.color="var(--text-dim)")},children:[k?(0,n.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,n.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),(0,n.jsx)("span",{style:S?{display:"none"}:void 0,children:k?"Copied":"Copy"})]}),v&&!t&&(0,n.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)",marginLeft:"auto"},children:v})]})]})}function tj({message:e,showTimestamp:t}){if(!e.display)return null;let r=t?tg(e.timestamp):null,o="string"==typeof e.content?e.content:e.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n"),i="subagent-notify"===e.customType,l=o.match(/^Background task (completed|failed|paused):\s*\*\*(.+?)\*\*/),s=l?"completed"===l[1]?"✅":"failed"===l[1]?"❌":"⏸":i?"\uD83E\uDD16":"ℹ";return(0,n.jsxs)("div",{style:{marginBottom:12},children:[(0,n.jsx)("div",{style:{padding:"8px 14px",borderRadius:8,border:`1px solid ${i?"rgba(99,102,241,0.25)":"var(--border)"}`,background:i?"rgba(99,102,241,0.05)":"var(--bg-panel)",fontSize:13,lineHeight:1.6,color:"var(--text-muted)"},children:(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[(0,n.jsx)("span",{style:{flexShrink:0,fontSize:14},children:s}),(0,n.jsx)("div",{style:{flex:1,minWidth:0},children:(0,n.jsx)(eT,{content:o,style:{fontSize:13}})})]})}),(r||l)&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:6,marginTop:3},children:[l&&(0,n.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)"},children:l[2]}),r&&(0,n.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)"},children:r})]})]})}function tk(e){let t=e.trim();if(!t.startsWith("/goal"))return null;let r=t.slice(5).trim();if(!r)return{kind:"invalid",reason:"请描述目标,例如:/goal 实现用户登录功能"};if(/^clear$/i.test(r))return{kind:"clear"};let n=r.indexOf("\n");if(n>0){let e=r.slice(0,n).trim(),t=r.slice(n+1).trim();return e?{kind:"set",objective:e,prompt:t||void 0}:{kind:"invalid",reason:"请描述目标,例如:/goal 实现用户登录功能"}}return{kind:"set",objective:r}}let tw={active:"进行中",paused:"已暂停",blocked:"已阻塞",usageLimited:"用量受限",budgetLimited:"预算受限",complete:"已完成"},tS=["image/","text/","application/pdf","application/json","application/gzip","application/x-gzip","application/zip","application/vnd.openxmlformats-officedocument","application/msword","application/vnd.ms-"],tC=new Set([".png",".jpg",".jpeg",".gif",".webp",".bmp",".svg",".pdf",".doc",".docx",".xls",".xlsx",".ppt",".pptx",".txt",".md",".csv",".tsv",".json",".yaml",".yml",".html",".htm",".xml",".fastq",".fq",".fasta",".fa",".faa",".fna",".bed",".vcf",".gff",".gtf",".sam",".bam",".cram",".gz",".tgz",".zip"]);function tT(e){let t,r=e.type.trim().toLowerCase();return!!(r&&tS.some(e=>r.startsWith(e)))||tC.has((t=e.name.toLowerCase().match(/(\.[^./\\]+)$/),t?.[1]??""))}function tI(e){if(!e)return!1;let t=Array.from(e.items);if(t.length>0)for(let e of t){if("file"!==e.kind)continue;let t=e.getAsFile();if(t&&tT(t))return!0;let r=e.type.trim().toLowerCase();if(r&&tS.some(e=>r.startsWith(e)))return!0}return Array.from(e.files).some(tT)}function tz(e){let[t,r]=(0,o.useState)(!1),n=(0,o.useRef)(0),i=(0,o.useCallback)(e=>{tI(e.dataTransfer)&&(e.preventDefault(),e.stopPropagation(),n.current+=1,r(!0))},[]),l=(0,o.useCallback)(e=>{tI(e.dataTransfer)&&(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect="copy")},[]);return{isDragOver:t,handleDragEnter:i,handleDragOver:l,handleDragLeave:(0,o.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),n.current-=1,n.current<=0&&(n.current=0,r(!1))},[]),handleDrop:(0,o.useCallback)(t=>{var o;t.preventDefault(),t.stopPropagation(),n.current=0,r(!1);let i=(o=t.dataTransfer)?Array.from(o.files).filter(tT):[];i.length&&e(i)},[e])}}let tM=["off","default","full"],tL={off:"none",default:"default",full:"full"},tR=["auto","off","minimal","low","medium","high","xhigh"],tW={auto:"沿用默认设置",off:"关闭推理",minimal:"最少推理",low:"低强度推理",medium:"中等推理",high:"高强度推理",xhigh:"最高强度推理"};function tE({doc:e,onRemove:t}){var r;let o=e.fileName.split(".").pop()?.toLowerCase()??"",i=function(e){switch(e){case"pdf":return{emoji:"\uD83D\uDCC4",color:"#ef4444"};case"docx":case"doc":return{emoji:"\uD83D\uDCDD",color:"#3b82f6"};case"xlsx":case"xls":return{emoji:"\uD83D\uDCCA",color:"#22c55e"};case"pptx":case"ppt":return{emoji:"\uD83D\uDCFD",color:"#f97316"};default:return{emoji:"\uD83D\uDCCE",color:"var(--text-muted)"}}}(o),l=(r=e.size)<1024?`${r} B`:r<1048576?`${(r/1024).toFixed(1)} KB`:`${(r/1048576).toFixed(1)} MB`;return(0,n.jsxs)("div",{style:{position:"relative",display:"flex",alignItems:"center",gap:6,padding:"5px 10px 5px 7px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,maxWidth:200},title:e.fileName,children:[(0,n.jsx)("span",{style:{color:i.color,fontSize:14,flexShrink:0},children:i.emoji}),(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",lineHeight:1.3},children:e.fileName}),(0,n.jsxs)("div",{style:{fontSize:10,color:"var(--text-dim)",lineHeight:1.3},children:[o.toUpperCase()," \xb7 ",l,e.extractionError?" \xb7 no text":e.truncated?" \xb7 truncated":e.extractedText?" \xb7 text":""]})]}),(0,n.jsx)("button",{onClick:t,style:{flexShrink:0,width:14,height:14,borderRadius:"50%",background:"var(--bg-hover)",border:"none",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,color:"var(--text-dim)"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)"},children:(0,n.jsxs)("svg",{width:"7",height:"7",viewBox:"0 0 7 7",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"1",y1:"1",x2:"6",y2:"6"}),(0,n.jsx)("line",{x1:"6",y1:"1",x2:"1",y2:"6"})]})})]})}let t$=[{command:"/compact",label:"/compact",description:"压缩当前上下文"},{command:"/goal",label:"/goal",description:"设置 Codex 持久目标(跨 turn 生效)"}],tP=[{command:"/memory",label:"/memory",description:"插入 MEMORY.md 沉淀模板",insertText:"请基于当前对话和项目上下文,整理建议写入 MEMORY.md 的长期记忆。\n要求:\n1. 只保留稳定、可复用、会影响后续协作的信息\n2. 区分建议新增、建议修改、建议删除\n3. 不要写入一次性的调试细节或临时状态\n4. 先给出建议内容,等我确认后再真正修改文件"},{command:"/init",label:"/init",description:"插入项目初始化梳理模板",insertText:"请先完成这个项目的初始化梳理,暂不改代码。\n输出:\n1. 运行、测试、发布相关命令\n2. 与当前任务最相关的架构路径和关键文件\n3. 当前需求的实现思路和落点\n4. 主要风险、假设和未知项"}];function tA(e){return e.replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'")}async function tB(e){let t=await r.e(2213).then(r.bind(r,12810));t.GlobalWorkerOptions.workerSrc=new r.U(r(53228)).toString();let n=await t.getDocument({data:e.slice(0)}).promise,o=[];for(let e=1;e<=n.numPages;e+=1){let t=await n.getPage(e),r=(await t.getTextContent()).items.map(e=>"str"in e?e.str:"").filter(Boolean).join(" ");r.trim()&&o.push(`Page ${e}
|
|
245
|
-
${r}`)}return o.join("\n\n")}async function tN(e){let t=(await r.e(4453).then(r.t.bind(r,54453,23))).default,n=await t.loadAsync(e),o=["word/document.xml",...Object.keys(n.files).filter(e=>/^word\/(footnotes|endnotes|comments)\.xml$/i.test(e)).sort()],i=[];for(let e of o){let t=n.file(e);if(!t)continue;let r=[...(await t.async("string")).replace(/<w:(br|cr)[^>]*\/>/g,"\n").replace(/<\/w:p>/g,"\n").matchAll(/<w:t[^>]*>([\s\S]*?)<\/w:t>/g)];i.push(...r.map(e=>tA(e[1])))}return i.join("").replace(/[ \t]+\n/g,"\n")}async function tD(e){let t=await Promise.all([r.e(3524),r.e(8436)]).then(r.bind(r,15967)),n=t.read(e,{type:"array"});return n.SheetNames.map(e=>{let r=n.Sheets[e],o=t.utils.sheet_to_csv(r);return`Sheet: ${e}
|
|
246
|
-
${o}`}).join("\n\n")}async function tO(e){let t=(await r.e(4453).then(r.t.bind(r,54453,23))).default,n=await t.loadAsync(e),o=Object.keys(n.files).map(e=>({name:e,match:/^ppt\/slides\/slide(\d+)\.xml$/i.exec(e)})).filter(e=>null!==e.match).sort((e,t)=>Number(e.match[1])-Number(t.match[1])),i=[];for(let{name:e,match:t}of o){let r=[...(await n.file(e).async("string")).matchAll(/<a:t[^>]*>([\s\S]*?)<\/a:t>/g)].map(e=>tA(e[1]).trim()).filter(Boolean);r.length&&i.push(`Slide ${t[1]}
|
|
247
|
-
${r.join("\n")}`)}return i.join("\n\n")}async function tH(e,t){let r=e.name.split(".").pop()?.toLowerCase()??"";try{let n,o="";if(e.type.startsWith("text/")||["csv","tsv","md","txt","json","xml"].includes(r))o=new TextDecoder("utf-8").decode(t);else if("pdf"===r||"application/pdf"===e.type)o=await tB(t);else if("docx"===r)o=await tN(t);else if("xlsx"===r)o=await tD(t);else{if("pptx"!==r)return{extractionError:"Text extraction is not supported for this file type"};o=await tO(t)}let{text:i,truncated:l}=(n=o.replace(/\r\n/g,"\n").replace(/\n{4,}/g,"\n\n\n").trim()).length<=6e4?{text:n,truncated:!1}:{text:`${n.slice(0,6e4)}
|
|
248
|
-
|
|
249
|
-
[truncated after 60000 characters]`,truncated:!0};if(!i)return{extractionError:"No extractable text found"};return{extractedText:i,truncated:l}}catch(e){return{extractionError:e instanceof Error?e.message:String(e)}}}let tF=(0,o.forwardRef)(function({onSend:e,onAbort:t,isStreaming:r,model:i,modelNames:s,modelList:a,onModelChange:d,onCompact:c,onAbortCompaction:u,isCompacting:p,compactError:h,onSetGoal:x,onClearGoal:g,onGoalInvalid:f,goalError:m,planMode:v,onPlanModeChange:y,toolPreset:b,onToolPresetChange:j,thinkingLevel:k,onThinkingLevelChange:w,availableThinkingLevels:S,thinkingLevelMap:C,retryInfo:T,soundEnabled:I,onSoundToggle:z,sandboxMode:M="workspace-write",onSandboxModeChange:L,enabledExtensions:R=[],availableExtensions:W=[],enabledExtensionDetails:P=[],onEnabledExtensionsChange:A,onOpenExtensionsSettings:B,sessionHistoryKey:N=null,promptHistory:D=[]},O){let H,F,_,{pushToast:U}=(0,l.d)(),[q,V]=(0,o.useState)(""),J=(0,o.useRef)(r);J.current=r;let[G,K]=(0,o.useState)([]),Y=(0,o.useRef)(D);Y.current=D;let Z=(0,o.useRef)(null),X=(0,o.useRef)(null);(0,o.useEffect)(()=>{if(!h){Z.current=null;return}h!==Z.current&&(Z.current=h,U(h,"error"))},[h,U]),(0,o.useEffect)(()=>{if(!m){X.current=null;return}m!==X.current&&(X.current=m,U(m,"error"))},[m,U]),(0,o.useEffect)(()=>{$(N)},[N]);let Q=(0,o.useCallback)(e=>{V(e),requestAnimationFrame(()=>{let t=eM.current;t&&(t.focus(),t.setSelectionRange(e.length,e.length),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)})},[]),[ee,et]=(0,o.useState)(!1),[er,en]=(0,o.useState)(null),[eo,ei]=(0,o.useState)(!1),[el,es]=(0,o.useState)(!1),[ea,ed]=(0,o.useState)(!1),[ec,eu]=(0,o.useState)(!1),[ep,eh]=(0,o.useState)(!1),[ex,eg]=(0,o.useState)(null),[ef,em]=(0,o.useState)([]),[ev,ey]=(0,o.useState)([]),eb=function(e=768){let[t,r]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{let t=window.matchMedia(`(max-width: ${e}px)`),n=()=>r(t.matches);return n(),t.addEventListener?.("change",n),()=>t.removeEventListener?.("change",n)},[e]),t}(),ej=eb?{display:"none"}:void 0,ek=eb?28:32,ew=eb?"6px 8px":"8px 12px",eS=eb?160:180,eC=eb&&!r,eT=ec?"var(--text)":"var(--text-muted)",eI={padding:"7px 8px",minHeight:eb?44:void 0,borderRadius:8,background:"var(--bg-panel)",border:"1px solid var(--border)",width:"100%",textAlign:"left",cursor:"pointer",touchAction:"manipulation",WebkitTapHighlightColor:"transparent"},ez=eb?{position:"sticky",bottom:0,zIndex:30,padding:"8px 0 calc(env(safe-area-inset-bottom, 0px) + 8px)",background:"linear-gradient(to top, color-mix(in srgb, var(--bg) 96%, transparent), color-mix(in srgb, var(--bg) 86%, transparent))",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",borderTop:"1px solid color-mix(in srgb, var(--border) 65%, transparent)"}:{flexShrink:0,background:"transparent",padding:"0 16px 8px",paddingRight:52},eM=(0,o.useRef)(null),eL=(0,o.useRef)(null),eR=(0,o.useRef)(null),eW=(0,o.useRef)(null),eE=(0,o.useRef)(null),e$=(0,o.useRef)(null),eP=(0,o.useRef)(null),eA=(0,o.useRef)(null),eB=(0,o.useRef)(null),eN=(0,o.useRef)(null),eD=(0,o.useCallback)(e=>{let t=eM.current;if(!t)return void V(t=>t+(t?" ":"")+e);let r=t.selectionStart??t.value.length,n=t.selectionEnd??t.value.length,o=t.value.slice(0,r),i=t.value.slice(n),l=!(o.length>0)||o.endsWith(" ")||o.endsWith("\n")||/^\s/.test(e)?"":" ";V(o+l+e+i),requestAnimationFrame(()=>{let t=eM.current;if(!t)return;let n=r+l.length+e.length;t.setSelectionRange(n,n),t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`})},[]),eO=(0,o.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/"));if(!t.length)return;let r=await Promise.all(t.map(e=>new Promise((t,r)=>{let n=new FileReader;n.onload=()=>{t({data:n.result.split(",")[1],mimeType:e.type,previewUrl:URL.createObjectURL(e),name:e.name})},n.onerror=r,n.readAsDataURL(e)})));em(e=>[...e,...r])},[]),eH=(0,o.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/")||/\.(png|jpe?g|gif|webp|bmp|svg)$/i.test(e.name)),r=e.filter(e=>!t.includes(e));if(t.length&&eO(t),r.length){let e=await Promise.all(r.map(e=>new Promise((t,r)=>{let n=new FileReader;n.onload=async()=>{let r=n.result,o=await tH(e,r);t({data:r,fileName:e.name,mimeType:e.type||"application/octet-stream",size:e.size,...o})},n.onerror=r,n.readAsArrayBuffer(e)})));ey(t=>[...t,...e])}},[eO]),{isDragOver:eF,handleDragEnter:e_,handleDragOver:eU,handleDragLeave:eq,handleDrop:eV}=tz((0,o.useCallback)(e=>{eH(e)},[eH])),eJ=(0,o.useCallback)(t=>{let r=t.text.trim();if(!r&&!t.images.length&&!t.docs.length)return;if("/compact"===r&&!t.images.length&&!t.docs.length&&c)return void(p?u?.():c());let n=tk(r);if(n&&!t.images.length&&!t.docs.length){if("clear"===n.kind&&g)return void g();if("set"===n.kind&&x){x(n.objective),n.prompt&&e(n.prompt);return}if("invalid"===n.kind)return void f?.(n.reason)}e(t.text,t.images.length?t.images:void 0,t.docs.length?t.docs:void 0)},[p,u,g,c,f,e,x]),eG=(0,o.useCallback)(e=>{(e.text.trim()||e.images.length||e.docs.length)&&(K(t=>[...t,{id:`${Date.now()}-${Math.random().toString(36).slice(2,8)}`,text:e.text,images:e.images.map(e=>({...e})),docs:e.docs.map(e=>({...e,data:e.data.slice(0)}))}]),U("Message queued — will send when the agent finishes.","info"))},[U]),eK=(0,o.useCallback)(e=>{K(t=>{let r=t.find(t=>t.id===e);return r&&r.images.forEach(e=>URL.revokeObjectURL(e.previewUrl)),t.filter(t=>t.id!==e)})},[]),eY=(0,o.useRef)(r);(0,o.useEffect)(()=>{let e=eY.current;eY.current=r,!r&&e&&K(e=>{if(0===e.length)return e;let[t,...r]=e;return queueMicrotask(()=>{eJ({text:t.text,images:t.images,docs:t.docs})}),r})},[eJ,r]);let eZ=G.map(e=>({id:e.id,text:e.text,imageCount:e.images.length,docCount:e.docs.length}));(0,o.useImperativeHandle)(O,()=>({insertIfEmpty(e){let t=eM.current;(t?t.value:q).trim()||(V(e),requestAnimationFrame(()=>{t&&(t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)}))},insertText(e){eD(e)},addImages(e){eO(e)},addFiles(e){eH(e)},sendOrQueue(e){let t=e.trim();if(t){if(J.current)return void eG({text:t,images:[],docs:[]});eJ({text:t,images:[],docs:[]})}}}),[eG,eJ,eD,eO,eH,q]);let eX=(0,o.useCallback)(e=>{em(t=>{let r=[...t];return URL.revokeObjectURL(r[e].previewUrl),r.splice(e,1),r})},[]),eQ=(0,o.useCallback)(e=>{ey(t=>{let r=[...t];return r.splice(e,1),r})},[]),e0=(0,o.useCallback)(()=>{em(e=>(e.forEach(e=>URL.revokeObjectURL(e.previewUrl)),[])),ey([])},[]),e1=(0,o.useCallback)(e=>{let t=q.trim()&&e.includes("\n")?`
|
|
250
|
-
|
|
251
|
-
${e}`:e;if(!q.trim()){V(t),requestAnimationFrame(()=>{let e=eM.current;e&&(e.focus(),e.setSelectionRange(t.length,t.length),e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)});return}eD(t)},[eD,q]),e2=(0,o.useCallback)(async e=>{if(!A)return;let t=R.includes(e)?R.filter(t=>t!==e):[...R,e];eg(e);try{await A(t)}finally{eg(null)}},[R,A]),e4=(0,o.useCallback)(()=>{if(!q.trim()&&!ef.length&&!ev.length)return;let e={text:q,images:ef,docs:ev};if(r){eG(e),V(""),e0(),eM.current&&(eM.current.style.height="auto");return}eJ(e),$(N),V(""),e0(),eM.current&&(eM.current.style.height="auto")},[ev,ef,e0,eG,eJ,r,N,q]),e5=(0,o.useCallback)(e=>{if("ArrowUp"!==e.key&&"ArrowDown"!==e.key||eo||ee||el||ea)return!1;let t=Y.current;if(!N||0===t.length)return!1;if("ArrowUp"===e.key){if(q.trim()&&!function(e){if(!e)return!1;let t=E.get(e);return(t?.cursor??-1)>=0}(N))return!1;let r=function(e,t,r){let n;if(!e||0===r.length)return null;let o=((n=E.get(e))||(n={cursor:-1,draftSnapshot:""},E.set(e,n)),n);if(-1===o.cursor)o.draftSnapshot=t,o.cursor=0;else{if(!(o.cursor<r.length-1))return null;o.cursor+=1}return r[o.cursor]??null}(N,q,t);return null!==r&&(e.preventDefault(),Q(r),!0)}let r=function(e,t){if(!e)return null;let r=E.get(e);if(!r||-1===r.cursor)return null;if(r.cursor>0)return r.cursor-=1,{text:t[r.cursor]??"",returnedToPresent:!1};let n=r.draftSnapshot;return r.cursor=-1,r.draftSnapshot="",{text:n,returnedToPresent:!0}}(N,t);return!!r&&(e.preventDefault(),Q(r.text),!0)},[Q,ee,N,eo,ea,el,q]),e6=(0,o.useCallback)(()=>{if(!L||r)return;let e="danger-full-access"===M?"workspace-write":"danger-full-access";("workspace-write"!==e||window.confirm("切换到默认权限后,执行命令或写文件时会请求你的确认。是否继续?"))&&L(e)},[r,L,M]),e3=(0,o.useCallback)(e=>{!e5(e)&&("Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),e4()))},[e5,e4]),e8=(0,o.useCallback)(()=>{let e=eM.current;e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[]),e7=(0,o.useCallback)(e=>{let t=Array.from(e.clipboardData?.items??[]).filter(e=>"file"===e.kind&&(e.type.startsWith("image/")||e.type.includes("pdf")||e.type.includes("officedocument")||e.type.includes("msword")||e.type.includes("ms-")));t.length&&(e.preventDefault(),eH(t.map(e=>e.getAsFile()).filter(e=>null!==e)))},[eH]),e9=a&&a.length>0?a.map(e=>({provider:e.provider,modelId:e.id,name:e.name})):Object.entries(s??{}).map(([e,t])=>({provider:i?.provider??"unknown",modelId:e,name:t})),te=[];for(let e of e9){let t=te.find(t=>t.provider===e.provider);t?t.options.push(e):te.push({provider:e.provider,options:[e]})}let tt=i?e9.find(e=>e.modelId===i.modelId&&e.provider===i.provider)?.name??i.modelId:"Select model",tr=tt??"Default",tn=(()=>{let e=k??"auto";if("auto"===e||!C)return e;let t=C[e];return null!=t?t:e})(),to=c||x?t$.filter(e=>"/compact"===e.command?!!c:"/goal"!==e.command||!!x):[],ti=to.length>0||tP.length>0,tl=e9.length>0&&!!d,ts=!!w,ta=!!j,td=W.length>0?W:P.length>0?P:R.map(e=>({id:e,name:e,transport:{type:"stdio"}})),tc=new Set(R),tu=td.filter(e=>tc.has(e.id)),tp=td.filter(e=>!tc.has(e.id)),th=td.length>0,tx=!!A,tg=Object.entries(tL).find(([,e])=>e===(b??"full"))?.[0]??"full",tf="danger-full-access"===M?"完全访问":"默认权限",tm=eb?26:32,tv=eb?7:9,ty=eb?3:6,tb={position:"fixed",left:8,right:8,bottom:"calc(env(safe-area-inset-bottom, 0px) + 8px)",zIndex:500,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:12,boxShadow:"0 -6px 24px rgba(0,0,0,0.14)",overflowX:"hidden",overflowY:"auto",maxHeight:"min(60dvh, 420px)",overscrollBehavior:"contain",WebkitOverflowScrolling:"touch",paddingBottom:"max(env(safe-area-inset-bottom, 0px), 4px)"},tj=eb&&(ee||eo||el||ea||ep||ec);return(0,o.useEffect)(()=>{if(!ee&&!eo&&!el&&!ea&&!ep&&!ec)return;let e=e=>{let t=e.target;if(!(t instanceof Node))return;let r=!!eL.current?.contains(t),n=!!eR.current?.contains(t);r||n||et(!1),eW.current?.contains(t)||ei(!1),e$.current?.contains(t)||es(!1),eP.current?.contains(t)||ed(!1),eA.current?.contains(t)||eu(!1),eE.current?.contains(t)||eh(!1)};return document.addEventListener("pointerdown",e,!0),()=>document.removeEventListener("pointerdown",e,!0)},[ee,eo,el,ea,ep,ec]),(0,o.useEffect)(()=>{if(!tj)return;let e=document.body,t=document.documentElement,r=e.style.overflow,n=e.style.overscrollBehavior,o=t.style.overscrollBehavior;return e.style.overflow="hidden",e.style.overscrollBehavior="contain",t.style.overscrollBehavior="contain",()=>{e.style.overflow=r,e.style.overscrollBehavior=n,t.style.overscrollBehavior=o}},[tj]),(0,n.jsxs)("div",{style:ez,children:[tj&&(0,n.jsx)("div",{"aria-hidden":!0,onClick:()=>{et(!1),ei(!1),es(!1),ed(!1),eu(!1)},style:{position:"fixed",inset:0,zIndex:490,background:"rgba(15, 23, 42, 0.18)",backdropFilter:"blur(1.5px)",WebkitBackdropFilter:"blur(1.5px)",touchAction:"none"}}),(0,n.jsx)("input",{ref:eB,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:e=>{eO(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsx)("input",{ref:eN,type:"file",accept:".pdf,.docx,.xlsx,.pptx,.doc,.xls,.ppt,.txt,.md,.csv,.tsv,.json,.yaml,.yml,.html,.htm,.xml,.fastq,.fq,.fasta,.fa,.bed,.vcf,.gff,.gtf,.sam,.gz,.zip,application/pdf,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.presentationml.presentation,text/plain,text/csv",multiple:!0,style:{display:"none"},onChange:e=>{eH(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsxs)("div",{style:{maxWidth:eb?"100%":820,margin:"0 auto",position:"relative",width:"100%",padding:eb?"0 8px":void 0,boxSizing:"border-box"},children:[T&&(0,n.jsxs)("div",{style:{marginBottom:eb?6:8,padding:eb?"4px 8px":"5px 10px",background:"rgba(234,179,8,0.08)",border:"1px solid rgba(234,179,8,0.25)",borderRadius:6,fontSize:eb?11:12,color:"rgba(180,130,0,0.9)",display:"flex",alignItems:"center",gap:6},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),(0,n.jsx)("path",{d:"M3 3v5h5"})]}),"Retrying (",T.attempt,"/",T.maxAttempts,")…",T.errorMessage&&(0,n.jsxs)("span",{style:{opacity:.7,marginLeft:4},children:["— ",T.errorMessage]})]}),(ef.length>0||ev.length>0||eZ.length>0)&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6,marginBottom:eb?4:6},children:[eZ.length>0&&(0,n.jsxs)("div",{style:{border:"1px solid color-mix(in srgb, var(--accent) 28%, var(--border))",borderRadius:8,background:"color-mix(in srgb, var(--accent) 6%, var(--bg-panel))",padding:"8px 10px",display:"flex",flexDirection:"column",gap:6},children:[(0,n.jsxs)("div",{style:{fontSize:10,fontWeight:650,color:"var(--accent)",letterSpacing:"0.04em",textTransform:"uppercase"},children:["Queued (",eZ.length,")"]}),eZ.map(e=>(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:11,color:"var(--text-muted)"},children:[(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:function(e,t,r){let n=e.trim(),o=[t>0?`${t} image${1===t?"":"s"}`:"",r>0?`${r} file${1===r?"":"s"}`:""].filter(Boolean).join(", ");if(!n)return o||"(empty message)";let i=n.length>96?`${n.slice(0,96)}…`:n;return o?`${i} \xb7 ${o}`:i}(e.text,e.imageCount,e.docCount)}),(0,n.jsx)("button",{type:"button",onClick:()=>eK(e.id),title:"Remove queued message",style:{flexShrink:0,width:22,height:22,borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text-dim)",cursor:"pointer",padding:0},children:"\xd7"})]},e.id))]}),(ef.length>0||ev.length>0)&&(0,n.jsxs)("div",{style:{display:"flex",gap:eb?4:6,flexWrap:"wrap",alignItems:"flex-end"},children:[ef.map((e,t)=>(0,n.jsxs)("div",{style:{position:"relative",flexShrink:0},children:[(0,n.jsx)("img",{src:e.previewUrl,alt:"",style:{width:56,height:56,objectFit:"cover",borderRadius:6,border:"1px solid var(--border)",display:"block"}}),(0,n.jsx)("button",{onClick:()=>eX(t),style:{position:"absolute",top:-4,right:-4,width:16,height:16,borderRadius:"50%",background:"var(--bg-panel)",border:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,color:"var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"1",y1:"1",x2:"7",y2:"7"}),(0,n.jsx)("line",{x1:"7",y1:"1",x2:"1",y2:"7"})]})})]},`img-${t}`)),ev.map((e,t)=>(0,n.jsx)(tE,{doc:e,onRemove:()=>eQ(t)},`doc-${t}`))]})]}),(0,n.jsxs)("div",{onDragEnter:e_,onDragOver:eU,onDragLeave:eq,onDrop:eV,style:{display:"flex",gap:8,alignItems:"center",background:eF?"color-mix(in srgb, var(--accent) 6%, var(--bg))":"var(--bg)",border:eF?"1px solid color-mix(in srgb, var(--accent) 55%, var(--border))":"1px solid color-mix(in srgb, var(--border) 70%, transparent)",borderRadius:14,padding:"10px 10px 10px 14px",boxShadow:eF?"0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent)":"0 1px 2px rgba(15,23,42,0.04), 0 8px 24px -12px rgba(15,23,42,0.10)",transition:"border-color 0.15s, background 0.15s, box-shadow 0.15s"},children:[(0,n.jsx)("textarea",{ref:eM,value:q,onChange:e=>V(e.target.value),onKeyDown:e3,onInput:e8,onPaste:e7,placeholder:r?"Agent is running — press Enter to queue the next message…":"Message… (drop files here)",rows:1,style:{flex:1,background:"none",border:"none",outline:"none",resize:"none",color:"var(--text)",fontSize:14,lineHeight:1.6,fontFamily:"inherit",minHeight:24,maxHeight:200,overflow:"auto"}}),(q.trim()||ef.length||ev.length)&&(0,n.jsxs)("button",{onClick:e4,style:{flexShrink:0,alignSelf:"flex-end",display:"flex",alignItems:"center",gap:eb?4:6,padding:eb?"6px 10px":"7px 14px",background:"var(--accent)",border:"none",borderRadius:8,color:"#fff",cursor:"pointer",fontSize:eb?12:13,fontWeight:600,letterSpacing:"-0.01em",boxShadow:"0 1px 3px rgba(37,99,235,0.25)",transition:"background 0.15s, box-shadow 0.15s"},children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"2",y1:"7",x2:"11",y2:"7"}),(0,n.jsx)("polyline",{points:"7.5 3 12 7 7.5 11"})]}),r?"Queue":"Send"]})]}),(0,n.jsxs)("div",{className:"chat-input-toolbar",style:{marginTop:eb?5:8,display:"flex",alignItems:eb?"flex-start":"center",gap:ty,flexWrap:eb?"wrap":"nowrap"},children:[(0,n.jsxs)("div",{className:"chat-input-toolbar-left",style:{flex:eb?"1 1 100%":"0 0 auto",width:eb?"100%":void 0,minWidth:0,display:"flex",alignItems:"center",gap:2*!eb,flexWrap:eb?"wrap":"nowrap",rowGap:4*!!eb},children:[(0,n.jsx)("button",{onClick:()=>eB.current?.click(),title:"Attach image (right-click for document)",style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:tm,height:tm,padding:0,background:"none",border:"none",borderRadius:tv,color:ef.length||ev.length?"var(--accent)":"var(--text-muted)",cursor:"pointer",opacity:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=ef.length||ev.length?"var(--accent)":"var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=ef.length||ev.length?"var(--accent)":"var(--text-muted)"},onContextMenu:e=>{e.preventDefault(),eN.current?.click()},children:(0,n.jsx)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})})}),th&&(0,n.jsxs)("div",{ref:eE,style:{position:"relative"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{r||(et(!1),ei(!1),es(!1),ed(!1),eu(!1),eh(e=>!e))},disabled:r,title:`Extensions (${R.length})`,style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",gap:6*!eb,width:eb?tm:void 0,height:ek,padding:eb?0:ew,background:ep?"var(--bg-hover)":"none",border:"none",borderRadius:eb?tv:9,color:R.length>0?"var(--accent)":"var(--text-muted)",cursor:r?"not-allowed":"pointer",fontSize:eb?11:12,opacity:r?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{r||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=R.length>0?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=ep?"var(--bg-hover)":"none",e.currentTarget.style.color=R.length>0?"var(--accent)":"var(--text-muted)"},children:[(0,n.jsxs)("svg",{width:eb?15:12,height:eb?15:12,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 2v6"}),(0,n.jsx)("path",{d:"M12 16v6"}),(0,n.jsx)("path",{d:"M4.93 4.93l4.24 4.24"}),(0,n.jsx)("path",{d:"M14.83 14.83l4.24 4.24"}),(0,n.jsx)("path",{d:"M2 12h6"}),(0,n.jsx)("path",{d:"M16 12h6"}),(0,n.jsx)("path",{d:"M4.93 19.07l4.24-4.24"}),(0,n.jsx)("path",{d:"M14.83 9.17l4.24-4.24"})]}),!eb&&(0,n.jsxs)("span",{style:{whiteSpace:"nowrap"},children:["Extensions (",R.length,")"]})]}),ep&&(0,n.jsxs)("div",{style:{...eb?tb:{position:"absolute",left:0,bottom:"calc(100% + 8px)",minWidth:260,maxWidth:320,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 14px 36px rgba(15,23,42,0.18)",zIndex:80},padding:8,display:"grid",gap:6},children:[(0,n.jsxs)("div",{style:{padding:"4px 6px 2px"},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:700,color:"var(--text)"},children:"Extensions"}),(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",marginTop:2},children:"Available extensions for this project. Toggle them for the current session runtime below."})]}),(0,n.jsxs)("div",{style:{display:"grid",gap:8,maxHeight:280,overflowY:"auto"},children:[tu.length>0&&(0,n.jsxs)("div",{style:{display:"grid",gap:4},children:[(0,n.jsx)("div",{style:{padding:"2px 6px",fontSize:11,fontWeight:700,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:.4},children:"Enabled in this session"}),tu.map(e=>{let t=e.id,r=e.transport?.type==="http"?"HTTP":"MCP",o=[t,e.scope,e.description].filter(Boolean).join(" \xb7 "),i=`Use the ${t} extension for this request if it helps.`,l=ex===t;return(0,n.jsxs)("div",{style:{display:"grid",gap:6,padding:"9px 10px",borderRadius:8,background:"var(--bg)",border:"1px solid var(--border)"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{e1(i),eh(!1)},style:{display:"grid",gap:6,width:"100%",padding:0,background:"transparent",border:"none",cursor:"pointer",textAlign:"left"},title:`Insert a prompt hint for ${t}`,children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,n.jsx)("span",{style:{fontSize:12,fontWeight:700,color:"var(--text)"},children:e.name||t}),(0,n.jsx)("span",{style:{fontSize:10,color:"var(--accent)",fontWeight:700,letterSpacing:.2},children:r})]}),(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",lineHeight:1.4},children:(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)"},children:o})})]}),tx&&(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",gap:8,paddingTop:2},children:[(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:"Session runtime"}),(0,n.jsx)("button",{type:"button",disabled:l,onClick:()=>{e2(t)},style:{minWidth:78,padding:"5px 9px",borderRadius:999,border:"1px solid var(--border)",background:"color-mix(in srgb, var(--accent) 16%, transparent)",color:"var(--accent)",cursor:l?"wait":"pointer",fontSize:11,fontWeight:700,opacity:l?.7:1},children:l?"Saving...":"Enabled"})]})]},t)})]}),tp.length>0&&(0,n.jsxs)("div",{style:{display:"grid",gap:4},children:[(0,n.jsx)("div",{style:{padding:"2px 6px",fontSize:11,fontWeight:700,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:.4},children:"Other available extensions"}),tp.map(e=>{let t=e.id,r=e.transport?.type==="http"?"HTTP":"MCP",o=[t,e.scope,e.description].filter(Boolean).join(" \xb7 "),i=`Use the ${t} extension for this request if it helps.`,l=ex===t;return(0,n.jsxs)("div",{style:{display:"grid",gap:6,padding:"9px 10px",borderRadius:8,background:"var(--bg)",border:"1px solid var(--border)"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{e1(i),eh(!1)},style:{display:"grid",gap:6,width:"100%",padding:0,background:"transparent",border:"none",cursor:"pointer",textAlign:"left"},title:`Insert a prompt hint for ${t}`,children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,n.jsx)("span",{style:{fontSize:12,fontWeight:700,color:"var(--text)"},children:e.name||t}),(0,n.jsx)("span",{style:{fontSize:10,color:"var(--accent)",fontWeight:700,letterSpacing:.2},children:r})]}),(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",lineHeight:1.4},children:(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)"},children:o})})]}),tx&&(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",gap:8,paddingTop:2},children:[(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:"Session runtime"}),(0,n.jsx)("button",{type:"button",disabled:l,onClick:()=>{e2(t)},style:{minWidth:78,padding:"5px 9px",borderRadius:999,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-dim)",cursor:l?"wait":"pointer",fontSize:11,fontWeight:700,opacity:l?.7:1},children:l?"Saving...":"Enable"})]})]},t)})]})]}),B&&(0,n.jsx)("button",{type:"button",onClick:()=>{eh(!1),B()},style:{marginTop:4,display:"flex",alignItems:"center",justifyContent:"center",gap:6,width:"100%",padding:"9px 10px",borderRadius:8,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",cursor:"pointer",fontSize:12,fontWeight:600},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg)"},children:"Open Extensions Settings"})]})]}),ti&&(0,n.jsxs)("div",{ref:eW,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>{r||(et(!1),es(!1),ed(!1),eu(!1),ei(e=>!e))},disabled:r,title:"插入斜杠命令",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:tm,height:tm,padding:0,background:eo?"var(--bg-hover)":"none",border:"none",borderRadius:tv,color:h?"#ef4444":"var(--text-muted)",cursor:r?"not-allowed":"pointer",opacity:r?.5:1,fontSize:15,fontWeight:700,fontFamily:"var(--font-mono)",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{r||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=h?"#ef4444":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=eo?"var(--bg-hover)":"none",e.currentTarget.style.color=h?"#ef4444":"var(--text-muted)"},children:["/",h&&(0,n.jsx)("span",{style:{position:"absolute",top:7,right:7,width:5,height:5,borderRadius:"50%",background:"#ef4444"}})]}),eo&&(0,n.jsxs)("div",{style:{...eb?tb:{position:"absolute",bottom:"calc(100% + 6px)",left:0,zIndex:100,minWidth:320,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)"},overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderBottom:h?"1px solid var(--border)":"none"},children:"Commands"}),to.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Native"}),to.map(e=>(0,n.jsxs)("button",{onClick:()=>{(ei(!1),"/compact"===e.command&&p)?u?.():"/goal"===e.command?e1("/goal "):e1(e.command)},style:{display:"flex",alignItems:"center",gap:eb?6:8,width:"100%",padding:ew,background:"none",border:"none",color:"/compact"===e.command&&p?"#ef4444":"var(--text-muted)",cursor:"pointer",fontSize:eb?11:12,textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,n.jsx)("span",{style:{width:18,flexShrink:0,display:"flex",justifyContent:"center",color:"/compact"===e.command&&p?"#ef4444":"var(--text-dim)"},children:"/compact"===e.command&&p?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:(0,n.jsx)("rect",{x:"2",y:"2",width:"6",height:"6",rx:"1",fill:"currentColor"})}):(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"4 14 10 14 10 20"}),(0,n.jsx)("polyline",{points:"20 10 14 10 14 4"}),(0,n.jsx)("line",{x1:"10",y1:"14",x2:"3",y2:"21"}),(0,n.jsx)("line",{x1:"21",y1:"3",x2:"14",y2:"10"})]})}),(0,n.jsxs)("span",{style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:8},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text)"},children:"/compact"===e.command&&p?"停止压缩":e.label}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:"/compact"===e.command&&p?"中止当前压缩任务":e.description})]})]},e.command))]}),tP.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:{marginTop:2*(to.length>0),padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:to.length>0?"1px solid var(--border)":"none"},children:"Prompt Shortcuts"}),tP.map(e=>(0,n.jsxs)("button",{onClick:()=>{ei(!1),e1(e.insertText??e.command)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:ew,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:eb?11:12,textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,n.jsx)("span",{style:{width:18,flexShrink:0,display:"flex",justifyContent:"center",color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:13},children:"/"}),(0,n.jsxs)("span",{style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:8},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text)"},children:e.label}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:e.description})]})]},e.command))]})]})]}),tl&&(0,n.jsxs)("div",{ref:eL,style:{position:"relative",flex:eb?"1 1 160px":void 0,minWidth:0},children:[(0,n.jsxs)("button",{onClick:e=>{if(!eb){let t=e.currentTarget.getBoundingClientRect();en({top:t.top,left:t.left,width:t.width})}ei(!1),es(!1),ed(!1),eu(!1),et(e=>!e)},disabled:r,style:{display:"flex",alignItems:"center",gap:6,padding:ew,height:ek,width:eb?"100%":void 0,maxWidth:eb?"100%":220,overflow:"hidden",background:ee?"var(--bg-hover)":"none",border:"none",borderRadius:eb?8:9,color:"var(--text-muted)",cursor:r?"not-allowed":"pointer",fontSize:eb?11:12,opacity:r?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{r||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=ee?"var(--bg-hover)":"none",e.currentTarget.style.color="var(--text-muted)"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),(0,n.jsx)("rect",{x:"9",y:"9",width:"6",height:"6"}),(0,n.jsx)("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),(0,n.jsx)("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),(0,n.jsx)("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),(0,n.jsx)("line",{x1:"15",y1:"20",x2:"15",y2:"23"}),(0,n.jsx)("line",{x1:"20",y1:"9",x2:"23",y2:"9"}),(0,n.jsx)("line",{x1:"20",y1:"14",x2:"23",y2:"14"}),(0,n.jsx)("line",{x1:"1",y1:"9",x2:"4",y2:"9"}),(0,n.jsx)("line",{x1:"1",y1:"14",x2:"4",y2:"14"})]}),(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:tt})]}),ee&&(eb?(0,n.jsxs)("div",{ref:eR,style:{...tb,display:"flex",flexDirection:"column"},children:[(0,n.jsxs)("div",{style:{padding:"8px 12px 6px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsx)("div",{style:{fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Models"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:tt})]}),(0,n.jsx)("div",{style:{overflowY:"auto"},children:te.map((e,t)=>(0,n.jsxs)("div",{children:[te.length>1&&(0,n.jsx)("div",{style:{padding:"6px 12px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:t>0?"1px solid var(--border)":"none"},children:e.provider}),e.options.map(e=>{let t=e.modelId===i?.modelId&&e.provider===i?.provider;return(0,n.jsxs)("button",{onClick:()=>{et(!1),t||d?.(e.provider,e.modelId)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"10px 12px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left",fontWeight:t?600:400},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,whiteSpace:"normal",lineHeight:1.35},children:e.name})]},`${e.provider}:${e.modelId}`)})]},e.provider))})]}):er&&(F=(H=window.visualViewport?.height??window.innerHeight)-er.top+6,_=Math.max(120,Math.min(er.top-8,.6*H)),(0,n.jsx)("div",{ref:eR,style:{position:"fixed",bottom:F,left:er.left,zIndex:500,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",overflow:"hidden",width:"max-content",minWidth:er.width,maxHeight:_,overflowY:"auto"},children:te.map((e,t)=>(0,n.jsxs)("div",{children:[te.length>1&&(0,n.jsx)("div",{style:{padding:"6px 12px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:t>0?"1px solid var(--border)":"none"},children:e.provider}),e.options.map(e=>{let t=e.modelId===i?.modelId&&e.provider===i?.provider;return(0,n.jsxs)("button",{onClick:()=>{et(!1),t||d?.(e.provider,e.modelId)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:eb?11:12,textAlign:"left",fontWeight:t?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),e.name]},`${e.provider}:${e.modelId}`)})]},e.provider))})))]}),!eC&&L&&(0,n.jsxs)("button",{onClick:e6,disabled:r,title:"danger-full-access"===M?"切换到默认权限(需要审批)":"切换到完全访问(danger-full-access)",style:{display:"flex",alignItems:"center",gap:6,padding:ew,height:ek,background:"danger-full-access"===M?"rgba(239,68,68,0.08)":"none",border:"danger-full-access"===M?"1px solid rgba(239,68,68,0.24)":"none",borderRadius:eb?8:9,color:"danger-full-access"===M?"#ef4444":"var(--text-muted)",cursor:r?"not-allowed":"pointer",fontSize:eb?11:12,opacity:r?.5:1,transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{r||(e.currentTarget.style.background="danger-full-access"===M?"rgba(239,68,68,0.14)":"var(--bg-hover)",e.currentTarget.style.color="danger-full-access"===M?"#ef4444":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background="danger-full-access"===M?"rgba(239,68,68,0.08)":"none",e.currentTarget.style.color="danger-full-access"===M?"#ef4444":"var(--text-muted)"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 2l7 4v6c0 5-3.5 8.5-7 10-3.5-1.5-7-5-7-10V6l7-4Z"}),"danger-full-access"===M?(0,n.jsx)("path",{d:"M9 12l2 2 4-4"}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("path",{d:"M12 8v4"}),(0,n.jsx)("path",{d:"M12 16h.01"})]})]}),(0,n.jsx)("span",{style:ej,children:"danger-full-access"===M?"完全访问":"默认权限"})]}),!eC&&y&&(0,n.jsxs)("button",{onClick:()=>{r||y("plan"===v?"code":"plan")},disabled:r,title:"plan"===v?"切换到 Code 模式(可执行代码)":"切换到 Plan 模式(只读规划)",style:{display:"flex",alignItems:"center",gap:6,padding:ew,height:ek,background:"plan"===v?"rgba(59,130,246,0.08)":"none",border:"plan"===v?"1px solid rgba(59,130,246,0.24)":"none",borderRadius:eb?8:9,color:"plan"===v?"#3b82f6":"var(--text-muted)",cursor:r?"not-allowed":"pointer",fontSize:eb?11:12,opacity:r?.5:1,transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{r||(e.currentTarget.style.background="plan"===v?"rgba(59,130,246,0.14)":"var(--bg-hover)",e.currentTarget.style.color="plan"===v?"#3b82f6":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background="plan"===v?"rgba(59,130,246,0.08)":"none",e.currentTarget.style.color="plan"===v?"#3b82f6":"var(--text-muted)"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M9 11l3 3L22 4"}),(0,n.jsx)("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]}),(0,n.jsx)("span",{style:ej,children:"plan"===v?"Plan":"Code"})]})]}),(0,n.jsx)("div",{className:"chat-input-toolbar-spacer",style:{display:eC?"none":void 0,flex:eb?"0 0 auto":1,width:eb?0:void 0,height:eb?0:void 0}}),(0,n.jsxs)("div",{className:"chat-input-toolbar-right",style:{flex:eb?"1 1 100%":"0 0 auto",width:eb?"100%":void 0,display:"flex",alignItems:"center",justifyContent:eb?"space-between":void 0,gap:eb?4:2,marginLeft:eb?0:"auto",marginTop:2*!!eb},children:[eC&&(tl||ts||ta||!!L)&&(0,n.jsxs)("div",{ref:eA,style:{position:"relative"},children:[(0,n.jsx)("button",{onClick:()=>{ei(!1),et(!1),es(!1),ed(!1),eu(e=>!e)},title:"更多设置",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:ec?"var(--bg-hover)":"none",border:"none",borderRadius:8,color:eT,cursor:"pointer",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background=ec?"var(--bg-hover)":"none",e.currentTarget.style.color=ec?"var(--text)":"var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("circle",{cx:"5",cy:"12",r:"1.5"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"1.5"}),(0,n.jsx)("circle",{cx:"19",cy:"12",r:"1.5"})]})}),ec&&(0,n.jsxs)("div",{style:{...tb,zIndex:510,padding:"6px",display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("div",{style:{padding:"4px 6px 2px",fontSize:10,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"More"}),(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",padding:"0 6px 4px"},children:"模型、推理、工具等设置已收进这里。"}),(0,n.jsxs)("div",{style:{display:"grid",gap:4},children:[tl&&(0,n.jsxs)("button",{onClick:()=>{eu(!1),ed(!1),es(!1),et(!0)},style:eI,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Model"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2,wordBreak:"break-word",lineHeight:1.35},children:tr})]}),(ts||ta)&&(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:ts&&ta?"1fr 1fr":"1fr",gap:4},children:[ts&&(0,n.jsxs)("button",{onClick:()=>{eu(!1),et(!1),es(!1),ed(!0)},style:eI,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Thinking"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:tn})]}),ta&&(0,n.jsxs)("button",{onClick:()=>{eu(!1),et(!1),ed(!1),es(!0)},style:eI,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Tools"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:tg})]})]}),L&&(0,n.jsxs)("button",{onClick:()=>{eu(!1),e6()},style:eI,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Sandbox"}),(0,n.jsx)("div",{style:{fontSize:12,color:"完全访问"===tf?"#ef4444":"var(--text)",marginTop:2},children:tf})]})]})]})]}),(!eC&&!r||eb&&ea)&&w&&(0,n.jsxs)("div",{ref:eP,style:{position:"relative"},children:[!eC&&!r&&(0,n.jsxs)("button",{onClick:()=>{r||(ei(!1),et(!1),es(!1),eu(!1),ed(e=>!e))},disabled:r,title:"切换推理强度",style:{display:"flex",alignItems:"center",gap:eb?3:5,padding:ew,height:ek,background:ea?"var(--bg-hover)":"none",border:"none",borderRadius:eb?8:9,color:"var(--text-muted)",cursor:r?"not-allowed":"pointer",fontSize:eb?11:12,opacity:r?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{r||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=ea?"var(--bg-hover)":"none",e.currentTarget.style.color="var(--text-muted)"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M9.5 2A5.5 5.5 0 0 0 4 7.5c0 1.7.78 3.21 2 4.21V14a1 1 0 0 0 1 1h5a1 1 0 0 0 1-1v-2.29c1.22-1 2-2.51 2-4.21A5.5 5.5 0 0 0 9.5 2z"}),(0,n.jsx)("line",{x1:"7",y1:"18",x2:"12",y2:"18"}),(0,n.jsx)("line",{x1:"8",y1:"21",x2:"11",y2:"21"})]}),(0,n.jsx)("span",{style:ej,children:tn})]}),ea&&(0,n.jsx)("div",{style:{...eb?tb:{position:"absolute",bottom:"calc(100% + 6px)",right:0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",minWidth:eS},overflow:"hidden"},children:tR.filter(e=>!S||"auto"===e||S.includes(e)).map(e=>{let t=(k??"auto")===e,r=tW[e],o="auto"!==e&&C?C[e]:void 0,i=null!=o?o:e,l=null!=o&&o!==e;return(0,n.jsxs)("button",{onClick:()=>{ed(!1),t||w(e)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:eb?11:12,textAlign:"left",fontWeight:t?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsxs)("span",{style:{flex:1},children:[i,l&&(0,n.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",fontFamily:"var(--font-mono)",marginLeft:5},children:["(",e,")"]})]}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:r})]},e)})})]}),(!eC&&!r||eb&&el)&&j&&(0,n.jsxs)("div",{ref:e$,style:{position:"relative"},children:[!eC&&!r&&(0,n.jsxs)("button",{onClick:()=>{r||(ei(!1),et(!1),ed(!1),eu(!1),es(e=>!e))},disabled:r,title:"切换工具预设",style:{display:"flex",alignItems:"center",gap:eb?3:5,padding:ew,height:ek,background:el?"var(--bg-hover)":"none",border:"none",borderRadius:eb?8:9,color:"var(--text-muted)",cursor:r?"not-allowed":"pointer",fontSize:eb?11:12,opacity:r?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{r||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=el?"var(--bg-hover)":"none",e.currentTarget.style.color="var(--text-muted)"},children:[(0,n.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"})}),(0,n.jsx)("span",{style:ej,children:Object.entries(tL).find(([,e])=>e===(b??"full"))?.[0]??"full"})]}),el&&(0,n.jsx)("div",{style:{...eb?tb:{position:"absolute",bottom:"calc(100% + 6px)",right:0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",minWidth:120},overflow:"hidden"},children:tM.map(e=>{let t=tL[e],r=(b??"full")===t,o="off"===e?"无工具,纯聊天":"default"===e?"4 项内置工具":"全部内置工具";return(0,n.jsxs)("button",{onClick:()=>{es(!1),r||j(t)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:r?"var(--bg-selected)":"none",border:"none",color:r?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:eb?11:12,textAlign:"left",fontWeight:r?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{r||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{r||(e.currentTarget.style.background="none")},children:[r?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1},children:e}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:o})]},e)})})]}),r&&(0,n.jsxs)("button",{onClick:t,title:"停止 Agent",style:{display:"flex",alignItems:"center",gap:6,padding:"8px 14px",height:ek,background:"rgba(239,68,68,0.08)",border:"1px solid rgba(239,68,68,0.3)",borderRadius:eb?8:9,color:"#ef4444",cursor:"pointer",fontSize:eb?11:12,fontWeight:600,whiteSpace:"nowrap",letterSpacing:"-0.01em",transition:"background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.16)"},onMouseLeave:e=>{e.currentTarget.style.background="rgba(239,68,68,0.08)"},children:[(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:(0,n.jsx)("rect",{x:"1.5",y:"1.5",width:"7",height:"7",rx:"1.5",fill:"currentColor"})}),"Stop"]}),void 0!==z&&(0,n.jsx)("button",{onClick:z,title:I?"关闭完成提示音":"开启完成提示音",style:{display:"flex",alignItems:"center",justifyContent:"center",width:tm,height:tm,padding:0,background:"none",border:"none",borderRadius:tv,color:I?"var(--text-muted)":"var(--text-dim)",cursor:"pointer",opacity:I?1:.55,transition:"background 0.12s, color 0.12s, opacity 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)",e.currentTarget.style.opacity="1"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=I?"var(--text-muted)":"var(--text-dim)",e.currentTarget.style.opacity=I?"1":"0.55"},children:I?(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,n.jsx)("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"}),(0,n.jsx)("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"})]}):(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,n.jsx)("line",{x1:"23",y1:"9",x2:"17",y2:"15"}),(0,n.jsx)("line",{x1:"17",y1:"9",x2:"23",y2:"15"})]})})]})]})]})]})});function t_(e){return"user"===e.role?{bg:"rgba(37,99,235,0.18)",border:"rgba(37,99,235,0.7)"}:{bg:"rgba(107,114,128,0.12)",border:"rgba(107,114,128,0.5)"}}function tU({messages:e,streamingMessage:t,scrollContainer:r,messageRefs:i}){let[l,s]=(0,o.useState)(0),[a,d]=(0,o.useState)(1),[c,u]=(0,o.useState)(!1),[p,h]=(0,o.useState)([]),[x,g]=(0,o.useState)(!1),[f,m]=(0,o.useState)(null),v=(0,o.useRef)(!1),y=(0,o.useRef)(null),b=(0,o.useMemo)(()=>t?[...e,t]:e,[e,t]),j=(0,o.useRef)(b);j.current=b;let k=(0,o.useRef)(null);k.current=()=>{let e=r.current;if(!e)return;let t=e.scrollHeight,n=e.clientHeight,o=t-n;u(o>20),o<=0?(s(0),d(1)):(s(e.scrollTop/o),d(n/t));let l=i.current,a=[],c=0,p=j.current;for(let r=0;r<p.length;r++){let n=p[r];if("user"!==n.role&&"assistant"!==n.role)continue;let o=l?.[c];if(c++,("user"===n.role||"assistant"===n.role&&(n.content??[]).some(e=>"text"===e.type))&&o&&t>0){let r=o.getBoundingClientRect(),i=e.getBoundingClientRect(),l=r.top-i.top+e.scrollTop,s=r.height;a.push({topRatio:l/t,heightRatio:s/t,msg:n,index:a.length})}}h(a)};let w=(0,o.useCallback)(()=>k.current(),[]);(0,o.useEffect)(()=>{let e=r.current;if(!e)return;e.addEventListener("scroll",w,{passive:!0});let t=new ResizeObserver(w);return t.observe(e),e.firstElementChild&&t.observe(e.firstElementChild),w(),()=>{e.removeEventListener("scroll",w),t.disconnect()}},[r,w]),(0,o.useEffect)(()=>{let e=setTimeout(w,50);return()=>clearTimeout(e)},[e.length,w]);let S=(0,o.useCallback)(e=>{let t=r.current;if(!t)return;let n=t.scrollHeight-t.clientHeight;n<=0||(t.scrollTop=Math.max(0,Math.min(1-a,e))/(1-a)*n)},[r,a]),C=(0,o.useCallback)(e=>{if(!c)return;v.current=!0;let t=e.currentTarget.getBoundingClientRect(),r=(e.clientY-t.top)/t.height,n=r-l*(1-a),o=n>=0&&n<=a?n:a/2;S(r-o);let i=e=>{v.current&&S((e.clientY-t.top)/t.height-o)},s=()=>{v.current=!1,window.removeEventListener("mousemove",i),window.removeEventListener("mouseup",s)};window.addEventListener("mousemove",i),window.addEventListener("mouseup",s)},[c,a,l,S]),T=y.current?.clientHeight??600,I=(0,o.useMemo)(()=>{if(!x||0===p.length)return[];let e=p.map(e=>Math.round(e.topRatio*T-11));for(let t=0;t<10;t++){for(let t=1;t<e.length;t++){let r=e[t-1]+22+2;e[t]<r&&(e[t]=r)}for(let t=e.length-2;t>=0;t--){let r=e[t+1]-22-2;e[t]>r&&(e[t]=r)}}for(let t=0;t<e.length;t++)e[t]=Math.max(0,Math.min(T-22,e[t]));return e},[x,p,T]);if(!c)return null;let z=l*(1-a)*100,M=100*a,L=null!==f&&p.length>0?p.reduce((e,t)=>Math.abs(t.topRatio-f)<Math.abs(p[e].topRatio-f)?t.index:e,0):null;return(0,n.jsxs)("div",{ref:y,onMouseDown:C,onMouseEnter:()=>g(!0),onMouseLeave:()=>{g(!1),m(null)},onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();m((e.clientY-t.top)/t.height)},style:{width:36,flexShrink:0,position:"relative",cursor:"default",userSelect:"none",borderLeft:"1px solid var(--border)",background:"var(--bg-panel)",overflow:"visible"},children:[(0,n.jsx)("div",{style:{position:"absolute",left:0,right:0,top:`${z}%`,height:`${M}%`,background:"rgba(100,100,100,0.1)",borderTop:"1px solid rgba(100,100,100,0.2)",borderBottom:"1px solid rgba(100,100,100,0.2)",pointerEvents:"none",zIndex:1}}),p.map(e=>{let t=t_(e.msg),r=x&&L===e.index,o="user"===e.msg.role,i=100*e.topRatio;return(0,n.jsx)("div",{style:{position:"absolute",top:`${i}%`,transform:"translateY(-50%)",left:0,right:0,height:"12px",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",zIndex:2},children:(0,n.jsx)("div",{style:{width:o?8:6,height:o?8:6,borderRadius:o?2:"50%",background:t.bg,border:`1.5px solid ${t.border}`,flexShrink:0,transition:"transform 0.1s",transform:r?"scale(1.6)":"scale(1)"}})},e.index)}),(0,n.jsx)("div",{style:{position:"absolute",left:"50%",top:0,bottom:0,width:1,background:"var(--border)",transform:"translateX(-50%)",zIndex:0}}),x&&p.map((e,t)=>{let r=function(e){if("user"===e.role){let t=e.content;return"string"==typeof t?t.slice(0,200):Array.isArray(t)?t.filter(e=>"text"===e.type&&e.text).map(e=>e.text).join("\n").slice(0,200):""}if("assistant"===e.role){let t=e.content??[],r=t.filter(e=>"text"===e.type).map(e=>e.text).join(" ");if(r)return r.slice(0,200);let n=t.filter(e=>"toolCall"===e.type).map(e=>e.toolName);if(n.length)return n.join(", ")}return""}(e.msg),o=t_(e.msg),i=L===e.index;return r&&0!==I.length?(0,n.jsx)("div",{style:{position:"absolute",top:I[t],right:"100%",marginRight:6,background:"var(--bg)",borderTop:`1px solid ${i?o.border:"var(--border)"}`,borderRight:`1px solid ${i?o.border:"var(--border)"}`,borderBottom:`1px solid ${i?o.border:"var(--border)"}`,borderLeft:`2px solid ${o.border}`,borderRadius:4,padding:"2px 7px",width:200,zIndex:100,pointerEvents:"none",opacity:i?1:.45,transition:"top 0.1s, opacity 0.1s"},children:(0,n.jsx)("div",{style:{fontSize:11,color:i?"var(--text)":"var(--text-muted)",lineHeight:1.4,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:r})},e.index):null})]})}function tq(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function tV(e){return"string"==typeof e&&e.trim()?e:void 0}function tJ(e){if(tq(e)){if("completed"in e)return"completed";if("failed"in e||"error"in e)return"failed";if("paused"in e||"blocked"in e)return"paused";if("not_found"in e)return"not_found";if("running"in e||"in_progress"in e||"pending"in e)return"running"}let t="string"==typeof e?e.toLowerCase().trim():"";return"completed"===t||"complete"===t||"done"===t||"success"===t||"succeeded"===t?"completed":"failed"===t||"failure"===t||"error"===t||"cancelled"===t||"canceled"===t?"failed":"paused"===t||"blocked"===t||"interrupted"===t?"paused":"not_found"===t||"not-found"===t||"missing"===t?"not_found":"pending"===t||"pending_init"===t||"starting"===t||"started"===t||"in_progress"===t||"running"===t?"running":"paused"}function tG(e){return"running"===e||"pending"===e}function tK(e){return(Array.isArray(e)?e:tq(e)?[e]:[]).filter(tq).map((e,t)=>({id:tV(e.id)??tV(e.threadId)??tV(e.thread_id)??`agent:${t}`,agent:tV(e.agent)??tV(e.agent_nickname)??"agent",status:tJ(e.status),role:tV(e.role)??tV(e.agent_role),task:tV(e.task)??tV(e.prompt),summary:tV(e.summary),threadId:tV(e.threadId)??tV(e.thread_id),parentThreadId:tV(e.parentThreadId)??tV(e.parent_thread_id),model:tV(e.model),reasoningEffort:tV(e.reasoningEffort)??tV(e.reasoning_effort),timestamp:"number"==typeof e.timestamp?e.timestamp:function(e){if("string"!=typeof e||!e)return;let t=Date.parse(e);return Number.isFinite(t)?t:void 0}(e.timestamp)}))}function tY(e,t="failed",r){return e?.length?e.map(e=>tG(e.status)?{...e,status:t,summary:e.summary??r,timestamp:Date.now()}:e):[]}function tZ(...e){let t=new Map;for(let r of e)for(let e of r??[]){let r=e.threadId?`thread:${e.threadId}`:`id:${e.id}`,n=t.get(r);t.set(r,{...n,...e,id:e.threadId??e.id,status:function(e,t){if(!e)return t;let r=tG(e),n=tG(t);return r&&!n?t:!r&&n?e:t}(n?.status,e.status),timestamp:Math.max(n?.timestamp??0,e.timestamp??0)||n?.timestamp||e.timestamp,summary:e.summary??n?.summary,task:e.task??n?.task,role:e.role??n?.role,threadId:e.threadId??n?.threadId})}return[...t.values()].sort((e,t)=>(t.timestamp??0)-(e.timestamp??0))}function tX(e){let t=new Map;for(let r of e){if("custom"===r.role&&"subagent-progress"===r.customType){let e=r.details;for(let r of tK(e?.runs))t.set(r.id,r)}if("custom"===r.role&&"subagent-notify"===r.customType&&"string"==typeof r.content){let e=r.content.match(/^Background task (completed|failed|paused):\s*\*\*(.+?)\*\*(?:\s+\((.+?)\))?/);if(e){let n=`bg-${e[2]}-${r.timestamp??""}`;t.set(n,{id:n,agent:e[2],status:e[1],task:e[3],summary:r.content.split("\n").slice(3).join("\n").trim()||void 0,timestamp:r.timestamp})}}if("assistant"===r.role){let e=r.content;if(!e)continue;for(let n of e)if("toolCall"===n.type&&"subagent"===n.toolName&&n.input){let e=n.input,o=e.agent??(e.chain?"chain":e.tasks?"parallel":e.action??"subagent"),i="string"==typeof e.task?e.task:void 0,l=n.toolCallId??`sub-${o}-${r.timestamp??Date.now()}`;t.set(l,{id:l,agent:o,status:"running",task:i,timestamp:r.timestamp})}}if("toolResult"===r.role&&r.toolCallId&&t.has(r.toolCallId)){let e=t.get(r.toolCallId);e.status=r.isError?"failed":"completed",e.summary=(r.content?.filter(e=>"text"===e.type).map(e=>e.text??"").join("\n")??"").slice(0,200)||void 0}}return Array.from(t.values()).sort((e,t)=>(t.timestamp??0)-(e.timestamp??0))}function tQ({messages:e,runs:t}){let r=(0,o.useMemo)(()=>tX(e??[]),[e]),i=(0,o.useMemo)(()=>tZ(r,t),[r,t]),l=i.filter(e=>tG(e.status)),s=i.filter(e=>!tG(e.status));return 0===i.length?null:(0,n.jsxs)("div",{style:{height:"100%",overflow:"auto",padding:12},children:[l.length>0&&(0,n.jsxs)("div",{style:{marginBottom:16},children:[(0,n.jsxs)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-dim)",marginBottom:8,textTransform:"uppercase",letterSpacing:"0.05em"},children:["Active (",l.length,")"]}),l.map(e=>(0,n.jsxs)("div",{style:{padding:"8px 12px",borderRadius:6,border:"1px solid rgba(99,102,241,0.2)",background:"rgba(99,102,241,0.04)",marginBottom:6,fontSize:12},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,n.jsx)("span",{style:{width:8,height:8,borderRadius:"50%",background:"#818cf8",display:"inline-block",animation:"pulse 1.5s infinite",flexShrink:0}}),(0,n.jsx)("span",{style:{fontWeight:600,color:"var(--text)"},children:e.agent}),e.role&&(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10},children:e.role}),(0,n.jsx)("span",{style:{color:"var(--accent)",fontSize:10,fontWeight:600},children:"running"})]}),e.task&&(0,n.jsx)("div",{style:{marginTop:4,color:"var(--text-muted)",fontSize:11,lineHeight:1.4},children:e.task.length>120?e.task.slice(0,120)+"…":e.task}),e.threadId&&(0,n.jsx)("div",{style:{marginTop:4,color:"var(--text-dim)",fontSize:10,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.threadId})]},e.id))]}),s.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-dim)",marginBottom:8,textTransform:"uppercase",letterSpacing:"0.05em"},children:["Completed (",s.length,")"]}),s.map(e=>(0,n.jsxs)("div",{style:{padding:"6px 12px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg-panel)",marginBottom:4,fontSize:12},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,n.jsx)("span",{style:{fontSize:12,flexShrink:0},children:"completed"===e.status?"✓":"failed"===e.status||"not_found"===e.status?"!":"paused"===e.status?"||":"..."}),(0,n.jsx)("span",{style:{fontWeight:600,color:"var(--text)"},children:e.agent}),e.role&&(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10},children:e.role}),(0,n.jsx)("span",{style:{color:"completed"===e.status?"#22c55e":"failed"===e.status||"not_found"===e.status?"#ef4444":"var(--text-dim)",fontSize:10,fontWeight:600},children:tJ(e.status)})]}),e.task&&(0,n.jsx)("div",{style:{marginTop:3,color:"var(--text-muted)",fontSize:11,lineHeight:1.4,maxHeight:44,overflow:"hidden"},children:e.task}),e.summary&&(0,n.jsx)("div",{style:{marginTop:3,color:"var(--text-muted)",fontSize:11,lineHeight:1.4,maxHeight:60,overflow:"hidden"},children:e.summary}),e.threadId&&(0,n.jsx)("div",{style:{marginTop:3,color:"var(--text-dim)",fontSize:10,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.threadId})]},e.id))]})]})}async function t0(e,t){let r=await fetch(`/api/agent/${encodeURIComponent(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),n=await r.json().catch(()=>({}));if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);if(n.sessionId&&n.data&&"object"==typeof n.data)return Array.isArray(n.data)?n.data:{...n.data,__sessionId:n.sessionId};return n.sessionId?{value:n.data,__sessionId:n.sessionId}:n.data}let t1="__annodexStreamSessions__",t2="__annodexStreamListeners__";function t4(e){return{sessionId:e,phase:"idle",startedAt:null,lastEventAt:null,lastHeartbeatAt:null,reconnectCount:0,lastSyncReason:null,accumulatedText:"",accumulatedThinking:"",fullThinking:"",toolCalls:[],toolResults:[],statusText:null,streamingMessage:null,isStreaming:!1,error:null}}function t5(){let e=globalThis;return e[t1]||(e[t1]=new Map),e[t1]}function t6(){let e=globalThis;return e[t2]||(e[t2]=new Map),e[t2]}let t3="__annodexStreamErrorCallbacks__";function t8(){let e=globalThis;return e[t3]||(e[t3]=new Map),e[t3]}function t7(e,t){for(let r of t6().get(e)??[])try{r(t)}catch{}}function t9(e){if(e.accumulatedThinking.trim()){var t;t=e.fullThinking,e.fullThinking=[t,e.accumulatedThinking].map(e=>e.trim()).filter(Boolean).join("\n\n---\n\n"),e.accumulatedThinking=""}e.thinkingPhaseEnded=!1}function re(e){e.textThrottleTimer&&(clearTimeout(e.textThrottleTimer),e.textThrottleTimer=null),e.textDirty&&(e.textDirty=!1,rr(e))}function rt(e,t=!1){let r=Date.now();if(e.snapshot.lastEventAt=r,!t){e.textDirty=!0,e.textThrottleTimer||(e.textThrottleTimer=setTimeout(()=>{e.textThrottleTimer=null,e.textDirty&&(e.textDirty=!1,rr(e))},100));return}re(e),rr(e)}function rr(e,t){let r=Date.now(),n=function(e){let t=[],r=e.accumulatedThinking.trim();for(let n of(r&&t.push({type:"thinking",thinking:r}),e.toolCalls.values()))t.push({type:"toolCall",toolCallId:n.toolCallId,toolName:n.toolName,input:n.input??{}});let n=e.accumulatedText.trim();return n&&t.push({type:"text",text:n}),t}(e),o=(t??e.snapshot.phase)==="active";e.snapshot={...e.snapshot,phase:t??e.snapshot.phase,lastEventAt:r,accumulatedText:e.accumulatedText,accumulatedThinking:e.accumulatedThinking,fullThinking:e.fullThinking,toolCalls:[...e.toolCalls.values()],toolResults:[...e.toolResults.values()],statusText:o?function(e){if(e.activeToolId){let t=e.toolCalls.get(e.activeToolId);if(t){let e=Math.max(0,Math.floor((Date.now()-t.startedAt)/1e3)),r=t.toolName||"tool";return`Running ${r}… (${e}s)`}}return e.accumulatedThinking.trim()?"Thinking…":e.accumulatedText.trim()?"Generating response…":e.toolCalls.size>0?"Finishing tool results…":null}(e):e.snapshot.statusText,streamingMessage:o&&(n.length>0||e.snapshot.startedAt)?{role:"assistant",content:n}:o?{role:"assistant",content:[]}:null,isStreaming:o},t7(e.snapshot.sessionId,{type:"snapshot-updated",snapshot:e.snapshot})}function rn(e){ro(e),e.idleCheckTimer=setInterval(()=>{let t=Math.max(e.snapshot.lastEventAt??0,e.snapshot.lastHeartbeatAt??0);if(Date.now()-t>=6e4){ri(e),re(e);let t="Stream idle timeout — no activity for 60s. The SSE connection may have dropped.";e.snapshot={...e.snapshot,phase:"error",isStreaming:!1,streamingMessage:null,statusText:null,error:t},ro(e),t7(e.snapshot.sessionId,{type:"error",snapshot:e.snapshot});let r=t8().get(e.snapshot.sessionId);if(r)try{r(e.snapshot.sessionId,t)}catch{}}},1e4)}function ro(e){e.idleCheckTimer&&(clearInterval(e.idleCheckTimer),e.idleCheckTimer=null)}function ri(e){e.toolProgressTimer&&(clearInterval(e.toolProgressTimer),e.toolProgressTimer=null)}function rl(e){let t=t5(),r=t.get(e);return r||(r={snapshot:t4(e),accumulatedText:"",accumulatedThinking:"",fullThinking:"",thinkingPhaseEnded:!1,toolCalls:new Map,toolResults:new Map,toolProgressTimer:null,activeToolId:null,textThrottleTimer:null,textDirty:!1,idleCheckTimer:null},t.set(e,r)),r}function rs(e){let t=t5().get(e);return t&&"idle"!==t.snapshot.phase?t.snapshot:null}function ra(e){let t=t5(),r=t.get(e);r&&(ri(r),ro(r),re(r)),t.delete(e)}function rd(e){let t=rl(e);if("active"===t.snapshot.phase)return rt(t,!0),rn(t),t.snapshot;let r=Date.now();return t.snapshot={...t4(e),phase:"active",startedAt:r,lastEventAt:r,isStreaming:!0,streamingMessage:{role:"assistant",content:[]}},rn(t),rt(t,!0),t.snapshot}var rc=r(79617),ru=r.n(rc);async function rp(e,t){if(!t.length)return[];let r=await fetch("/api/images/upload",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,images:t.map(e=>({data:e.data,mimeType:e.mimeType,name:e.name}))})}),n=await r.json().catch(()=>({}));if(!r.ok||n.error)throw Error(n.error??`Upload failed (HTTP ${r.status})`);return(n.uploaded??[]).map((e,r)=>({...e,previewUrl:t[r]?.previewUrl}))}async function rh(e,t){if(!t.length)return[];let r=await fetch("/api/attachments/upload",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:t.map(e=>({data:e.data,mimeType:e.mimeType,name:e.fileName}))})}),n=await r.json().catch(()=>({}));if(!r.ok||n.error)throw Error(n.error??`Upload failed (HTTP ${r.status})`);return n.uploaded??[]}var rx=r(92619).Buffer;function rg({startedAt:e}){let[t,r]=(0,o.useState)(0);return(0,o.useEffect)(()=>{r(0);let e=setTimeout(()=>r(1),5e3),t=setTimeout(()=>r(2),15e3);return()=>{clearTimeout(e),clearTimeout(t)}},[e]),(0,n.jsx)("span",{className:"animate-[pulse_1.5s_ease-in-out_infinite] text-[13px] text-text-muted",children:["Generating…","Waiting for response…","Still working…"][t]})}function rf({agentPhase:e,startedAt:t,statusText:r=null,hasContent:i=!1,reconnectCount:l=0,lastSyncReason:s=null,threadGoal:a=null}){let[d,c]=(0,o.useState)(0);(0,o.useEffect)(()=>{if(!t)return void c(0);let e=()=>c(Math.max(0,Math.floor((Date.now()-t)/1e3)));e();let r=setInterval(e,1e3);return()=>clearInterval(r)},[t]);let u=function(e,t){if(t)return t;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]}…`:`Running ${t.slice(0,2).join(", ")}${t.length>2?` (+${t.length-2})`:""}…`}return e?.kind==="waiting_model"?"Waiting for model…":"Working…"}(e,r),p=a?.status==="active"?"Toward goal":null,h=r?.match(/\((\d+)s\)/),x=h?parseInt(h[1],10):0,g=!i&&!r&&e?.kind==="waiting_model",f=[l>0?`reconnect \xd7${l}`:null,s?`sync: ${s}`:null].filter(e=>!!e);return(0,n.jsxs)("div",{className:"mb-2 flex flex-wrap items-center gap-x-3 gap-y-1 rounded-lg border border-[var(--border)] bg-[var(--bg-panel)] px-3 py-2 text-[12px] text-text-muted",role:"status","aria-live":"polite",children:[(0,n.jsxs)("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[p&&(0,n.jsx)("span",{className:"shrink-0 rounded bg-[rgba(37,99,235,0.12)] px-1.5 py-0.5 text-[10px] font-medium text-[var(--accent)]",children:p}),g?(0,n.jsx)(rg,{startedAt:t}):(0,n.jsx)("span",{className:"truncate text-[13px] text-text",children:u})]}),t&&(0,n.jsx)("span",{className:"shrink-0 tabular-nums text-[11px] font-medium text-[var(--accent)]",children:function(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);return`${t}m ${String(e%60).padStart(2,"0")}s`}(d)}),x>=60&&(0,n.jsx)("span",{className:`shrink-0 text-[11px] ${x>=90?"text-red-400":"text-amber-400"}`,children:x>=90?"Running longer than usual":"Taking a while"}),f.length>0&&(0,n.jsx)("span",{className:"shrink-0 text-[10px] opacity-60",children:f.join(" \xb7 ")})]})}function rm({goal:e,onClear:t,clearing:r=!1}){var i;let l=(0,o.useMemo)(()=>null==e.tokenBudget||e.tokenBudget<=0?null:Math.min(100,Math.round(e.tokensUsed/e.tokenBudget*100)),[e.tokenBudget,e.tokensUsed]);return(0,n.jsxs)("div",{className:"mb-4 rounded-[8px] border border-[rgba(37,99,235,0.22)] bg-[rgba(37,99,235,0.04)] px-3 py-2.5",role:"region","aria-label":"Thread goal",children:[(0,n.jsxs)("div",{className:"mb-1.5 flex items-center justify-between gap-2",children:[(0,n.jsxs)("div",{className:"flex min-w-0 items-center gap-2",children:[(0,n.jsx)("span",{className:"shrink-0 rounded px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-white",style:{background:function(e){switch(e){case"active":return"rgba(37,99,235,0.85)";case"complete":return"rgba(34,197,94,0.85)";case"blocked":return"rgba(239,68,68,0.85)";case"paused":default:return"rgba(148,163,184,0.85)";case"usageLimited":case"budgetLimited":return"rgba(245,158,11,0.85)"}}(e.status)},children:tw[i=e.status]??i}),(0,n.jsx)("span",{className:"truncate text-[11px] font-medium text-text-muted",children:"Goal"})]}),t&&(0,n.jsx)("button",{type:"button",onClick:()=>t(),disabled:r,className:"shrink-0 rounded px-2 py-0.5 text-[11px] text-text-muted transition hover:bg-[var(--bg-panel)] hover:text-text disabled:opacity-50",children:r?"清除中…":"清除"})]}),(0,n.jsx)("p",{className:"mb-2 whitespace-pre-wrap text-[13px] leading-relaxed text-text",children:e.objective}),(0,n.jsxs)("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-1 text-[11px] text-text-muted",children:[(0,n.jsxs)("span",{children:["已用时间 ",function(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m ${String(e%60).padStart(2,"0")}s`;let r=Math.floor(t/60);return`${r}h ${t%60}m`}(e.timeUsedSeconds)]}),(0,n.jsxs)("span",{children:["Tokens ",e.tokensUsed.toLocaleString(),null!=e.tokenBudget?` / ${e.tokenBudget.toLocaleString()}`:""]})]}),null!=l&&(0,n.jsx)("div",{className:"mt-2 h-1 overflow-hidden rounded-full bg-[var(--border)]",children:(0,n.jsx)("div",{className:"h-full rounded-full bg-[rgba(37,99,235,0.65)] transition-[width] duration-300",style:{width:`${l}%`}})})]})}function rv({tasks:e,onExecute:t,isRunning:r}){let[i,l]=(0,o.useState)(!1),s=(0,o.useCallback)(()=>{l(e=>!e)},[]);if(0===e.length)return null;let a=e.filter(e=>"completed"===e.status).length,d=e.some(e=>"inProgress"===e.status),c=a===e.length;return(0,n.jsxs)("div",{className:"mb-4 rounded-[8px] border border-[rgba(59,130,246,0.22)] bg-[rgba(59,130,246,0.04)] px-3 py-2.5",role:"region","aria-label":"Plan",children:[(0,n.jsxs)("div",{className:"flex cursor-pointer items-center justify-between gap-2",onClick:s,role:"button",tabIndex:0,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&s()},"aria-expanded":!i,children:[(0,n.jsxs)("div",{className:"flex min-w-0 items-center gap-2",children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#3b82f6",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M9 11l3 3L22 4"}),(0,n.jsx)("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]}),(0,n.jsxs)("span",{className:"text-[12px] font-medium",style:{color:"#3b82f6"},children:["Plan \xb7 ",e.length," 步"]}),d&&(0,n.jsx)("span",{className:"rounded px-1.5 py-0 text-[10px] font-semibold",style:{background:"rgba(59,130,246,0.12)",color:"#3b82f6"},children:"进行中"}),c&&!d&&(0,n.jsxs)("span",{className:"rounded px-1.5 py-0 text-[10px] font-semibold",style:{background:"rgba(34,197,94,0.12)",color:"rgba(34,197,94,0.85)"},children:["已完成 ",a,"/",e.length]})]}),(0,n.jsxs)("div",{className:"flex shrink-0 items-center gap-2",children:[t&&c&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),t()},disabled:r,className:"rounded px-2.5 py-1 text-[11px] font-medium text-white transition disabled:opacity-50",style:{background:r?"rgba(59,130,246,0.3)":"#3b82f6",cursor:r?"not-allowed":"pointer"},children:"执行计划"}),(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-muted)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:i?"rotate(-90deg)":"rotate(0deg)",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"6 9 12 15 18 9"})})]})]}),!i&&(0,n.jsx)("div",{className:"mt-2 space-y-1.5",children:e.map(e=>(0,n.jsxs)("div",{className:"flex items-start gap-2 rounded-[4px] px-2 py-1 transition",style:{background:"inProgress"===e.status?"rgba(59,130,246,0.04)":"transparent"},children:[(0,n.jsx)("div",{className:"mt-[1px]",children:function(e){switch(e){case"completed":return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"rgba(34,197,94,0.12)",stroke:"rgba(34,197,94,0.6)",strokeWidth:"1.5"}),(0,n.jsx)("path",{d:"M7 12.5l3 3 7-7",stroke:"rgba(34,197,94,0.9)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]});case"inProgress":return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0,animation:"spin 1.5s linear infinite"},children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"rgba(59,130,246,0.2)",strokeWidth:"2.5"}),(0,n.jsx)("path",{d:"M12 2a10 10 0 0 1 10 10",stroke:"rgba(59,130,246,0.85)",strokeWidth:"2.5",strokeLinecap:"round"})]});default:return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"rgba(148,163,184,0.3)",strokeWidth:"1.5"})})}}(e.status)}),(0,n.jsx)("span",{className:"text-[12px] leading-relaxed",style:function(e){switch(e){case"completed":return{color:"rgba(34,197,94,0.85)",textDecoration:"line-through"};case"inProgress":return{color:"#3b82f6",fontWeight:500};default:return{color:"var(--text-muted)"}}}(e.status),children:e.step})]},e.id))})]})}let ry=["annotate and analyze.","vibe code bioinformatics.","turn data into figures.","inspect your project.","trace reproducible workflows.","summarize that paper.","review the pipeline.","compare markers.","draft methods.","find the next analysis step."];function rb({phrases:e}){let[t,r]=(0,o.useState)(()=>Math.floor(Math.random()*e.length)),[i,l]=(0,o.useState)(""),[s,a]=(0,o.useState)(!1),[d,c]=(0,o.useState)(!0);return(0,o.useEffect)(()=>{let e=setInterval(()=>c(e=>!e),530);return()=>clearInterval(e)},[]),(0,o.useEffect)(()=>{let n,o=e[t];if(s||i!==o)if(s&&""===i)a(!1),r(t=>(t+1)%e.length);else{let e=s?o.slice(0,i.length-1):o.slice(0,i.length+1);n=setTimeout(()=>l(e),s?28:55)}else n=setTimeout(()=>a(!0),1800);return()=>clearTimeout(n)},[i,s,t,e]),(0,n.jsxs)("span",{style:{color:"var(--text-muted)",fontWeight:400},children:[i,(0,n.jsx)("span",{style:{opacity:+!!d,color:"var(--accent)",marginLeft:1},children:"▍"})]})}function rj({session:e,newSessionCwd:t,onAgentEnd:i,onSessionCreated:l,onSessionForked:s,onOpenImage:a,modelsRefreshKey:d,chatInputRef:c,onSystemPromptChange:p,onSessionStatsChange:h,onContextUsageChange:x,generativeUI:g,onOpenExtensionsSettings:f}){var m;let v,[y,b]=(0,o.useState)("code"),{data:j,loading:k,error:w,messages:S,entryIds:C,streamState:T,streamingProcessState:I,streamingToolResults:z,agentRunning:M,modelNames:L,modelList:R,modelThinkingLevels:E,modelThinkingLevelMaps:$,toolPreset:P,thinkingLevel:A,sandboxMode:B,enabledExtensions:N,availableExtensions:D,enabledExtensionDetails:O,retryInfo:H,contextUsage:F,forkingEntryId:_,isCompacting:U,compactError:q,threadGoal:V,goalError:J,goalSetting:G,goalClearing:K,displayModel:Y,sessionStats:Z,agentPhase:X,agentError:Q,subagentRuns:ee,pendingApproval:et,planTasks:er,isNew:en,messagesEndRef:eo,scrollContainerRef:ei,lastUserMsgRef:el,handleSend:es,handleAbort:ea,handleFork:ed,handleModelChange:ec,handleCompact:eu,handleAbortCompaction:ep,handleSetGoal:eh,handleClearGoal:ex,handleGoalInvalid:eg,handleToolPresetChange:ef,handleThinkingLevelChange:em,handleSandboxModeChange:ey,handleEnabledExtensionsChange:eb,handleResolveApproval:ej,handleAgentEventRef:ek}=function(e){let{session:t,newSessionCwd:n,onAgentEnd:i,onSessionCreated:l,onSessionForked:s,modelsRefreshKey:a,onSystemPromptChange:d,planMode:c}=e,u=t?.id??null,p=null===t&&null!==n,[h,x]=(0,o.useState)(null),[g,f]=(0,o.useState)(!p),[m,v]=(0,o.useState)(null),[y,b]=(0,o.useState)([]),[j,k]=(0,o.useState)([]),[w,S]=(0,o.useState)(u),C=function(e){let[t,r]=(0,o.useState)(()=>e?rs(e):null);return(0,o.useEffect)(()=>{var t;let n,o;return e?(r(rs(e)),t=e=>{r(e.snapshot)},(n=t6()).has(e)||n.set(e,new Set),n.get(e).add(t),(o=rs(e))&&t({type:"snapshot-updated",snapshot:o}),()=>{n.get(e)?.delete(t)}):void r(null)},[e]),t}(w),[T,I]=(0,o.useState)(!1),[z,M]=(0,o.useState)({}),[L,R]=(0,o.useState)([]),[E,$]=(0,o.useState)({}),[P,A]=(0,o.useState)({}),[B,N]=(0,o.useState)(null),[D,O]=(0,o.useState)("full"),[H,F]=(0,o.useState)("auto"),[_,U]=(0,o.useState)("danger-full-access"),[q,V]=(0,o.useState)([]),[J,G]=(0,o.useState)([]),[K,Y]=(0,o.useState)([]),[Z,X]=(0,o.useState)(null),[Q,ee]=(0,o.useState)(null),[et,er]=(0,o.useState)(null),[en,eo]=(0,o.useState)(null),[ei,el]=(0,o.useState)(null),[es,ea]=(0,o.useState)(null),[ed,ec]=(0,o.useState)(!1),[eu,ep]=(0,o.useState)(null),[eh,ex]=(0,o.useState)(null),[eg,ef]=(0,o.useState)(null),[em,ey]=(0,o.useState)(!1),[eb,ej]=(0,o.useState)(!1),[ek,ew]=(0,o.useState)(null),[eS,eC]=(0,o.useState)(null),[eT,eI]=(0,o.useState)([]),[ez,eM]=(0,o.useState)([]),[eL,eR]=(0,o.useState)(null),eW=(0,o.useRef)(null),eE=(0,o.useRef)(null),e$=(0,o.useRef)(1e3),eP=(0,o.useRef)(null),eA=(0,o.useRef)(t?.id??null),eB=(0,o.useRef)(!1),eN=(0,o.useRef)(!1),eD=(0,o.useRef)(null),eO=(0,o.useRef)(null),eH=(0,o.useRef)(!1),eF=(0,o.useRef)(null),e_=(0,o.useRef)(!1),eU=(0,o.useRef)(null),eq=(0,o.useRef)(null),eV=(0,o.useRef)(!1),eJ=e.setNewSessionModel??N,eG=e.setToolPreset??O,eK=ei??h?.context.model??es??null,eY=p?B:eK,eZ=(0,o.useCallback)(e=>e?.length?e.map((e,t)=>{let r=e.uploadedPath?`
|
|
252
|
-
Saved path: ${e.uploadedPath}`:"",n=`Attachment ${t+1}: ${e.fileName} (${e.mimeType||"application/octet-stream"}, ${e.size} bytes)${r}`;if(e.extractedText){let t=e.truncated?"\n[The extracted text was truncated before sending.]":"";return`${n}
|
|
253
|
-
${t}
|
|
254
|
-
${e.extractedText}`.trim()}return`${n}
|
|
255
|
-
[Text extraction unavailable: ${e.extractionError??"unsupported file type"}]`}).join("\n\n---\n\n"):"",[]),eX=(()=>{let e={input:0,output:0,cacheRead:0,cacheWrite:0},t=0;for(let r of y){if("assistant"!==r.role)continue;let n=r.usage;n&&(e.input+=n.input??0,e.output+=n.output??0,e.cacheRead+=n.cacheRead??0,e.cacheWrite+=n.cacheWrite??0,t+=n.cost?.total??0)}return e.input+e.output+e.cacheRead+e.cacheWrite>0?{tokens:e,cost:t}:null})(),eQ=h?.context.sessionStats??eX,e0=(0,o.useCallback)(async(e,t)=>{try{let r=await fetch(`/api/extensions${t?`?cwd=${encodeURIComponent(t)}`:""}`,{cache:"no-store"}),n=await r.json().catch(()=>({}));if(!r.ok)throw Error(n.error??`HTTP ${r.status}`);let o=n.extensions??[];G(o);let i=new Map(o.map(e=>[e.id,e]));Y(e.map(e=>i.get(e)??{id:e,name:e,transport:{type:"stdio"}}).filter(e=>!!e))}catch{G([]),Y(e.map(e=>({id:e,name:e,transport:{type:"stdio"}})))}},[]),e1=(0,o.useCallback)(async e=>{try{await t0(e,{type:"set_sandbox_mode",mode:"danger-full-access"}),U("danger-full-access")}catch(e){console.error("Failed to force sandbox mode to danger-full-access:",e)}},[]),[e2,e4]=(0,o.useState)(null);(0,o.useEffect)(()=>{T?e4(e=>e??Date.now()):e4(null)},[T]);let e5=(0,o.useMemo)(()=>({isStreaming:T||!!C?.isStreaming,streamingMessage:C?.streamingMessage??(T?{role:"assistant",content:[]}:null)}),[T,C]),e6=(0,o.useMemo)(()=>{if(C)return{thinkingBlocks:C.accumulatedThinking.trim()?[{content:C.accumulatedThinking}]:C.fullThinking.trim()?[{content:C.fullThinking}]:[],toolCalls:C.toolCalls.map(e=>({type:"toolCall",toolCallId:e.toolCallId,toolName:e.toolName,input:e.input??{}})),startedAt:C.startedAt,lastEventAt:C.lastEventAt,reconnectCount:C.reconnectCount,lastSyncReason:C.lastSyncReason,statusText:C.statusText};return T?{thinkingBlocks:[],toolCalls:[],startedAt:e2,lastEventAt:null,reconnectCount:0,lastSyncReason:null,statusText:null}:{thinkingBlocks:[],toolCalls:[],startedAt:null,lastEventAt:null,reconnectCount:0,lastSyncReason:null,statusText:null}},[T,e2,C]),e3=(0,o.useCallback)(async(e,r=!1,o=!1,i)=>{try{var l;r&&f(!0);let s=o?`/api/sessions/${encodeURIComponent(e)}?includeState`:`/api/sessions/${encodeURIComponent(e)}`,a=await fetch(s);if(404===a.status)return r&&(x(null),b([]),v(null)),null;if(!a.ok)throw Error(`HTTP ${a.status}`);let d=await a.json();if(x(d),!i?.skipMessages){let e=eD.current,t=function(e,t,r){if(!t)return e;let n=W(t);return!n||e.some(e=>"user"===e.role&&W(e)===n)?e:r?[...e,t]:e}(d.context.messages,e,eN.current);e&&W(e)&&d.context.messages.some(t=>"user"===t.role&&W(t)===W(e))&&(eD.current=null),b(t),k(d.context.entryIds??[])}eI(d.agentState?.running?d.context.subagentRuns??[]:(l=d.context.subagentRuns,tY(l,"paused"))),d.agentState?.state?.contextUsage||void 0===d.context.contextUsage||ee(d.context.contextUsage??null);let c=d.agentState?.state?.enabledExtensions??[];return V(c),e0(c,d.info?.cwd??t?.cwd??n??null),el(null),v(null),d.agentState?.state?.threadGoal!==void 0&&ex(d.agentState.state.threadGoal??null),!d.agentState?.state?.thinkingLevel&&d.context.thinkingLevel&&"off"!==d.context.thinkingLevel&&F(d.context.thinkingLevel),U("danger-full-access"),d.agentState??null}catch(e){return v(String(e)),null}finally{r&&f(!1)}},[n,t?.cwd,e0]),e8=(0,o.useCallback)(async e=>{try{let t=await t0(e,{type:"get_tools"});if(t){let{getPresetFromTools:e}=await r.e(8451).then(r.bind(r,48451));eG(e(t))}}catch(e){console.error("Failed to load tools:",e)}},[eG]),e7=(0,o.useCallback)(async e=>{try{let t=await t0(e,{type:"goal_get"});ex(t?.goal??null)}catch{}},[]),e9=(0,o.useCallback)(e=>{eP.current&&eP.current!==e||(eW.current?.close(),eW.current=null,eP.current=null)},[]),te=(0,o.useCallback)(async(e,t,r=!1)=>{try{let n;await e3(e,!1,r,{skipMessages:!1}),e&&(n=t5().get(e))&&(n.snapshot={...n.snapshot,lastSyncReason:t,lastEventAt:Date.now()},rt(n,!0))}catch(e){console.error(`Failed to reconcile session (${t}):`,e)}},[e3]),tt=(0,o.useCallback)(e=>{eW.current&&(eW.current.close(),eW.current=null),eP.current=null;let t=new EventSource(`/api/agent/${encodeURIComponent(e)}/events`);eW.current=t,eP.current=e,t.onmessage=e=>{try{let t=JSON.parse(e.data);eO.current?.(t)}catch{}},t.onerror=()=>{if(eW.current===t&&eB.current){t.close(),eW.current=null,eP.current=null,eE.current&&clearTimeout(eE.current);let r=e$.current,n=Math.min(3e4,r>=1e3?2*r:1e3);e$.current=n,eE.current=setTimeout(()=>{if(eE.current=null,eB.current){let t;(t=t5().get(e))&&(t.snapshot={...t.snapshot,reconnectCount:t.snapshot.reconnectCount+1,lastSyncReason:"sse-reconnect",lastEventAt:Date.now()},rt(t,!0)),tt(e),te(e,"sse-reconnect",!0)}},n)}}},[te]),tr=(0,o.useRef)(new Set),tn=(0,o.useCallback)((e,t=5e3,r=!1)=>new Promise((n,o)=>{let i=Date.now(),l=!1,s=t=>{if(!l){if(l=!0,t)return void n();eP.current===e&&(eW.current?.close(),eW.current=null,eP.current=null),tr.current.delete(e),o(Error(`Timed out waiting for agent event stream for session ${e}`))}},a=()=>{if(l)return;let n=eP.current===e&&eW.current?.readyState===EventSource.OPEN;!r&&n||r&&n&&tr.current.has(e)?s(!0):Date.now()-i>=t?s(!1):setTimeout(a,50)};tt(e),tr.current.delete(e),a()}),[tt]),to=(0,o.useCallback)(async()=>{let e=eA.current??t?.id;if(e)return e;if(!p||!n)throw Error("请先创建会话后再设置 goal");B&&ea(B);let{PRESET_NONE:o,PRESET_DEFAULT:i,PRESET_FULL:s}=await r.e(8451).then(r.bind(r,48451)),a="none"===D?o:"default"===D?i:s,d=await fetch("/api/agent/new",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:n,toolNames:a,...B?{provider:B.provider,modelId:B.modelId}:{},..."auto"!==H?{thinkingLevel:H}:{},sandboxMode:_})}),c=await d.json().catch(()=>({}));if(!d.ok||c.error||!c.sessionId)throw Error(c.error??`HTTP ${d.status}`);let u=c.sessionId;return eA.current=u,await tn(u,1e4,!0),eV.current=!0,l?.({id:u,path:"",cwd:n,name:void 0,created:new Date().toISOString(),modified:new Date().toISOString(),messageCount:0,firstMessage:""}),u},[p,n,B,l,_,t?.id,H,D,tn]),ti=(0,o.useCallback)(async e=>{if(!em){ef(null),ey(!0);try{let t=await to(),r=await t0(t,{type:"goal_set",objective:e});r?.goal&&ex(r.goal)}catch(e){ef(e instanceof Error?e.message:String(e))}finally{ey(!1)}}},[to,em]),tl=(0,o.useCallback)(async()=>{let e=eA.current??t?.id;if(e&&!eb){ef(null),ej(!0);try{await t0(e,{type:"goal_clear"}),ex(null)}catch(e){ef(e instanceof Error?e.message:String(e))}finally{ej(!1)}}},[eb,t?.id]),ts=(0,o.useCallback)(e=>{ef(e)},[]);(0,o.useEffect)(()=>{eB.current=T},[T]),eO.current=(0,o.useCallback)(e=>{let t=eA.current;switch(t&&function(e,t){let r=rl(e),n=Date.now();switch(t.type){case"agent_start":if("active"===r.snapshot.phase)return rt(r,!0),r.snapshot;return ri(r),r.accumulatedText="",r.accumulatedThinking="",r.fullThinking="",r.thinkingPhaseEnded=!1,r.toolCalls.clear(),r.toolResults.clear(),r.activeToolId=null,r.snapshot={...t4(e),phase:"active",startedAt:n,lastEventAt:n,isStreaming:!0,streamingMessage:{role:"assistant",content:[]}},rn(r),rt(r,!0),r.snapshot;case"message_update":{let e=t.message;if(!e||"assistant"!==e.role)return r.snapshot;let o=e.content;for(let e of Array.isArray(o)?o:[])if("object"==typeof e&&null!==e&&"type"in e)if("thinking"===e.type){let t=e.thinking??"";r.thinkingPhaseEnded&&t9(r),r.accumulatedThinking=t}else"text"===e.type?(t9(r),r.thinkingPhaseEnded=!0,r.accumulatedText=e.text??""):"toolCall"===e.type&&(t9(r),r.thinkingPhaseEnded=!0,e.toolCallId&&!r.toolCalls.has(e.toolCallId)&&r.toolCalls.set(e.toolCallId,{...e,startedAt:n}));return rt(r,!1),r.snapshot}case"tool_execution_start":{let e="string"==typeof t.toolCallId?t.toolCallId:"",o="string"==typeof t.toolName?t.toolName:"tool",i=t.input??{};if(!e)return r.snapshot;t9(r),r.thinkingPhaseEnded=!0;let l=r.toolCalls.get(e);return r.toolCalls.set(e,{type:"toolCall",toolCallId:e,toolName:o,input:l?.input??i,startedAt:l?.startedAt??n}),r.activeToolId=e,ri(r),r.activeToolId&&(r.toolProgressTimer=setInterval(()=>rt(r,!0),1e3)),rt(r,!0),r.snapshot}case"tool_execution_end":{let e="string"==typeof t.toolCallId?t.toolCallId:"",o="string"==typeof t.toolName?t.toolName:"tool",i="string"==typeof t.result?t.result:JSON.stringify(t.result??"");if(e){let l=r.toolCalls.get(e);l&&r.toolCalls.set(e,{...l,endedAt:n}),r.toolResults.set(e,{role:"toolResult",toolCallId:e,toolName:o,content:[{type:"text",text:i}],isError:!!t.isError,timestamp:n}),r.activeToolId===e&&(r.activeToolId=null,ri(r))}return rt(r,!0),r.snapshot}case"message_end":return re(r),rt(r,!0),r.snapshot;case"agent_end":{re(r),ri(r),ro(r);let n="string"==typeof t.error?t.error:null;return r.activeToolId=null,r.snapshot={...r.snapshot,phase:n?"error":"completed",isStreaming:!1,streamingMessage:null,statusText:null,error:n},t7(e,n?{type:"error",snapshot:r.snapshot}:{type:"completed",snapshot:r.snapshot}),r.snapshot}case"heartbeat":return r.snapshot={...r.snapshot,lastHeartbeatAt:n},r.snapshot;default:return r.snapshot}}(t,e),e.type){case"connected":{e$.current=1e3;let t="string"==typeof e.sessionId?e.sessionId:null;t&&(tr.current.add(t),S(t),eA.current&&t!==eA.current&&(eA.current=t,s?.(t)));break}case"agent_start":eC(null),I(!0),eB.current=!0,ew({kind:"waiting_model"}),t&&S(t);break;case"agent_end":{let r="string"==typeof e.error?e.error:null;I(!1),eB.current=!1,ew(null),X(null),eR(null),eC(r),eI(e=>tY(e,r?"failed":"paused",r??void 0)),t&&ra(t),eA.current&&(te(eA.current,"agent-end",!0),fetch(`/api/agent/${encodeURIComponent(eA.current)}`).then(e=>e.json()).then(e=>{e.state?.contextUsage!==void 0&&ee(e.state.contextUsage??null),e.state?.systemPrompt!==void 0&&er(e.state.systemPrompt??null)}).catch(()=>{})),i?.();break}case"plan_update":{let t=e.plan;t&&eM(t);break}case"message_start":case"message_update":ew(null);break;case"message_end":ew({kind:"waiting_model"});break;case"tool_execution_start":{let t=e.toolCallId,r=e.toolName;ew(e=>{let n=e?.kind==="running_tools"?[...e.tools]:[];return n.some(e=>e.id===t)||n.push({id:t,name:r}),{kind:"running_tools",tools:n}});break}case"approval_request":{let t="string"==typeof e.requestId?e.requestId:"",r="string"==typeof e.method?e.method:"";t&&r&&eR({requestId:t,method:r,params:e.params});break}case"approval_resolved":{let t="string"==typeof e.requestId?e.requestId:"";eR(e=>e?.requestId===t?null:e);break}case"tool_execution_end":{let t=e.toolCallId;ew(e=>{if(e?.kind!=="running_tools")return e;let r=e.tools.filter(e=>e.id!==t);return 0===r.length?{kind:"waiting_model"}:{kind:"running_tools",tools:r}});break}case"subagent_progress":{let t=tK(e.runs);t.length>0&&eI(e=>{let r=tZ(e,t),n=r.filter(e=>tG(e.status));return n.length>0?ew({kind:"running_tools",tools:n.map(e=>({id:e.id,name:e.agent}))}):eB.current&&ew({kind:"waiting_model"}),r});break}case"auto_retry_start":X({attempt:e.attempt,maxAttempts:e.maxAttempts,errorMessage:e.errorMessage});break;case"auto_retry_end":X(null);break;case"auto_compaction_start":case"compaction_start":ec(!0),ep(null);break;case"auto_compaction_end":case"compaction_end":ec(!1),e.errorMessage?ep(e.errorMessage):!e.aborted&&eA.current&&e3(eA.current);break;case"goal_updated":{var r;let t=(r=e.goal)&&"object"==typeof r?"string"!=typeof r.threadId||"string"!=typeof r.objective||"string"!=typeof r.status?null:{threadId:r.threadId,objective:r.objective,status:r.status,tokenBudget:"number"==typeof r.tokenBudget?r.tokenBudget:(r.tokenBudget,null),tokensUsed:"number"==typeof r.tokensUsed?r.tokensUsed:0,timeUsedSeconds:"number"==typeof r.timeUsedSeconds?r.timeUsedSeconds:0,createdAt:"number"==typeof r.createdAt?r.createdAt:0,updatedAt:"number"==typeof r.updatedAt?r.updatedAt:0}:null;t&&ex(t);break}case"goal_cleared":ex(null)}},[e3,i,s,te]);let ta=(0,o.useCallback)(async(e,o,i)=>{if(!e.trim()&&!o?.length&&!i?.length||T||eN.current)return;if(!o?.length&&!i?.length){let t=tk(e.trim());if(t?.kind==="invalid")return void ts(t.reason);if(t?.kind==="clear")return void await tl();if(t?.kind==="set")return void await ti(t.objective)}let a=h?.info?.cwd??t?.cwd??n??null,d=!!o?.length,u=!!i?.length;if((d||u)&&!a)return void eC("Cannot attach files without a project directory.");let x=[];if(o?.length)try{x=await rp(a,o)}catch(e){eC(e instanceof Error?e.message:String(e));return}let g=[];if(i?.length)try{g=await rh(a,i.map(e=>({data:rx.from(e.data).toString("base64"),mimeType:e.mimeType||"application/octet-stream",fileName:e.fileName})))}catch(e){eC(e instanceof Error?e.message:String(e));return}let f=eZ(i?.map((e,t)=>({...e,uploadedPath:g[t]?.path}))),m=function(e){if(!e.length)return"";let t=e.map((e,t)=>{let r=e.name??ru().basename(e.path);return`[User attached image ${t+1}: ${e.path} (${r})]`});return`
|
|
256
|
-
|
|
257
|
-
${t.join("\n")}`}(x),v=e.trim()?f?`${e}
|
|
258
|
-
|
|
259
|
-
Attached document text:
|
|
260
|
-
|
|
261
|
-
${f}`:e:f?`Attached document text:
|
|
262
|
-
|
|
263
|
-
${f}`:"",y=`${v}${m}`.trim()||v,j=x.map(e=>{var t;return{type:"image",path:e.path,mimeType:e.mimeType,name:e.name,source:{type:"url",url:(t=e.path,`/api/files/${ev(t)}?type=read`),media_type:e.mimeType}}}),k={role:"user",content:j.length?[{type:"text",text:y||" "},...j]:y,timestamp:Date.now()};eN.current=!0,eD.current=k,b(e=>{let t=W(k);return t&&e.some(e=>"user"===e.role&&W(e)===t)?e:[...e,k]}),eC(null),eB.current=!0,I(!0),ew({kind:"waiting_model"});let w=t?.id??eA.current;w&&(S(w),rd(w)),e_.current=!0;let C=x.map(e=>({type:"image",path:e.path,mimeType:e.mimeType,name:e.name})),z=e=>{S(e),rd(e),eB.current||(eB.current=!0,I(!0),ew({kind:"waiting_model"}))};try{if(p&&n){B&&ea(B);let{PRESET_NONE:t,PRESET_DEFAULT:o,PRESET_FULL:i}=await r.e(8451).then(r.bind(r,48451)),s="none"===D?t:"default"===D?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"!==H?{thinkingLevel:H}:{},sandboxMode:_,..."plan"===c?{mode:"plan"}:{}})}),d=await a.json().catch(()=>({}));if(!a.ok||d.error||!d.sessionId)throw Error(d.error??`HTTP ${a.status}`);let u=d.sessionId;eA.current=u,await tn(u,1e4,!0),z(u),await t0(u,{type:"prompt",message:y,toolNames:s,...C.length?{images:C}:{}}),eV.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)),i="none"===D?e:"default"===D?n:o;await tn(t.id,1e4,!0),z(t.id);let l=await t0(t.id,{type:"prompt",message:y,toolNames:i,...C.length?{images:C}:{}});l?.__sessionId&&l.__sessionId!==t.id&&(eA.current=l.__sessionId,tt(l.__sessionId),s?.(l.__sessionId))}}catch(r){console.error("Failed to send message:",r);let e=r instanceof Error?r.message:String(r);eC(`Send failed: ${e}`),I(!1),eB.current=!1,ew(null);let t=eD.current;t&&(b(e=>e.filter(e=>e!==t)),eD.current=null)}finally{eN.current=!1}},[p,n,B,D,H,_,t,T,tn,l,s,tt,eZ,tl,ts,ti,c]),td=(0,o.useCallback)(async()=>{let e=eA.current;if(e){eB.current=!1,eC(null),I(!1),ew(null),eR(null),eI(e=>tY(e,"paused","Aborted by user.")),e&&ra(e),eW.current?.close(),eW.current=null,eP.current=null;try{await t0(e,{type:"abort"}),await e3(e)}catch(t){console.error("Failed to abort:",t),await e3(e)}}},[e3]),tc=(0,o.useCallback)(async e=>{let t=eA.current;if(t){eo(e);try{let{cancelled:r,newSessionId:n}=await t0(t,{type:"fork",entryId:e})??{};!r&&n&&s?.(n)}catch(e){console.error("Fork failed:",e)}finally{eo(null)}}},[s]),tu=(0,o.useCallback)(async(e,t)=>{if(p)return void eJ({provider:e,modelId:t});let r=eA.current;if(r)try{let n=await t0(r,{type:"set_model",provider:e,modelId:t}),o=n.newSessionId??n.__sessionId;o&&o!==r&&(eA.current=o,s?.(o)),el({provider:n?.provider??e,modelId:n?.id??t})}catch(e){console.error("Failed to set model:",e)}},[p,s,eJ]),tp=(0,o.useCallback)(async()=>{let e=eA.current;if(e&&!ed){ec(!0),ep(null);try{await t0(e,{type:"compact"}),await e3(e,!0)}catch(e){ep(e instanceof Error?e.message:String(e))}finally{ec(!1)}}},[ed,e3]),th=(0,o.useCallback)(async()=>{let e=eA.current;if(e)try{await t0(e,{type:"abort_compaction"})}catch(e){console.error("Failed to abort compaction:",e)}},[]),tx=(0,o.useCallback)(async e=>{if(F(e),"auto"===e)return;let t=eA.current;if(t)try{await t0(t,{type:"set_thinking_level",level:e})}catch(e){console.error("Failed to set thinking level:",e)}},[]),tg=(0,o.useCallback)(async e=>{U(e);let t=eA.current;if(t&&!p)try{await t0(t,{type:"set_sandbox_mode",mode:e})}catch(e){console.error("Failed to set sandbox mode:",e)}},[p]),tf=(0,o.useCallback)(async e=>{let r=[...new Set(e.filter(Boolean))].sort();V(r),e0(r,h?.info?.cwd??t?.cwd??n??null);let o=eA.current;if(o&&!p)try{await fetch("/api/extensions/session",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:o,enabledExtensions:r})})}catch(e){console.error("Failed to set enabled extensions:",e)}},[h?.info?.cwd,p,n,t?.cwd,e0]),tm=(0,o.useCallback)(async(e,t,r)=>{let n=eA.current;n&&(await t0(n,{type:"resolve_approval",requestId:e,decision:t,...r?.permissions!==void 0?{permissions:r.permissions}:{},...r?.scope?{scope:r.scope}:{}}),eR(t=>t?.requestId===e?null:t))},[]),tv=(0,o.useCallback)(async e=>{let{PRESET_NONE:t,PRESET_DEFAULT:n,PRESET_FULL:o}=await r.e(8451).then(r.bind(r,48451));eG(e);let i=eA.current;if(i)try{await t0(i,{type:"set_tools",toolNames:"none"===e?t:"default"===e?n:o})}catch(e){console.error("Failed to set tools:",e)}},[eG]),ty=(0,o.useCallback)((e="smooth")=>{eU.current?.scrollIntoView({behavior:e})},[]),tb=(0,o.useCallback)(()=>{let e=eq.current,t=eF.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)(()=>{u&&S(u)},[u]),(0,o.useEffect)(()=>{var e;let r,o;return eV.current?(eV.current=!1,()=>{u&&e9(u)}):(u&&(eA.current=u,e3(u,!0,!0).then(e=>{if(e?.running?(e1(u),e8(u),I(!0),ew({kind:"waiting_model"}),S(u),rd(u),tt(u),te(u,"resume-running",!0)):e1(u),e?.state){if(void 0!==e.state.isCompacting&&ec(e.state.isCompacting),void 0!==e.state.contextUsage&&ee(e.state.contextUsage??null),void 0!==e.state.systemPrompt&&er(e.state.systemPrompt??null),void 0!==e.state.thinkingLevel&&F(e.state.thinkingLevel??"auto"),void 0!==e.state.sandboxMode&&U(e.state.sandboxMode??"danger-full-access"),void 0!==e.state.enabledExtensions){let r=e.state.enabledExtensions??[];V(r),e0(r,h?.info?.cwd??t?.cwd??n??null)}void 0!==e.state.threadGoal?ex(e.state.threadGoal??null):e7(u)}else e7(u)})),u&&(e=(e,t)=>{eB.current=!1,I(!1),ew(null),eC(t),fetch(`/api/agent/${encodeURIComponent(u)}`).then(e=>e.json().catch(()=>({}))).then(e=>{e.state?.contextUsage!==void 0&&ee(e.state.contextUsage??null)}).catch(()=>{})},(o=t8()).set(u,e),r=()=>{o.get(u)===e&&o.delete(u)}),()=>{u&&e9(u),r?.()})},[u,e9,tt,h?.info?.cwd,e1,e3,e8,n,te,e7,t?.cwd,e0]),(0,o.useEffect)(()=>{d?.(et)},[et,d]),(0,o.useEffect)(()=>{y.length>0&&(e_.current?(e_.current=!1,eH.current=!0,tb()):eH.current?eB.current||ty("smooth"):(eH.current=!0,ty("instant")))},[y.length,T,ty,tb]),(0,o.useEffect)(()=>{fetch("/api/models").then(e=>e.json()).then(e=>{if(M(e.models),e.thinkingLevels&&$(e.thinkingLevels),e.thinkingLevelMaps&&A(e.thinkingLevelMaps),e.modelList&&(R(e.modelList),p)){let t=e.defaultModel,r=t&&e.modelList.find(e=>e.id===t.modelId&&e.provider===t.provider);eJ(r?{provider:r.provider,modelId:r.id}:t??null)}}).catch(()=>{})},[p,a,eJ]),(0,o.useEffect)(()=>{p&&fetch("/api/settings").then(e=>e.json()).then(()=>{U("danger-full-access")}).catch(()=>{})},[p]),(0,o.useEffect)(()=>{if(!eu)return;let e=setTimeout(()=>ep(null),3e3);return()=>clearTimeout(e)},[eu]),(0,o.useEffect)(()=>{if(!eg)return;let e=setTimeout(()=>ef(null),4e3);return()=>clearTimeout(e)},[eg]),(0,o.useEffect)(()=>{ex(null),eI([])},[u]),(0,o.useEffect)(()=>()=>{eE.current&&clearTimeout(eE.current)},[]),(0,o.useEffect)(()=>{if(!T||!eA.current)return;let e=eA.current,t=setInterval(()=>{te(e,"running-reconcile",!1)},1e4);return()=>clearInterval(t)},[T,te]),{data:h,loading:g,error:m,messages:y,entryIds:j,streamState:e5,streamingProcessState:e6,streamingToolResults:(0,o.useMemo)(()=>{let e=new Map;for(let t of C?.toolResults??[])e.set(t.toolCallId,t);return e},[C]),agentRunning:T,modelNames:z,modelList:L,modelThinkingLevels:E,modelThinkingLevelMaps:P,newSessionModel:B,toolPreset:D,thinkingLevel:H,sandboxMode:_,enabledExtensions:q,availableExtensions:J,enabledExtensionDetails:K,retryInfo:Z,contextUsage:Q,systemPrompt:et,forkingEntryId:en,isCompacting:ed,compactError:eu,threadGoal:eh,goalError:eg,goalSetting:em,goalClearing:eb,currentModel:eK,displayModel:eY,sessionStats:eQ,agentPhase:ek,agentError:eS,subagentRuns:eT,pendingApproval:eL,planTasks:ez,isNew:p,sessionIdRef:eA,eventSourceRef:eW,messagesEndRef:eU,scrollContainerRef:eq,lastUserMsgRef:eF,pendingScrollToUserRef:e_,initialScrollDoneRef:eH,handleSend:ta,handleAbort:td,handleFork:tc,handleModelChange:tu,handleCompact:tp,handleAbortCompaction:th,handleSetGoal:ti,handleClearGoal:tl,handleGoalInvalid:ts,handleToolPresetChange:tv,handleThinkingLevelChange:tx,handleSandboxModeChange:tg,handleEnabledExtensionsChange:tf,handleResolveApproval:tm,loadTools:e8,setData:x,setMessages:b,setAgentRunning:I,setForkingEntryId:eo,handleAgentEventRef:eO}}({session:e,newSessionCwd:t,onAgentEnd:i,onSessionCreated:l,onSessionForked:s,modelsRefreshKey:d,onSystemPromptChange:p,planMode:y}),{soundEnabled:ew,onSoundToggle:eS,playDoneSound:eC}=function(){let[e,t]=(0,o.useState)(()=>{let e=localStorage.getItem("annodex-sound-enabled");return null===e||"true"===e}),r=(0,o.useRef)(e);(0,o.useEffect)(()=>{r.current=e},[e]);let n=(0,o.useRef)(null),i=(0,o.useCallback)(()=>{n.current||(n.current=new AudioContext);let e=n.current;return"suspended"===e.state&&e.resume(),e},[]);return{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=i(),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(.4,l+.02),i.gain.exponentialRampToValueAtTime(.001,l+.45),o.start(l),o.stop(l+.45)})}catch{}},[i]),soundEnabledRef:r}}(),eT=(0,o.useRef)(eC);eT.current=eC;let eI=(0,o.useRef)(ew);eI.current=ew;let ez=ek.current;(0,o.useEffect)(()=>{ek.current=e=>{"agent_end"===e.type&&eI.current&&eT.current(),ez?.(e)}},[ez,ek]);let eM=Z?`${Z.tokens.input}|${Z.tokens.output}|${Z.tokens.cacheRead}|${Z.tokens.cacheWrite}|${Z.cost??0}`:null,eL=(0,o.useRef)(Z);eL.current=Z,(0,o.useEffect)(()=>{h?.(eL.current)},[eM,h]),(0,o.useEffect)(()=>()=>{h?.(null)},[h]);let eR=F?`${F.percent??"null"}|${F.contextWindow}|${F.tokens??"null"}`:null,eW=(0,o.useRef)(F);eW.current=F,(0,o.useEffect)(()=>{x?.(eW.current)},[eR,x]),(0,o.useEffect)(()=>()=>{x?.(null)},[x]);let{isDragOver:eE,handleDragEnter:e$,handleDragOver:eP,handleDragLeave:eA,handleDrop:eB}=tz((0,o.useCallback)(e=>{c?.current?.addFiles(e)},[c])),eN=S.filter(e=>"user"===e.role||"assistant"===e.role),eD=(m=eN.length,(v=(0,o.useRef)([])).current=Array(m).fill(null).map((e,t)=>v.current[t]??null),v),eO=en&&0===S.length&&!T.isStreaming&&!M,eH=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}(),[eF,e_]=(0,o.useState)(!1),eU=tZ(ee,tX(S)),eq=eU.filter(e=>tG(e.status)).length,eV=eq>0;(0,o.useEffect)(()=>{!eV&&eF&&e_(!1)},[eV,eF]),(0,o.useEffect)(()=>{eH&&eF&&e_(!1)},[eH,eF]);let eJ=(0,o.useCallback)(e=>{"plan"===e&&M||b(e)},[M]),eG=(0,o.useCallback)(()=>{b("code"),es("同意,请落地")},[es]),eK=Y?E[`${Y.provider}:${Y.modelId}`]??null:null,eY=e?.id??t??"new-chat",eZ=(0,o.useMemo)(()=>(function(e){let t=[];for(let r=e.length-1;r>=0;r-=1){let n=e[r];if("user"!==n.role)continue;let o=n.text.trim();o&&t.push(o)}return t})(eN.map(e=>({role:e.role,text:W(e)}))),[eN]),eX=Y?$[`${Y.provider}:${Y.modelId}`]??null:null,eQ=(0,n.jsx)(tF,{ref:c,onSend:es,onAbort:ea,isStreaming:M,model:Y,modelNames:L,modelList:R,onModelChange:ec,onCompact:e||en?eu:void 0,onAbortCompaction:ep,isCompacting:U,compactError:q,onSetGoal:e||en?eh:void 0,onClearGoal:e||en?ex:void 0,onGoalInvalid:e||en?eg:void 0,goalError:J,toolPreset:P,onToolPresetChange:e||en?ef:void 0,thinkingLevel:A,onThinkingLevelChange:e||en?em:void 0,availableThinkingLevels:eK,thinkingLevelMap:eX,sandboxMode:B,onSandboxModeChange:e||en?ey:void 0,enabledExtensions:N,availableExtensions:D,enabledExtensionDetails:O,onEnabledExtensionsChange:eb,onOpenExtensionsSettings:f,retryInfo:H,soundEnabled:ew,onSoundToggle:eS,planMode:y,onPlanModeChange:eJ,sessionHistoryKey:eY,promptHistory:eZ}),e0=(0,o.useCallback)(e=>{M?c?.current?.sendOrQueue(e):es(e)},[M,c,es]);return k?(0,n.jsx)("div",{className:"flex h-full items-center justify-center text-text-muted",children:"Loading session..."}):w?(0,n.jsx)("div",{className:"flex h-full items-center justify-center text-red-400",children:w}):(0,n.jsxs)("div",{className:"relative flex h-full flex-col overflow-hidden",onDragEnter:e$,onDragOver:eP,onDragLeave:eA,onDrop:eB,children:[et&&(0,n.jsx)(rk,{request:et,onApprove:()=>void ej(et.requestId,(et.method,"accept"),"item/permissions/requestApproval"===et.method?{permissions:et.params?.permissions??{},scope:"turn"}:void 0),onApproveSession:()=>void ej(et.requestId,"item/permissions/requestApproval"===et.method?"accept":"acceptForSession","item/permissions/requestApproval"===et.method?{permissions:et.params?.permissions??{},scope:"session"}:void 0),onDeny:()=>void ej(et.requestId,(et.method,"decline"),"item/permissions/requestApproval"===et.method?{permissions:{},scope:"turn"}:void 0)}),eE&&(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"})]})]})]}),eO?(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:u.C3}),(0,n.jsx)("span",{style:{fontSize:14,minWidth:0,overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"},children:(0,n.jsx)(rb,{phrases:ry})})]}),(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.88"]})})]}),eQ]})}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"relative flex flex-1 overflow-hidden",children:[(0,n.jsx)("div",{ref:ei,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:eH?{paddingBottom:"calc(env(safe-area-inset-bottom, 0px) + 128px)"}:void 0,children:[V&&(0,n.jsx)(rm,{goal:V,onClear:ex,clearing:K}),"plan"===y&&er.length>0&&(0,n.jsx)(rv,{tasks:er,onExecute:eG,isRunning:M}),G&&!V&&(0,n.jsx)("div",{className:"mb-4 rounded-[8px] border border-[var(--border)] bg-[var(--bg-panel)] px-3 py-2 text-[12px] text-text-muted",children:"正在设置 goal…"}),(()=>{let r=new Map;for(let e of S)"toolResult"===e.role&&r.set(e.toolCallId,e);let o=-1;for(let e=S.length-1;e>=0;e--)if("user"===S[e].role){o=e;break}let i=0;return S.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=S.slice(s+1).find(e=>"user"===e.role||"assistant"===e.role);e?.role==="assistant"&&(u=!1),u&&T.isStreaming&&s===S.length-1&&(u=!1)}let p=(0,n.jsx)(tv,{message:l,toolResults:r,modelNames:L,entryId:C[s],onFork:M||en||0===s&&"user"===l.role?void 0:ed,forking:_===C[s],onSendMessage:e0,onOpenImage:a,showTimestamp:u,prevTimestamp:s>0?S[s-1].timestamp:void 0,renderVisualCodeBlocks:!!g,cwd:j?.info?.cwd??e?.cwd??t??void 0},s);return d?(0,n.jsx)("div",{ref:e=>{eD.current[c]=e,s===o&&(el.current=e)},children:p},s):p})})(),M&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(rf,{agentPhase:X,startedAt:I.startedAt,statusText:I.statusText,hasContent:!!(T.streamingMessage?.content&&Array.isArray(T.streamingMessage.content)&&T.streamingMessage.content.length>0),reconnectCount:I.reconnectCount,lastSyncReason:I.lastSyncReason,threadGoal:V}),(0,n.jsx)(tv,{message:T.streamingMessage??{role:"assistant",content:[],model:"",provider:""},isStreaming:!0,toolResults:z,modelNames:L,onSendMessage:e0,onOpenImage:a,renderVisualCodeBlocks:!!g,cwd:j?.info?.cwd??e?.cwd??t??void 0,streamingProcessState:I,showWaitingShell:!0})]}),j?.info?.cwd&&!1===j.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:j.info.cwd})]}),Q&&(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:Q}),M&&(0,n.jsx)("div",{style:{height:ei.current?ei.current.clientHeight:"80vh"}}),(0,n.jsx)("div",{ref:eo})]})}),!eH&&(0,n.jsx)(tU,{messages:S,streamingMessage:T.streamingMessage,scrollContainer:ei,messageRefs:eD}),eV&&(0,n.jsxs)("button",{onClick:()=>e_(e=>!e),title:eF?"Hide agent runs":"Show agent runs",style:{position:"absolute",right:eH?8:eF?260:40,top:8,minWidth:28,height:28,display:"flex",alignItems:"center",justifyContent:"center",gap:6,padding:eq>1?"0 8px":0,background:eF?"var(--bg-selected)":"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:eF?"var(--accent)":"var(--text-dim)",cursor:"pointer",zIndex:30,fontSize:12,transition:"right 0.2s ease, background 0.12s"},onMouseEnter:e=>{eF||(e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{eF||(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"})]}),eq>1&&(0,n.jsx)("span",{style:{display:"flex",alignItems:"center",gap:4,fontSize:10,fontWeight:700,color:"var(--accent)"},children:(0,n.jsxs)("span",{children:[eq," active"]})})]}),eF&&eV&&(0,n.jsxs)("div",{style:{position:"absolute",right:eH?8:48,top:4,bottom:4,width:eH?"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)(tQ,{runs:eU})]})]}),(0,n.jsx)("div",{className:"relative",children:eQ})]})]})}function rk({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 rw="var(--text-dim)";function rS({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:rw}),(0,n.jsx)("path",{d:"M1 6h14.5L14 13H2L1 6Z",stroke:rw,strokeWidth:"1",fill:rw,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:rw,strokeWidth:"1",fill:rw,fillOpacity:"0.1"})})}function rC({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:rw,strokeWidth:"1",fill:rw,fillOpacity:"0.08"}),(0,n.jsx)("path",{d:"M10 2v3h3",stroke:rw,strokeWidth:"1",fill:"none",strokeLinejoin:"round"})]})}function rT({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:rw,strokeWidth:"0.9",fill:rw,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:rw,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:rw,letterSpacing:"0",children:e})]})}function rI({size:e=14}){return(0,n.jsx)(rT,{label:"TS",size:e})}function rz({size:e=14}){return(0,n.jsx)(rT,{label:"TSX",size:e})}function rM({size:e=14}){return(0,n.jsx)(rT,{label:"JS",size:e})}function rL({size:e=14}){return(0,n.jsx)(rT,{label:"JSX",size:e})}function rR({size:e=14}){return(0,n.jsx)(rT,{label:"PY",size:e})}function rW({size:e=14}){return(0,n.jsx)(rT,{label:"{}",size:e})}function rE({size:e=14}){return(0,n.jsx)(rT,{label:"CSS",size:e})}function r$({size:e=14}){return(0,n.jsx)(rT,{label:"SC",size:e})}function rP({size:e=14}){return(0,n.jsx)(rT,{label:"HTM",size:e})}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:rw,strokeWidth:"0.9",fill:rw,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:rw,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M3.5 9.5V7l1.5 1.5L6.5 7v2.5",stroke:rw,strokeWidth:"0.9",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,n.jsx)("path",{d:"M8 7v2.5M7 9l1 1.5 1-1.5",stroke:rw,strokeWidth:"0.9",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]})}function rB({size:e=14}){return(0,n.jsx)(rT,{label:"YML",size:e})}function rN({size:e=14}){return(0,n.jsx)(rT,{label:"TOM",size:e})}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:rw,strokeWidth:"0.9",fill:rw,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:rw,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M4 7.5l2 1.5-2 1.5",stroke:rw,strokeWidth:"0.95",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,n.jsx)("path",{d:"M7.5 10.5h2.5",stroke:rw,strokeWidth:"0.95",strokeLinecap:"round"})]})}function rO({size:e=14}){return(0,n.jsx)(rT,{label:"RS",size:e})}function rH({size:e=14}){return(0,n.jsx)(rT,{label:"GO",size:e})}function rF({size:e=14}){return(0,n.jsx)(rT,{label:"SQL",size:e})}function r_({size:e=14}){return(0,n.jsx)(rT,{label:"GQL",size:e})}function rU({size:e=14}){return(0,n.jsx)(rT,{label:"TF",size:e})}function rq({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:rw,strokeWidth:"0.9",fill:rw,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:rw,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:rw,strokeWidth:"0.8"}),(0,n.jsx)("rect",{x:"6",y:"6.5",width:"2",height:"1.5",rx:"0.3",stroke:rw,strokeWidth:"0.8"}),(0,n.jsx)("rect",{x:"3.5",y:"8.5",width:"2",height:"1.5",rx:"0.3",stroke:rw,strokeWidth:"0.8"})]})}function rV({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:rw,strokeWidth:"0.9",fill:rw,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:rw,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"5.5",cy:"8.5",r:"1.5",stroke:rw,strokeWidth:"0.9"}),(0,n.jsx)("path",{d:"M7 8.5h2.5M8.5 8.5v1.5",stroke:rw,strokeWidth:"0.9",strokeLinecap:"round"})]})}function rJ({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:rw,strokeWidth:"0.9",fill:rw,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:rw,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"5",cy:"6.5",r:"1",stroke:rw,strokeWidth:"0.85"}),(0,n.jsx)("circle",{cx:"9",cy:"6.5",r:"1",stroke:rw,strokeWidth:"0.85"}),(0,n.jsx)("circle",{cx:"5",cy:"10",r:"1",stroke:rw,strokeWidth:"0.85"}),(0,n.jsx)("path",{d:"M5 7.5V9",stroke:rw,strokeWidth:"0.85",strokeLinecap:"round"}),(0,n.jsx)("path",{d:"M9 7.5v.5a2 2 0 0 1-2 2H6",stroke:rw,strokeWidth:"0.85",strokeLinecap:"round",fill:"none"})]})}function rG({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:rw,strokeWidth:"0.9",fill:rw,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:rw,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:rw,strokeWidth:"0.9"}),(0,n.jsx)("path",{d:"M5.5 8.5V7.5a1.5 1.5 0 0 1 3 0v1",stroke:rw,strokeWidth:"0.9",strokeLinecap:"round",fill:"none"})]})}function rK({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:rw,strokeWidth:"0.9",fill:rw,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:rw,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"7",cy:"8.5",r:"1.3",stroke:rw,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:rw,strokeWidth:"0.8",strokeLinecap:"round"})]})}function rY(e,t=14){let r=e.toLowerCase(),o=r.split(".").pop()??"";if("dockerfile"===r||r.startsWith("dockerfile."))return(0,n.jsx)(rq,{size:t});if(".env"===r||r.startsWith(".env."))return(0,n.jsx)(rV,{size:t});if(".gitignore"===r||".gitattributes"===r||".gitmodules"===r)return(0,n.jsx)(rJ,{size:t});if("package-lock.json"===r||"yarn.lock"===r||"bun.lock"===r||"pnpm-lock.yaml"===r||"cargo.lock"===r)return(0,n.jsx)(rG,{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)(rK,{size:t});switch(o){case"ts":return(0,n.jsx)(rI,{size:t});case"tsx":return(0,n.jsx)(rz,{size:t});case"js":case"mjs":case"cjs":return(0,n.jsx)(rM,{size:t});case"jsx":return(0,n.jsx)(rL,{size:t});case"py":return(0,n.jsx)(rR,{size:t});case"json":case"jsonl":return(0,n.jsx)(rW,{size:t});case"css":case"less":return(0,n.jsx)(rE,{size:t});case"scss":return(0,n.jsx)(r$,{size:t});case"html":case"htm":return(0,n.jsx)(rP,{size:t});case"md":case"mdx":return(0,n.jsx)(rA,{size:t});case"yaml":case"yml":return(0,n.jsx)(rB,{size:t});case"toml":return(0,n.jsx)(rN,{size:t});case"sh":case"bash":case"zsh":case"fish":return(0,n.jsx)(rD,{size:t});case"rs":return(0,n.jsx)(rO,{size:t});case"go":return(0,n.jsx)(rH,{size:t});case"sql":return(0,n.jsx)(rF,{size:t});case"graphql":case"gql":return(0,n.jsx)(r_,{size:t});case"tf":case"hcl":return(0,n.jsx)(rU,{size:t});case"lock":return(0,n.jsx)(rG,{size:t});default:return(0,n.jsx)(rC,{size:t})}}async function rZ(e){let t=ev(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,`${em(e).replace(/\/$/,"")}/${r}`),isDir:t.isDir,size:t.size,children:t.isDir?[]:void 0,loaded:!t.isDir}}):[]}function rX(e,t){let r=t.trim().toLowerCase();return!!(!r||e.name.toLowerCase().includes(r))||(e.children??[]).some(e=>rX(e,r))}function rQ(e){return!!Array.from(e.types).includes("Files")||Array.from(e.items).some(e=>"file"===e.kind)}function r0(e){return Array.from(e.files).filter(e=>!!e.name)}function r1(e,t){return e===t?".":eb(e,t)}function r2({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),T=h?g.filter(e=>rX(e,p??"")):g,I=(0,o.useCallback)(async(t=!1)=>{if(!m||t){b(!0);try{let t=await rZ(e.fullPath);f(t),v(!0)}catch{}finally{b(!1)}}},[m,e.fullPath]),z=(0,o.useRef)(m);(0,o.useEffect)(()=>{z.current=m}),(0,o.useEffect)(()=>{x&&m&&I(!0)},[u]);let M=(0,o.useCallback)(()=>{if(e.isDir){let t=!x;a(e.fullPath,t),t&&!m&&I()}else i(e.fullPath,e.name)},[e.isDir,e.fullPath,e.name,m,x,I,i,a]),L=(0,o.useCallback)(t=>{e.isDir&&rQ(t.dataTransfer)&&(t.preventDefault(),t.stopPropagation(),t.dataTransfer.dropEffect="copy",S(!0))},[e.isDir]),R=(0,o.useCallback)(t=>{e.isDir&&rQ(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||!rQ(t.dataTransfer))return;t.preventDefault(),t.stopPropagation(),S(!1);let r=r0(t.dataTransfer);r.length>0&&(d(r,e.fullPath),x||a(e.fullPath,!0),m||I())},[I,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)(rS,{size:14,open:x}):rY(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(eb(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:[T.map(e=>(0,n.jsx)(r2,{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===T.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 r4({cwd:e,onOpenFile:t,refreshKey:r,onAtMention:i,searchQuery:s="",onSearchChange:a}){let{pushToast:d}=(0,l.d)(),[c,u]=(0,o.useState)([]),[p,h]=(0,o.useState)(!0),[x,g]=(0,o.useState)(!1),[f,m]=(0,o.useState)(new Set),[v,y]=(0,o.useState)(!1),[b,j]=(0,o.useState)(null),[k,w]=(0,o.useState)(null),S=(0,o.useRef)(null),C=(0,o.useRef)(null),T=(0,o.useRef)(0),I=(0,o.useCallback)((e,t)=>(h(t),g(!1),rZ(e).then(e=>u(e)).catch(e=>{g(!0),d(String(e),"error")}).finally(()=>h(!1))),[d]),z=(0,o.useCallback)((e,t)=>{m(r=>{let n=new Set(r);return t?n.add(e):n.delete(e),n})},[]);(0,o.useEffect)(()=>{let t=S.current!==e;S.current=e,t&&m(new Set),I(e,t)},[e,r,I]),(0,o.useEffect)(()=>()=>{C.current&&clearTimeout(C.current)},[]);let M=(0,o.useCallback)(()=>{I(e,0===c.length)},[e,c.length,I]),L=(0,o.useCallback)(()=>{C.current&&clearTimeout(C.current),C.current=setTimeout(()=>w(null),5e3)},[]),R=(0,o.useCallback)((t,r)=>{if(0===t.length)return;T.current=0,y(!1),C.current&&clearTimeout(C.current);let n=t.reduce((e,t)=>e+t.size,0),o=r1(r,e);j(r),w({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=ev(r);l.open("POST",`/api/files/${s}?type=upload`),l.upload.onprogress=e=>{e.lengthComputable&&w(t=>t?{...t,loaded:e.loaded,total:e.total}:t)},l.onload=()=>{j(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}`)];w({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}),M(),L()}else{let o=e.error??`Upload failed (HTTP ${l.status})`;w({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}),L()}},l.onerror=()=>{j(null),w({phase:"error",targetPath:r,fileCount:t.length,loaded:0,total:n,message:"Upload failed due to a network error"}),L()},l.onabort=()=>{j(null),w({phase:"error",targetPath:r,fileCount:t.length,loaded:0,total:n,message:"Upload canceled"}),L()},l.send(i)},[e,M,L]),W=(0,o.useCallback)(e=>{rQ(e.dataTransfer)&&(e.preventDefault(),T.current+=1,y(!0))},[]),E=(0,o.useCallback)(e=>{rQ(e.dataTransfer)&&(e.preventDefault(),e.dataTransfer.dropEffect="copy")},[]),$=(0,o.useCallback)(()=>{T.current-=1,T.current<=0&&(T.current=0,y(!1))},[]),P=(0,o.useCallback)(t=>{if(!rQ(t.dataTransfer))return;t.preventDefault(),T.current=0,y(!1);let r=r0(t.dataTransfer);r.length>0&&R(r,e)},[e,R]),A=s.trim()?c.filter(e=>rX(e,s)):c,B=s.trim().length>0;return p?(0,n.jsx)(r5,{cwd:e,isDraggingFiles:v,uploadState:k,onDragEnter:W,onDragOver:E,onDragLeave:$,onDrop:P,children:(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:"Loading files..."})}):x?(0,n.jsx)(r5,{cwd:e,isDraggingFiles:v,uploadState:k,onDragEnter:W,onDragOver:E,onDragLeave:$,onDrop:P,children:(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:"Could not load files"})}):(0,n.jsx)(r5,{cwd:e,isDraggingFiles:v,uploadState:k,onDragEnter:W,onDragOver:E,onDragLeave:$,onDrop:P,children:(0,n.jsxs)("div",{style:{padding:"2px 4px"},children:[A.map(o=>(0,n.jsx)(r2,{node:o,depth:0,cwd:e,onOpenFile:t,onAtMention:i,expandedPaths:f,onToggleExpanded:z,onUploadFiles:R,uploadTargetPath:b,refreshKey:r,searchQuery:s},o.fullPath)),0===A.length&&(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:B?"No matching files":"No files found"})]})})}function r5({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 ",r1(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))})]})]})}async function r6(e){let t=await fetch(`/api/files/${ev(e)}?type=download`);if(!t.ok)throw Error((await t.json().catch(()=>({error:`HTTP ${t.status}`}))).error??`HTTP ${t.status}`);ee(await t.blob(),ey(e))}let r3={padding:"2px 10px",fontSize:11,cursor:"pointer",background:"var(--bg-hover)",color:"var(--text-muted)",border:"1px solid var(--border)",borderRadius:5,fontWeight:600};function r8({filePath:e}){let[t,r]=(0,o.useState)(!1),[i,l]=(0,o.useState)(null);return(0,n.jsx)("button",{onClick:()=>{l(null),r(!0),r6(e).catch(e=>l(e instanceof Error?e.message:String(e))).finally(()=>r(!1))},disabled:t,title:i??"Download original file",style:{...r3,opacity:t?.7:1,cursor:t?"wait":"pointer",...i?{borderColor:"var(--danger)",color:"var(--danger)"}:{}},onMouseEnter:e=>{t||i||(e.currentTarget.style.background="var(--accent)",e.currentTarget.style.color="#fff",e.currentTarget.style.borderColor="var(--accent)")},onMouseLeave:e=>{i||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)")},children:t?"Downloading…":"Download"})}function r7({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:r9,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:r9,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 r9={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"},ne=null;function nt({arrayBuffer:e,fileName:t,toolbarExtra:i}){let l=(0,o.useRef)(null),[s,a]=(0,o.useState)(!0),[d,c]=(0,o.useState)(null),[u,p]=(0,o.useState)(0),[h,x]=(0,o.useState)(1),[g,f]=(0,o.useState)(1),m=(0,o.useRef)(g);m.current=g;let v=(0,o.useRef)(null),y=(0,o.useRef)(null),b=(0,o.useCallback)(async e=>{if(!ne||!v.current)return;let t=v.current;if(!(e<1)&&!(e>t.numPages)){y.current&&(y.current.cancel(),y.current=null);try{let r=await t.getPage(e),n=r.getViewport({scale:m.current*(window.devicePixelRatio||1)}),o=l.current;if(!o)return;let i=o.querySelector("canvas");if(i||((i=document.createElement("canvas")).style.display="block",i.style.margin="0 auto",o.innerHTML="",o.appendChild(i)),i.width=n.width,i.height=n.height,i.style.width=`${n.width/(window.devicePixelRatio||1)}px`,i.style.height=`${n.height/(window.devicePixelRatio||1)}px`,!i.getContext("2d"))return;let s=r.render({canvas:i,viewport:n});y.current=s,await s.promise,y.current=null}catch(e){"RenderingCancelledException"!==e.name&&console.error("PDF render error:",e)}}},[]);return(0,o.useEffect)(()=>{let t=!1;return async function(){a(!0),c(null);try{ne||((ne=await r.e(2213).then(r.bind(r,12810))).GlobalWorkerOptions.workerSrc=new r.U(r(53228)).toString());let n=await ne.getDocument({data:e}).promise;if(t)return;v.current=n,p(n.numPages),x(1),a(!1)}catch(e){t||(c(String(e)),a(!1))}}(),()=>{t=!0,y.current&&(y.current.cancel(),y.current=null)}},[e]),(0,o.useEffect)(()=>{!s&&u>0&&b(h)},[s,h,u,b]),(0,o.useEffect)(()=>{!s&&u>0&&b(h)},[g]),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsx)(r7,{fileName:t,pageInfo:u>0?`Page ${h} / ${u}`:void 0,zoom:g,onZoomIn:()=>f(e=>Math.min(e+.25,3)),onZoomOut:()=>f(e=>Math.max(e-.25,.25)),extra:(0,n.jsxs)(n.Fragment,{children:[u>1&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsx)("button",{onClick:()=>x(e=>Math.max(e-1,1)),disabled:h<=1,style:{...nr,opacity:h<=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:[h,"/",u]}),(0,n.jsx)("button",{onClick:()=>x(e=>Math.min(e+1,u)),disabled:h>=u,style:{...nr,opacity:h>=u?.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"})})})]}),i]})}),(0,n.jsxs)("div",{style:{flex:1,overflow:"auto",background:"#525659",display:"flex",justifyContent:"center",padding:16},children:[s&&(0,n.jsx)("div",{style:{color:"#ccc",fontSize:13,display:"flex",alignItems:"center",gap:6,alignSelf:"flex-start",marginTop:40},children:"Loading PDF..."}),d&&(0,n.jsx)("div",{style:{color:"#f87171",fontSize:13,alignSelf:"flex-start",marginTop:40},children:d}),(0,n.jsx)("div",{ref:l,style:{visibility:s?"hidden":"visible"}})]})]})}let nr={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 nn({arrayBuffer:e,fileName:t,toolbarExtra:i}){let l=(0,o.useRef)(null),[s,a]=(0,o.useState)(!0),[d,c]=(0,o.useState)(null);return(0,o.useEffect)(()=>{let t=!1;return async function(){a(!0),c(null);try{let{renderAsync:n}=await Promise.all([r.e(4453),r.e(2274)]).then(r.bind(r,52274)),o=l.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||a(!1)}catch(e){t||(console.error("DOCX render error:",e),c(String(e)),a(!1))}}(),()=>{t=!0}},[e]),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsx)(r7,{fileName:t,extra:i}),(0,n.jsxs)("div",{style:{flex:1,overflow:"auto",background:"#e8e8e8",padding:"24px 0"},children:[s&&(0,n.jsx)("div",{style:{color:"var(--text-muted)",fontSize:13,padding:"40px 16px",textAlign:"center"},children:"Loading document..."}),d&&(0,n.jsx)("div",{style:{color:"#f87171",fontSize:13,padding:"40px 16px",textAlign:"center"},children:d}),(0,n.jsx)("div",{ref:l,style:{maxWidth:816,margin:"0 auto",background:"#fff",boxShadow:"0 1px 4px rgba(0,0,0,0.12)",minHeight:100,visibility:s?"hidden":"visible"},className:"docx-preview-container"})]})]})}function no({arrayBuffer:e,fileName:t,toolbarExtra:i}){let[l,s]=(0,o.useState)(!0),[a,d]=(0,o.useState)(null),[c,u]=(0,o.useState)([]),[p,h]=(0,o.useState)(0),x=(0,o.useRef)(null),[g,f]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{let t=!1;return async function(){s(!0),d(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||(u(i),h(0),s(!1))}catch(e){t||(console.error("XLSX parse error:",e),d(String(e)),s(!1))}}(),()=>{t=!0}},[e]),(0,o.useEffect)(()=>{let e=x.current;if(!e)return;let t=e.querySelector("table");if(!t)return;let r=()=>{f(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()},[p,c]),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsx)(r7,{fileName:t,extra:(0,n.jsxs)(n.Fragment,{children:[c.length>1&&(0,n.jsx)("div",{style:{display:"flex",alignItems:"center",gap:2},children:c.map((e,t)=>(0,n.jsx)("button",{onClick:()=>h(t),style:{padding:"2px 10px",fontSize:11,border:"1px solid var(--border)",borderBottom:t===p?"2px solid var(--accent)":"1px solid var(--border)",borderRadius:"4px 4px 0 0",background:t===p?"var(--bg-selected)":"none",color:t===p?"var(--text)":"var(--text-muted)",cursor:"pointer",fontWeight:t===p?600:400,transition:"background 0.12s"},onMouseEnter:e=>{t!==p&&(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t!==p&&(e.currentTarget.style.background="none")},children:e.name},t))}),i]})}),(0,n.jsxs)("div",{style:{flex:1,overflow:"auto",background:"var(--bg-panel)"},children:[l&&(0,n.jsx)("div",{style:{color:"var(--text-muted)",fontSize:13,padding:"40px 16px",textAlign:"center"},children:"Loading spreadsheet..."}),a&&(0,n.jsx)("div",{style:{color:"#f87171",fontSize:13,padding:"40px 16px",textAlign:"center"},children:a}),!l&&!a&&c.length>0&&(0,n.jsx)("div",{ref:x,style:{padding:"0 16px 16px",overflow:g?"auto":"visible"},dangerouslySetInnerHTML:{__html:c[p]?.html??""},className:"xlsx-preview"})]})]})}function ni({arrayBuffer:e,fileName:t,toolbarExtra:i}){let[l,s]=(0,o.useState)(!0),[a,d]=(0,o.useState)(null),[c,u]=(0,o.useState)([]),[p,h]=(0,o.useState)(0);(0,o.useEffect)(()=>{let t=!1;return async function(){s(!0),d(null);try{let n=(await 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 l=[];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,s=[];for(;null!==(r=i.exec(n));){let e=r[1].trim();e&&s.push(e)}l.push({index:e.index,texts:s})}t||(u(l),s(!1))}catch(e){t||(console.error("PPTX parse error:",e),d(String(e)),s(!1))}}(),()=>{t=!0}},[e]);let x=c[p],g=c.length;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsx)(r7,{fileName:t,pageInfo:g>0?`Slide ${p+1} / ${g}`:void 0,extra:(0,n.jsxs)(n.Fragment,{children:[g>1&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsx)("button",{onClick:()=>h(e=>Math.max(e-1,0)),disabled:p<=0,style:{...nl,opacity:p<=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:[p+1,"/",g]}),(0,n.jsx)("button",{onClick:()=>h(e=>Math.min(e+1,g-1)),disabled:p>=g-1,style:{...nl,opacity:p>=g-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"})})})]}),i]})}),(0,n.jsxs)("div",{style:{flex:1,overflow:"auto",background:"var(--bg-panel)",display:"flex",justifyContent:"center",alignItems:"flex-start",padding:24},children:[l&&(0,n.jsx)("div",{style:{color:"var(--text-muted)",fontSize:13,padding:"40px 16px",textAlign:"center"},children:"Loading presentation..."}),a&&(0,n.jsx)("div",{style:{color:"#f87171",fontSize:13,padding:"40px 16px",textAlign:"center"},children:a}),!l&&!a&&x&&(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 ",x.index]}),(0,n.jsx)("div",{style:{padding:"24px 32px 40px",minHeight:200},children:0===x.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:x.texts.map((e,t)=>(0,n.jsx)("li",{style:{padding:"4px 0",fontSize:14,lineHeight:1.6,color:"var(--text)",borderBottom:t<x.texts.length-1?"1px solid var(--bg-panel)":"none"},children:e},t))})})]}),g>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:c.map((e,t)=>(0,n.jsxs)("button",{onClick:()=>h(t),style:{padding:"10px 12px",background:t===p?"var(--bg-selected)":"var(--bg)",border:t===p?"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!==p&&(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t!==p&&(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 nl={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 ns=r(27071),na=r(89561),nd=r(82228),nc=r(46732),nu=r(74059),np=r(13307),nh=r(53689),nx=r(14097),ng=r(25460),nf=r(20144),nm=r(82774),nv=r(62733),ny=r(77482),nb=r(55135),nj=r(11209),nk=r(88198),nw=r(4238),nS=r(44542);function nC({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,np.Q2)({typescript:"typescript"===e});case"python":return(0,nh.Hg)();case"sql":return(0,nx.ll)();case"json":return(0,ng.Pq)();case"html":return(0,nf.qy)();case"css":case"scss":case"less":return(0,nm.AH)();case"markdown":return(0,nv.wD)();case"xml":case"yaml":case"toml":return(0,ny._n)();case"rust":return(0,nb.T)();case"go":return(0,nj.go)();case"java":return(0,nk.J)();default:return null}}(t),i=l?na.w4.of([{key:"Mod-s",run:()=>(c.current?.(),!0),preventDefault:!0}]):[],u=ns.$t.create({doc:e,extensions:[(0,na.$K)(),(0,na.dz)(),(0,nd.b6)(),(0,nc.y9)(nc.Zt),na.w4.of([...nd.pw,...nd.cL,...nS.OO,...nw.Eo]),i,(0,nS.yU)(),...r?[nu.bM]:[],...o?[o]:[],na.Lz.updateListener.of(e=>{e.docChanged&&d.current?.(e.state.doc.toString())}),na.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 na.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 nT({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 nI(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 nz({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:()=>{nI(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:()=>{nI(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)(nT,{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 nM=new Set(["png","jpg","jpeg","gif","webp","svg","bmp","ico","avif"]),nL=new Set(["mp3","wav","ogg","oga","opus","m4a","aac","flac","weba","webm"]),nR=new Set(["pdf","docx","xlsx","pptx","doc","xls","ppt"]);function nW(e){let t=ey(e).toLowerCase().split(".").pop()??"";return"csv"===t?",":"tsv"===t?" ":null}function nE(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function n$({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 nP({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=ey(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=ev(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=ev(e),y=`/api/files/${v}?type=read${l?`&v=${l}`:""}`,b=null!=a?nE(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:eb(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.jsx)(r8,{filePath:e}),(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 nA({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=ey(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=ev(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=ev(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:eb(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:nE(a)}),(0,n.jsx)(r8,{filePath:e}),(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 nB({filePath:e,cwd:t,onOpenFile:r}){let o,i,l;return(o=ey(e).toLowerCase().split(".").pop()??"",nM.has(o))?(0,n.jsx)(nP,{filePath:e,cwd:t}):(i=ey(e).toLowerCase().split(".").pop()??"",nL.has(i))?(0,n.jsx)(nA,{filePath:e,cwd:t}):(l=ey(e).toLowerCase().split(".").pop()??"",nR.has(l))?(0,n.jsx)(nN,{filePath:e,cwd:t}):(0,n.jsx)(nD,{filePath:e,cwd:t,onOpenFile:r})}function nN({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=ey(e).toLowerCase().split(".").pop()??"")?"pdf":"docx"===r||"doc"===r?"docx":"xlsx"===r||"xls"===r?"xlsx":"pptx"===r||"ppt"===r?"pptx":"other",x=ey(e).toLowerCase().split(".").pop()??"",g=(0,o.useCallback)(async e=>{try{let t=ev(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=ev(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=eb(e,t),m=(0,n.jsx)(r8,{filePath:e});return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:["pdf"===h&&(0,n.jsx)(nt,{arrayBuffer:i,fileName:f,toolbarExtra:m}),"docx"===h&&(0,n.jsx)(nn,{arrayBuffer:i,fileName:f,toolbarExtra:m}),"xlsx"===h&&(0,n.jsx)(no,{arrayBuffer:i,fileName:f,toolbarExtra:m}),"pptx"===h&&(0,n.jsx)(ni,{arrayBuffer:i,fileName:f,toolbarExtra:m}),"other"===h&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(r7,{fileName:f,extra:m}),(0,n.jsxs)("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:["Unsupported document format: .",x]})]})]})}function nD({filePath:e,cwd:t,onOpenFile:r}){let{isDark:i}=F(),[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),[T,I]=(0,o.useState)(!1),[z,M]=(0,o.useState)(""),[L,R]=(0,o.useState)(!1),[W,E]=(0,o.useState)(!1),[$,P]=(0,o.useState)(!1),[A,N]=(0,o.useState)(null),D=(0,o.useRef)(null),O=(0,o.useRef)(!1);O.current=T,(0,o.useRef)(null).current=l;let H=(0,o.useCallback)((e,t=!1)=>{let r=ev(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),D.current&&(D.current.close(),D.current=null),H(e).then(t=>{(t?.language==="markdown"||nW(e))&&m(!0)}).finally(()=>u(!1));let t=ev(e),r=new EventSource(`/api/files/${t}?type=watch`);return D.current=r,r.addEventListener("connected",()=>{w(!0)}),r.addEventListener("change",()=>{O.current?E(!0):H(e,!0)}),r.addEventListener("error",()=>{w(!1)}),r.onerror=()=>{w(!1)},()=>{r.close(),D.current=null}},[e,H]);let _=(0,o.useCallback)(()=>{l&&(I(!0),M(l.content),N(l.mtime??null),P(!1),g(null),E(!1),m(!1),y("source"))},[l]),U=(0,o.useCallback)(async(t=!1)=>{let r=ev(e);R(!0),P(!1),g(null);try{let n=await fetch(`/api/files/${r}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:z,...t||!A?{}:{baseMtime:A}})});if(409===n.status){let e=await n.json().catch(()=>({error:"File changed on disk since it was opened"}));throw P(!0),E(!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 H(e,!0);N(o?.mtime??null),I(!1),E(!1),P(!1)}catch(e){g(e instanceof Error?e.message:String(e))}finally{R(!1)}},[e,z,A,H]),q=(0,o.useCallback)(()=>{I(!1),E(!1),P(!1),g(null),N(null)},[]),V=(0,o.useCallback)(async()=>{let t=await H(e,!0);t&&(M(t.content),N(t.mtime??null),E(!1),P(!1),g(null),h(null))},[H,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 J="html"===l.language,G="markdown"===l.language,K=nW(e),Y=null!==K,Z=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:eb(e,t)}),(0,n.jsx)("span",{style:{marginLeft:"auto"},children:l.language}),"source"===v&&(0,n.jsxs)("span",{children:[Z.length," lines"]}),(0,n.jsx)("span",{children:nE(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"]}),(0,n.jsx)(r8,{filePath:e}),T?(0,n.jsxs)(n.Fragment,{children:[(W||$||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",(W||$)&&(0,n.jsx)("button",{onClick:V,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"}),$&&(0,n.jsx)("button",{onClick:()=>void U(!0),disabled:L,style:{marginLeft:4,padding:"1px 6px",fontSize:10,cursor:L?"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:L,title:"Save file (Ctrl+S)",style:{padding:"2px 10px",fontSize:11,cursor:L?"not-allowed":"pointer",background:"var(--accent)",color:"#fff",border:"1px solid var(--accent)",borderRadius:5,fontWeight:600,opacity:L?.6:1},children:L?"Saving…":"Save"}),(0,n.jsx)("button",{onClick:q,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"}),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(!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"})]}),G&&"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:T?"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:T&&!(G&&f)?(0,n.jsx)(nC,{initialContent:z,language:l.language,isDark:i,onChange:M,onSave:()=>void U()}):T&&G&&f?(0,n.jsx)(eT,{content:z,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)(n$,{oldContent:a,newContent:l.content,language:l.language}):J&&f?(0,n.jsx)("iframe",{srcDoc:l.content,sandbox:"allow-scripts",style:{width:"100%",height:"100%",border:"none",background:"var(--bg)"},title:"HTML preview"}):G&&f?(0,n.jsx)(eT,{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&&K?(0,n.jsx)(nz,{content:l.content,delimiter:K,fileName:ey(e)}):(0,n.jsx)(B.A,{language:"text"===l.language||"csv"===l.language||"tsv"===l.language?"plaintext":l.language,style:ef(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 nO(e,t,r){return Math.min(Math.max(e,t),r)}function nH({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 nF({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),T=S?l[(s-1+l.length)%l.length]:null,I=S?l[(s+1)%l.length]:null,z=(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:nO(e.left,8,Math.max(8,window.innerWidth-n-8)),top:nO(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:nO(r,8,Math.max(8,window.innerWidth-120)),top:nO(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:nO(r,360,Math.max(360,window.innerWidth-e.left-8)),height:nO(n,280,Math.max(280,window.innerHeight-e.top-8))}))},[]),P=(0,o.useCallback)(e=>{let t=w.current;t?.pointerId===e.pointerId&&(e.currentTarget.releasePointerCapture(e.pointerId),w.current=null,b(!1))},[]),A=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(),z(-1)),"ArrowRight"===t.key&&(t.preventDefault(),z(1))},style:{...A,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:()=>z(-1),title:T?.title?`Previous: ${T.title}`:"Previous image","aria-label":"Previous image",style:n_,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:()=>z(1),title:I?.title?`Next: ${I.title}`:"Next image","aria-label":"Next image",style:n_,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:n_,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:n_,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)(nH,{src:t,alt:r}):(0,n.jsx)(nB,{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:P,onPointerCancel:P,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 n_={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},nU={__soul__:{apiPath:"/api/soul",title:"SOUL.md"},__harness__:{apiPath:"/api/harness",title:"HARNESS.md"}};function nq({filePath:e}){let t=nU[e],{isDark:r}=F(),{pushToast:i}=(0,l.d)(),[s,a]=(0,o.useState)(""),[d,c]=(0,o.useState)(!0),[u,p]=(0,o.useState)(!1),[h,x]=(0,o.useState)(!1),[g,f]=(0,o.useState)(!1);(0,o.useEffect)(()=>{t&&(c(!0),p(!1),fetch(t.apiPath).then(e=>e.json()).then(e=>a(e.content??"")).catch(e=>{p(!0),i(String(e),"error")}).finally(()=>c(!1)))},[t,i]);let m=(0,o.useCallback)(async()=>{if(t){x(!0);try{let e=await fetch(t.apiPath,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:s})});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error??`HTTP ${e.status}`)}f(!0),i("Saved","success"),setTimeout(()=>f(!1),2e3)}catch(e){i(String(e),"error")}finally{x(!1)}}},[t,s,i]);return t?d?(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:"Loading…"}):u?(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:"Could not load file"}):(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"}),g&&(0,n.jsx)("span",{style:{color:"#4ade80",fontWeight:600,animation:"saved-pop 0.3s ease"},children:"✓ Saved"}),(0,n.jsx)("button",{onClick:m,disabled:h,title:"Save (Ctrl+S)",style:{padding:"2px 10px",fontSize:11,cursor:h?"not-allowed":"pointer",background:"var(--accent)",color:"#fff",border:"1px solid var(--accent)",borderRadius:5,fontWeight:600,opacity:h?.6:1},children:h?"Saving…":"Save"})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"hidden"},children:(0,n.jsx)(nC,{initialContent:s,language:"markdown",isDark:r,onChange:a,onSave:m})})]}):null}function nV(){document.body.style.cursor="",document.body.style.userSelect=""}function nJ({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),nV(),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,nV(),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 nG({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"})}):rY(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 nK(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 nY(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 nZ(e){return e?ey(e)||e:"-"}function nX({refreshKey:e=0,cwd:t}){let{pushToast:r}=(0,l.d)(),[i,s]=(0,o.useState)(null),[a,d]=(0,o.useState)(null),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(null),x=(0,o.useCallback)(async()=>{try{let e=new URLSearchParams;t&&e.set("cwd",t);let r=await fetch(`/api/agent/runtime${e.toString()?`?${e}`:""}`,{cache:"no-store"}),n=await r.json();if(!r.ok||!Array.isArray(n.sessions))throw Error(n.error??`HTTP ${r.status}`);s(n),d(n.memory??null)}catch(e){r(e instanceof Error?e.message:String(e),"error")}},[t,r]);(0,o.useEffect)(()=>{x()},[x,e]),(0,o.useEffect)(()=>{let e=window.setInterval(()=>{x()},3e3);return()=>window.clearInterval(e)},[x]);let g=(0,o.useCallback)(async(e,n)=>{if(t){u(`${e}:${n}`);try{let o=await fetch("/api/memory/promote",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,memoryId:e,target:n})}),i=await o.json();if(!o.ok)throw Error(i.error??`HTTP ${o.status}`);await x(),r("Memory promoted","success")}catch(e){r(e instanceof Error?e.message:String(e),"error")}finally{u(null)}}},[t,x,r]),f=(0,o.useCallback)(async e=>{h(e.sessionId);try{let t=await fetch(`/api/agent/${encodeURIComponent(e.sessionId)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"abort"})}),n=await t.json().catch(()=>({}));if(!t.ok||n.error)throw Error(n.error??`HTTP ${t.status}`);await x(),r("Session aborted","success")}catch(e){r(e instanceof Error?e.message:String(e),"error")}finally{h(null)}},[x,r]),m=(0,o.useMemo)(()=>[...i?.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")}),[i]),v=m.filter(e=>e.busy),y=v.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.jsx)("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:[v.length," agent running \xb7 ",i?.activeSessions??0," active",t?` \xb7 ${nZ(t)}`:""]})]}),(0,n.jsx)("button",{type:"button",onClick:()=>void x(),style:n4,title:"Refresh runtime",children:"Refresh"})]})}),(0,n.jsx)("div",{style:{flex:1,overflow:"auto",padding:10},children:(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[(0,n.jsxs)("section",{children:[(0,n.jsx)(nQ,{title:"Agent Runtime",subtitle:y.length>0?`${y.length} waiting for first token`:`${v.length} active chat${1===v.length?"":"s"}`}),0===m.length?(0,n.jsx)(n0,{label:"No agent runtime is active."}):(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:m.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:nK(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:nK(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:[nZ(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)(n1,{label:"uptime",value:nY(e.uptimeMs)}),(0,n.jsx)(n1,{label:"wait",value:nY(e.waitingForModelMs),color:"waiting_model"===e.phase?nK(e.phase):void 0}),(0,n.jsx)(n1,{label:"pending",value:null===e.pendingMessageCount?"-":String(e.pendingMessageCount)}),(0,n.jsx)(n1,{label:"event",value:e.lastEventType??"-"}),(0,n.jsx)(n1,{label:"tools",value:o||"-"}),(0,n.jsx)(n1,{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 f(e),disabled:!e.busy||p===e.sessionId,style:{...n4,border:"1px solid rgba(239,68,68,0.35)",color:"#ef4444",background:"rgba(239,68,68,0.08)",opacity:e.busy&&p!==e.sessionId?1:.55},children:"Abort"})})]},e.sessionId)})})]}),(0,n.jsxs)("section",{children:[(0,n.jsx)(nQ,{title:"Memory",subtitle:a?`${a.count} stored \xb7 ${a.candidateCount} candidates`:t?"loading":"No project selected"}),t?a?(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",padding:10},children:[(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:"5px 10px",fontSize:11,color:"var(--text-muted)"},children:[(0,n.jsx)(n1,{label:"fact",value:String(a.byType.fact)}),(0,n.jsx)(n1,{label:"context",value:String(a.byType.context)}),(0,n.jsx)(n1,{label:"decision",value:String(a.byType.decision)}),(0,n.jsx)(n1,{label:"preference",value:String(a.byType.preference)}),(0,n.jsx)(n1,{label:"note",value:String(a.byType.note)}),(0,n.jsx)(n1,{label:"candidates",value:String(a.candidateCount),color:a.candidateCount>0?"var(--accent)":void 0})]}),(0,n.jsx)("div",{title:a.filePath,style:{marginTop:8,fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:eb(a.filePath,t)})]}),(0,n.jsx)(n2,{title:"Promotion Candidates",emptyLabel:"No promotion candidates yet.",items:a.topCandidates,onPromote:g,busyAction:c}),(0,n.jsx)(n2,{title:"Recent Memory",emptyLabel:"No memory stored for this project.",items:a.recent})]}):(0,n.jsx)(n0,{label:"Memory status unavailable."}):(0,n.jsx)(n0,{label:"Select a project to inspect memory status."})]})]})})]})}function nQ({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 n0({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 n1({label:e,value:t,color:r}){return(0,n.jsxs)("div",{style:{minWidth:0,display:"flex",alignItems:"center",gap:5},children:[(0,n.jsx)("span",{style:{color:"var(--text-dim)",flexShrink:0},children:e}),(0,n.jsx)("span",{style:{color:r??"var(--text-muted)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)"},children:t})]})}function n2({title:e,emptyLabel:t,items:r,onPromote:o,busyAction:i}){return(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"8px 10px",borderBottom:"1px solid var(--border)",fontSize:12,fontWeight:700,color:"var(--text)"},children:e}),0===r.length?(0,n.jsx)("div",{style:{padding:"14px 10px",fontSize:12,color:"var(--text-dim)",textAlign:"center"},children:t}):(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column"},children:r.map((e,t)=>(0,n.jsxs)("div",{style:{padding:"9px 10px",borderTop:0===t?"none":"1px solid var(--border)",display:"flex",flexDirection:"column",gap:5},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,minWidth:0},children:[(0,n.jsx)("span",{style:{fontSize:10,color:"project_memory"===e.candidate?"#f59e0b":"spark"===e.candidate?"var(--accent)":"var(--text-dim)",fontWeight:700,textTransform:"uppercase",flexShrink:0},children:"none"===e.candidate?e.memoryType:e.candidate}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)",flexShrink:0},children:e.importance.toFixed(2)}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:new Date(e.timestamp).toLocaleString()})]}),(0,n.jsx)("div",{title:e.content,style:{fontSize:12,color:"var(--text)",lineHeight:1.45,display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical",overflow:"hidden"},children:e.content}),o&&(0,n.jsxs)("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[(0,n.jsx)("button",{type:"button",disabled:e.promotedTo.includes("memory")||i===`${e.id}:context`||i===`${e.id}:memory`,onClick:()=>void o(e.id,"memory"),style:{...n4,height:26,fontSize:11,opacity:e.promotedTo.includes("memory")||i===`${e.id}:context`||i===`${e.id}:memory`?.55:1},children:e.promotedTo.includes("memory")?"In MEMORY.md":i===`${e.id}:memory`?"Saving...":"To MEMORY.md"}),(0,n.jsx)("button",{type:"button",disabled:e.promotedTo.includes("context")||i===`${e.id}:context`||i===`${e.id}:memory`,onClick:()=>void o(e.id,"context"),style:{...n4,height:26,fontSize:11,opacity:e.promotedTo.includes("context")||i===`${e.id}:context`||i===`${e.id}:memory`?.55:1},children:e.promotedTo.includes("context")?"In CONTEXT.md":i===`${e.id}:context`?"Saving...":"To CONTEXT.md"})]})]},e.id))})]})}let n4={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},n5=["openai-responses","openai-completions"],n6=[/\/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],n3=[/api\.openai\.com/i,/\/responses(?:$|[?#])/i];function n8(e,t,r="openai-responses"){let n=`${t??""} ${e??""}`.toLowerCase();return n.trim()?n3.some(e=>e.test(n))?"openai-responses":n6.some(e=>e.test(n))?"openai-completions":r:r}function n7(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 n9=n7((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"})),oe=n7((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"})),ot=n7((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"})]})),or=n7((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"})]})),on=n7((0,n.jsx)("path",{d:"M4 4h16v16H4z",fill:"#F55036"}),"0 0 24 24"),oo=n7((0,n.jsx)("path",{d:"M4 4h5v5H4zm5.5 0h5v5h-5zM15 4h5v5h-5zM4 9.5h5v5H4zm5.5 5.5h5v5h-5zM15 9.5h5v5h-5z",fill:"#FA6F00"})),oi=n7((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),"0 0 24 24"),ol=n7((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"})]})),os=n7((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",fill:"#FF5722"}),"0 0 24 24"),oa=n7((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"})),od=n7((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"})]})),oc=n7((0,n.jsx)("path",{d:"M12 2l9 5v10l-9 5-9-5V7l9-5z",stroke:"currentColor",strokeWidth:"1.5",fill:"none"})),ou=n7((0,n.jsx)("path",{d:"M4 4l8 8 8-8M4 20l8-8 8 8",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})),op=n7((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"})),oh=n7((0,n.jsx)("path",{d:"M12 2L22 20H2L12 2z",fill:"currentColor"})),ox=n7((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),"0 0 24 24"),og=n7((0,n.jsx)("path",{d:"M3 15h2l1-3h2l1 3h2V9H9v3L8 9H6l-1 3V9H3v6zm9 0h2v-2h2v-2h-2V9h-2v2h-2v2h2v2z",fill:"#FF9900"})),of=n7((0,n.jsx)("path",{d:"M12 2L3 18h5l4-6 4 6h5L12 2z",fill:"#0078D4"})),om=n7((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"})]})),ov=n7((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"})]})),oy=n7((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"})]})),ob=n7((0,n.jsx)("path",{d:"M4 8h16v2H4zm0 4h12v2H4zm0 4h8v2H4z",fill:"#3059B1"})),oj=n7((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"})),ok=n7((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",fill:"#0F6CBD"}),"0 0 24 24"),ow=n7((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),"0 0 24 24"),oS=[{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:[]}],oC={anthropic:{Icon:n9,hasColor:!1},openai:{Icon:oe,hasColor:!1},"openai-codex":{Icon:oe,hasColor:!1},google:{Icon:ot,hasColor:!0},"google-vertex":{Icon:ot,hasColor:!0},deepseek:{Icon:or,hasColor:!0},groq:{Icon:on,hasColor:!1},mistral:{Icon:oo,hasColor:!0},moonshotai:{Icon:oi,hasColor:!1},"moonshotai-cn":{Icon:oi,hasColor:!1},moonshot:{Icon:oi,hasColor:!1},minimax:{Icon:ol,hasColor:!0},"minimax-cn":{Icon:ol,hasColor:!0},fireworks:{Icon:os,hasColor:!0},huggingface:{Icon:oa,hasColor:!0},cerebras:{Icon:od,hasColor:!0},openrouter:{Icon:oc,hasColor:!1},xai:{Icon:ou,hasColor:!1},"cloudflare-ai-gateway":{Icon:op,hasColor:!0},"cloudflare-workers-ai":{Icon:op,hasColor:!0},"vercel-ai-gateway":{Icon:oh,hasColor:!1},"github-copilot":{Icon:ox,hasColor:!1},"amazon-bedrock":{Icon:og,hasColor:!0},"azure-openai-responses":{Icon:of,hasColor:!0},"kimi-coding":{Icon:om,hasColor:!0},qwen:{Icon:ov,hasColor:!0},zai:{Icon:oy,hasColor:!0},cohere:{Icon:ob,hasColor:!0},perplexity:{Icon:oj,hasColor:!0},together:{Icon:ok,hasColor:!0},grok:{Icon:ow,hasColor:!1}};function oT(e){return oS.find(t=>t.id===e)}let oI=[{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 oz({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 oM={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 oL({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:{...oM,fontFamily:o?"var(--font-mono)":"inherit",...l}})}function oR({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:{...oM,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 oW({value:e,onChange:t,placeholder:r}){return(0,n.jsx)("input",{type:"number",value:e,onChange:e=>t(e.target.value),placeholder:r,style:oM})}function oE({value:e,onChange:t,required:r}){return(0,n.jsxs)("select",{value:e,onChange:e=>{let r=e.target.value;t("string"==typeof r&&n5.includes(r)?r:"")},style:{...oM,color:e?"var(--text)":"var(--text-dim)"},children:[!r&&(0,n.jsx)("option",{value:"",children:"— inherit / none —"}),oI.map(e=>(0,n.jsx)("option",{value:e.value,children:e.label},e.value))]})}function o$({api:e}){let t=oI.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 oP({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 oA({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 oB({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)(oA,{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)(oz,{label:"Provider name",children:[(0,n.jsx)(oL,{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)(oz,{label:"Base URL",children:(0,n.jsx)(oL,{value:t.baseUrl??"",onChange:e=>!u&&p("baseUrl",e||void 0),placeholder:"https://api.example.com/v1",mono:!0})}),(0,n.jsxs)(oz,{label:"API Key",children:[(0,n.jsx)(oR,{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)(oz,{label:"Protocol",children:[(0,n.jsx)(oE,{value:t.api??n8(t.baseUrl,e),onChange:e=>!u&&p("api",e||void 0),required:!0}),(0,n.jsx)(o$,{api:t.api??n8(t.baseUrl,e)})]}),(0,n.jsxs)(oz,{label:"Model ID",children:[(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsx)(oL,{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 oN=["off","minimal","low","medium","high","xhigh"],oD={off:"var(--text-dim)",minimal:"#6b7280",low:"#60a5fa",medium:"#a78bfa",high:"#f472b6",xhigh:"#fb923c"};function oO({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:oN.map(e=>{let t=r[e],i=e in r?null===t?"null":"string":"omit",l="string"==typeof t?t:"",s=oD[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 oH={thinkingFormat:"deepseek",requiresReasoningContentOnAssistantMessages:!0};function oF({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)(oA,{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)(oz,{label:"ID *",children:(0,n.jsx)(oL,{value:r.id,onChange:e=>d("id",e),placeholder:"model-id",mono:!0})}),(0,n.jsx)(oz,{label:"Name",children:(0,n.jsx)(oL,{value:r.name??"",onChange:e=>d("name",e||void 0),placeholder:"Display name"})})]}),(0,n.jsxs)(oz,{label:"API override",children:[(0,n.jsx)(oE,{value:r.api??"",onChange:e=>d("api",e||void 0)}),(0,n.jsx)(o$,{api:r.api??""})]}),(0,n.jsxs)("div",{style:{display:"flex",gap:20,flexWrap:"wrap"},children:[(0,n.jsx)(oP,{label:"Reasoning / thinking",checked:r.reasoning??!1,onChange:e=>d("reasoning",e||void 0)}),(0,n.jsx)(oP,{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)(oP,{label:"DeepSeek thinking compat",checked:r.compat?.thinkingFormat==="deepseek",onChange:e=>i(function(e,t){if(t)return{...e,compat:{...e.compat??{},...oH}};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)(oA,{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)(oO,{value:r.thinkingLevelMap,onChange:e=>d("thinkingLevelMap",e)})]})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[(0,n.jsx)(oz,{label:"Context window (tokens)",children:(0,n.jsx)(oW,{value:void 0!==r.contextWindow?String(r.contextWindow):"",onChange:e=>d("contextWindow",e?parseInt(e):void 0),placeholder:"128000"})}),(0,n.jsx)(oz,{label:"Max output tokens",children:(0,n.jsx)(oW,{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)(oA,{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)(oz,{label:e,children:(0,n.jsx)(oW,{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 o_({provider:e,onRefresh:t}){let{pushToast:r}=(0,l.d)(),[i,s]=(0,o.useState)({phase:"idle"}),[a,d]=(0,o.useState)(""),c=(0,o.useRef)(null),u=(0,o.useRef)(null);(0,o.useEffect)(()=>{("auth"===i.phase||"prompt"===i.phase)&&setTimeout(()=>u.current?.focus(),50)},[i.phase]),(0,o.useEffect)(()=>{s({phase:"idle"}),d(""),c.current?.close(),c.current=null},[e.id]),(0,o.useEffect)(()=>()=>{c.current?.close()},[]),(0,o.useEffect)(()=>{"error"===i.phase&&r(i.message,"error")},[i,r]);let p=(0,o.useCallback)(()=>{c.current?.close(),s({phase:"connecting"}),d("");let r=new EventSource(`/api/auth/login/${encodeURIComponent(e.id)}`);c.current=r,r.onmessage=e=>{let n=JSON.parse(e.data);"auth"===n.type?(s({phase:"auth",url:n.url,instructions:n.instructions??null,token:n.token}),window.open(n.url,"_blank","noopener,noreferrer")):"device_code"===n.type?(s({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?s({phase:"prompt",message:n.message,placeholder:n.placeholder??null,token:n.token}):"select_request"===n.type?s({phase:"select",message:n.message,options:n.options??[],token:n.token}):"progress"===n.type?s({phase:"progress",message:n.message}):"success"===n.type?(r.close(),s({phase:"success"}),t()):"error"===n.type?(r.close(),s({phase:"error",message:n.message})):"cancelled"===n.type&&(r.close(),s({phase:"idle"}))},r.onerror=()=>{r.close(),s(e=>"success"===e.phase?e:{phase:"error",message:"Connection lost"})}},[e.id,t]),h=(0,o.useCallback)(async()=>{await fetch(`/api/auth/logout/${encodeURIComponent(e.id)}`,{method:"POST"}),s({phase:"idle"}),t()},[e.id,t]),x=(0,o.useCallback)(async(t,r)=>{if(r.trim()){s({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(()=>({}));s({phase:"error",message:e.error??`Server error ${n.status}`});return}d("")}catch(e){s({phase:"error",message:e instanceof Error?e.message:"Network error"})}}},[e.id]),g=(0,o.useCallback)(async(t,r)=>{s({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(()=>({}));s({phase:"error",message:e.error??`Server error ${n.status}`})}}catch(e){s({phase:"error",message:e instanceof Error?e.message:"Network error"})}},[e.id]),f="connecting"===i.phase||"progress"===i.phase||"auth"===i.phase||"device_code"===i.phase||"prompt"===i.phase||"select"===i.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)(oA,{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"===i.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"===i.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)"},children:"Opening browser…"}),"select"===i.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:i.message}),(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:i.options.map(e=>(0,n.jsx)("button",{onClick:()=>g(i.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"===i.phase||"prompt"===i.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"===i.phase?"Complete sign-in in the browser, then copy the redirect URL from the address bar and paste it below.":i.message}),"auth"===i.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:i.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:u,value:a,onChange:e=>d(e.target.value),onKeyDown:e=>{"Enter"===e.key&&x(i.token,a)},placeholder:"auth"===i.phase?"http://localhost:1455/auth/callback?code=…":i.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:()=>x(i.token,a),disabled:!a.trim(),style:{padding:"6px 12px",background:a.trim()?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:5,color:a.trim()?"#fff":"var(--text-dim)",cursor:a.trim()?"pointer":"not-allowed",fontSize:12,fontWeight:600,flexShrink:0},children:"Submit"})]})]}),"device_code"===i.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:i.userCode}),(0,n.jsxs)("p",{style:{margin:0,fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:[(0,n.jsx)("a",{href:i.verificationUri,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)",wordBreak:"break-all"},children:i.verificationUri}),i.expiresInSeconds?` Expires in ${Math.ceil(i.expiresInSeconds/60)} minutes.`:""]})]}),"progress"===i.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)"},children:i.message}),"success"===i.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"#4ade80"},children:"Connected successfully."})]}),(0,n.jsx)("div",{style:{display:"flex",gap:8},children:f?(0,n.jsx)("button",{onClick:()=>{c.current?.close(),s({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:p,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:h,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 oU({provider:e,onRefresh:t}){let{pushToast:r}=(0,l.d)(),[i,s]=(0,o.useState)(""),[a,d]=(0,o.useState)(!1),[c,u]=(0,o.useState)(!1),[p,h]=(0,o.useState)(!1);(0,o.useEffect)(()=>{s(""),h(!1)},[e.id]);let x=(0,o.useCallback)(async()=>{if(i.trim()){d(!0),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:i.trim()})}),o=await n.json();!n.ok||o.error?r(o.error??`HTTP ${n.status}`,"error"):(s(""),h(!0),setTimeout(()=>h(!1),2e3),r("API key saved","success"),t())}catch(e){r(String(e),"error")}finally{d(!1)}}},[i,t,e.id,r]),g=(0,o.useCallback)(async()=>{u(!0);try{let n=await fetch(`/api/auth/api-key/${encodeURIComponent(e.id)}`,{method:"DELETE"}),o=await n.json();!n.ok||o.error?r(o.error??`HTTP ${n.status}`,"error"):(r("API key removed","success"),t())}catch(e){r(String(e),"error")}finally{u(!1)}},[t,e.id,r]);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)(oA,{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)(oz,{label:"API Key",children:(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsx)(oR,{value:i,onChange:s,onKeyDown:e=>{"Enter"===e.key&&i.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:a||!i.trim()||p,style:{padding:"6px 12px",background:p?"#16a34a":i.trim()?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:5,color:i.trim()||p?"#fff":"var(--text-dim)",cursor:a||!i.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":a?"Saving…":"Save"]})]})}),e.configured&&(0,n.jsx)("button",{onClick:g,disabled:c,style:{alignSelf:"flex-start",padding:"5px 12px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:5,color:"#ef4444",cursor:c?"not-allowed":"pointer",fontSize:12},children:c?"Removing…":"Disconnect"})]})}function oq({id:e,size:t}){let r=oC[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 oV({oauthProviders:e,apiKeyProviders:t,onSelectOAuth:r,onSelectApiKey:i,onAddCustom:s,onDiscover:a,onAddPreset:d,configuredProviderIds:c,onClose:u}){let{pushToast:p}=(0,l.d)(),[h,x]=(0,o.useState)(""),[g,f]=(0,o.useState)({}),[m,v]=(0,o.useState)(null),y=(0,o.useRef)(null);(0,o.useEffect)(()=>{setTimeout(()=>y.current?.focus(),30)},[]);let b=h.trim().toLowerCase(),j=oS.filter(e=>!c.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),T=j.length+k.length+w.length+ +!!S+ +!!C,I=async e=>{let t=(g[e]??"").trim(),r=oT(e);if(!t)return void p(`Enter an API key for ${r?.displayName??e}`,"error");if(!r)return void p(`Unknown preset: ${e}`,"error");v(e);try{await d(e,t),u()}catch(e){p(e instanceof Error?e.message:String(e),"error")}finally{v(null)}},z={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&&u()},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:h,onChange:e=>x(e.target.value),onKeyDown:e=>{"Escape"===e.key&&u()},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===T?(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=g[e.id]??"",r=m===e.id;return(0,n.jsxs)("div",{style:{...z,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)(oq,{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=>{f(r=>({...r,[e.id]:t.target.value}))},onKeyDown:r=>{"Enter"===r.key&&t.trim()&&I(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:()=>I(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)}),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:()=>{s(),u()},style:z,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:()=>{a(),u()},style:z,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),u()},style:z,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)(oq,{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),u()},style:z,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)(oq,{id:e.id,size:28})]},e.id))]})})]})})}function oJ({existingProviders:e,onImport:t,onClose:r}){let{pushToast:i}=(0,l.d)(),[s,a]=(0,o.useState)(""),[d,c]=(0,o.useState)(""),[u,p]=(0,o.useState)("custom-provider"),[h,x]=(0,o.useState)(new Set),[g,f]=(0,o.useState)({phase:"idle"}),m=(0,o.useCallback)(async()=>{let e=s.trim();if(e&&"loading"!==g.phase){f({phase:"loading"});try{let t=await fetch("/api/models-config/discover",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:e,apiKey:d,provider:u,enrich:!1})}),r=await t.json();if(!t.ok||!r.ok||!r.models||!r.piModels||!r.endpoint){i(r.error??`HTTP ${t.status}`,"error"),f({phase:"idle"});return}f({phase:"success",endpoint:r.endpoint,models:r.models,piModels:r.piModels}),x(new Set(r.piModels.map(e=>e.id)))}catch(e){i(e instanceof Error?e.message:String(e),"error"),f({phase:"idle"})}}},[d,s,u,i,g.phase]),v="success"===g.phase?g:null,y=h.size,b=!!(v&&u.trim()&&y>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)(oz,{label:"Base URL",children:(0,n.jsx)(oL,{value:s,onChange:a,placeholder:"https://api.example.com",mono:!0})}),(0,n.jsx)(oz,{label:"API Key",children:(0,n.jsx)(oR,{value:d,onChange:c,placeholder:"optional for local providers",mono:!0})}),(0,n.jsx)(oz,{label:"Provider name",children:(0,n.jsx)(oL,{value:u,onChange:p,placeholder:"provider-name",mono:!0})}),(0,n.jsx)("button",{onClick:m,disabled:!s.trim()||"loading"===g.phase,style:{height:31,padding:"0 14px",background:s.trim()&&"loading"!==g.phase?"var(--accent)":"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:5,color:s.trim()&&"loading"!==g.phase?"#fff":"var(--text-dim)",cursor:s.trim()&&"loading"!==g.phase?"pointer":"not-allowed",fontSize:12,fontWeight:600,whiteSpace:"nowrap"},children:"loading"===g.phase?"Fetching...":"Fetch models"})]}),(0,n.jsxs)("div",{style:{flex:1,overflow:"hidden",display:"flex",flexDirection:"column"},children:["idle"===g.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"===g.phase&&(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:"Fetching model catalog..."}),v&&(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:[v.piModels.length," models from ",v.endpoint]}),(0,n.jsx)("button",{onClick:()=>{if(v){if(h.size===v.piModels.length)return void x(new Set);x(new Set(v.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:h.size===v.piModels.length?"Clear":"Select all"})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"auto"},children:v.piModels.map((e,t)=>{let r=v.models[t],o=h.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 x(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:[y," 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(!v||!b)return;let n=s.trim().replace(/\/+$/,""),o=d.trim(),i=Object.entries(e).find(([,e])=>(e.baseUrl??"").replace(/\/+$/,"")===n&&(e.apiKey??"")===o),l=i?.[0]??u.trim(),a=e[l],c=new Map((a?.models??[]).map(e=>[e.id,e])),p=0;for(let e of v.piModels)h.has(e.id)&&!c.has(e.id)&&(c.set(e.id,e),p+=1);t(l,{...a??{},baseUrl:n,api:a?.api??n8(n,l),...o?{apiKey:o}:{},models:Array.from(c.values())},p),r()},disabled:!b,style:{padding:"6px 16px",background:b?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:6,color:b?"#fff":"var(--text-dim)",cursor:b?"pointer":"not-allowed",fontSize:13,fontWeight:600},children:"Import selected"})]})]})]})})}function oG({onClose:e,embedded:t=!1}){let{pushToast:r}=(0,l.d)(),[i,s]=(0,o.useState)({providers:{}}),[a,d]=(0,o.useState)(!0),[c,u]=(0,o.useState)(!1),[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),T=(0,o.useCallback)(()=>{fetch("/api/auth/providers").then(e=>e.json()).then(e=>y(e.providers)).catch(()=>{})},[]),I=(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:{}};s(t);let r=Object.keys(t.providers??{});r.length>0&&m({type:"provider",name:r[0]})}).catch(()=>s({providers:{}})).finally(()=>d(!1)),T(),I()},[T,I]);let z=(0,o.useCallback)(()=>{let e="custom",t=1;for(;i.providers?.[e];)e=`custom-${t++}`;s(t=>({...t,providers:{...t.providers??{},[e]:{baseUrl:""}}})),m({type:"provider",name:e})},[i.providers]),M=(0,o.useCallback)(async(e,t)=>{let r=oT(e);if(!r)throw Error(`Unknown preset: ${e}`);s(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),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?(s(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(i.providers??{}).filter(([,e])=>"codex"!==e.source).map(([e])=>e)),R=(0,o.useCallback)((e,t)=>{s(r=>({...r,providers:{...r.providers??{},[e]:t}}))},[]),W=(0,o.useCallback)((e,t)=>{s(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=>{s(t=>{let r={...t.providers??{}};return delete r[e],{...t,providers:r}}),s(e=>{let t=Object.keys(e.providers??{});return m(t.length>0?{type:"provider",name:t[0]}:null),e})},[]),$=(0,o.useCallback)(e=>{s(t=>{let r=t.providers?.[e]??{},n=[...r.models??[],{id:""}];return{...t,providers:{...t.providers??{},[e]:{...r,models:n}}}}),s(t=>{let r=(t.providers?.[e]?.models?.length??1)-1;return m({type:"model",providerName:e,index:r}),t})},[]),P=(0,o.useCallback)((e,t,r)=>{s(n=>{let o=n.providers?.[e]??{},i=[...o.models??[]];return i[t]=r,{...n,providers:{...n.providers??{},[e]:{...o,models:i}}}})},[]),A=(0,o.useCallback)((e,t)=>{s(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})},[]),B=(0,o.useCallback)((e,t,r)=>{s(r=>({...r,providers:{...r.providers??{},[e]:t}})),m({type:"provider",name:e}),g(!1),h(`${r} model${1===r?"":"s"} imported. Click Save to write providers.json.`)},[]),N=(0,o.useCallback)(async()=>{u(!0),h(null),g(!1);try{let e=await fetch("/api/models-config",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({providers:i.providers??{}})}),t=await e.json();!e.ok||t.error?r(t.error??`HTTP ${e.status}`,"error"):(g(!0),r("Models config saved","success"),setTimeout(()=>g(!1),2e3))}catch(e){r(String(e),"error")}finally{u(!1)}},[i,r]),D=Object.entries(i.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)(o_,{provider:e,onRefresh:T},e.id):null}if("apikey"===f.type){let e=b.find(e=>e.id===f.providerId);return e?(0,n.jsx)(oU,{provider:e,onRefresh:I},e.id):null}if("provider"===f.type){let e=i.providers?.[f.name];return e?(0,n.jsx)(oB,{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=i.providers?.[f.providerName],t=e?.models?.[f.index];return t?(0,n.jsx)(oF,{providerName:f.providerName,provider:e,model:t,onChange:e=>P(f.providerName,f.index,e),onDelete:()=>A(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)(oq,{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)(oq,{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)"}}),a?(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:a?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:[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:N,disabled:c||x,style:{position:"relative",padding:"6px 16px",minWidth:92,background:x?"#16a34a":c?"var(--bg-panel)":"var(--accent)",border:"none",borderRadius:6,color:x?"#fff":c?"var(--text-muted)":"#fff",cursor:c||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":c?"Saving…":"Save"})]})]})]})}),k&&(0,n.jsx)(oV,{oauthProviders:v,apiKeyProviders:b,onSelectOAuth:e=>m({type:"oauth",providerId:e}),onSelectApiKey:e=>m({type:"apikey",providerId:e}),onAddCustom:z,onDiscover:()=>C(!0),onAddPreset:M,configuredProviderIds:L,onClose:()=>w(!1)}),S&&(0,n.jsx)(oJ,{existingProviders:i.providers??{},onImport:B,onClose:()=>C(!1)})]})}function oK(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function oY(e){let t=e.sourceInfo?.source,r=e.sourceInfo?.scope;return"user"===r||"user"===t?"global":"project"===r||"project"===t?"project":"path"}function oZ({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 oX({skill:e,cwd:t,onToggle:r,toggling:o}){let i=oY(e),l=!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"===i?"rgba(99,102,241,0.12)":"rgba(120,120,120,0.12)",color:"project"===i?"rgba(99,102,241,0.8)":"var(--text-dim)"},children:i}),(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"===i&&e.startsWith(t)){let r=e.slice(t.length).replace(/^[/\\]/,"");return`./${r}`}return oK(e)}(e.filePath)}),(0,n.jsx)(oZ,{enabled:l,loading:o,onToggle:()=>r(e)})]}),(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 oQ({cwd:e,onInstalled:t}){let{pushToast:r}=(0,l.d)(),[i,s]=(0,o.useState)(""),[a,d]=(0,o.useState)([]),[c,u]=(0,o.useState)(!1),[p,h]=(0,o.useState)(!1),[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 T=(0,o.useCallback)(async e=>{if(e.trim()){u(!0),h(!0),d([]);try{let t=await fetch("/api/skills/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:e.trim()})}),n=await t.json();if(n.error)return void r(n.error,"error");d(n.results??[])}catch(e){r(String(e),"error")}finally{u(!1)}}},[r]),I=(0,o.useCallback)(async n=>{let o=new AbortController;C.current=o,g(n),m("Starting installer"),y(["Starting installer"]);try{let i=await fetch("/api/skills/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({package:n,scope:k,cwd:e,stream:!0}),signal:o.signal});if(!i.ok||!i.body){let e=await i.json().catch(()=>null);r(e?.error??`HTTP ${i.status}`,"error");return}let l=i.body.getReader(),s=new TextDecoder,a="",d=!1,c=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?(d=!0,m("Installed"),y(e=>[...e,"Installed"].slice(-8))):"error"===e.type&&r(e.error??"Install failed","error")};for(;;){let{value:e,done:t}=await l.read(),r=(a+=s.decode(e??new Uint8Array,{stream:!t})).split("\n");for(let e of(a=r.pop()??"",r))e.trim()&&c(JSON.parse(e));if(t)break}a.trim()&&c(JSON.parse(a)),d&&(j(e=>new Set(e).add(n)),r("Skill installed","success"),t())}catch(e){o.signal.aborted?(m("Canceled"),y(e=>[...e,"Canceled"].slice(-8))):r(String(e),"error")}finally{C.current===o&&(C.current=null),g(null)}},[e,t,r,k]),z=(0,o.useCallback)(()=>{C.current?.abort()},[]),M="global"===k?"~/.codex/skills/":`${oK(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:i,onChange:e=>s(e.target.value),onKeyDown:e=>{"Enter"===e.key&&T(i)},placeholder:"e.g. react, testing, deploy",style:{flex:1,padding:"7px 10px",fontSize:13,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",outline:"none"}}),(0,n.jsx)("button",{onClick:()=>T(i),disabled:c||!i.trim(),style:{padding:"7px 16px",fontSize:13,borderRadius:6,border:"none",background:"var(--accent)",color:"#fff",cursor:c||!i.trim()?"not-allowed":"pointer",opacity:c||!i.trim()?.5:1,flexShrink:0},children:c?"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]})]}),x&&(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:x})]}),(0,n.jsx)("button",{onClick:z,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}`))})]})]}),a.length>0?(0,n.jsx)("div",{style:{flex:1,overflowY:"auto"},children:a.map(e=>{let t=b.has(e.package),r=x===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!==x||I(e.package)},disabled:t||null!==x,style:{flexShrink:0,padding:"5px 14px",fontSize:12,fontWeight:500,borderRadius:5,border:"1px solid var(--border)",cursor:r?"wait":t||null!==x?"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)})}):p&&!c?(0,n.jsx)("div",{style:{fontSize:13,color:"var(--text-dim)",lineHeight:1.8},children:"No skills found for that query."}):!c&&(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 o0({cwd:e,onClose:t,embedded:r=!1}){let{pushToast:i}=(0,l.d)(),[s,a]=(0,o.useState)([]),[d,c]=(0,o.useState)(!0),[u,p]=(0,o.useState)(!1),[h,x]=(0,o.useState)(null),[g,f]=(0,o.useState)(new Set),[m,v]=(0,o.useState)(!1),y=(0,o.useCallback)(()=>{c(!0),p(!1),fetch(`/api/skills?cwd=${encodeURIComponent(e)}`).then(e=>e.json()).then(e=>{if(e.error){p(!0),i(e.error,"error");return}let t=e.skills??[];a(t),t.length>0&&!h&&x(t[0].filePath)}).catch(e=>{p(!0),i(String(e),"error")}).finally(()=>c(!1))},[e,i,h]);(0,o.useEffect)(()=>{y()},[e]);let b=(0,o.useCallback)(async e=>{let t=!e.disableModelInvocation;f(t=>new Set(t).add(e.filePath));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 i(n.error??`HTTP ${r.status}`,"error");a(r=>r.map(r=>r.filePath===e.filePath?{...r,disableModelInvocation:t}:r)),i(t?"Skill enabled":"Skill disabled","success")}catch(e){i(String(e),"error")}finally{f(t=>{let r=new Set(t);return r.delete(e.filePath),r})}},[i]),j=s.find(e=>e.filePath===h)??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:oK(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:d?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:"Loading…"}):u?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"var(--text-dim)"},children:"Could not load skills"}):0===s.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=s.filter(e=>oY(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&&h===e.filePath,r=e.disableModelInvocation;return(0,n.jsxs)("div",{onClick:()=>{x(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)(oQ,{cwd:e,onInstalled:()=>{y()}}):d?null:j?(0,n.jsx)(oX,{skill:j,cwd:e,onToggle:b,toggling:g.has(j.filePath)},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"})})]})})}async function o1(e){let t=e.trim();if(!t)throw Error("Nothing to copy");if(navigator.clipboard?.writeText)return void await navigator.clipboard.writeText(t);let r=document.createElement("textarea");r.value=t,r.style.position="fixed",r.style.inset="0",r.style.opacity="0",document.body.appendChild(r),r.focus(),r.select();let n=document.execCommand("copy");if(document.body.removeChild(r),!n)throw Error("Clipboard copy failed")}function o2({text:e,label:t="Copy",title:r,onCopied:i,onError:l}){let[s,a]=(0,o.useState)(!1);(0,o.useEffect)(()=>{if(!s)return;let e=setTimeout(()=>a(!1),1500);return()=>clearTimeout(e)},[s]);let d=(0,o.useCallback)(async()=>{try{await o1(e),a(!0),i?.()}catch(e){l?.(e instanceof Error?e:Error(String(e)))}},[i,l,e]);return(0,n.jsx)("button",{type:"button",onClick:()=>void d(),title:r??(s?"Copied":t),style:{height:24,padding:"0 8px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg-hover)",color:s?"#22c55e":"var(--text-muted)",fontSize:10,fontWeight:600,cursor:"pointer",flexShrink:0},children:s?"Copied":t})}r(41463);let o4="annodex im-gateway";function o5({cwd:e,embedded:t=!1}){var r,i;let s,{pushToast:a}=(0,l.d)(),[d,c]=(0,o.useState)(null),[u,p]=(0,o.useState)(null),[h,x]=(0,o.useState)(null),[g,f]=(0,o.useState)(""),[m,v]=(0,o.useState)(""),[y,b]=(0,o.useState)(!0),[j,k]=(0,o.useState)(""),[w,S]=(0,o.useState)(""),[C,T]=(0,o.useState)(null),[I,z]=(0,o.useState)(null),[M,L]=(0,o.useState)([]),[R,W]=(0,o.useState)(null),[E,$]=(0,o.useState)(!1),[P,A]=(0,o.useState)(!1),[B,N]=(0,o.useState)(!1),D=(0,o.useCallback)(async()=>{try{let e=await fetch("/api/im/gateway-status",{cache:"no-store"}),t=await e.json();if(!e.ok||!t.gateway)return;x(t.gateway)}catch{}},[]),O=(0,o.useCallback)(async()=>{try{let e=await fetch("/api/models",{cache:"no-store"}),t=await e.json(),r=(t.modelList??[]).map(e=>({provider:e.provider,modelId:e.id,name:e.name||e.id}));L(r),W(t.defaultModel??null)}catch{}},[]),H=(0,o.useCallback)(async()=>{if(!e)return void c(null);$(!0);try{let t=await fetch(`/api/im/project?cwd=${encodeURIComponent(e)}`,{cache:"no-store"}),r=await t.json();if(!t.ok||!r.config)throw Error(r.error??`HTTP ${t.status}`);c(r.config),p(r.gatewayToken??null),f(r.config.botId),b(r.config.requireMentionInGroup),k(r.config.boundChatId??""),S(r.config.allowedUsers.join("\n")),T(r.config.modelProvider??null),z(r.config.modelId??null),v("")}catch(e){a(e instanceof Error?e.message:String(e),"error")}finally{$(!1)}},[e,a]);(0,o.useEffect)(()=>{H(),O()},[H,O]),(0,o.useEffect)(()=>{if(!e||!d?.enabled)return void x(null);D();let t=setInterval(()=>{D()},12e3);return()=>clearInterval(t)},[d?.enabled,e,D]);let F=(0,o.useCallback)(async t=>{if(e){A(!0);try{let r=await fetch("/api/im/project",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,...t})}),n=await r.json();if(!r.ok||!n.config)throw Error(n.error??`HTTP ${r.status}`);c(n.config),p(n.gatewayToken??null),f(n.config.botId),b(n.config.requireMentionInGroup),k(n.config.boundChatId??""),S(n.config.allowedUsers.join("\n")),T(n.config.modelProvider??null),z(n.config.modelId??null),v(""),a(n.summary??"IM settings saved.","success")}catch(e){a(e instanceof Error?e.message:String(e),"error")}finally{A(!1)}}},[e,a]),_=(0,o.useCallback)(e=>({enabled:e,botId:g.trim(),requireMentionInGroup:y,boundChatId:j.trim()||null,allowedUsers:w.split(/\r?\n/).map(e=>e.trim()).filter(Boolean),modelProvider:C?.trim()||null,modelId:I?.trim()||null,...m.trim()?{botSecret:m.trim()}:{}}),[w,g,m,j,I,C,y]),U=(0,o.useCallback)(e=>{F(_(e))},[_,F]),q=(0,o.useCallback)(async()=>{if(e&&d?.sessionId&&window.confirm("Reset the IM Codex thread for this project?\n\nThis deletes ~/.config/annodex/im-sessions/<project>.json and stops the in-memory IM session. WeCom pairing and bot settings are kept. The next IM message starts a fresh thread with the current IM system prompt.")){N(!0);try{let t=await fetch(`/api/im/project?cwd=${encodeURIComponent(e)}`,{method:"DELETE"}),r=await t.json();if(!t.ok||!r.config)throw Error(r.error??`HTTP ${t.status}`);c(r.config),p(r.gatewayToken??null),a(r.summary??"IM thread reset.","success")}catch(e){a(e instanceof Error?e.message:String(e),"error")}finally{N(!1)}}},[d?.sessionId,e,a]);if(!e)return(0,n.jsx)(ie,{label:"Select a project to configure WeCom IM."});if(E&&!d)return(0,n.jsx)(ie,{label:"Loading IM settings..."});let V=d?.enabled??!1,J=C&&I?`${C}:${I}`:"",G=R?(r=R.provider,i=R.modelId,(s=M.find(e=>e.provider===r&&e.modelId===i))?s.name:i):"global default";return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8,paddingTop:12*!!t},children:[(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-panel)",padding:12,display:"flex",flexDirection:"column",gap:12},children:[(0,n.jsx)(o8,{label:"WeCom bot for this project",description:V?"Gateway can connect this project directory to your WeCom AI bot.":"Off — enable to bind a WeCom bot to this project cwd.",checked:V,disabled:P,onChange:U}),V?(0,n.jsxs)(n.Fragment,{children:[h?(0,n.jsx)(o6,{status:h}):null,(0,n.jsx)(o7,{label:"Bot ID",value:g,onChange:f,placeholder:"From WeCom AI bot console"}),(0,n.jsx)(o7,{label:d?.hasSecret?"Bot secret (leave blank to keep)":"Bot secret",value:m,onChange:v,placeholder:"From WeCom AI bot console",secret:!0}),(0,n.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4,fontSize:11,color:"var(--text-muted)"},children:[(0,n.jsx)("span",{children:"IM model"}),(0,n.jsxs)("select",{value:J,onChange:e=>{let t=e.target.value;if(!t){T(null),z(null);return}let r=t.indexOf(":");r<=0||(T(t.slice(0,r)),z(t.slice(r+1)))},style:io,children:[(0,n.jsxs)("option",{value:"",children:["Global default",R?` (${G})`:""]}),M.map(e=>(0,n.jsxs)("option",{value:`${e.provider}:${e.modelId}`,children:[e.name," (",e.provider,")"]},`${e.provider}:${e.modelId}`))]}),(0,n.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)",lineHeight:1.45},children:"Used when the IM Codex thread starts or resumes. Changing this applies on the next turn after save."})]}),(0,n.jsx)(o8,{label:"Require @mention in group chats",description:"In group chats, users must @ the bot before messages are handled.",checked:y,disabled:P,compact:!0,onChange:b}),(0,n.jsx)(o7,{label:"Bound group chat id (optional)",value:j,onChange:k,placeholder:"Restrict to one group"}),(0,n.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4,fontSize:11,color:"var(--text-muted)"},children:[(0,n.jsx)("span",{children:"Allowed WeCom user ids (one per line)"}),(0,n.jsx)("textarea",{value:w,onChange:e=>S(e.target.value),rows:3,style:ii,placeholder:"Users can also self-pair with the pairing code"})]}),(0,n.jsxs)("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[(0,n.jsx)(o9,{primary:!0,disabled:P,onClick:()=>void F(_(!0)),children:P?"Saving...":"Save IM settings"}),(0,n.jsx)(o9,{disabled:P,onClick:()=>void F({regeneratePairingCode:!0}),children:"Regenerate pairing code"})]})]}):null]}),V&&d?(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-panel)",padding:12,fontSize:11,color:"var(--text-muted)",display:"flex",flexDirection:"column",gap:8},children:[(0,n.jsx)(o3,{label:"Pairing code",value:d.pairingCode,copyLabel:"Copy code"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,flexWrap:"wrap"},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("strong",{style:{color:"var(--text)"},children:"IM session:"})," ",d.sessionId?`${d.sessionId.slice(0,12)}…`:"not started"]}),d.sessionId?(0,n.jsx)(o9,{danger:!0,disabled:P||B,onClick:()=>void q(),children:B?"Resetting...":"Reset IM thread"}):null]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("strong",{style:{color:"var(--text)"},children:"Gateway token:"})," ",u?`${u.slice(0,8)}…`:"created on save"]}),(0,n.jsx)(o3,{label:"Gateway command",value:o4,copyLabel:"Copy command",mono:!0}),(0,n.jsxs)("div",{style:{lineHeight:1.55,color:"var(--text-dim)"},children:["Run ",(0,n.jsx)("code",{style:it,children:"annodex"}),", then in the ",(0,n.jsx)("strong",{style:{color:"var(--text-muted)",fontWeight:600},children:"same Linux account"})," run"," ",(0,n.jsx)("code",{style:it,children:o4})," (or ",(0,n.jsx)("code",{style:it,children:"annodex-im-gateway"}),"). The gateway reads enabled projects and bot secrets from the local annodex API — you do not copy secret files to the gateway machine."]}),(0,n.jsxs)("div",{style:{lineHeight:1.55,color:"var(--text-dim)"},children:["Pairing and allowlist: ",(0,n.jsxs)("code",{style:it,children:[e,"/.annodex/im.json"]})," \xb7 ","Bot secret: server-side ",(0,n.jsx)("code",{style:it,children:"~/.config/annodex/im-secrets/"})," (never committed)."]})]}):null]})}function o6({status:e}){var t,r,o,i;let l=function(e){if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}(e.startedAt),s=e.alive&&e.pid?`pid ${e.pid}${l?` \xb7 since ${l}`:""}`:l?`last started ${l}`:"Run annodex im-gateway in the same Linux account";return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:10,padding:"8px 10px",borderRadius:8,border:`1px solid ${"running"===(t=e.tone)?"rgba(34,197,94,0.28)":"stale"===t?"rgba(245,158,11,0.28)":"rgba(248,113,113,0.28)"}`,background:"running"===(r=e.tone)?"rgba(34,197,94,0.08)":"stale"===r?"rgba(245,158,11,0.08)":"rgba(248,113,113,0.08)"},children:[(0,n.jsx)("span",{"aria-hidden":!0,style:{width:8,height:8,borderRadius:"50%",marginTop:4,flexShrink:0,background:"running"===(o=e.tone)?"#22c55e":"stale"===o?"#f59e0b":"#f87171"}}),(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:11,fontWeight:650,color:"running"===(i=e.tone)?"#22c55e":"stale"===i?"#f59e0b":"#f87171"},children:e.label}),(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:3,lineHeight:1.45},children:s})]})]})}function o3({label:e,value:t,copyLabel:r,mono:o}){let{pushToast:i}=(0,l.d)();return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsxs)("strong",{style:{color:"var(--text)"},children:[e,":"]})," ",(0,n.jsx)("code",{style:{...it,...o?{wordBreak:"break-all"}:{}},children:t})]}),(0,n.jsx)(o2,{text:t,label:r,onCopied:()=>i(`${e} copied.`,"success"),onError:e=>i(e.message,"error")})]})}function o8({label:e,description:t,checked:r,disabled:o,compact:i,onChange:l}){return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:i?"2px 0":"10px 12px",borderRadius:8*!i,border:i?"none":`1px solid ${r?"color-mix(in srgb, var(--accent) 35%, var(--border))":"var(--border)"}`,background:i?"transparent":r?"color-mix(in srgb, var(--accent) 8%, var(--bg-panel))":"var(--bg)"},children:[(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:i?11:13,fontWeight:i?500:650,color:"var(--text)"},children:e}),t?(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",marginTop:4,lineHeight:1.45},children:t}):null]}),(0,n.jsx)("button",{type:"button",role:"switch","aria-checked":r,disabled:o,onClick:()=>l(!r),style:{position:"relative",width:44,height:26,borderRadius:999,border:"none",flexShrink:0,background:r?"var(--accent)":"color-mix(in srgb, var(--text-dim) 35%, var(--border))",cursor:o?"default":"pointer",opacity:o?.55:1,transition:"background 0.15s",padding:0},children:(0,n.jsx)("span",{style:{position:"absolute",top:3,left:r?21:3,width:20,height:20,borderRadius:"50%",background:"#fff",boxShadow:"0 1px 3px rgba(0,0,0,0.18)",transition:"left 0.15s"}})})]})}function o7({label:e,value:t,onChange:r,placeholder:o,secret:i}){return(0,n.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4,fontSize:11,color:"var(--text-muted)"},children:[(0,n.jsx)("span",{children:e}),(0,n.jsx)("input",{type:i?"password":"text",value:t,onChange:e=>r(e.target.value),placeholder:o,style:ir})]})}function o9({children:e,disabled:t,primary:r,danger:o,onClick:i}){return(0,n.jsx)("button",{type:"button",disabled:t,onClick:i,style:{height:28,padding:"0 10px",borderRadius:6,border:r?"none":o?"1px solid rgba(248,113,113,0.45)":"1px solid var(--border)",background:r?"var(--accent)":o?"rgba(248,113,113,0.08)":"var(--bg-hover)",color:r?"#fff":o?"#f87171":"var(--text)",fontSize:11,fontWeight:r?600:400,cursor:t?"default":"pointer",opacity:t?.55:1},children:e})}function ie({label:e}){return(0,n.jsx)("div",{style:{border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",padding:"18px 10px",color:"var(--text-dim)",fontSize:12,textAlign:"center"},children:e})}let it={fontFamily:"var(--font-mono)",fontSize:"0.95em"},ir={height:30,padding:"0 8px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:12,fontFamily:"var(--font-mono)"},io={...ir,height:32,fontFamily:"inherit"},ii={padding:"8px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:12,fontFamily:"var(--font-mono)",resize:"vertical"};function il({activeCwd:e,onSelectProject:t,onProjectsChanged:r}){let{pushToast:i}=(0,l.d)(),[s,a]=(0,o.useState)([]),[d,u]=(0,o.useState)(!0),[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,w]=(0,o.useState)(new Set),S=(0,o.useRef)(null),C=(0,o.useCallback)(async()=>{try{u(!0);let e=await fetch("/api/projects"),t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);a(t.projects??[])}catch(e){i(e instanceof Error?e.message:String(e),"error")}finally{u(!1)}},[i]);(0,o.useEffect)(()=>{C()},[C]);let T=(0,o.useMemo)(()=>({projects:s.length,chats:s.reduce((e,t)=>e+t.chatCount,0)}),[s]),I=(0,o.useCallback)(async()=>{let e=p.trim();if(e){m("add");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),i("Project added.","success"),C()}catch(e){i(e instanceof Error?e.message:String(e),"error")}finally{m(null)}}},[C,r,t,p,i]),z=(0,o.useCallback)(async e=>{m("add");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),i("Project added.","success"),C()}catch(e){i(e instanceof Error?e.message:String(e),"error")}finally{m(null)}},[C,r,t,i]),M=(0,o.useCallback)(async e=>{m(`rename:${e}`);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(""),i("Project renamed.","success"),await C(),r?.()}catch(e){i(e instanceof Error?e.message:String(e),"error")}finally{m(null)}},[C,r,i,b]),L=(0,o.useCallback)(async e=>{m(`remove:${e}`);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}`);i("Project removed.","success"),await C(),r?.()}catch(e){i(e instanceof Error?e.message:String(e),"error")}finally{m(null)}},[C,r,i]),R=(0,o.useCallback)(e=>{y(e.cwd),j(e.name??e.displayName),window.setTimeout(()=>S.current?.select(),0)},[]),W=(0,o.useCallback)(e=>{w(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]);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:[T.projects," projects / ",T.chats," chats"]})]}),(0,n.jsx)("button",{type:"button",onClick:()=>void C(),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&&I()},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 I(),style:{height:32,padding:"0 12px",border:"none",borderRadius:6,background:p.trim()?"var(--accent)":"var(--bg-hover)",color:p.trim()?"#fff":"var(--text-dim)",cursor:p.trim()?"pointer":"default",fontSize:12,fontWeight:650},children:"Add"})]})}),(0,n.jsx)("div",{style:{border:"1px solid var(--border)",borderRadius:8,overflow:"hidden"},children:d?(0,n.jsx)("div",{style:{padding:16,color:"var(--text-muted)",fontSize:12},children:"Loading..."}):0===s.length?(0,n.jsx)("div",{style:{padding:16,color:"var(--text-muted)",fontSize:12},children:"No projects yet."}):s.map(r=>{var o;let i,l=r.cwd===e,s=v===r.cwd,a=k.has(r.cwd),d=r.lastAccessed??r.created??null;return(0,n.jsxs)("div",{style:{borderBottom:"1px solid var(--border)",background:l?"var(--bg-selected)":"var(--bg)"},children:[(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) auto",gap:12,alignItems:"center",padding:"12px 14px"},children:[(0,n.jsxs)("div",{style:{minWidth:0},children:[s?(0,n.jsx)("input",{ref:S,value:b,onChange:e=>j(e.target.value),onKeyDown:e=>{"Enter"===e.key&&M(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()}(d),r.exists?"":" / path missing"]})]}),(0,n.jsx)("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap",justifyContent:"flex-end"},children:s?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",disabled:f===`rename:${r.cwd}`,onClick:()=>void M(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.jsxs)("button",{type:"button",onClick:()=>W(r.cwd),"aria-expanded":a,style:{height:28,padding:"0 9px",border:"1px solid var(--border)",borderRadius:6,background:a?"var(--bg-selected)":"var(--bg-panel)",color:a?"var(--accent)":"var(--text-muted)",cursor:"pointer",fontSize:12,display:"inline-flex",alignItems:"center",gap:4},children:[(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:a?"rotate(90deg)":"none",transition:"transform 0.15s",flexShrink:0},children:(0,n.jsx)("polyline",{points:"3 2 7 5 3 8"})}),"WeCom IM"]}),(0,n.jsx)("button",{type:"button",onClick:()=>R(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 L(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"})]})})]}),a&&(0,n.jsx)("div",{style:{padding:"0 14px 14px",borderTop:"1px solid var(--border)",background:"var(--bg-panel)"},children:(0,n.jsx)(o5,{cwd:r.cwd,embedded:!0})})]},r.cwd)})})]}),(0,n.jsx)(c,{open:x,initialPath:e,onClose:()=>g(!1),onSelect:e=>void z(e)})]})}function is({title:e,hint:t,checked:r,disabled:o,onChange:i}){return(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",gap:12,alignItems:"center",border:"1px solid var(--border)",borderRadius:10,padding:"12px 14px",minWidth:0},children:[(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)"},children:e}),t?(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",marginTop:4,lineHeight:1.5},children:t}):null]}),(0,n.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:8,color:"var(--text)",fontSize:12,flexShrink:0},children:[(0,n.jsx)("input",{type:"checkbox",checked:r,disabled:o,onChange:e=>i(e.target.checked)}),(0,n.jsx)("span",{style:{whiteSpace:"nowrap"},children:r?"On":"Off"})]})]})}function ia({children:e}){return(0,n.jsx)("label",{style:{display:"grid",gap:6,fontSize:12,color:"var(--text-muted)",minWidth:0},children:(0,n.jsx)("span",{children:e})})}let id={width:"100%",minWidth:0,maxWidth:"100%",boxSizing:"border-box",borderRadius:8,border:"1px solid var(--border)",background:"var(--bg-input)",color:"var(--text)",padding:"8px 10px"},ic={minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"};function iu({label:e,busyLabel:t,busy:r,onClick:o,quiet:i}){return(0,n.jsx)("button",{type:"button",onClick:o,disabled:r,style:{borderRadius:8,border:i?"none":"1px solid var(--border)",background:i?"transparent":"var(--bg-secondary)",color:i?"var(--text-dim)":"var(--text)",padding:i?0:"8px 10px",cursor:r?"wait":"pointer",opacity:r?.7:1,fontSize:i?11:12},children:r?t??e:e})}function ip({cwd:e,sessionId:t,embedded:r,onClose:i}){let{pushToast:s}=(0,l.d)(),[a,d]=(0,o.useState)([]),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(!1),[x,g]=(0,o.useState)(!1),[f,m]=(0,o.useState)(!0),[v,y]=(0,o.useState)(!1),[b,j]=(0,o.useState)(null),[k,w]=(0,o.useState)([]),[S,C]=(0,o.useState)([]),[T,I]=(0,o.useState)([]),[z,M]=(0,o.useState)(""),[L,R]=(0,o.useState)(""),[W,E]=(0,o.useState)(""),[$,P]=(0,o.useState)([]),[A,B]=(0,o.useState)(!1),N=(0,o.useMemo)(()=>a.find(e=>e.id===c)??null,[a,c]),D=e?"project":"global",O=(0,o.useMemo)(()=>[{id:"annodex-memory",name:"Annodex Memory",description:"Project working memory MCP server (retain, recall, reflect)",scope:D,enabled:!0,source:"annodex",transport:{type:"stdio",command:"annodex-memory-mcp",args:[]},notes:"Requires annodex to be running. Enable per session from chat or below."},{id:"browser-use",name:"Browser Use",description:"Browser automation MCP server preset",scope:D,enabled:!0,transport:{type:"stdio",command:"uvx",args:["browser-use","mcp"]},notes:"Adjust command/args in Advanced if your install differs."},{id:"generic-mcp",name:"Generic MCP Server",description:"Manual stdio/http MCP endpoint",scope:D,enabled:!1,transport:{type:"stdio",command:"node",args:["server.js"]},notes:"Starting point for custom MCP servers."}],[D]),H=(0,o.useCallback)(async()=>{m(!0);try{let t=await fetch(`/api/extensions${e?`?cwd=${encodeURIComponent(e)}`:""}`,{cache:"no-store"}),r=await t.json().catch(()=>({}));if(!t.ok)throw Error(r.error??`HTTP ${t.status}`);let n=r.extensions??[];d(n),u(e=>e&&n.some(t=>t.id===e)?e:n[0]?.id??null)}catch(e){s(e instanceof Error?e.message:String(e),"error")}finally{m(!1)}},[e,s]),F=(0,o.useCallback)(async()=>{y(!0);try{let e=await fetch("/api/extensions/discover",{cache:"no-store"}),t=await e.json().catch(()=>({}));if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);w(t.mcp??[]),C(t.marketplaces??[]),I(t.plugins??[])}catch(e){s(e instanceof Error?e.message:String(e),"error")}finally{y(!1)}},[s]);(0,o.useEffect)(()=>{H()},[H]);let _=(0,o.useCallback)(async()=>{if(!t)return void P([]);try{let e=await t0(t,{type:"get_state"});P(e?.enabledExtensions??[])}catch{try{let e=await fetch(`/api/sessions/${encodeURIComponent(t)}?includeState`,{cache:"no-store"}),r=await e.json().catch(()=>({}));P(r.agentState?.state?.enabledExtensions??[])}catch{P([])}}},[t]);(0,o.useEffect)(()=>{_()},[_]);let U=(0,o.useCallback)(async t=>{g(!0);try{let r=await fetch("/api/extensions",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,scope:t.scope??D,extension:t})}),n=await r.json().catch(()=>({}));if(!r.ok)throw Error(n.error??`HTTP ${r.status}`);await H(),s("Extension saved","success")}catch(e){s(e instanceof Error?e.message:String(e),"error")}finally{g(!1)}},[e,D,H,s]),q=(0,o.useCallback)(async e=>{await U({...e,scope:e.scope??D})},[D,U]),V=(0,o.useCallback)(e=>{if(!N)return;let t={...N,...e,transport:{...N.transport,...e.transport??{}}};d(e=>e.map(e=>e.id===t.id?t:e)),U(t)},[U,N]),J=(0,o.useCallback)(async(e,t,r,n=!0)=>{j(e);try{let e=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)}),o=await e.json().catch(()=>({}));if(!e.ok)throw Error(o.error??`HTTP ${e.status}`);n&&await F(),s("Done","success")}catch(e){s(e instanceof Error?e.message:String(e),"error")}finally{j(null)}},[F,s]),G=(0,o.useCallback)(()=>{N&&J(`mcp-install:${N.id}`,"/api/extensions/mcp",{name:N.id,transport:N.transport,env:N.env})},[J,N]),K=(0,o.useCallback)(()=>{N&&J(`mcp-remove:${N.id}`,"/api/extensions/mcp",{action:"remove",name:N.id})},[J,N]),Y=(0,o.useCallback)(()=>{z.trim()&&L.trim()&&J(`marketplace-add:${z.trim()}`,"/api/extensions/plugin-marketplace",{name:z.trim(),source:L.trim(),ref:W.trim()||void 0})},[z,W,L,J]),Z=(0,o.useCallback)(async e=>{if(t){B(!0);try{let r=await fetch("/api/extensions/session",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:t,enabledExtensions:e})}),n=await r.json().catch(()=>({}));if(!r.ok)throw Error(n.error??`HTTP ${r.status}`);P(n.data?.enabledExtensions??e),s("Session extensions updated","success")}catch(e){s(e instanceof Error?e.message:String(e),"error")}finally{B(!1)}}},[t,s]),X=(0,o.useCallback)((e,t)=>{Z(t?[...new Set([...$,e])].sort():$.filter(t=>t!==e))},[Z,$]),Q=(0,n.jsxs)("div",{style:{width:260,minWidth:260,maxWidth:260,borderRight:"1px solid var(--border)",display:"flex",flexDirection:"column",minHeight:0,overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:14,borderBottom:"1px solid var(--border)",display:"grid",gap:10},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:"Extensions"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",marginTop:4},children:"Add MCP capabilities for this project. Toggle them on from chat or the panel on the right."})]}),(0,n.jsxs)("div",{style:{display:"grid",gap:8},children:[(0,n.jsx)(iu,{label:"+ Annodex Memory",onClick:()=>void q(O[0])}),(0,n.jsx)(iu,{label:"+ Browser Use",onClick:()=>void q(O[1])}),(0,n.jsx)(iu,{label:"+ Custom MCP",onClick:()=>void q(O[2])})]})]}),(0,n.jsxs)("div",{style:{minHeight:0,overflowY:"auto",overflowX:"hidden",padding:10,display:"grid",gap:8},children:[a.map(e=>{let t=e.id===c,r=$.includes(e.id),o=r?"In session":e.enabled?"Saved on":"Saved off";return(0,n.jsxs)("button",{type:"button",onClick:()=>{u(e.id),h(!1)},style:{textAlign:"left",padding:12,borderRadius:10,border:`1px solid ${t?"var(--accent)":"var(--border)"}`,background:t?"color-mix(in srgb, var(--accent) 10%, transparent)":"transparent",color:"var(--text)",cursor:"pointer",display:"grid",gap:4,minWidth:0,maxWidth:"100%",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",gap:8,minWidth:0},children:[(0,n.jsx)("span",{style:{fontSize:13,fontWeight:700,...ic},title:e.name,children:e.name}),(0,n.jsx)("span",{style:{fontSize:11,color:r?"var(--accent)":"var(--text-dim)",flexShrink:0},children:o})]}),e.description?(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-muted)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:e.description,children:e.description}):null]},e.id)}),f||0!==a.length?null:(0,n.jsx)("div",{style:{padding:14,border:"1px dashed var(--border)",borderRadius:10,color:"var(--text-muted)",fontSize:12},children:"No extensions yet. Add Annodex Memory or another preset to begin."})]})]}),ee=(0,n.jsx)("div",{style:{flex:1,minWidth:0,minHeight:0,overflowY:"auto",overflowX:"hidden"},children:(0,n.jsx)("div",{style:{padding:18,display:"grid",gap:14,maxWidth:640},children:f?(0,n.jsx)("div",{style:{color:"var(--text-muted)",fontSize:13},children:"Loading extensions…"}):N?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{style:{display:"grid",gap:6},children:[(0,n.jsx)("div",{style:{fontSize:18,fontWeight:700,color:"var(--text)"},children:N.name}),(0,n.jsx)("div",{style:{fontSize:13,color:"var(--text-muted)",lineHeight:1.55},children:N.description||"No description provided."})]}),(0,n.jsx)(is,{title:"Saved for this project",hint:"When on, annodex registers this MCP server and syncs it to Codex.",checked:!!N.enabled,onChange:e=>V({enabled:e})}),t?(0,n.jsx)(is,{title:"Enabled in current chat",hint:"Session-only. You can also toggle extensions from the chat input bar.",checked:$.includes(N.id),disabled:A,onChange:e=>X(N.id,e)}):(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:"Open a chat to bind extensions to the active session."}),(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)"},children:x?"Saving…":A?"Updating session…":"Changes save automatically."}),(0,n.jsxs)("div",{style:{borderTop:"1px solid var(--border)",paddingTop:12},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>h(e=>!e),style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"8px 0",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:600,textAlign:"left"},children:[(0,n.jsx)("span",{style:{display:"inline-block",transform:p?"rotate(90deg)":"none",transition:"transform 0.12s"},children:"▸"}),"Advanced",(0,n.jsx)("span",{style:{fontWeight:400,color:"var(--text-dim)"},children:"connection, Codex CLI, plugins"})]}),p?(0,n.jsxs)("div",{style:{display:"grid",gap:14,marginTop:8},children:[(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:12},children:[(0,n.jsxs)(ia,{children:["ID",(0,n.jsx)("input",{value:N.id,onChange:e=>V({id:e.target.value}),style:id})]}),(0,n.jsxs)(ia,{children:["Name",(0,n.jsx)("input",{value:N.name,onChange:e=>V({name:e.target.value}),style:id})]})]}),(0,n.jsxs)(ia,{children:["Description",(0,n.jsx)("input",{value:N.description??"",onChange:e=>V({description:e.target.value}),style:id})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:12},children:[(0,n.jsxs)(ia,{children:["Scope",(0,n.jsxs)("select",{value:N.scope??D,onChange:e=>V({scope:e.target.value}),style:id,children:[(0,n.jsx)("option",{value:"global",children:"Global"}),(0,n.jsx)("option",{value:"project",children:"Project"})]})]}),(0,n.jsxs)(ia,{children:["Transport",(0,n.jsxs)("select",{value:N.transport.type,onChange:e=>V({transport:"http"===e.target.value?{type:"http",url:N.transport.url??"http://localhost:3000/mcp"}:{type:"stdio",command:N.transport.command??"node",args:N.transport.args??[]}}),style:id,children:[(0,n.jsx)("option",{value:"stdio",children:"stdio"}),(0,n.jsx)("option",{value:"http",children:"http"})]})]})]}),"stdio"===N.transport.type?(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:12},children:[(0,n.jsxs)(ia,{children:["Command",(0,n.jsx)("input",{value:N.transport.command??"",onChange:e=>V({transport:{type:"stdio",command:e.target.value}}),style:id})]}),(0,n.jsxs)(ia,{children:["Args",(0,n.jsx)("input",{value:(N.transport.args??[]).join(" "),onChange:e=>V({transport:{type:"stdio",args:e.target.value.split(/\s+/).map(e=>e.trim()).filter(Boolean)}}),style:id})]})]}):(0,n.jsxs)(ia,{children:["URL",(0,n.jsx)("input",{value:N.transport.url??"",onChange:e=>V({transport:{type:"http",url:e.target.value}}),style:id})]}),(0,n.jsxs)(ia,{children:["Notes",(0,n.jsx)("textarea",{value:N.notes??"",onChange:e=>V({notes:e.target.value}),rows:3,style:{...id,resize:"vertical",padding:"10px 12px"}})]}),(0,n.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[(0,n.jsx)(iu,{label:"Install to Codex MCP",busyLabel:"Installing MCP…",busy:b===`mcp-install:${N.id}`,onClick:G}),(0,n.jsx)(iu,{label:"Remove from Codex MCP",busyLabel:"Removing MCP…",busy:b===`mcp-remove:${N.id}`,onClick:K})]}),(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:10,padding:14,display:"grid",gap:12},children:[(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",gap:12,alignItems:"flex-start"},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Codex discovery"}),(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:4,lineHeight:1.5},children:"Inspect local Codex CLI MCP servers, plugin marketplaces, and plugins."})]}),(0,n.jsx)(iu,{label:"Inspect",busyLabel:"Inspecting…",busy:v,onClick:()=>void F()})]}),(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,padding:12,display:"grid",gap:10},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:700,color:"var(--text)"},children:"Add plugin marketplace"}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(0, 1.4fr) minmax(0, 0.8fr) auto",gap:8},children:[(0,n.jsx)("input",{value:z,onChange:e=>M(e.target.value),placeholder:"name",style:id}),(0,n.jsx)("input",{value:L,onChange:e=>R(e.target.value),placeholder:"owner/repo or local path",style:id}),(0,n.jsx)("input",{value:W,onChange:e=>E(e.target.value),placeholder:"ref (optional)",style:id}),(0,n.jsx)(iu,{label:"Add",busyLabel:"Adding…",busy:b===`marketplace-add:${z.trim()}`,onClick:Y})]})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:12},children:[(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6,color:"var(--text)"},children:["MCP servers (",k.length,")"]}),(0,n.jsx)("div",{style:{display:"grid",gap:6},children:0===k.length?(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)"},children:"Run Inspect to load Codex MCP state."}):k.map(e=>(0,n.jsx)("div",{style:{border:"1px solid var(--border)",borderRadius:8,padding:10,minWidth:0,overflow:"hidden"},children:(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",gap:8,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:700,color:"var(--text)",...ic},title:e.name,children:e.name}),(0,n.jsx)(iu,{label:"Remove",busyLabel:"Removing…",busy:b===`mcp-remove:${e.name}`,quiet:!0,onClick:()=>void J(`mcp-remove:${e.name}`,"/api/extensions/mcp",{action:"remove",name:e.name})})]})},e.name))})]}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6,color:"var(--text)"},children:["Plugin marketplaces (",S.length,")"]}),(0,n.jsx)("div",{style:{display:"grid",gap:6},children:0===S.length?(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)"},children:"Run Inspect to load marketplaces."}):S.map(e=>(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,padding:10,minWidth:0,overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",gap:8,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:700,color:"var(--text)",...ic},title:e.name,children:e.name}),(0,n.jsx)(iu,{label:"Remove",busyLabel:"Removing…",busy:b===`marketplace-remove:${e.name}`,quiet:!0,onClick:()=>void J(`marketplace-remove:${e.name}`,"/api/extensions/plugin-marketplace",{action:"remove",name:e.name})})]}),(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",marginTop:4,...ic},title:e.root,children:e.root})]},e.name))})]})]}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6,color:"var(--text)"},children:["Plugins (",T.length,")"]}),(0,n.jsxs)("div",{style:{maxHeight:220,overflowY:"auto",display:"grid",gap:6},children:[0===T.length?(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)"},children:"Run Inspect to load plugins."}):T.slice(0,20).map(e=>(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,padding:10,minWidth:0,overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",gap:8,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:700,color:"var(--text)",...ic},title:e.plugin,children:e.plugin}),(0,n.jsxs)("div",{style:{display:"flex",gap:8},children:["installed"!==e.status?(0,n.jsx)(iu,{label:"Install",busyLabel:"Installing…",busy:b===`plugin-add:${e.plugin}`,quiet:!0,onClick:()=>void J(`plugin-add:${e.plugin}`,"/api/extensions/plugin",{plugin:e.plugin,marketplace:e.marketplace||void 0})}):null,(0,n.jsx)(iu,{label:"Remove",busyLabel:"Removing…",busy:b===`plugin-remove:${e.plugin}`,quiet:!0,onClick:()=>void J(`plugin-remove:${e.plugin}`,"/api/extensions/plugin",{action:"remove",plugin:e.plugin,marketplace:e.marketplace||void 0})})]})]}),(0,n.jsxs)("div",{style:{fontSize:11,color:"var(--text-dim)",marginTop:4},children:[e.status,e.version?` \xb7 ${e.version}`:""]})]},e.plugin)),T.length>20?(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)"},children:"Showing first 20 plugins."}):null]})]})]})]}):null]})]}):(0,n.jsx)("div",{style:{color:"var(--text-muted)",fontSize:13},children:"Select an extension to configure it."})})});return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",minHeight:0,height:"100%"},children:[r?null:(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 18px",borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:"Extensions"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",marginTop:4},children:"Add MCP servers for this project. Use chat to toggle extensions per session."})]}),i?(0,n.jsx)(iu,{label:"Close",onClick:i}):null]}),(0,n.jsxs)("div",{style:{display:"flex",minHeight:0,flex:1,overflow:"hidden"},children:[Q,ee]})]})}function ih({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 ix(){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 ig(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"})]}):"extensions"===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 2v20"}),(0,n.jsx)("path",{d:"M2 12h20"}),(0,n.jsx)("rect",{x:"4",y:"4",width:"6",height:"6",rx:"1.5"}),(0,n.jsx)("rect",{x:"14",y:"14",width:"6",height:"6",rx:"1.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 im({cwd:e,sessionId:t,generativeUI:r,initialTab:i="projects",onGenerativeUIToggle:l,onClose:s,onModelsChanged:a,onProjectSelect:d,onProjectsChanged:c}){let[u,p]=(0,o.useState)(i);(0,o.useEffect)(()=>{p(i)},[i]),(0,o.useEffect)(()=>{let e=e=>{"Escape"===e.key&&s()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[s]);let h=[{id:"projects",label:"Project",description:e?"Overview, paths, and WeCom IM":"Add or select a project",icon:ig("projects")},{id:"models",label:"Models",description:"~/.config/annodex/providers.json",icon:ig("models")},{id:"skills",label:"Skills",description:e?"Project and global skills":"Select a project first",disabled:!e,icon:ig("skills")},{id:"extensions",label:"Extensions",description:e?"MCP servers and plugins":"Select a project first",disabled:!e,icon:ig("extensions")},{id:"generative-ui",label:"Generative UI",description:r?"Enabled":"Disabled",icon:ig("generative-ui")}],x=h.find(e=>e.id===u)??h[0];return(0,n.jsx)("div",{className:"settings-dialog-backdrop",onClick:e=>{e.target===e.currentTarget&&s()},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)(ix,{})}),(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:15,fontWeight:700,color:"var(--text)",lineHeight:1.25},children:"Settings"}),(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:x.label})]})]}),(0,n.jsx)("button",{type:"button",onClick:s,title:"Close settings","aria-label":"Close settings",style:{width:30,height:30,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:"x"})]}),(0,n.jsxs)("div",{className:"settings-dialog-body",children:[(0,n.jsx)("div",{className:"settings-dialog-tabs",children:h.map(e=>{let t=u===e.id;return(0,n.jsxs)("button",{type:"button",disabled:e.disabled,onClick:()=>p(e.id),className:"settings-dialog-tab",style:{background:t?"var(--bg-selected)":"transparent",color:t?"var(--text)":"var(--text-muted)",opacity:e.disabled?.45:1,cursor:e.disabled?"not-allowed":"pointer"},onMouseEnter:r=>{t||e.disabled||(r.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="transparent")},children:[(0,n.jsx)("span",{style:{flexShrink:0,color:t?"var(--accent)":"currentColor",display:"flex"},children:e.icon}),(0,n.jsxs)("span",{style:{minWidth:0,flex:1},children:[(0,n.jsx)("span",{style:{display:"block",fontSize:12,fontWeight:t?700:600,lineHeight:1.25},children:e.label}),(0,n.jsx)("span",{style:{display:"block",marginTop:2,fontSize:10,color:"var(--text-dim)",lineHeight:1.25,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.description})]})]},e.id)})}),(0,n.jsxs)("div",{className:"settings-dialog-panel",children:["projects"===u&&(0,n.jsx)(il,{activeCwd:e,onSelectProject:d,onProjectsChanged:c}),"models"===u&&(0,n.jsx)(oG,{embedded:!0,onClose:()=>{a?.(),s()}}),"skills"===u&&e&&(0,n.jsx)(o0,{cwd:e,embedded:!0,onClose:s}),"extensions"===u&&e&&(0,n.jsx)(ip,{cwd:e,sessionId:t,embedded:!0,onClose:s}),"generative-ui"===u&&(0,n.jsx)("div",{style:{height:"100%",overflowY:"auto",padding:20},children:(0,n.jsxs)("div",{style:{maxWidth:720,display:"flex",flexDirection:"column",gap:18},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:18,padding:16,border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)",lineHeight:1.35},children:"Generative UI"}),(0,n.jsx)("div",{style:{marginTop:5,fontSize:12,color:"var(--text-muted)",lineHeight:1.55},children:"Render structured widgets and safe visual code blocks directly in chat when the assistant produces UI content."})]}),(0,n.jsx)(ih,{checked:r,onChange:l})]}),(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 iv({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 iy=new Set(["pdf","png","jpg","jpeg","gif","webp","svg","bmp","ico","avif"]);function ib(e){let t=(e.replace(/[?#].*$/,"").replace(/[\\/]+$/,"").split(/[\\/]/).pop()??e).toLowerCase().split(".").pop()??"";return iy.has(t)}function ij(){let e=(0,i.useRouter)(),t=(0,i.useSearchParams)(),{isDark:r,toggleTheme:l}=F(),[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"),[w,S]=(0,o.useState)({generativeUI:!0,autoRestart:!0}),[C,I]=(0,o.useState)(null),[z,M]=(0,o.useState)(!0),L=iv({initialWidth:260,minWidth:180,maxWidth:500,storageKey:"--annodex-sidebar-width"}),R=iv({initialWidth:500,minWidth:300,maxWidth:1200,storageKey:"--annodex-right-panel-width",direction:"left"}),W=(0,o.useRef)(null),E=(0,o.useRef)(null),[$,P]=(0,o.useState)(null),A=(0,o.useRef)(null),[B,N]=(0,o.useState)(!1),[D,O]=(0,o.useState)(""),H=(0,o.useRef)(null),_=(0,o.useRef)(!1),U=(0,o.useCallback)(e=>{P(e)},[]);(0,o.useEffect)(()=>{N(!1)},[s?.id]);let q=(0,o.useCallback)(e=>e?e.name||e.firstMessage.slice(0,80)||e.id.slice(0,12):"",[]),V=(0,o.useCallback)(()=>{s&&(_.current=!1,O(s.name||q(s)),N(!0),setTimeout(()=>H.current?.select(),0))},[q,s]),J=(0,o.useCallback)(async()=>{if(_.current){_.current=!1,N(!1);return}if(!s)return void N(!1);let e=D.trim(),t=q(s);if(N(!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{}},[q,s,D]),G=(0,o.useCallback)(e=>{"Enter"===e.key?(e.preventDefault(),J()):"Escape"===e.key&&(_.current=!0,N(!1))},[J]);(0,o.useEffect)(()=>{let e=!1;return fetch("/api/settings").then(e=>e.ok?e.json():null).then(t=>{e||S(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||I(t)}).catch(()=>{}).finally(()=>{t=!1}))};r();let n=window.setInterval(r,6e4);return()=>{e=!0,window.clearInterval(n)}},[]);let K=(0,o.useCallback)(()=>{let e=!w.generativeUI;S(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=>{S(t=>({...t,..."boolean"==typeof e.settings?.generativeUI?{generativeUI:e.settings.generativeUI}:{}}))}).catch(()=>S(e=>({...e,generativeUI:!e.generativeUI})))},[w.generativeUI]),[Y,Z]=(0,o.useState)(null),X=(0,o.useCallback)(e=>{Z(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),eT=(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),P(null),en(null),e.replace("/workspace",{scroll:!1}))},[e]),eI=(0,o.useCallback)(e=>{eT(e),b(!1),p(e=>e+1)},[eT]),ez=(0,o.useCallback)((t,r=!1)=>{c(null),ek(t.cwd),a(t),x(e=>e+1),P(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),P(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),P(null),en(null),e.replace("/workspace",{scroll:!1})}},[s,e]),eP=(0,o.useCallback)(e=>{ef(t=>t.filter(t=>t.id!==e))},[]),eA=(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})},[]),eB=(0,o.useCallback)((e,t)=>{if(ib(e)||ib(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)},[]),eN=(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,eq=s?q(s):eO?"New chat":"No session",eV=s?.cwd??eO??ej??"",eJ=eV?eV.replace(/\/+$/,"").split(/[\\/]/).filter(Boolean).pop()||eV:"",eG=s?.cwd??ej??eO??void 0,eK=ej??s?.cwd??d??null,eY=(()=>{let e=C?.runtime,t=e?.installedVersion??C?.latest;if(e?.restartPending&&t){let r=!!e.restartStartedAt;return{label:`${r?"Restarting":"Restart queued"} ${t}`,title:[`Current runtime: v${e.version??C?.current??"unknown"}`,`Installed: v${t}`,r?"A replacement server is starting.":"annodex will restart after active sessions become idle."].join("\n"),active:!0}}return C?.updateAvailable&&C.latest?{label:`Update ${C.latest}`,title:`Current: v${C.current}
|
|
264
|
-
Latest: v${C.latest}
|
|
265
|
-
Run: ${C.updateCommand}`,active:!1}:null})(),eZ=(0,o.useCallback)((e="projects")=>{k(e),b(!0)},[]),eX=(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(T,{selectedSessionId:s?.id??null,onSelectSession:ez,onNewSession:eM,initialSessionId:eb,onInitialRestoreDone:eE,refreshKey:u,onSessionDeleted:e$,selectedCwd:s?.cwd??d??ej??null,onCwdChange:eT}),(0,n.jsx)("div",{style:{padding:"8px",flexShrink:0},children:(0,n.jsx)("button",{type:"button",onClick:()=>eZ("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:+!!z,pointerEvents:z?"auto":"none",transition:"opacity 0.25s ease"}}),(0,n.jsx)("div",{className:`sidebar-container${z?" sidebar-open":" sidebar-closed"}`,style:{background:"var(--bg-panel)",borderRight:"1px solid var(--border)",display:"flex",flexDirection:"column",flexShrink:0,zIndex:200,width:L.width,minWidth:L.width,transition:z||L.isResizing?"none":void 0},children:eX}),z&&(0,n.jsx)(nJ,{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:z?"Hide sidebar":"Show sidebar",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="var(--bg-panel)"},children:z?(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,n.jsx)("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]}):(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"3",y1:"6",x2:"21",y2:"6"}),(0,n.jsx)("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),(0,n.jsx)("line",{x1:"3",y1:"18",x2:"21",y2:"18"})]})}),(0,n.jsxs)("div",{className:"topbar-title-area",style:{display:"flex",alignItems:"center",gap:7,minWidth:0,flex:1},children:[(0,n.jsx)("div",{style:{minWidth:0,display:"flex",alignItems:"center",gap:6},children:B&&s?(0,n.jsx)("input",{ref:H,value:D,onChange:e=>O(e.target.value),onKeyDown:G,onBlur:()=>void J(),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:eq,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:eq}),s&&(0,n.jsx)("button",{type:"button",className:"topbar-rename-button",onClick:V,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"})]})})]})}),eJ&&(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:eV||eJ,style:{minWidth:0,maxWidth:"min(280px, 24vw)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-muted)",fontSize:12,lineHeight:1.2},children:eJ})]})]}),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:A,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:$?"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:K,title:`生成式 UI: ${w.generativeUI?"on":"off"}`,"aria-label":`生成式 UI: ${w.generativeUI?"on":"off"}`,style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:28,padding:0,background:w.generativeUI?"var(--bg-selected)":"var(--bg-panel)",border:`1px solid ${w.generativeUI?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,color:w.generativeUI?"var(--accent)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color=w.generativeUI?"var(--accent)":"var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color=w.generativeUI?"var(--accent)":"var(--text-muted)",e.currentTarget.style.background=w.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:$?(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:$}):""===$?(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)(rj,{session:s,newSessionCwd:eO,onAgentEnd:eR,onSessionCreated:eL,onSessionForked:eW,onOpenImage:eN,modelsRefreshKey:m,chatInputRef:W,onSystemPromptChange:U,onSessionStatsChange:X,onContextUsageChange:et,generativeUI:w.generativeUI,onOpenExtensionsSettings:()=>eZ("extensions")},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)(nJ,{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)(nG,{tabs:e_,activeTabId:ed,onSelectTab:ec,onCloseTab:eD})})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"hidden"},children:"files"===ed?eG?(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)(r4,{cwd:eG,onOpenFile:eB,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)(nX,{refreshKey:em,cwd:eG??null}):eU?.filePath?eU.filePath.startsWith("__")?(0,n.jsx)(nq,{filePath:eU.filePath}):(0,n.jsx)(nB,{filePath:eU.filePath,cwd:ej??void 0,onOpenFile:eB}):(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)(nF,{id:e.id,filePath:e.imageSrc??e.filePath,fileName:e.fileName,cwd:eG,galleryItems:e.galleryItems,galleryIndex:e.galleryIndex,active:t===eg.length-1,stackIndex:t,zIndex:700+t,onClose:eP,onFocus:eA,onOpenFile:eB,onOpenImage:eN},e.id)),y&&(0,n.jsx)(im,{cwd:eK,sessionId:s?.id??null,generativeUI:w.generativeUI,initialTab:j,onGenerativeUIToggle:K,onModelsChanged:()=>v(e=>e+1),onProjectSelect:eI,onProjectsChanged:()=>p(e=>e+1),onClose:()=>{b(!1),v(e=>e+1)}})]})}},46653:(e,t,r)=>{"use strict";r.d(t,{d:()=>s,t:()=>l});var n=r(95155),o=r(12115);let i=(0,o.createContext)(null);function l({children:e}){let[t,r]=(0,o.useState)([]),s=(0,o.useRef)(new Map),a=(0,o.useCallback)(e=>{let t=s.current.get(e);t&&(clearTimeout(t),s.current.delete(e)),r(t=>t.filter(t=>t.id!==e))},[]),d=(0,o.useCallback)((e,t="info")=>{let n=e.trim();if(!n)return;let o=`${Date.now()}-${Math.random().toString(36).slice(2,8)}`;r(e=>[...e.slice(-4),{id:o,tone:t,message:n}]);let i=setTimeout(()=>a(o),4500);s.current.set(o,i)},[a]);(0,o.useEffect)(()=>()=>{for(let e of s.current.values())clearTimeout(e);s.current.clear()},[]);let c=(0,o.useMemo)(()=>({pushToast:d}),[d]);return(0,n.jsxs)(i.Provider,{value:c,children:[e,(0,n.jsx)("div",{"aria-live":"polite",style:{position:"fixed",right:16,bottom:16,zIndex:10050,display:"flex",flexDirection:"column",gap:8,maxWidth:"min(420px, calc(100vw - 32px))",pointerEvents:"none"},children:t.map(e=>{var t,r,o;return(0,n.jsx)("div",{role:"status",style:{pointerEvents:"auto",padding:"10px 12px",borderRadius:8,border:`1px solid ${"success"===(t=e.tone)?"rgba(34,197,94,0.35)":"error"===t?"rgba(248,113,113,0.35)":"rgba(96,165,250,0.35)"}`,background:"success"===(r=e.tone)?"color-mix(in srgb, #22c55e 12%, var(--bg-panel))":"error"===r?"color-mix(in srgb, #f87171 12%, var(--bg-panel))":"color-mix(in srgb, #60a5fa 12%, var(--bg-panel))",color:"success"===(o=e.tone)?"#22c55e":"error"===o?"#f87171":"var(--text)",fontSize:12,lineHeight:1.45,boxShadow:"0 8px 24px rgba(0,0,0,0.18)"},children:e.message},e.id)})})]})}function s(){let e=(0,o.useContext)(i);if(!e)throw Error("useToast must be used within ToastProvider");return e}},65673:(e,t,r)=>{"use strict";r.d(t,{C3:()=>n});let n="annodex"},70704:(e,t,r)=>{Promise.resolve().then(r.bind(r,936))}},e=>{e.O(0,[6079,7627,4683,8441,3794,7358],()=>e(e.s=70704)),_N_E=e.O()}]);
|