@seqyuan/pidex 0.7.8 → 0.7.9
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 +1 -1
- 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/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 +4 -4
- package/.next/server/app/page_client-reference-manifest.js +1 -1
- package/.next/server/app-paths-manifest.json +1 -1
- package/.next/server/middleware-build-manifest.js +1 -1
- package/.next/server/middleware-manifest.json +5 -5
- 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-85942b6ba2cbbac9.js +83 -0
- package/.next/trace +32 -32
- package/.next/trace-build +1 -1
- package/package.json +1 -1
- package/.next/static/chunks/app/page-7db7cc03c3a65772.js +0 -83
- /package/.next/static/{Qs9n3NBmC9jWCeAmStQih → 5BCSga9uuLcScgFzT89vv}/_buildManifest.js +0 -0
- /package/.next/static/{Qs9n3NBmC9jWCeAmStQih → 5BCSga9uuLcScgFzT89vv}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8974],{1564:(e,t,r)=>{Promise.resolve().then(r.bind(r,4570))},4570:(e,t,r)=>{"use strict";r.d(t,{AppShell:()=>t8});var n=r(5155),o=r(2115),i=r(3321);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 m({size:e=14}){return(0,n.jsx)(d,{label:"SC",size:e})}function v({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 z({size:e=14}){return(0,n.jsx)(d,{label:"GQL",size:e})}function L({size:e=14}){return(0,n.jsx)(d,{label:"TF",size:e})}function T({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)(T,{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)(m,{size:t});case"html":case"htm":return(0,n.jsx)(v,{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)(z,{size:t});case"tf":case"hcl":return(0,n.jsx)(L,{size:t});case"lock":return(0,n.jsx)(R,{size:t});default:return(0,n.jsx)(a,{size:t})}}function B(e){return/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith("\\\\")?e.replace(/\\/g,"/"):e}function $(e){return B(e).split("/").filter(Boolean).map(encodeURIComponent).join("/")}function F(e){let t=B(e).replace(/\/+$/,"");return t.split("/").pop()??t}function P(e,t){if(!t)return e;let r=B(e),n=B(t).replace(/\/$/,"");return r.startsWith(n+"/")?r.slice(n.length+1):e}async function A(e){let t=$(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,`${B(e).replace(/\/$/,"")}/${r}`),isDir:t.isDir,size:t.size,children:t.isDir?[]:void 0,loaded:!t.isDir}}):[]}function D({node:e,depth:t,cwd:r,onOpenFile:i,onAtMention:l,expandedPaths:a,onToggleExpanded:d,refreshKey:c}){let u=a.has(e.fullPath),[p,h]=(0,o.useState)(e.children??[]),[x,g]=(0,o.useState)(e.loaded??!1),[f,m]=(0,o.useState)(!1),[v,y]=(0,o.useState)(!1),b=(0,o.useCallback)(async(t=!1)=>{if(!x||t){m(!0);try{let t=await A(e.fullPath);h(t),g(!0)}catch{}finally{m(!1)}}},[x,e.fullPath]),j=(0,o.useRef)(x);(0,o.useEffect)(()=>{j.current=x}),(0,o.useEffect)(()=>{u&&x&&b(!0)},[c]);let k=(0,o.useCallback)(()=>{if(e.isDir){let t=!u;d(e.fullPath,t),t&&!x&&b()}else i(e.fullPath,e.name)},[e.isDir,e.fullPath,e.name,x,u,b,i,d]);return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{onClick:k,onMouseEnter:()=>y(!0),onMouseLeave:()=>y(!1),style:{position:"relative",display:"flex",alignItems:"center",gap:4,paddingLeft:8+14*t,paddingRight:8,height:24,cursor:"pointer",background:v?"var(--bg-hover)":"transparent",borderRadius:4,userSelect:"none"},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:u?"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:u}):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}),f&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",children:(0,n.jsx)("path",{d:"M12 2v4M12 18v4M4.93 4.93l2.83 2.83M16.24 16.24l2.83 2.83M2 12h4M18 12h4"})}),l&&v&&(0,n.jsxs)("button",{onClick:t=>{t.stopPropagation(),l(P(e.fullPath,r))},title:"Insert path into chat",style:{position:"absolute",right:4,top:"50%",transform:"translateY(-50%)",display:"flex",alignItems:"center",justifyContent:"center",gap:4,padding:"0 8px",height:20,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:4,color:"var(--accent)",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"4"}),(0,n.jsx)("path",{d:"M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8"})]}),"mention"]})]}),e.isDir&&u&&(0,n.jsxs)("div",{children:[p.map(e=>(0,n.jsx)(D,{node:e,depth:t+1,cwd:r,onOpenFile:i,onAtMention:l,expandedPaths:a,onToggleExpanded:d,refreshKey:c},e.fullPath)),0===p.length&&x&&(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 H({cwd:e,onOpenFile:t,refreshKey:r,onAtMention:i}){let[l,s]=(0,o.useState)([]),[a,d]=(0,o.useState)(!0),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(new Set),x=(0,o.useRef)(null),g=(0,o.useCallback)((e,t)=>{h(r=>{let n=new Set(r);return t?n.add(e):n.delete(e),n})},[]);return((0,o.useEffect)(()=>{let t=x.current!==e;x.current=e,t&&h(new Set),d(t),u(null),A(e).then(e=>s(e)).catch(e=>u(String(e))).finally(()=>d(!1))},[e,r]),a)?(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:"Loading files..."}):c?(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"#f87171"},children:c}):(0,n.jsxs)("div",{style:{padding:"2px 4px"},children:[l.map(o=>(0,n.jsx)(D,{node:o,depth:0,cwd:e,onOpenFile:t,onAtMention:i,expandedPaths:p,onToggleExpanded:g,refreshKey:r},o.fullPath)),0===l.length&&(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:"No files found"})]})}function N({cwd:e,onOpenFile:t}){let[r,i]=(0,o.useState)([]),[l,s]=(0,o.useState)(!1);(0,o.useEffect)(()=>{!async function(){let t=[];try{let e=await fetch("/api/soul"),r=await e.json();t.push({name:"soul.md",path:"soul.md",label:"soul.md",description:"Global agent personality & core guidelines",exists:r.exists??!1,size:r.size,isGlobal:!0})}catch{t.push({name:"soul.md",path:"",label:"soul.md",description:"Global agent personality",exists:!1,isGlobal:!0})}try{let e=await fetch("/api/harness"),r=await e.json();t.push({name:"harness.md",path:"harness.md",label:"harness.md",description:"Behavioral constraints & output guidelines",exists:r.exists??!1,size:r.size,isGlobal:!0})}catch{t.push({name:"harness.md",path:"",label:"harness.md",description:"Behavioral constraints",exists:!1,isGlobal:!0})}if(e)for(let r of[{name:"AGENTS.md",description:"Project instructions (auto-loaded by pi)"},{name:"memory.md",description:"Self-updating project memory & analysis log"}]){try{let n=encodeURIComponent(`${e}/${r.name}`.replace(/^\//,"")),o=await fetch(`/api/files/${n}?type=read`);if(o.ok){let n=await o.json();if(!n.error){t.push({name:r.name,path:`${e}/${r.name}`,label:r.name,description:r.description,exists:!0,size:n.size,isGlobal:!1});continue}}}catch{}t.push({name:r.name,path:e?`${e}/${r.name}`:"",label:r.name,description:r.description,exists:!1,isGlobal:!1})}i(t)}()},[e]);let a=r.filter(e=>e.isGlobal),d=r.filter(e=>!e.isGlobal),c=r.some(e=>e.exists);return(0,n.jsxs)("div",{style:{borderTop:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsxs)("button",{onClick:()=>s(e=>!e),style:{display:"flex",alignItems:"center",gap:6,width:"100%",padding:"6px 12px",background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:11,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.05em"},children:[(0,n.jsx)("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",style:{transform:l?"rotate(-90deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"1.5 2.5 4 5 6.5 2.5"})}),"Context",c&&(0,n.jsx)("span",{style:{marginLeft:"auto",fontSize:10,color:"var(--accent)"},children:r.filter(e=>e.exists).length})]}),!l&&(0,n.jsxs)("div",{style:{padding:"0 8px 6px"},children:[(0,n.jsx)("div",{style:{fontSize:10,fontWeight:600,color:"var(--text-dim)",padding:"2px 8px 4px",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Global"}),a.map(r=>{let o="soul.md"===r.name,i="harness.md"===r.name,l=o?"__soul__":i?"__harness__":null;return(0,n.jsx)(O,{file:r,cwd:e,onOpen:r.exists&&l?()=>t(l,r.name):void 0,onCreate:!r.exists&&l?()=>t(l,r.name):void 0},r.name)}),e&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:{fontSize:10,fontWeight:600,color:"var(--text-dim)",padding:"2px 8px 4px",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Project"}),d.map(r=>(0,n.jsx)(O,{file:r,cwd:e,onOpen:r.exists?()=>t(r.path,r.name):void 0},r.name))]}),(0,n.jsxs)("div",{style:{fontSize:10,color:"var(--text-dim)",padding:"4px 8px 0",lineHeight:1.5},children:[(0,n.jsx)("strong",{children:"memory.md"})," is self-updating — pi will append analysis results and corrections. ",(0,n.jsx)("strong",{children:"soul.md"})," is global — defines agent personality for all projects."]}),(0,n.jsxs)("div",{onClick:()=>{navigator.clipboard.writeText("Scan the project files, scripts, and notebooks to summarize what analyses have been done so far — including key parameters, input/output files, and findings. Write the summary to memory.md.").catch(()=>{})},title:"Click to copy scan prompt",style:{margin:"4px 8px 0",padding:"5px 8px",background:"var(--bg-panel)",border:"1px dashed var(--border)",borderRadius:5,fontSize:10,color:"var(--accent)",cursor:"pointer",textAlign:"center",lineHeight:1.5},onMouseEnter:e=>{e.currentTarget.style.background="rgba(37,99,235,0.06)",e.currentTarget.style.borderColor="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-panel)",e.currentTarget.style.borderColor="var(--border)"},children:["\uD83D\uDD0D Scan project & summarize → memory.md",(0,n.jsx)("br",{}),(0,n.jsx)("span",{style:{color:"var(--text-dim)"},children:"Click to copy prompt"})]})]})]})}function O({file:e,onOpen:t,onCreate:r}){var o;return(0,n.jsxs)("button",{onClick:t??r,title:e.description,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"5px 8px",background:"none",border:"none",borderRadius:5,color:e.exists?"var(--text-muted)":"var(--text-dim)",cursor:e.exists||r?"pointer":"default",fontSize:12,textAlign:"left",opacity:e.exists||r?1:.55},onMouseEnter:t=>{(e.exists||r)&&(t.currentTarget.style.background="var(--bg-hover)",t.currentTarget.style.color="var(--text)")},onMouseLeave:t=>{t.currentTarget.style.background="none",t.currentTarget.style.color=e.exists?"var(--text-muted)":"var(--text-dim)"},children:[(0,n.jsx)("span",{style:{fontSize:12,flexShrink:0},children:e.exists?"\uD83D\uDCDD":"➕"}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.label}),e.exists&&void 0!==e.size&&(0,n.jsx)("span",{style:{marginLeft:"auto",fontSize:10,color:"var(--text-dim)"},children:(o=e.size)<1024?`${o} B`:o<1048576?`${(o/1024).toFixed(1)} KB`:`${(o/1048576).toFixed(1)} MB`})]})}function _(e){let t=new Map;for(let r of e){if(!r.cwd)continue;let e=t.get(r.cwd);(!e||r.modified>e)&&t.set(r.cwd,r.modified)}return[...t.entries()].sort((e,t)=>t[1].localeCompare(e[1])).slice(0,5).map(([e])=>e)}function U(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)}let V="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";function K(){let[e,t]=(0,o.useState)(!1),[r,i]=(0,o.useState)(!1),l=(0,o.useRef)(null),s=function(e,t){let[r,n]=(0,o.useState)(e),i=(0,o.useRef)(null),l=(0,o.useRef)(0);return(0,o.useEffect)(()=>{if(!t)return void n(e);l.current=0;let r=4*e.length,o=()=>{l.current+=1;let t=Math.floor(l.current/r*e.length);n(e.split("").map((e,r)=>" "===e?" ":r<t?e:V[Math.floor(Math.random()*V.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?"0.7.9p0.75.5":"pidex",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:"6ch"},children:s})}function Y({selectedSessionId:e,onSelectSession:t,onNewSession:r,initialSessionId:i,onInitialRestoreDone:l,refreshKey:s,onSessionDeleted:a,selectedCwd:d,onCwdChange:c,onOpenFile:u,explorerRefreshKey:p,onAtMention:h}){let[x,g]=(0,o.useState)([]),[f,m]=(0,o.useState)(!0),[v,y]=(0,o.useState)(null),[b,j]=(0,o.useState)(null),[k,w]=(0,o.useState)(""),[S,C]=(0,o.useState)(!1),[z,L]=(0,o.useState)(!1),[T,I]=(0,o.useState)(""),M=(0,o.useRef)(null),R=(0,o.useRef)(null),[W,E]=(0,o.useState)(!0),[B,$]=(0,o.useState)(0),[F,P]=(0,o.useState)(!1),[A,D]=(0,o.useState)(!1),O=(0,o.useRef)(null),V=(0,o.useRef)(null),J=(0,o.useCallback)(async(e=!1)=>{try{e&&m(!0);let t=await fetch("/api/sessions");if(!t.ok)throw Error(`HTTP ${t.status}`);let r=await t.json();g(r.sessions),y(null),e||(P(!0),O.current&&clearTimeout(O.current),O.current=setTimeout(()=>P(!1),2e3))}catch(e){y(String(e))}finally{e&&m(!1)}},[]),Z=(0,o.useRef)(!1);(0,o.useEffect)(()=>{let e=!Z.current;Z.current=!0,J(e)},[J,s]),(0,o.useEffect)(()=>{void 0!==p&&$(e=>e+1)},[p]),(0,o.useEffect)(()=>{fetch("/api/home").then(e=>e.json()).then(e=>{e.home&&w(e.home)}).catch(()=>{})},[]);let G=(0,o.useRef)(!1);(0,o.useEffect)(()=>{c?.(b)},[b,c]),(0,o.useEffect)(()=>{if(0!==x.length&&null===b){if(i&&!G.current){G.current=!0;let e=x.find(e=>e.id===i);if(e){j(e.cwd),t(e,!0);return}l?.()}let e=_(x);e.length>0&&j(e[0])}},[x,b,i,t,l]);let X=(0,o.useCallback)(()=>{let e=T.trim();e&&j(e),L(!1),I(""),C(!1)},[T]),Q=(0,o.useCallback)(async()=>{try{let e=await fetch("/api/default-cwd",{method:"POST"}),t=await e.json();t.cwd&&(j(t.cwd),C(!1))}catch{}},[]);(0,o.useEffect)(()=>{let e=e=>{R.current&&!R.current.contains(e.target)&&(C(!1),L(!1),I(""))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let ee=(0,o.useCallback)(()=>{if(!b)return;let e="function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}-${Math.random().toString(36).slice(2)}`;r?.(e,b)},[b,r]),et=_(x),er=b?x.filter(e=>e.cwd===b):x,en=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}(er);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:10},children:[(0,n.jsx)(K,{}),(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsxs)("button",{onClick:ee,disabled:!b,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,background:"var(--bg-hover)",border:"1px solid var(--border)",color:b?"var(--text-muted)":"var(--text-dim)",cursor:b?"pointer":"not-allowed",height:32,paddingLeft:10,paddingRight:12,borderRadius:7,fontSize:12,fontWeight:500,letterSpacing:"-0.01em",flexShrink:0,transition:"background 0.12s, color 0.12s, border-color 0.12s"},title:b?`New session in ${b}`:"Select a project first",onMouseEnter:e=>{b&&(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=b?"var(--text-muted)":"var(--text-dim)",e.currentTarget.style.borderColor="var(--border)"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"6",y1:"1",x2:"6",y2:"11"}),(0,n.jsx)("line",{x1:"1",y1:"6",x2:"11",y2:"6"})]}),"New"]}),(0,n.jsx)("button",{onClick:()=>J(!1),style:{display:"flex",alignItems:"center",justifyContent:"center",background:F?"rgba(74,222,128,0.18)":"var(--bg-hover)",border:`1px solid ${F?"rgba(74,222,128,0.4)":"var(--border)"}`,color:F?"#4ade80":"var(--text-muted)",cursor:"pointer",width:32,height:32,borderRadius:7,padding:0,flexShrink:0,transition:"background 0.3s, color 0.3s, border-color 0.3s"},onMouseEnter:e=>{F||(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=>{F||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)")},title:"Refresh",children:F?(0,n.jsx)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"#4ade80",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 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"})]})})]})]}),(0,n.jsxs)("div",{ref:R,style:{position:"relative"},children:[(0,n.jsx)("button",{onClick:()=>C(e=>!e),style:{width:"100%",display:"flex",alignItems:"center",padding:"6px 10px",background:b?"var(--bg-hover)":"rgba(37,99,235,0.06)",border:b?"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)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)",fontSize:11,color:b?"var(--text)":"var(--text-dim)"},title:b??"",children:b?U(b,k):i&&!G.current?"":"Select project…"})}),S&&(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:[et.map(e=>(0,n.jsxs)("button",{onClick:()=>{j(e),L(!1),I(""),C(!1)},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:e===b?"var(--bg-selected)":"none",border:"none",borderBottom:"1px solid var(--border)",color:e===b?"var(--text)":"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:e,children:[e===b&&(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"})}),e!==b&&(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:U(e,k)})]},e)),!z&&(0,n.jsxs)("button",{onClick:e=>{e.stopPropagation(),Q()},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",borderTop:et.length>0?"1px solid var(--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"})]}),z?(0,n.jsxs)("div",{style:{padding:"6px 8px",borderTop:et.length>0?"none":void 0},children:[(0,n.jsx)("input",{ref:M,value:T,onChange:e=>I(e.target.value),onKeyDown:e=>{"Enter"===e.key&&X(),"Escape"===e.key&&(L(!1),I(""))},placeholder:"/path/to/project",style:{width:"100%",fontSize:11,fontFamily:"var(--font-mono)",padding:"5px 8px",border:"1px solid var(--accent)",borderRadius:5,outline:"none",background:"var(--bg)",color:"var(--text)",boxSizing:"border-box"}}),(0,n.jsxs)("div",{style:{display:"flex",gap:5,marginTop:5},children:[(0,n.jsx)("button",{onClick:X,style:{flex:1,padding:"4px 0",background:"var(--accent)",border:"none",borderRadius:5,color:"#fff",fontSize:11,fontWeight:600,cursor:"pointer"},children:"Open"}),(0,n.jsx)("button",{onClick:()=>{L(!1),I("")},style:{flex:1,padding:"4px 0",background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-muted)",fontSize:11,cursor:"pointer"},children:"Cancel"})]})]}):(0,n.jsxs)("button",{onClick:e=>{e.stopPropagation(),L(!0),setTimeout(()=>M.current?.focus(),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",style:{flexShrink:0},children:[(0,n.jsx)("line",{x1:"5",y1:"1",x2:"5",y2:"9"}),(0,n.jsx)("line",{x1:"1",y1:"5",x2:"9",y2:"5"})]}),(0,n.jsx)("span",{children:"Custom path…"})]})]})]})]}),(0,n.jsxs)("div",{style:{flex:W&&(d||b)?"1 1 0":"1 1 auto",overflowY:"auto",padding:"0",minHeight:80},children:[f&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Loading..."}),v&&(0,n.jsx)("div",{style:{padding:"12px 14px",color:"#f87171",fontSize:12},children:v}),!f&&!v&&0===er.length&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"No sessions found"}),en.map(r=>(0,n.jsx)(q,{node:r,selectedSessionId:e,onSelectSession:t,onRenamed:J,onSessionDeleted:e=>{a?.(e),J()},depth:0},r.session.id))]}),(d||b)&&(0,n.jsxs)("div",{style:{borderTop:"1px solid var(--border)",display:"flex",flexDirection:"column",flex:W?"1 1 0":"0 0 auto",minHeight:0,overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",flexShrink:0},children:[(0,n.jsxs)("button",{onClick:()=>E(e=>!e),style:{display:"flex",alignItems:"center",gap:6,flex:1,padding:"6px 10px",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:W?"rotate(90deg)":"none",transition:"transform 0.15s",flexShrink:0},children:(0,n.jsx)("polyline",{points:"3 2 7 5 3 8"})}),"Explorer"]}),(0,n.jsx)("button",{onClick:()=>{$(e=>e+1),D(!0),V.current&&clearTimeout(V.current),V.current=setTimeout(()=>D(!1),2e3)},title:"Refresh explorer",style:{display:"flex",alignItems:"center",justifyContent:"center",width:26,height:26,padding:0,marginRight:6,background:A?"rgba(74,222,128,0.18)":"none",border:"none",color:A?"#4ade80":"var(--text-dim)",cursor:"pointer",borderRadius:5,flexShrink:0,transition:"color 0.3s, background 0.3s"},onMouseEnter:e=>{A||(e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{A||(e.currentTarget.style.color="var(--text-dim)",e.currentTarget.style.background="none")},children:A?(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"#4ade80",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 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"})]})})]}),W&&(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",overflowX:"hidden"},children:(0,n.jsx)(H,{cwd:d??b,onOpenFile:u??(()=>{}),refreshKey:B,onAtMention:h})}),(0,n.jsx)(N,{cwd:d??b??null,onOpenFile:(e,t)=>(u??(()=>{}))(e,t)})]})]})}function q({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)(J,{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)(q,{node:e,selectedSessionId:t,onSelectSession:r,onRenamed:i,onSessionDeleted:l,depth:s+1},e.session.id))})]})}function J({session:e,isSelected:t,onClick:r,onRenamed:i,onDeleted:l,depth:s=0,hasChildren:a=!1,collapsed:d=!1,onToggleCollapse:c}){let u,p,h,x,g,[f,m]=(0,o.useState)(!1),[v,y]=(0,o.useState)(!1),[b,j]=(0,o.useState)(""),[k,w]=(0,o.useState)(!1),[S,C]=(0,o.useState)(!1),z=(0,o.useRef)(null),L=e.name||e.firstMessage.slice(0,50)||e.id.slice(0,12),T=(0,o.useCallback)(t=>{t.stopPropagation(),j(e.name??""),y(!0),setTimeout(()=>z.current?.select(),0)},[e.name]),I=(0,o.useCallback)(async()=>{let t=b.trim();if(y(!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{}},[b,e.id,e.name,i]),M=(0,o.useCallback)(e=>{e.stopPropagation(),w(!0)},[]),R=(0,o.useCallback)(async t=>{t.stopPropagation(),w(!1),C(!0);try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"DELETE"}),l?.(e.id)}catch{C(!1)}},[e.id,l]),W=(0,o.useCallback)(e=>{e.stopPropagation(),w(!1)},[]);return(0,n.jsx)("div",{onClick:k||v?void 0:r,onMouseEnter:()=>m(!0),onMouseLeave:()=>{m(!1)},style:{height:54,display:"flex",alignItems:"center",paddingLeft:s>0?12*s+14:14,paddingRight:8,cursor:k||v?"default":"pointer",background:k?"rgba(239,68,68,0.06)":t?"var(--bg-selected)":f?"var(--bg-hover)":"transparent",borderLeft:k?"2px solid #ef4444":t?"2px solid var(--accent)":"2px solid transparent",transition:"background 0.1s",opacity:S?.5:1,gap:6,overflow:"hidden"},children:k?(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:["“",L.slice(0,22),L.length>22?"…":"","”"]}),"?"]}),(0,n.jsxs)("div",{style:{display:"flex",gap:5,flexShrink:0},children:[(0,n.jsxs)("button",{onClick:R,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:W,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"})]})]}):v?(0,n.jsx)("input",{ref:z,value:b,onChange:e=>j(e.target.value),onBlur:I,onKeyDown:e=>{"Enter"===e.key&&I(),"Escape"===e.key&&y(!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:L,children:L}),(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:(u=new Date(e.modified),h=Math.floor((p=new Date().getTime()-u.getTime())/6e4),x=Math.floor(p/36e5),g=Math.floor(p/864e5),h<1?"just now":h<60?`${h}m ago`:x<24?`${x}h ago`:g<7?`${g}d ago`:u.toLocaleDateString())}),(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"})})}),f&&(0,n.jsxs)("div",{style:{display:"flex",gap:4,flexShrink:0},children:[(0,n.jsx)("button",{onClick:T,title:"Rename",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",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:M,title:"Delete",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.08)",e.currentTarget.style.color="#ef4444",e.currentTarget.style.borderColor="rgba(239,68,68,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,n.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,n.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,n.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]})})]})]})})}var Z=r(3143),G=r(2957),X=r(9893),Q=r(7644);let ee=new Set;function et(e){return ee.add(e),()=>{ee.delete(e)}}function er(){return"u"<typeof document?"light":document.documentElement.classList.contains("dark")?"dark":"light"}function en(){return"light"}function eo(){let e=(0,o.useSyncExternalStore)(et,er,en);return{theme:e,toggleTheme:(0,o.useCallback)(e=>{let t="dark"===er()?"light":"dark",r=()=>{"dark"===t?document.documentElement.classList.add("dark"):document.documentElement.classList.remove("dark");try{localStorage.setItem("pi-theme",t)}catch{}ee.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 ei(e){return/^\s*<(!DOCTYPE|html)/i.test(e)?e:`<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"></head>
|
|
4
|
+
<body style="margin:0;padding:8px;font-family:system-ui,sans-serif">
|
|
5
|
+
${e}
|
|
6
|
+
</body>
|
|
7
|
+
</html>`}function el({code:e,isStreaming:t,title:r}){let i=(0,o.useRef)(null),l=(0,o.useRef)(null),s=(0,o.useRef)(""),[a,d]=(0,o.useState)(!1),[c,u]=(0,o.useState)(120),[p,h]=(0,o.useState)(!1),x=(0,o.useRef)(!1),g=(0,o.useRef)(""),f=(0,o.useRef)(`<!DOCTYPE html>
|
|
8
|
+
<html>
|
|
9
|
+
<head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
10
|
+
<style>
|
|
11
|
+
:root { color-scheme: light dark; }
|
|
12
|
+
body { margin:0; padding:8px; font-family:system-ui,sans-serif; }
|
|
13
|
+
</style>
|
|
14
|
+
</head>
|
|
15
|
+
<body>
|
|
16
|
+
<script>
|
|
17
|
+
(function() {
|
|
18
|
+
var ready = false;
|
|
19
|
+
function notifyReady() {
|
|
20
|
+
if (ready) return;
|
|
21
|
+
ready = true;
|
|
22
|
+
parent.postMessage({ type: "widget:ready" }, "*");
|
|
23
|
+
}
|
|
24
|
+
function reportHeight() {
|
|
25
|
+
var h = Math.max(
|
|
26
|
+
document.documentElement.scrollHeight,
|
|
27
|
+
document.body.scrollHeight,
|
|
28
|
+
document.documentElement.offsetHeight,
|
|
29
|
+
document.body.offsetHeight
|
|
30
|
+
);
|
|
31
|
+
parent.postMessage({ type: "widget:resize", height: h }, "*");
|
|
32
|
+
}
|
|
33
|
+
function handleUpdate(html) {
|
|
34
|
+
document.body.innerHTML = html;
|
|
35
|
+
// Run inline scripts (they're already sanitized)
|
|
36
|
+
var scripts = document.body.querySelectorAll("script");
|
|
37
|
+
scripts.forEach(function(s) {
|
|
38
|
+
try {
|
|
39
|
+
var ns = document.createElement("script");
|
|
40
|
+
ns.textContent = s.textContent;
|
|
41
|
+
Array.from(s.attributes).forEach(function(a) { ns.setAttribute(a.name, a.value); });
|
|
42
|
+
s.parentNode.replaceChild(ns, s);
|
|
43
|
+
} catch(e) {}
|
|
44
|
+
});
|
|
45
|
+
requestAnimationFrame(reportHeight);
|
|
46
|
+
}
|
|
47
|
+
function handleFinalize(html) {
|
|
48
|
+
document.open();
|
|
49
|
+
document.write(html);
|
|
50
|
+
document.close();
|
|
51
|
+
requestAnimationFrame(function() {
|
|
52
|
+
reportHeight();
|
|
53
|
+
setTimeout(reportHeight, 300);
|
|
54
|
+
setTimeout(reportHeight, 1000);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function handleTheme(vars) {
|
|
58
|
+
Object.entries(vars || {}).forEach(function(_a) {
|
|
59
|
+
var key = _a[0], val = _a[1];
|
|
60
|
+
document.documentElement.style.setProperty(key, val);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
var ro = new ResizeObserver(function() { reportHeight(); });
|
|
65
|
+
ro.observe(document.body);
|
|
66
|
+
|
|
67
|
+
window.addEventListener("message", function(e) {
|
|
68
|
+
if (!e.data || typeof e.data.type !== "string") return;
|
|
69
|
+
switch (e.data.type) {
|
|
70
|
+
case "widget:update": handleUpdate(e.data.html || ""); break;
|
|
71
|
+
case "widget:finalize": handleFinalize(e.data.html || ""); break;
|
|
72
|
+
case "widget:theme": handleTheme(e.data.vars); break;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
window.addEventListener("load", notifyReady);
|
|
77
|
+
notifyReady();
|
|
78
|
+
})();
|
|
79
|
+
</script>
|
|
80
|
+
</body>
|
|
81
|
+
</html>`);(0,o.useEffect)(()=>{function e(e){if(e.data&&"string"==typeof e.data.type&&(!i.current||e.source===i.current.contentWindow))switch(e.data.type){case"widget:ready":d(!0);break;case"widget:resize":"number"==typeof e.data.height&&e.data.height>0&&u(Math.min(e.data.height+6,1200))}}return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[]);let m=(0,o.useCallback)(e=>{let t=i.current;t?.contentWindow&&e!==s.current&&(s.current=e,t.contentWindow.postMessage({type:"widget:update",html:e},"*"))},[]);return(0,o.useEffect)(()=>{if(!t||!a)return;let r=ei(e.replace(/<script\b[\s\S]*?<\/script>/gi,"").replace(/<script\b[\s\S]*$/gi,""));return l.current&&clearTimeout(l.current),l.current=setTimeout(()=>m(r),150),()=>{l.current&&clearTimeout(l.current)}},[e,t,a,m]),(0,o.useEffect)(()=>{if(t||!a||g.current===e)return;let r=ei(e),n=i.current;n?.contentWindow&&(g.current=e,x.current=!0,s.current=r,n.contentWindow.postMessage({type:"widget:finalize",html:r},"*"))},[t,a,e]),(0,n.jsxs)("div",{style:{position:"relative",marginTop:4,marginBottom:4},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"4px 10px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderBottom:"none",borderRadius:"6px 6px 0 0",fontSize:11,color:"var(--text-dim)"},children:[(0,n.jsx)("span",{children:"\uD83D\uDCCA"}),(0,n.jsx)("span",{style:{fontWeight:600},children:r||"Widget"}),t&&(0,n.jsx)("span",{style:{marginLeft:"auto",fontSize:10,color:"var(--accent)",animation:"pulse 1.5s infinite"},children:"streaming…"}),(0,n.jsx)("button",{onClick:()=>h(e=>!e),style:{marginLeft:"auto",padding:"1px 6px",fontSize:10,background:"var(--bg-hover)",color:"var(--text-dim)",border:"1px solid var(--border)",borderRadius:3,cursor:"pointer"},children:p?"Preview":"Code"})]}),p&&(0,n.jsx)("pre",{style:{margin:0,padding:"8px 10px",fontSize:11,fontFamily:"var(--font-mono)",color:"var(--text-muted)",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:"0 0 6px 6px",overflow:"auto",maxHeight:400,whiteSpace:"pre-wrap"},children:e}),!p&&(0,n.jsx)("iframe",{ref:i,sandbox:"allow-scripts",srcDoc:f.current,title:r||"Widget",onLoad:()=>d(!0),style:{width:"100%",height:c,border:"1px solid var(--border)",borderRadius:"0 0 6px 6px",display:"block",overflow:"hidden"}})]})}function es(e){if(!e)return null;let t=new Date(e),r=new Date,n=t.getFullYear()===r.getFullYear()&&t.getMonth()===r.getMonth()&&t.getDate()===r.getDate(),o=t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});if(n)return o;let i=t.toLocaleDateString([],{month:"short",day:"numeric",year:t.getFullYear()!==r.getFullYear()?"numeric":void 0});return`${i} ${o}`}function ea(e){if(navigator.clipboard?.writeText)return navigator.clipboard.writeText(e);try{let t=document.createElement("textarea");return t.value=e,t.style.position="fixed",t.style.opacity="0",document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t),Promise.resolve()}catch{return Promise.reject()}}function ed({message:e,isStreaming:t,toolResults:r,modelNames:o,entryId:i,onFork:l,forking:s,onNavigate:a,prevAssistantEntryId:d,onEditContent:c,showTimestamp:u,prevTimestamp:p}){return"user"===e.role?(0,n.jsx)(ec,{message:e,entryId:i,onFork:l,forking:s,onNavigate:a,prevAssistantEntryId:d,onEditContent:c}):"assistant"===e.role?(0,n.jsx)(eu,{message:e,isStreaming:t,toolResults:r,modelNames:o,showTimestamp:u,prevTimestamp:p}):"toolResult"===e.role?null:"custom"===e.role?(0,n.jsx)(ey,{message:e,showTimestamp:u}):null}function ec({message:e,entryId:t,onFork:r,forking:i,onNavigate:l,prevAssistantEntryId:s,onEditContent:a}){let[d,c]=(0,o.useState)(!1),[u,p]=(0,o.useState)(!1),h="string"==typeof e.content?e.content:e.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n"),x="string"==typeof e.content?[]:e.content.filter(e=>"image"===e.type),g=es(e.timestamp),f=!!t&&!!r,m=!!s&&!!l;return(0,n.jsxs)("div",{style:{marginBottom:16,display:"flex",flexDirection:"column",alignItems:"flex-end"},onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),children:[(0,n.jsx)("div",{style:{display:"flex",alignItems:"flex-end",gap:6,maxWidth:"85%"},children:(0,n.jsxs)("div",{style:{flex:1,minWidth:0,background:"var(--user-bg)",border:"1px solid rgba(59,130,246,0.2)",borderRadius:12,padding:"8px 12px",fontSize:14,lineHeight:1.6,color:"var(--text)",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:[x.length>0&&(0,n.jsx)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginBottom:8*!!h},children:x.map((e,t)=>{let r=e.source?"base64"===e.source.type?`data:${e.source.media_type};base64,${e.source.data}`:e.source.url??"":e.data?`data:${e.mimeType};base64,${e.data}`:"";return(0,n.jsx)("img",{src:r,alt:"",style:{maxWidth:240,maxHeight:240,borderRadius:6,objectFit:"contain",display:"block",border:"1px solid rgba(59,130,246,0.15)"}},t)})}),h]})}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:6,marginTop:3},children:[(0,n.jsx)("div",{style:{display:"flex",gap:3,opacity:+!!d,pointerEvents:d?"auto":"none",transition:"opacity 0.12s"},children:(0,n.jsxs)("button",{onClick:()=>{ea(h).then(()=>{p(!0),setTimeout(()=>p(!1),1500)})},title:"Copy message",style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",height:22,background:"none",border:"none",borderRadius:5,color:u?"var(--accent)":"var(--text-dim)",cursor:"pointer",fontSize:11,fontWeight:400,whiteSpace:"nowrap",transition:"color 0.12s"},onMouseEnter:e=>{u||(e.currentTarget.style.color="var(--accent)")},onMouseLeave:e=>{u||(e.currentTarget.style.color="var(--text-dim)")},children:[u?(0,n.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,n.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),u?"Copied":"Copy"]})}),(f||m)&&(0,n.jsxs)("div",{style:{display:"flex",gap:3,opacity:d||i?1:0,pointerEvents:d||i?"auto":"none",transition:"opacity 0.12s"},children:[m&&(0,n.jsxs)("button",{onClick:()=>{l(s),a?.(h)},title:"Edit from here — branches within this session",style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",height:22,background:"none",border:"none",borderRadius:5,color:"var(--text-dim)",cursor:"pointer",fontSize:11,fontWeight:400,whiteSpace:"nowrap",transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"15 10 20 15 15 20"}),(0,n.jsx)("path",{d:"M4 4v7a4 4 0 0 0 4 4h12"})]}),"Edit from here"]}),f&&(0,n.jsxs)("button",{onClick:()=>{r(t)},disabled:i,title:i?"Creating new session…":"New session — creates an independent copy from here",style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",height:22,background:"none",border:"none",borderRadius:5,color:i?"var(--accent)":"var(--text-dim)",cursor:i?"not-allowed":"pointer",fontSize:11,fontWeight:400,whiteSpace:"nowrap",transition:"color 0.12s"},onMouseEnter:e=>{i||(e.currentTarget.style.color="var(--accent)")},onMouseLeave:e=>{i||(e.currentTarget.style.color="var(--text-dim)")},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),i?"Creating…":"New session"]})]}),g&&(0,n.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)"},children:g})]})]})}function eu({message:e,isStreaming:t,toolResults:r,modelNames:i,showTimestamp:l,prevTimestamp:s}){var a;let d,c=l?es(e.timestamp):null,u=e.content??[],[p,h]=(0,o.useState)(!1),[x,g]=(0,o.useState)(!1),f=(0,o.useRef)(null),[m,v]=(0,o.useState)(null),y=(0,o.useRef)(u);y.current=u;let b=(0,o.useRef)(new Map),[j,k]=(0,o.useState)(new Map),w=(0,o.useMemo)(()=>{if(!e.timestamp||!s)return;let t=Math.round((e.timestamp-s)/1e3);return t>0?t:void 0},[e.timestamp,s]),S=(0,o.useMemo)(()=>{let t=new Map;if(!r||!e.timestamp)return t;for(let[n,o]of r)if(o.timestamp&&e.timestamp){let r=Math.round((o.timestamp-e.timestamp)/1e3);r>0&&t.set(n,r)}return t},[r,e.timestamp]),C=u.filter(e=>"text"===e.type).map(e=>e.text).join("\n");return(0,o.useEffect)(()=>{if(!t){let e=Date.now();k(t=>{let r=new Map(t);for(let[t,n]of b.current)r.has(t)||r.set(t,Math.round((e-n)/1e3));return r}),f.current=null,v(null);return}let e=setInterval(()=>{let e=y.current,t=Date.now();e.forEach((e,r)=>{b.current.has(r)||b.current.set(r,t)}),k(r=>{let n=!1,o=new Map(r);for(let r=0;r<e.length-1;r++)if(!o.has(r)&&b.current.has(r)){let e=b.current.get(r),i=b.current.get(r+1)??t;o.set(r,Math.round((i-e)/1e3)),n=!0}return n?o:r});let r=0;for(let t of e)"text"===t.type?r+=t.text?.length??0:"thinking"===t.type?r+=t.thinking?.length??0:"toolCall"===t.type&&(r+=JSON.stringify(t.input??{}).length);if(0===r)return;null===f.current&&(f.current=t);let n=(t-f.current)/1e3;n>.5&&v(r/4/n)},300);return()=>clearInterval(e)},[t]),(0,n.jsxs)("div",{style:{marginBottom:16},onMouseEnter:()=>h(!0),onMouseLeave:()=>h(!1),children:[(0,n.jsxs)("div",{style:{fontSize:11,color:"var(--text-dim)",marginBottom:4,display:"flex",alignItems:"center",gap:6},children:[e.provider&&(0,n.jsx)("span",{children:i?.[`${e.provider}:${e.model}`]??i?.[e.model]??e.model}),t&&(()=>{let e,t=0;for(let e of u)"text"===e.type?t+=e.text?.length??0:"thinking"===e.type?t+=e.thinking?.length??0:"toolCall"===e.type&&(t+=JSON.stringify(e.input??{}).length);let r=Math.round(t/4);return(0,n.jsx)(n.Fragment,{children:r>0&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4,color:"var(--text)"},title:"预估 token 数(流式接收中)",children:[(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:2,fontSize:11,fontWeight:400},children:[(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"5",y1:"1.5",x2:"5",y2:"8.5"}),(0,n.jsx)("polyline",{points:"2 6 5 8.5 8 6"})]}),r]}),null!==m&&(e=m>=50?"#53b3cb":m>=30?"#9bc53d":m>=15?"#f9c22e":"#e01a4f",(0,n.jsxs)("span",{style:{marginLeft:6,padding:"1px 6px",borderRadius:4,background:e,color:"#fff",fontSize:11,fontWeight:400},children:[m.toFixed(1)," t/s"]}))]})})})()]}),(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:u.map((e,o)=>(0,n.jsx)(ep,{block:e,toolResults:r,isStreaming:t,streamingDuration:j.get(o)??("thinking"===e.type?w:void 0),toolCallDurations:S},o))}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:4},children:[e.usage&&!t&&(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)"},children:(a=e.usage,d=[],a.input&&d.push(`${a.input.toLocaleString()} in`),a.output&&d.push(`${a.output.toLocaleString()} out`),a.cacheRead&&d.push(`${a.cacheRead.toLocaleString()} cache`),a.cost?.total&&d.push(`$${a.cost.total.toFixed(4)}`),d.join(" \xb7 "))}),C&&!t&&(0,n.jsxs)("button",{onClick:()=>{ea(C).then(()=>{g(!0),setTimeout(()=>g(!1),1500)})},title:"Copy message",style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",height:22,background:"none",border:"none",borderRadius:5,color:x?"var(--accent)":"var(--text-dim)",cursor:"pointer",fontSize:11,fontWeight:400,whiteSpace:"nowrap",opacity:+!!p,pointerEvents:p?"auto":"none",transition:"opacity 0.12s, color 0.12s"},onMouseEnter:e=>{x||(e.currentTarget.style.color="var(--accent)")},onMouseLeave:e=>{x||(e.currentTarget.style.color="var(--text-dim)")},children:[x?(0,n.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,n.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),x?"Copied":"Copy"]}),c&&!t&&(0,n.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)",marginLeft:"auto"},children:c})]})]})}function ep({block:e,toolResults:t,isStreaming:r,streamingDuration:o,toolCallDurations:i}){if("text"===e.type)return(0,n.jsx)(eh,{block:e,isStreaming:r});if("thinking"===e.type)return(0,n.jsx)(eg,{block:e,duration:o});if("toolCall"===e.type){let o=t?.get(e.toolCallId),l=i?.get(e.toolCallId);return(0,n.jsx)(ef,{block:e,result:o,isRunning:r&&!o,duration:l})}return null}function eh({block:e,isStreaming:t}){let r=function(e){let t,r=[],n=/```show-widget\s*\n([\s\S]*?)```/g,o=0;for(;null!==(t=n.exec(e));){let n=e.slice(o,t.index).trim();n&&r.push({type:"text",content:n});let i=function(e){if(e.startsWith("{")&&e.endsWith("}"))try{let t=JSON.parse(e);if(t.widget_code)return{title:t.title,code:t.widget_code}}catch{}return/<(!DOCTYPE|html|svg|canvas|script|style|div)/i.test(e)?{code:e}:null}(t[1].trim());i?r.push({type:"widget",title:i.title,code:i.code}):r.push({type:"text",content:t[0]}),o=t.index+t[0].length}let i=e.slice(o).trim();return i&&r.push({type:"text",content:i}),0===r.length&&e.trim()&&r.push({type:"text",content:e}),r}(e.text);return r.some(e=>"widget"===e.type)?(0,n.jsx)(n.Fragment,{children:r.map((e,r)=>"text"===e.type?(0,n.jsx)(ex,{text:e.content},r):(0,n.jsx)(el,{code:e.code,isStreaming:!!t,title:e.title},r))}):(0,n.jsx)(ex,{text:e.text})}function ex({text:e}){return(0,n.jsx)("div",{className:"markdown-body",children:(0,n.jsx)(Z.oz,{remarkPlugins:[G.A],components:{code({className:e,children:t,...r}){let o=e?.replace("language-","")??"",i=String(t);return e?.includes("language-")||i.includes("\n")?(0,n.jsx)(ev,{code:i.replace(/\n$/,""),lang:o}):(0,n.jsx)("code",{style:{background:"var(--bg-selected)",padding:"1px 4px",borderRadius:3,fontFamily:"var(--font-mono)",fontSize:"0.9em"},...r,children:t})},pre:({children:e})=>(0,n.jsx)(n.Fragment,{children:e})},children:e})})}function eg({block:e,duration:t}){let[r,i]=(0,o.useState)(!1);return(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:6,overflow:"hidden",fontSize:13},children:[(0,n.jsxs)("button",{onClick:()=>i(e=>!e),style:{display:"flex",alignItems:"center",gap:6,width:"100%",padding:"6px 10px",background:"var(--bg-panel)",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left"},children:[(0,n.jsx)("span",{children:"Thinking"}),void 0!==t&&(0,n.jsxs)("span",{style:{marginLeft:"auto",fontSize:11,color:"var(--text-dim)",fontVariantNumeric:"tabular-nums"},children:[t,"s"]})]}),r&&(0,n.jsx)("div",{style:{padding:"8px 10px",color:"var(--text-muted)",fontSize:12,lineHeight:1.6,whiteSpace:"pre-wrap",background:"var(--bg-panel)",borderTop:"1px solid var(--border)"},children:e.thinking})]})}function ef({block:e,result:t,isRunning:r,duration:i}){let[l,s]=(0,o.useState)(!1),a=JSON.stringify(e.input,null,2),d=t?t.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n"):null,c=null!==d&&("(no output)"===d.trim()||""===d.trim()),u=t?.isError??!1;return(0,n.jsxs)("div",{style:{borderRadius:7,overflow:"hidden",fontSize:12,border:u?"1px solid rgba(248,113,113,0.45)":"1px solid rgba(34,197,94,0.25)",background:u?"rgba(248,113,113,0.05)":"rgba(34,197,94,0.04)"},children:[(0,n.jsxs)("button",{onClick:()=>s(e=>!e),style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"6px 10px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left",minWidth:0},children:[(0,n.jsx)("span",{style:{color:u?"#f87171":"#16a34a",fontFamily:"var(--font-mono)",fontWeight:600,fontSize:11,flexShrink:0},children:e.toolName}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,minWidth:0},children:function(e){let t=e.input;if(!t||"object"!=typeof t)return"";let r=Object.keys(t);return 0===r.length?"":"command"in t?String(t.command).slice(0,120):"path"in t?String(t.path).slice(0,120):"file_path"in t?String(t.file_path).slice(0,120):"pattern"in t?String(t.pattern).slice(0,120):"query"in t?String(t.query).slice(0,120):String(t[r[0]]).slice(0,120)}(e)}),void 0!==i&&(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-dim)",flexShrink:0,fontVariantNumeric:"tabular-nums"},children:[i,"s"]}),(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:l?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),l&&(0,n.jsx)("pre",{style:{margin:0,padding:"8px 10px",color:"var(--text-muted)",fontSize:12,lineHeight:1.5,overflow:"auto",background:"var(--bg-subtle)",borderTop:u?"1px solid rgba(248,113,113,0.25)":"1px solid rgba(34,197,94,0.2)",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:a}),l&&t&&(0,n.jsx)(em,{text:d??"",isEmpty:c,isError:u})]})}function em({text:e,isEmpty:t,isError:r}){return(0,n.jsx)("div",{style:{borderTop:`1px solid ${r?"rgba(248,113,113,0.3)":"rgba(34,197,94,0.15)"}`,background:r?"rgba(248,113,113,0.04)":"var(--bg-subtle)"},children:(0,n.jsx)("pre",{style:{margin:0,padding:"8px 10px",color:r?"#f87171":t?"var(--text-dim)":"var(--text-muted)",fontSize:12,lineHeight:1.5,overflow:"auto",maxHeight:400,background:"var(--bg)",whiteSpace:"pre-wrap",wordBreak:"break-all",fontStyle:t?"italic":"normal",opacity:t?.6:1},children:t?"(no output)":e})})}function ev({code:e,lang:t}){let{isDark:r}=eo(),[i,l]=(0,o.useState)(!1);return(0,n.jsxs)("div",{style:{position:"relative",marginTop:4,marginBottom:4,borderRadius:6,overflow:"hidden",border:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{style:{padding:"3px 10px",background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[(0,n.jsx)("span",{children:t}),(0,n.jsx)("button",{onClick:()=>{ea(e).then(()=>{l(!0),setTimeout(()=>l(!1),1500)})},style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:11},children:i?"copied":"copy"})]}),(0,n.jsx)(X.A,{language:t||"text",style:r?Q.xJ:Q.vs,showLineNumbers:!0,lineNumberStyle:{color:"var(--text-dim)",fontStyle:"normal"},customStyle:{margin:0,padding:"10px 12px",fontSize:12.5,lineHeight:1.6,borderRadius:0,background:"var(--bg)"},codeTagProps:{style:{fontFamily:"var(--font-mono)"}},children:e})]})}function ey({message:e,showTimestamp:t}){if(!e.display)return null;let r=t?es(e.timestamp):null,o="string"==typeof e.content?e.content:e.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n"),i="subagent-notify"===e.customType,l=o.match(/^Background task (completed|failed|paused):\s*\*\*(.+?)\*\*/),s=l?"completed"===l[1]?"✅":"failed"===l[1]?"❌":"⏸":i?"\uD83E\uDD16":"ℹ";return(0,n.jsxs)("div",{style:{marginBottom:12},children:[(0,n.jsx)("div",{style:{padding:"8px 14px",borderRadius:8,border:`1px solid ${i?"rgba(99,102,241,0.25)":"var(--border)"}`,background:i?"rgba(99,102,241,0.05)":"var(--bg-panel)",fontSize:13,lineHeight:1.6,color:"var(--text-muted)"},children:(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[(0,n.jsx)("span",{style:{flexShrink:0,fontSize:14},children:s}),(0,n.jsx)("div",{style:{flex:1,minWidth:0},children:(0,n.jsx)("div",{className:"markdown-body",style:{fontSize:13},children:(0,n.jsx)(Z.oz,{remarkPlugins:[G.A],children:o})})})]})}),(r||l)&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:6,marginTop:3},children:[l&&(0,n.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)"},children:l[2]}),r&&(0,n.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)"},children:r})]})]})}let eb=["off","default","full"],ej={off:"none",default:"default",full:"full"},ek=["auto","off","minimal","low","medium","high","xhigh"],ew={auto:"沿用 pi 默认设置",off:"关闭推理",minimal:"最少推理",low:"低强度推理",medium:"中等推理",high:"高强度推理",xhigh:"最高强度推理"};function eS({doc:e,onRemove:t}){var r;let o=e.fileName.split(".").pop()?.toLowerCase()??"",i=function(e){switch(e){case"pdf":return{emoji:"\uD83D\uDCC4",color:"#ef4444"};case"docx":case"doc":return{emoji:"\uD83D\uDCDD",color:"#3b82f6"};case"xlsx":case"xls":return{emoji:"\uD83D\uDCCA",color:"#22c55e"};case"pptx":case"ppt":return{emoji:"\uD83D\uDCFD",color:"#f97316"};default:return{emoji:"\uD83D\uDCCE",color:"var(--text-muted)"}}}(o),l=(r=e.size)<1024?`${r} B`:r<1048576?`${(r/1024).toFixed(1)} KB`:`${(r/1048576).toFixed(1)} MB`;return(0,n.jsxs)("div",{style:{position:"relative",display:"flex",alignItems:"center",gap:6,padding:"5px 10px 5px 7px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,maxWidth:200},title:e.fileName,children:[(0,n.jsx)("span",{style:{color:i.color,fontSize:14,flexShrink:0},children:i.emoji}),(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",lineHeight:1.3},children:e.fileName}),(0,n.jsxs)("div",{style:{fontSize:10,color:"var(--text-dim)",lineHeight:1.3},children:[o.toUpperCase()," \xb7 ",l]})]}),(0,n.jsx)("button",{onClick:t,style:{flexShrink:0,width:14,height:14,borderRadius:"50%",background:"var(--bg-hover)",border:"none",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,color:"var(--text-dim)"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)"},children:(0,n.jsxs)("svg",{width:"7",height:"7",viewBox:"0 0 7 7",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"1",y1:"1",x2:"6",y2:"6"}),(0,n.jsx)("line",{x1:"6",y1:"1",x2:"1",y2:"6"})]})})]})}let eC=(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:m,onThinkingLevelChange:v,availableThinkingLevels:y,thinkingLevelMap:b,retryInfo:j,soundEnabled:k,onSoundToggle:w},S){let C,z,L,[T,I]=(0,o.useState)(""),[M,R]=(0,o.useState)(!1),[W,E]=(0,o.useState)(null),[B,$]=(0,o.useState)(!1),[F,P]=(0,o.useState)(!1),[A,D]=(0,o.useState)([]),[H,N]=(0,o.useState)([]),O=(0,o.useRef)(null),_=(0,o.useRef)(null),U=(0,o.useRef)(null),V=(0,o.useRef)(null),K=(0,o.useRef)(null),Y=(0,o.useRef)(null),q=(0,o.useRef)(null);(0,o.useImperativeHandle)(S,()=>({insertIfEmpty(e){let t=O.current;(t?t.value:T).trim()||(I(e),requestAnimationFrame(()=>{t&&(t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)}))},insertText(e){let t=O.current;if(!t)return void I(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(" ")?" ":"";I(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){J(e)},addFiles(e){Z(e)}}));let J=(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)})));D(e=>[...e,...r])},[]),Z=(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&&J(t),r.length){let e=await Promise.all(r.map(e=>new Promise((t,r)=>{let n=new FileReader;n.onload=()=>{t({data:n.result,fileName:e.name,mimeType:e.type||"application/octet-stream",size:e.size})},n.onerror=r,n.readAsArrayBuffer(e)})));N(t=>[...t,...e])}},[J]),G=(0,o.useCallback)(e=>{D(t=>{let r=[...t];return URL.revokeObjectURL(r[e].previewUrl),r.splice(e,1),r})},[]),X=(0,o.useCallback)(e=>{N(t=>{let r=[...t];return r.splice(e,1),r})},[]),Q=(0,o.useCallback)(()=>{D(e=>(e.forEach(e=>URL.revokeObjectURL(e.previewUrl)),[])),N([])},[]),ee=(0,o.useCallback)(()=>{let t=T.trim();(t||A.length||H.length)&&!l&&(e(t,A.length?A:void 0,H.length?H:void 0),I(""),Q(),O.current&&(O.current.style.height="auto"))},[T,A,H,l,e,Q]),et=(0,o.useCallback)(e=>{let t=T.trim();if(!t&&!A.length&&!H.length)return;let n=A.length?A:void 0,o=H.length?H:void 0;"steer"===e&&r?r(t,n,o):"followup"===e&&i&&i(t,n,o),I(""),Q(),O.current&&(O.current.style.height="auto")},[T,A,H,r,i,Q]),er=(0,o.useCallback)(e=>{"Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),l&&(r||i)?et(r?"steer":"followup"):ee())},[l,r,i,et,ee]),en=(0,o.useCallback)(()=>{let e=O.current;e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[]),eo=(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(),Z(t.map(e=>e.getAsFile()).filter(e=>null!==e)))},[Z]),ei=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})),el=[];for(let e of ei){let t=el.find(t=>t.provider===e.provider);t?t.options.push(e):el.push({provider:e.provider,options:[e]})}let es=s?ei.find(e=>e.modelId===s.modelId&&e.provider===s.provider)?.name??s.modelId:ei.length>0?ei[0].name:null;return(0,o.useEffect)(()=>{let e=e=>{_.current&&!_.current.contains(e.target)&&U.current&&!U.current.contains(e.target)&&R(!1),V.current&&!V.current.contains(e.target)&&$(!1),K.current&&!K.current.contains(e.target)&&P(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,n.jsxs)("div",{style:{flexShrink:0,background:"transparent",padding:"0 16px 8px",paddingRight:52},children:[(0,n.jsx)("input",{ref:Y,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:e=>{J(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsx)("input",{ref:q,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=>{Z(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsxs)("div",{style:{maxWidth:820,margin:"0 auto"},children:[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]})]}),(A.length>0||H.length>0)&&(0,n.jsxs)("div",{style:{display:"flex",gap:6,marginBottom:6,flexWrap:"wrap",alignItems:"flex-end"},children:[A.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:()=>G(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}`)),H.map((e,t)=>(0,n.jsx)(eS,{doc:e,onRemove:()=>X(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:O,value:T,onChange:e=>I(e.target.value),onKeyDown:er,onInput:en,onPaste:eo,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:()=>et("steer"),disabled:!T.trim()&&!A.length&&!H.length,title:"打断 Agent 当前运行,立即注入消息",style:{display:"flex",alignItems:"center",gap:5,padding:"7px 12px",background:T.trim()||A.length||H.length?"rgba(234,179,8,0.12)":"none",border:"1px solid rgba(234,179,8,0.35)",borderRadius:8,color:T.trim()||A.length||H.length?"rgba(180,130,0,1)":"var(--text-dim)",cursor:T.trim()||A.length||H.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:()=>et("followup"),disabled:!T.trim()&&!A.length&&!H.length,title:"在 Agent 完成后排队发送",style:{display:"flex",alignItems:"center",gap:5,padding:"7px 12px",background:T.trim()||A.length||H.length?"rgba(129,140,248,0.12)":"none",border:"1px solid rgba(129,140,248,0.35)",borderRadius:8,color:T.trim()||A.length||H.length?"rgba(99,102,241,1)":"var(--text-dim)",cursor:T.trim()||A.length||H.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:ee,disabled:!T.trim()&&!A.length&&!H.length,style:{flexShrink:0,alignSelf:"flex-end",display:"flex",alignItems:"center",gap:6,padding:"7px 14px",background:T.trim()||A.length||H.length?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:8,color:T.trim()||A.length||H.length?"#fff":"var(--text-dim)",cursor:T.trim()||A.length||H.length?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",boxShadow:T.trim()||A.length||H.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",{style:{marginTop:8,display:"flex",alignItems:"center",gap:6},children:[(0,n.jsxs)("div",{style:{flex:"0 0 auto",display:"flex",alignItems:"center",gap:2},children:[(0,n.jsx)("button",{onClick:()=>Y.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:A.length||H.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=A.length||H.length?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=A.length||H.length?"var(--accent)":"var(--text-muted)"},onContextMenu:e=>{e.preventDefault(),q.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"})})}),ei.length>0&&es&&c&&(0,n.jsxs)("div",{ref:_,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:e=>{let t=e.currentTarget.getBoundingClientRect();E({top:t.top,left:t.left,width:t.width}),R(e=>!e)},disabled:l,style:{display:"flex",alignItems:"center",gap:6,padding:"8px 12px",height:32,maxWidth:220,overflow:"hidden",background:M?"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=M?"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:es})]}),M&&W&&(z=(C=window.visualViewport?.height??window.innerHeight)-W.top+6,L=Math.max(120,Math.min(W.top-8,.6*C)),(0,n.jsx)("div",{ref:U,style:{position:"fixed",bottom:z,left:W.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:W.width,maxHeight:L,overflowY:"auto"},children:el.map((e,t)=>(0,n.jsxs)("div",{children:[el.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:()=>{R(!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",{style:{flex:1}}),(0,n.jsxs)("div",{style:{flex:"0 0 auto",display:"flex",alignItems:"center",gap:2,marginLeft:"auto"},children:[!l&&v&&(0,n.jsxs)("div",{ref:K,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>!l&&P(e=>!e),disabled:l,title:"切换推理强度",style:{display:"flex",alignItems:"center",gap:5,padding:"8px 12px",height:32,background:F?"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=F?"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=m??"auto";if("auto"===e||!b)return e;let t=b[e];return null!=t?t:e})()})]}),F&&(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:ek.filter(e=>!y||"auto"===e||y.includes(e)).map(e=>{let t=(m??"auto")===e,r=ew[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:()=>{P(!1),t||v(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:V,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>!l&&$(e=>!e),disabled:l,title:"切换工具预设",style:{display:"flex",alignItems:"center",gap:5,padding:"8px 12px",height:32,background:B?"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=B?"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(ej).find(([,e])=>e===(g??"default"))?.[0]??"default"})]}),B&&(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:eb.map(e=>{let t=ej[e],r=(g??"default")===t,o="off"===e?"无工具,纯聊天":"default"===e?"4 项内置工具":"全部内置工具";return(0,n.jsxs)("button",{onClick:()=>{$(!1),r||f(t)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:r?"var(--bg-selected)":"none",border:"none",color:r?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left",fontWeight:r?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{r||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{r||(e.currentTarget.style.background="none")},children:[r?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1},children:e}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:o})]},e)})})]}),!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 ez(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 eL({messages:e,streamingMessage:t,scrollContainer:r,messageRefs:i}){let[l,s]=(0,o.useState)(0),[a,d]=(0,o.useState)(1),[c,u]=(0,o.useState)(!1),[p,h]=(0,o.useState)([]),[x,g]=(0,o.useState)(!1),[f,m]=(0,o.useState)(null),v=(0,o.useRef)(!1),y=(0,o.useRef)(null),b=(0,o.useMemo)(()=>t?[...e,t]:e,[e,t]),j=(0,o.useRef)(b);j.current=b;let k=(0,o.useRef)(null);k.current=()=>{let e=r.current;if(!e)return;let t=e.scrollHeight,n=e.clientHeight,o=t-n;u(o>20),o<=0?(s(0),d(1)):(s(e.scrollTop/o),d(n/t));let l=i.current,a=[],c=0,p=j.current;for(let r=0;r<p.length;r++){let n=p[r];if("user"!==n.role&&"assistant"!==n.role)continue;let o=l?.[c];if(c++,("user"===n.role||"assistant"===n.role&&(n.content??[]).some(e=>"text"===e.type))&&o&&t>0){let r=o.getBoundingClientRect(),i=e.getBoundingClientRect(),l=r.top-i.top+e.scrollTop,s=r.height;a.push({topRatio:l/t,heightRatio:s/t,msg:n,index:a.length})}}h(a)};let w=(0,o.useCallback)(()=>k.current(),[]);(0,o.useEffect)(()=>{let e=r.current;if(!e)return;e.addEventListener("scroll",w,{passive:!0});let t=new ResizeObserver(w);return t.observe(e),e.firstElementChild&&t.observe(e.firstElementChild),w(),()=>{e.removeEventListener("scroll",w),t.disconnect()}},[r,w]),(0,o.useEffect)(()=>{let e=setTimeout(w,50);return()=>clearTimeout(e)},[e.length,w]);let S=(0,o.useCallback)(e=>{let t=r.current;if(!t)return;let n=t.scrollHeight-t.clientHeight;n<=0||(t.scrollTop=Math.max(0,Math.min(1-a,e))/(1-a)*n)},[r,a]),C=(0,o.useCallback)(e=>{if(!c)return;v.current=!0;let t=e.currentTarget.getBoundingClientRect(),r=(e.clientY-t.top)/t.height,n=r-l*(1-a),o=n>=0&&n<=a?n:a/2;S(r-o);let i=e=>{v.current&&S((e.clientY-t.top)/t.height-o)},s=()=>{v.current=!1,window.removeEventListener("mousemove",i),window.removeEventListener("mouseup",s)};window.addEventListener("mousemove",i),window.addEventListener("mouseup",s)},[c,a,l,S]),z=y.current?.clientHeight??600,L=(0,o.useMemo)(()=>{if(!x||0===p.length)return[];let e=p.map(e=>Math.round(e.topRatio*z-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(z-22,e[t]));return e},[x,p,z]);if(!c)return null;let T=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),m(null)},onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();m((e.clientY-t.top)/t.height)},style:{width:36,flexShrink:0,position:"relative",cursor:"default",userSelect:"none",borderLeft:"1px solid var(--border)",background:"var(--bg-panel)",overflow:"visible"},children:[(0,n.jsx)("div",{style:{position:"absolute",left:0,right:0,top:`${T}%`,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=ez(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=ez(e.msg),i=M===e.index;return r&&0!==L.length?(0,n.jsx)("div",{style:{position:"absolute",top:L[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 eT({messages:e}){let t=(0,o.useMemo)(()=>(function(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:r.content.split("\n").slice(3).join("\n").trim()||void 0,timestamp:r.timestamp})}}if("assistant"===r.role){let e=r.content;if(!e)continue;for(let n of e)if("toolCall"===n.type&&"subagent"===n.toolName&&n.input){let e=n.input,o=e.agent??(e.chain?"chain":e.tasks?"parallel":e.action??"subagent"),i="string"==typeof e.task?e.task:void 0,l=n.toolCallId??`sub-${o}-${r.timestamp??Date.now()}`;t.set(l,{id:l,agent:o,status:"running",task:i,timestamp:r.timestamp})}}if("toolResult"===r.role&&r.toolCallId&&t.has(r.toolCallId)){let e=t.get(r.toolCallId);e.status=r.isError?"failed":"completed",e.summary=(r.content?.filter(e=>"text"===e.type).map(e=>e.text??"").join("\n")??"").slice(0,200)||void 0}}return Array.from(t.values()).sort((e,t)=>(t.timestamp??0)-(e.timestamp??0))})(e),[e]),r=t.filter(e=>"running"===e.status),i=t.filter(e=>"running"!==e.status);return 0===t.length?null:(0,n.jsxs)("div",{style:{height:"100%",overflow:"auto",padding:12},children:[r.length>0&&(0,n.jsxs)("div",{style:{marginBottom:16},children:[(0,n.jsxs)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-dim)",marginBottom:8,textTransform:"uppercase",letterSpacing:"0.05em"},children:["Active (",r.length,")"]}),r.map(e=>(0,n.jsxs)("div",{style:{padding:"8px 12px",borderRadius:6,border:"1px solid rgba(99,102,241,0.2)",background:"rgba(99,102,241,0.04)",marginBottom:6,fontSize:12},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,n.jsx)("span",{style:{width:8,height:8,borderRadius:"50%",background:"#818cf8",display:"inline-block",animation:"pulse 1.5s infinite",flexShrink:0}}),(0,n.jsx)("span",{style:{fontWeight:600,color:"var(--text)"},children:e.agent}),(0,n.jsx)("span",{style:{color:"var(--accent)",fontSize:10,fontWeight:600},children:"running"})]}),e.task&&(0,n.jsx)("div",{style:{marginTop:4,color:"var(--text-muted)",fontSize:11,lineHeight:1.4},children:e.task.length>120?e.task.slice(0,120)+"…":e.task})]},e.id))]}),i.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-dim)",marginBottom:8,textTransform:"uppercase",letterSpacing:"0.05em"},children:["Completed (",i.length,")"]}),i.map(e=>(0,n.jsxs)("div",{style:{padding:"6px 12px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg-panel)",marginBottom:4,fontSize:12},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,n.jsx)("span",{style:{fontSize:12,flexShrink:0},children:"completed"===e.status?"✅":"failed"===e.status?"❌":"⏸"}),(0,n.jsx)("span",{style:{fontWeight:600,color:"var(--text)"},children:e.agent}),(0,n.jsx)("span",{style:{color:"completed"===e.status?"#22c55e":"failed"===e.status?"#ef4444":"var(--text-dim)",fontSize:10,fontWeight:600},children:e.status})]}),e.summary&&(0,n.jsx)("div",{style:{marginTop:3,color:"var(--text-muted)",fontSize:11,lineHeight:1.4,maxHeight:60,overflow:"hidden"},children:e.summary})]},e.id))]})]})}function eI(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 eM(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}function eR(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}}let eW=["image/","application/pdf","application/vnd.openxmlformats-officedocument","application/msword","application/vnd.ms-"];function eE(e){return eW.some(t=>e.type.startsWith(t))}let eB=["ready when you are.","ask me anything.","let's build something cool.","explore your codebase.","draft an email.","summarize that paper.","plan your weekend.","explain it like I'm five.","pair-program with me.","fix that pesky bug.","translate to 中文.","write a haiku.","brainstorm ideas.","review my pull request.","what should we cook tonight?","ship it.","make it pretty.","rubber-duck with me."];function e$({phrases:e}){let[t,r]=(0,o.useState)(()=>Math.floor(Math.random()*e.length)),[i,l]=(0,o.useState)(""),[s,a]=(0,o.useState)(!1),[d,c]=(0,o.useState)(!0);return(0,o.useEffect)(()=>{let e=setInterval(()=>c(e=>!e),530);return()=>clearInterval(e)},[]),(0,o.useEffect)(()=>{let n,o=e[t];if(s||i!==o)if(s&&""===i)a(!1),r(t=>(t+1)%e.length);else{let e=s?o.slice(0,i.length-1):o.slice(0,i.length+1);n=setTimeout(()=>l(e),s?28:55)}else n=setTimeout(()=>a(!0),1800);return()=>clearTimeout(n)},[i,s,t,e]),(0,n.jsxs)("span",{style:{color:"var(--text-muted)",fontWeight:400},children:[i,(0,n.jsx)("span",{style:{opacity:+!!d,color:"var(--accent)",marginLeft:1},children:"▍"})]})}function eF({session:e,newSessionCwd:t,onAgentEnd:i,onSessionCreated:l,onSessionForked:s,modelsRefreshKey:a,chatInputRef:d,onBranchDataChange:c,onSystemPromptChange:u,onSessionStatsChange:p,onContextUsageChange:h}){var x;let g,{loading:f,error:m,messages:v,entryIds:y,streamState:b,agentRunning:j,modelNames:k,modelList:w,modelThinkingLevels:S,modelThinkingLevelMaps:C,toolPreset:z,thinkingLevel:L,retryInfo:T,contextUsage:I,forkingEntryId:M,isCompacting:R,compactError:W,displayModel:E,sessionStats:B,agentPhase:$,isNew:F,messagesEndRef:P,scrollContainerRef:A,lastUserMsgRef:D,handleSend:H,handleAbort:N,handleFork:O,handleNavigate:_,handleModelChange:U,handleCompact:V,handleSteer:K,handleFollowUp:Y,handleAbortCompaction:q,handleToolPresetChange:J,handleThinkingLevelChange:Z,handleAgentEventRef:G}=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,m]=(0,o.useState)(null),[v,y]=(0,o.useState)(null),[b,j]=(0,o.useState)([]),[k,w]=(0,o.useState)([]),[S,C]=(0,o.useReducer)(eR,{isStreaming:!1,streamingMessage:null}),[z,L]=(0,o.useState)(!1),[T,I]=(0,o.useState)({}),[M,R]=(0,o.useState)([]),[W,E]=(0,o.useState)({}),[B,$]=(0,o.useState)({}),[F,P]=(0,o.useState)(null),[A,D]=(0,o.useState)("default"),[H,N]=(0,o.useState)("auto"),[O,_]=(0,o.useState)(null),[U,V]=(0,o.useState)(null),[K,Y]=(0,o.useState)(null),[q,J]=(0,o.useState)(null),[Z,G]=(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=(0,o.useRef)(null),es=(0,o.useRef)(t?.id??null),ea=(0,o.useRef)(!1),ed=(0,o.useRef)(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)(null),eg=e.setNewSessionModel??P,ef=e.setToolPreset??D,em=Z??p?.context.model??X??null,ev=u?F:em,ey=(()=>{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})(),eb=(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(404===o.status)return t&&(h(null),y(null),j([]),m(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??[]),G(null),m(null),!i.agentState?.state?.thinkingLevel&&i.context.thinkingLevel&&"off"!==i.context.thinkingLevel&&N(i.context.thinkingLevel),i.agentState??null}catch(e){return m(String(e)),null}finally{t&&g(!1)}},[]),ej=(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??[])}catch(e){console.error("Failed to load context:",e)}},[]),ek=(0,o.useCallback)(async e=>{try{let t=await eM(e,{type:"get_tools"});if(t){let{getPresetFromTools:e}=await r.e(8451).then(r.bind(r,8451));ef(e(t))}}catch(e){console.error("Failed to load tools:",e)}},[ef]),ew=(0,o.useCallback)(e=>{el.current&&(el.current.close(),el.current=null);let t=new EventSource(`/api/agent/${encodeURIComponent(e)}/events`);el.current=t,t.onmessage=e=>{try{let t=JSON.parse(e.data);ed.current?.(t)}catch{}},t.onerror=()=>{el.current===t&&ea.current&&(t.close(),el.current=null,setTimeout(()=>{ea.current&&ew(e)},1e3))}},[]);(0,o.useEffect)(()=>{ea.current=z},[z]),ed.current=(0,o.useCallback)(e=>{switch(e.type){case"agent_start":L(!0),ei({kind:"waiting_model"}),C({type:"start"});break;case"agent_end":L(!1),ei(null),_(null),C({type:"end"}),es.current&&(eb(es.current),fetch(`/api/agent/${encodeURIComponent(es.current)}`).then(e=>e.json()).then(e=>{e.state?.contextUsage!==void 0&&V(e.state.contextUsage??null),e.state?.systemPrompt!==void 0&&Y(e.state.systemPrompt??null)}).catch(()=>{})),i?.();break;case"message_start":case"message_update":{let t=e.message;t&&C({type:"update",message:eI(t)}),ei(null);break}case"message_end":{let t=e.message;t&&j(e=>[...e,eI(t)]),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":_({attempt:e.attempt,maxAttempts:e.maxAttempts,errorMessage:e.errorMessage});break;case"auto_retry_end":_(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&&es.current&&eb(es.current)}},[eb,i]);let eS=(0,o.useCallback)(async(e,o,i)=>{if(!e.trim()&&!o?.length&&!i?.length||z)return;let s=i?.length?i.map(e=>`[Attached: ${e.fileName}]`).join("\n"):null,a=e.trim()?s?`${e}
|
|
82
|
+
|
|
83
|
+
${s}`:e:s??"",d=o?.map(e=>({type:"image",source:{type:"base64",media_type:e.mimeType,data:e.data}})),c={role:"user",content:d?.length?[...a.trim()?[{type:"text",text:a}]:[],...d]:a,timestamp:Date.now()};j(e=>[...e,c]),L(!0),ei({kind:"waiting_model"}),C({type:"start"}),ep.current=!0;let p=o?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType}));try{if(u&&n){F&&Q(F);let{PRESET_NONE:t,PRESET_DEFAULT:o,PRESET_FULL:i}=await r.e(8451).then(r.bind(r,8451)),s="none"===A?t:"default"===A?o:i,d=await fetch("/api/agent/new",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:n,type:"prompt",message:a,toolNames:s,...p?.length?{images:p}:{},...F?{provider:F.provider,modelId:F.modelId}:{},..."auto"!==H?{thinkingLevel:H}:{}})});if(!d.ok)throw Error(`HTTP ${d.status}`);let c=(await d.json()).sessionId;es.current=c,ew(c),l?.({id:c,path:"",cwd:n,name:void 0,created:new Date().toISOString(),modified:new Date().toISOString(),messageCount:1,firstMessage:e})}else t&&(ew(t.id),await eM(t.id,{type:"prompt",message:a,...p?.length?{images:p}:{}}))}catch(e){console.error("Failed to send message:",e),L(!1),ei(null),C({type:"end"})}},[u,n,F,A,H,t,z,ew,l]),eC=(0,o.useCallback)(async()=>{let e=es.current;if(e)try{await eM(e,{type:"abort"})}catch(e){console.error("Failed to abort:",e)}},[]),ez=(0,o.useCallback)(async e=>{let t=es.current;if(t){J(e);try{let{cancelled:r,newSessionId:n}=await eM(t,{type:"fork",entryId:e})??{};!r&&n&&s?.(n)}catch(e){console.error("Fork failed:",e)}finally{J(null)}}},[s]),eL=(0,o.useCallback)(async e=>{let t=es.current;t&&(eM(t,{type:"navigate_tree",targetId:e}).catch(()=>{}),y(e),await ej(t,e))},[ej]),eT=(0,o.useCallback)(async e=>{y(e);let t=es.current;t&&(await ej(t,e),e&&eM(t,{type:"navigate_tree",targetId:e}).catch(()=>{}))},[ej]),eW=(0,o.useCallback)(async(e,t)=>{if(u)return void eg({provider:e,modelId:t});let r=es.current;if(r)try{await eM(r,{type:"set_model",provider:e,modelId:t}),G({provider:e,modelId:t})}catch(e){console.error("Failed to set model:",e)}},[u,eg]),eE=(0,o.useCallback)(async()=>{let e=es.current;if(e&&!ee){et(!0),en(null);try{await eM(e,{type:"compact"}),await eb(e,!0)}catch(e){en(e instanceof Error?e.message:String(e))}finally{et(!1)}}},[ee,eb]),eB=(0,o.useCallback)(async(e,t,r)=>{let n=es.current;if(!n)return;let o=e+(r?.length?"\n"+r.map(e=>`[Attached: ${e.fileName}]`).join("\n"):"");j(e=>[...e,{role:"user",content:`[steer] ${o}`,timestamp:Date.now()}]);let i=t?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType}));try{await eM(n,{type:"steer",message:o,...i?.length?{images:i}:{}})}catch(e){console.error("Failed to steer:",e)}},[]),e$=(0,o.useCallback)(async(e,t,r)=>{let n=es.current;if(!n)return;let o=e+(r?.length?"\n"+r.map(e=>`[Attached: ${e.fileName}]`).join("\n"):"");j(e=>[...e,{role:"user",content:o,timestamp:Date.now()}]);let i=t?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType}));try{await eM(n,{type:"follow_up",message:o,...i?.length?{images:i}:{}})}catch(e){console.error("Failed to follow up:",e)}},[]),eF=(0,o.useCallback)(async()=>{let e=es.current;if(e)try{await eM(e,{type:"abort_compaction"})}catch(e){console.error("Failed to abort compaction:",e)}},[]),eP=(0,o.useCallback)(async e=>{if(N(e),"auto"===e)return;let t=es.current;if(t)try{await eM(t,{type:"set_thinking_level",level:e})}catch(e){console.error("Failed to set thinking level:",e)}},[]),eA=(0,o.useCallback)(async e=>{let{PRESET_NONE:t,PRESET_DEFAULT:n,PRESET_FULL:o}=await r.e(8451).then(r.bind(r,8451));ef(e);let i=es.current;if(i)try{await eM(i,{type:"set_tools",toolNames:"none"===e?t:"default"===e?n:o})}catch(e){console.error("Failed to set tools:",e)}},[ef]),eD=(0,o.useCallback)((e="smooth")=>{eh.current?.scrollIntoView({behavior:e})},[]),eH=(0,o.useCallback)(()=>{let e=ex.current,t=eu.current;if(!e||!t)return;let r=t.getBoundingClientRect().top-e.getBoundingClientRect().top+e.scrollTop;e.scrollTo({top:r-16,behavior:"smooth"})},[]);return(0,o.useEffect)(()=>(t&&(es.current=t.id,eb(t.id,!0,!0).then(e=>{e?.running&&(ek(t.id),L(!0),ei({kind:"waiting_model"}),C({type:"start"}),ew(t.id)),e?.state&&(void 0!==e.state.isCompacting&&et(e.state.isCompacting),void 0!==e.state.contextUsage&&V(e.state.contextUsage??null),void 0!==e.state.systemPrompt&&Y(e.state.systemPrompt??null),void 0!==e.state.thinkingLevel&&N(e.state.thinkingLevel??"auto"))})),()=>{el.current?.close(),el.current=null}),[]),(0,o.useEffect)(()=>{c?.(K)},[K,c]),(0,o.useEffect)(()=>{d&&d(p?.tree??[],v,eT)},[p?.tree,v,eT,d]),(0,o.useEffect)(()=>{b.length>0&&(ep.current?(ep.current=!1,ec.current=!0,eH()):ec.current?ea.current||eD("smooth"):(ec.current=!0,eD("instant")))},[b.length,z,eD,eH]),(0,o.useEffect)(()=>{fetch("/api/models").then(e=>e.json()).then(e=>{if(I(e.models),e.thinkingLevels&&E(e.thinkingLevels),e.thinkingLevelMaps&&$(e.thinkingLevelMaps),e.modelList&&(R(e.modelList),u&&e.modelList.length>0)){let t=e.defaultModel,r=t&&e.modelList.find(e=>e.id===t.modelId&&e.provider===t.provider);eg(r?{provider:r.provider,modelId:r.id}:{provider:e.modelList[0].provider,modelId:e.modelList[0].id})}}).catch(()=>{})},[u,a,eg]),(0,o.useEffect)(()=>{if(!er)return;let e=setTimeout(()=>en(null),3e3);return()=>clearTimeout(e)},[er]),{data:p,loading:x,error:f,activeLeafId:v,messages:b,entryIds:k,streamState:S,agentRunning:z,modelNames:T,modelList:M,modelThinkingLevels:W,modelThinkingLevelMaps:B,newSessionModel:F,toolPreset:A,thinkingLevel:H,retryInfo:O,contextUsage:U,systemPrompt:K,forkingEntryId:q,isCompacting:ee,compactError:er,currentModel:em,displayModel:ev,sessionStats:ey,agentPhase:eo,isNew:u,sessionIdRef:es,eventSourceRef:el,messagesEndRef:eh,scrollContainerRef:ex,lastUserMsgRef:eu,pendingScrollToUserRef:ep,initialScrollDoneRef:ec,handleSend:eS,handleAbort:eC,handleFork:ez,handleNavigate:eL,handleModelChange:eW,handleCompact:eE,handleSteer:eB,handleFollowUp:e$,handleAbortCompaction:eF,handleToolPresetChange:eA,handleThinkingLevelChange:eP,loadTools:ek,setActiveLeafId:y,setData:h,setMessages:j,dispatch:C,setAgentRunning:L,setForkingEntryId:J,handleAgentEventRef:ed}}({session:e,newSessionCwd:t,onAgentEnd:i,onSessionCreated:l,onSessionForked:s,modelsRefreshKey:a,onBranchDataChange:c,onSystemPromptChange:u}),{soundEnabled:X,onSoundToggle:Q,playDoneSound:ee}=function(){let[e,t]=(0,o.useState)(()=>{let e=localStorage.getItem("pi-sound-enabled");return null===e||"true"===e}),r=(0,o.useRef)(e);return(0,o.useEffect)(()=>{r.current=e},[e]),{soundEnabled:e,onSoundToggle:(0,o.useCallback)(()=>{t(e=>{let t=!e;return localStorage.setItem("pi-sound-enabled",String(t)),t})},[]),playDoneSound:(0,o.useCallback)(()=>{if(r.current)try{let e=new AudioContext,t=e.currentTime;[523.25,659.25].forEach((r,n)=>{let o=e.createOscillator(),i=e.createGain();o.connect(i),i.connect(e.destination),o.type="sine",o.frequency.value=r;let l=t+.18*n;i.gain.setValueAtTime(0,l),i.gain.linearRampToValueAtTime(.18,l+.02),i.gain.exponentialRampToValueAtTime(.001,l+.45),o.start(l),o.stop(l+.45)}),setTimeout(()=>e.close(),1200)}catch{}},[]),soundEnabledRef:r}}(),et=(0,o.useRef)(ee);et.current=ee;let er=(0,o.useRef)(X);er.current=X;let en=G.current;(0,o.useEffect)(()=>{G.current=e=>{"agent_end"===e.type&&er.current&&et.current(),en?.(e)}},[en,G]);let eo=B?`${B.tokens.input}|${B.tokens.output}|${B.tokens.cacheRead}|${B.tokens.cacheWrite}|${B.cost??0}`:null,ei=(0,o.useRef)(B);ei.current=B,(0,o.useEffect)(()=>{p?.(ei.current)},[eo,p]),(0,o.useEffect)(()=>()=>{p?.(null)},[p]);let el=I?`${I.percent??"null"}|${I.contextWindow}|${I.tokens??"null"}`:null,es=(0,o.useRef)(I);es.current=I,(0,o.useEffect)(()=>{h?.(es.current)},[el,h]),(0,o.useEffect)(()=>()=>{h?.(null)},[h]);let{isDragOver:ea,handleDragEnter:ec,handleDragOver:eu,handleDragLeave:ep,handleDrop:eh}=function(e){let[t,r]=(0,o.useState)(!1),n=(0,o.useRef)(0),i=(0,o.useCallback)(e=>{Array.from(e.dataTransfer.items).some(eE)&&(e.preventDefault(),n.current+=1,r(!0))},[]),l=(0,o.useCallback)(e=>{Array.from(e.dataTransfer.items).some(eE)&&e.preventDefault()},[]);return{isDragOver:t,handleDragEnter:i,handleDragOver:l,handleDragLeave:(0,o.useCallback)(()=>{n.current-=1,n.current<=0&&(n.current=0,r(!1))},[]),handleDrop:(0,o.useCallback)(t=>{t.preventDefault(),n.current=0,r(!1),e(Array.from(t.dataTransfer.files))},[e])}}((0,o.useCallback)(e=>{d?.current?.addImages(e)},[d])),ex=(x=v.filter(e=>"user"===e.role||"assistant"===e.role).length,(g=(0,o.useRef)([])).current=Array(x).fill(null).map((e,t)=>g.current[t]??null),g),eg=F&&0===v.length&&!b.isStreaming&&!j,[ef,em]=(0,o.useState)(!1),ev=E?S[`${E.provider}:${E.modelId}`]??null:null,ey=E?C[`${E.provider}:${E.modelId}`]??null:null,eb=(0,n.jsx)(eC,{ref:d,onSend:H,onAbort:N,onSteer:j?K:void 0,onFollowUp:j?Y:void 0,isStreaming:j,model:E,modelNames:k,modelList:w,onModelChange:U,onCompact:e||F?V:void 0,onAbortCompaction:q,isCompacting:R,compactError:W,toolPreset:z,onToolPresetChange:e||F?J:void 0,thinkingLevel:L,onThinkingLevelChange:e||F?Z:void 0,availableThinkingLevels:ev,thinkingLevelMap:ey,retryInfo:T,soundEnabled:X,onSoundToggle:Q});return f?(0,n.jsx)("div",{className:"flex h-full items-center justify-center text-text-muted",children:"Loading session..."}):m?(0,n.jsx)("div",{className:"flex h-full items-center justify-center text-red-400",children:m}):(0,n.jsxs)("div",{className:"relative flex h-full flex-col overflow-hidden",onDragEnter:ec,onDragOver:eu,onDragLeave:ep,onDrop:eh,children:[ea&&(0,n.jsxs)("div",{className:"pointer-events-none absolute inset-0 z-50 flex animate-[drop-zone-in_0.15s_ease_both] items-center justify-center bg-[rgba(37,99,235,0.06)] backdrop-blur-[1px]",children:[(0,n.jsx)("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",children:[0,.8,1.6].map(e=>(0,n.jsx)("div",{className:"absolute h-[720px] w-[720px] rounded-full border-[1.5px] border-solid border-[rgba(37,99,235,0.5)] animate-[drop-ripple_2.4s_ease-out_infinite_backwards]",style:{transformOrigin:"center",animationDelay:`${e}s`}},e))}),(0,n.jsxs)("svg",{width:"280",height:"280",viewBox:"0 0 140 140",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"drop-shadow-[0_6px_18px_rgba(37,99,235,0.18)]",children:[(0,n.jsx)("rect",{x:"28",y:"44",width:"84",height:"60",rx:"8",fill:"rgba(37,99,235,0.08)",stroke:"rgba(37,99,235,0.50)",strokeWidth:"1.8"}),(0,n.jsx)("path",{d:"M36 100 L54 72 L68 88 L80 74 L104 100Z",fill:"rgba(37,99,235,0.16)",stroke:"rgba(37,99,235,0.40)",strokeWidth:"1.4",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"96",cy:"58",r:"8",fill:"rgba(37,99,235,0.22)",stroke:"rgba(37,99,235,0.55)",strokeWidth:"1.6"}),(0,n.jsxs)("g",{stroke:"rgba(37,99,235,0.45)",strokeWidth:"1.4",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"96",y1:"46",x2:"96",y2:"43"}),(0,n.jsx)("line",{x1:"96",y1:"70",x2:"96",y2:"73"}),(0,n.jsx)("line",{x1:"84",y1:"58",x2:"81",y2:"58"}),(0,n.jsx)("line",{x1:"108",y1:"58",x2:"111",y2:"58"}),(0,n.jsx)("line",{x1:"87.5",y1:"49.5",x2:"85.4",y2:"47.4"}),(0,n.jsx)("line",{x1:"104.5",y1:"66.5",x2:"106.6",y2:"68.6"}),(0,n.jsx)("line",{x1:"104.5",y1:"49.5",x2:"106.6",y2:"47.4"}),(0,n.jsx)("line",{x1:"87.5",y1:"66.5",x2:"85.4",y2:"68.6"})]})]})]}),eg?(0,n.jsx)("div",{className:"flex flex-1 flex-col items-center justify-center overflow-y-auto px-4 py-8",children:(0,n.jsxs)("div",{className:"w-full max-w-[820px]",children:[(0,n.jsxs)("div",{className:"mb-3",style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,marginLeft:16,marginRight:52,fontFamily:"var(--font-mono)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10,minWidth:0,flex:1,lineHeight:1.4},children:[(0,n.jsx)("span",{style:{fontSize:28,fontWeight:700,letterSpacing:"-0.02em",color:"var(--text)"},children:"π"}),(0,n.jsx)("span",{style:{fontSize:22,color:"var(--text)",fontWeight:700,letterSpacing:"-0.01em"},children:"pidex"}),(0,n.jsx)("span",{style:{fontSize:14,minWidth:0,overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"},children:(0,n.jsx)(e$,{phrases:eB})})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",alignItems:"flex-end",gap:2,flexShrink:0},children:[(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)"},children:["web ",(0,n.jsxs)("span",{style:{color:"var(--text)"},children:["v","0.7.9"]})]}),(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)"},children:["pi ",(0,n.jsxs)("span",{style:{color:"var(--text)"},children:["v","0.75.5"]})]})]})]}),eb]})}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"relative flex flex-1 overflow-hidden",children:[(0,n.jsx)("div",{ref:A,className:"flex-1 overflow-y-auto pt-4 [scrollbar-width:none]",children:(0,n.jsxs)("div",{className:"mx-auto max-w-[820px] px-4",children:[(()=>{let e=new Map;for(let t of v)"toolResult"===t.role&&e.set(t.toolCallId,t);let t=-1;for(let e=v.length-1;e>=0;e--)if("user"===v[e].role){t=e;break}let r=0;return v.map((o,i)=>{let l="user"===o.role&&i>0&&"assistant"===v[i-1].role?y[i-1]:void 0,s="user"===o.role||"assistant"===o.role,a=s?r++:-1,c=!1;if("assistant"===o.role){c=!0;for(let e=i+1;e<v.length;e++){let t=v[e].role;if("user"===t)break;if("assistant"===t){c=!1;break}}c&&b.isStreaming&&i===v.length-1&&(c=!1)}let u=(0,n.jsx)(ed,{message:o,toolResults:e,modelNames:k,entryId:y[i],onFork:j||F||0===i&&"user"===o.role?void 0:O,forking:M===y[i],onNavigate:j?void 0:_,prevAssistantEntryId:j?void 0:l,onEditContent:e=>d?.current?.insertIfEmpty(e),showTimestamp:c,prevTimestamp:i>0?v[i-1].timestamp:void 0},i);return s?(0,n.jsx)("div",{ref:e=>{ex.current[a]=e,i===t&&(D.current=e)},children:u},i):u})})(),b.isStreaming&&b.streamingMessage&&(0,n.jsx)(ed,{message:b.streamingMessage,isStreaming:!0,modelNames:k}),j&&!b.streamingMessage&&(0,n.jsx)("div",{className:"py-2 text-[13px] text-text-muted",children:(0,n.jsx)("span",{className:"animate-[pulse_1.5s_infinite]",children:function(e){if(e?.kind==="running_tools"){let t=e.tools.map(e=>e.name);return 0===t.length?"Running tool...":1===t.length?`Running ${t[0]}...`:t.length<=3?`Running ${t.join(", ")}...`:`Running ${t.slice(0,2).join(", ")} (+${t.length-2})...`}return e?.kind==="waiting_model"?"Waiting for model...":"Thinking..."}($)})}),j&&(0,n.jsx)("div",{style:{height:A.current?A.current.clientHeight:"80vh"}}),(0,n.jsx)("div",{ref:P})]})}),(0,n.jsx)(eL,{messages:v,streamingMessage:b.streamingMessage,scrollContainer:A,messageRefs:ex}),(0,n.jsx)("button",{onClick:()=>em(e=>!e),title:ef?"Hide subagent runs":"Show subagent runs",style:{position:"absolute",right:ef?260:40,top:8,width:28,height:28,display:"flex",alignItems:"center",justifyContent:"center",background:ef?"var(--bg-selected)":"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:ef?"var(--accent)":"var(--text-dim)",cursor:"pointer",zIndex:30,fontSize:12,transition:"right 0.2s ease, background 0.12s"},onMouseEnter:e=>{ef||(e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{ef||(e.currentTarget.style.color="var(--text-dim)")},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),(0,n.jsx)("circle",{cx:"9",cy:"7",r:"4"}),(0,n.jsx)("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),(0,n.jsx)("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]})}),ef&&(0,n.jsxs)("div",{style:{position:"absolute",right:48,top:4,bottom:4,width:250,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"-2px 0 12px rgba(0,0,0,0.08)",zIndex:25,overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"6px 12px",fontSize:11,fontWeight:600,color:"var(--text-dim)",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Subagents"}),(0,n.jsx)(eT,{messages:v})]})]}),(0,n.jsx)("div",{className:"relative",children:eb})]})]})}function eP({fileName:e,pageInfo:t,onZoomIn:r,onZoomOut:o,zoom:i,extra:l}){return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"4px 16px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",background:"var(--bg)",flexShrink:0,minHeight:32},children:[e&&(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:300},title:e,children:e}),(0,n.jsx)("span",{style:{marginLeft:"auto"}}),t&&(0,n.jsx)("span",{children:t}),void 0!==i&&o&&r&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsx)("button",{onClick:o,title:"Zoom out",style:eA,children:(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:(0,n.jsx)("line",{x1:"2",y1:"5",x2:"8",y2:"5"})})}),(0,n.jsxs)("span",{style:{minWidth:36,textAlign:"center",fontVariantNumeric:"tabular-nums"},children:[Math.round(100*i),"%"]}),(0,n.jsx)("button",{onClick:r,title:"Zoom in",style:eA,children:(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"5",y1:"2",x2:"5",y2:"8"}),(0,n.jsx)("line",{x1:"2",y1:"5",x2:"8",y2:"5"})]})})]}),l]})}let eA={display:"flex",alignItems:"center",justifyContent:"center",width:24,height:24,padding:0,background:"none",border:"1px solid var(--border)",borderRadius:4,color:"var(--text-muted)",cursor:"pointer"},eD=null;function eH({arrayBuffer:e,fileName:t}){let i=(0,o.useRef)(null),[l,s]=(0,o.useState)(!0),[a,d]=(0,o.useState)(null),[c,u]=(0,o.useState)(0),[p,h]=(0,o.useState)(1),[x,g]=(0,o.useState)(1),f=(0,o.useRef)(x);f.current=x;let m=(0,o.useRef)(null),v=(0,o.useRef)(null),y=(0,o.useCallback)(async e=>{if(!eD||!m.current)return;let t=m.current;if(!(e<1)&&!(e>t.numPages)){v.current&&(v.current.cancel(),v.current=null);try{let r=await t.getPage(e),n=r.getViewport({scale:f.current*(window.devicePixelRatio||1)}),o=i.current;if(!o)return;let l=o.querySelector("canvas");if(l||((l=document.createElement("canvas")).style.display="block",l.style.margin="0 auto",o.innerHTML="",o.appendChild(l)),l.width=n.width,l.height=n.height,l.style.width=`${n.width/(window.devicePixelRatio||1)}px`,l.style.height=`${n.height/(window.devicePixelRatio||1)}px`,!l.getContext("2d"))return;let s=r.render({canvas:l,viewport:n});v.current=s,await s.promise,v.current=null}catch(e){"RenderingCancelledException"!==e.name&&console.error("PDF render error:",e)}}},[]);return(0,o.useEffect)(()=>{let t=!1;return async function(){s(!0),d(null);try{eD||((eD=await Promise.all([r.e(2084),r.e(2619)]).then(r.bind(r,6898))).GlobalWorkerOptions.workerSrc=new r.U(r(9924)).toString());let n=await eD.getDocument({data:e}).promise;if(t)return;m.current=n,u(n.numPages),h(1),s(!1)}catch(e){t||(d(String(e)),s(!1))}}(),()=>{t=!0,v.current&&(v.current.cancel(),v.current=null)}},[e]),(0,o.useEffect)(()=>{!l&&c>0&&y(p)},[l,p,c,y]),(0,o.useEffect)(()=>{!l&&c>0&&y(p)},[x]),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsx)(eP,{fileName:t,pageInfo:c>0?`Page ${p} / ${c}`:void 0,zoom:x,onZoomIn:()=>g(e=>Math.min(e+.25,3)),onZoomOut:()=>g(e=>Math.max(e-.25,.25)),extra:c>1&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsx)("button",{onClick:()=>h(e=>Math.max(e-1,1)),disabled:p<=1,style:{...eN,opacity:p<=1?.4:1},children:(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:(0,n.jsx)("polyline",{points:"6 2 3 5 6 8"})})}),(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-dim)",minWidth:28,textAlign:"center"},children:[p,"/",c]}),(0,n.jsx)("button",{onClick:()=>h(e=>Math.min(e+1,c)),disabled:p>=c,style:{...eN,opacity:p>=c?.4:1},children:(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:(0,n.jsx)("polyline",{points:"4 2 7 5 4 8"})})})]})}),(0,n.jsxs)("div",{style:{flex:1,overflow:"auto",background:"#525659",display:"flex",justifyContent:"center",padding:16},children:[l&&(0,n.jsx)("div",{style:{color:"#ccc",fontSize:13,display:"flex",alignItems:"center",gap:6,alignSelf:"flex-start",marginTop:40},children:"Loading PDF..."}),a&&(0,n.jsx)("div",{style:{color:"#f87171",fontSize:13,alignSelf:"flex-start",marginTop:40},children:a}),(0,n.jsx)("div",{ref:i,style:{visibility:l?"hidden":"visible"}})]})]})}let eN={display:"flex",alignItems:"center",justifyContent:"center",width:24,height:24,padding:0,background:"none",border:"1px solid var(--border)",borderRadius:4,color:"var(--text-muted)",cursor:"pointer"};function eO({arrayBuffer:e,fileName:t}){let i=(0,o.useRef)(null),[l,s]=(0,o.useState)(!0),[a,d]=(0,o.useState)(null);return(0,o.useEffect)(()=>{let t=!1;return async function(){s(!0),d(null);try{let{renderAsync:n}=await Promise.all([r.e(2619),r.e(4453),r.e(2274)]).then(r.bind(r,2274)),o=i.current;if(!o||t)return;o.innerHTML="",await n(e,o,void 0,{className:"docx-preview",inWrapper:!0,ignoreWidth:!1,ignoreHeight:!1,ignoreFonts:!1,breakPages:!0,ignoreLastRenderedPageBreak:!1,experimental:!1,trimXmlDeclaration:!0,useBase64URL:!1,renderChanges:!1,renderHeaders:!0,renderFooters:!0,renderFootnotes:!0,renderEndnotes:!0}),t||s(!1)}catch(e){t||(console.error("DOCX render error:",e),d(String(e)),s(!1))}}(),()=>{t=!0}},[e]),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsx)(eP,{fileName:t}),(0,n.jsxs)("div",{style:{flex:1,overflow:"auto",background:"#e8e8e8",padding:"24px 0"},children:[l&&(0,n.jsx)("div",{style:{color:"var(--text-muted)",fontSize:13,padding:"40px 16px",textAlign:"center"},children:"Loading document..."}),a&&(0,n.jsx)("div",{style:{color:"#f87171",fontSize:13,padding:"40px 16px",textAlign:"center"},children:a}),(0,n.jsx)("div",{ref:i,style:{maxWidth:816,margin:"0 auto",background:"#fff",boxShadow:"0 1px 4px rgba(0,0,0,0.12)",minHeight:100,visibility:l?"hidden":"visible"},className:"docx-preview-container"})]})]})}function e_({arrayBuffer:e,fileName:t}){let[i,l]=(0,o.useState)(!0),[s,a]=(0,o.useState)(null),[d,c]=(0,o.useState)([]),[u,p]=(0,o.useState)(0),h=(0,o.useRef)(null),[x,g]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{let t=!1;return async function(){l(!0),a(null);try{let n=await Promise.all([r.e(3524),r.e(8436)]).then(r.bind(r,5967)),o=n.read(e,{type:"array"}),i=o.SheetNames.map(e=>{let t=o.Sheets[e],r=n.utils.sheet_to_html(t,{editable:!1});return{name:e,html:r}});t||(c(i),p(0),l(!1))}catch(e){t||(console.error("XLSX parse error:",e),a(String(e)),l(!1))}}(),()=>{t=!0}},[e]),(0,o.useEffect)(()=>{let e=h.current;if(!e)return;let t=e.querySelector("table");if(!t)return;let r=()=>{g(t.querySelectorAll("colgroup col, thead tr:first-child th, tbody tr:first-child td").length>8)};r();let n=new ResizeObserver(r);return n.observe(e),()=>n.disconnect()},[u,d]),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsx)(eP,{fileName:t,extra:d.length>1&&(0,n.jsx)("div",{style:{display:"flex",alignItems:"center",gap:2},children:d.map((e,t)=>(0,n.jsx)("button",{onClick:()=>p(t),style:{padding:"2px 10px",fontSize:11,border:"1px solid var(--border)",borderBottom:t===u?"2px solid var(--accent)":"1px solid var(--border)",borderRadius:"4px 4px 0 0",background:t===u?"var(--bg-selected)":"none",color:t===u?"var(--text)":"var(--text-muted)",cursor:"pointer",fontWeight:t===u?600:400,transition:"background 0.12s"},onMouseEnter:e=>{t!==u&&(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t!==u&&(e.currentTarget.style.background="none")},children:e.name},t))})}),(0,n.jsxs)("div",{style:{flex:1,overflow:"auto",background:"var(--bg-panel)"},children:[i&&(0,n.jsx)("div",{style:{color:"var(--text-muted)",fontSize:13,padding:"40px 16px",textAlign:"center"},children:"Loading spreadsheet..."}),s&&(0,n.jsx)("div",{style:{color:"#f87171",fontSize:13,padding:"40px 16px",textAlign:"center"},children:s}),!i&&!s&&d.length>0&&(0,n.jsx)("div",{ref:h,style:{padding:"0 16px 16px",overflow:x?"auto":"visible"},dangerouslySetInnerHTML:{__html:d[u]?.html??""},className:"xlsx-preview"})]})]})}function eU({arrayBuffer:e,fileName:t}){let[i,l]=(0,o.useState)(!0),[s,a]=(0,o.useState)(null),[d,c]=(0,o.useState)([]),[u,p]=(0,o.useState)(0);(0,o.useEffect)(()=>{let t=!1;return async function(){l(!0),a(null);try{let n=(await Promise.all([r.e(2619),r.e(4453)]).then(r.t.bind(r,4453,23))).default,o=await n.loadAsync(e),i=[];o.forEach(e=>{let t=/^ppt\/slides\/slide(\d+)\.xml$/i.exec(e);t&&i.push({name:e,index:parseInt(t[1],10)})}),i.sort((e,t)=>e.index-t.index);let s=[];for(let e of i){let r;if(t)return;let n=await o.file(e.name).async("string"),i=/<a:t[^>]*>([^<]*)<\/a:t>/g,l=[];for(;null!==(r=i.exec(n));){let e=r[1].trim();e&&l.push(e)}s.push({index:e.index,texts:l})}t||(c(s),l(!1))}catch(e){t||(console.error("PPTX parse error:",e),a(String(e)),l(!1))}}(),()=>{t=!0}},[e]);let h=d[u],x=d.length;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsx)(eP,{fileName:t,pageInfo:x>0?`Slide ${u+1} / ${x}`:void 0,extra:x>1&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsx)("button",{onClick:()=>p(e=>Math.max(e-1,0)),disabled:u<=0,style:{...eV,opacity:u<=0?.4:1},children:(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:(0,n.jsx)("polyline",{points:"6 2 3 5 6 8"})})}),(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-dim)",minWidth:28,textAlign:"center"},children:[u+1,"/",x]}),(0,n.jsx)("button",{onClick:()=>p(e=>Math.min(e+1,x-1)),disabled:u>=x-1,style:{...eV,opacity:u>=x-1?.4:1},children:(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:(0,n.jsx)("polyline",{points:"4 2 7 5 4 8"})})})]})}),(0,n.jsxs)("div",{style:{flex:1,overflow:"auto",background:"var(--bg-panel)",display:"flex",justifyContent:"center",alignItems:"flex-start",padding:24},children:[i&&(0,n.jsx)("div",{style:{color:"var(--text-muted)",fontSize:13,padding:"40px 16px",textAlign:"center"},children:"Loading presentation..."}),s&&(0,n.jsx)("div",{style:{color:"#f87171",fontSize:13,padding:"40px 16px",textAlign:"center"},children:s}),!i&&!s&&h&&(0,n.jsxs)("div",{style:{width:"100%",maxWidth:800},children:[(0,n.jsxs)("div",{style:{background:"#fff",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 2px 8px rgba(0,0,0,0.08)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:"8px 16px",background:"var(--bg)",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:["Slide ",h.index]}),(0,n.jsx)("div",{style:{padding:"24px 32px 40px",minHeight:200},children:0===h.texts.length?(0,n.jsx)("div",{style:{color:"var(--text-dim)",fontStyle:"italic",fontSize:13},children:"(No text content)"}):(0,n.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none"},children:h.texts.map((e,t)=>(0,n.jsx)("li",{style:{padding:"4px 0",fontSize:14,lineHeight:1.6,color:"var(--text)",borderBottom:t<h.texts.length-1?"1px solid var(--bg-panel)":"none"},children:e},t))})})]}),x>1&&(0,n.jsxs)("div",{style:{marginTop:24},children:[(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)",marginBottom:8},children:"All slides"}),(0,n.jsx)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(140px, 1fr))",gap:8},children:d.map((e,t)=>(0,n.jsxs)("button",{onClick:()=>p(t),style:{padding:"10px 12px",background:t===u?"var(--bg-selected)":"var(--bg)",border:t===u?"2px solid var(--accent)":"1px solid var(--border)",borderRadius:6,cursor:"pointer",textAlign:"left",fontSize:11,color:"var(--text-muted)",transition:"border-color 0.12s, background 0.12s"},onMouseEnter:e=>{t!==u&&(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t!==u&&(e.currentTarget.style.background="var(--bg)")},children:[(0,n.jsxs)("div",{style:{fontWeight:600,marginBottom:2,color:"var(--text)"},children:["Slide ",e.index]}),(0,n.jsx)("div",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.texts[0]||"(empty)"})]},e.index))})]})]})]})]})}let eV={display:"flex",alignItems:"center",justifyContent:"center",width:24,height:24,padding:0,background:"none",border:"1px solid var(--border)",borderRadius:4,color:"var(--text-muted)",cursor:"pointer"};var eK=r(7071),eY=r(9561),eq=r(2228),eJ=r(6732),eZ=r(4059),eG=r(3307),eX=r(3689),eQ=r(4097),e0=r(5460),e1=r(144),e2=r(2774),e4=r(2733),e5=r(7482),e6=r(5135),e8=r(1209),e3=r(8198),e9=r(4238),e7=r(2161);function te({initialContent:e,language:t,isDark:r,onChange:i,onSave:l}){let s=(0,o.useRef)(null),a=(0,o.useRef)(null);return(0,o.useEffect)(()=>{let n=s.current;if(!n)return;let o=function(e){switch(e){case"javascript":case"typescript":return(0,eG.Q2)({typescript:"typescript"===e});case"python":return(0,eX.Hg)();case"sql":return(0,eQ.ll)();case"json":return(0,e0.Pq)();case"html":return(0,e1.qy)();case"css":case"scss":case"less":return(0,e2.AH)();case"markdown":return(0,e4.wD)();case"xml":case"yaml":case"toml":return(0,e5._n)();case"rust":return(0,e6.T)();case"go":return(0,e8.go)();case"java":return(0,e3.J)();default:return null}}(t),d=l?eY.w4.of([{key:"Mod-s",run:()=>(l(),!0),preventDefault:!0}]):[],c=eK.$t.create({doc:e,extensions:[(0,eY.$K)(),(0,eY.dz)(),(0,eq.b6)(),(0,eJ.y9)(eJ.Zt),eY.w4.of([...eq.pw,...eq.cL,...e7.OO,...e9.Eo]),d,(0,e7.yU)(),...r?[eZ.bM]:[],...o?[o]:[],eY.Lz.updateListener.of(e=>{e.docChanged&&i?.(e.state.doc.toString())}),eY.Lz.theme({"&":{height:"100%",fontSize:"13px"},".cm-scroller":{overflow:"auto",fontFamily:"var(--font-mono)"},".cm-content":{padding:"8px 0"},".cm-gutters":{borderRight:"1px solid var(--border)",background:"var(--bg)",color:"var(--text-dim)"},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground":{background:r?"#3a3d4e":"#b4d5fe"}})]}),u=new eY.Lz({state:c,parent:n});return a.current=u,()=>{u.destroy(),a.current=null}},[t,r]),(0,o.useEffect)(()=>{let t=a.current;t&&t.state.doc.toString()!==e&&t.dispatch({changes:{from:0,to:t.state.doc.length,insert:e}})},[e]),(0,n.jsx)("div",{ref:s,style:{height:"100%",overflow:"hidden"}})}let tt=new Set(["png","jpg","jpeg","gif","webp","svg","bmp","ico","avif"]),tr=new Set(["mp3","wav","ogg","oga","opus","m4a","aac","flac","weba","webm"]),tn=new Set(["pdf","docx","xlsx","pptx","doc","xls","ppt"]);function to(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function ti({oldContent:e,newContent:t}){let r=function(e,t){let r=e.length,n=t.length,o=r+n,i=Array(2*o+1).fill(0),l=[];for(let s=0;s<=o;s++){l.push([...i]);for(let a=-s;a<=s;a+=2){let d,c=(d=a===-s||a!==s&&i[a-1+o]<i[a+1+o]?i[a+1+o]:i[a-1+o]+1)-a;for(;d<r&&c<n&&e[d]===t[c];)d++,c++;if(i[a+o]=d,d>=r&&c>=n){let i=[],a=r,d=n;for(let r=s;r>0;r--){let n,s=l[r-1],c=a-d;n=c===-r||c!==r&&s[c-1+o]<s[c+1+o]?c+1:c-1;let u=s[n+o],p=u-n;for(;a>u&&d>p;)a--,d--,i.unshift({type:"unchanged",text:e[a],lineNo:a+1});r>0&&(a>u?(a--,i.unshift({type:"removed",text:e[a],lineNo:a+1})):(d--,i.unshift({type:"added",text:t[d],lineNo:d+1})))}for(;a>0&&d>0;)a--,d--,i.unshift({type:"unchanged",text:e[a],lineNo:a+1});return i}}}return[...e.map((e,t)=>({type:"removed",text:e,lineNo:t+1})),...t.map((e,t)=>({type:"added",text:e,lineNo:t+1}))]}(e.split("\n"),t.split("\n"));if(!r.some(e=>"unchanged"!==e.type))return(0,n.jsx)("div",{style:{padding:"12px 16px",fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:"No changes"});let o=new Set(r.flatMap((e,t)=>"unchanged"!==e.type?[t]:[])),i=new Set;for(let e of o)for(let t=Math.max(0,e-3);t<=Math.min(r.length-1,e+3);t++)i.add(t);let l=[],s=0;for(;s<r.length;)if(i.has(s)){let e=[];for(;s<r.length&&i.has(s);)e.push(r[s]),s++;l.push({hidden:!1,lines:e})}else{let e=0;for(;s<r.length&&!i.has(s);)e++,s++;l.push({hidden:!0,count:e})}let a=[],d=1;for(let e of r)"removed"===e.type?a.push(0):a.push(d++);let c=0;return(0,n.jsx)("div",{style:{fontFamily:"var(--font-mono)",fontSize:13,lineHeight:1.6},children:l.map((e,t)=>{if(e.hidden){let r=(0,n.jsxs)("div",{style:{padding:"2px 16px",color:"var(--text-dim)",background:"var(--bg-panel)",fontSize:11,borderTop:"1px solid var(--border)",borderBottom:"1px solid var(--border)"},children:["... ",e.count," unchanged lines ..."]},t);return c+=e.count,r}let r=e.lines.map((e,t)=>{let r=a[c+t],o="added"===e.type?"rgba(0,200,80,0.12)":"removed"===e.type?"rgba(240,60,60,0.14)":"transparent",i="added"===e.type?"+":"removed"===e.type?"-":" ",l="added"===e.type?"#4ade80":"removed"===e.type?"#f87171":"var(--text-dim)";return(0,n.jsxs)("div",{style:{display:"flex",background:o,borderLeft:"added"===e.type?"3px solid #4ade80":"removed"===e.type?"3px solid #f87171":"3px solid transparent"},children:[(0,n.jsx)("span",{style:{minWidth:44,padding:"0 8px 0 16px",textAlign:"right",color:"var(--text-dim)",userSelect:"none",fontSize:11,lineHeight:1.6,borderRight:"1px solid var(--border)",background:"var(--bg-panel)",flexShrink:0},children:"removed"===e.type?e.lineNo:r||""}),(0,n.jsx)("span",{style:{minWidth:16,padding:"0 6px",color:l,userSelect:"none",flexShrink:0,fontWeight:600},children:i}),(0,n.jsx)("span",{style:{flex:1,padding:"0 8px 0 0",whiteSpace:"pre",color:"var(--text)",overflowX:"auto"},children:e.text||"\xa0"})]},t)});return c+=e.lines.length,(0,n.jsx)("div",{children:r},t)})})}function tl({filePath:e,cwd:t}){let[r,i]=(0,o.useState)(!1),[l,s]=(0,o.useState)(0),[a,d]=(0,o.useState)(null),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(null),x=(0,o.useRef)(null),g=F(e).toLowerCase().split(".").pop()??"";(0,o.useEffect)(()=>{s(0),d(null),u(null),h(null),i(!1),x.current&&(x.current.close(),x.current=null);let t=$(e),r=new EventSource(`/api/files/${t}?type=watch`);return x.current=r,r.addEventListener("connected",()=>i(!0)),r.addEventListener("change",e=>{try{let t=JSON.parse(e.data);"number"==typeof t.size&&d(t.size)}catch{}s(e=>e+1)}),r.addEventListener("error",()=>i(!1)),r.onerror=()=>i(!1),()=>{r.close(),x.current=null}},[e]);let f=$(e),m=`/api/files/${f}?type=read${l?`&v=${l}`:""}`,v=null!=a?to(a):null;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"4px 16px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",background:"var(--bg)",flexShrink:0},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)"},title:e,children:P(e,t)}),(0,n.jsx)("span",{style:{marginLeft:"auto"},children:g||"image"}),c&&(0,n.jsxs)("span",{children:[c.w," \xd7 ",c.h]}),v&&(0,n.jsx)("span",{children:v}),(0,n.jsxs)("span",{title:r?"Live sync active":"Not watching",style:{display:"flex",alignItems:"center",gap:4,color:r?"#4ade80":"var(--text-dim)"},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:r?"#4ade80":"var(--border)",display:"inline-block",boxShadow:r?"0 0 4px #4ade80":"none"}}),r?"live":"static"]})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"auto",background:"var(--bg-panel)",display:"flex",alignItems:"center",justifyContent:"center",padding:16,backgroundImage:"linear-gradient(45deg, var(--bg) 25%, transparent 25%), linear-gradient(-45deg, var(--bg) 25%, transparent 25%), linear-gradient(45deg, transparent 75%, var(--bg) 75%), linear-gradient(-45deg, transparent 75%, var(--bg) 75%)",backgroundSize:"16px 16px",backgroundPosition:"0 0, 0 8px, 8px -8px, -8px 0px"},children:p?(0,n.jsx)("div",{style:{color:"#f87171",fontSize:13},children:p}):(0,n.jsx)("img",{src:m,alt:e,onLoad:e=>{let t=e.currentTarget;u({w:t.naturalWidth,h:t.naturalHeight})},onError:()=>h("Failed to load image"),style:{maxWidth:"100%",maxHeight:"100%",objectFit:"contain",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"}})})]})}function ts({filePath:e,cwd:t}){let[r,i]=(0,o.useState)(!1),[l,s]=(0,o.useState)(0),[a,d]=(0,o.useState)(null),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(null),x=(0,o.useRef)(null),g=F(e).toLowerCase().split(".").pop()??"";(0,o.useEffect)(()=>{s(0),d(null),u(null),h(null),i(!1),x.current&&(x.current.close(),x.current=null);let t=$(e),r=new EventSource(`/api/files/${t}?type=watch`);return x.current=r,r.addEventListener("connected",()=>i(!0)),r.addEventListener("change",e=>{try{let t=JSON.parse(e.data);"number"==typeof t.size&&d(t.size)}catch{}u(null),h(null),s(e=>e+1)}),r.addEventListener("error",()=>i(!1)),r.onerror=()=>i(!1),()=>{r.close(),x.current=null}},[e]);let f=$(e),m=`/api/files/${f}?type=read${l?`&v=${l}`:""}`;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"4px 16px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",background:"var(--bg)",flexShrink:0},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)"},title:e,children:P(e,t)}),(0,n.jsx)("span",{style:{marginLeft:"auto"},children:g||"audio"}),null!=c&&(0,n.jsx)("span",{children:function(e){if(!Number.isFinite(e))return"";let t=Math.round(e),r=Math.floor(t/60);return`${r}:${String(t%60).padStart(2,"0")}`}(c)}),null!=a&&(0,n.jsx)("span",{children:to(a)}),(0,n.jsxs)("span",{title:r?"Live sync active":"Not watching",style:{display:"flex",alignItems:"center",gap:4,color:r?"#4ade80":"var(--text-dim)"},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:r?"#4ade80":"var(--border)",display:"inline-block",boxShadow:r?"0 0 4px #4ade80":"none"}}),r?"live":"static"]})]}),(0,n.jsx)("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",padding:24,background:"var(--bg-panel)"},children:(0,n.jsxs)("div",{style:{width:"min(680px, 100%)"},children:[p&&(0,n.jsx)("div",{style:{color:"#f87171",fontSize:13,marginBottom:12,textAlign:"center"},children:p}),(0,n.jsx)("audio",{controls:!0,preload:"metadata",src:m,onLoadedMetadata:e=>u(e.currentTarget.duration),onError:()=>h("Failed to load audio"),style:{width:"100%"}},m)]})})]})}function ta({filePath:e,cwd:t}){let r,o,i;return(r=F(e).toLowerCase().split(".").pop()??"",tt.has(r))?(0,n.jsx)(tl,{filePath:e,cwd:t}):(o=F(e).toLowerCase().split(".").pop()??"",tr.has(o))?(0,n.jsx)(ts,{filePath:e,cwd:t}):(i=F(e).toLowerCase().split(".").pop()??"",tn.has(i))?(0,n.jsx)(td,{filePath:e,cwd:t}):(0,n.jsx)(tc,{filePath:e,cwd:t})}function td({filePath:e,cwd:t}){let r,[i,l]=(0,o.useState)(null),[s,a]=(0,o.useState)(!0),[d,c]=(0,o.useState)(null),u=(0,o.useRef)(null),p=(0,o.useRef)(0),h="pdf"===(r=F(e).toLowerCase().split(".").pop()??"")?"pdf":"docx"===r||"doc"===r?"docx":"xlsx"===r||"xls"===r?"xlsx":"pptx"===r||"ppt"===r?"pptx":"other",x=F(e).toLowerCase().split(".").pop()??"",g=(0,o.useCallback)(async e=>{try{let t=$(e),r=p.current?`&v=${p.current}`:"",n=await fetch(`/api/files/${t}?type=read${r}`);if(!n.ok){let e=await n.json().catch(()=>({error:String(n.status)}));c(e.error??`HTTP ${n.status}`);return}let o=await n.arrayBuffer();l(o),c(null)}catch(e){c(String(e))}},[]);if((0,o.useEffect)(()=>{a(!0),c(null),l(null),p.current=0,u.current&&(u.current.close(),u.current=null),g(e).finally(()=>a(!1));let t=$(e),r=new EventSource(`/api/files/${t}?type=watch`);return u.current=r,r.addEventListener("connected",()=>{}),r.addEventListener("change",()=>{p.current+=1,g(e)}),r.addEventListener("error",()=>{}),r.onerror=()=>{},()=>{r.close(),u.current=null}},[e,g]),s&&!i)return(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:"Loading..."});if(d&&!i)return(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#f87171",fontSize:13},children:d});if(!i)return null;let f=P(e,t);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:["pdf"===h&&(0,n.jsx)(eH,{arrayBuffer:i,fileName:f}),"docx"===h&&(0,n.jsx)(eO,{arrayBuffer:i,fileName:f}),"xlsx"===h&&(0,n.jsx)(e_,{arrayBuffer:i,fileName:f}),"pptx"===h&&(0,n.jsx)(eU,{arrayBuffer:i,fileName:f}),"other"===h&&(0,n.jsxs)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:["Unsupported document format: .",x]})]})}function tc({filePath:e,cwd:t}){let{isDark:r}=eo(),[i,l]=(0,o.useState)(null),[s,a]=(0,o.useState)(null),[d,c]=(0,o.useState)(!0),[u,p]=(0,o.useState)(null),[h,x]=(0,o.useState)(!1),[g,f]=(0,o.useState)("source"),[m,v]=(0,o.useState)(!1),[y,b]=(0,o.useState)(!1),[j,k]=(0,o.useState)(0),[w,S]=(0,o.useState)(!1),[C,z]=(0,o.useState)(""),[L,T]=(0,o.useState)(!1),[I,M]=(0,o.useState)(!1),R=(0,o.useRef)(null),W=(0,o.useRef)(!1);W.current=w,(0,o.useRef)(null).current=i;let E=(0,o.useCallback)((e,t=!1)=>{let r=$(e);return fetch(`/api/files/${r}?type=read`).then(e=>e.json()).then(e=>e.error?(p(e.error),null):(t?(l(t=>(t&&a(t.content),e)),k(e=>e+1)):l(e),e)).catch(e=>(p(String(e)),null))},[]);(0,o.useEffect)(()=>{c(!0),p(null),l(null),a(null),x(!1),f("source"),v(!1),k(0),b(!1),R.current&&(R.current.close(),R.current=null),E(e).then(e=>{e?.language==="markdown"&&x(!0)}).finally(()=>c(!1));let t=$(e),r=new EventSource(`/api/files/${t}?type=watch`);return R.current=r,r.addEventListener("connected",()=>{b(!0)}),r.addEventListener("change",()=>{W.current?M(!0):E(e,!0)}),r.addEventListener("error",()=>{b(!1)}),r.onerror=()=>{b(!1)},()=>{r.close(),R.current=null}},[e,E]);let B=(0,o.useCallback)(()=>{i&&(S(!0),z(i.content),M(!1),x(!1),f("source"))},[i]),F=(0,o.useCallback)(async()=>{let t=$(e);T(!0);try{let r=await fetch(`/api/files/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:C})});if(!r.ok){let e=await r.json().catch(()=>({error:String(r.status)}));throw Error(e.error??`HTTP ${r.status}`)}await E(e,!0),S(!1),M(!1)}catch(e){p(String(e))}finally{T(!1)}},[e,C,E]),A=(0,o.useCallback)(()=>{S(!1),M(!1)},[]),D=(0,o.useCallback)(()=>{i&&(z(i.content),M(!1))},[i]);if(d)return(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:"Loading..."});if(u)return(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#f87171",fontSize:13},children:u});if(!i)return null;let H="html"===i.language,N="markdown"===i.language,O=i.content.split("\n"),_=null!==s&&s!==i.content;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"4px 16px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",background:"var(--bg)",flexShrink:0},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)"},title:e,children:P(e,t)}),(0,n.jsx)("span",{style:{marginLeft:"auto"},children:i.language}),"source"===g&&(0,n.jsxs)("span",{children:[O.length," lines"]}),(0,n.jsx)("span",{children:to(i.size)}),(0,n.jsxs)("span",{title:y?"Live sync active":"Not watching",style:{display:"flex",alignItems:"center",gap:4,color:y?"#4ade80":"var(--text-dim)"},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:y?"#4ade80":"var(--border)",display:"inline-block",boxShadow:y?"0 0 4px #4ade80":"none"}}),y?"live":"static"]}),w?(0,n.jsxs)(n.Fragment,{children:[I&&(0,n.jsxs)("span",{title:"File changed on disk while editing",style:{padding:"2px 8px",fontSize:11,background:"rgba(234,179,8,0.1)",color:"#b8860b",border:"1px solid rgba(234,179,8,0.3)",borderRadius:5,display:"flex",alignItems:"center",gap:4},children:[(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,n.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),"External change",(0,n.jsx)("button",{onClick:D,style:{marginLeft:4,padding:"1px 6px",fontSize:10,cursor:"pointer",background:"rgba(234,179,8,0.2)",color:"#b8860b",border:"1px solid rgba(234,179,8,0.3)",borderRadius:3,fontWeight:600},children:"Reload"})]}),(0,n.jsx)("button",{onClick:F,disabled:L,title:"Save file (Ctrl+S)",style:{padding:"2px 10px",fontSize:11,cursor:L?"not-allowed":"pointer",background:"var(--accent)",color:"#fff",border:"1px solid var(--accent)",borderRadius:5,fontWeight:600,opacity:L?.6:1},children:L?"Saving…":"Save"}),(0,n.jsx)("button",{onClick:A,title:"Cancel editing",style:{padding:"2px 10px",fontSize:11,cursor:"pointer",background:"var(--bg-hover)",color:"var(--text-muted)",border:"1px solid var(--border)",borderRadius:5,fontWeight:600},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.1)",e.currentTarget.style.color="#ef4444",e.currentTarget.style.borderColor="rgba(239,68,68,0.3)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:"Cancel"})]}):(0,n.jsx)("button",{onClick:B,title:"Edit file",style:{padding:"2px 10px",fontSize:11,cursor:"pointer",background:"var(--bg-hover)",color:"var(--text-muted)",border:"1px solid var(--border)",borderRadius:5,fontWeight:600},onMouseEnter:e=>{e.currentTarget.style.background="var(--accent)",e.currentTarget.style.color="#fff",e.currentTarget.style.borderColor="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:"Edit"}),_&&(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,overflow:"hidden",border:"1px solid var(--border)"},children:[(0,n.jsx)("button",{onClick:()=>f("source"),style:{padding:"2px 8px",fontSize:11,border:"none",cursor:"pointer",background:"source"===g?"var(--bg-selected)":"var(--bg-hover)",color:"source"===g?"var(--text)":"var(--text-muted)",fontWeight:"source"===g?600:400},children:"Source"}),(0,n.jsxs)("button",{onClick:()=>f("diff"),style:{padding:"2px 8px",fontSize:11,border:"none",borderLeft:"1px solid var(--border)",cursor:"pointer",background:"diff"===g?"var(--bg-selected)":"var(--bg-hover)",color:"diff"===g?"var(--text)":"var(--text-muted)",fontWeight:"diff"===g?600:400},children:["Diff ",j>0&&(0,n.jsxs)("span",{style:{color:"#4ade80",marginLeft:2},children:["+",j]})]})]}),"source"===g&&!h&&(0,n.jsx)("button",{onClick:()=>v(e=>!e),title:m?"Disable word wrap":"Enable word wrap",style:{padding:"2px 8px",fontSize:11,cursor:"pointer",background:m?"var(--bg-selected)":"var(--bg-hover)",color:m?"var(--text)":"var(--text-muted)",border:"1px solid var(--border)",borderRadius:5,fontWeight:m?600:400},children:"wrap"}),H&&"source"===g&&(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,overflow:"hidden",border:"1px solid var(--border)"},children:[(0,n.jsx)("button",{onClick:()=>x(!1),style:{padding:"2px 8px",fontSize:11,border:"none",cursor:"pointer",background:h?"var(--bg-hover)":"var(--bg-selected)",color:h?"var(--text-muted)":"var(--text)",fontWeight:h?400:600},children:"Code"}),(0,n.jsx)("button",{onClick:()=>x(!0),style:{padding:"2px 8px",fontSize:11,border:"none",borderLeft:"1px solid var(--border)",cursor:"pointer",background:h?"var(--bg-selected)":"var(--bg-hover)",color:h?"var(--text)":"var(--text-muted)",fontWeight:h?600:400},children:"Preview"})]}),N&&"source"===g&&(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,overflow:"hidden",border:"1px solid var(--border)"},children:[(0,n.jsx)("button",{onClick:()=>x(!0),style:{padding:"2px 8px",fontSize:11,border:"none",cursor:"pointer",background:h?"var(--bg-selected)":"var(--bg-hover)",color:h?"var(--text)":"var(--text-muted)",fontWeight:h?600:400},children:"Preview"}),(0,n.jsx)("button",{onClick:()=>x(!1),style:{padding:"2px 8px",fontSize:11,border:"none",borderLeft:"1px solid var(--border)",cursor:"pointer",background:h?"var(--bg-hover)":"var(--bg-selected)",color:h?"var(--text-muted)":"var(--text)",fontWeight:h?400:600},children:"Raw"})]})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"auto",background:"var(--bg)"},children:w?(0,n.jsx)(te,{initialContent:C,language:i.language,isDark:r,onChange:z,onSave:F}):"diff"===g&&_?(0,n.jsx)(ti,{oldContent:s,newContent:i.content,language:i.language}):H&&h?(0,n.jsx)("iframe",{srcDoc:i.content,sandbox:"allow-scripts",style:{width:"100%",height:"100%",border:"none",background:"var(--bg)"},title:"HTML preview"}):N&&h?(0,n.jsx)("div",{className:"markdown-body markdown-file-preview",style:{padding:"24px 32px",maxWidth:800},children:(0,n.jsx)(Z.oz,{remarkPlugins:[G.A],children:i.content})}):(0,n.jsx)(X.A,{language:"text"===i.language?"plaintext":i.language,style:r?Q.xJ:Q.vs,showLineNumbers:!0,lineNumberStyle:{color:"var(--text-dim)",fontStyle:"normal",minWidth:"3em",paddingRight:"1em"},customStyle:{margin:0,padding:"12px 0",background:"var(--bg)",fontSize:13,lineHeight:1.6,fontFamily:"var(--font-mono)",minHeight:"100%"},codeTagProps:{style:{fontFamily:"var(--font-mono)"}},wrapLongLines:m,children:i.content})})]})}let tu={__soul__:{apiPath:"/api/soul",title:"soul.md"},__harness__:{apiPath:"/api/harness",title:"harness.md"}};function tp({filePath:e}){let t=tu[e],{isDark:r}=eo(),[i,l]=(0,o.useState)(""),[s,a]=(0,o.useState)(!0),[d,c]=(0,o.useState)(null),[u,p]=(0,o.useState)(!1),[h,x]=(0,o.useState)(!1);(0,o.useEffect)(()=>{t&&(a(!0),fetch(t.apiPath).then(e=>e.json()).then(e=>l(e.content??"")).catch(e=>c(String(e))).finally(()=>a(!1)))},[t]);let g=(0,o.useCallback)(async()=>{if(t){p(!0);try{await fetch(t.apiPath,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:i})}),x(!0),setTimeout(()=>x(!1),2e3)}catch(e){c(String(e))}finally{p(!1)}}},[t,i]);return t?s?(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:"Loading…"}):d?(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#f87171",fontSize:13},children:d}):(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"4px 16px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",background:"var(--bg)",flexShrink:0},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontWeight:600,color:"var(--text)"},children:t.title}),(0,n.jsx)("span",{style:{marginLeft:"auto",fontSize:10,color:"var(--text-dim)"},children:"Global"}),h&&(0,n.jsx)("span",{style:{color:"#4ade80",fontWeight:600,animation:"saved-pop 0.3s ease"},children:"✓ Saved"}),(0,n.jsx)("button",{onClick:g,disabled:u,title:"Save (Ctrl+S)",style:{padding:"2px 10px",fontSize:11,cursor:u?"not-allowed":"pointer",background:"var(--accent)",color:"#fff",border:"1px solid var(--accent)",borderRadius:5,fontWeight:600,opacity:u?.6:1},children:u?"Saving…":"Save"})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"hidden"},children:(0,n.jsx)(te,{initialContent:i,language:"markdown",isDark:r,onChange:l,onSave:g})})]}):null}function th({tabs:e,activeTabId:t,onSelectTab:r,onCloseTab:i}){let[l,s]=(0,o.useState)(null);return(0,n.jsx)("div",{style:{display:"flex",alignItems:"flex-end",background:"var(--bg-panel)",overflowX:"auto",flexShrink:0,height:36},children:e.map(e=>{let o=e.id===t;return(0,n.jsxs)("div",{onClick:()=>r(e.id),style:{display:"flex",alignItems:"center",gap:6,height:36,paddingLeft:12,paddingRight:6,borderRight:"1px solid var(--border)",background:o?"var(--bg)":"var(--bg-panel)",cursor:"pointer",fontSize:12,color:o?"var(--text)":"var(--text-muted)",whiteSpace:"nowrap",maxWidth:180,minWidth:80,flexShrink:0,userSelect:"none",transition:"background 0.1s, color 0.1s"},children:[(0,n.jsx)("span",{style:{flexShrink:0,opacity:o?1:.7,display:"flex",alignItems:"center"},children:E(e.label,13)}),(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",flex:1,fontWeight:o?500:400},title:e.filePath,children:e.label}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),i(e.id)},onMouseEnter:()=>s(e.id),onMouseLeave:()=>s(null),style:{display:"flex",alignItems:"center",justifyContent:"center",width:16,height:16,background:l===e.id?"var(--bg-hover)":"transparent",border:"none",borderRadius:3,color:l===e.id?"var(--text)":"var(--text-dim)",cursor:"pointer",padding:0,flexShrink:0,transition:"background 0.1s, color 0.1s"},title:"Close",children:(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"2",y1:"2",x2:"8",y2:"8"}),(0,n.jsx)("line",{x1:"8",y1:"2",x2:"2",y2:"8"})]})})]},e.id)})})}function tx(e,t="0 0 24 24"){return({size:r=24,style:o})=>(0,n.jsx)("svg",{width:r,height:r,viewBox:t,fill:"none",style:o,children:e})}let tg=tx((0,n.jsx)("path",{d:"M17.5 3H6.5L3 21h4l1.2-6h7.6l1.2 6h4L17.5 3zm-2.3 9H8.8L12 5.5 15.2 12z",fill:"currentColor"})),tf=tx((0,n.jsx)("path",{d:"M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5",stroke:"currentColor",strokeWidth:"1.5",strokeLinejoin:"round"})),tm=tx((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("path",{d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92a5.06 5.06 0 01-2.2 3.32v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.1z",fill:"#4285F4"}),(0,n.jsx)("path",{d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z",fill:"#34A853"}),(0,n.jsx)("path",{d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z",fill:"#FBBC05"}),(0,n.jsx)("path",{d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z",fill:"#EA4335"})]})),tv=tx((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"3",fill:"#4D6BFE"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"white",fontSize:"10",fontWeight:"bold",fontFamily:"sans-serif",children:"DS"})]})),ty=tx((0,n.jsx)("path",{d:"M4 4h16v16H4z",fill:"#F55036"}),"0 0 24 24"),tb=tx((0,n.jsx)("path",{d:"M4 4h5v5H4zm5.5 0h5v5h-5zM15 4h5v5h-5zM4 9.5h5v5H4zm5.5 5.5h5v5h-5zM15 9.5h5v5h-5z",fill:"#FA6F00"})),tj=tx((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),"0 0 24 24"),tk=tx((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"3",fill:"#00D4AA"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"white",fontSize:"9",fontWeight:"bold",fontFamily:"sans-serif",children:"MM"})]})),tw=tx((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",fill:"#FF5722"}),"0 0 24 24"),tS=tx((0,n.jsx)("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 5h2v3h-2V7zm0 4h2v2h-2v-2zm3 5H7v-2h7v2z",fill:"#FFD21E"})),tC=tx((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"3",fill:"#E84026"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"white",fontSize:"9",fontWeight:"bold",fontFamily:"sans-serif",children:"CB"})]})),tz=tx((0,n.jsx)("path",{d:"M12 2l9 5v10l-9 5-9-5V7l9-5z",stroke:"currentColor",strokeWidth:"1.5",fill:"none"})),tL=tx((0,n.jsx)("path",{d:"M4 4l8 8 8-8M4 20l8-8 8 8",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})),tT=tx((0,n.jsx)("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 5l4 3-4 3V7z",fill:"#F38020"})),tI={anthropic:{Icon:tg,hasColor:!1},openai:{Icon:tf,hasColor:!1},"openai-codex":{Icon:tf,hasColor:!1},google:{Icon:tm,hasColor:!0},"google-vertex":{Icon:tm,hasColor:!0},deepseek:{Icon:tv,hasColor:!0},groq:{Icon:ty,hasColor:!1},mistral:{Icon:tb,hasColor:!0},moonshotai:{Icon:tj,hasColor:!1},"moonshotai-cn":{Icon:tj,hasColor:!1},moonshot:{Icon:tj,hasColor:!1},minimax:{Icon:tk,hasColor:!0},"minimax-cn":{Icon:tk,hasColor:!0},fireworks:{Icon:tw,hasColor:!0},huggingface:{Icon:tS,hasColor:!0},cerebras:{Icon:tC,hasColor:!0},openrouter:{Icon:tz,hasColor:!1},xai:{Icon:tL,hasColor:!1},"cloudflare-ai-gateway":{Icon:tT,hasColor:!0},"cloudflare-workers-ai":{Icon:tT,hasColor:!0},"vercel-ai-gateway":{Icon:tx((0,n.jsx)("path",{d:"M12 2L22 20H2L12 2z",fill:"currentColor"})),hasColor:!1},"github-copilot":{Icon:tx((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),"0 0 24 24"),hasColor:!1},"amazon-bedrock":{Icon:tx((0,n.jsx)("path",{d:"M3 15h2l1-3h2l1 3h2V9H9v3L8 9H6l-1 3V9H3v6zm9 0h2v-2h2v-2h-2V9h-2v2h-2v2h2v2z",fill:"#FF9900"})),hasColor:!0},"azure-openai-responses":{Icon:tx((0,n.jsx)("path",{d:"M12 2L3 18h5l4-6 4 6h5L12 2z",fill:"#0078D4"})),hasColor:!0},"kimi-coding":{Icon:tx((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"3",fill:"#6C5CE7"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"white",fontSize:"10",fontWeight:"bold",fontFamily:"sans-serif",children:"Ki"})]})),hasColor:!0},qwen:{Icon:tx((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"3",fill:"#615CED"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"white",fontSize:"9",fontWeight:"bold",fontFamily:"sans-serif",children:"QW"})]})),hasColor:!0},zai:{Icon:tx((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"3",fill:"#3859FF"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"white",fontSize:"9",fontWeight:"bold",fontFamily:"sans-serif",children:"ZP"})]})),hasColor:!0},cohere:{Icon:tx((0,n.jsx)("path",{d:"M4 8h16v2H4zm0 4h12v2H4zm0 4h8v2H4z",fill:"#3059B1"})),hasColor:!0},perplexity:{Icon:tx((0,n.jsx)("path",{d:"M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5",stroke:"#1DB954",strokeWidth:"1.5",fill:"none",strokeLinejoin:"round"})),hasColor:!0},together:{Icon:tx((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",fill:"#0F6CBD"}),"0 0 24 24"),hasColor:!0},grok:{Icon:tx((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),"0 0 24 24"),hasColor:!1}},tM=["openai-completions","openai-responses","anthropic-messages","google-generative-ai"];function tR({label:e,children:t}){return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("label",{style:{fontSize:11,color:"var(--text-muted)",fontWeight:500},children:e}),t]})}let tW={padding:"6px 9px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",fontSize:12,outline:"none",width:"100%",boxSizing:"border-box"};function tE({value:e,onChange:t,placeholder:r,mono:o}){return(0,n.jsx)("input",{value:e,onChange:e=>t(e.target.value),placeholder:r,style:{...tW,fontFamily:o?"var(--font-mono)":"inherit"}})}function tB({value:e,onChange:t,placeholder:r,mono:i,onKeyDown:l,autoComplete:s="off",spellCheck:a=!1,style:d}){let[c,u]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{e||u(!1)},[e]),(0,n.jsxs)("div",{style:{position:"relative",width:"100%",...d},children:[(0,n.jsx)("input",{type:c?"text":"password",value:e,onChange:e=>t(e.target.value),onKeyDown:l,placeholder:r,style:{...tW,paddingRight:34,fontFamily:i?"var(--font-mono)":"inherit"},autoComplete:s,spellCheck:a}),(0,n.jsx)("button",{type:"button",onClick:()=>u(e=>!e),"aria-label":c?"Hide API key":"Show API key",title:c?"Hide API key":"Show API key",style:{position:"absolute",right:5,top:"50%",transform:"translateY(-50%)",width:24,height:24,padding:0,border:"none",background:"transparent",color:"var(--text-dim)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},children:c?(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M17.94 17.94A10.94 10.94 0 0 1 12 20C7 20 2.73 16.89 1 12a18.45 18.45 0 0 1 5.06-6.94"}),(0,n.jsx)("path",{d:"M9.9 4.24A10.94 10.94 0 0 1 12 4c5 0 9.27 3.11 11 8a18.5 18.5 0 0 1-2.16 3.19"}),(0,n.jsx)("path",{d:"M14.12 14.12A3 3 0 0 1 9.88 9.88"}),(0,n.jsx)("path",{d:"M1 1l22 22"})]}):(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8S1 12 1 12Z"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})})]})}function t$({value:e,onChange:t,placeholder:r}){return(0,n.jsx)("input",{type:"number",value:e,onChange:e=>t(e.target.value),placeholder:r,style:tW})}function tF({value:e,onChange:t,options:r,required:o}){return(0,n.jsxs)("select",{value:e,onChange:e=>t(e.target.value),style:{...tW,color:e?"var(--text)":"var(--text-dim)"},children:[!o&&(0,n.jsx)("option",{value:"",children:"— inherit / none —"}),r.map(e=>(0,n.jsx)("option",{value:e,children:e},e))]})}function tP({label:e,checked:t,onChange:r}){return(0,n.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:6,cursor:"pointer",fontSize:12,color:"var(--text-muted)"},children:[(0,n.jsx)("input",{type:"checkbox",checked:t,onChange:e=>r(e.target.checked),style:{width:13,height:13,accentColor:"var(--accent)",cursor:"pointer"}}),e]})}function tA({children:e}){return(0,n.jsx)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:2},children:e})}function tD({name:e,provider:t,onChange:r,onRename:i,onDelete:l}){let[s,a]=(0,o.useState)(e);(0,o.useEffect)(()=>a(e),[e]);let d=(e,n)=>r({...t,[e]:n});return(0,o.useEffect)(()=>{t.api||r({...t,api:"openai-completions"})},[t.api]),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(tA,{children:"Provider"}),(0,n.jsx)("button",{onClick:l,style:{padding:"3px 8px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:4,color:"#ef4444",cursor:"pointer",fontSize:11},children:"Delete"})]}),(0,n.jsxs)(tR,{label:"Provider name",children:[(0,n.jsx)(tE,{value:s,onChange:a,placeholder:"provider-name",mono:!0}),s!==e&&s.trim()&&(0,n.jsx)("button",{onClick:()=>i(s.trim()),style:{marginTop:4,padding:"3px 10px",background:"var(--accent)",border:"none",borderRadius:4,color:"#fff",cursor:"pointer",fontSize:11,alignSelf:"flex-start"},children:"Rename"})]}),(0,n.jsx)(tR,{label:"Base URL",children:(0,n.jsx)(tE,{value:t.baseUrl??"",onChange:e=>d("baseUrl",e||void 0),placeholder:"https://api.example.com/v1",mono:!0})}),(0,n.jsxs)(tR,{label:"API Key",children:[(0,n.jsx)(tB,{value:t.apiKey??"",onChange:e=>d("apiKey",e||void 0),placeholder:"ENV_VAR_NAME, !shell-command, or literal key",mono:!0}),(0,n.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:["Prefix with ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)"},children:"!"})," to run a shell command, or use an env var name"]})]}),(0,n.jsx)(tR,{label:"API",children:(0,n.jsx)(tF,{value:t.api??"openai-completions",onChange:e=>d("api",e),options:tM,required:!0})})]})}let tH=["off","minimal","low","medium","high","xhigh"],tN={off:"var(--text-dim)",minimal:"#6b7280",low:"#60a5fa",medium:"#a78bfa",high:"#f472b6",xhigh:"#fb923c"};function tO({value:e,onChange:t}){let r=e??{},o=(e,n)=>{let o={...r};"omit"===n?delete o[e]:o[e]=n,t(Object.keys(o).length?o:void 0)};return(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:2},children:tH.map(e=>{let t=r[e],i=e in r?null===t?"null":"string":"omit",l="string"==typeof t?t:"",s=tN[e],a={padding:"4px 10px",fontSize:10,border:"none",cursor:"pointer",fontWeight:400,transition:"background 0.1s, color 0.1s",whiteSpace:"nowrap",background:"var(--bg-panel)",color:"var(--text-dim)"},d={background:"var(--accent)",color:"#fff",fontWeight:600};return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"5px 4px",borderRadius:6,background:"transparent",border:"1px solid transparent"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:5,width:68,flexShrink:0},children:[(0,n.jsx)("span",{style:{width:6,height:6,borderRadius:"50%",background:s,flexShrink:0,opacity:"null"===i?.3:1}}),(0,n.jsx)("span",{style:{fontSize:11,fontFamily:"var(--font-mono)",color:"null"===i?"var(--text-dim)":"var(--text-muted)",textDecoration:"null"===i?"line-through":"none"},children:e})]}),(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,border:"1px solid var(--border)",overflow:"hidden",flexShrink:0},children:[(0,n.jsx)("button",{onClick:()=>o(e,"omit"),style:{...a,..."omit"===i?d:{}},children:"Default"}),(0,n.jsx)("button",{onClick:()=>o(e,null),style:{...a,borderLeft:"1px solid var(--border)",..."null"===i?{background:"#ef4444",color:"#fff",fontWeight:600}:{}},children:"Disabled"})]}),(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,border:`1px solid ${"string"===i?"var(--accent)":"var(--border)"}`,overflow:"hidden",transition:"border-color 0.1s"},children:[(0,n.jsx)("button",{onClick:()=>o(e,l||e),style:{...a,..."string"===i?d:{},borderRight:"1px solid var(--border)",flexShrink:0},children:"Custom"}),(0,n.jsx)("input",{value:l,onChange:t=>o(e,t.target.value),onFocus:()=>{"string"!==i&&o(e,l||e)},placeholder:e,maxLength:10,style:{width:"12ch",background:"string"===i?"var(--bg)":"var(--bg-panel)",border:"none",outline:"none",color:"string"===i?"var(--text)":"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11,padding:"4px 7px",transition:"background 0.1s, color 0.1s"}})]})]},e)})})}let t_={thinkingFormat:"deepseek",requiresReasoningContentOnAssistantMessages:!0};function tU({providerName:e,provider:t,model:r,onChange:i,onDelete:l}){let[s,a]=(0,o.useState)({phase:"idle"}),d=(e,t)=>i({...r,[e]:t}),c=(()=>{if("idle"===s.phase)return null;if("testing"===s.phase)return"Testing model connection...";let e=[void 0!==s.latencyMs?`${s.latencyMs}ms`:null,void 0!==s.status?`HTTP ${s.status}`:null].filter(Boolean);return"success"===s.phase?["Connected",...e,s.responseText||null].filter(Boolean).join(" \xb7 "):["Failed",...e,s.message].filter(Boolean).join(" \xb7 ")})();(0,o.useEffect)(()=>{a({phase:"idle"})},[e,t.baseUrl,t.api,t.apiKey,r.id,r.api]);let u=(0,o.useCallback)(async()=>{if(r.id.trim()&&"testing"!==s.phase){a({phase:"testing"});try{let n=await fetch("/api/models-config/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerName:e,provider:t,model:r})}),o=await n.json();if(!n.ok||!o.ok)return void a({phase:"error",message:o.error??`HTTP ${n.status}`,latencyMs:o.latencyMs,status:o.status});a({phase:"success",latencyMs:o.latencyMs,status:o.status,responseText:o.responseText})}catch(e){a({phase:"error",message:e instanceof Error?e.message:String(e)})}}},[r,t,e,s.phase]);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(tA,{children:"Model"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[c&&(0,n.jsx)("span",{title:c,style:{maxWidth:260,height:24,padding:"0 8px",border:`1px solid ${"error"===s.phase?"#fecaca":"success"===s.phase?"#bbf7d0":"var(--border)"}`,borderRadius:4,background:"error"===s.phase?"#fee2e2":"success"===s.phase?"#dcfce7":"#e5e7eb",color:"#111827",fontSize:11,display:"inline-flex",alignItems:"center",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",boxSizing:"border-box"},children:c}),(0,n.jsxs)("button",{onClick:u,disabled:!r.id.trim()||"testing"===s.phase,title:"Test model connection",style:{height:24,padding:"0 8px",background:"success"===s.phase?"#16a34a":"none",border:`1px solid ${"success"===s.phase?"#16a34a":"var(--border)"}`,borderRadius:4,color:"success"===s.phase?"#fff":r.id.trim()&&"testing"!==s.phase?"var(--text-muted)":"var(--text-dim)",cursor:r.id.trim()&&"testing"!==s.phase?"pointer":"not-allowed",fontSize:11,display:"inline-flex",alignItems:"center",justifyContent:"center",boxSizing:"border-box",gap:5},children:["success"===s.phase&&(0,n.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}),"testing"===s.phase?"Testing…":"success"===s.phase?"OK":"Test"]}),(0,n.jsx)("button",{onClick:l,style:{height:24,padding:"0 8px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:4,color:"#ef4444",cursor:"pointer",fontSize:11,boxSizing:"border-box"},children:"Remove"})]})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[(0,n.jsx)(tR,{label:"ID *",children:(0,n.jsx)(tE,{value:r.id,onChange:e=>d("id",e),placeholder:"model-id",mono:!0})}),(0,n.jsx)(tR,{label:"Name",children:(0,n.jsx)(tE,{value:r.name??"",onChange:e=>d("name",e||void 0),placeholder:"Display name"})})]}),(0,n.jsx)(tR,{label:"API override",children:(0,n.jsx)(tF,{value:r.api??"",onChange:e=>d("api",e||void 0),options:tM})}),(0,n.jsxs)("div",{style:{display:"flex",gap:20,flexWrap:"wrap"},children:[(0,n.jsx)(tP,{label:"Reasoning / thinking",checked:r.reasoning??!1,onChange:e=>d("reasoning",e||void 0)}),(0,n.jsx)(tP,{label:"Image input",checked:r.input?.includes("image")??!1,onChange:e=>d("input",e?["text","image"]:void 0)})]}),r.reasoning&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(tP,{label:"DeepSeek thinking compat",checked:r.compat?.thinkingFormat==="deepseek",onChange:e=>i(function(e,t){if(t)return{...e,compat:{...e.compat??{},...t_}};if(!e.compat)return e;let r={...e.compat};return delete r.thinkingFormat,delete r.requiresReasoningContentOnAssistantMessages,{...e,compat:Object.keys(r).length?r:void 0}}(r,e))}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:8},children:[(0,n.jsx)(tA,{children:"Thinking level map"}),r.thinkingLevelMap&&(0,n.jsx)("button",{onClick:()=>d("thinkingLevelMap",void 0),style:{fontSize:10,padding:"2px 7px",background:"none",border:"1px solid var(--border)",borderRadius:4,color:"var(--text-dim)",cursor:"pointer"},children:"clear all"})]}),(0,n.jsx)(tO,{value:r.thinkingLevelMap,onChange:e=>d("thinkingLevelMap",e)})]})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[(0,n.jsx)(tR,{label:"Context window (tokens)",children:(0,n.jsx)(t$,{value:void 0!==r.contextWindow?String(r.contextWindow):"",onChange:e=>d("contextWindow",e?parseInt(e):void 0),placeholder:"128000"})}),(0,n.jsx)(tR,{label:"Max output tokens",children:(0,n.jsx)(t$,{value:void 0!==r.maxTokens?String(r.maxTokens):"",onChange:e=>d("maxTokens",e?parseInt(e):void 0),placeholder:"16384"})})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)(tA,{children:"Cost (per million tokens)"}),(0,n.jsx)("div",{style:{marginTop:8,display:"grid",gridTemplateColumns:"1fr 1fr 1fr 1fr",gap:8},children:["input","output","cacheRead","cacheWrite"].map(e=>(0,n.jsx)(tR,{label:e,children:(0,n.jsx)(t$,{value:r.cost?.[e]!==void 0?String(r.cost[e]):"",onChange:t=>{let n;return n=parseFloat(t),void i({...r,cost:{...r.cost??{},[e]:isNaN(n)?void 0:n}})},placeholder:"0"})},e))})]})]})}function tV({provider:e,onRefresh:t}){let[r,i]=(0,o.useState)({phase:"idle"}),[l,s]=(0,o.useState)(""),a=(0,o.useRef)(null),d=(0,o.useRef)(null);(0,o.useEffect)(()=>{("auth"===r.phase||"prompt"===r.phase)&&setTimeout(()=>d.current?.focus(),50)},[r.phase]),(0,o.useEffect)(()=>{i({phase:"idle"}),s(""),a.current?.close(),a.current=null},[e.id]),(0,o.useEffect)(()=>()=>{a.current?.close()},[]);let c=(0,o.useCallback)(()=>{a.current?.close(),i({phase:"connecting"}),s("");let r=new EventSource(`/api/auth/login/${encodeURIComponent(e.id)}`);a.current=r,r.onmessage=e=>{let n=JSON.parse(e.data);"auth"===n.type?(i({phase:"auth",url:n.url,instructions:n.instructions??null,token:n.token}),window.open(n.url,"_blank","noopener,noreferrer")):"device_code"===n.type?(i({phase:"device_code",userCode:n.userCode,verificationUri:n.verificationUri,intervalSeconds:n.intervalSeconds??null,expiresInSeconds:n.expiresInSeconds??null}),window.open(n.verificationUri,"_blank","noopener,noreferrer")):"prompt_request"===n.type?i({phase:"prompt",message:n.message,placeholder:n.placeholder??null,token:n.token}):"select_request"===n.type?i({phase:"select",message:n.message,options:n.options??[],token:n.token}):"progress"===n.type?i({phase:"progress",message:n.message}):"success"===n.type?(r.close(),i({phase:"success"}),t()):"error"===n.type?(r.close(),i({phase:"error",message:n.message})):"cancelled"===n.type&&(r.close(),i({phase:"idle"}))},r.onerror=()=>{r.close(),i(e=>"success"===e.phase?e:{phase:"error",message:"Connection lost"})}},[e.id,t]),u=(0,o.useCallback)(async()=>{await fetch(`/api/auth/logout/${encodeURIComponent(e.id)}`,{method:"POST"}),i({phase:"idle"}),t()},[e.id,t]),p=(0,o.useCallback)(async(t,r)=>{if(r.trim()){i({phase:"progress",message:"Verifying…"});try{let n=await fetch(`/api/auth/login/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:t,code:r.trim()})});if(!n.ok){let e=await n.json().catch(()=>({}));i({phase:"error",message:e.error??`Server error ${n.status}`});return}s("")}catch(e){i({phase:"error",message:e instanceof Error?e.message:"Network error"})}}},[e.id]),h=(0,o.useCallback)(async(t,r)=>{i({phase:"progress",message:"Continuing…"});try{let n=await fetch(`/api/auth/login/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:t,code:r})});if(!n.ok){let e=await n.json().catch(()=>({}));i({phase:"error",message:e.error??`Server error ${n.status}`})}}catch(e){i({phase:"error",message:e instanceof Error?e.message:"Network error"})}},[e.id]),x="connecting"===r.phase||"progress"===r.phase||"auth"===r.phase||"device_code"===r.phase||"prompt"===r.phase||"select"===r.phase;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(tA,{children:"Subscription"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:e.loggedIn?"#4ade80":"var(--border)",display:"inline-block"}}),(0,n.jsx)("span",{style:{fontSize:11,color:e.loggedIn?"#4ade80":"var(--text-dim)"},children:e.loggedIn?"connected":"not connected"})]})]}),(0,n.jsxs)("div",{style:{minHeight:48},children:["idle"===r.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:e.loggedIn?"Already connected. You can re-login or disconnect.":`Connect your ${e.name} account.`}),"connecting"===r.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)"},children:"Opening browser…"}),"select"===r.phase&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:r.message}),(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:r.options.map(e=>(0,n.jsx)("button",{onClick:()=>h(r.token,e.id),style:{padding:"6px 9px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",cursor:"pointer",fontSize:12,textAlign:"left"},children:e.label},e.id))})]}),("auth"===r.phase||"prompt"===r.phase)&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:"auth"===r.phase?"Complete sign-in in the browser, then copy the redirect URL from the address bar and paste it below.":r.message}),"auth"===r.phase&&(0,n.jsxs)("p",{style:{margin:0,fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:["If the browser window did not open,"," ",(0,n.jsx)("a",{href:r.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)",wordBreak:"break-all"},children:"click here to open the login page"}),"."]}),(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsx)("input",{ref:d,value:l,onChange:e=>s(e.target.value),onKeyDown:e=>{"Enter"===e.key&&p(r.token,l)},placeholder:"auth"===r.phase?"http://localhost:1455/auth/callback?code=…":r.placeholder??"Enter value…",style:{flex:1,padding:"6px 9px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",fontSize:12,outline:"none",fontFamily:"var(--font-mono)",boxSizing:"border-box"}}),(0,n.jsx)("button",{onClick:()=>p(r.token,l),disabled:!l.trim(),style:{padding:"6px 12px",background:l.trim()?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:5,color:l.trim()?"#fff":"var(--text-dim)",cursor:l.trim()?"pointer":"not-allowed",fontSize:12,fontWeight:600,flexShrink:0},children:"Submit"})]})]}),"device_code"===r.phase&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:"Open the verification page and enter this code:"}),(0,n.jsx)("div",{style:{padding:"8px 10px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",fontSize:16,fontWeight:700,fontFamily:"var(--font-mono)",letterSpacing:0},children:r.userCode}),(0,n.jsxs)("p",{style:{margin:0,fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:[(0,n.jsx)("a",{href:r.verificationUri,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)",wordBreak:"break-all"},children:r.verificationUri}),r.expiresInSeconds?` Expires in ${Math.ceil(r.expiresInSeconds/60)} minutes.`:""]})]}),"progress"===r.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)"},children:r.message}),"success"===r.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"#4ade80"},children:"Connected successfully."}),"error"===r.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"#f87171"},children:r.message})]}),(0,n.jsx)("div",{style:{display:"flex",gap:8},children:x?(0,n.jsx)("button",{onClick:()=>{a.current?.close(),i({phase:"idle"})},style:{padding:"5px 12px",background:"none",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Cancel"}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:c,style:{padding:"5px 14px",background:"var(--accent)",border:"none",borderRadius:5,color:"#fff",cursor:"pointer",fontSize:12,fontWeight:600},children:e.loggedIn?"Re-login":"Login"}),e.loggedIn&&(0,n.jsx)("button",{onClick:u,style:{padding:"5px 12px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:5,color:"#ef4444",cursor:"pointer",fontSize:12},children:"Disconnect"})]})})]})}function tK({provider:e,onRefresh:t}){let[r,i]=(0,o.useState)(""),[l,s]=(0,o.useState)(!1),[a,d]=(0,o.useState)(!1),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(!1);(0,o.useEffect)(()=>{i(""),u(null),h(!1)},[e.id]);let x=(0,o.useCallback)(async()=>{if(r.trim()){s(!0),u(null),h(!1);try{let n=await fetch(`/api/auth/api-key/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:r.trim()})}),o=await n.json();!n.ok||o.error?u(o.error??`HTTP ${n.status}`):(i(""),h(!0),setTimeout(()=>h(!1),2e3),t())}catch(e){u(String(e))}finally{s(!1)}}},[r,e.id,t]),g=(0,o.useCallback)(async()=>{d(!0),u(null);try{let r=await fetch(`/api/auth/api-key/${encodeURIComponent(e.id)}`,{method:"DELETE"}),n=await r.json();!r.ok||n.error?u(n.error??`HTTP ${r.status}`):t()}catch(e){u(String(e))}finally{d(!1)}},[e.id,t]);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(tA,{children:"API Key"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:e.configured?"#4ade80":"var(--border)",display:"inline-block"}}),(0,n.jsx)("span",{style:{fontSize:11,color:e.configured?"#4ade80":"var(--text-dim)"},children:e.configured?"configured":"not configured"})]})]}),(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:e.configured?"API key is stored. Enter a new key below to replace it, or disconnect to remove it.":`Enter your ${e.displayName} API key to enable ${e.modelCount} model${1!==e.modelCount?"s":""}.`}),(0,n.jsx)(tR,{label:"API Key",children:(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsx)(tB,{value:r,onChange:i,onKeyDown:e=>{"Enter"===e.key&&r.trim()&&x()},placeholder:e.configured?"Enter new key to replace…":"sk-…",style:{flex:1},autoComplete:"off",spellCheck:!1,mono:!0}),(0,n.jsxs)("button",{onClick:x,disabled:l||!r.trim()||p,style:{padding:"6px 12px",background:p?"#16a34a":r.trim()?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:5,color:r.trim()||p?"#fff":"var(--text-dim)",cursor:l||!r.trim()||p?"not-allowed":"pointer",fontSize:12,fontWeight:600,flexShrink:0,display:"flex",alignItems:"center",gap:5},children:[p&&(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}),p?"Saved":l?"Saving…":"Save"]})]})}),c&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"#f87171"},children:c}),e.configured&&(0,n.jsx)("button",{onClick:g,disabled:a,style:{alignSelf:"flex-start",padding:"5px 12px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:5,color:"#ef4444",cursor:a?"not-allowed":"pointer",fontSize:12},children:a?"Removing…":"Disconnect"})]})}function tY({id:e,size:t}){let r=tI[e];return r?r.hasColor?(0,n.jsx)(r.Icon,{size:t}):(0,n.jsx)(r.Icon,{size:t,style:{color:"var(--text-muted)"}}):null}function tq({oauthProviders:e,apiKeyProviders:t,onSelectOAuth:r,onSelectApiKey:i,onAddCustom:l,onClose:s}){let[a,d]=(0,o.useState)(""),c=(0,o.useRef)(null);(0,o.useEffect)(()=>{setTimeout(()=>c.current?.focus(),30)},[]);let u=a.trim().toLowerCase(),p=e.filter(e=>!e.loggedIn&&(!u||e.name.toLowerCase().includes(u))),h=t.filter(e=>!e.configured&&(!u||e.displayName.toLowerCase().includes(u)||e.id.toLowerCase().includes(u))),x=!u||"custom".includes(u)||"openai-compatible".includes(u)||"anthropic-compatible".includes(u),g=p.length+h.length+ +!!x,f={display:"flex",flexDirection:"row",alignItems:"center",gap:8,padding:"10px 12px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:7,boxSizing:"border-box",cursor:"pointer",minWidth:0,textAlign:"left",transition:"border-color 0.12s, background 0.12s",width:"100%"};return(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1100,background:"rgba(0,0,0,0.4)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:e=>{e.target===e.currentTarget&&s()},children:(0,n.jsxs)("div",{style:{width:820,maxWidth:"calc(100vw - 32px)",maxHeight:"min(72vh, calc(100vh - 32px))",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.22)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:"10px 14px",borderBottom:"1px solid var(--border)",flexShrink:0,display:"flex",alignItems:"center",gap:8},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0},children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,n.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),(0,n.jsx)("input",{ref:c,value:a,onChange:e=>d(e.target.value),onKeyDown:e=>{"Escape"===e.key&&s()},placeholder:"Search providers…",style:{flex:1,background:"none",border:"none",outline:"none",color:"var(--text)",fontSize:13,boxSizing:"border-box"}})]}),(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",padding:14},children:0===g?(0,n.jsx)("div",{style:{padding:"20px 0",fontSize:12,color:"var(--text-dim)",textAlign:"center"},children:"No providers match"}):(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(min(240px, 100%), 1fr))",gap:8},children:[x&&(0,n.jsx)("div",{style:{gridColumn:"1 / -1",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Custom"}),x&&(0,n.jsxs)("button",{onClick:()=>{l(),s()},style:f,onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.background="var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"OpenAI / Anthropic compatible"}),(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:"Custom endpoint format"})]}),(0,n.jsx)("span",{style:{width:26,height:26,borderRadius:5,background:"var(--bg-hover)",border:"1px dashed var(--border)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)"},children:[(0,n.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,n.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})})]}),p.length>0&&(0,n.jsx)("div",{style:{gridColumn:"1 / -1",paddingTop:6*!!x,fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Subscriptions"}),p.map(e=>(0,n.jsxs)("button",{onClick:()=>{r(e.id),s()},style:f,onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.background="var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:"OAuth"})]}),(0,n.jsx)(tY,{id:e.id,size:28})]},e.id)),h.length>0&&(0,n.jsx)("div",{style:{gridColumn:"1 / -1",paddingTop:6*(p.length>0),fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"API Key"}),h.map(e=>(0,n.jsxs)("button",{onClick:()=>{i(e.id),s()},style:f,onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.background="var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.displayName}),(0,n.jsxs)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:[e.modelCount," models"]})]}),(0,n.jsx)(tY,{id:e.id,size:28})]},e.id))]})})]})})}function tJ({onClose:e}){let[t,r]=(0,o.useState)({providers:{}}),[i,l]=(0,o.useState)(!0),[s,a]=(0,o.useState)(!1),[d,c]=(0,o.useState)(null),[u,p]=(0,o.useState)(!1),[h,x]=(0,o.useState)(null),[g,f]=(0,o.useState)([]),[m,v]=(0,o.useState)([]),[y,b]=(0,o.useState)(!1),j=(0,o.useCallback)(()=>{fetch("/api/auth/providers").then(e=>e.json()).then(e=>f(e.providers)).catch(()=>{})},[]),k=(0,o.useCallback)(()=>{fetch("/api/auth/all-providers").then(e=>e.json()).then(e=>v(e.providers)).catch(()=>{})},[]);(0,o.useEffect)(()=>{fetch("/api/models-config").then(e=>e.json()).then(e=>{let t=e.providers?e:{...e,providers:{}};r(t);let n=Object.keys(t.providers??{});n.length>0&&x({type:"provider",name:n[0]})}).catch(()=>r({providers:{}})).finally(()=>l(!1)),j(),k()},[j,k]);let w=(0,o.useCallback)(()=>{let e="new-provider",n=1;for(;t.providers?.[e];)e=`new-provider-${n++}`;r(t=>({...t,providers:{...t.providers??{},[e]:{api:"openai-completions"}}})),x({type:"provider",name:e})},[t.providers]),S=(0,o.useCallback)((e,t)=>{r(r=>({...r,providers:{...r.providers??{},[e]:t}}))},[]),C=(0,o.useCallback)((e,t)=>{r(r=>{let n=Object.entries(r.providers??{}),o=n.findIndex(([t])=>t===e);return -1===o?r:(n[o]=[t,n[o][1]],{...r,providers:Object.fromEntries(n)})}),x(r=>r?"provider"===r.type&&r.name===e?{type:"provider",name:t}:"model"===r.type&&r.providerName===e?{...r,providerName:t}:r:r)},[]),z=(0,o.useCallback)(e=>{r(t=>{let r={...t.providers??{}};return delete r[e],{...t,providers:r}}),r(e=>{let t=Object.keys(e.providers??{});return x(t.length>0?{type:"provider",name:t[0]}:null),e})},[]),L=(0,o.useCallback)(e=>{r(t=>{let r=t.providers?.[e]??{},n=[...r.models??[],{id:""}];return{...t,providers:{...t.providers??{},[e]:{...r,models:n}}}}),r(t=>{let r=(t.providers?.[e]?.models?.length??1)-1;return x({type:"model",providerName:e,index:r}),t})},[]),T=(0,o.useCallback)((e,t,n)=>{r(r=>{let o=r.providers?.[e]??{},i=[...o.models??[]];return i[t]=n,{...r,providers:{...r.providers??{},[e]:{...o,models:i}}}})},[]),I=(0,o.useCallback)((e,t)=>{r(r=>{let n=r.providers?.[e]??{},o=[...n.models??[]];return o.splice(t,1),{...r,providers:{...r.providers??{},[e]:{...n,models:o.length?o:void 0}}}}),x({type:"provider",name:e})},[]),M=(0,o.useCallback)(async()=>{a(!0),c(null),p(!1);try{let e=await fetch("/api/models-config",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),r=await e.json();!e.ok||r.error?c(r.error??`HTTP ${e.status}`):(p(!0),setTimeout(()=>p(!1),2e3))}catch(e){c(String(e))}finally{a(!1)}},[t]),R=Object.entries(t.providers??{}),W=g.filter(e=>e.loggedIn),E=m.filter(e=>e.configured),B=(()=>{if(!h)return null;if("oauth"===h.type){let e=g.find(e=>e.id===h.providerId);return e?(0,n.jsx)(tV,{provider:e,onRefresh:j},e.id):null}if("apikey"===h.type){let e=m.find(e=>e.id===h.providerId);return e?(0,n.jsx)(tK,{provider:e,onRefresh:k},e.id):null}if("provider"===h.type){let e=t.providers?.[h.name];return e?(0,n.jsx)(tD,{name:h.name,provider:e,onChange:e=>S(h.name,e),onRename:e=>C(h.name,e),onDelete:()=>z(h.name)},h.name):null}let e=t.providers?.[h.providerName],r=e?.models?.[h.index];return r?(0,n.jsx)(tU,{providerName:h.providerName,provider:e,model:r,onChange:e=>T(h.providerName,h.index,e),onDelete:()=>I(h.providerName,h.index)},`${h.providerName}-${h.index}`):null})();return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:t=>{t.target===t.currentTarget&&e()},children:(0,n.jsxs)("div",{style:{width:860,height:"78vh",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.18)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 18px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10},children:[(0,n.jsx)("span",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:"Models"}),(0,n.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:"~/.pi/agent/models.json"})]}),(0,n.jsx)("button",{onClick:e,style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),(0,n.jsxs)("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{width:210,borderRight:"1px solid var(--border)",display:"flex",flexDirection:"column",flexShrink:0,background:"var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,overflowY:"auto",padding:"8px 6px"},children:[W.map(e=>{let t=h?.type==="oauth"&&h.providerId===e.id;return(0,n.jsxs)("div",{onClick:()=>x({type:"oauth",providerId:e.id}),style:{display:"flex",alignItems:"center",gap:7,padding:"5px 8px",borderRadius:5,cursor:"pointer",background:t?"var(--bg-selected)":"none"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,n.jsx)(tY,{id:e.id,size:16}),(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name})]},e.id)}),E.map(e=>{let t=h?.type==="apikey"&&h.providerId===e.id;return(0,n.jsxs)("div",{onClick:()=>x({type:"apikey",providerId:e.id}),style:{display:"flex",alignItems:"center",gap:7,padding:"5px 8px",borderRadius:5,cursor:"pointer",background:t?"var(--bg-selected)":"none"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,n.jsx)(tY,{id:e.id,size:16}),(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.displayName})]},e.id)}),(W.length>0||E.length>0)&&R.length>0&&(0,n.jsx)("div",{style:{margin:"4px 8px",borderTop:"1px solid var(--border)"}}),i?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:"Loading…"}):R.map(([e,t])=>{let r=h?.type==="provider"&&h.name===e,o=t.models??[];return(0,n.jsxs)("div",{style:{marginBottom:2},children:[(0,n.jsxs)("div",{onClick:()=>x({type:"provider",name:e}),style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,cursor:"pointer",background:r?"var(--bg-selected)":"none"},onMouseEnter:e=>{r||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{r||(e.currentTarget.style.background="none")},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0},children:[(0,n.jsx)("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),(0,n.jsx)("rect",{x:"9",y:"9",width:"6",height:"6"}),(0,n.jsx)("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),(0,n.jsx)("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),(0,n.jsx)("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),(0,n.jsx)("line",{x1:"15",y1:"20",x2:"15",y2:"23"}),(0,n.jsx)("line",{x1:"20",y1:"9",x2:"23",y2:"9"}),(0,n.jsx)("line",{x1:"20",y1:"14",x2:"23",y2:"14"}),(0,n.jsx)("line",{x1:"1",y1:"9",x2:"4",y2:"9"}),(0,n.jsx)("line",{x1:"1",y1:"14",x2:"4",y2:"14"})]}),(0,n.jsx)("span",{style:{fontSize:12,fontWeight:r?600:400,color:"var(--text)",fontFamily:"var(--font-mono)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e})]}),o.map((t,r)=>{let o=h?.type==="model"&&h.providerName===e&&h.index===r;return(0,n.jsxs)("div",{onClick:()=>x({type:"model",providerName:e,index:r}),style:{display:"flex",alignItems:"center",gap:6,padding:"5px 8px 5px 26px",borderRadius:5,cursor:"pointer",background:o?"var(--bg-selected)":"none"},onMouseEnter:e=>{o||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{o||(e.currentTarget.style.background="none")},children:[(0,n.jsx)("span",{style:{fontSize:11,fontFamily:"var(--font-mono)",color:t.id?"var(--text-muted)":"var(--text-dim)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.id||"new model"}),t.reasoning&&(0,n.jsx)("span",{style:{fontSize:9,padding:"1px 4px",background:"rgba(99,102,241,0.12)",color:"rgba(99,102,241,0.8)",borderRadius:3,flexShrink:0},children:"T"})]},r)}),(0,n.jsx)("div",{onClick:t=>{t.stopPropagation(),L(e)},style:{display:"flex",alignItems:"center",gap:4,padding:"4px 8px 4px 26px",borderRadius:5,cursor:"pointer",color:"var(--text-dim)"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)",e.currentTarget.style.background="none"},children:(0,n.jsx)("span",{style:{fontSize:11},children:"+ model"})})]},e)})]}),(0,n.jsx)("div",{style:{borderTop:"1px solid var(--border)",padding:"8px 6px"},children:(0,n.jsx)("button",{onClick:()=>b(!0),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,width:"100%",padding:"6px 0",background:"none",border:"1px dashed var(--border)",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",fontSize:12},onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.color="var(--text-muted)"},children:"+ Add provider"})})]}),(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:i?null:B??(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:"Select a provider or model"})})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:10,padding:"10px 18px",borderTop:"1px solid var(--border)",flexShrink:0},children:[d&&(0,n.jsx)("span",{style:{fontSize:12,color:"#f87171",flex:1},children:d}),(0,n.jsx)("button",{onClick:e,style:{padding:"6px 14px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:13},children:"Cancel"}),(0,n.jsxs)("button",{onClick:M,disabled:s||u,style:{position:"relative",padding:"6px 16px",minWidth:92,background:u?"#16a34a":s?"var(--bg-panel)":"var(--accent)",border:"none",borderRadius:6,color:u?"#fff":s?"var(--text-muted)":"#fff",cursor:s||u?"default":"pointer",fontSize:13,fontWeight:600,display:"inline-flex",alignItems:"center",justifyContent:"center",gap:6,transition:"background-color 0.2s ease, color 0.2s ease",animation:u?"saved-pop 0.45s ease":void 0},children:[u&&(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",style:{strokeDasharray:18,animation:"saved-check-draw 0.35s ease forwards",flexShrink:0},children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}),(0,n.jsx)("span",{children:u?"Saved":s?"Saving…":"Save"})]})]})]})}),y&&(0,n.jsx)(tq,{oauthProviders:g,apiKeyProviders:m,onSelectOAuth:e=>x({type:"oauth",providerId:e}),onSelectApiKey:e=>x({type:"apikey",providerId:e}),onAddCustom:w,onClose:()=>b(!1)})]})}function tZ(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function tG(e){let t=e.sourceInfo?.source,r=e.sourceInfo?.scope;return"user"===r||"user"===t?"global":"project"===r||"project"===t?"project":"path"}function tX({enabled:e,loading:t,onToggle:r}){return(0,n.jsx)("button",{onClick:r,disabled:t,title:e?"Visible in model prompt — click to disable":"Hidden from model prompt — click to enable",style:{flexShrink:0,width:40,height:22,borderRadius:11,border:"none",padding:0,cursor:t?"wait":"pointer",background:e?"var(--accent)":"var(--border)",position:"relative",transition:"background 0.18s",outline:"none"},children:(0,n.jsx)("span",{style:{position:"absolute",top:3,left:e?21:3,width:16,height:16,borderRadius:"50%",background:"var(--bg)",boxShadow:"0 1px 4px rgba(0,0,0,0.22)",transition:"left 0.18s cubic-bezier(.4,0,.2,1)"}})})}function tQ({skill:e,cwd:t,onToggle:r,toggling:o,saveError:i}){let l=tG(e),s=!e.disableModelInvocation;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:20},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:7},children:[(0,n.jsx)("span",{style:{fontSize:10,padding:"1px 5px",borderRadius:3,flexShrink:0,background:"project"===l?"rgba(99,102,241,0.12)":"rgba(120,120,120,0.12)",color:"project"===l?"rgba(99,102,241,0.8)":"var(--text-dim)"},children:l}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:function(e){if("project"===l&&e.startsWith(t)){let r=e.slice(t.length).replace(/^[/\\]/,"");return`./${r}`}return tZ(e)}(e.filePath)}),(0,n.jsx)(tX,{enabled:s,loading:o,onToggle:()=>r(e)}),i&&(0,n.jsx)("span",{style:{fontSize:12,color:"#f87171",flexShrink:0},children:i})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:"Name"}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:14,color:"var(--text)"},children:e.name})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:"Description"}),(0,n.jsx)("span",{style:{fontSize:14,color:"var(--text-muted)",lineHeight:1.6},children:e.description})]})]})}function t0({cwd:e,onInstalled:t}){let[r,i]=(0,o.useState)(""),[l,s]=(0,o.useState)([]),[a,d]=(0,o.useState)(!1),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(null),[x,g]=(0,o.useState)(null),[f,m]=(0,o.useState)(new Set),[v,y]=(0,o.useState)("global"),b=(0,o.useRef)(null);(0,o.useEffect)(()=>{b.current?.focus()},[]);let j=(0,o.useCallback)(async e=>{if(e.trim()){d(!0),u(null),s([]);try{let t=await fetch("/api/skills/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:e.trim()})}),r=await t.json();if(r.error)return void u(r.error);s(r.results??[]),0===(r.results??[]).length&&u("No skills found")}catch(e){u(String(e))}finally{d(!1)}}},[]),k=(0,o.useCallback)(async r=>{h(r),g(null);try{let n=await fetch("/api/skills/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({package:r,scope:v,cwd:e})}),o=await n.json();if(!n.ok||o.error)return void g(o.error??`HTTP ${n.status}`);m(e=>new Set(e).add(r)),t()}catch(e){g(String(e))}finally{h(null)}},[t,v,e]),w="global"===v?"~/.pi/agent/skills/":`${tZ(e)}/.pi/agent/skills/`;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,marginBottom:20},children:[(0,n.jsx)("div",{style:{fontSize:14,fontWeight:600,color:"var(--text)"},children:"Add Skill"}),(0,n.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,n.jsx)("input",{ref:b,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{"Enter"===e.key&&j(r)},placeholder:"e.g. react, testing, deploy",style:{flex:1,padding:"7px 10px",fontSize:13,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",outline:"none"}}),(0,n.jsx)("button",{onClick:()=>j(r),disabled:a||!r.trim(),style:{padding:"7px 16px",fontSize:13,borderRadius:6,border:"none",background:"var(--accent)",color:"#fff",cursor:a||!r.trim()?"not-allowed":"pointer",opacity:a||!r.trim()?.5:1,flexShrink:0},children:a?"Searching…":"Search"})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10},children:[(0,n.jsx)("div",{style:{display:"flex",borderRadius:5,border:"1px solid var(--border)",overflow:"hidden",fontSize:12,flexShrink:0},children:["global","project"].map(e=>(0,n.jsx)("button",{onClick:()=>y(e),style:{padding:"3px 10px",border:"none",cursor:"pointer",background:v===e?"var(--bg-selected)":"none",color:v===e?"var(--text)":"var(--text-dim)",fontWeight:v===e?600:400,borderRight:"global"===e?"1px solid var(--border)":"none"},children:e},e))}),(0,n.jsxs)("span",{style:{fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["→ ",w]})]}),c&&(0,n.jsx)("div",{style:{fontSize:12,color:"#f87171"},children:c}),x&&(0,n.jsx)("div",{style:{fontSize:12,color:"#f87171",wordBreak:"break-word"},children:x})]}),l.length>0?(0,n.jsx)("div",{style:{flex:1,overflowY:"auto"},children:l.map(e=>{let t=f.has(e.package),r=p===e.package,o=e.package.indexOf("@"),i=o>-1?e.package.slice(0,o):e.package,l=o>-1?e.package.slice(o+1):null;return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:14,padding:"12px 0",borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)",marginBottom:3},children:l??i}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)"},children:i}),(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:e.installs}),e.url&&(0,n.jsx)("a",{href:e.url,target:"_blank",rel:"noreferrer",style:{fontSize:12,color:"var(--accent)",textDecoration:"none"},children:"skills.sh ↗"})]})]}),(0,n.jsx)("button",{onClick:()=>!t&&!r&&k(e.package),disabled:t||r||null!==p,style:{flexShrink:0,padding:"5px 14px",fontSize:12,fontWeight:500,borderRadius:5,border:"1px solid var(--border)",cursor:t||r||null!==p?"not-allowed":"pointer",background:t?"rgba(34,197,94,0.1)":"none",color:t?"#16a34a":r?"var(--accent)":"var(--text-muted)",transition:"color 0.12s"},children:t?"✓ Installed":r?"Installing…":"Install"})]},e.package)})}):!c&&!a&&(0,n.jsxs)("div",{style:{fontSize:13,color:"var(--text-dim)",lineHeight:1.8},children:["Search"," ",(0,n.jsx)("a",{href:"https://skills.sh",target:"_blank",rel:"noreferrer",style:{color:"var(--accent)",textDecoration:"none"},children:"skills.sh"})," ","to discover and install skills for your agent."]})]})}function t1({cwd:e,onClose:t}){let[r,i]=(0,o.useState)([]),[l,s]=(0,o.useState)(!0),[a,d]=(0,o.useState)(null),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(new Set),[x,g]=(0,o.useState)(null),[f,m]=(0,o.useState)(!1),v=(0,o.useCallback)(()=>{s(!0),d(null),fetch(`/api/skills?cwd=${encodeURIComponent(e)}`).then(e=>e.json()).then(e=>{if(e.error)return void d(e.error);let t=e.skills??[];i(t),t.length>0&&!c&&u(t[0].filePath)}).catch(e=>d(String(e))).finally(()=>s(!1))},[e,c]);(0,o.useEffect)(()=>{v()},[e]);let y=(0,o.useCallback)(async e=>{let t=!e.disableModelInvocation;h(t=>new Set(t).add(e.filePath)),g(null);try{let r=await fetch("/api/skills",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({filePath:e.filePath,disableModelInvocation:t})}),n=await r.json();if(!r.ok||n.error)return void g(n.error??`HTTP ${r.status}`);i(r=>r.map(r=>r.filePath===e.filePath?{...r,disableModelInvocation:t}:r))}catch(e){g(String(e))}finally{h(t=>{let r=new Set(t);return r.delete(e.filePath),r})}},[]),b=r.find(e=>e.filePath===c)??null;return(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:e=>{e.target===e.currentTarget&&t()},children:(0,n.jsxs)("div",{style:{width:860,height:"78vh",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.18)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 18px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10},children:[(0,n.jsx)("span",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:"Skills"}),(0,n.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)",maxWidth:320,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:tZ(e)})]}),(0,n.jsx)("button",{onClick:t,style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),(0,n.jsxs)("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{width:210,borderRight:"1px solid var(--border)",display:"flex",flexDirection:"column",flexShrink:0,background:"var(--bg-panel)"},children:[(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",padding:"8px 6px"},children:l?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:"Loading…"}):a?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"#f87171"},children:a}):0===r.length?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"var(--text-dim)"},children:"No skills found"}):(()=>{let e=[];for(let t of["project","global","path"]){let n=r.filter(e=>tG(e)===t);n.length>0&&e.push({label:t,skills:n})}return e.map(({label:e,skills:t})=>(0,n.jsxs)("div",{style:{marginBottom:6},children:[(0,n.jsx)("div",{style:{padding:"4px 8px 3px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.06em"},children:e}),t.map(e=>{let t=!f&&c===e.filePath,r=e.disableModelInvocation;return(0,n.jsxs)("div",{onClick:()=>{u(e.filePath),m(!1)},style:{display:"flex",alignItems:"center",gap:7,padding:"8px 8px",borderRadius:5,cursor:"pointer",background:t?"var(--bg-selected)":"none"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,n.jsx)("span",{style:{flexShrink:0,width:7,height:7,borderRadius:"50%",background:r?"var(--border)":"var(--accent)",boxShadow:r?"none":"0 0 4px var(--accent)",transition:"background 0.15s, box-shadow 0.15s"}}),(0,n.jsx)("span",{style:{fontSize:12,fontWeight:t?600:400,color:r?"var(--text-dim)":"var(--text)",fontFamily:"var(--font-mono)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name})]},e.filePath)})]},e))})()}),(0,n.jsx)("div",{style:{padding:"8px 6px",borderTop:"1px solid var(--border)",flexShrink:0},children:(0,n.jsxs)("div",{onClick:()=>m(!0),style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,cursor:"pointer",background:f?"var(--bg-selected)":"none",color:f?"var(--accent)":"var(--text-dim)",fontSize:12},onMouseEnter:e=>{f||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{f||(e.currentTarget.style.background="none")},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,n.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),"Add skill"]})})]}),(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:f?(0,n.jsx)(t0,{cwd:e,onInstalled:()=>{v()}}):l?null:b?(0,n.jsx)(tQ,{skill:b,cwd:e,onToggle:y,toggling:p.has(b.filePath),saveError:x},b.filePath):(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:"Select a skill"})})]}),(0,n.jsx)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",padding:"10px 18px",borderTop:"1px solid var(--border)",flexShrink:0},children:(0,n.jsx)("button",{onClick:t,style:{padding:"6px 14px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:13},children:"Close"})})]})})}function t2(e){let t=e,r=0;for(;1===t.children.length;)t=t.children[0],r++;return{node:t,skipped:r}}function t4({node:e,activePathIds:t,depth:r,isLast:o,parentLines:i,onSelect:l}){let{node:s,skipped:a}=t2(e),d=t.has(s.entry.id),c=t.has(e.entry.id)||t.has(s.entry.id),u=function(e){if("message"===e.type&&"message"in e){let t=e.message,r=t.content,n="";if("string"==typeof r?n=r:Array.isArray(r)&&(n=r.filter(e=>"text"===e.type).map(e=>e.text).join(" ")),n.length>40&&(n=n.slice(0,40)+"…"),n)return n;if("assistant"===t.role)return"[assistant]"}return e.type}(s.entry),p="message"===s.entry.type&&"message"in s.entry?s.entry.message.role:null;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",height:24,cursor:"pointer"},onClick:()=>l(s.entry.id),children:[i.map((e,t)=>(0,n.jsx)("div",{style:{width:16,flexShrink:0,position:"relative",height:"100%",alignSelf:"stretch"},children:e&&(0,n.jsx)("div",{style:{position:"absolute",left:7,top:0,bottom:0,width:1,background:"var(--border)"}})},t)),(0,n.jsxs)("div",{style:{width:16,flexShrink:0,position:"relative",height:"100%",alignSelf:"stretch"},children:[(0,n.jsx)("div",{style:{position:"absolute",left:7,top:0,bottom:o?"50%":0,width:1,background:"var(--border)"}}),(0,n.jsx)("div",{style:{position:"absolute",left:7,top:"50%",width:9,height:1,background:"var(--border)"}})]}),(0,n.jsx)("div",{style:{width:7,height:7,borderRadius:"50%",flexShrink:0,background:d?"var(--accent)":c?"var(--text-muted)":"var(--border)",border:d?"none":"1px solid var(--text-dim)",marginRight:6,transition:"background 0.12s"}}),p&&(0,n.jsx)("span",{style:{fontSize:9,fontFamily:"var(--font-mono)",color:"user"===p?"var(--accent)":"var(--text-dim)",background:"user"===p?"rgba(37,99,235,0.08)":"var(--bg-hover)",border:`1px solid ${"user"===p?"rgba(37,99,235,0.2)":"var(--border)"}`,borderRadius:3,padding:"0 4px",marginRight:5,flexShrink:0,lineHeight:"16px"},children:"user"===p?"U":"A"}),a>0&&(0,n.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",marginRight:5,flexShrink:0},children:["+",a]}),(0,n.jsx)("span",{style:{fontSize:11,color:d?"var(--text)":c?"var(--text-muted)":"var(--text-dim)",fontWeight:d?500:400,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,minWidth:0},children:u})]}),s.children.map((e,a)=>(0,n.jsx)(t4,{node:e,activePathIds:t,depth:r+1,isLast:a===s.children.length-1,parentLines:[...i,!o],onSelect:l},e.entry.id))]})}function t5({tree:e,activeLeafId:t,onLeafChange:r,inline:i,containerRef:l,open:s,onToggle:a,hasSession:d}){let[c,u]=(0,o.useState)(!1),p=void 0!==s?s:c,h=(0,o.useRef)(null),[x,g]=(0,o.useState)(null);(0,o.useEffect)(()=>{if(!p||!i)return;let e=l?.current??h.current;if(!e)return;let t=()=>{let t=e.getBoundingClientRect();g({top:t.bottom,left:t.left,width:t.width})};t();let r=new ResizeObserver(t);return r.observe(e),()=>r.disconnect()},[p,i,l]);let f=(0,o.useMemo)(()=>t?new Set(function e(r,n){for(let o of r){let r=[...n,o.entry.id];if(o.entry.id===t)return r;let i=e(o.children,r);if(i)return i}return null}(e,[])??[]):new Set,[e,t]),m=(0,o.useCallback)(e=>{r(e)},[r]),v=d?!function e(t){for(let r of t)if(r.children.length>1||e(r.children))return!0;return!1}(e)?"This session has no branches":null:"No active session",y=e.length>0?t2(e[0]):null,b=y?.node??null,j=!v&&b&&b.children.length>1,k=(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:j?"var(--accent)":"var(--text-dim)",flexShrink:0},children:[(0,n.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),w=(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{marginLeft:2,transform:p?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})});return i?(0,n.jsxs)("div",{style:{height:"100%",display:"flex",alignItems:"stretch"},children:[(0,n.jsxs)("button",{ref:h,onClick:()=>a?a():u(e=>!e),style:{display:"flex",alignItems:"center",gap:6,height:"100%",padding:"0 12px",background:p?"var(--bg-selected)":"none",border:"none",borderTop:p?"2px solid var(--accent)":"2px solid transparent",borderRight:"1px solid var(--border)",cursor:"pointer",color:p?"var(--text)":"var(--text-muted)",fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color=p?"var(--text)":"var(--text-muted)"},children:[k,(0,n.jsx)("span",{children:"Branches"})]}),p&&x&&(0,n.jsx)("div",{style:{position:"fixed",top:x.top,left:x.left,width:x.width,background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",zIndex:500},children:j&&b?(0,n.jsx)("div",{style:{padding:"4px 12px 8px 12px",maxHeight:260,overflowY:"auto"},children:b.children.map((e,t)=>(0,n.jsx)(t4,{node:e,activePathIds:f,depth:0,isLast:t===b.children.length-1,parentLines:[],onSelect:m},e.entry.id))}):(0,n.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:v})})]}):(0,n.jsxs)("div",{style:{borderBottom:"1px solid var(--border)",background:"var(--bg)",flexShrink:0,position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>u(e=>!e),style:{display:"flex",alignItems:"center",gap:6,width:"100%",padding:"5px 12px",background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",fontSize:11,textAlign:"left"},children:[k,(0,n.jsx)("span",{style:{color:"var(--text-muted)"},children:"Branches"}),w]}),p&&(0,n.jsx)("div",{style:{position:"absolute",top:"100%",left:0,right:0,background:"var(--bg)",borderBottom:"1px solid var(--border)",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100},children:j&&b?(0,n.jsx)("div",{style:{padding:"4px 12px 8px 12px",maxHeight:260,overflowY:"auto"},children:b.children.map((e,t)=>(0,n.jsx)(t4,{node:e,activePathIds:f,depth:0,isLast:t===b.children.length-1,parentLines:[],onSelect:m},e.entry.id))}):(0,n.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:v??"This session has no branches"})})]})}function t6({initialWidth:e,minWidth:t,maxWidth:r,storageKey:n,direction:i="right"}){let l=(0,o.useRef)(e);return(0,o.useEffect)(()=>{try{let e=localStorage.getItem(n);if(e){let o=parseInt(e,10);!isNaN(o)&&o>=t&&o<=r&&(l.current=o,document.documentElement.style.setProperty(n,`${o}px`))}}catch{}},[n,t,r]),{handleMouseDown:(0,o.useCallback)(e=>{e.preventDefault();let o=e.clientX,s=l.current,a="left"===i?-1:1,d=e=>{let i=Math.max(t,Math.min(r,s+(e.clientX-o)*a));l.current=i,document.documentElement.style.setProperty(n,`${i}px`)},c=()=>{document.removeEventListener("mousemove",d),document.removeEventListener("mouseup",c),document.body.style.cursor="",document.body.style.userSelect="";try{localStorage.setItem(n,String(l.current))}catch{}};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",d),document.addEventListener("mouseup",c)},[t,r,n,i]),widthRef:l}}function t8(){let e=(0,i.useRouter)(),t=(0,i.useSearchParams)(),{isDark:r,toggleTheme:l}=eo(),[s,a]=(0,o.useState)(null),[d,c]=(0,o.useState)(null),[u,p]=(0,o.useState)(0),[h,x]=(0,o.useState)(0),[g,f]=(0,o.useState)(0),[m,v]=(0,o.useState)(!1),[y,b]=(0,o.useState)(0),[j,k]=(0,o.useState)(!1),[w,S]=(0,o.useState)(!0),C=t6({initialWidth:260,minWidth:180,maxWidth:500,storageKey:"--pi-sidebar-width"}),z=t6({initialWidth:500,minWidth:300,maxWidth:1200,storageKey:"--pi-right-panel-width",direction:"left"}),L=(0,o.useRef)(null),T=(0,o.useRef)(null),[I,M]=(0,o.useState)([]),[R,W]=(0,o.useState)(null),E=(0,o.useRef)(null),B=(0,o.useCallback)((e,t,r)=>{M(e),W(t),E.current=r},[]),$=(0,o.useCallback)(e=>{E.current?.(e)},[]),[F,P]=(0,o.useState)(null),A=(0,o.useRef)(null),D=(0,o.useCallback)(e=>{P(e)},[]),[H,N]=(0,o.useState)(null),O=(0,o.useCallback)(e=>{N(e)},[]),[_,U]=(0,o.useState)(null),V=(0,o.useCallback)(e=>{U(e)},[]),[K,q]=(0,o.useState)(null),[J,Z]=(0,o.useState)(null),G=(0,o.useCallback)(e=>{q(t=>t===e?null:e)},[]);(0,o.useEffect)(()=>{if(!K||!T.current)return;let e=()=>{let e=T.current.getBoundingClientRect();Z({top:e.bottom,left:e.left,width:e.width})};e();let t=new ResizeObserver(e);return t.observe(T.current),()=>t.disconnect()},[K]);let[X,Q]=(0,o.useState)([]),[ee,et]=(0,o.useState)(null),[er,en]=(0,o.useState)(!1),ei=(0,o.useCallback)(e=>{L.current?.insertText("`"+e+"`")},[]),[el]=(0,o.useState)(()=>t.get("session")),[es,ea]=(0,o.useState)(null),[ed,ec]=(0,o.useState)(()=>!t.get("session")),eu=(0,o.useRef)(!1),ep=(0,o.useCallback)(t=>{ea(t),t&&!eu.current&&(a(e=>e&&e.cwd!==t?null:e),c(e=>e&&e!==t?null:e),x(e=>e+1),f(e=>e+1),M([]),W(null),P(null),q(null),e.replace("/",{scroll:!1}))},[e]),eh=(0,o.useCallback)((t,r=!1)=>{c(null),a(t),x(e=>e+1),P(null),ec(!0),r&&(eu.current=!0,setTimeout(()=>{eu.current=!1},0)),r||e.replace(`?session=${encodeURIComponent(t.id)}`,{scroll:!1})},[e]),ex=(0,o.useCallback)((t,r)=>{a(null),c(r),x(e=>e+1),M([]),W(null),P(null),q(null),e.replace("/",{scroll:!1})},[e]),eg=(0,o.useCallback)(t=>{c(null),a(t),p(e=>e+1),e.replace(`?session=${encodeURIComponent(t.id)}`,{scroll:!1})},[e]),ef=(0,o.useCallback)(()=>{p(e=>e+1),f(e=>e+1)},[]),em=(0,o.useCallback)(t=>{p(e=>e+1),x(e=>e+1),c(null),a(e=>({...e??{path:"",cwd:"",created:"",modified:"",messageCount:0,firstMessage:""},id:t})),e.replace(`?session=${encodeURIComponent(t)}`,{scroll:!1})},[e]),ev=(0,o.useCallback)(()=>{ec(!0)},[]),ey=(0,o.useCallback)(t=>{if(p(e=>e+1),s?.id===t){let t=s.cwd;a(null),c(t??null),x(e=>e+1),M([]),W(null),P(null),q(null),e.replace("/",{scroll:!1})}},[s,e]),eb=(0,o.useCallback)((e,t)=>{let r=`file:${e}`;Q(n=>n.find(e=>e.id===r)?n:[...n,{id:r,label:t,filePath:e}]),et(r),en(!0)},[]),ej=(0,o.useCallback)(e=>{Q(t=>{let r=t.filter(t=>t.id!==e);return 0===r.length&&en(!1),r}),et(t=>{if(t!==e)return t;let r=X.filter(t=>t.id!==e);return r.length>0?r[r.length-1].id:null})},[X]),ek=d??(null===s&&es?es:null),ew=null!==s||null!==ek,eS=ed&&!ew,eC=X.find(e=>e.id===ee)??null,ez=(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(Y,{selectedSessionId:s?.id??null,onSelectSession:eh,onNewSession:ex,initialSessionId:el,onInitialRestoreDone:ev,refreshKey:u,onSessionDeleted:ey,selectedCwd:s?.cwd??d??null,onCwdChange:ep,onOpenFile:eb,explorerRefreshKey:g,onAtMention:ei}),(0,n.jsx)("div",{style:{padding:"8px",flexShrink:0,display:"flex",justifyContent:"space-between",gap:4},children:[{label:"Models",onClick:()=>v(!0),disabled:!1,icon:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"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"})]})},{label:"Skills",onClick:()=>k(!0),disabled:!es&&!s?.cwd&&!d,icon:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),(0,n.jsx)("path",{d:"M2 17l10 5 10-5"}),(0,n.jsx)("path",{d:"M2 12l10 5 10-5"})]})}].map(({label:e,onClick:t,disabled:r,icon:o})=>(0,n.jsxs)("button",{onClick:t,disabled:r,title:e,style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",gap:6,height:32,padding:0,background:"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:r?"default":"pointer",fontSize:12,opacity:r?.35:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{r||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:[o,e]},e))})]});return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{style:{display:"flex",height:"100dvh",overflow:"hidden",background:"var(--bg)"},children:[(0,n.jsx)("div",{className:"sidebar-overlay-backdrop",onClick:()=>S(!1),style:{position:"fixed",inset:0,zIndex:199,background:"rgba(0,0,0,0.4)",opacity:+!!w,pointerEvents:w?"auto":"none",transition:"opacity 0.25s ease"}}),(0,n.jsx)("div",{className:`sidebar-container${w?" sidebar-open":" sidebar-closed"}`,style:{background:"var(--bg-panel)",borderRight:"1px solid var(--border)",display:"flex",flexDirection:"column",flexShrink:0,zIndex:200,width:w?C.widthRef.current:0,minWidth:w?C.widthRef.current:0,transition:w?"none":void 0},children:ez}),w&&(0,n.jsx)("div",{className:"resize-handle",onMouseDown:C.handleMouseDown,style:{width:5,cursor:"col-resize",flexShrink:0,zIndex:201,marginLeft:-3,marginRight:-2,background:"transparent",transition:"background 0.15s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"}}),(0,n.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden",minWidth:0},children:[(0,n.jsxs)("div",{ref:T,style:{display:"flex",alignItems:"center",flexShrink:0,borderBottom:"1px solid var(--border)",height:36,background:"var(--bg-panel)"},children:[(0,n.jsx)("button",{onClick:()=>S(e=>!e),title:w?"Hide sidebar":"Show sidebar",style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"none",border:"none",borderRight:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)"},children:w?(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,n.jsx)("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]}):(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"3",y1:"6",x2:"21",y2:"6"}),(0,n.jsx)("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),(0,n.jsx)("line",{x1:"3",y1:"18",x2:"21",y2:"18"})]})}),(0,n.jsx)("button",{onClick:e=>{let t=e.currentTarget.getBoundingClientRect();l({x:t.left+t.width/2,y:t.top+t.height/2})},title:r?"Switch to light mode":"Switch to dark mode","aria-label":r?"Switch to light mode":"Switch to dark mode","aria-pressed":r,style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"none",border:"none",borderRight:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)"},children:r?(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"5"}),(0,n.jsx)("line",{x1:"12",y1:"1",x2:"12",y2:"3"}),(0,n.jsx)("line",{x1:"12",y1:"21",x2:"12",y2:"23"}),(0,n.jsx)("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"}),(0,n.jsx)("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"}),(0,n.jsx)("line",{x1:"1",y1:"12",x2:"3",y2:"12"}),(0,n.jsx)("line",{x1:"21",y1:"12",x2:"23",y2:"12"}),(0,n.jsx)("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"}),(0,n.jsx)("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"})]}):(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"})})}),ew&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"stretch",height:"100%"},children:[(0,n.jsx)(t5,{tree:I,activeLeafId:R,onLeafChange:$,inline:!0,containerRef:T,open:"branches"===K,onToggle:()=>G("branches"),hasSession:!0}),(0,n.jsxs)("button",{ref:A,onClick:()=>G("system"),style:{display:"flex",alignItems:"center",gap:6,height:"100%",padding:"0 12px",background:"system"===K?"var(--bg-selected)":"none",border:"none",borderTop:"system"===K?"2px solid var(--accent)":"2px solid transparent",borderRight:"1px solid var(--border)",cursor:"pointer",color:"system"===K?"var(--text)":"var(--text-muted)",fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="system"===K?"var(--text)":"var(--text-muted)"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:F?"var(--accent)":"var(--text-dim)",flexShrink:0},children:[(0,n.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,n.jsx)("polyline",{points:"14 2 14 8 20 8"}),(0,n.jsx)("line",{x1:"8",y1:"13",x2:"16",y2:"13"}),(0,n.jsx)("line",{x1:"8",y1:"17",x2:"13",y2:"17"})]}),(0,n.jsx)("span",{children:"System"})]})]}),ew&&(H||_)&&(()=>{let e=H?.tokens,t=H?.cost??0,r=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(0)}k`:String(e),o=t>0?t>=.01?`$${t.toFixed(2)}`:"<$0.01":null,i="var(--text-muted)",l=null;if(_?.contextWindow){let e=_.percent;null!==e&&e>90?i="#ef4444":null!==e&&e>70&&(i="rgba(234,179,8,0.95)"),l=null!==e?`${e.toFixed(0)}% / ${r(_.contextWindow)}`:`? / ${r(_.contextWindow)}`}let s=[];if(e&&(s.push(`in: ${e.input.toLocaleString()}`),s.push(`out: ${e.output.toLocaleString()}`),s.push(`cache read: ${e.cacheRead.toLocaleString()}`),s.push(`cache write: ${e.cacheWrite.toLocaleString()}`),t>0&&s.push(`cost: $${t.toFixed(4)}`)),_?.contextWindow){let e=_.percent;s.push(`context: ${null!==e?e.toFixed(1)+"%":"unknown"} of ${_.contextWindow.toLocaleString()} tokens`)}let a=s.join(" | ");return(0,n.jsxs)("div",{title:a,style:{marginLeft:"auto",display:"flex",alignItems:"center",gap:10,paddingLeft:12,paddingRight:er?12:48,height:"100%",fontSize:11,color:"var(--text-muted)",whiteSpace:"nowrap",cursor:"default",fontVariantNumeric:"tabular-nums"},children:[e&&e.input>0&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"5",y1:"8.5",x2:"5",y2:"1.5"}),(0,n.jsx)("polyline",{points:"2 4 5 1.5 8 4"})]}),r(e.input)]}),e&&e.output>0&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"5",y1:"1.5",x2:"5",y2:"8.5"}),(0,n.jsx)("polyline",{points:"2 6 5 8.5 8 6"})]}),r(e.output)]}),e&&e.cacheRead>0&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M8.5 5a3.5 3.5 0 1 1-1-2.45"}),(0,n.jsx)("polyline",{points:"6.5 1.5 8.5 2.5 7.5 4.5"})]}),r(e.cacheRead)]}),o&&(0,n.jsx)("span",{style:{display:"flex",alignItems:"center",color:"var(--text)",fontWeight:500},children:o}),l&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4,color:i},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M1 9 L1 5 Q1 1 5 1 Q9 1 9 5 L9 9"}),(0,n.jsx)("line",{x1:"1",y1:"9",x2:"9",y2:"9"})]}),l]})]})})(),K&&J&&(0,n.jsx)("div",{style:{position:"fixed",top:J.top,left:J.left,width:J.width,zIndex:500},children:"system"===K&&(0,n.jsx)("div",{style:{background:"var(--bg-panel)",borderBottom:"1px solid var(--border)"},children:F?(0,n.jsx)("div",{style:{maxHeight:"min(600px, 75vh)",overflowY:"auto",padding:"12px 16px",color:"var(--text-muted)",fontSize:12,lineHeight:1.6,whiteSpace:"pre-wrap",fontFamily:"var(--font-mono)"},children:F}):""===F?(0,n.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:"System prompt is empty (tools are disabled)"}):(0,n.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:"Send a message to load the system prompt"})})})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"hidden",position:"relative"},children:ew?(0,n.jsx)(eF,{session:s,newSessionCwd:ek,onAgentEnd:ef,onSessionCreated:eg,onSessionForked:em,modelsRefreshKey:y,chatInputRef:L,onBranchDataChange:B,onSystemPromptChange:D,onSessionStatsChange:O,onContextUsageChange:V},h):eS?es?(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:15},children:"Select a session from the sidebar"}):(0,n.jsxs)("div",{style:{position:"absolute",top:12,left:12,display:"flex",alignItems:"flex-start",gap:8,userSelect:"none",pointerEvents:"none"},children:[(0,n.jsxs)("svg",{width:"44",height:"44",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:.7,flexShrink:0},children:[(0,n.jsx)("line",{x1:"20",y1:"12",x2:"4",y2:"12"}),(0,n.jsx)("polyline",{points:"10 6 4 12 10 18"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:18,fontWeight:600,color:"var(--text)",marginBottom:8},children:"Get Started"}),(0,n.jsxs)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.8},children:[(0,n.jsx)("span",{style:{color:"var(--text-dim)",marginRight:6},children:"1."}),"Select a project directory from the sidebar",(0,n.jsx)("br",{}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",marginRight:6},children:"2."}),"Add models via the ",(0,n.jsx)("strong",{style:{color:"var(--text)"},children:"Models"})," button at the bottom"]})]})]}):null})]}),er&&(0,n.jsx)("div",{className:"resize-handle",onMouseDown:z.handleMouseDown,style:{width:5,cursor:"col-resize",flexShrink:0,zIndex:201,marginLeft:-2,marginRight:-3,background:"transparent",transition:"background 0.15s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"}}),(0,n.jsxs)("div",{className:`right-panel-container${er?" right-panel-open":" right-panel-closed"}`,style:{display:er?"flex":"none",flexDirection:"column",borderLeft:"1px solid var(--border)",background:"var(--bg)",flexShrink:0,width:z.widthRef.current,minWidth:z.widthRef.current},children:[(0,n.jsx)("div",{style:{display:"flex",alignItems:"center",flexShrink:0,background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",height:36},children:(0,n.jsx)("div",{style:{flex:1,overflow:"hidden"},children:(0,n.jsx)(th,{tabs:X,activeTabId:ee??"",onSelectTab:et,onCloseTab:ej})})}),(0,n.jsx)("div",{style:{flex:1,overflow:"hidden"},children:eC?.filePath?eC.filePath.startsWith("__")?(0,n.jsx)(tp,{filePath:eC.filePath}):(0,n.jsx)(ta,{filePath:eC.filePath,cwd:es??void 0}):(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:12},children:"No file open"})})]})]}),(0,n.jsx)("button",{onClick:()=>en(e=>!e),title:er?"Hide file panel":"Show file panel",style:{position:"fixed",top:0,right:0,zIndex:300,display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"var(--bg-panel)",border:"none",borderLeft:"1px solid var(--border)",borderBottom:"1px solid var(--border)",color:er?"var(--text)":"var(--text-muted)",cursor:"pointer",transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color=er?"var(--text)":"var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,n.jsx)("line",{x1:"15",y1:"3",x2:"15",y2:"21"})]})}),m&&(0,n.jsx)(tJ,{onClose:()=>{v(!1),b(e=>e+1)}}),j&&(es??s?.cwd??d)&&(0,n.jsx)(t1,{cwd:es??s?.cwd??d,onClose:()=>k(!1)})]})}}},e=>{e.O(0,[6079,7355,8441,3794,7358],()=>e(e.s=1564)),_N_E=e.O()}]);
|