@seqyuan/annovibe 0.8.23 → 0.8.24
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 +7 -7
- 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/apps/[id]/[[...path]]/route.js +2 -2
- package/.next/server/app/api/apps/route.js +2 -2
- package/.next/server/app/api/internal/runtime/route.js +1 -1
- package/.next/server/app/api/version/route.js +1 -1
- package/.next/server/app/index.html +1 -1
- package/.next/server/app/index.rsc +2 -2
- package/.next/server/app/index.segments/__PAGE__.segment.rsc +2 -2
- package/.next/server/app/index.segments/_full.segment.rsc +2 -2
- package/.next/server/app/index.segments/_head.segment.rsc +1 -1
- package/.next/server/app/index.segments/_index.segment.rsc +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.js +2 -2
- package/.next/server/app/page_client-reference-manifest.js +1 -1
- package/.next/server/app-paths-manifest.json +7 -7
- 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/{page-c63ff970773f1496.js → page-e6bf6ff10f57135c.js} +2 -2
- package/.next/trace +75 -75
- package/.next/trace-build +1 -1
- package/package.json +1 -1
- /package/.next/static/{TFhJ1NtMURrrsapy9bEy4 → CzkRIupKhJuGvzwryyncq}/_buildManifest.js +0 -0
- /package/.next/static/{TFhJ1NtMURrrsapy9bEy4 → CzkRIupKhJuGvzwryyncq}/_ssgManifest.js +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8974],{14755:(e,t,r)=>{"use strict";r.d(t,{C1:()=>l,ES:()=>u,IN:()=>i,Tt:()=>o,me:()=>s,xG:()=>c,yK:()=>a});let n="subagent",o=[],i=["read","bash","edit","write"],l=["bash","read","edit","write","grep","find","ls"],s=[...l,"kernel_plot_run","kernel_plot_stop","kernel_plot_artifacts"],a=[...l,n];function d(e){return[...e].sort().join(",")}function c(e){switch(e){case"none":return o;case"default":return i;case"full-plot":return s;case"agent":return a;default:return l}}function u(e){let t=e.filter(e=>e.active).map(e=>e.name),r=d(t);return""===r?"none":r===d(i)?"default":r===d(l)?"full":r===d(s)?"full-plot":r===d(a)||t.includes(n)?"agent":"default"}},30054:(e,t,r)=>{"use strict";r.d(t,{AppShell:()=>n_});var n=r(95155),o=r(12115),i=r(73321);let l="var(--text-dim)";function s({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:l}),(0,n.jsx)("path",{d:"M1 6h14.5L14 13H2L1 6Z",stroke:l,strokeWidth:"1",fill:l,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:l,strokeWidth:"1",fill:l,fillOpacity:"0.1"})})}function a({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:l,strokeWidth:"1",fill:l,fillOpacity:"0.08"}),(0,n.jsx)("path",{d:"M10 2v3h3",stroke:l,strokeWidth:"1",fill:"none",strokeLinejoin:"round"})]})}function d({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:l,strokeWidth:"0.9",fill:l,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:l,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:l,letterSpacing:"0",children:e})]})}function c({size:e=14}){return(0,n.jsx)(d,{label:"TS",size:e})}function u({size:e=14}){return(0,n.jsx)(d,{label:"TSX",size:e})}function p({size:e=14}){return(0,n.jsx)(d,{label:"JS",size:e})}function h({size:e=14}){return(0,n.jsx)(d,{label:"JSX",size:e})}function x({size:e=14}){return(0,n.jsx)(d,{label:"PY",size:e})}function g({size:e=14}){return(0,n.jsx)(d,{label:"{}",size:e})}function f({size:e=14}){return(0,n.jsx)(d,{label:"CSS",size:e})}function v({size:e=14}){return(0,n.jsx)(d,{label:"SC",size:e})}function m({size:e=14}){return(0,n.jsx)(d,{label:"HTM",size:e})}function y({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:l,strokeWidth:"0.9",fill:l,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:l,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M3.5 9.5V7l1.5 1.5L6.5 7v2.5",stroke:l,strokeWidth:"0.9",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,n.jsx)("path",{d:"M8 7v2.5M7 9l1 1.5 1-1.5",stroke:l,strokeWidth:"0.9",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]})}function b({size:e=14}){return(0,n.jsx)(d,{label:"YML",size:e})}function j({size:e=14}){return(0,n.jsx)(d,{label:"TOM",size:e})}function k({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:l,strokeWidth:"0.9",fill:l,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:l,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M4 7.5l2 1.5-2 1.5",stroke:l,strokeWidth:"0.95",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,n.jsx)("path",{d:"M7.5 10.5h2.5",stroke:l,strokeWidth:"0.95",strokeLinecap:"round"})]})}function w({size:e=14}){return(0,n.jsx)(d,{label:"RS",size:e})}function S({size:e=14}){return(0,n.jsx)(d,{label:"GO",size:e})}function C({size:e=14}){return(0,n.jsx)(d,{label:"SQL",size:e})}function T({size:e=14}){return(0,n.jsx)(d,{label:"GQL",size:e})}function z({size:e=14}){return(0,n.jsx)(d,{label:"TF",size:e})}function L({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:l,strokeWidth:"0.9",fill:l,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:l,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:l,strokeWidth:"0.8"}),(0,n.jsx)("rect",{x:"6",y:"6.5",width:"2",height:"1.5",rx:"0.3",stroke:l,strokeWidth:"0.8"}),(0,n.jsx)("rect",{x:"3.5",y:"8.5",width:"2",height:"1.5",rx:"0.3",stroke:l,strokeWidth:"0.8"})]})}function I({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:l,strokeWidth:"0.9",fill:l,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:l,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"5.5",cy:"8.5",r:"1.5",stroke:l,strokeWidth:"0.9"}),(0,n.jsx)("path",{d:"M7 8.5h2.5M8.5 8.5v1.5",stroke:l,strokeWidth:"0.9",strokeLinecap:"round"})]})}function M({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:l,strokeWidth:"0.9",fill:l,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:l,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"5",cy:"6.5",r:"1",stroke:l,strokeWidth:"0.85"}),(0,n.jsx)("circle",{cx:"9",cy:"6.5",r:"1",stroke:l,strokeWidth:"0.85"}),(0,n.jsx)("circle",{cx:"5",cy:"10",r:"1",stroke:l,strokeWidth:"0.85"}),(0,n.jsx)("path",{d:"M5 7.5V9",stroke:l,strokeWidth:"0.85",strokeLinecap:"round"}),(0,n.jsx)("path",{d:"M9 7.5v.5a2 2 0 0 1-2 2H6",stroke:l,strokeWidth:"0.85",strokeLinecap:"round",fill:"none"})]})}function R({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:l,strokeWidth:"0.9",fill:l,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:l,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:l,strokeWidth:"0.9"}),(0,n.jsx)("path",{d:"M5.5 8.5V7.5a1.5 1.5 0 0 1 3 0v1",stroke:l,strokeWidth:"0.9",strokeLinecap:"round",fill:"none"})]})}function W({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:l,strokeWidth:"0.9",fill:l,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:l,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"7",cy:"8.5",r:"1.3",stroke:l,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:l,strokeWidth:"0.8",strokeLinecap:"round"})]})}function E(e,t=14){let r=e.toLowerCase(),o=r.split(".").pop()??"";if("dockerfile"===r||r.startsWith("dockerfile."))return(0,n.jsx)(L,{size:t});if(".env"===r||r.startsWith(".env."))return(0,n.jsx)(I,{size:t});if(".gitignore"===r||".gitattributes"===r||".gitmodules"===r)return(0,n.jsx)(M,{size:t});if("package-lock.json"===r||"yarn.lock"===r||"bun.lock"===r||"pnpm-lock.yaml"===r||"cargo.lock"===r)return(0,n.jsx)(R,{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)(W,{size:t});switch(o){case"ts":return(0,n.jsx)(c,{size:t});case"tsx":return(0,n.jsx)(u,{size:t});case"js":case"mjs":case"cjs":return(0,n.jsx)(p,{size:t});case"jsx":return(0,n.jsx)(h,{size:t});case"py":return(0,n.jsx)(x,{size:t});case"json":case"jsonl":return(0,n.jsx)(g,{size:t});case"css":case"less":return(0,n.jsx)(f,{size:t});case"scss":return(0,n.jsx)(v,{size:t});case"html":case"htm":return(0,n.jsx)(m,{size:t});case"md":case"mdx":return(0,n.jsx)(y,{size:t});case"yaml":case"yml":return(0,n.jsx)(b,{size:t});case"toml":return(0,n.jsx)(j,{size:t});case"sh":case"bash":case"zsh":case"fish":return(0,n.jsx)(k,{size:t});case"rs":return(0,n.jsx)(w,{size:t});case"go":return(0,n.jsx)(S,{size:t});case"sql":return(0,n.jsx)(C,{size:t});case"graphql":case"gql":return(0,n.jsx)(T,{size:t});case"tf":case"hcl":return(0,n.jsx)(z,{size:t});case"lock":return(0,n.jsx)(R,{size:t});default:return(0,n.jsx)(a,{size:t})}}function $(e){return/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith("\\\\")?e.replace(/\\/g,"/"):e}function N(e){return $(e).split("/").filter(Boolean).map(encodeURIComponent).join("/")}function B(e){let t=$(e).replace(/\/+$/,"");return t.split("/").pop()??t}function P(e,t){if(!t)return e;let r=$(e),n=$(t).replace(/\/$/,"");return r.startsWith(n+"/")?r.slice(n.length+1):e}async function A(e){let t=N(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,`${$(e).replace(/\/$/,"")}/${r}`),isDir:t.isDir,size:t.size,children:t.isDir?[]:void 0,loaded:!t.isDir}}):[]}function H(e,t){let r=t.trim().toLowerCase();return!!(!r||e.name.toLowerCase().includes(r))||(e.children??[]).some(e=>H(e,r))}function O(e){return!!Array.from(e.types).includes("Files")||Array.from(e.items).some(e=>"file"===e.kind)}function D(e){return Array.from(e.files).filter(e=>!!e.name)}function F(e,t){return e===t?".":P(e,t)}function U({node:e,depth:t,cwd:r,onOpenFile:i,onExploreFile:l,onAtMention:a,expandedPaths:d,onToggleExpanded:c,onUploadFiles:u,uploadTargetPath:p,refreshKey:h,searchQuery:x}){let g=!!x?.trim(),f=g?e.isDir:d.has(e.fullPath),[v,m]=(0,o.useState)(e.children??[]),[y,b]=(0,o.useState)(e.loaded??!1),[j,k]=(0,o.useState)(!1),[w,S]=(0,o.useState)(!1),[C,T]=(0,o.useState)(!1),z=e.isDir&&(C||p===e.fullPath),L=!!a&&w,I=!!l&&w&&!e.isDir&&e.name.toLowerCase().endsWith(".h5ad"),M=L||I,R=g?v.filter(e=>H(e,x??"")):v,W=(0,o.useCallback)(async(t=!1)=>{if(!y||t){k(!0);try{let t=await A(e.fullPath);m(t),b(!0)}catch{}finally{k(!1)}}},[y,e.fullPath]),$=(0,o.useRef)(y);(0,o.useEffect)(()=>{$.current=y}),(0,o.useEffect)(()=>{f&&y&&W(!0)},[h]);let N=(0,o.useCallback)(()=>{if(e.isDir){let t=!f;c(e.fullPath,t),t&&!y&&W()}else i(e.fullPath,e.name)},[e.isDir,e.fullPath,e.name,y,f,W,i,c]),B=(0,o.useCallback)(t=>{e.isDir&&O(t.dataTransfer)&&(t.preventDefault(),t.stopPropagation(),t.dataTransfer.dropEffect="copy",T(!0))},[e.isDir]),F=(0,o.useCallback)(t=>{e.isDir&&O(t.dataTransfer)&&(t.preventDefault(),t.stopPropagation(),t.dataTransfer.dropEffect="copy")},[e.isDir]),_=(0,o.useCallback)(t=>{if(!e.isDir)return;let r=t.relatedTarget;r instanceof Node&&t.currentTarget.contains(r)||T(!1)},[e.isDir]),V=(0,o.useCallback)(t=>{if(!e.isDir||!O(t.dataTransfer))return;t.preventDefault(),t.stopPropagation(),T(!1);let r=D(t.dataTransfer);r.length>0&&(u(r,e.fullPath),f||c(e.fullPath,!0),y||W())},[W,y,e.fullPath,e.isDir,c,u,f]);return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{onClick:N,onMouseEnter:()=>S(!0),onMouseLeave:()=>S(!1),onDragEnter:B,onDragOver:F,onDragLeave:_,onDrop:V,style:{position:"relative",display:"flex",alignItems:"center",gap:4,paddingLeft:8+14*t,paddingRight:M?L&&I?146:82:8,height:24,cursor:"pointer",background:z?"rgba(37,99,235,0.14)":w?"var(--bg-hover)":"transparent",outline:z?"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:f?"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)(s,{size:14,open:f}):E(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}),j&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",children:(0,n.jsx)("path",{d:"M12 2v4M12 18v4M4.93 4.93l2.83 2.83M16.24 16.24l2.83 2.83M2 12h4M18 12h4"})}),M&&(0,n.jsxs)("div",{style:{position:"absolute",right:4,top:"50%",transform:"translateY(-50%)",display:"flex",alignItems:"center",gap:4},children:[I&&(0,n.jsxs)("button",{onClick:t=>{t.stopPropagation(),l?.(e.fullPath,e.name)},title:"Explore H5AD",style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,padding:"0 8px",height:20,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:4,color:"var(--accent)",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.1",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"7"}),(0,n.jsx)("path",{d:"M16 16l4 4"}),(0,n.jsx)("path",{d:"M8.5 11h5"}),(0,n.jsx)("path",{d:"M11 8.5v5"})]}),"@explore"]}),L&&(0,n.jsxs)("button",{onClick:t=>{t.stopPropagation(),a?.(P(e.fullPath,r))},title:"Insert path into chat",style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,padding:"0 8px",height:20,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:4,color:"var(--accent)",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"4"}),(0,n.jsx)("path",{d:"M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8"})]}),"@mention"]})]})]}),e.isDir&&f&&(0,n.jsxs)("div",{children:[R.map(e=>(0,n.jsx)(U,{node:e,depth:t+1,cwd:r,onOpenFile:i,onExploreFile:l,onAtMention:a,expandedPaths:d,onToggleExpanded:c,onUploadFiles:u,uploadTargetPath:p,refreshKey:h,searchQuery:x},e.fullPath)),0===R.length&&y&&!g&&(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 _({cwd:e,onOpenFile:t,onExploreFile:r,refreshKey:i,onAtMention:l,searchQuery:s="",onSearchChange:a}){let[d,c]=(0,o.useState)([]),[u,p]=(0,o.useState)(!0),[h,x]=(0,o.useState)(null),[g,f]=(0,o.useState)(new Set),[v,m]=(0,o.useState)(!1),[y,b]=(0,o.useState)(null),[j,k]=(0,o.useState)(null),w=(0,o.useRef)(null),S=(0,o.useRef)(null),C=(0,o.useRef)(0),T=(0,o.useCallback)((e,t)=>(p(t),x(null),A(e).then(e=>c(e)).catch(e=>x(String(e))).finally(()=>p(!1))),[]),z=(0,o.useCallback)((e,t)=>{f(r=>{let n=new Set(r);return t?n.add(e):n.delete(e),n})},[]);(0,o.useEffect)(()=>{let t=w.current!==e;w.current=e,t&&f(new Set),T(e,t)},[e,i,T]),(0,o.useEffect)(()=>()=>{S.current&&clearTimeout(S.current)},[]);let L=(0,o.useCallback)(()=>{T(e,0===d.length)},[e,d.length,T]),I=(0,o.useCallback)(()=>{S.current&&clearTimeout(S.current),S.current=setTimeout(()=>k(null),5e3)},[]),M=(0,o.useCallback)((t,r)=>{if(0===t.length)return;C.current=0,m(!1),S.current&&clearTimeout(S.current);let n=t.reduce((e,t)=>e+t.size,0),o=F(r,e);b(r),k({phase:"uploading",targetPath:r,fileCount:t.length,loaded:0,total:n,message:`Uploading ${t.length} file${1===t.length?"":"s"} to ${o}`});let i=new FormData;t.forEach(e=>i.append("files",e,e.name));let l=new XMLHttpRequest,s=N(r);l.open("POST",`/api/files/${s}?type=upload`),l.upload.onprogress=e=>{e.lengthComputable&&k(t=>t?{...t,loaded:e.loaded,total:e.total}:t)},l.onload=()=>{b(null);let e={};try{e=JSON.parse(l.responseText)}catch{e={}}if(l.status>=200&&l.status<300){let i=e.uploaded??[],l=e.failed??[],s=[...i.filter(e=>e.name!==e.originalName).slice(0,3).map(e=>`${e.originalName} saved as ${e.name}`),...l.slice(0,3).map(e=>`${e.name}: ${e.error}`)];k({phase:l.length>0?"warning":"success",targetPath:r,fileCount:t.length,loaded:n,total:n,message:l.length>0?`Uploaded ${i.length}, ${l.length} failed`:`Uploaded ${i.length} file${1===i.length?"":"s"} to ${o}`,details:s}),L(),I()}else{let o=e.error??`Upload failed (HTTP ${l.status})`;k({phase:(l.status,"error"),targetPath:r,fileCount:t.length,loaded:0,total:n,message:o,details:403===l.status?["Check directory write permission or project access."]:void 0}),I()}},l.onerror=()=>{b(null),k({phase:"error",targetPath:r,fileCount:t.length,loaded:0,total:n,message:"Upload failed due to a network error"}),I()},l.onabort=()=>{b(null),k({phase:"error",targetPath:r,fileCount:t.length,loaded:0,total:n,message:"Upload canceled"}),I()},l.send(i)},[e,L,I]),R=(0,o.useCallback)(e=>{O(e.dataTransfer)&&(e.preventDefault(),C.current+=1,m(!0))},[]),W=(0,o.useCallback)(e=>{O(e.dataTransfer)&&(e.preventDefault(),e.dataTransfer.dropEffect="copy")},[]),E=(0,o.useCallback)(()=>{C.current-=1,C.current<=0&&(C.current=0,m(!1))},[]),$=(0,o.useCallback)(t=>{if(!O(t.dataTransfer))return;t.preventDefault(),C.current=0,m(!1);let r=D(t.dataTransfer);r.length>0&&M(r,e)},[e,M]),B=s.trim()?d.filter(e=>H(e,s)):d,P=s.trim().length>0;return u?(0,n.jsx)(V,{cwd:e,isDraggingFiles:v,uploadState:j,onDragEnter:R,onDragOver:W,onDragLeave:E,onDrop:$,children:(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:"Loading files..."})}):h?(0,n.jsx)(V,{cwd:e,isDraggingFiles:v,uploadState:j,onDragEnter:R,onDragOver:W,onDragLeave:E,onDrop:$,children:(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"#f87171"},children:h})}):(0,n.jsx)(V,{cwd:e,isDraggingFiles:v,uploadState:j,onDragEnter:R,onDragOver:W,onDragLeave:E,onDrop:$,children:(0,n.jsxs)("div",{style:{padding:"2px 4px"},children:[B.map(o=>(0,n.jsx)(U,{node:o,depth:0,cwd:e,onOpenFile:t,onExploreFile:r,onAtMention:l,expandedPaths:g,onToggleExpanded:z,onUploadFiles:M,uploadTargetPath:y,refreshKey:i,searchQuery:s},o.fullPath)),0===B.length&&(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:P?"No matching files":"No files found"})]})})}function V({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 ",F(e,e)]})}),r&&(0,n.jsxs)("div",{style:{margin:"6px",padding:"7px 8px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",boxShadow:"0 8px 24px rgba(0,0,0,0.12)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:7,minWidth:0},children:[(0,n.jsx)("span",{style:{width:8,height:8,borderRadius:999,background:c,flexShrink:0}}),(0,n.jsx)("span",{title:r.message,style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text)",fontSize:11,fontWeight:600},children:r.message}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,flexShrink:0},children:"uploading"===r.phase?`${d}%`:function(e){if(!Number.isFinite(e)||e<=0)return"0 B";let t=["B","KB","MB","GB"],r=e,n=0;for(;r>=1024&&n<t.length-1;)r/=1024,n+=1;return`${r>=10||0===n?Math.round(r):r.toFixed(1)} ${t[n]}`}(r.total)})]}),(0,n.jsx)("div",{style:{marginTop:6,height:3,borderRadius:999,background:"var(--bg)",overflow:"hidden"},children:(0,n.jsx)("div",{style:{width:`${d}%`,height:"100%",borderRadius:999,background:c,transition:"width 0.15s ease"}})}),r.details&&r.details.length>0&&(0,n.jsx)("div",{style:{marginTop:5,display:"grid",gap:2},children:r.details.map(e=>(0,n.jsx)("div",{title:e,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontSize:10},children:e},e))})]})]})}function J(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 q(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 K({open:e,cwd:t,homeDir:r,onClose:i,onSelectSession:l}){let[s,a]=(0,o.useState)(""),[d,c]=(0,o.useState)("current"),[u,p]=(0,o.useState)([]),[h,x]=(0,o.useState)(!1),[g,f]=(0,o.useState)(null),[v,m]=(0,o.useState)(!1),y=(0,o.useRef)(null);if((0,o.useEffect)(()=>{e&&(c(t?"current":"all"),setTimeout(()=>y.current?.focus(),0))},[e,t]),(0,o.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&i()};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,i]),(0,o.useEffect)(()=>{if(!e)return;let r=s.trim();if(r.length<2){p([]),x(!1),f(null),m(!1);return}let n=new AbortController,o=setTimeout(async()=>{x(!0),f(null);try{let e=new URLSearchParams({q:r,scope:d});t&&e.set("cwd",t);let o=await fetch(`/api/search?${e.toString()}`,{signal:n.signal});if(!o.ok)throw Error(`HTTP ${o.status}`);let i=await o.json();if(i.error)throw Error(i.error);p(i.results??[]),m(i.truncated??!1)}catch(e){"AbortError"!==e.name&&f(String(e))}finally{x(!1)}},180);return()=>{clearTimeout(o),n.abort()}},[e,s,d,t]),!e)return null;let b=s.trim(),j=u.reduce((e,t)=>e+t.matches.length,0);return(0,n.jsx)("div",{role:"dialog","aria-modal":"true","aria-label":"Search conversation history",style:{position:"fixed",inset:0,zIndex:500,display:"flex",alignItems:"flex-start",justifyContent:"center",padding:"8vh 16px 16px",background:"rgba(0,0,0,0.28)"},onMouseDown:e=>{e.target===e.currentTarget&&i()},children:(0,n.jsxs)("div",{style:{width:"min(760px, 100%)",maxHeight:"78vh",display:"flex",flexDirection:"column",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 16px 48px rgba(0,0,0,0.24)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:12,borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1,minWidth:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:8,padding:"0 10px"},children:[(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"7",cy:"7",r:"4.5"}),(0,n.jsx)("path",{d:"M10.5 10.5 13.5 13.5"})]}),(0,n.jsx)("input",{ref:y,value:s,onChange:e=>a(e.target.value),placeholder:"Search conversation history...",style:{flex:1,minWidth:0,height:38,background:"transparent",border:"none",outline:"none",color:"var(--text)",fontSize:14}})]}),(0,n.jsx)("button",{type:"button",onClick:i,title:"Close",style:{width:34,height:34,display:"inline-flex",alignItems:"center",justifyContent:"center",background:"none",border:"none",borderRadius:7,color:"var(--text-dim)",cursor:"pointer"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-dim)"},children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,n.jsx)("path",{d:"M4 4 12 12"}),(0,n.jsx)("path",{d:"M12 4 4 12"})]})})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:10},children:[(0,n.jsx)("div",{style:{display:"inline-flex",padding:2,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7},children:[{value:"current",label:"Current project",disabled:!t},{value:"all",label:"All history",disabled:!1}].map(e=>(0,n.jsx)("button",{type:"button",disabled:e.disabled,onClick:()=>c(e.value),style:{height:24,padding:"0 9px",background:d===e.value?"var(--bg-selected)":"transparent",border:"none",borderRadius:5,color:e.disabled?"var(--text-dim)":d===e.value?"var(--text)":"var(--text-muted)",cursor:e.disabled?"not-allowed":"pointer",fontSize:11,fontWeight:500},children:e.label},e.value))}),(0,n.jsx)("div",{style:{flex:1,minWidth:0,color:"var(--text-dim)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"current"===d&&t?J(t,r):"Searching every saved session"})]})]}),(0,n.jsxs)("div",{style:{flex:1,overflowY:"auto",minHeight:180},children:[b.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."}),b.length>=2&&h&&0===u.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Searching..."}),g&&(0,n.jsx)("div",{style:{padding:18,color:"#ef4444",fontSize:13},children:g}),b.length>=2&&!h&&!g&&0===u.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"No matching conversations found."}),u.map(e=>(0,n.jsxs)("div",{style:{borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{l(e.session),i()},style:{width:"100%",display:"flex",alignItems:"center",gap:10,padding:"10px 12px",background:"var(--bg-panel)",border:"none",borderBottom:"1px solid var(--border)",color:"var(--text)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13,fontWeight:600},children:e.session.name||e.session.firstMessage||"(no messages)"}),(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:11},children:q(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:J(e.session.cwd,r)})]}),e.matchCount>e.matches.length&&(0,n.jsxs)("span",{style:{flexShrink:0,color:"var(--text-muted)",fontSize:11},children:[e.matchCount," matches"]})]}),e.matches.map(t=>(0,n.jsxs)("button",{type:"button",onClick:()=>{l(e.session),i()},style:{width:"100%",padding:"9px 14px 9px 28px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:3},children:[(0,n.jsx)("span",{style:{minWidth:54,color:"user"===t.role?"var(--accent)":"var(--text-dim)",fontSize:11,fontWeight:600,textTransform:"capitalize"},children:t.role}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:q(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,b)})]},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:j>0?`${j}${v?"+":""} results`:"Esc to close"}),h&&u.length>0&&(0,n.jsx)("span",{children:"Updating..."})]})]})})}function Z({open:e,initialPath:t,onClose:r,onSelect:i}){let[l,s]=(0,o.useState)(""),[a,d]=(0,o.useState)(null),[c,u]=(0,o.useState)([]),[p,h]=(0,o.useState)([]),[x,g]=(0,o.useState)(""),[f,v]=(0,o.useState)(!1),[m,y]=(0,o.useState)(null),b=(0,o.useCallback)(async e=>{v(!0),y(null);try{let t=e?`/api/projects/browse?dir=${encodeURIComponent(e)}`:"/api/projects/browse",r=await fetch(t),n=await r.json();if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);s(n.current??""),d(n.parent??null),u(n.directories??[]),h(n.drives??[]),g(n.current??"")}catch(e){y(e instanceof Error?e.message:String(e))}finally{v(!1)}},[]);return((0,o.useEffect)(()=>{e&&b(t||void 0)},[b,t,e]),(0,o.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&r()};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[r,e]),e)?(0,n.jsx)("div",{onMouseDown:e=>{e.target===e.currentTarget&&r()},style:{position:"fixed",inset:0,zIndex:1200,display:"flex",alignItems:"center",justifyContent:"center",padding:18,background:"rgba(0,0,0,0.34)"},children:(0,n.jsxs)("div",{style:{width:"min(560px, 100%)",maxHeight:"min(720px, 88dvh)",display:"flex",flexDirection:"column",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 12px 40px rgba(0,0,0,0.25)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{height:48,padding:"0 14px",display:"flex",alignItems:"center",justifyContent:"space-between",borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:14,fontWeight:750},children:"Select project path"}),(0,n.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:11},children:"Server filesystem"})]}),(0,n.jsx)("button",{type:"button",onClick:r,"aria-label":"Close",title:"Close",style:{width:30,height:30,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:"x"})]}),(0,n.jsx)("div",{style:{padding:12,borderBottom:"1px solid var(--border)"},children:(0,n.jsxs)("form",{onSubmit:e=>{e.preventDefault(),x.trim()&&b(x.trim())},style:{display:"flex",gap:8},children:[(0,n.jsx)("input",{value:x,onChange:e=>g(e.target.value),placeholder:"/path/to/project",style:{flex:1,minWidth:0,height:32,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:12,outline:"none"}}),(0,n.jsx)("button",{type:"submit",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:"Go"})]})}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"8px 12px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsx)("button",{type:"button",onClick:()=>a&&void b(a),disabled:!a,style:{width:28,height:28,border:"1px solid var(--border)",borderRadius:6,background:a?"var(--bg)":"transparent",color:a?"var(--text-muted)":"var(--text-dim)",cursor:a?"pointer":"default",padding:0},title:"Up",children:(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"2 6.5 5 3.5 8 6.5"})})}),p.length>0&&(0,n.jsxs)("select",{value:p.find(e=>l.toLowerCase().startsWith(e.toLowerCase()))??"",onChange:e=>{e.target.value&&b(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"}),p.map(e=>(0,n.jsx)("option",{value:e,children:e},e))]}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11},title:l,children:l})]}),(0,n.jsx)("div",{style:{flex:1,minHeight:220,maxHeight:360,overflowY:"auto",padding:6},children:f?(0,n.jsx)("div",{style:{padding:18,color:"var(--text-muted)",fontSize:12},children:"Loading..."}):m?(0,n.jsx)("div",{style:{padding:18,color:"#f87171",fontSize:12},children:m}):0===c.length?(0,n.jsx)("div",{style:{padding:18,color:"var(--text-muted)",fontSize:12},children:"No subdirectories"}):c.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>void b(e.path),style:{width:"100%",display:"flex",alignItems:"center",gap:9,padding:"8px 9px",border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:12},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},title:e.path,children:[(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--accent)",flexShrink:0},children:(0,n.jsx)("path",{d:"M3 6.5A2.5 2.5 0 0 1 5.5 4H10l2 2.5h6.5A2.5 2.5 0 0 1 21 9v8.5A2.5 2.5 0 0 1 18.5 20h-13A2.5 2.5 0 0 1 3 17.5v-11Z"})}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0},children:(0,n.jsx)("polyline",{points:"3.5 2 6.5 5 3.5 8"})})]},e.path))}),(0,n.jsxs)("div",{style:{padding:12,borderTop:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",gap:10},children:[(0,n.jsx)("div",{style:{minWidth:0,color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:l,children:l}),(0,n.jsxs)("div",{style:{display:"flex",gap:7,flexShrink:0},children:[(0,n.jsx)("button",{type:"button",onClick:r,style:{height:32,padding:"0 12px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Cancel"}),(0,n.jsx)("button",{type:"button",onClick:()=>l&&i(l),disabled:!l,style:{height:32,padding:"0 12px",border:"none",borderRadius:6,background:l?"var(--accent)":"var(--bg-hover)",color:l?"#fff":"var(--text-dim)",cursor:l?"pointer":"default",fontSize:12,fontWeight:650},children:"Select"})]})]})]})}):null}let G="AnnoVibe";async function Y(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 X(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 Q(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 ee(e,t){if(!e)return"No Project";let r=e.replace(/[\\/]+$/,""),n=r.includes("/")?"/":"\\";return r.split(n).filter(Boolean).pop()||Q(e,t)}function et(e){return e.lastAccessed??e.created??""}let er="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";function en(){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:er[Math.floor(Math.random()*er.length)]).join("")),l.current<r?i.current=requestAnimationFrame(o):n(e)};return i.current=requestAnimationFrame(o),()=>{i.current&&cancelAnimationFrame(i.current)}},[e,t]),r}(e?"v0.8.23":G,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 eo({selectedSessionId:e,onSelectSession:t,onNewSession:r,initialSessionId:i,onInitialRestoreDone:l,refreshKey:s,onSessionDeleted:a,selectedCwd:d,onCwdChange:c,onOpenFile:u,onExploreFile:p,explorerRefreshKey:h,onAtMention:x}){let[g,f]=(0,o.useState)([]),[v,m]=(0,o.useState)([]),[y,b]=(0,o.useState)(!0),[j,k]=(0,o.useState)(null),[w,S]=(0,o.useState)(null),[C,T]=(0,o.useState)(""),[z,L]=(0,o.useState)(!1),[I,M]=(0,o.useState)(null),[R,W]=(0,o.useState)(!1),[E,$]=(0,o.useState)(!1),[N,B]=(0,o.useState)(!1),[P,A]=(0,o.useState)(!0),H=(0,o.useRef)(!1),O=(0,o.useRef)(!1),D=(0,o.useRef)(null),[F,U]=(0,o.useState)(!0),[V,J]=(0,o.useState)(0),[q,G]=(0,o.useState)(""),er=(0,o.useCallback)(async(e=!1)=>{try{e&&(k(null),b(!0));let[t,r]=await Promise.all([fetch("/api/sessions"),fetch("/api/projects")]);if(!t.ok)throw Error(await Y("sessions",t));if(!r.ok)throw Error(await Y("projects",r));let n=await t.json(),o=await r.json();f(n.sessions),m(o.projects),k(null)}catch(e){k(String(e))}finally{e&&b(!1)}},[]),el=(0,o.useCallback)(()=>{A(e=>!e),L(!1),M(null),er(!0)},[er]),es=(0,o.useRef)(!1);(0,o.useEffect)(()=>{let e=!es.current;es.current=!0,er(e)},[er,s]),(0,o.useEffect)(()=>{void 0!==h&&J(e=>e+1)},[h]),(0,o.useEffect)(()=>{fetch("/api/home").then(e=>e.json()).then(e=>{e.home&&T(e.home)}).catch(()=>{})},[]);let ea=(0,o.useRef)(!1);(0,o.useEffect)(()=>{if(H.current){H.current=!1;return}if(O.current){O.current=!1;return}c?.(w)},[w,c]);let ed=(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 M(n.error??`HTTP ${r.status}`),!1;return er(!1),!0}catch(e){return M(e instanceof Error?e.message:String(e)),!1}},[er]),ec=(0,o.useCallback)(e=>{fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,touch:!0})}).catch(()=>{})},[]),eu=(0,o.useCallback)(e=>{O.current=!0,S(e),B(!1),U(!0),G(""),J(e=>e+1),c?.(e),ec(e)},[c,ec]);(0,o.useEffect)(()=>{if((0!==g.length||0!==v.length)&&null===w){if(i&&!ea.current){ea.current=!0;let e=g.find(e=>e.id===i);if(e){S(e.cwd),ec(e.cwd),t(e,!0);return}l?.()}let e=v[0]?.cwd;e&&(S(e),ec(e))}},[g,v,w,i,t,l,ec]);let ep=(0,o.useCallback)(async()=>{try{let e=await fetch("/api/default-cwd",{method:"POST"}),t=await e.json();t.cwd&&(await ed(t.cwd,!1),eu(t.cwd),L(!1))}catch{}},[eu,ed]),eh=(0,o.useCallback)(async e=>{await ed(e,!1)&&(eu(e),W(!1),M(null),L(!1))},[eu,ed]);(0,o.useEffect)(()=>{let e=e=>{D.current&&!D.current.contains(e.target)&&(L(!1),M(null))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let ex=d??w,eg=(0,o.useCallback)(e=>{if(!e)return void L(!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]),ef=(0,o.useCallback)(()=>{eg(ex)},[eg,ex]),ev=(0,o.useMemo)(()=>[...ex&&!v.some(e=>e.cwd===ex)?[{cwd:ex,displayName:ee(ex,C),chatCount:g.filter(e=>e.cwd===ex).length,lastAccessed:null,created:null,exists:!0,source:"manual"}]:[],...v].sort((e,t)=>{if(ex&&e.cwd===ex)return -1;if(ex&&t.cwd===ex)return 1;let r=et(e),n=et(t);return r!==n?n.localeCompare(r):e.displayName.localeCompare(t.displayName)}),[g,ex,C,v]),em=(0,o.useMemo)(()=>g.filter(e=>e.cwd===ex).sort((e,t)=>t.modified.localeCompare(e.modified)),[g,ex]),ey=ex?ev.find(e=>e.cwd===ex):void 0,eb=ex?ev.find(e=>e.cwd===ex)?.displayName||ee(ex,C):"Open project...",ej=ey?.chatCount??em.length,ek=(0,o.useMemo)(()=>(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})(em),[em]),ew=ek.length,eS=ek;if(ew>10&&!N){eS=ek.slice(0,10);let t=ek.find(t=>(function e(t,r){return!!r&&(t.session.id===r||t.children.some(t=>e(t,r)))})(t,e));t&&!eS.includes(t)&&(eS=[...eS,t])}let eC=ew-eS.length,eT=(0,o.useCallback)((e,r=!1)=>{e.cwd!==ex&&(H.current=!0,S(e.cwd)),ec(e.cwd),t(e,r)},[t,ex,ec]);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:"12px 10px 10px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:8},children:[(0,n.jsx)(en,{}),(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsxs)("button",{onClick:ef,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,background:"var(--bg-hover)",border:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",height:32,paddingLeft:10,paddingRight:12,borderRadius:7,fontSize:12,fontWeight:500,letterSpacing:"-0.01em",flexShrink:0,transition:"background 0.12s, color 0.12s, border-color 0.12s"},title:ex?`New session in ${ex}`:"Select a project first",onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-selected)",e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"6",y1:"1",x2:"6",y2:"11"}),(0,n.jsx)("line",{x1:"1",y1:"6",x2:"11",y2:"6"})]}),"New"]}),(0,n.jsx)("button",{onClick:()=>$(!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:D,style:{position:"relative"},children:[(0,n.jsxs)("button",{type:"button",onClick:el,title:"Toggle and refresh project conversations","aria-expanded":P,style:{width:"100%",display:"flex",alignItems:"center",gap:6,padding:"6px 0",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:600,letterSpacing:"0.05em",textTransform:"uppercase",textAlign:"left"},children:[(0,n.jsx)("svg",{width:"9",height:"9",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:P?"rotate(90deg)":"none",transition:"transform 0.15s",flexShrink:0},children:(0,n.jsx)("polyline",{points:"3 2 7 5 3 8"})}),(0,n.jsx)("span",{style:{flex:1},children:"Project"}),y&&(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,fontWeight:500,letterSpacing:0,textTransform:"none"},children:"Refreshing..."})]}),P&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{onClick:()=>L(e=>!e),style:{width:"100%",display:"flex",alignItems:"center",gap:9,padding:"8px 10px",background:ex?"var(--bg-hover)":"rgba(37,99,235,0.06)",border:ex?"1px solid var(--border)":"1px solid rgba(37,99,235,0.4)",borderRadius:7,cursor:"pointer",fontSize:12,color:"var(--text)",textAlign:"left",transition:"border-color 0.15s, background 0.15s"},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:ex?"var(--accent)":"var(--text-dim)",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.jsxs)("span",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("span",{style:{display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:12,fontWeight:650,color:ex?"var(--text)":"var(--text-dim)"},children:ex?eb:i&&!ea.current?"":"Open project..."}),ex&&(0,n.jsx)("span",{style:{display:"block",marginTop:2,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)",fontSize:10,color:"var(--text-dim)"},title:ex,children:Q(ex,C)})]}),ex&&(0,n.jsxs)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:[ej," chats"]}),(0,n.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0,transform:z?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),z&&(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"},children:[(0,n.jsxs)("div",{style:{maxHeight:260,overflowY:"auto"},children:[0===ev.length&&(0,n.jsx)("div",{style:{padding:"10px 12px",color:"var(--text-muted)",fontSize:12},children:"No projects yet"}),ev.map(e=>{let t=e.cwd===ex,r=et(e);return(0,n.jsxs)("button",{onClick:()=>{eu(e.cwd),M(null),L(!1)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"8px 10px",background:t?"var(--bg-selected)":"none",border:"none",borderBottom:"1px solid var(--border)",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11},title:e.cwd,children:[t?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsxs)("span",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("span",{style:{display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:t?"var(--text)":"var(--text-muted)",fontWeight:t?650:500},children:e.displayName}),(0,n.jsxs)("span",{style:{display:"block",marginTop:2,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontSize:10},children:[e.chatCount," chats",r?` / ${X(r)}`:"",e.exists?"":" / missing"]})]})]},e.cwd)})]}),(0,n.jsxs)("div",{style:{borderTop:ev.length>0?"1px solid var(--border)":"none"},children:[(0,n.jsxs)("button",{onClick:e=>{e.stopPropagation(),ep()},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11},children:[(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.1",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("path",{d:"M1 3A1 1 0 0 1 2 2H4L5 3.5H8.5a.5.5 0 0 1 .5.5v4a.5.5 0 0 1-.5.5h-7A.5.5 0 0 1 1 8V3Z"})}),(0,n.jsx)("span",{children:"Use default directory"})]}),(0,n.jsxs)("button",{onClick:e=>{e.stopPropagation(),M(null),W(!0)},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11},children:[(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.1",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M1 3A1 1 0 0 1 2 2h1.5L4.5 3H8a1 1 0 0 1 1 1v4a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V3Z"}),(0,n.jsx)("path",{d:"M5 4.5v3M3.5 6h3"})]}),(0,n.jsx)("span",{children:"Select project path..."})]}),I&&(0,n.jsx)("div",{style:{padding:"0 10px 8px 27px",color:"#f87171",fontSize:10,lineHeight:1.4},children:I})]})]})]})]})]}),(0,n.jsx)(K,{open:E,cwd:ex,homeDir:C,onClose:()=>$(!1),onSelectSession:e=>{eT(e)}}),P&&(0,n.jsx)(n.Fragment,{children:(0,n.jsxs)("div",{style:{flex:F&&ex?"1 1 0":"1 1 auto",overflowY:"auto",padding:"6px 8px 8px",minHeight:120},children:[y&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Loading..."}),j&&(0,n.jsx)("div",{style:{padding:"12px 14px",color:"#f87171",fontSize:12},children:j}),!y&&!j&&!ex&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Open or create a project to start chatting."}),!y&&!j&&ex&&(0,n.jsxs)(n.Fragment,{children:[0===em.length?(0,n.jsx)("button",{type:"button",onClick:()=>eg(ex),style:{width:"100%",padding:"12px",background:"transparent",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:12},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:"Start a new session in this project"}):eS.map(t=>(0,n.jsx)(ei,{node:t,selectedSessionId:e,onSelectSession:eT,onRenamed:er,onSessionDeleted:e=>{a?.(e),er()},depth:0},t.session.id)),(N||eC>0)&&ew>10&&(0,n.jsx)("button",{type:"button",onClick:()=>B(e=>!e),style:{width:"100%",padding:"6px 10px",background:"transparent",border:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:11,textAlign:"center"},children:N?"Show less":`Show ${Math.max(0,eC)} more`})]})]})}),ex&&(0,n.jsxs)("div",{style:{borderTop:"1px solid var(--border)",display:"flex",flexDirection:"column",flex:F?"1 1 0":"0 0 auto",minHeight:0,overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",flexShrink:0,gap:0,padding:"2px 4px"},children:[(0,n.jsxs)("button",{onClick:()=>{U(e=>!e),J(e=>e+1)},style:{display:"flex",alignItems:"center",gap:6,padding:"6px 6px 6px 6px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:600,letterSpacing:"0.05em",textTransform:"uppercase",textAlign:"left",flexShrink:0},children:[(0,n.jsx)("svg",{width:"9",height:"9",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:F?"rotate(90deg)":"none",transition:"transform 0.15s",flexShrink:0},children:(0,n.jsx)("polyline",{points:"3 2 7 5 3 8"})}),"Explorer"]}),(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:q,onChange:e=>G(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"}}),q&&(0,n.jsx)("button",{type:"button",onClick:()=>G(""),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"})]})})]})]}),F&&(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",overflowX:"hidden"},children:(0,n.jsx)(_,{cwd:ex,onOpenFile:u??(()=>{}),onExploreFile:p,refreshKey:V,onAtMention:x,searchQuery:q,onSearchChange:G})})]}),(0,n.jsx)(Z,{open:R,initialPath:ex||C||null,onClose:()=>W(!1),onSelect:e=>void eh(e)})]})}function ei({node:e,selectedSessionId:t,onSelectSession:r,onRenamed:i,onSessionDeleted:l,depth:s}){let[a,d]=(0,o.useState)(!1),c=e.children.length>0;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{position:"relative"},children:[s>0&&(0,n.jsx)("div",{style:{position:"absolute",left:12*s+6,top:0,bottom:0,width:1,background:"var(--border)",pointerEvents:"none"}}),(0,n.jsx)(el,{session:e.session,isSelected:e.session.id===t,onClick:()=>r(e.session),onRenamed:i,onDeleted:e=>l?.(e),depth:s,hasChildren:c,collapsed:a,onToggleCollapse:()=>d(e=>!e)})]}),c&&!a&&(0,n.jsx)("div",{children:e.children.map(e=>(0,n.jsx)(ei,{node:e,selectedSessionId:t,onSelectSession:r,onRenamed:i,onSessionDeleted:l,depth:s+1},e.session.id))})]})}function el({session:e,isSelected:t,onClick:r,onRenamed:i,onDeleted:l,depth:s=0,hasChildren:a=!1,collapsed:d=!1,onToggleCollapse:c}){let[u,p]=(0,o.useState)(!1),[h,x]=(0,o.useState)(!1),[g,f]=(0,o.useState)(""),[v,m]=(0,o.useState)(!1),[y,b]=(0,o.useState)(!1),j=(0,o.useRef)(null),k=e.name||e.firstMessage.slice(0,50)||e.id.slice(0,12),w=(0,o.useCallback)(t=>{t.stopPropagation(),f(e.name??""),x(!0),setTimeout(()=>j.current?.select(),0)},[e.name]),S=(0,o.useCallback)(async()=>{let t=g.trim();if(x(!1),t!==(e.name??""))try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t})}),i?.()}catch{}},[g,e.id,e.name,i]),C=(0,o.useCallback)(e=>{e.stopPropagation(),m(!0)},[]),T=(0,o.useCallback)(async t=>{t.stopPropagation(),m(!1),b(!0);try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"DELETE"}),l?.(e.id)}catch{b(!1)}},[e.id,l]),z=(0,o.useCallback)(e=>{e.stopPropagation(),m(!1)},[]);return(0,n.jsx)("div",{onClick:v||h?void 0:r,onMouseEnter:()=>p(!0),onMouseLeave:()=>{p(!1)},style:{height:54,display:"flex",alignItems:"center",paddingLeft:s>0?12*s+14:14,paddingRight:8,cursor:v||h?"default":"pointer",background:v?"rgba(239,68,68,0.06)":t?"var(--bg-selected)":u?"var(--bg-hover)":"transparent",borderLeft:v?"2px solid #ef4444":t?"2px solid var(--accent)":"2px solid transparent",transition:"background 0.1s",opacity:y?.5:1,gap:6,overflow:"hidden"},children:v?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0,fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["Delete ",(0,n.jsxs)("span",{style:{fontWeight:600},children:["“",k.slice(0,22),k.length>22?"…":"","”"]}),"?"]}),(0,n.jsxs)("div",{style:{display:"flex",gap:5,flexShrink:0},children:[(0,n.jsxs)("button",{onClick:T,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:z,style:{display:"flex",alignItems:"center",justifyContent:"center",height:30,padding:"0 11px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:500,whiteSpace:"nowrap"},children:"Cancel"})]})]}):h?(0,n.jsx)("input",{ref:j,value:g,onChange:e=>f(e.target.value),onBlur:S,onKeyDown:e=>{"Enter"===e.key&&S(),"Escape"===e.key&&x(!1)},autoFocus:!0,style:{flex:1,fontSize:12,padding:"5px 8px",border:"1px solid var(--accent)",borderRadius:5,outline:"none",background:"var(--bg)",color:"var(--text)",height:30}}):(0,n.jsxs)(n.Fragment,{children:[s>0&&(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:t?500:400,lineHeight:1.4,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text)"},title:k,children:k}),(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:X(e.modified)}),(0,n.jsxs)("span",{children:[e.messageCount," msgs"]})]})]}),a&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),c?.()},title:d?"Expand forks":"Collapse forks",style:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,flexShrink:0,background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",transform:d?"rotate(-90deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})}),u&&(0,n.jsxs)("div",{style:{display:"flex",gap:4,flexShrink:0},children:[(0,n.jsx)("button",{onClick:w,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:C,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"})]})})]})]})})}let es=new Set;function ea(e){return es.add(e),()=>{es.delete(e)}}function ed(){return"u"<typeof document?"light":document.documentElement.classList.contains("dark")?"dark":"light"}function ec(){return"light"}function eu(){let e=(0,o.useSyncExternalStore)(ea,ed,ec);return{theme:e,toggleTheme:(0,o.useCallback)(e=>{let t="dark"===ed()?"light":"dark",r=()=>{"dark"===t?document.documentElement.classList.add("dark"):document.documentElement.classList.remove("dark");try{localStorage.setItem("pi-theme",t)}catch{}es.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 ep(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=eh(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=ex(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=eh(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=eh(t);i?r.push({type:"widget",...i}):t&&r.push({type:"text",content:t}),n.lastIndex=o=a+3}else{let t=eh(e.slice(s).trim());if(t){let e=ex(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 eh(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 ex(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 eg=/<(iframe|object|embed|meta|link|base|form)[\s>][\s\S]*?<\/\1>/gi,ef=/<(iframe|object|embed|meta|link|base)\b[^>]*\/?>/gi;function ev(e){return e.replace(eg,"").replace(ef,"")}let em=["--bg","--bg-panel","--bg-hover","--bg-selected","--border","--text","--text-muted","--text-dim","--accent","--accent-hover"];function ey(){if("u"<typeof document)return{};let e=getComputedStyle(document.documentElement),t={};for(let r of em){let n=e.getPropertyValue(r).trim();n&&(t[r]=n)}return t}let eb=["--bg","--bg-panel","--bg-hover","--bg-selected","--border","--text","--text-muted","--text-dim","--accent","--accent-hover"];async function ej(e){if(navigator.clipboard?.writeText)return void await navigator.clipboard.writeText(e);let t=document.createElement("textarea");t.value=e,t.style.position="fixed",t.style.inset="0",t.style.opacity="0",document.body.appendChild(t),t.focus(),t.select();let r=document.execCommand("copy");if(document.body.removeChild(t),!r)throw Error("Clipboard copy failed.")}async function ek(e){let t=await ew(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=eT({width:e.bodyWidth||640,height:e.bodyHeight||360}),r=function(e){let t=document.createElement("template");t.innerHTML=ev(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 eS(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 eb.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 eL(eI('<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 ew(e){var t;let r,n,o,i,l=function(e){let t=ev(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;eS(l),l.setAttribute("xmlns","http://www.w3.org/2000/svg");let s=eT((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=eC(t.getAttribute("width"))??r?.width??640,o=r?r.height/r.width:.5625,i=eC(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),eL(eI(new XMLSerializer().serializeToString(l)),s.width,s.height)}function eS(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 eC(e){if(!e||e.includes("%"))return null;let t=Number.parseFloat(e);return Number.isFinite(t)&&t>0?t:null}function eT(e){let t=ez(Math.ceil(e.width||640),240,2e3),r=ez(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 ez(e,t,r){return Math.min(Math.max(e,t),r)}function eL(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 eI(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 eM=/cdnjs\.cloudflare\.com|cdn\.jsdelivr\.net|unpkg\.com|esm\.sh/,eR=new Map;function eW(e){return e.slice(0,200)}function eE({code:e,isStreaming:t,title:r,showOverlay:i,onSendMessage:l}){let{isDark:s}=eu(),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)(()=>eR.get(eW(e))??0),[v,m]=(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),z=(0,o.useRef)(""),L=(0,o.useRef)((eR.get(eW(e))??0)>0),I=(0,o.useRef)(!1),M=(0,o.useRef)(s),R=(0,o.useMemo)(()=>eM.test(e),[e]),W=(0,o.useMemo)(()=>{let e;return function(e="",t=!1){return`<!DOCTYPE html>
|
|
1
|
+
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8974],{14755:(e,t,r)=>{"use strict";r.d(t,{C1:()=>l,ES:()=>u,IN:()=>i,Tt:()=>o,me:()=>s,xG:()=>c,yK:()=>a});let n="subagent",o=[],i=["read","bash","edit","write"],l=["bash","read","edit","write","grep","find","ls"],s=[...l,"kernel_plot_run","kernel_plot_stop","kernel_plot_artifacts"],a=[...l,n];function d(e){return[...e].sort().join(",")}function c(e){switch(e){case"none":return o;case"default":return i;case"full-plot":return s;case"agent":return a;default:return l}}function u(e){let t=e.filter(e=>e.active).map(e=>e.name),r=d(t);return""===r?"none":r===d(i)?"default":r===d(l)?"full":r===d(s)?"full-plot":r===d(a)||t.includes(n)?"agent":"default"}},30054:(e,t,r)=>{"use strict";r.d(t,{AppShell:()=>n_});var n=r(95155),o=r(12115),i=r(73321);let l="var(--text-dim)";function s({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:l}),(0,n.jsx)("path",{d:"M1 6h14.5L14 13H2L1 6Z",stroke:l,strokeWidth:"1",fill:l,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:l,strokeWidth:"1",fill:l,fillOpacity:"0.1"})})}function a({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:l,strokeWidth:"1",fill:l,fillOpacity:"0.08"}),(0,n.jsx)("path",{d:"M10 2v3h3",stroke:l,strokeWidth:"1",fill:"none",strokeLinejoin:"round"})]})}function d({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:l,strokeWidth:"0.9",fill:l,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:l,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:l,letterSpacing:"0",children:e})]})}function c({size:e=14}){return(0,n.jsx)(d,{label:"TS",size:e})}function u({size:e=14}){return(0,n.jsx)(d,{label:"TSX",size:e})}function p({size:e=14}){return(0,n.jsx)(d,{label:"JS",size:e})}function h({size:e=14}){return(0,n.jsx)(d,{label:"JSX",size:e})}function x({size:e=14}){return(0,n.jsx)(d,{label:"PY",size:e})}function g({size:e=14}){return(0,n.jsx)(d,{label:"{}",size:e})}function f({size:e=14}){return(0,n.jsx)(d,{label:"CSS",size:e})}function v({size:e=14}){return(0,n.jsx)(d,{label:"SC",size:e})}function m({size:e=14}){return(0,n.jsx)(d,{label:"HTM",size:e})}function y({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:l,strokeWidth:"0.9",fill:l,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:l,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M3.5 9.5V7l1.5 1.5L6.5 7v2.5",stroke:l,strokeWidth:"0.9",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,n.jsx)("path",{d:"M8 7v2.5M7 9l1 1.5 1-1.5",stroke:l,strokeWidth:"0.9",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]})}function b({size:e=14}){return(0,n.jsx)(d,{label:"YML",size:e})}function j({size:e=14}){return(0,n.jsx)(d,{label:"TOM",size:e})}function k({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:l,strokeWidth:"0.9",fill:l,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:l,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M4 7.5l2 1.5-2 1.5",stroke:l,strokeWidth:"0.95",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,n.jsx)("path",{d:"M7.5 10.5h2.5",stroke:l,strokeWidth:"0.95",strokeLinecap:"round"})]})}function w({size:e=14}){return(0,n.jsx)(d,{label:"RS",size:e})}function S({size:e=14}){return(0,n.jsx)(d,{label:"GO",size:e})}function C({size:e=14}){return(0,n.jsx)(d,{label:"SQL",size:e})}function T({size:e=14}){return(0,n.jsx)(d,{label:"GQL",size:e})}function z({size:e=14}){return(0,n.jsx)(d,{label:"TF",size:e})}function L({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:l,strokeWidth:"0.9",fill:l,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:l,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:l,strokeWidth:"0.8"}),(0,n.jsx)("rect",{x:"6",y:"6.5",width:"2",height:"1.5",rx:"0.3",stroke:l,strokeWidth:"0.8"}),(0,n.jsx)("rect",{x:"3.5",y:"8.5",width:"2",height:"1.5",rx:"0.3",stroke:l,strokeWidth:"0.8"})]})}function I({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:l,strokeWidth:"0.9",fill:l,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:l,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"5.5",cy:"8.5",r:"1.5",stroke:l,strokeWidth:"0.9"}),(0,n.jsx)("path",{d:"M7 8.5h2.5M8.5 8.5v1.5",stroke:l,strokeWidth:"0.9",strokeLinecap:"round"})]})}function M({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:l,strokeWidth:"0.9",fill:l,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:l,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"5",cy:"6.5",r:"1",stroke:l,strokeWidth:"0.85"}),(0,n.jsx)("circle",{cx:"9",cy:"6.5",r:"1",stroke:l,strokeWidth:"0.85"}),(0,n.jsx)("circle",{cx:"5",cy:"10",r:"1",stroke:l,strokeWidth:"0.85"}),(0,n.jsx)("path",{d:"M5 7.5V9",stroke:l,strokeWidth:"0.85",strokeLinecap:"round"}),(0,n.jsx)("path",{d:"M9 7.5v.5a2 2 0 0 1-2 2H6",stroke:l,strokeWidth:"0.85",strokeLinecap:"round",fill:"none"})]})}function R({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:l,strokeWidth:"0.9",fill:l,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:l,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:l,strokeWidth:"0.9"}),(0,n.jsx)("path",{d:"M5.5 8.5V7.5a1.5 1.5 0 0 1 3 0v1",stroke:l,strokeWidth:"0.9",strokeLinecap:"round",fill:"none"})]})}function W({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:l,strokeWidth:"0.9",fill:l,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:l,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"7",cy:"8.5",r:"1.3",stroke:l,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:l,strokeWidth:"0.8",strokeLinecap:"round"})]})}function E(e,t=14){let r=e.toLowerCase(),o=r.split(".").pop()??"";if("dockerfile"===r||r.startsWith("dockerfile."))return(0,n.jsx)(L,{size:t});if(".env"===r||r.startsWith(".env."))return(0,n.jsx)(I,{size:t});if(".gitignore"===r||".gitattributes"===r||".gitmodules"===r)return(0,n.jsx)(M,{size:t});if("package-lock.json"===r||"yarn.lock"===r||"bun.lock"===r||"pnpm-lock.yaml"===r||"cargo.lock"===r)return(0,n.jsx)(R,{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)(W,{size:t});switch(o){case"ts":return(0,n.jsx)(c,{size:t});case"tsx":return(0,n.jsx)(u,{size:t});case"js":case"mjs":case"cjs":return(0,n.jsx)(p,{size:t});case"jsx":return(0,n.jsx)(h,{size:t});case"py":return(0,n.jsx)(x,{size:t});case"json":case"jsonl":return(0,n.jsx)(g,{size:t});case"css":case"less":return(0,n.jsx)(f,{size:t});case"scss":return(0,n.jsx)(v,{size:t});case"html":case"htm":return(0,n.jsx)(m,{size:t});case"md":case"mdx":return(0,n.jsx)(y,{size:t});case"yaml":case"yml":return(0,n.jsx)(b,{size:t});case"toml":return(0,n.jsx)(j,{size:t});case"sh":case"bash":case"zsh":case"fish":return(0,n.jsx)(k,{size:t});case"rs":return(0,n.jsx)(w,{size:t});case"go":return(0,n.jsx)(S,{size:t});case"sql":return(0,n.jsx)(C,{size:t});case"graphql":case"gql":return(0,n.jsx)(T,{size:t});case"tf":case"hcl":return(0,n.jsx)(z,{size:t});case"lock":return(0,n.jsx)(R,{size:t});default:return(0,n.jsx)(a,{size:t})}}function $(e){return/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith("\\\\")?e.replace(/\\/g,"/"):e}function N(e){return $(e).split("/").filter(Boolean).map(encodeURIComponent).join("/")}function B(e){let t=$(e).replace(/\/+$/,"");return t.split("/").pop()??t}function P(e,t){if(!t)return e;let r=$(e),n=$(t).replace(/\/$/,"");return r.startsWith(n+"/")?r.slice(n.length+1):e}async function A(e){let t=N(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,`${$(e).replace(/\/$/,"")}/${r}`),isDir:t.isDir,size:t.size,children:t.isDir?[]:void 0,loaded:!t.isDir}}):[]}function H(e,t){let r=t.trim().toLowerCase();return!!(!r||e.name.toLowerCase().includes(r))||(e.children??[]).some(e=>H(e,r))}function O(e){return!!Array.from(e.types).includes("Files")||Array.from(e.items).some(e=>"file"===e.kind)}function D(e){return Array.from(e.files).filter(e=>!!e.name)}function F(e,t){return e===t?".":P(e,t)}function U({node:e,depth:t,cwd:r,onOpenFile:i,onExploreFile:l,onAtMention:a,expandedPaths:d,onToggleExpanded:c,onUploadFiles:u,uploadTargetPath:p,refreshKey:h,searchQuery:x}){let g=!!x?.trim(),f=g?e.isDir:d.has(e.fullPath),[v,m]=(0,o.useState)(e.children??[]),[y,b]=(0,o.useState)(e.loaded??!1),[j,k]=(0,o.useState)(!1),[w,S]=(0,o.useState)(!1),[C,T]=(0,o.useState)(!1),z=e.isDir&&(C||p===e.fullPath),L=!!a&&w,I=!!l&&w&&!e.isDir&&e.name.toLowerCase().endsWith(".h5ad"),M=L||I,R=g?v.filter(e=>H(e,x??"")):v,W=(0,o.useCallback)(async(t=!1)=>{if(!y||t){k(!0);try{let t=await A(e.fullPath);m(t),b(!0)}catch{}finally{k(!1)}}},[y,e.fullPath]),$=(0,o.useRef)(y);(0,o.useEffect)(()=>{$.current=y}),(0,o.useEffect)(()=>{f&&y&&W(!0)},[h]);let N=(0,o.useCallback)(()=>{if(e.isDir){let t=!f;c(e.fullPath,t),t&&!y&&W()}else i(e.fullPath,e.name)},[e.isDir,e.fullPath,e.name,y,f,W,i,c]),B=(0,o.useCallback)(t=>{e.isDir&&O(t.dataTransfer)&&(t.preventDefault(),t.stopPropagation(),t.dataTransfer.dropEffect="copy",T(!0))},[e.isDir]),F=(0,o.useCallback)(t=>{e.isDir&&O(t.dataTransfer)&&(t.preventDefault(),t.stopPropagation(),t.dataTransfer.dropEffect="copy")},[e.isDir]),_=(0,o.useCallback)(t=>{if(!e.isDir)return;let r=t.relatedTarget;r instanceof Node&&t.currentTarget.contains(r)||T(!1)},[e.isDir]),V=(0,o.useCallback)(t=>{if(!e.isDir||!O(t.dataTransfer))return;t.preventDefault(),t.stopPropagation(),T(!1);let r=D(t.dataTransfer);r.length>0&&(u(r,e.fullPath),f||c(e.fullPath,!0),y||W())},[W,y,e.fullPath,e.isDir,c,u,f]);return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{onClick:N,onMouseEnter:()=>S(!0),onMouseLeave:()=>S(!1),onDragEnter:B,onDragOver:F,onDragLeave:_,onDrop:V,style:{position:"relative",display:"flex",alignItems:"center",gap:4,paddingLeft:8+14*t,paddingRight:M?L&&I?146:82:8,height:24,cursor:"pointer",background:z?"rgba(37,99,235,0.14)":w?"var(--bg-hover)":"transparent",outline:z?"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:f?"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)(s,{size:14,open:f}):E(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}),j&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",children:(0,n.jsx)("path",{d:"M12 2v4M12 18v4M4.93 4.93l2.83 2.83M16.24 16.24l2.83 2.83M2 12h4M18 12h4"})}),M&&(0,n.jsxs)("div",{style:{position:"absolute",right:4,top:"50%",transform:"translateY(-50%)",display:"flex",alignItems:"center",gap:4},children:[I&&(0,n.jsxs)("button",{onClick:t=>{t.stopPropagation(),l?.(e.fullPath,e.name)},title:"Explore H5AD",style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,padding:"0 8px",height:20,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:4,color:"var(--accent)",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.1",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"7"}),(0,n.jsx)("path",{d:"M16 16l4 4"}),(0,n.jsx)("path",{d:"M8.5 11h5"}),(0,n.jsx)("path",{d:"M11 8.5v5"})]}),"@explore"]}),L&&(0,n.jsxs)("button",{onClick:t=>{t.stopPropagation(),a?.(P(e.fullPath,r))},title:"Insert path into chat",style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,padding:"0 8px",height:20,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:4,color:"var(--accent)",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"4"}),(0,n.jsx)("path",{d:"M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8"})]}),"@mention"]})]})]}),e.isDir&&f&&(0,n.jsxs)("div",{children:[R.map(e=>(0,n.jsx)(U,{node:e,depth:t+1,cwd:r,onOpenFile:i,onExploreFile:l,onAtMention:a,expandedPaths:d,onToggleExpanded:c,onUploadFiles:u,uploadTargetPath:p,refreshKey:h,searchQuery:x},e.fullPath)),0===R.length&&y&&!g&&(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 _({cwd:e,onOpenFile:t,onExploreFile:r,refreshKey:i,onAtMention:l,searchQuery:s="",onSearchChange:a}){let[d,c]=(0,o.useState)([]),[u,p]=(0,o.useState)(!0),[h,x]=(0,o.useState)(null),[g,f]=(0,o.useState)(new Set),[v,m]=(0,o.useState)(!1),[y,b]=(0,o.useState)(null),[j,k]=(0,o.useState)(null),w=(0,o.useRef)(null),S=(0,o.useRef)(null),C=(0,o.useRef)(0),T=(0,o.useCallback)((e,t)=>(p(t),x(null),A(e).then(e=>c(e)).catch(e=>x(String(e))).finally(()=>p(!1))),[]),z=(0,o.useCallback)((e,t)=>{f(r=>{let n=new Set(r);return t?n.add(e):n.delete(e),n})},[]);(0,o.useEffect)(()=>{let t=w.current!==e;w.current=e,t&&f(new Set),T(e,t)},[e,i,T]),(0,o.useEffect)(()=>()=>{S.current&&clearTimeout(S.current)},[]);let L=(0,o.useCallback)(()=>{T(e,0===d.length)},[e,d.length,T]),I=(0,o.useCallback)(()=>{S.current&&clearTimeout(S.current),S.current=setTimeout(()=>k(null),5e3)},[]),M=(0,o.useCallback)((t,r)=>{if(0===t.length)return;C.current=0,m(!1),S.current&&clearTimeout(S.current);let n=t.reduce((e,t)=>e+t.size,0),o=F(r,e);b(r),k({phase:"uploading",targetPath:r,fileCount:t.length,loaded:0,total:n,message:`Uploading ${t.length} file${1===t.length?"":"s"} to ${o}`});let i=new FormData;t.forEach(e=>i.append("files",e,e.name));let l=new XMLHttpRequest,s=N(r);l.open("POST",`/api/files/${s}?type=upload`),l.upload.onprogress=e=>{e.lengthComputable&&k(t=>t?{...t,loaded:e.loaded,total:e.total}:t)},l.onload=()=>{b(null);let e={};try{e=JSON.parse(l.responseText)}catch{e={}}if(l.status>=200&&l.status<300){let i=e.uploaded??[],l=e.failed??[],s=[...i.filter(e=>e.name!==e.originalName).slice(0,3).map(e=>`${e.originalName} saved as ${e.name}`),...l.slice(0,3).map(e=>`${e.name}: ${e.error}`)];k({phase:l.length>0?"warning":"success",targetPath:r,fileCount:t.length,loaded:n,total:n,message:l.length>0?`Uploaded ${i.length}, ${l.length} failed`:`Uploaded ${i.length} file${1===i.length?"":"s"} to ${o}`,details:s}),L(),I()}else{let o=e.error??`Upload failed (HTTP ${l.status})`;k({phase:(l.status,"error"),targetPath:r,fileCount:t.length,loaded:0,total:n,message:o,details:403===l.status?["Check directory write permission or project access."]:void 0}),I()}},l.onerror=()=>{b(null),k({phase:"error",targetPath:r,fileCount:t.length,loaded:0,total:n,message:"Upload failed due to a network error"}),I()},l.onabort=()=>{b(null),k({phase:"error",targetPath:r,fileCount:t.length,loaded:0,total:n,message:"Upload canceled"}),I()},l.send(i)},[e,L,I]),R=(0,o.useCallback)(e=>{O(e.dataTransfer)&&(e.preventDefault(),C.current+=1,m(!0))},[]),W=(0,o.useCallback)(e=>{O(e.dataTransfer)&&(e.preventDefault(),e.dataTransfer.dropEffect="copy")},[]),E=(0,o.useCallback)(()=>{C.current-=1,C.current<=0&&(C.current=0,m(!1))},[]),$=(0,o.useCallback)(t=>{if(!O(t.dataTransfer))return;t.preventDefault(),C.current=0,m(!1);let r=D(t.dataTransfer);r.length>0&&M(r,e)},[e,M]),B=s.trim()?d.filter(e=>H(e,s)):d,P=s.trim().length>0;return u?(0,n.jsx)(V,{cwd:e,isDraggingFiles:v,uploadState:j,onDragEnter:R,onDragOver:W,onDragLeave:E,onDrop:$,children:(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:"Loading files..."})}):h?(0,n.jsx)(V,{cwd:e,isDraggingFiles:v,uploadState:j,onDragEnter:R,onDragOver:W,onDragLeave:E,onDrop:$,children:(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"#f87171"},children:h})}):(0,n.jsx)(V,{cwd:e,isDraggingFiles:v,uploadState:j,onDragEnter:R,onDragOver:W,onDragLeave:E,onDrop:$,children:(0,n.jsxs)("div",{style:{padding:"2px 4px"},children:[B.map(o=>(0,n.jsx)(U,{node:o,depth:0,cwd:e,onOpenFile:t,onExploreFile:r,onAtMention:l,expandedPaths:g,onToggleExpanded:z,onUploadFiles:M,uploadTargetPath:y,refreshKey:i,searchQuery:s},o.fullPath)),0===B.length&&(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:P?"No matching files":"No files found"})]})})}function V({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 ",F(e,e)]})}),r&&(0,n.jsxs)("div",{style:{margin:"6px",padding:"7px 8px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",boxShadow:"0 8px 24px rgba(0,0,0,0.12)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:7,minWidth:0},children:[(0,n.jsx)("span",{style:{width:8,height:8,borderRadius:999,background:c,flexShrink:0}}),(0,n.jsx)("span",{title:r.message,style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text)",fontSize:11,fontWeight:600},children:r.message}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,flexShrink:0},children:"uploading"===r.phase?`${d}%`:function(e){if(!Number.isFinite(e)||e<=0)return"0 B";let t=["B","KB","MB","GB"],r=e,n=0;for(;r>=1024&&n<t.length-1;)r/=1024,n+=1;return`${r>=10||0===n?Math.round(r):r.toFixed(1)} ${t[n]}`}(r.total)})]}),(0,n.jsx)("div",{style:{marginTop:6,height:3,borderRadius:999,background:"var(--bg)",overflow:"hidden"},children:(0,n.jsx)("div",{style:{width:`${d}%`,height:"100%",borderRadius:999,background:c,transition:"width 0.15s ease"}})}),r.details&&r.details.length>0&&(0,n.jsx)("div",{style:{marginTop:5,display:"grid",gap:2},children:r.details.map(e=>(0,n.jsx)("div",{title:e,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontSize:10},children:e},e))})]})]})}function J(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 q(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 K({open:e,cwd:t,homeDir:r,onClose:i,onSelectSession:l}){let[s,a]=(0,o.useState)(""),[d,c]=(0,o.useState)("current"),[u,p]=(0,o.useState)([]),[h,x]=(0,o.useState)(!1),[g,f]=(0,o.useState)(null),[v,m]=(0,o.useState)(!1),y=(0,o.useRef)(null);if((0,o.useEffect)(()=>{e&&(c(t?"current":"all"),setTimeout(()=>y.current?.focus(),0))},[e,t]),(0,o.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&i()};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,i]),(0,o.useEffect)(()=>{if(!e)return;let r=s.trim();if(r.length<2){p([]),x(!1),f(null),m(!1);return}let n=new AbortController,o=setTimeout(async()=>{x(!0),f(null);try{let e=new URLSearchParams({q:r,scope:d});t&&e.set("cwd",t);let o=await fetch(`/api/search?${e.toString()}`,{signal:n.signal});if(!o.ok)throw Error(`HTTP ${o.status}`);let i=await o.json();if(i.error)throw Error(i.error);p(i.results??[]),m(i.truncated??!1)}catch(e){"AbortError"!==e.name&&f(String(e))}finally{x(!1)}},180);return()=>{clearTimeout(o),n.abort()}},[e,s,d,t]),!e)return null;let b=s.trim(),j=u.reduce((e,t)=>e+t.matches.length,0);return(0,n.jsx)("div",{role:"dialog","aria-modal":"true","aria-label":"Search conversation history",style:{position:"fixed",inset:0,zIndex:500,display:"flex",alignItems:"flex-start",justifyContent:"center",padding:"8vh 16px 16px",background:"rgba(0,0,0,0.28)"},onMouseDown:e=>{e.target===e.currentTarget&&i()},children:(0,n.jsxs)("div",{style:{width:"min(760px, 100%)",maxHeight:"78vh",display:"flex",flexDirection:"column",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 16px 48px rgba(0,0,0,0.24)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:12,borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1,minWidth:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:8,padding:"0 10px"},children:[(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"7",cy:"7",r:"4.5"}),(0,n.jsx)("path",{d:"M10.5 10.5 13.5 13.5"})]}),(0,n.jsx)("input",{ref:y,value:s,onChange:e=>a(e.target.value),placeholder:"Search conversation history...",style:{flex:1,minWidth:0,height:38,background:"transparent",border:"none",outline:"none",color:"var(--text)",fontSize:14}})]}),(0,n.jsx)("button",{type:"button",onClick:i,title:"Close",style:{width:34,height:34,display:"inline-flex",alignItems:"center",justifyContent:"center",background:"none",border:"none",borderRadius:7,color:"var(--text-dim)",cursor:"pointer"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-dim)"},children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,n.jsx)("path",{d:"M4 4 12 12"}),(0,n.jsx)("path",{d:"M12 4 4 12"})]})})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:10},children:[(0,n.jsx)("div",{style:{display:"inline-flex",padding:2,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7},children:[{value:"current",label:"Current project",disabled:!t},{value:"all",label:"All history",disabled:!1}].map(e=>(0,n.jsx)("button",{type:"button",disabled:e.disabled,onClick:()=>c(e.value),style:{height:24,padding:"0 9px",background:d===e.value?"var(--bg-selected)":"transparent",border:"none",borderRadius:5,color:e.disabled?"var(--text-dim)":d===e.value?"var(--text)":"var(--text-muted)",cursor:e.disabled?"not-allowed":"pointer",fontSize:11,fontWeight:500},children:e.label},e.value))}),(0,n.jsx)("div",{style:{flex:1,minWidth:0,color:"var(--text-dim)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"current"===d&&t?J(t,r):"Searching every saved session"})]})]}),(0,n.jsxs)("div",{style:{flex:1,overflowY:"auto",minHeight:180},children:[b.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."}),b.length>=2&&h&&0===u.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Searching..."}),g&&(0,n.jsx)("div",{style:{padding:18,color:"#ef4444",fontSize:13},children:g}),b.length>=2&&!h&&!g&&0===u.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"No matching conversations found."}),u.map(e=>(0,n.jsxs)("div",{style:{borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{l(e.session),i()},style:{width:"100%",display:"flex",alignItems:"center",gap:10,padding:"10px 12px",background:"var(--bg-panel)",border:"none",borderBottom:"1px solid var(--border)",color:"var(--text)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13,fontWeight:600},children:e.session.name||e.session.firstMessage||"(no messages)"}),(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:11},children:q(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:J(e.session.cwd,r)})]}),e.matchCount>e.matches.length&&(0,n.jsxs)("span",{style:{flexShrink:0,color:"var(--text-muted)",fontSize:11},children:[e.matchCount," matches"]})]}),e.matches.map(t=>(0,n.jsxs)("button",{type:"button",onClick:()=>{l(e.session),i()},style:{width:"100%",padding:"9px 14px 9px 28px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:3},children:[(0,n.jsx)("span",{style:{minWidth:54,color:"user"===t.role?"var(--accent)":"var(--text-dim)",fontSize:11,fontWeight:600,textTransform:"capitalize"},children:t.role}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:q(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,b)})]},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:j>0?`${j}${v?"+":""} results`:"Esc to close"}),h&&u.length>0&&(0,n.jsx)("span",{children:"Updating..."})]})]})})}function Z({open:e,initialPath:t,onClose:r,onSelect:i}){let[l,s]=(0,o.useState)(""),[a,d]=(0,o.useState)(null),[c,u]=(0,o.useState)([]),[p,h]=(0,o.useState)([]),[x,g]=(0,o.useState)(""),[f,v]=(0,o.useState)(!1),[m,y]=(0,o.useState)(null),b=(0,o.useCallback)(async e=>{v(!0),y(null);try{let t=e?`/api/projects/browse?dir=${encodeURIComponent(e)}`:"/api/projects/browse",r=await fetch(t),n=await r.json();if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);s(n.current??""),d(n.parent??null),u(n.directories??[]),h(n.drives??[]),g(n.current??"")}catch(e){y(e instanceof Error?e.message:String(e))}finally{v(!1)}},[]);return((0,o.useEffect)(()=>{e&&b(t||void 0)},[b,t,e]),(0,o.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&r()};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[r,e]),e)?(0,n.jsx)("div",{onMouseDown:e=>{e.target===e.currentTarget&&r()},style:{position:"fixed",inset:0,zIndex:1200,display:"flex",alignItems:"center",justifyContent:"center",padding:18,background:"rgba(0,0,0,0.34)"},children:(0,n.jsxs)("div",{style:{width:"min(560px, 100%)",maxHeight:"min(720px, 88dvh)",display:"flex",flexDirection:"column",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 12px 40px rgba(0,0,0,0.25)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{height:48,padding:"0 14px",display:"flex",alignItems:"center",justifyContent:"space-between",borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:14,fontWeight:750},children:"Select project path"}),(0,n.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:11},children:"Server filesystem"})]}),(0,n.jsx)("button",{type:"button",onClick:r,"aria-label":"Close",title:"Close",style:{width:30,height:30,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:"x"})]}),(0,n.jsx)("div",{style:{padding:12,borderBottom:"1px solid var(--border)"},children:(0,n.jsxs)("form",{onSubmit:e=>{e.preventDefault(),x.trim()&&b(x.trim())},style:{display:"flex",gap:8},children:[(0,n.jsx)("input",{value:x,onChange:e=>g(e.target.value),placeholder:"/path/to/project",style:{flex:1,minWidth:0,height:32,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:12,outline:"none"}}),(0,n.jsx)("button",{type:"submit",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:"Go"})]})}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"8px 12px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsx)("button",{type:"button",onClick:()=>a&&void b(a),disabled:!a,style:{width:28,height:28,border:"1px solid var(--border)",borderRadius:6,background:a?"var(--bg)":"transparent",color:a?"var(--text-muted)":"var(--text-dim)",cursor:a?"pointer":"default",padding:0},title:"Up",children:(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"2 6.5 5 3.5 8 6.5"})})}),p.length>0&&(0,n.jsxs)("select",{value:p.find(e=>l.toLowerCase().startsWith(e.toLowerCase()))??"",onChange:e=>{e.target.value&&b(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"}),p.map(e=>(0,n.jsx)("option",{value:e,children:e},e))]}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11},title:l,children:l})]}),(0,n.jsx)("div",{style:{flex:1,minHeight:220,maxHeight:360,overflowY:"auto",padding:6},children:f?(0,n.jsx)("div",{style:{padding:18,color:"var(--text-muted)",fontSize:12},children:"Loading..."}):m?(0,n.jsx)("div",{style:{padding:18,color:"#f87171",fontSize:12},children:m}):0===c.length?(0,n.jsx)("div",{style:{padding:18,color:"var(--text-muted)",fontSize:12},children:"No subdirectories"}):c.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>void b(e.path),style:{width:"100%",display:"flex",alignItems:"center",gap:9,padding:"8px 9px",border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:12},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},title:e.path,children:[(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--accent)",flexShrink:0},children:(0,n.jsx)("path",{d:"M3 6.5A2.5 2.5 0 0 1 5.5 4H10l2 2.5h6.5A2.5 2.5 0 0 1 21 9v8.5A2.5 2.5 0 0 1 18.5 20h-13A2.5 2.5 0 0 1 3 17.5v-11Z"})}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0},children:(0,n.jsx)("polyline",{points:"3.5 2 6.5 5 3.5 8"})})]},e.path))}),(0,n.jsxs)("div",{style:{padding:12,borderTop:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",gap:10},children:[(0,n.jsx)("div",{style:{minWidth:0,color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:l,children:l}),(0,n.jsxs)("div",{style:{display:"flex",gap:7,flexShrink:0},children:[(0,n.jsx)("button",{type:"button",onClick:r,style:{height:32,padding:"0 12px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Cancel"}),(0,n.jsx)("button",{type:"button",onClick:()=>l&&i(l),disabled:!l,style:{height:32,padding:"0 12px",border:"none",borderRadius:6,background:l?"var(--accent)":"var(--bg-hover)",color:l?"#fff":"var(--text-dim)",cursor:l?"pointer":"default",fontSize:12,fontWeight:650},children:"Select"})]})]})]})}):null}let G="AnnoVibe";async function Y(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 X(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 Q(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 ee(e,t){if(!e)return"No Project";let r=e.replace(/[\\/]+$/,""),n=r.includes("/")?"/":"\\";return r.split(n).filter(Boolean).pop()||Q(e,t)}function et(e){return e.lastAccessed??e.created??""}let er="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";function en(){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:er[Math.floor(Math.random()*er.length)]).join("")),l.current<r?i.current=requestAnimationFrame(o):n(e)};return i.current=requestAnimationFrame(o),()=>{i.current&&cancelAnimationFrame(i.current)}},[e,t]),r}(e?"v0.8.24":G,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 eo({selectedSessionId:e,onSelectSession:t,onNewSession:r,initialSessionId:i,onInitialRestoreDone:l,refreshKey:s,onSessionDeleted:a,selectedCwd:d,onCwdChange:c,onOpenFile:u,onExploreFile:p,explorerRefreshKey:h,onAtMention:x}){let[g,f]=(0,o.useState)([]),[v,m]=(0,o.useState)([]),[y,b]=(0,o.useState)(!0),[j,k]=(0,o.useState)(null),[w,S]=(0,o.useState)(null),[C,T]=(0,o.useState)(""),[z,L]=(0,o.useState)(!1),[I,M]=(0,o.useState)(null),[R,W]=(0,o.useState)(!1),[E,$]=(0,o.useState)(!1),[N,B]=(0,o.useState)(!1),[P,A]=(0,o.useState)(!0),H=(0,o.useRef)(!1),O=(0,o.useRef)(!1),D=(0,o.useRef)(null),[F,U]=(0,o.useState)(!0),[V,J]=(0,o.useState)(0),[q,G]=(0,o.useState)(""),er=(0,o.useCallback)(async(e=!1)=>{try{e&&(k(null),b(!0));let[t,r]=await Promise.all([fetch("/api/sessions"),fetch("/api/projects")]);if(!t.ok)throw Error(await Y("sessions",t));if(!r.ok)throw Error(await Y("projects",r));let n=await t.json(),o=await r.json();f(n.sessions),m(o.projects),k(null)}catch(e){k(String(e))}finally{e&&b(!1)}},[]),el=(0,o.useCallback)(()=>{A(e=>!e),L(!1),M(null),er(!0)},[er]),es=(0,o.useRef)(!1);(0,o.useEffect)(()=>{let e=!es.current;es.current=!0,er(e)},[er,s]),(0,o.useEffect)(()=>{void 0!==h&&J(e=>e+1)},[h]),(0,o.useEffect)(()=>{fetch("/api/home").then(e=>e.json()).then(e=>{e.home&&T(e.home)}).catch(()=>{})},[]);let ea=(0,o.useRef)(!1);(0,o.useEffect)(()=>{if(H.current){H.current=!1;return}if(O.current){O.current=!1;return}c?.(w)},[w,c]);let ed=(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 M(n.error??`HTTP ${r.status}`),!1;return er(!1),!0}catch(e){return M(e instanceof Error?e.message:String(e)),!1}},[er]),ec=(0,o.useCallback)(e=>{fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,touch:!0})}).catch(()=>{})},[]),eu=(0,o.useCallback)(e=>{O.current=!0,S(e),B(!1),U(!0),G(""),J(e=>e+1),c?.(e),ec(e)},[c,ec]);(0,o.useEffect)(()=>{if((0!==g.length||0!==v.length)&&null===w){if(i&&!ea.current){ea.current=!0;let e=g.find(e=>e.id===i);if(e){S(e.cwd),ec(e.cwd),t(e,!0);return}l?.()}let e=v[0]?.cwd;e&&(S(e),ec(e))}},[g,v,w,i,t,l,ec]);let ep=(0,o.useCallback)(async()=>{try{let e=await fetch("/api/default-cwd",{method:"POST"}),t=await e.json();t.cwd&&(await ed(t.cwd,!1),eu(t.cwd),L(!1))}catch{}},[eu,ed]),eh=(0,o.useCallback)(async e=>{await ed(e,!1)&&(eu(e),W(!1),M(null),L(!1))},[eu,ed]);(0,o.useEffect)(()=>{let e=e=>{D.current&&!D.current.contains(e.target)&&(L(!1),M(null))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let ex=d??w,eg=(0,o.useCallback)(e=>{if(!e)return void L(!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]),ef=(0,o.useCallback)(()=>{eg(ex)},[eg,ex]),ev=(0,o.useMemo)(()=>[...ex&&!v.some(e=>e.cwd===ex)?[{cwd:ex,displayName:ee(ex,C),chatCount:g.filter(e=>e.cwd===ex).length,lastAccessed:null,created:null,exists:!0,source:"manual"}]:[],...v].sort((e,t)=>{if(ex&&e.cwd===ex)return -1;if(ex&&t.cwd===ex)return 1;let r=et(e),n=et(t);return r!==n?n.localeCompare(r):e.displayName.localeCompare(t.displayName)}),[g,ex,C,v]),em=(0,o.useMemo)(()=>g.filter(e=>e.cwd===ex).sort((e,t)=>t.modified.localeCompare(e.modified)),[g,ex]),ey=ex?ev.find(e=>e.cwd===ex):void 0,eb=ex?ev.find(e=>e.cwd===ex)?.displayName||ee(ex,C):"Open project...",ej=ey?.chatCount??em.length,ek=(0,o.useMemo)(()=>(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})(em),[em]),ew=ek.length,eS=ek;if(ew>10&&!N){eS=ek.slice(0,10);let t=ek.find(t=>(function e(t,r){return!!r&&(t.session.id===r||t.children.some(t=>e(t,r)))})(t,e));t&&!eS.includes(t)&&(eS=[...eS,t])}let eC=ew-eS.length,eT=(0,o.useCallback)((e,r=!1)=>{e.cwd!==ex&&(H.current=!0,S(e.cwd)),ec(e.cwd),t(e,r)},[t,ex,ec]);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:"12px 10px 10px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:8},children:[(0,n.jsx)(en,{}),(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsxs)("button",{onClick:ef,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,background:"var(--bg-hover)",border:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",height:32,paddingLeft:10,paddingRight:12,borderRadius:7,fontSize:12,fontWeight:500,letterSpacing:"-0.01em",flexShrink:0,transition:"background 0.12s, color 0.12s, border-color 0.12s"},title:ex?`New session in ${ex}`:"Select a project first",onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-selected)",e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"6",y1:"1",x2:"6",y2:"11"}),(0,n.jsx)("line",{x1:"1",y1:"6",x2:"11",y2:"6"})]}),"New"]}),(0,n.jsx)("button",{onClick:()=>$(!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:D,style:{position:"relative"},children:[(0,n.jsxs)("button",{type:"button",onClick:el,title:"Toggle and refresh project conversations","aria-expanded":P,style:{width:"100%",display:"flex",alignItems:"center",gap:6,padding:"6px 0",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:600,letterSpacing:"0.05em",textTransform:"uppercase",textAlign:"left"},children:[(0,n.jsx)("svg",{width:"9",height:"9",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:P?"rotate(90deg)":"none",transition:"transform 0.15s",flexShrink:0},children:(0,n.jsx)("polyline",{points:"3 2 7 5 3 8"})}),(0,n.jsx)("span",{style:{flex:1},children:"Project"}),y&&(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,fontWeight:500,letterSpacing:0,textTransform:"none"},children:"Refreshing..."})]}),P&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{onClick:()=>L(e=>!e),style:{width:"100%",display:"flex",alignItems:"center",gap:9,padding:"8px 10px",background:ex?"var(--bg-hover)":"rgba(37,99,235,0.06)",border:ex?"1px solid var(--border)":"1px solid rgba(37,99,235,0.4)",borderRadius:7,cursor:"pointer",fontSize:12,color:"var(--text)",textAlign:"left",transition:"border-color 0.15s, background 0.15s"},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:ex?"var(--accent)":"var(--text-dim)",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.jsxs)("span",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("span",{style:{display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:12,fontWeight:650,color:ex?"var(--text)":"var(--text-dim)"},children:ex?eb:i&&!ea.current?"":"Open project..."}),ex&&(0,n.jsx)("span",{style:{display:"block",marginTop:2,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)",fontSize:10,color:"var(--text-dim)"},title:ex,children:Q(ex,C)})]}),ex&&(0,n.jsxs)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:[ej," chats"]}),(0,n.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0,transform:z?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),z&&(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"},children:[(0,n.jsxs)("div",{style:{maxHeight:260,overflowY:"auto"},children:[0===ev.length&&(0,n.jsx)("div",{style:{padding:"10px 12px",color:"var(--text-muted)",fontSize:12},children:"No projects yet"}),ev.map(e=>{let t=e.cwd===ex,r=et(e);return(0,n.jsxs)("button",{onClick:()=>{eu(e.cwd),M(null),L(!1)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"8px 10px",background:t?"var(--bg-selected)":"none",border:"none",borderBottom:"1px solid var(--border)",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11},title:e.cwd,children:[t?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsxs)("span",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("span",{style:{display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:t?"var(--text)":"var(--text-muted)",fontWeight:t?650:500},children:e.displayName}),(0,n.jsxs)("span",{style:{display:"block",marginTop:2,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontSize:10},children:[e.chatCount," chats",r?` / ${X(r)}`:"",e.exists?"":" / missing"]})]})]},e.cwd)})]}),(0,n.jsxs)("div",{style:{borderTop:ev.length>0?"1px solid var(--border)":"none"},children:[(0,n.jsxs)("button",{onClick:e=>{e.stopPropagation(),ep()},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11},children:[(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.1",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("path",{d:"M1 3A1 1 0 0 1 2 2H4L5 3.5H8.5a.5.5 0 0 1 .5.5v4a.5.5 0 0 1-.5.5h-7A.5.5 0 0 1 1 8V3Z"})}),(0,n.jsx)("span",{children:"Use default directory"})]}),(0,n.jsxs)("button",{onClick:e=>{e.stopPropagation(),M(null),W(!0)},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11},children:[(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.1",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M1 3A1 1 0 0 1 2 2h1.5L4.5 3H8a1 1 0 0 1 1 1v4a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V3Z"}),(0,n.jsx)("path",{d:"M5 4.5v3M3.5 6h3"})]}),(0,n.jsx)("span",{children:"Select project path..."})]}),I&&(0,n.jsx)("div",{style:{padding:"0 10px 8px 27px",color:"#f87171",fontSize:10,lineHeight:1.4},children:I})]})]})]})]})]}),(0,n.jsx)(K,{open:E,cwd:ex,homeDir:C,onClose:()=>$(!1),onSelectSession:e=>{eT(e)}}),P&&(0,n.jsx)(n.Fragment,{children:(0,n.jsxs)("div",{style:{flex:F&&ex?"1 1 0":"1 1 auto",overflowY:"auto",padding:"6px 8px 8px",minHeight:120},children:[y&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Loading..."}),j&&(0,n.jsx)("div",{style:{padding:"12px 14px",color:"#f87171",fontSize:12},children:j}),!y&&!j&&!ex&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Open or create a project to start chatting."}),!y&&!j&&ex&&(0,n.jsxs)(n.Fragment,{children:[0===em.length?(0,n.jsx)("button",{type:"button",onClick:()=>eg(ex),style:{width:"100%",padding:"12px",background:"transparent",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:12},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:"Start a new session in this project"}):eS.map(t=>(0,n.jsx)(ei,{node:t,selectedSessionId:e,onSelectSession:eT,onRenamed:er,onSessionDeleted:e=>{a?.(e),er()},depth:0},t.session.id)),(N||eC>0)&&ew>10&&(0,n.jsx)("button",{type:"button",onClick:()=>B(e=>!e),style:{width:"100%",padding:"6px 10px",background:"transparent",border:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:11,textAlign:"center"},children:N?"Show less":`Show ${Math.max(0,eC)} more`})]})]})}),ex&&(0,n.jsxs)("div",{style:{borderTop:"1px solid var(--border)",display:"flex",flexDirection:"column",flex:F?"1 1 0":"0 0 auto",minHeight:0,overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",flexShrink:0,gap:0,padding:"2px 4px"},children:[(0,n.jsxs)("button",{onClick:()=>{U(e=>!e),J(e=>e+1)},style:{display:"flex",alignItems:"center",gap:6,padding:"6px 6px 6px 6px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:600,letterSpacing:"0.05em",textTransform:"uppercase",textAlign:"left",flexShrink:0},children:[(0,n.jsx)("svg",{width:"9",height:"9",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:F?"rotate(90deg)":"none",transition:"transform 0.15s",flexShrink:0},children:(0,n.jsx)("polyline",{points:"3 2 7 5 3 8"})}),"Explorer"]}),(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:q,onChange:e=>G(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"}}),q&&(0,n.jsx)("button",{type:"button",onClick:()=>G(""),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"})]})})]})]}),F&&(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",overflowX:"hidden"},children:(0,n.jsx)(_,{cwd:ex,onOpenFile:u??(()=>{}),onExploreFile:p,refreshKey:V,onAtMention:x,searchQuery:q,onSearchChange:G})})]}),(0,n.jsx)(Z,{open:R,initialPath:ex||C||null,onClose:()=>W(!1),onSelect:e=>void eh(e)})]})}function ei({node:e,selectedSessionId:t,onSelectSession:r,onRenamed:i,onSessionDeleted:l,depth:s}){let[a,d]=(0,o.useState)(!1),c=e.children.length>0;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{position:"relative"},children:[s>0&&(0,n.jsx)("div",{style:{position:"absolute",left:12*s+6,top:0,bottom:0,width:1,background:"var(--border)",pointerEvents:"none"}}),(0,n.jsx)(el,{session:e.session,isSelected:e.session.id===t,onClick:()=>r(e.session),onRenamed:i,onDeleted:e=>l?.(e),depth:s,hasChildren:c,collapsed:a,onToggleCollapse:()=>d(e=>!e)})]}),c&&!a&&(0,n.jsx)("div",{children:e.children.map(e=>(0,n.jsx)(ei,{node:e,selectedSessionId:t,onSelectSession:r,onRenamed:i,onSessionDeleted:l,depth:s+1},e.session.id))})]})}function el({session:e,isSelected:t,onClick:r,onRenamed:i,onDeleted:l,depth:s=0,hasChildren:a=!1,collapsed:d=!1,onToggleCollapse:c}){let[u,p]=(0,o.useState)(!1),[h,x]=(0,o.useState)(!1),[g,f]=(0,o.useState)(""),[v,m]=(0,o.useState)(!1),[y,b]=(0,o.useState)(!1),j=(0,o.useRef)(null),k=e.name||e.firstMessage.slice(0,50)||e.id.slice(0,12),w=(0,o.useCallback)(t=>{t.stopPropagation(),f(e.name??""),x(!0),setTimeout(()=>j.current?.select(),0)},[e.name]),S=(0,o.useCallback)(async()=>{let t=g.trim();if(x(!1),t!==(e.name??""))try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t})}),i?.()}catch{}},[g,e.id,e.name,i]),C=(0,o.useCallback)(e=>{e.stopPropagation(),m(!0)},[]),T=(0,o.useCallback)(async t=>{t.stopPropagation(),m(!1),b(!0);try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"DELETE"}),l?.(e.id)}catch{b(!1)}},[e.id,l]),z=(0,o.useCallback)(e=>{e.stopPropagation(),m(!1)},[]);return(0,n.jsx)("div",{onClick:v||h?void 0:r,onMouseEnter:()=>p(!0),onMouseLeave:()=>{p(!1)},style:{height:54,display:"flex",alignItems:"center",paddingLeft:s>0?12*s+14:14,paddingRight:8,cursor:v||h?"default":"pointer",background:v?"rgba(239,68,68,0.06)":t?"var(--bg-selected)":u?"var(--bg-hover)":"transparent",borderLeft:v?"2px solid #ef4444":t?"2px solid var(--accent)":"2px solid transparent",transition:"background 0.1s",opacity:y?.5:1,gap:6,overflow:"hidden"},children:v?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0,fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["Delete ",(0,n.jsxs)("span",{style:{fontWeight:600},children:["“",k.slice(0,22),k.length>22?"…":"","”"]}),"?"]}),(0,n.jsxs)("div",{style:{display:"flex",gap:5,flexShrink:0},children:[(0,n.jsxs)("button",{onClick:T,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:z,style:{display:"flex",alignItems:"center",justifyContent:"center",height:30,padding:"0 11px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:500,whiteSpace:"nowrap"},children:"Cancel"})]})]}):h?(0,n.jsx)("input",{ref:j,value:g,onChange:e=>f(e.target.value),onBlur:S,onKeyDown:e=>{"Enter"===e.key&&S(),"Escape"===e.key&&x(!1)},autoFocus:!0,style:{flex:1,fontSize:12,padding:"5px 8px",border:"1px solid var(--accent)",borderRadius:5,outline:"none",background:"var(--bg)",color:"var(--text)",height:30}}):(0,n.jsxs)(n.Fragment,{children:[s>0&&(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:t?500:400,lineHeight:1.4,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text)"},title:k,children:k}),(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:X(e.modified)}),(0,n.jsxs)("span",{children:[e.messageCount," msgs"]})]})]}),a&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),c?.()},title:d?"Expand forks":"Collapse forks",style:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,flexShrink:0,background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",transform:d?"rotate(-90deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})}),u&&(0,n.jsxs)("div",{style:{display:"flex",gap:4,flexShrink:0},children:[(0,n.jsx)("button",{onClick:w,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:C,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"})]})})]})]})})}let es=new Set;function ea(e){return es.add(e),()=>{es.delete(e)}}function ed(){return"u"<typeof document?"light":document.documentElement.classList.contains("dark")?"dark":"light"}function ec(){return"light"}function eu(){let e=(0,o.useSyncExternalStore)(ea,ed,ec);return{theme:e,toggleTheme:(0,o.useCallback)(e=>{let t="dark"===ed()?"light":"dark",r=()=>{"dark"===t?document.documentElement.classList.add("dark"):document.documentElement.classList.remove("dark");try{localStorage.setItem("pi-theme",t)}catch{}es.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 ep(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=eh(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=ex(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=eh(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=eh(t);i?r.push({type:"widget",...i}):t&&r.push({type:"text",content:t}),n.lastIndex=o=a+3}else{let t=eh(e.slice(s).trim());if(t){let e=ex(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 eh(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 ex(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 eg=/<(iframe|object|embed|meta|link|base|form)[\s>][\s\S]*?<\/\1>/gi,ef=/<(iframe|object|embed|meta|link|base)\b[^>]*\/?>/gi;function ev(e){return e.replace(eg,"").replace(ef,"")}let em=["--bg","--bg-panel","--bg-hover","--bg-selected","--border","--text","--text-muted","--text-dim","--accent","--accent-hover"];function ey(){if("u"<typeof document)return{};let e=getComputedStyle(document.documentElement),t={};for(let r of em){let n=e.getPropertyValue(r).trim();n&&(t[r]=n)}return t}let eb=["--bg","--bg-panel","--bg-hover","--bg-selected","--border","--text","--text-muted","--text-dim","--accent","--accent-hover"];async function ej(e){if(navigator.clipboard?.writeText)return void await navigator.clipboard.writeText(e);let t=document.createElement("textarea");t.value=e,t.style.position="fixed",t.style.inset="0",t.style.opacity="0",document.body.appendChild(t),t.focus(),t.select();let r=document.execCommand("copy");if(document.body.removeChild(t),!r)throw Error("Clipboard copy failed.")}async function ek(e){let t=await ew(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=eT({width:e.bodyWidth||640,height:e.bodyHeight||360}),r=function(e){let t=document.createElement("template");t.innerHTML=ev(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 eS(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 eb.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 eL(eI('<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 ew(e){var t;let r,n,o,i,l=function(e){let t=ev(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;eS(l),l.setAttribute("xmlns","http://www.w3.org/2000/svg");let s=eT((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=eC(t.getAttribute("width"))??r?.width??640,o=r?r.height/r.width:.5625,i=eC(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),eL(eI(new XMLSerializer().serializeToString(l)),s.width,s.height)}function eS(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 eC(e){if(!e||e.includes("%"))return null;let t=Number.parseFloat(e);return Number.isFinite(t)&&t>0?t:null}function eT(e){let t=ez(Math.ceil(e.width||640),240,2e3),r=ez(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 ez(e,t,r){return Math.min(Math.max(e,t),r)}function eL(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 eI(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 eM=/cdnjs\.cloudflare\.com|cdn\.jsdelivr\.net|unpkg\.com|esm\.sh/,eR=new Map;function eW(e){return e.slice(0,200)}function eE({code:e,isStreaming:t,title:r,showOverlay:i,onSendMessage:l}){let{isDark:s}=eu(),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)(()=>eR.get(eW(e))??0),[v,m]=(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),z=(0,o.useRef)(""),L=(0,o.useRef)((eR.get(eW(e))??0)>0),I=(0,o.useRef)(!1),M=(0,o.useRef)(s),R=(0,o.useMemo)(()=>eM.test(e),[e]),W=(0,o.useMemo)(()=>{let e;return function(e="",t=!1){return`<!DOCTYPE html>
|
|
2
2
|
<html class="${t?"dark":""}">
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="utf-8">
|
|
@@ -246,7 +246,7 @@ ${r}`)}return o.join("\n\n")}async function ty(e){let t=(await Promise.all([r.e(
|
|
|
246
246
|
${o}`}).join("\n\n")}async function tj(e){let t=(await Promise.all([r.e(2619),r.e(4453)]).then(r.t.bind(r,54453,23))).default,n=await t.loadAsync(e),o=Object.keys(n.files).map(e=>({name:e,match:/^ppt\/slides\/slide(\d+)\.xml$/i.exec(e)})).filter(e=>null!==e.match).sort((e,t)=>Number(e.match[1])-Number(t.match[1])),i=[];for(let{name:e,match:t}of o){let r=[...(await n.file(e).async("string")).matchAll(/<a:t[^>]*>([\s\S]*?)<\/a:t>/g)].map(e=>tv(e[1]).trim()).filter(Boolean);r.length&&i.push(`Slide ${t[1]}
|
|
247
247
|
${r.join("\n")}`)}return i.join("\n\n")}async function tk(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 tm(t);else if("docx"===r)o=await ty(t);else if("xlsx"===r)o=await tb(t);else{if("pptx"!==r)return{extractionError:"Text extraction is not supported for this file type"};o=await tj(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
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 tw=(0,o.forwardRef)(function({onSend:e,onAbort:t,onSteer:r,onFollowUp:i,isStreaming:l,model:s,modelNames:a,modelList:d,onModelChange:c,onCompact:u,onAbortCompaction:p,isCompacting:h,compactError:x,toolPreset:g,onToolPresetChange:f,thinkingLevel:v,onThinkingLevelChange:m,availableThinkingLevels:y,thinkingLevelMap:b,retryInfo:j,soundEnabled:k,onSoundToggle:w,cornerBadge:S},C){let T,z,L,[I,M]=(0,o.useState)(""),[R,W]=(0,o.useState)(!1),[E,$]=(0,o.useState)(null),[N,B]=(0,o.useState)(!1),[P,A]=(0,o.useState)(!1),[H,O]=(0,o.useState)(null),[D,F]=(0,o.useState)([]),[U,_]=(0,o.useState)([]),V=(0,o.useRef)(null),J=(0,o.useRef)(null),q=(0,o.useRef)(null),K=(0,o.useRef)(null),Z=(0,o.useRef)(null),G=(0,o.useRef)(null),Y=(0,o.useRef)(null);(0,o.useImperativeHandle)(C,()=>({insertIfEmpty(e){let t=V.current;(t?t.value:I).trim()||(M(e),requestAnimationFrame(()=>{t&&(t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)}))},insertText(e){let t=V.current;if(!t)return void M(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(" ")?" ":"";M(o+l+e+i),requestAnimationFrame(()=>{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`})},addImages(e){X(e)},addFiles(e){Q(e)}}));let X=(0,o.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/"));if(!t.length)return;let r=await Promise.all(t.map(e=>new Promise((t,r)=>{let n=new FileReader;n.onload=()=>{t({data:n.result.split(",")[1],mimeType:e.type,previewUrl:URL.createObjectURL(e)})},n.onerror=r,n.readAsDataURL(e)})));F(e=>[...e,...r])},[]),Q=(0,o.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/")),r=e.filter(e=>!e.type.startsWith("image/"));if(t.length&&X(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 tk(e,r);t({data:r,fileName:e.name,mimeType:e.type||"application/octet-stream",size:e.size,...o})},n.onerror=r,n.readAsArrayBuffer(e)})));_(t=>[...t,...e])}},[X]),ee=(0,o.useCallback)(e=>{F(t=>{let r=[...t];return URL.revokeObjectURL(r[e].previewUrl),r.splice(e,1),r})},[]),et=(0,o.useCallback)(e=>{_(t=>{let r=[...t];return r.splice(e,1),r})},[]),er=(0,o.useCallback)(()=>{F(e=>(e.forEach(e=>URL.revokeObjectURL(e.previewUrl)),[])),_([])},[]),en=(0,o.useCallback)(()=>{let t=I.trim();(t||D.length||U.length)&&!l&&(e(t,D.length?D:void 0,U.length?U:void 0),M(""),er(),V.current&&(V.current.style.height="auto"))},[I,D,U,l,e,er]),eo=(0,o.useCallback)(e=>{let t=I.trim();if(!t&&!D.length&&!U.length)return;let n=D.length?D:void 0,o=U.length?U:void 0;"steer"===e&&r?r(t,n,o):"followup"===e&&i&&i(t,n,o),M(""),er(),V.current&&(V.current.style.height="auto")},[I,D,U,r,i,er]),ei=(0,o.useCallback)(e=>{"Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),l&&(r||i)?eo(r?"steer":"followup"):en())},[l,r,i,eo,en]),el=(0,o.useCallback)(()=>{let e=V.current;e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[]),es=(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(),Q(t.map(e=>e.getAsFile()).filter(e=>null!==e)))},[Q]),ea=d&&d.length>0?d.map(e=>({provider:e.provider,modelId:e.id,name:e.name})):Object.entries(a??{}).map(([e,t])=>({provider:s?.provider??"unknown",modelId:e,name:t})),ed=[];for(let e of ea){let t=ed.find(t=>t.provider===e.provider);t?t.options.push(e):ed.push({provider:e.provider,options:[e]})}let ec=s?ea.find(e=>e.modelId===s.modelId&&e.provider===s.provider)?.name??s.modelId:ea.length>0?ea[0].name:null;return(0,o.useEffect)(()=>{let e=e=>{J.current&&!J.current.contains(e.target)&&q.current&&!q.current.contains(e.target)&&W(!1),K.current&&!K.current.contains(e.target)&&B(!1),Z.current&&!Z.current.contains(e.target)&&A(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,o.useEffect)(()=>{if(!f)return;let e=!1;return fetch("/api/subagents/status").then(e=>e.ok?e.json():null).then(t=>{e||O(!!t?.ready)}).catch(()=>{e||O(!1)}),()=>{e=!0}},[f]),(0,n.jsxs)("div",{style:{flexShrink:0,background:"transparent",padding:"0 16px 8px",paddingRight:52},children:[(0,n.jsx)("input",{ref:G,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:e=>{X(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsx)("input",{ref:Y,type:"file",accept:".pdf,.docx,.xlsx,.pptx,.doc,.xls,.ppt,application/pdf,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.presentationml.presentation",multiple:!0,style:{display:"none"},onChange:e=>{Q(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsxs)("div",{style:{maxWidth:820,margin:"0 auto",position:"relative"},children:[S&&(0,n.jsx)("div",{style:{position:"absolute",right:8,top:-22,display:"flex",alignItems:"center",justifyContent:"flex-end",maxWidth:"min(320px, 60vw)",minHeight:18,zIndex:2,fontFamily:"var(--font-mono)",overflow:"hidden"},children:S}),j&&(0,n.jsxs)("div",{style:{marginBottom:8,padding:"5px 10px",background:"rgba(234,179,8,0.08)",border:"1px solid rgba(234,179,8,0.25)",borderRadius:6,fontSize: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 (",j.attempt,"/",j.maxAttempts,")…",j.errorMessage&&(0,n.jsxs)("span",{style:{opacity:.7,marginLeft:4},children:["— ",j.errorMessage]})]}),(D.length>0||U.length>0)&&(0,n.jsxs)("div",{style:{display:"flex",gap:6,marginBottom:6,flexWrap:"wrap",alignItems:"flex-end"},children:[D.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:()=>ee(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}`)),U.map((e,t)=>(0,n.jsx)(tf,{doc:e,onRemove:()=>et(t)},`doc-${t}`))]}),(0,n.jsxs)("div",{style:{display:"flex",gap:8,alignItems:"center",background:"var(--bg)",border:`1px solid ${l&&(r||i)?"rgba(234,179,8,0.4)":"color-mix(in srgb, var(--border) 70%, transparent)"}`,borderRadius:14,padding:"10px 10px 10px 14px",boxShadow:"0 1px 2px rgba(15,23,42,0.04), 0 8px 24px -12px rgba(15,23,42,0.10)",transition:"border-color 0.15s, background 0.15s, box-shadow 0.15s"},children:[(0,n.jsx)("textarea",{ref:V,value:I,onChange:e=>M(e.target.value),onKeyDown:ei,onInput:el,onPaste:es,placeholder:l&&(r||i)?"Steer 立即注入 / Follow-up 排队…":l?"Agent is running…":"Message…",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"}}),l?(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,flexShrink:0,alignSelf:"flex-end"},children:[r&&(0,n.jsxs)("button",{onClick:()=>eo("steer"),disabled:!I.trim()&&!D.length&&!U.length,title:"打断 Agent 当前运行,立即注入消息",style:{display:"flex",alignItems:"center",gap:5,padding:"7px 12px",background:I.trim()||D.length||U.length?"rgba(234,179,8,0.12)":"none",border:"1px solid rgba(234,179,8,0.35)",borderRadius:8,color:I.trim()||D.length||U.length?"rgba(180,130,0,1)":"var(--text-dim)",cursor:I.trim()||D.length||U.length?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",transition:"background 0.12s"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M5 1 L9 5 L5 9"}),(0,n.jsx)("line",{x1:"1",y1:"5",x2:"9",y2:"5"})]}),"Steer"]}),i&&(0,n.jsxs)("button",{onClick:()=>eo("followup"),disabled:!I.trim()&&!D.length&&!U.length,title:"在 Agent 完成后排队发送",style:{display:"flex",alignItems:"center",gap:5,padding:"7px 12px",background:I.trim()||D.length||U.length?"rgba(129,140,248,0.12)":"none",border:"1px solid rgba(129,140,248,0.35)",borderRadius:8,color:I.trim()||D.length||U.length?"rgba(99,102,241,1)":"var(--text-dim)",cursor:I.trim()||D.length||U.length?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",transition:"background 0.12s"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"5",y1:"1",x2:"5",y2:"6"}),(0,n.jsx)("polyline",{points:"2.5 3.5 5 1 7.5 3.5"}),(0,n.jsx)("line",{x1:"2",y1:"9",x2:"8",y2:"9"})]}),"Follow-up"]})]}):(0,n.jsxs)("button",{onClick:en,disabled:!I.trim()&&!D.length&&!U.length,style:{flexShrink:0,alignSelf:"flex-end",display:"flex",alignItems:"center",gap:6,padding:"7px 14px",background:I.trim()||D.length||U.length?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:8,color:I.trim()||D.length||U.length?"#fff":"var(--text-dim)",cursor:I.trim()||D.length||U.length?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",boxShadow:I.trim()||D.length||U.length?"0 1px 3px rgba(37,99,235,0.25)":"none",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"})]}),"Send"]})]}),(0,n.jsxs)("div",{className:"chat-input-toolbar",style:{marginTop:8,display:"flex",alignItems:"center",gap:6},children:[(0,n.jsxs)("div",{className:"chat-input-toolbar-left",style:{flex:"0 0 auto",display:"flex",alignItems:"center",gap:2},children:[(0,n.jsx)("button",{onClick:()=>G.current?.click(),disabled:l,title:"Attach image (right-click for document)",style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"none",border:"none",borderRadius:9,color:D.length||U.length?"var(--accent)":"var(--text-muted)",cursor:l?"not-allowed":"pointer",opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=D.length||U.length?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=D.length||U.length?"var(--accent)":"var(--text-muted)"},onContextMenu:e=>{e.preventDefault(),Y.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"})})}),ea.length>0&&ec&&c&&(0,n.jsxs)("div",{ref:J,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:e=>{let t=e.currentTarget.getBoundingClientRect();$({top:t.top,left:t.left,width:t.width}),W(e=>!e)},disabled:l,style:{display:"flex",alignItems:"center",gap:6,padding:"8px 12px",height:32,maxWidth:220,overflow:"hidden",background:R?"var(--bg-hover)":"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=R?"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:ec})]}),R&&E&&(z=(T=window.visualViewport?.height??window.innerHeight)-E.top+6,L=Math.max(120,Math.min(E.top-8,.6*T)),(0,n.jsx)("div",{ref:q,style:{position:"fixed",bottom:z,left:E.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:E.width,maxHeight:L,overflowY:"auto"},children:ed.map((e,t)=>(0,n.jsxs)("div",{children:[ed.length>1&&(0,n.jsx)("div",{style:{padding:"6px 12px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:t>0?"1px solid var(--border)":"none"},children:e.provider}),e.options.map(e=>{let t=e.modelId===s?.modelId&&e.provider===s?.provider;return(0,n.jsxs)("button",{onClick:()=>{W(!1),t||c(e.provider,e.modelId)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize: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))}))]})]}),(0,n.jsx)("div",{className:"chat-input-toolbar-spacer",style:{flex:1}}),(0,n.jsxs)("div",{className:"chat-input-toolbar-right",style:{flex:"0 0 auto",display:"flex",alignItems:"center",gap:2,marginLeft:"auto"},children:[!l&&m&&(0,n.jsxs)("div",{ref:Z,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>!l&&A(e=>!e),disabled:l,title:"切换推理强度",style:{display:"flex",alignItems:"center",gap:5,padding:"8px 12px",height:32,background:P?"var(--bg-hover)":"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=P?"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",{children:(()=>{let e=v??"auto";if("auto"===e||!b)return e;let t=b[e];return null!=t?t:e})()})]}),P&&(0,n.jsx)("div",{style:{position:"absolute",bottom:"calc(100% + 6px)",right:0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",overflow:"hidden",minWidth:180},children:tx.filter(e=>!y||"auto"===e||y.includes(e)).map(e=>{let t=(v??"auto")===e,r=tg[e],o="auto"!==e&&b?b[e]:void 0,i=null!=o&&o!==e?o:e,l=null!=o&&o!==e;return(0,n.jsxs)("button",{onClick:()=>{A(!1),t||m(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: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)})})]}),!l&&f&&(0,n.jsxs)("div",{ref:K,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>!l&&B(e=>!e),disabled:l,title:"切换工具预设",style:{display:"flex",alignItems:"center",gap:5,padding:"8px 12px",height:32,background:N?"var(--bg-hover)":"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=N?"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",{children:Object.entries(tp).find(([,e])=>e===(g??"full"))?.[0]??"full"})]}),N&&(0,n.jsx)("div",{style:{position:"absolute",bottom:"calc(100% + 6px)",right:0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",overflow:"hidden",minWidth:120},children:tu.map(e=>{let t=tp[e],r=(g??"full")===t,o="agent"===e&&!1===H,i=o?"需安装 pi-subagents":th[e];return(0,n.jsxs)("button",{onClick:()=>{!o&&(B(!1),r||f(t))},disabled:o,title:o?"运行 pi install npm:pi-subagents 后再启用":void 0,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:r?"var(--bg-selected)":"none",border:"none",color:r?"var(--text)":"var(--text-muted)",cursor:o?"not-allowed":"pointer",fontSize:12,textAlign:"left",fontWeight:r?600:400,opacity:o?.5:1,whiteSpace:"nowrap"},onMouseEnter:e=>{r||o||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{r||(e.currentTarget.style.background="none")},children:[r?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1},children:e}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:i})]},e)})})]}),!l&&u&&(0,n.jsxs)("div",{style:{position:"relative"},children:[x&&(0,n.jsx)("div",{style:{position:"absolute",bottom:"calc(100% + 6px)",right:0,background:"#1f2937",color:"#f87171",fontSize:11,padding:"4px 8px",borderRadius:5,whiteSpace:"nowrap",pointerEvents:"none",boxShadow:"0 2px 8px rgba(0,0,0,0.2)",zIndex:50},children:x}),(0,n.jsx)("button",{onClick:h?p:u,disabled:l&&!h,style:{display:"flex",alignItems:"center",gap:5,padding:"8px 12px",height:32,background:h?"rgba(239,68,68,0.08)":"none",border:"none",borderRadius:9,color:h?"#ef4444":"var(--text-muted)",cursor:l&&!h?"not-allowed":"pointer",fontSize:12,opacity:l&&!h?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{(!l||h)&&(e.currentTarget.style.background=h?"rgba(239,68,68,0.16)":"var(--bg-hover)",e.currentTarget.style.color=h?"#ef4444":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=h?"rgba(239,68,68,0.08)":"none",e.currentTarget.style.color=h?"#ef4444":"var(--text-muted)"},title:h?"停止压缩":"压缩上下文",children:h?(0,n.jsxs)(n.Fragment,{children:[(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"})}),"Compacting…"]}):(0,n.jsxs)(n.Fragment,{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)("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"})]}),"Compact"]})})]}),l&&(0,n.jsxs)("button",{onClick:t,title:"停止 Agent",style:{display:"flex",alignItems:"center",gap:6,padding:"8px 14px",height:32,background:"rgba(239,68,68,0.08)",border:"1px solid rgba(239,68,68,0.3)",borderRadius:9,color:"#ef4444",cursor:"pointer",fontSize: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!==w&&(0,n.jsx)("button",{onClick:w,title:k?"关闭完成提示音":"开启完成提示音",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"none",border:"none",borderRadius:9,color:k?"var(--text-muted)":"var(--text-dim)",cursor:"pointer",opacity:k?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=k?"var(--text-muted)":"var(--text-dim)",e.currentTarget.style.opacity=k?"1":"0.55"},children:k?(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 tS(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 tC({messages:e,streamingMessage:t,scrollContainer:r,messageRefs:i}){let[l,s]=(0,o.useState)(0),[a,d]=(0,o.useState)(1),[c,u]=(0,o.useState)(!1),[p,h]=(0,o.useState)([]),[x,g]=(0,o.useState)(!1),[f,v]=(0,o.useState)(null),m=(0,o.useRef)(!1),y=(0,o.useRef)(null),b=(0,o.useMemo)(()=>t?[...e,t]:e,[e,t]),j=(0,o.useRef)(b);j.current=b;let k=(0,o.useRef)(null);k.current=()=>{let e=r.current;if(!e)return;let t=e.scrollHeight,n=e.clientHeight,o=t-n;u(o>20),o<=0?(s(0),d(1)):(s(e.scrollTop/o),d(n/t));let l=i.current,a=[],c=0,p=j.current;for(let r=0;r<p.length;r++){let n=p[r];if("user"!==n.role&&"assistant"!==n.role)continue;let o=l?.[c];if(c++,("user"===n.role||"assistant"===n.role&&(n.content??[]).some(e=>"text"===e.type))&&o&&t>0){let r=o.getBoundingClientRect(),i=e.getBoundingClientRect(),l=r.top-i.top+e.scrollTop,s=r.height;a.push({topRatio:l/t,heightRatio:s/t,msg:n,index:a.length})}}h(a)};let w=(0,o.useCallback)(()=>k.current(),[]);(0,o.useEffect)(()=>{let e=r.current;if(!e)return;e.addEventListener("scroll",w,{passive:!0});let t=new ResizeObserver(w);return t.observe(e),e.firstElementChild&&t.observe(e.firstElementChild),w(),()=>{e.removeEventListener("scroll",w),t.disconnect()}},[r,w]),(0,o.useEffect)(()=>{let e=setTimeout(w,50);return()=>clearTimeout(e)},[e.length,w]);let S=(0,o.useCallback)(e=>{let t=r.current;if(!t)return;let n=t.scrollHeight-t.clientHeight;n<=0||(t.scrollTop=Math.max(0,Math.min(1-a,e))/(1-a)*n)},[r,a]),C=(0,o.useCallback)(e=>{if(!c)return;m.current=!0;let t=e.currentTarget.getBoundingClientRect(),r=(e.clientY-t.top)/t.height,n=r-l*(1-a),o=n>=0&&n<=a?n:a/2;S(r-o);let i=e=>{m.current&&S((e.clientY-t.top)/t.height-o)},s=()=>{m.current=!1,window.removeEventListener("mousemove",i),window.removeEventListener("mouseup",s)};window.addEventListener("mousemove",i),window.addEventListener("mouseup",s)},[c,a,l,S]),T=y.current?.clientHeight??600,z=(0,o.useMemo)(()=>{if(!x||0===p.length)return[];let e=p.map(e=>Math.round(e.topRatio*T-11));for(let t=0;t<10;t++){for(let t=1;t<e.length;t++){let r=e[t-1]+22+2;e[t]<r&&(e[t]=r)}for(let t=e.length-2;t>=0;t--){let r=e[t+1]-22-2;e[t]>r&&(e[t]=r)}}for(let t=0;t<e.length;t++)e[t]=Math.max(0,Math.min(T-22,e[t]));return e},[x,p,T]);if(!c)return null;let L=l*(1-a)*100,I=100*a,M=null!==f&&p.length>0?p.reduce((e,t)=>Math.abs(t.topRatio-f)<Math.abs(p[e].topRatio-f)?t.index:e,0):null;return(0,n.jsxs)("div",{ref:y,onMouseDown:C,onMouseEnter:()=>g(!0),onMouseLeave:()=>{g(!1),v(null)},onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();v((e.clientY-t.top)/t.height)},style:{width:36,flexShrink:0,position:"relative",cursor:"default",userSelect:"none",borderLeft:"1px solid var(--border)",background:"var(--bg-panel)",overflow:"visible"},children:[(0,n.jsx)("div",{style:{position:"absolute",left:0,right:0,top:`${L}%`,height:`${I}%`,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=tS(e.msg),r=x&&M===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=tS(e.msg),i=M===e.index;return r&&0!==z.length?(0,n.jsx)("div",{style:{position:"absolute",top:z[t],right:"100%",marginRight:6,background:"var(--bg)",borderTop:`1px solid ${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 tT(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function tz(e,t=220){if(!e)return;let r=e.trim();if(r)return r.length>t?`${r.slice(0,t)}...`:r}function tL(...e){for(let t of e)if("string"==typeof t&&t.trim())return t}function tI(...e){for(let t of e)if("number"==typeof t&&Number.isFinite(t))return t}function tM(e){let t=new Map;for(let r of e){if("custom"===r.role&&"subagent-notify"===r.customType&&"string"==typeof r.content){let e=r.content.match(/^Background task (completed|failed|paused):\s*\*\*(.+?)\*\*(?:\s+\((.+?)\))?/);if(e){let n=`bg-${e[2]}-${r.timestamp??""}`;t.set(n,{id:n,agent:e[2],status:e[1],task:e[3],summary:tz(r.content.split("\n").slice(3).join("\n")),timestamp:r.timestamp})}}if("assistant"===r.role){let e=r.content;if(!e)continue;for(let n of e)if("toolCall"===n.type&&"subagent"===n.toolName&&n.input){let e=n.input,o=e.agent??(e.chain?"chain":e.tasks?"parallel":e.action??"subagent"),i="string"==typeof e.task?e.task:void 0,l=n.toolCallId??`sub-${o}-${r.timestamp??Date.now()}`;t.set(l,{id:l,agent:o,status:"running",task:i,timestamp:r.timestamp})}}if("toolResult"===r.role){if(r.toolName&&"subagent"!==r.toolName||!r.toolCallId||!t.has(r.toolCallId))continue;let e=t.get(r.toolCallId),n=r.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n");t.set(r.toolCallId,function(e,t,r){let n;if(!tT(t))return{...e,summary:tz(r)};let o=Array.isArray(t.results)?t.results.filter(tT):[],i=o[0],l=i?.progressSummary,s=i&&(n=i.artifactPaths)?Object.values(n).filter(e=>"string"==typeof e&&e.trim().length>0):[],a=tL(i?.finalOutput,i?.output,r);return{...e,mode:tL(t.mode),runId:tL(t.runId),agent:tL(i?.agent,e.agent)??e.agent,task:tL(i?.task,e.task),summary:tz(a),model:tL(i?.model),durationMs:tI(l?.durationMs),toolCount:tI(l?.toolCount),tokens:tI(l?.tokens),outputPath:tL(i?.savedOutputPath,i?.artifactPaths?.outputPath),sessionFile:tL(i?.sessionFile,i?.artifactPaths?.jsonlPath),artifacts:s,resultCount:o.length||void 0}}({...e,status:function(e){if(e.isError)return"failed";let t=e.details;return tT(t)&&Array.isArray(t.results)&&t.results.some(e=>tT(e)&&"number"==typeof e.exitCode&&0!==e.exitCode)?"failed":"completed"}(r)},r.details,n))}}return Array.from(t.values()).sort((e,t)=>(t.timestamp??0)-(e.timestamp??0))}function tR({messages:e,runs:t}){let r=(0,o.useMemo)(()=>tM(e??[]),[e]),i=t??r,l=i.filter(e=>"running"===e.status),s=i.filter(e=>"running"!==e.status);return 0===i.length?null:(0,n.jsxs)("div",{style:{height:"100%",overflow:"auto",padding:12},children:[l.length>0&&(0,n.jsx)(tW,{title:`Active (${l.length})`,runs:l}),s.length>0&&(0,n.jsx)(tW,{title:`Completed (${s.length})`,runs:s,compact:l.length>0})]})}function tW({title:e,runs:t,compact:r}){return(0,n.jsxs)("div",{style:{marginBottom:r?10:16},children:[(0,n.jsx)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-dim)",marginBottom:8,textTransform:"uppercase",letterSpacing:"0.05em"},children:e}),t.map(e=>(0,n.jsx)(tE,{run:e},e.id))]})}function tE({run:e}){let[t,r]=(0,o.useState)(!1),i="running"===e.status,l="completed"===e.status?"#22c55e":"failed"===e.status?"#ef4444":i?"var(--accent)":"var(--text-dim)",s="failed"===e.status?"rgba(248,113,113,0.35)":i?"rgba(99,102,241,0.25)":"var(--border)",a="failed"===e.status?"rgba(248,113,113,0.05)":i?"rgba(99,102,241,0.05)":"var(--bg-panel)",d=[e.mode,e.resultCount&&e.resultCount>1?`${e.resultCount} results`:void 0,void 0!==e.toolCount?`${e.toolCount} tools`:void 0,void 0!==e.tokens?`${e.tokens.toLocaleString()} tok`:void 0,void 0!==e.durationMs?`${Math.round(e.durationMs/1e3)}s`:void 0].filter(Boolean).join(" \xb7 "),c=!!(e.summary||e.outputPath||e.sessionFile||e.artifacts?.length||e.model||e.runId);return(0,n.jsxs)("div",{style:{borderRadius:6,border:`1px solid ${s}`,background:a,marginBottom:6,fontSize:12,overflow:"hidden"},children:[(0,n.jsxs)("button",{onClick:()=>c&&r(e=>!e),style:{display:"flex",alignItems:"center",gap:7,width:"100%",border:"none",background:"transparent",padding:"8px 10px",color:"var(--text-muted)",textAlign:"left",cursor:c?"pointer":"default"},children:[(0,n.jsx)(t$,{running:i,color:l}),(0,n.jsx)("span",{style:{fontWeight:650,color:"var(--text)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.agent}),(0,n.jsx)("span",{style:{color:l,fontSize:10,fontWeight:700,flexShrink:0},children:e.status}),d&&(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,marginLeft:"auto",whiteSpace:"nowrap"},children:d}),c&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:t?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),e.task&&(0,n.jsx)("div",{style:{padding:"0 10px 8px 25px",color:"var(--text-muted)",fontSize:11,lineHeight:1.4},children:tz(e.task,150)}),t&&c&&(0,n.jsxs)("div",{style:{borderTop:`1px solid ${s}`,background:"var(--bg)",padding:"8px 10px",display:"flex",flexDirection:"column",gap:7},children:[e.summary&&(0,n.jsx)("pre",{style:{margin:0,color:"var(--text-muted)",fontSize:11,lineHeight:1.45,whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:160,overflow:"auto"},children:e.summary}),(0,n.jsx)(tN,{run:e})]})]})}function t$({running:e,color:t}){return(0,n.jsx)("span",{style:{width:8,height:8,borderRadius:"50%",background:t,display:"inline-block",animation:e?"pulse 1.5s infinite":void 0,flexShrink:0}})}function tN({run:e}){let t=[e.model?["model",e.model]:void 0,e.runId?["run",e.runId]:void 0,e.outputPath?["output",e.outputPath]:void 0,e.sessionFile?["session",e.sessionFile]:void 0,...(e.artifacts??[]).slice(0,4).map((e,t)=>[`artifact ${t+1}`,e])].filter(Boolean);return 0===t.length?null:(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:3},children:t.map(([e,t])=>(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"58px minmax(0, 1fr)",gap:6,fontSize:10},children:[(0,n.jsx)("span",{style:{color:"var(--text-dim)",textTransform:"uppercase"},children:e}),(0,n.jsx)("span",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:t,children:t})]},`${e}:${t}`))})}function tB(e){if("assistant"!==e.role)return e;let t=e.content;if(!Array.isArray(t))return e;let r=t.map(e=>("object"!=typeof e||null===e||Array.isArray(e)||"toolCall"!==e.type?null:{type:"toolCall",toolCallId:"string"==typeof e.toolCallId?e.toolCallId:"string"==typeof e.id?e.id:"",toolName:"string"==typeof e.toolName?e.toolName:"string"==typeof e.name?e.name:"",input:"object"!=typeof e.input||null===e.input||Array.isArray(e.input)?"object"!=typeof e.arguments||null===e.arguments||Array.isArray(e.arguments)?{}:e.arguments:e.input})??e);return{...e,content:r}}async function tP(e,t){let r=await fetch(`/api/agent/${encodeURIComponent(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),n=await r.json().catch(()=>({}));if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);return n.data}var tA=r(14755);function tH(e,t){switch(t.type){case"start":return{isStreaming:!0,streamingMessage:null};case"update":return{isStreaming:!0,streamingMessage:t.message};case"end":case"reset":return{isStreaming:!1,streamingMessage:null};default:return e}}function tO(e){if("user"!==e.role)return null;var t=e.content;if("string"==typeof t)return`text:${t}`;if(!Array.isArray(t))try{return`other:${JSON.stringify(t)}`}catch{return"other:"}let r=t.map(e=>{if(!e||"object"!=typeof e)return e;if("text"===e.type)return{type:"text",text:e.text};if("image"===e.type){let t=e.source&&"object"==typeof e.source?e.source:{};return{type:"image",mimeType:t.media_type??e.mimeType,data:t.data??e.data,url:t.url}}return e});try{return`blocks:${JSON.stringify(r)}`}catch{return"blocks:"}}function tD(e){if(!e.role)return null;try{return`${e.role}:${JSON.stringify(e)}`}catch{return null}}let tF=["image/","application/pdf","application/vnd.openxmlformats-officedocument","application/msword","application/vnd.ms-"];function tU(e){return tF.some(t=>e.type.startsWith(t))}let t_=["annotate and analyze.","vibe code bioinformatics.","turn data into figures.","inspect your project.","build a reproducible report.","run R/Python plots.","summarize that paper.","review the pipeline.","compare markers.","draft methods.","find the next analysis step."],tV=/\b(seurat|scanpy|single[- ]cell|scrna|sc[- ]rna|rna[- ]seq|transcriptom|gene|genes|marker|cell type|cluster|clustering|umap|tsne|pca|qc|mitochondrial|percent\.mt|nfeature|ncount|deg|differential expression|go enrichment|kegg|reactome|pathway|gsea|volcano|heatmap|h5ad|rds|loom|mtx|fastq|bam|vcf|counts?|expression|annotation|doublet|batch|integration|harmony|scvi)\b|生信|单细胞|转录组|基因|表达矩阵|差异表达|富集|通路|聚类|细胞类型|细胞注释|质控|线粒体|标记基因|火山图|热图/i,tJ=/(?:^|[\s(["'`])(?:\.{1,2}\/|\/|~\/)?[A-Za-z0-9_.@+\-/\\]+\/\s*(?:[::-]|[0-9]+|含|共|files?|个文件|PDFs?|PNGs?|输出|output|results?)/im,tq=/\.(?:csv|tsv|xlsx|xls|pdf|png|jpg|jpeg|svg|html|r|R|py|rds|h5ad|loom|mtx|tsv\.gz|csv\.gz)\b/i;function tK({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 tZ({status:e}){let t=e?.current??"0.8.23"??"0.0.0";if(e?.updateAvailable){let r=e.latest?`v${e.latest}`:"latest";return(0,n.jsxs)("span",{title:`Current v${t}; latest ${r}; run ${e.updateCommand}`,style:{display:"block",maxWidth:"100%",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:11,color:"var(--accent)"},children:["Update: ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)",color:"var(--accent)"},children:e.updateCommand})]})}return(0,n.jsxs)("span",{title:`AnnoVibe v${t}`,style:{fontSize:11,color:"var(--text-dim)",whiteSpace:"nowrap"},children:["v",t]})}function tG(e){let t=e.content;return"string"==typeof t?t:Array.isArray(t)?t.map(e=>"text"===e.type?e.text:"toolCall"===e.type?`${e.toolName} ${JSON.stringify(e.input)}`:"").join("\n"):""}function tY({session:e,newSessionCwd:t,onAgentEnd:i,onSessionCreated:l,onSessionForked:s,modelsRefreshKey:a,chatInputRef:d,onBranchDataChange:c,onSystemPromptChange:u,onSessionStatsChange:p,onContextUsageChange:h,onReportUpdated:x,generativeUI:g}){var f;let v,{data:m,loading:y,error:b,messages:j,entryIds:k,streamState:w,activeLeafId:S,agentRunning:C,modelNames:T,modelList:z,modelThinkingLevels:L,modelThinkingLevelMaps:I,toolPreset:M,thinkingLevel:R,retryInfo:W,contextUsage:E,forkingEntryId:$,isCompacting:N,compactError:B,displayModel:P,sessionStats:A,agentPhase:H,agentError:O,isNew:D,messagesEndRef:F,scrollContainerRef:U,lastUserMsgRef:_,handleSend:V,handleAbort:J,handleFork:q,handleNavigate:K,handleModelChange:Z,handleCompact:Y,handleSteer:X,handleFollowUp:Q,handleAbortCompaction:ee,handleToolPresetChange:et,handleThinkingLevelChange:er,handleAgentEventRef:en}=function(e){let{session:t,newSessionCwd:n,onAgentEnd:i,onSessionCreated:l,onSessionForked:s,modelsRefreshKey:a,onBranchDataChange:d,onSystemPromptChange:c}=e,u=null===t&&null!==n,[p,h]=(0,o.useState)(null),[x,g]=(0,o.useState)(!u),[f,v]=(0,o.useState)(null),[m,y]=(0,o.useState)(null),[b,j]=(0,o.useState)([]),[k,w]=(0,o.useState)([]),[S,C]=(0,o.useReducer)(tH,{isStreaming:!1,streamingMessage:null}),[T,z]=(0,o.useState)(!1),[L,I]=(0,o.useState)({}),[M,R]=(0,o.useState)([]),[W,E]=(0,o.useState)({}),[$,N]=(0,o.useState)({}),[B,P]=(0,o.useState)(null),[A,H]=(0,o.useState)("full"),[O,D]=(0,o.useState)("auto"),[F,U]=(0,o.useState)(null),[_,V]=(0,o.useState)(null),[J,q]=(0,o.useState)(null),[K,Z]=(0,o.useState)(null),[G,Y]=(0,o.useState)(null),[X,Q]=(0,o.useState)(null),[ee,et]=(0,o.useState)(!1),[er,en]=(0,o.useState)(null),[eo,ei]=(0,o.useState)(null),[el,es]=(0,o.useState)(null),ea=(0,o.useRef)(null),ed=(0,o.useRef)(t?.id??null),ec=(0,o.useRef)(!1),eu=(0,o.useRef)(null),ep=(0,o.useRef)(!1),eh=(0,o.useRef)(null),ex=(0,o.useRef)(!1),eg=(0,o.useRef)(null),ef=(0,o.useRef)(null),ev=(0,o.useRef)(new Map),em=(0,o.useRef)(new Set),ey=e.setNewSessionModel??P,eb=e.setToolPreset??H,ej=G??p?.context.model??X??null,ek=u?B:ej,ew=(0,o.useCallback)(e=>e?.length?e.map((e,t)=>{let r=`Attachment ${t+1}: ${e.fileName} (${e.mimeType||"application/octet-stream"}, ${e.size} bytes)`;if(e.extractedText){let t=e.truncated?"\n[The extracted text was truncated before sending.]":"";return`${r}
|
|
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 tw=(0,o.forwardRef)(function({onSend:e,onAbort:t,onSteer:r,onFollowUp:i,isStreaming:l,model:s,modelNames:a,modelList:d,onModelChange:c,onCompact:u,onAbortCompaction:p,isCompacting:h,compactError:x,toolPreset:g,onToolPresetChange:f,thinkingLevel:v,onThinkingLevelChange:m,availableThinkingLevels:y,thinkingLevelMap:b,retryInfo:j,soundEnabled:k,onSoundToggle:w,cornerBadge:S},C){let T,z,L,[I,M]=(0,o.useState)(""),[R,W]=(0,o.useState)(!1),[E,$]=(0,o.useState)(null),[N,B]=(0,o.useState)(!1),[P,A]=(0,o.useState)(!1),[H,O]=(0,o.useState)(null),[D,F]=(0,o.useState)([]),[U,_]=(0,o.useState)([]),V=(0,o.useRef)(null),J=(0,o.useRef)(null),q=(0,o.useRef)(null),K=(0,o.useRef)(null),Z=(0,o.useRef)(null),G=(0,o.useRef)(null),Y=(0,o.useRef)(null);(0,o.useImperativeHandle)(C,()=>({insertIfEmpty(e){let t=V.current;(t?t.value:I).trim()||(M(e),requestAnimationFrame(()=>{t&&(t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)}))},insertText(e){let t=V.current;if(!t)return void M(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(" ")?" ":"";M(o+l+e+i),requestAnimationFrame(()=>{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`})},addImages(e){X(e)},addFiles(e){Q(e)}}));let X=(0,o.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/"));if(!t.length)return;let r=await Promise.all(t.map(e=>new Promise((t,r)=>{let n=new FileReader;n.onload=()=>{t({data:n.result.split(",")[1],mimeType:e.type,previewUrl:URL.createObjectURL(e)})},n.onerror=r,n.readAsDataURL(e)})));F(e=>[...e,...r])},[]),Q=(0,o.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/")),r=e.filter(e=>!e.type.startsWith("image/"));if(t.length&&X(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 tk(e,r);t({data:r,fileName:e.name,mimeType:e.type||"application/octet-stream",size:e.size,...o})},n.onerror=r,n.readAsArrayBuffer(e)})));_(t=>[...t,...e])}},[X]),ee=(0,o.useCallback)(e=>{F(t=>{let r=[...t];return URL.revokeObjectURL(r[e].previewUrl),r.splice(e,1),r})},[]),et=(0,o.useCallback)(e=>{_(t=>{let r=[...t];return r.splice(e,1),r})},[]),er=(0,o.useCallback)(()=>{F(e=>(e.forEach(e=>URL.revokeObjectURL(e.previewUrl)),[])),_([])},[]),en=(0,o.useCallback)(()=>{let t=I.trim();(t||D.length||U.length)&&!l&&(e(t,D.length?D:void 0,U.length?U:void 0),M(""),er(),V.current&&(V.current.style.height="auto"))},[I,D,U,l,e,er]),eo=(0,o.useCallback)(e=>{let t=I.trim();if(!t&&!D.length&&!U.length)return;let n=D.length?D:void 0,o=U.length?U:void 0;"steer"===e&&r?r(t,n,o):"followup"===e&&i&&i(t,n,o),M(""),er(),V.current&&(V.current.style.height="auto")},[I,D,U,r,i,er]),ei=(0,o.useCallback)(e=>{"Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),l&&(r||i)?eo(r?"steer":"followup"):en())},[l,r,i,eo,en]),el=(0,o.useCallback)(()=>{let e=V.current;e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[]),es=(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(),Q(t.map(e=>e.getAsFile()).filter(e=>null!==e)))},[Q]),ea=d&&d.length>0?d.map(e=>({provider:e.provider,modelId:e.id,name:e.name})):Object.entries(a??{}).map(([e,t])=>({provider:s?.provider??"unknown",modelId:e,name:t})),ed=[];for(let e of ea){let t=ed.find(t=>t.provider===e.provider);t?t.options.push(e):ed.push({provider:e.provider,options:[e]})}let ec=s?ea.find(e=>e.modelId===s.modelId&&e.provider===s.provider)?.name??s.modelId:ea.length>0?ea[0].name:null;return(0,o.useEffect)(()=>{let e=e=>{J.current&&!J.current.contains(e.target)&&q.current&&!q.current.contains(e.target)&&W(!1),K.current&&!K.current.contains(e.target)&&B(!1),Z.current&&!Z.current.contains(e.target)&&A(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,o.useEffect)(()=>{if(!f)return;let e=!1;return fetch("/api/subagents/status").then(e=>e.ok?e.json():null).then(t=>{e||O(!!t?.ready)}).catch(()=>{e||O(!1)}),()=>{e=!0}},[f]),(0,n.jsxs)("div",{style:{flexShrink:0,background:"transparent",padding:"0 16px 8px",paddingRight:52},children:[(0,n.jsx)("input",{ref:G,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:e=>{X(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsx)("input",{ref:Y,type:"file",accept:".pdf,.docx,.xlsx,.pptx,.doc,.xls,.ppt,application/pdf,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.presentationml.presentation",multiple:!0,style:{display:"none"},onChange:e=>{Q(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsxs)("div",{style:{maxWidth:820,margin:"0 auto",position:"relative"},children:[S&&(0,n.jsx)("div",{style:{position:"absolute",right:8,top:-22,display:"flex",alignItems:"center",justifyContent:"flex-end",maxWidth:"min(320px, 60vw)",minHeight:18,zIndex:2,fontFamily:"var(--font-mono)",overflow:"hidden"},children:S}),j&&(0,n.jsxs)("div",{style:{marginBottom:8,padding:"5px 10px",background:"rgba(234,179,8,0.08)",border:"1px solid rgba(234,179,8,0.25)",borderRadius:6,fontSize: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 (",j.attempt,"/",j.maxAttempts,")…",j.errorMessage&&(0,n.jsxs)("span",{style:{opacity:.7,marginLeft:4},children:["— ",j.errorMessage]})]}),(D.length>0||U.length>0)&&(0,n.jsxs)("div",{style:{display:"flex",gap:6,marginBottom:6,flexWrap:"wrap",alignItems:"flex-end"},children:[D.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:()=>ee(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}`)),U.map((e,t)=>(0,n.jsx)(tf,{doc:e,onRemove:()=>et(t)},`doc-${t}`))]}),(0,n.jsxs)("div",{style:{display:"flex",gap:8,alignItems:"center",background:"var(--bg)",border:`1px solid ${l&&(r||i)?"rgba(234,179,8,0.4)":"color-mix(in srgb, var(--border) 70%, transparent)"}`,borderRadius:14,padding:"10px 10px 10px 14px",boxShadow:"0 1px 2px rgba(15,23,42,0.04), 0 8px 24px -12px rgba(15,23,42,0.10)",transition:"border-color 0.15s, background 0.15s, box-shadow 0.15s"},children:[(0,n.jsx)("textarea",{ref:V,value:I,onChange:e=>M(e.target.value),onKeyDown:ei,onInput:el,onPaste:es,placeholder:l&&(r||i)?"Steer 立即注入 / Follow-up 排队…":l?"Agent is running…":"Message…",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"}}),l?(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,flexShrink:0,alignSelf:"flex-end"},children:[r&&(0,n.jsxs)("button",{onClick:()=>eo("steer"),disabled:!I.trim()&&!D.length&&!U.length,title:"打断 Agent 当前运行,立即注入消息",style:{display:"flex",alignItems:"center",gap:5,padding:"7px 12px",background:I.trim()||D.length||U.length?"rgba(234,179,8,0.12)":"none",border:"1px solid rgba(234,179,8,0.35)",borderRadius:8,color:I.trim()||D.length||U.length?"rgba(180,130,0,1)":"var(--text-dim)",cursor:I.trim()||D.length||U.length?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",transition:"background 0.12s"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M5 1 L9 5 L5 9"}),(0,n.jsx)("line",{x1:"1",y1:"5",x2:"9",y2:"5"})]}),"Steer"]}),i&&(0,n.jsxs)("button",{onClick:()=>eo("followup"),disabled:!I.trim()&&!D.length&&!U.length,title:"在 Agent 完成后排队发送",style:{display:"flex",alignItems:"center",gap:5,padding:"7px 12px",background:I.trim()||D.length||U.length?"rgba(129,140,248,0.12)":"none",border:"1px solid rgba(129,140,248,0.35)",borderRadius:8,color:I.trim()||D.length||U.length?"rgba(99,102,241,1)":"var(--text-dim)",cursor:I.trim()||D.length||U.length?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",transition:"background 0.12s"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"5",y1:"1",x2:"5",y2:"6"}),(0,n.jsx)("polyline",{points:"2.5 3.5 5 1 7.5 3.5"}),(0,n.jsx)("line",{x1:"2",y1:"9",x2:"8",y2:"9"})]}),"Follow-up"]})]}):(0,n.jsxs)("button",{onClick:en,disabled:!I.trim()&&!D.length&&!U.length,style:{flexShrink:0,alignSelf:"flex-end",display:"flex",alignItems:"center",gap:6,padding:"7px 14px",background:I.trim()||D.length||U.length?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:8,color:I.trim()||D.length||U.length?"#fff":"var(--text-dim)",cursor:I.trim()||D.length||U.length?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",boxShadow:I.trim()||D.length||U.length?"0 1px 3px rgba(37,99,235,0.25)":"none",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"})]}),"Send"]})]}),(0,n.jsxs)("div",{className:"chat-input-toolbar",style:{marginTop:8,display:"flex",alignItems:"center",gap:6},children:[(0,n.jsxs)("div",{className:"chat-input-toolbar-left",style:{flex:"0 0 auto",display:"flex",alignItems:"center",gap:2},children:[(0,n.jsx)("button",{onClick:()=>G.current?.click(),disabled:l,title:"Attach image (right-click for document)",style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"none",border:"none",borderRadius:9,color:D.length||U.length?"var(--accent)":"var(--text-muted)",cursor:l?"not-allowed":"pointer",opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=D.length||U.length?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=D.length||U.length?"var(--accent)":"var(--text-muted)"},onContextMenu:e=>{e.preventDefault(),Y.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"})})}),ea.length>0&&ec&&c&&(0,n.jsxs)("div",{ref:J,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:e=>{let t=e.currentTarget.getBoundingClientRect();$({top:t.top,left:t.left,width:t.width}),W(e=>!e)},disabled:l,style:{display:"flex",alignItems:"center",gap:6,padding:"8px 12px",height:32,maxWidth:220,overflow:"hidden",background:R?"var(--bg-hover)":"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=R?"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:ec})]}),R&&E&&(z=(T=window.visualViewport?.height??window.innerHeight)-E.top+6,L=Math.max(120,Math.min(E.top-8,.6*T)),(0,n.jsx)("div",{ref:q,style:{position:"fixed",bottom:z,left:E.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:E.width,maxHeight:L,overflowY:"auto"},children:ed.map((e,t)=>(0,n.jsxs)("div",{children:[ed.length>1&&(0,n.jsx)("div",{style:{padding:"6px 12px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:t>0?"1px solid var(--border)":"none"},children:e.provider}),e.options.map(e=>{let t=e.modelId===s?.modelId&&e.provider===s?.provider;return(0,n.jsxs)("button",{onClick:()=>{W(!1),t||c(e.provider,e.modelId)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize: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))}))]})]}),(0,n.jsx)("div",{className:"chat-input-toolbar-spacer",style:{flex:1}}),(0,n.jsxs)("div",{className:"chat-input-toolbar-right",style:{flex:"0 0 auto",display:"flex",alignItems:"center",gap:2,marginLeft:"auto"},children:[!l&&m&&(0,n.jsxs)("div",{ref:Z,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>!l&&A(e=>!e),disabled:l,title:"切换推理强度",style:{display:"flex",alignItems:"center",gap:5,padding:"8px 12px",height:32,background:P?"var(--bg-hover)":"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=P?"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",{children:(()=>{let e=v??"auto";if("auto"===e||!b)return e;let t=b[e];return null!=t?t:e})()})]}),P&&(0,n.jsx)("div",{style:{position:"absolute",bottom:"calc(100% + 6px)",right:0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",overflow:"hidden",minWidth:180},children:tx.filter(e=>!y||"auto"===e||y.includes(e)).map(e=>{let t=(v??"auto")===e,r=tg[e],o="auto"!==e&&b?b[e]:void 0,i=null!=o&&o!==e?o:e,l=null!=o&&o!==e;return(0,n.jsxs)("button",{onClick:()=>{A(!1),t||m(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: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)})})]}),!l&&f&&(0,n.jsxs)("div",{ref:K,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>!l&&B(e=>!e),disabled:l,title:"切换工具预设",style:{display:"flex",alignItems:"center",gap:5,padding:"8px 12px",height:32,background:N?"var(--bg-hover)":"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=N?"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",{children:Object.entries(tp).find(([,e])=>e===(g??"full"))?.[0]??"full"})]}),N&&(0,n.jsx)("div",{style:{position:"absolute",bottom:"calc(100% + 6px)",right:0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",overflow:"hidden",minWidth:120},children:tu.map(e=>{let t=tp[e],r=(g??"full")===t,o="agent"===e&&!1===H,i=o?"需安装 pi-subagents":th[e];return(0,n.jsxs)("button",{onClick:()=>{!o&&(B(!1),r||f(t))},disabled:o,title:o?"运行 pi install npm:pi-subagents 后再启用":void 0,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:r?"var(--bg-selected)":"none",border:"none",color:r?"var(--text)":"var(--text-muted)",cursor:o?"not-allowed":"pointer",fontSize:12,textAlign:"left",fontWeight:r?600:400,opacity:o?.5:1,whiteSpace:"nowrap"},onMouseEnter:e=>{r||o||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{r||(e.currentTarget.style.background="none")},children:[r?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1},children:e}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:i})]},e)})})]}),!l&&u&&(0,n.jsxs)("div",{style:{position:"relative"},children:[x&&(0,n.jsx)("div",{style:{position:"absolute",bottom:"calc(100% + 6px)",right:0,background:"#1f2937",color:"#f87171",fontSize:11,padding:"4px 8px",borderRadius:5,whiteSpace:"nowrap",pointerEvents:"none",boxShadow:"0 2px 8px rgba(0,0,0,0.2)",zIndex:50},children:x}),(0,n.jsx)("button",{onClick:h?p:u,disabled:l&&!h,style:{display:"flex",alignItems:"center",gap:5,padding:"8px 12px",height:32,background:h?"rgba(239,68,68,0.08)":"none",border:"none",borderRadius:9,color:h?"#ef4444":"var(--text-muted)",cursor:l&&!h?"not-allowed":"pointer",fontSize:12,opacity:l&&!h?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{(!l||h)&&(e.currentTarget.style.background=h?"rgba(239,68,68,0.16)":"var(--bg-hover)",e.currentTarget.style.color=h?"#ef4444":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=h?"rgba(239,68,68,0.08)":"none",e.currentTarget.style.color=h?"#ef4444":"var(--text-muted)"},title:h?"停止压缩":"压缩上下文",children:h?(0,n.jsxs)(n.Fragment,{children:[(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"})}),"Compacting…"]}):(0,n.jsxs)(n.Fragment,{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)("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"})]}),"Compact"]})})]}),l&&(0,n.jsxs)("button",{onClick:t,title:"停止 Agent",style:{display:"flex",alignItems:"center",gap:6,padding:"8px 14px",height:32,background:"rgba(239,68,68,0.08)",border:"1px solid rgba(239,68,68,0.3)",borderRadius:9,color:"#ef4444",cursor:"pointer",fontSize: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!==w&&(0,n.jsx)("button",{onClick:w,title:k?"关闭完成提示音":"开启完成提示音",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"none",border:"none",borderRadius:9,color:k?"var(--text-muted)":"var(--text-dim)",cursor:"pointer",opacity:k?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=k?"var(--text-muted)":"var(--text-dim)",e.currentTarget.style.opacity=k?"1":"0.55"},children:k?(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 tS(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 tC({messages:e,streamingMessage:t,scrollContainer:r,messageRefs:i}){let[l,s]=(0,o.useState)(0),[a,d]=(0,o.useState)(1),[c,u]=(0,o.useState)(!1),[p,h]=(0,o.useState)([]),[x,g]=(0,o.useState)(!1),[f,v]=(0,o.useState)(null),m=(0,o.useRef)(!1),y=(0,o.useRef)(null),b=(0,o.useMemo)(()=>t?[...e,t]:e,[e,t]),j=(0,o.useRef)(b);j.current=b;let k=(0,o.useRef)(null);k.current=()=>{let e=r.current;if(!e)return;let t=e.scrollHeight,n=e.clientHeight,o=t-n;u(o>20),o<=0?(s(0),d(1)):(s(e.scrollTop/o),d(n/t));let l=i.current,a=[],c=0,p=j.current;for(let r=0;r<p.length;r++){let n=p[r];if("user"!==n.role&&"assistant"!==n.role)continue;let o=l?.[c];if(c++,("user"===n.role||"assistant"===n.role&&(n.content??[]).some(e=>"text"===e.type))&&o&&t>0){let r=o.getBoundingClientRect(),i=e.getBoundingClientRect(),l=r.top-i.top+e.scrollTop,s=r.height;a.push({topRatio:l/t,heightRatio:s/t,msg:n,index:a.length})}}h(a)};let w=(0,o.useCallback)(()=>k.current(),[]);(0,o.useEffect)(()=>{let e=r.current;if(!e)return;e.addEventListener("scroll",w,{passive:!0});let t=new ResizeObserver(w);return t.observe(e),e.firstElementChild&&t.observe(e.firstElementChild),w(),()=>{e.removeEventListener("scroll",w),t.disconnect()}},[r,w]),(0,o.useEffect)(()=>{let e=setTimeout(w,50);return()=>clearTimeout(e)},[e.length,w]);let S=(0,o.useCallback)(e=>{let t=r.current;if(!t)return;let n=t.scrollHeight-t.clientHeight;n<=0||(t.scrollTop=Math.max(0,Math.min(1-a,e))/(1-a)*n)},[r,a]),C=(0,o.useCallback)(e=>{if(!c)return;m.current=!0;let t=e.currentTarget.getBoundingClientRect(),r=(e.clientY-t.top)/t.height,n=r-l*(1-a),o=n>=0&&n<=a?n:a/2;S(r-o);let i=e=>{m.current&&S((e.clientY-t.top)/t.height-o)},s=()=>{m.current=!1,window.removeEventListener("mousemove",i),window.removeEventListener("mouseup",s)};window.addEventListener("mousemove",i),window.addEventListener("mouseup",s)},[c,a,l,S]),T=y.current?.clientHeight??600,z=(0,o.useMemo)(()=>{if(!x||0===p.length)return[];let e=p.map(e=>Math.round(e.topRatio*T-11));for(let t=0;t<10;t++){for(let t=1;t<e.length;t++){let r=e[t-1]+22+2;e[t]<r&&(e[t]=r)}for(let t=e.length-2;t>=0;t--){let r=e[t+1]-22-2;e[t]>r&&(e[t]=r)}}for(let t=0;t<e.length;t++)e[t]=Math.max(0,Math.min(T-22,e[t]));return e},[x,p,T]);if(!c)return null;let L=l*(1-a)*100,I=100*a,M=null!==f&&p.length>0?p.reduce((e,t)=>Math.abs(t.topRatio-f)<Math.abs(p[e].topRatio-f)?t.index:e,0):null;return(0,n.jsxs)("div",{ref:y,onMouseDown:C,onMouseEnter:()=>g(!0),onMouseLeave:()=>{g(!1),v(null)},onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();v((e.clientY-t.top)/t.height)},style:{width:36,flexShrink:0,position:"relative",cursor:"default",userSelect:"none",borderLeft:"1px solid var(--border)",background:"var(--bg-panel)",overflow:"visible"},children:[(0,n.jsx)("div",{style:{position:"absolute",left:0,right:0,top:`${L}%`,height:`${I}%`,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=tS(e.msg),r=x&&M===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=tS(e.msg),i=M===e.index;return r&&0!==z.length?(0,n.jsx)("div",{style:{position:"absolute",top:z[t],right:"100%",marginRight:6,background:"var(--bg)",borderTop:`1px solid ${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 tT(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function tz(e,t=220){if(!e)return;let r=e.trim();if(r)return r.length>t?`${r.slice(0,t)}...`:r}function tL(...e){for(let t of e)if("string"==typeof t&&t.trim())return t}function tI(...e){for(let t of e)if("number"==typeof t&&Number.isFinite(t))return t}function tM(e){let t=new Map;for(let r of e){if("custom"===r.role&&"subagent-notify"===r.customType&&"string"==typeof r.content){let e=r.content.match(/^Background task (completed|failed|paused):\s*\*\*(.+?)\*\*(?:\s+\((.+?)\))?/);if(e){let n=`bg-${e[2]}-${r.timestamp??""}`;t.set(n,{id:n,agent:e[2],status:e[1],task:e[3],summary:tz(r.content.split("\n").slice(3).join("\n")),timestamp:r.timestamp})}}if("assistant"===r.role){let e=r.content;if(!e)continue;for(let n of e)if("toolCall"===n.type&&"subagent"===n.toolName&&n.input){let e=n.input,o=e.agent??(e.chain?"chain":e.tasks?"parallel":e.action??"subagent"),i="string"==typeof e.task?e.task:void 0,l=n.toolCallId??`sub-${o}-${r.timestamp??Date.now()}`;t.set(l,{id:l,agent:o,status:"running",task:i,timestamp:r.timestamp})}}if("toolResult"===r.role){if(r.toolName&&"subagent"!==r.toolName||!r.toolCallId||!t.has(r.toolCallId))continue;let e=t.get(r.toolCallId),n=r.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n");t.set(r.toolCallId,function(e,t,r){let n;if(!tT(t))return{...e,summary:tz(r)};let o=Array.isArray(t.results)?t.results.filter(tT):[],i=o[0],l=i?.progressSummary,s=i&&(n=i.artifactPaths)?Object.values(n).filter(e=>"string"==typeof e&&e.trim().length>0):[],a=tL(i?.finalOutput,i?.output,r);return{...e,mode:tL(t.mode),runId:tL(t.runId),agent:tL(i?.agent,e.agent)??e.agent,task:tL(i?.task,e.task),summary:tz(a),model:tL(i?.model),durationMs:tI(l?.durationMs),toolCount:tI(l?.toolCount),tokens:tI(l?.tokens),outputPath:tL(i?.savedOutputPath,i?.artifactPaths?.outputPath),sessionFile:tL(i?.sessionFile,i?.artifactPaths?.jsonlPath),artifacts:s,resultCount:o.length||void 0}}({...e,status:function(e){if(e.isError)return"failed";let t=e.details;return tT(t)&&Array.isArray(t.results)&&t.results.some(e=>tT(e)&&"number"==typeof e.exitCode&&0!==e.exitCode)?"failed":"completed"}(r)},r.details,n))}}return Array.from(t.values()).sort((e,t)=>(t.timestamp??0)-(e.timestamp??0))}function tR({messages:e,runs:t}){let r=(0,o.useMemo)(()=>tM(e??[]),[e]),i=t??r,l=i.filter(e=>"running"===e.status),s=i.filter(e=>"running"!==e.status);return 0===i.length?null:(0,n.jsxs)("div",{style:{height:"100%",overflow:"auto",padding:12},children:[l.length>0&&(0,n.jsx)(tW,{title:`Active (${l.length})`,runs:l}),s.length>0&&(0,n.jsx)(tW,{title:`Completed (${s.length})`,runs:s,compact:l.length>0})]})}function tW({title:e,runs:t,compact:r}){return(0,n.jsxs)("div",{style:{marginBottom:r?10:16},children:[(0,n.jsx)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-dim)",marginBottom:8,textTransform:"uppercase",letterSpacing:"0.05em"},children:e}),t.map(e=>(0,n.jsx)(tE,{run:e},e.id))]})}function tE({run:e}){let[t,r]=(0,o.useState)(!1),i="running"===e.status,l="completed"===e.status?"#22c55e":"failed"===e.status?"#ef4444":i?"var(--accent)":"var(--text-dim)",s="failed"===e.status?"rgba(248,113,113,0.35)":i?"rgba(99,102,241,0.25)":"var(--border)",a="failed"===e.status?"rgba(248,113,113,0.05)":i?"rgba(99,102,241,0.05)":"var(--bg-panel)",d=[e.mode,e.resultCount&&e.resultCount>1?`${e.resultCount} results`:void 0,void 0!==e.toolCount?`${e.toolCount} tools`:void 0,void 0!==e.tokens?`${e.tokens.toLocaleString()} tok`:void 0,void 0!==e.durationMs?`${Math.round(e.durationMs/1e3)}s`:void 0].filter(Boolean).join(" \xb7 "),c=!!(e.summary||e.outputPath||e.sessionFile||e.artifacts?.length||e.model||e.runId);return(0,n.jsxs)("div",{style:{borderRadius:6,border:`1px solid ${s}`,background:a,marginBottom:6,fontSize:12,overflow:"hidden"},children:[(0,n.jsxs)("button",{onClick:()=>c&&r(e=>!e),style:{display:"flex",alignItems:"center",gap:7,width:"100%",border:"none",background:"transparent",padding:"8px 10px",color:"var(--text-muted)",textAlign:"left",cursor:c?"pointer":"default"},children:[(0,n.jsx)(t$,{running:i,color:l}),(0,n.jsx)("span",{style:{fontWeight:650,color:"var(--text)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.agent}),(0,n.jsx)("span",{style:{color:l,fontSize:10,fontWeight:700,flexShrink:0},children:e.status}),d&&(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,marginLeft:"auto",whiteSpace:"nowrap"},children:d}),c&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:t?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),e.task&&(0,n.jsx)("div",{style:{padding:"0 10px 8px 25px",color:"var(--text-muted)",fontSize:11,lineHeight:1.4},children:tz(e.task,150)}),t&&c&&(0,n.jsxs)("div",{style:{borderTop:`1px solid ${s}`,background:"var(--bg)",padding:"8px 10px",display:"flex",flexDirection:"column",gap:7},children:[e.summary&&(0,n.jsx)("pre",{style:{margin:0,color:"var(--text-muted)",fontSize:11,lineHeight:1.45,whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:160,overflow:"auto"},children:e.summary}),(0,n.jsx)(tN,{run:e})]})]})}function t$({running:e,color:t}){return(0,n.jsx)("span",{style:{width:8,height:8,borderRadius:"50%",background:t,display:"inline-block",animation:e?"pulse 1.5s infinite":void 0,flexShrink:0}})}function tN({run:e}){let t=[e.model?["model",e.model]:void 0,e.runId?["run",e.runId]:void 0,e.outputPath?["output",e.outputPath]:void 0,e.sessionFile?["session",e.sessionFile]:void 0,...(e.artifacts??[]).slice(0,4).map((e,t)=>[`artifact ${t+1}`,e])].filter(Boolean);return 0===t.length?null:(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:3},children:t.map(([e,t])=>(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"58px minmax(0, 1fr)",gap:6,fontSize:10},children:[(0,n.jsx)("span",{style:{color:"var(--text-dim)",textTransform:"uppercase"},children:e}),(0,n.jsx)("span",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:t,children:t})]},`${e}:${t}`))})}function tB(e){if("assistant"!==e.role)return e;let t=e.content;if(!Array.isArray(t))return e;let r=t.map(e=>("object"!=typeof e||null===e||Array.isArray(e)||"toolCall"!==e.type?null:{type:"toolCall",toolCallId:"string"==typeof e.toolCallId?e.toolCallId:"string"==typeof e.id?e.id:"",toolName:"string"==typeof e.toolName?e.toolName:"string"==typeof e.name?e.name:"",input:"object"!=typeof e.input||null===e.input||Array.isArray(e.input)?"object"!=typeof e.arguments||null===e.arguments||Array.isArray(e.arguments)?{}:e.arguments:e.input})??e);return{...e,content:r}}async function tP(e,t){let r=await fetch(`/api/agent/${encodeURIComponent(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),n=await r.json().catch(()=>({}));if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);return n.data}var tA=r(14755);function tH(e,t){switch(t.type){case"start":return{isStreaming:!0,streamingMessage:null};case"update":return{isStreaming:!0,streamingMessage:t.message};case"end":case"reset":return{isStreaming:!1,streamingMessage:null};default:return e}}function tO(e){if("user"!==e.role)return null;var t=e.content;if("string"==typeof t)return`text:${t}`;if(!Array.isArray(t))try{return`other:${JSON.stringify(t)}`}catch{return"other:"}let r=t.map(e=>{if(!e||"object"!=typeof e)return e;if("text"===e.type)return{type:"text",text:e.text};if("image"===e.type){let t=e.source&&"object"==typeof e.source?e.source:{};return{type:"image",mimeType:t.media_type??e.mimeType,data:t.data??e.data,url:t.url}}return e});try{return`blocks:${JSON.stringify(r)}`}catch{return"blocks:"}}function tD(e){if(!e.role)return null;try{return`${e.role}:${JSON.stringify(e)}`}catch{return null}}let tF=["image/","application/pdf","application/vnd.openxmlformats-officedocument","application/msword","application/vnd.ms-"];function tU(e){return tF.some(t=>e.type.startsWith(t))}let t_=["annotate and analyze.","vibe code bioinformatics.","turn data into figures.","inspect your project.","build a reproducible report.","run R/Python plots.","summarize that paper.","review the pipeline.","compare markers.","draft methods.","find the next analysis step."],tV=/\b(seurat|scanpy|single[- ]cell|scrna|sc[- ]rna|rna[- ]seq|transcriptom|gene|genes|marker|cell type|cluster|clustering|umap|tsne|pca|qc|mitochondrial|percent\.mt|nfeature|ncount|deg|differential expression|go enrichment|kegg|reactome|pathway|gsea|volcano|heatmap|h5ad|rds|loom|mtx|fastq|bam|vcf|counts?|expression|annotation|doublet|batch|integration|harmony|scvi)\b|生信|单细胞|转录组|基因|表达矩阵|差异表达|富集|通路|聚类|细胞类型|细胞注释|质控|线粒体|标记基因|火山图|热图/i,tJ=/(?:^|[\s(["'`])(?:\.{1,2}\/|\/|~\/)?[A-Za-z0-9_.@+\-/\\]+\/\s*(?:[::-]|[0-9]+|含|共|files?|个文件|PDFs?|PNGs?|输出|output|results?)/im,tq=/\.(?:csv|tsv|xlsx|xls|pdf|png|jpg|jpeg|svg|html|r|R|py|rds|h5ad|loom|mtx|tsv\.gz|csv\.gz)\b/i;function tK({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 tZ({status:e}){let t=e?.current??"0.8.24"??"0.0.0";if(e?.updateAvailable){let r=e.latest?`v${e.latest}`:"latest";return(0,n.jsxs)("span",{title:`Current v${t}; latest ${r}; run ${e.updateCommand}`,style:{display:"block",maxWidth:"100%",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:11,color:"var(--accent)"},children:["Update: ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)",color:"var(--accent)"},children:e.updateCommand})]})}return(0,n.jsxs)("span",{title:`AnnoVibe v${t}`,style:{fontSize:11,color:"var(--text-dim)",whiteSpace:"nowrap"},children:["v",t]})}function tG(e){let t=e.content;return"string"==typeof t?t:Array.isArray(t)?t.map(e=>"text"===e.type?e.text:"toolCall"===e.type?`${e.toolName} ${JSON.stringify(e.input)}`:"").join("\n"):""}function tY({session:e,newSessionCwd:t,onAgentEnd:i,onSessionCreated:l,onSessionForked:s,modelsRefreshKey:a,chatInputRef:d,onBranchDataChange:c,onSystemPromptChange:u,onSessionStatsChange:p,onContextUsageChange:h,onReportUpdated:x,generativeUI:g}){var f;let v,{data:m,loading:y,error:b,messages:j,entryIds:k,streamState:w,activeLeafId:S,agentRunning:C,modelNames:T,modelList:z,modelThinkingLevels:L,modelThinkingLevelMaps:I,toolPreset:M,thinkingLevel:R,retryInfo:W,contextUsage:E,forkingEntryId:$,isCompacting:N,compactError:B,displayModel:P,sessionStats:A,agentPhase:H,agentError:O,isNew:D,messagesEndRef:F,scrollContainerRef:U,lastUserMsgRef:_,handleSend:V,handleAbort:J,handleFork:q,handleNavigate:K,handleModelChange:Z,handleCompact:Y,handleSteer:X,handleFollowUp:Q,handleAbortCompaction:ee,handleToolPresetChange:et,handleThinkingLevelChange:er,handleAgentEventRef:en}=function(e){let{session:t,newSessionCwd:n,onAgentEnd:i,onSessionCreated:l,onSessionForked:s,modelsRefreshKey:a,onBranchDataChange:d,onSystemPromptChange:c}=e,u=null===t&&null!==n,[p,h]=(0,o.useState)(null),[x,g]=(0,o.useState)(!u),[f,v]=(0,o.useState)(null),[m,y]=(0,o.useState)(null),[b,j]=(0,o.useState)([]),[k,w]=(0,o.useState)([]),[S,C]=(0,o.useReducer)(tH,{isStreaming:!1,streamingMessage:null}),[T,z]=(0,o.useState)(!1),[L,I]=(0,o.useState)({}),[M,R]=(0,o.useState)([]),[W,E]=(0,o.useState)({}),[$,N]=(0,o.useState)({}),[B,P]=(0,o.useState)(null),[A,H]=(0,o.useState)("full"),[O,D]=(0,o.useState)("auto"),[F,U]=(0,o.useState)(null),[_,V]=(0,o.useState)(null),[J,q]=(0,o.useState)(null),[K,Z]=(0,o.useState)(null),[G,Y]=(0,o.useState)(null),[X,Q]=(0,o.useState)(null),[ee,et]=(0,o.useState)(!1),[er,en]=(0,o.useState)(null),[eo,ei]=(0,o.useState)(null),[el,es]=(0,o.useState)(null),ea=(0,o.useRef)(null),ed=(0,o.useRef)(t?.id??null),ec=(0,o.useRef)(!1),eu=(0,o.useRef)(null),ep=(0,o.useRef)(!1),eh=(0,o.useRef)(null),ex=(0,o.useRef)(!1),eg=(0,o.useRef)(null),ef=(0,o.useRef)(null),ev=(0,o.useRef)(new Map),em=(0,o.useRef)(new Set),ey=e.setNewSessionModel??P,eb=e.setToolPreset??H,ej=G??p?.context.model??X??null,ek=u?B:ej,ew=(0,o.useCallback)(e=>e?.length?e.map((e,t)=>{let r=`Attachment ${t+1}: ${e.fileName} (${e.mimeType||"application/octet-stream"}, ${e.size} bytes)`;if(e.extractedText){let t=e.truncated?"\n[The extracted text was truncated before sending.]":"";return`${r}
|
|
250
250
|
${t}
|
|
251
251
|
${e.extractedText}`.trim()}return`${r}
|
|
252
252
|
[Text extraction unavailable: ${e.extractionError??"unsupported file type"}]`}).join("\n\n---\n\n"):"",[]),eS=(0,o.useCallback)(e=>{let t=tO(e);if(!t)return;let r=ev.current;r.set(t,(r.get(t)??0)+1)},[]),eC=(0,o.useCallback)(e=>{let t=tO(e);if(!t)return!1;let r=ev.current,n=r.get(t)??0;return!(n<=0)&&(1===n?r.delete(t):r.set(t,n-1),!0)},[]),eT=(()=>{let e={input:0,output:0,cacheRead:0,cacheWrite:0},t=0;for(let r of b){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})(),ez=(0,o.useCallback)(async(e,t=!1,r=!1)=>{try{t&&g(!0);let n=r?`/api/sessions/${encodeURIComponent(e)}?includeState`:`/api/sessions/${encodeURIComponent(e)}`,o=await fetch(n);if(ed.current&&ed.current!==e)return null;if(404===o.status)return t&&(h(null),y(null),j([]),v(null)),null;if(!o.ok)throw Error(`HTTP ${o.status}`);let i=await o.json();return h(i),y(i.leafId),j(i.context.messages),w(i.context.entryIds??[]),ev.current.clear(),em.current=new Set(i.context.messages.map(tD).filter(e=>!!e)),Y(null),v(null),!i.agentState?.state?.thinkingLevel&&i.context.thinkingLevel&&"off"!==i.context.thinkingLevel&&D(i.context.thinkingLevel),i.agentState??null}catch(e){return v(String(e)),null}finally{t&&g(!1)}},[]),eL=(0,o.useCallback)(async(e,t)=>{try{let r=t?`/api/sessions/${encodeURIComponent(e)}/context?leafId=${encodeURIComponent(t)}`:`/api/sessions/${encodeURIComponent(e)}/context`,n=await fetch(r);if(!n.ok)throw Error(`HTTP ${n.status}`);let o=await n.json();j(o.context.messages),w(o.context.entryIds??[]),ev.current.clear()}catch(e){console.error("Failed to load context:",e)}},[]),eI=(0,o.useCallback)(async e=>{try{let t=await tP(e,{type:"get_tools"});if(t){let{getPresetFromTools:e}=await r.e(8451).then(r.bind(r,48451));eb(e(t))}}catch(e){console.error("Failed to load tools:",e)}},[eb]),eM=(0,o.useCallback)((e,t={})=>{ea.current&&(ea.current.close(),ea.current=null);let r=new EventSource(`/api/agent/${encodeURIComponent(e)}/events${t.replay?"?replay=1":""}`);ea.current=r,r.onmessage=e=>{try{let t=JSON.parse(e.data);eu.current?.(t)}catch{}},r.onerror=()=>{ea.current===r&&ec.current&&(r.close(),ea.current=null,setTimeout(()=>{ec.current&&eM(e)},1e3))}},[]);(0,o.useEffect)(()=>{ec.current=T},[T]),eu.current=(0,o.useCallback)(e=>{switch(e.type){case"agent_start":es(null),z(!0),ei({kind:"waiting_model"}),C({type:"start"});break;case"agent_end":z(!1),ei(null),U(null),C({type:"end"}),ed.current&&(ez(ed.current),fetch(`/api/agent/${encodeURIComponent(ed.current)}`).then(e=>e.json()).then(e=>{e.state?.contextUsage!==void 0&&V(e.state.contextUsage??null),e.state?.systemPrompt!==void 0&&q(e.state.systemPrompt??null)}).catch(()=>{})),i?.();break;case"message_start":case"message_update":{let t=e.message;if(t){let e=tB(t);em.current.has(tD(e)??"")||C({type:"update",message:e})}ei(null);break}case"message_end":{let t=e.message;if(t){let e=tB(t),r=tD(e),n=!!r&&em.current.has(r);r&&em.current.add(r),n||"user"===e.role&&eC(e)||j(t=>[...t,e])}C({type:"reset"}),ei({kind:"waiting_model"});break}case"tool_execution_start":{let t=e.toolCallId,r=e.toolName;ei(e=>{let n=e?.kind==="running_tools"?[...e.tools]:[];return n.some(e=>e.id===t)||n.push({id:t,name:r}),{kind:"running_tools",tools:n}});break}case"tool_execution_end":{let t=e.toolCallId;ei(e=>{if(e?.kind!=="running_tools")return e;let r=e.tools.filter(e=>e.id!==t);return 0===r.length?{kind:"waiting_model"}:{kind:"running_tools",tools:r}});break}case"auto_retry_start":U({attempt:e.attempt,maxAttempts:e.maxAttempts,errorMessage:e.errorMessage});break;case"auto_retry_end":U(null);break;case"auto_compaction_start":case"compaction_start":et(!0),en(null);break;case"auto_compaction_end":case"compaction_end":et(!1),e.errorMessage?en(e.errorMessage):!e.aborted&&ed.current&&ez(ed.current)}},[eC,ez,i]);let eR=(0,o.useCallback)(async(e,r,o)=>{if(!e.trim()&&!r?.length&&!o?.length||T)return;let i=ew(o),s=e.trim()?i?`${e}
|