@qt4798/pi-web 0.17.0 → 0.17.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/app-path-routes-manifest.json +22 -22
  3. package/.next/build-manifest.json +3 -3
  4. package/.next/next-server.js.nft.json +1 -1
  5. package/.next/prerender-manifest.json +5 -5
  6. package/.next/required-server-files.js +1 -1
  7. package/.next/required-server-files.json +1 -1
  8. package/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  9. package/.next/server/app/_global-error.html +1 -1
  10. package/.next/server/app/_global-error.rsc +1 -1
  11. package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  12. package/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  13. package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  14. package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  15. package/.next/server/app/_not-found.html +1 -1
  16. package/.next/server/app/_not-found.rsc +4 -5
  17. package/.next/server/app/_not-found.segments/_full.segment.rsc +4 -5
  18. package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +4 -5
  19. package/.next/server/app/_not-found.segments/_tree.segment.rsc +3 -4
  20. package/.next/server/app/api/app-update/route.js +1 -1
  21. package/.next/server/app/index.html +1 -1
  22. package/.next/server/app/index.rsc +6 -7
  23. package/.next/server/app/index.segments/__PAGE__.segment.rsc +6 -7
  24. package/.next/server/app/index.segments/_full.segment.rsc +6 -7
  25. package/.next/server/app/index.segments/_tree.segment.rsc +3 -4
  26. package/.next/server/app/page.js +3 -3
  27. package/.next/server/app/page_client-reference-manifest.js +1 -1
  28. package/.next/server/app-paths-manifest.json +22 -22
  29. package/.next/server/chunks/4253.js +1 -1
  30. package/.next/server/chunks/6429.js +1 -1
  31. package/.next/server/chunks/7915.js +1 -1
  32. package/.next/server/middleware-build-manifest.js +1 -1
  33. package/.next/server/pages/404.html +1 -1
  34. package/.next/server/pages/500.html +1 -1
  35. package/.next/server/server-reference-manifest.json +1 -1
  36. package/.next/static/chunks/app/{layout-8def4e2d1e761159.js → layout-344bb26f147e8fc7.js} +1 -1
  37. package/.next/static/chunks/app/{page-a580932c40c3cd1f.js → page-a5bd25a6c7117c16.js} +3 -3
  38. package/.next/static/chunks/{webpack-5b085ae581af4587.js → webpack-6a622f7fe45a5a31.js} +1 -1
  39. package/.next/static/css/{93fb21dec5e72367.css → 2f46e0db0d4a3aed.css} +1 -1
  40. package/.next/static/css/683b2ca13a4576ae.css +1 -0
  41. package/.next/trace +8 -9
  42. package/.next/trace-build +1 -1
  43. package/package.json +10 -7
  44. package/.next/static/css/1e6342ca3186c2ef.css +0 -1
  45. package/.next/static/css/fcd139415428d9a1.css +0 -1
  46. /package/.next/static/{oDQqLMJRH8ZLoY87E7Kt9 → ttjXA0WqHPS9c_XTNNfP0}/_buildManifest.js +0 -0
  47. /package/.next/static/{oDQqLMJRH8ZLoY87E7Kt9 → ttjXA0WqHPS9c_XTNNfP0}/_ssgManifest.js +0 -0
@@ -24,16 +24,16 @@ At the end of each turn report your disposition explicitly:
24
24
  ${s}`:`${i}
25
25
  `))},title:e.text.slice(0,60),style:{display:"inline-flex",alignItems:"center",gap:4,padding:"3px 9px",fontSize:12,color:o.value?"var(--accent)":"var(--text-muted)",background:o.value?"color-mix(in srgb, var(--accent) 10%, transparent)":"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:6,cursor:"pointer",whiteSpace:"nowrap",maxWidth:220,overflow:"hidden",textOverflow:"ellipsis",transition:"background 0.12s, border-color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.borderColor="color-mix(in srgb, var(--accent) 45%, var(--border))"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--border)"},children:o.label},n))})}function rj(){return(0,r.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})})}function rS(e,t,o){return Math.min(o,Math.max(t,e))}function rC(e,t,o,r){return o<=0||r<=0||e<=0||t<=0?1:Math.min(.9*e/o,.9*t/r)}function rT({children:e,contentWidth:t,contentHeight:o,title:s,ariaLabel:i,onClose:a}){let{t:l}=(0,A.s)(),d=(0,n.useRef)(null),c=(0,n.useRef)(null),p=t+26,u=o+26,[h,g]=(0,n.useState)(1),[m,f]=(0,n.useState)({scale:1,tx:0,ty:0}),[x,k]=(0,n.useState)(!1),[v,y]=(0,n.useState)(!1),b=(0,n.useRef)(0),w=(0,n.useRef)(h),j=(0,n.useRef)(m);w.current=h,j.current=m;let S=(0,n.useRef)(null),C=(0,n.useCallback)((e,t,o)=>{let{scale:r,tx:n,ty:s}=j.current,i=w.current,a=rS(e,.25*i,3*i);a!==r&&f({scale:a,tx:t-(t-n)*a/r,ty:o-(o-s)*a/r})},[]),T=(0,n.useCallback)(e=>{let t=c.current;if(!t)return;let o=t.getBoundingClientRect(),r=o.width/2,n=o.height/2,s=w.current;C((j.current.scale/s+.25*e)*s,r,n)},[C]),R=(0,n.useCallback)(()=>{let e=c.current;if(!e)return;let{clientWidth:t,clientHeight:o}=e,r=rC(t,o,p,u);g(r),f({scale:r,tx:(t-p*r)/2,ty:(o-u*r)/2})},[p,u]);(0,n.useEffect)(()=>{let e=d.current;if(!e)return;let t=document.body.style.overflow;document.body.style.overflow="hidden",e.showModal();let o=requestAnimationFrame(()=>{R()});return()=>{cancelAnimationFrame(o),document.body.style.overflow=t,e.open&&e.close()}},[R]),(0,n.useEffect)(()=>{let e=c.current;if(!e||"u"<typeof ResizeObserver)return;let t=!1,o=new ResizeObserver(()=>{if(!t){t=!0;return}let{clientWidth:o,clientHeight:r}=e;if(o<=0||r<=0)return;let n=w.current,s=j.current,i=s.scale/n,a=rC(o,r,p,u),l=rS(i*a,.25*a,3*a),d=o/2,c=r/2,h=(d-s.tx)/s.scale,m=(c-s.ty)/s.scale;g(a),f({scale:l,tx:d-h*l,ty:c-m*l})});return o.observe(e),()=>o.disconnect()},[p,u]);let z=e=>{let t=S.current;if(!t||t.pointerId!==e.pointerId)return;t.capturing&&e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId);let o=t.moved;S.current=null,k(!1),o&&(b.current=Date.now())},I=Math.round(m.scale/h*100),M=.25*h,P=3*h;return(0,r.jsx)("dialog",{ref:d,className:"mermaid-zoom-dialog","aria-label":i,onCancel:e=>{e.preventDefault(),a()},onKeyDown:e=>{"Escape"===e.key&&(e.preventDefault(),a())},children:(0,r.jsxs)("div",{className:"mermaid-zoom-layout",children:[(0,r.jsxs)("div",{className:"mermaid-zoom-toolbar",children:[s?(0,r.jsx)("span",{className:"mermaid-zoom-title",children:s}):null,!v&&(0,r.jsx)("span",{className:"mermaid-zoom-hint",children:l("desktop.zoomPanHint")}),(0,r.jsxs)("div",{className:"mermaid-zoom-actions",children:[(0,r.jsx)("button",{type:"button",className:["mermaid-zoom-icon-button","mermaid-zoom-select-button",v?"is-active":""].filter(Boolean).join(" "),onClick:()=>y(e=>!e),title:l("desktop.selectText"),"aria-label":l("desktop.selectText"),"aria-pressed":v,children:(0,r.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M4 6V4h16v2M4 18v2h16v-2M12 4v16"})})}),(0,r.jsxs)("div",{className:"mermaid-zoom-stepper",children:[(0,r.jsx)("button",{type:"button",onClick:()=>T(-1),disabled:m.scale<=M+1e-9,title:l("desktop.zoomOut"),"aria-label":l("desktop.zoomOut"),children:(0,r.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M5 12h14"})})}),(0,r.jsxs)("button",{type:"button",className:"mermaid-zoom-value",onClick:()=>{R()},title:l("desktop.resetZoom"),"aria-label":`${I}%`,children:[I,"%"]}),(0,r.jsx)("button",{type:"button",onClick:()=>T(1),disabled:m.scale>=P-1e-9,title:l("desktop.zoomIn"),"aria-label":l("desktop.zoomIn"),children:(0,r.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M12 5v14M5 12h14"})})})]}),(0,r.jsx)("button",{type:"button",className:"mermaid-zoom-icon-button",onClick:R,title:l("desktop.fitToViewport"),"aria-label":l("desktop.fitToViewport"),children:(0,r.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M8 3H3v5M16 3h5v5M8 21H3v-5M16 21h5v-5"})})}),(0,r.jsx)("button",{type:"button",className:"mermaid-zoom-icon-button",onClick:a,title:l("desktop.close"),"aria-label":l("desktop.close"),children:(0,r.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M6 6l12 12M18 6 6 18"})})})]})]}),(0,r.jsx)("div",{ref:c,className:["mermaid-zoom-viewport",v?"is-selecting":"",x?"is-dragging":""].filter(Boolean).join(" "),onWheel:e=>{e.preventDefault();let t=c.current;if(!t)return;let o=t.getBoundingClientRect(),r=e.clientX-o.left,n=e.clientY-o.top,s=Math.exp(-(.0015*e.deltaY));C(j.current.scale*s,r,n)},onPointerDown:e=>{0!==e.button||v||(S.current={pointerId:e.pointerId,startX:e.clientX,startY:e.clientY,originTx:j.current.tx,originTy:j.current.ty,moved:!1,capturing:!1})},onPointerMove:e=>{let t=S.current;if(!t||t.pointerId!==e.pointerId)return;let o=e.clientX-t.startX,r=e.clientY-t.startY;if(!t.moved){if(4>Math.hypot(o,r))return;t.moved=!0,t.capturing=!0,k(!0),e.currentTarget.setPointerCapture(e.pointerId)}f(e=>({...e,tx:t.originTx+o,ty:t.originTy+r}))},onPointerUp:z,onPointerCancel:z,onClick:e=>{if(Date.now()-b.current<500||e.target!==e.currentTarget)return;let t=window.getSelection();(!t||t.isCollapsed)&&a()},onDoubleClick:e=>{if(v)return;e.preventDefault();let t=c.current;if(!t)return;let o=t.getBoundingClientRect(),r=e.clientX-o.left,n=e.clientY-o.top,s=w.current,i=.05>Math.abs(j.current.scale/s-1)?2:1;1===i?R():C(i*s,r,n)},children:(0,r.jsx)("div",{className:"mermaid-zoom-world",style:{width:t*m.scale+26,height:o*m.scale+26,left:m.tx,top:m.ty},children:(0,r.jsx)("div",{className:"mermaid-zoom-canvas",children:e})})})]})})}let rR=(0,n.createContext)({openId:null,setOpenId:()=>{}});function rz({isStreaming:e,cwd:t,onOpenFile:o,onQuoteReply:s,quoteScope:i="markdown"}){return{h1:({children:e})=>(0,r.jsx)("h1",{id:rp(e),className:"scroll-mt-24 text-xl font-semibold mt-4 mb-2 text-(--text)",children:e}),h2:({children:e})=>(0,r.jsx)("h2",{id:rp(e),className:"scroll-mt-24 text-lg font-semibold mt-3 mb-2 text-(--text)",children:e}),h3:({children:e})=>(0,r.jsx)("h3",{id:rp(e),className:"scroll-mt-24 text-base font-semibold mt-3 mb-1 text-(--text)",children:e}),code({className:t,children:o,...n}){let s=t?.replace("language-","").toLowerCase()??"",i=String(o);return t?.includes("language-")?"mermaid"===s?(0,r.jsx)(rE,{code:i.replace(/\n$/,""),isStreaming:e}):(0,r.jsx)(rD,{code:i.replace(/\n$/,""),lang:s,isStreaming:e}):(0,r.jsx)("code",{className:"inline max-w-full whitespace-normal break-words [overflow-wrap:anywhere] align-baseline bg-(--bg-secondary) border border-(--border) px-1.5 py-0.5 text-xs font-mono text-(--accent-blue)",...n,children:o})},pre:({children:e})=>(0,r.jsx)("div",{className:"markdown-block-code",children:e}),p({children:e,node:a,...l}){let d=`${i}-p-${a?.position?.start?.offset??0}`;return n.Children.toArray(e).some(e=>(0,n.isValidElement)(e)&&("div"===e.type||"pre"===e.type||"table"===e.type||"ul"===e.type||"ol"===e.type))?(0,r.jsx)("div",{className:"markdown-block-wrap",...l,children:e}):s?(0,r.jsx)(rF,{pid:d,onQuoteReply:s,onOpenFile:o,cwd:t,children:e}):(0,r.jsx)("p",{...l,children:e})},li({children:e,node:n,...a}){let l=`${i}-li-${n?.position?.start?.offset??0}`;return s?(0,r.jsx)(rF,{as:"li",pid:l,onQuoteReply:s,onOpenFile:o,cwd:t,children:e}):(0,r.jsx)("li",{...a,children:e})},a({href:e,children:n,...s}){delete s.node;let i="text-(--accent-blue) underline underline-offset-2 hover:text-(--accent-blue)/80",a=o?oe(e,t):null;if(!a||!o){let t="string"==typeof e&&(e.startsWith("file:")||!/^https?:/i.test(e)&&!e.startsWith("#"));return(0,r.jsx)("a",{href:e,...s,className:i,...t?{}:{target:"_blank",rel:"noopener noreferrer"},children:n})}return(0,r.jsx)("a",{href:e,...s,className:i,onClick:e=>{if(e.defaultPrevented||0!==e.button||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;let t=e.currentTarget.getAttribute("target");t&&"_self"!==t||(e.preventDefault(),o(a))},children:n})},img({src:e,alt:o,...n}){delete n.node;let s="string"==typeof e?oe(e,t):null,i=s?`/api/files/${ed(s)}?type=read`:e;return(0,r.jsx)("img",{src:i,alt:o??"",loading:"lazy",...n})},table:({children:e})=>(0,r.jsx)("div",{className:"my-3 rounded-lg overflow-hidden border border-(--border)",children:(0,r.jsx)("div",{className:"overflow-x-auto",children:(0,r.jsx)("table",{className:"w-full text-sm border-collapse [&_tr:last-child>td]:border-b-0",children:e})})}),tr({children:e,node:n,...a}){let l=`${i}-tr-${n?.position?.start?.offset??0}`;return s?(0,r.jsx)(rF,{as:"tr",pid:l,onQuoteReply:s,onOpenFile:o,cwd:t,children:e}):(0,r.jsx)("tr",{...a,children:e})}}}let rI=(0,n.memo)(function({text:e,isStreaming:t,cwd:o,onOpenFile:s,onQuoteReply:i,quoteScope:a}){let l=(0,n.useMemo)(()=>ru(e),[e]),d=(0,n.useMemo)(()=>rz({isStreaming:t,cwd:o,onOpenFile:s,onQuoteReply:i,quoteScope:a}),[t,o,s,i,a]);return(0,r.jsx)(on.oz,{remarkPlugins:rm,rehypePlugins:rf,components:d,children:l})});function rM({children:e,className:t,isStreaming:o,cwd:s,onOpenFile:i,onQuoteReply:a}){let l=(0,n.useMemo)(()=>ru(e),[e]),d=(0,n.useRef)(new Map),c=(0,n.useMemo)(()=>(function(e,t){let o;if(0===e.length)return[];let r=e.split(/\r?\n/),n="",s=0,i=!1,a=-1;for(let e=0;e<r.length;e++){let t=ro.exec(r[e]);i?t&&t[1][0]===n&&t[1].length>=s&&(i=!1,n="",s=0,a=-1):t&&(n=t[1][0],s=t[1].length,i=!0,a=e)}if(a>=0)o=a;else{let e=-1;for(let t=0;t<r.length;t++)""===r[t]&&(e=t);o=e+1}let l=r.slice(0,o),d=r.slice(o),c=[],p=[],u=()=>{for(;p.length>0&&""===p[p.length-1];)p.pop();for(;p.length>0&&""===p[0];)p.shift();p.length>0&&(c.push(rt(p.join("\n"),!1,t)),p=[])};for(let e of l)""===e&&p.length>0?u():p.push(e);for(p.length>0&&u();d.length>0&&""===d[0];)d.shift();return d.length>0&&c.push(rt(d.join("\n"),!0,t)),c})(l,d.current),[l]),p=o&&c.length>1,u=(0,n.useMemo)(()=>rz({isStreaming:o,cwd:s,onOpenFile:i,onQuoteReply:a,quoteScope:"full"}),[o,s,i,a]);return(0,r.jsx)(rP,{children:(0,r.jsx)("div",{className:["markdown-body",t].filter(Boolean).join(" "),children:p?c.map((e,t)=>(0,r.jsx)(rI,{text:e.text,isStreaming:!!e.tail&&o,cwd:s,onOpenFile:i,onQuoteReply:a,quoteScope:e.id},`${t}-${e.id}`)):(0,r.jsx)(on.oz,{remarkPlugins:rm,rehypePlugins:rf,urlTransform:i?rc:void 0,components:u,children:l})})})}function rP({children:e}){let[t,o]=(0,n.useState)(null),s=(0,n.useMemo)(()=>({openId:t,setOpenId:o}),[t]);return(0,r.jsx)(rR.Provider,{value:s,children:e})}function rE({code:e,isStreaming:t}){let{t:s}=(0,A.s)(),{isDark:i}=o9(),[a,l]=(0,n.useState)(!t),[d,c]=(0,n.useState)(null),[p,u]=(0,n.useState)(""),[h,g]=(0,n.useState)(null),[m,f]=(0,n.useState)(!1),x=`${i?"dark":"light"}
26
26
  ${e}`;(0,n.useEffect)(()=>{t||l(!0)},[t]),(0,n.useEffect)(()=>{if(!a||t)return;let r=!1;return g(null),(async()=>{let{default:t}=await Promise.all([o.e(988),o.e(9425),o.e(3308)]).then(o.bind(o,43328));if(t.initialize({startOnLoad:!1,securityLevel:"strict",suppressErrorRendering:!0,theme:i?"dark":"default"}),!await t.parse(e,{suppressErrors:!0}))throw Error("Invalid Mermaid diagram");let n="u">typeof crypto&&"randomUUID"in crypto?`mermaid-${crypto.randomUUID()}`:`mermaid-${Date.now()}-${Math.random().toString(36).slice(2)}`,s=await t.render(n,e);r||(c(s.svg),u(x))})().catch(()=>{r||g(x)}),()=>{r=!0}},[e,x,i,t,a]);let k=(0,r.jsx)("button",{onClick:()=>l(e=>!e),disabled:t,title:s(t?"desktop.markdownPreviewAvailableAfterStreaming":a?"desktop.source":"desktop.markdownPreviewMermaidDiagram"),className:["markdown-code-action",a?"is-active":""].filter(Boolean).join(" "),children:s(a?"desktop.source":"desktop.preview")});if(!a||t)return(0,r.jsx)(rD,{code:e,lang:"mermaid",headerAction:k,isStreaming:t});let v=h===x?(0,r.jsx)("div",{className:"mermaid-block mermaid-block-error",children:s("desktop.markdownInvalidMermaidDiagram")}):d&&p===x?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{type:"button",className:"mermaid-block mermaid-preview-button",title:s("desktop.openMermaidViewer"),"aria-label":s("desktop.openMermaidViewer"),onClick:()=>f(!0),dangerouslySetInnerHTML:{__html:d}}),m&&(0,r.jsx)(rW,{svg:d,onClose:()=>f(!1)})]}):(0,r.jsx)("div",{className:"mermaid-block mermaid-block-loading","aria-label":s("desktop.markdownRenderingMermaidDiagram")});return(0,r.jsxs)("div",{className:"markdown-code-block",children:[(0,r.jsxs)("div",{className:"markdown-code-header",children:[(0,r.jsx)("span",{className:"markdown-code-lang",children:"mermaid"}),(0,r.jsx)("div",{className:"markdown-code-actions",children:k})]}),v]})}function rW({svg:e,onClose:t}){let{t:o}=(0,A.s)(),s=(0,n.useMemo)(()=>(function(e){if("u"<typeof DOMParser)return{html:e,width:800,height:600};let t=new DOMParser().parseFromString(e,"image/svg+xml").documentElement;if(!t||"svg"!==t.tagName.toLowerCase())return{html:e,width:800,height:600};let o=0,r=0,n=t.getAttribute("viewBox");if(n){let e=n.trim().split(/[\s,]+/).map(Number);4===e.length&&e.every(e=>Number.isFinite(e))&&(o=e[2],r=e[3])}return o>0&&r>0||(o=parseFloat(t.getAttribute("width")||""),r=parseFloat(t.getAttribute("height")||"")),o>0&&r>0||(o=800,r=600),t.removeAttribute("width"),t.removeAttribute("height"),t.style.maxWidth="none",t.getAttribute("viewBox")||t.setAttribute("viewBox",`0 0 ${o} ${r}`),{html:t.outerHTML,width:o,height:r}})(e),[e]);return(0,r.jsx)(rT,{contentWidth:s.width,contentHeight:s.height,title:o("desktop.mermaidDiagram"),ariaLabel:o("desktop.mermaidViewer"),onClose:t,children:(0,r.jsx)("div",{dangerouslySetInnerHTML:{__html:s.html}})})}function rF({children:e,onQuoteReply:t,onOpenFile:o,cwd:s,as:i="p",pid:a}){let{openId:l,setOpenId:d}=(0,n.useContext)(rR),{t:c}=(0,A.s)(),p=l===a,u=(0,n.useRef)(null),[h,g]=(0,n.useState)(null),[m,f]=(0,n.useState)(!1),[x,k]=(0,n.useState)(1),v=(0,n.useRef)(null),[y]=(0,n.useState)(()=>window.matchMedia?.("(pointer: coarse)").matches);(0,n.useEffect)(()=>{!p&&h&&g(null)},[p,h]);let b=(0,n.useRef)(null);(0,n.useEffect)(()=>{h&&b.current&&b.current.scrollIntoView({block:"nearest"})},[h]);let w=()=>{g(null),d(null)},j=()=>{h?w():(()=>{let e;if(h||p)return;let t=u.current,o=(!(e=rk("tr"===i&&t?Array.from(t.querySelectorAll("td, th")).map(e=>(e.textContent??"").trim()).join(" | "):t?.textContent??""))?[]:e.split(/(?<=[??])|[;;]/u).map(e=>e.trim()).filter(e=>e.length>0)).map(e=>({text:e,options:function(e){let t=rk(e);if(!t)return null;let o=t.match(/^(.+?)\s*(?:还是|或者|或者还是|\bor\b)\s*(.+?)[??]?\s*$/iu);if(o){let e=ry(o[1]),t=ry(o[2]);if(e&&t&&e!==t)return[{label:rv(e,12),value:e},{label:rv(t,12),value:t}]}if(!/怎么|如何|怎样|哪个|哪些|什么|为什么|为何|谁|多少|几(个|点|时)?|what|how|why|who|where/u.test(t)&&(/[??]\s*$/u.test(t)||/(?:吗|吧|呢)[??]?\s*$/u.test(t)||/是否|要不要|能不能|可不可以|要不要我|需要我/u.test(t))){let e=t.replace(/^(要我|需要我|要不要我?|是否|能不能|可不可以|要不要|或者|还是|你能|你可以|请|麻烦)\s*/u,"").replace(/[吗吧呢啊呀]?[??]+$/u,"").replace(/[吗吧呢啊呀]$/u,"").trim();return e&&e.length<=16?[{label:`好,${rv(e,10)}`,value:"是的"},{label:"不用",value:"不用了"}]:[{label:"是",value:"是的"},{label:"否",value:"不用了"}]}return null}(e)}));o.length>0&&("tr"===i&&t&&k(Math.max(1,t.querySelectorAll("td, th").length)),g(o),d(a))})()},S=(e,t)=>{v.current&&(v.current.style.left=`${e+12}px`,v.current.style.top=`${t+14}px`)},C=h&&(0,r.jsx)(rb,{innerRef:b,segments:h,onPick:e=>{t(e),w()},onOpenFile:o,cwd:s});return"tr"===i?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("tr",{ref:e=>{u.current=e},onClick:j,title:y||h?void 0:c("desktop.quoteReplyHint"),style:{cursor:"pointer"},children:e}),C&&(0,r.jsx)("tr",{children:(0,r.jsx)("td",{colSpan:x,children:C})})]}):(0,r.jsxs)(i,{ref:u,onMouseEnter:e=>{if(y)return;f(!0);let{clientX:t,clientY:o}=e;requestAnimationFrame(()=>S(t,o))},onMouseMove:y?void 0:e=>S(e.clientX,e.clientY),onMouseLeave:()=>f(!1),onClick:j,style:{position:"relative",cursor:"pointer"},children:[e,m&&!h&&(0,r.jsx)("span",{ref:v,style:{position:"fixed",left:-9999,top:-9999,fontSize:11,color:"var(--text-dim)",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:4,padding:"2px 6px",pointerEvents:"none",zIndex:50,whiteSpace:"nowrap"},children:c("desktop.quoteReplyHint")}),C]})}function rD({code:e,lang:t,headerAction:o,isStreaming:s}){let{t:i}=(0,A.s)(),[a,l]=(0,n.useState)(!1),[d,c]=(0,n.useState)(!1);return(0,r.jsxs)("div",{className:"markdown-code-block",onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),children:[(0,r.jsxs)("div",{style:{position:"absolute",top:6,right:8,zIndex:1,display:"flex",alignItems:"center",gap:6,opacity:+!!d,pointerEvents:d?"auto":"none",transition:"opacity 0.12s"},children:[(0,r.jsx)("span",{style:{color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:10,fontWeight:600,letterSpacing:"0.06em",textTransform:"uppercase",userSelect:"none"},children:t||i("desktop.markdownPlainText")}),o,(0,r.jsx)("button",{onClick:()=>{re(e).then(()=>{l(!0),setTimeout(()=>l(!1),1500)})},title:i(a?"desktop.copied":"desktop.copy"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,border:"none",borderRadius:5,background:"transparent",color:a?"var(--accent)":"var(--text-dim)",cursor:"pointer",fontSize:10,transition:"color 0.12s"},onMouseEnter:e=>{a||(e.currentTarget.style.color="var(--accent)")},onMouseLeave:e=>{a||(e.currentTarget.style.color="var(--text-dim)")},children:a?(0,r.jsx)(m.J,{size:11,"aria-hidden":"true"}):(0,r.jsx)(or.Q,{size:11,"aria-hidden":"true"})})]}),s?(0,r.jsx)("pre",{className:"markdown-code-streaming",children:(0,r.jsx)("code",{children:e})}):(0,r.jsx)(os.A,{language:t||"text",style:rx,showLineNumbers:!1,customStyle:{margin:0,padding:"10px 16px",fontSize:13,lineHeight:1.65,borderRadius:0,border:"none",background:"var(--bg-secondary)"},codeTagProps:{style:{fontFamily:"var(--font-mono)"}},children:e})]})}let rA=/^<skill name="([^"]+)" location="([^"]+)">/,rN="\n</skill>";function rL({src:e,alt:t="",children:o,className:s,style:i}){let{t:a}=(0,A.s)(),[l,d]=(0,n.useState)(!1),c=(0,n.useRef)(null),p=(0,n.useRef)(null),u=(0,n.useRef)(null);(0,n.useEffect)(()=>{if(!l)return;let e=p.current;if(!e)return;let t=c.current,o=document.body.style.overflow;return document.body.style.overflow="hidden",e.showModal(),u.current?.focus({preventScroll:!0}),()=>{document.body.style.overflow=o,e.open&&e.close(),t?.isConnected&&t.focus({preventScroll:!0})}},[l]);let h=()=>{p.current?.open&&p.current.close(),d(!1)};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{ref:c,type:"button",className:s,style:{display:"block",padding:0,border:"none",background:"none",color:"inherit",cursor:"zoom-in",...i},onClick:()=>d(!0),"aria-label":a("chat.previewImage"),"aria-haspopup":"dialog","aria-expanded":l,title:a("chat.previewImage"),children:o}),l&&(0,r.jsxs)("dialog",{ref:p,className:"image-preview-dialog","aria-label":a("chat.previewImage"),onCancel:e=>{e.preventDefault(),e.stopPropagation(),h()},onKeyDown:e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),h())},onClick:e=>{e.target===e.currentTarget&&h()},children:[(0,r.jsx)("img",{className:"image-preview-image",src:e,alt:t}),(0,r.jsx)("button",{ref:u,type:"button",className:"image-preview-close",onClick:h,"aria-label":a("chat.close"),title:a("chat.close"),children:(0,r.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M6 6l12 12M18 6 6 18"})})})]})]})}let r$=/<(read-files|modified-files)>\s*([\s\S]*?)\s*<\/\1>/g,rH=/(?:\r?\n){2,}((?:[ \t]*<(?:read-files|modified-files)>[ \t]*\r?\n[\s\S]*?\r?\n[ \t]*<\/(?:read-files|modified-files)>[ \t]*(?:\r?\n)?)+)\s*$/;function rO({content:e}){var t,o,s;let i,{t:a}=(0,A.s)(),[l,d]=(0,n.useState)(!1),c="string"==typeof e?e:e.filter(e=>"text"===e.type).map(e=>e.text).join("\n"),p=(0,n.useMemo)(()=>{let e,t,o,r,n;return e=[],t=[],o=c.match(rH),r=o?.[1]??"",n=o?.index===void 0?c:c.slice(0,o.index),r.replace(r$,(o,r,n)=>{let s=n.split(/\r?\n/).map(e=>e.trim()).filter(Boolean);return"read-files"===r?e.push(...s):t.push(...s),""}),{body:n.trim(),readFiles:e,modifiedFiles:t}},[c]),u=(t=p.readFiles.length,o=p.modifiedFiles.length,s=a,i=[],t>0&&i.push(s("desktop.readFilesCount",{count:t})),o>0&&i.push(s("desktop.modifiedFilesCount",{count:o})),i.length>0?i.join(", "):null),[h,g]=(0,n.useState)(!1),[m,f]=(0,n.useState)(!1),x=(0,n.useRef)(null),k=(0,n.useCallback)(()=>{let e=x.current;e&&(g(e.scrollTop>0),f(e.scrollHeight-e.scrollTop-e.clientHeight>1))},[]);return(0,n.useEffect)(()=>{let e=x.current;if(!e||!l)return;let t=new ResizeObserver(k);return e.addEventListener("scroll",k,{passive:!0}),t.observe(e),e.firstElementChild&&t.observe(e.firstElementChild),k(),()=>{e.removeEventListener("scroll",k),t.disconnect()}},[l,k]),(0,r.jsxs)("div",{className:"group/process relative mb-3 min-w-0",children:[(0,r.jsx)("div",{className:"group/summary-row flex items-center justify-between",children:(0,r.jsxs)("button",{type:"button",onClick:()=>d(e=>!e),className:"group/summary flex min-w-0 items-center gap-1.5 text-left text-sm leading-relaxed text-text-muted transition-colors hover:text-text","aria-expanded":l,children:[(0,r.jsx)("span",{className:"truncate",children:a("desktop.conversationCompacted")}),(0,r.jsx)("span",{className:`opacity-0 transition-opacity group-hover/summary:opacity-60 ${l?"rotate-90":""}`,children:(0,r.jsx)(b.J,{size:12,className:"shrink-0 transition-all duration-150"})})]})}),l&&(0,r.jsxs)("div",{className:"relative mt-2",children:[(0,r.jsxs)("div",{ref:x,className:"max-h-[280px] overflow-y-auto pr-2 text-text-dim",children:[(0,r.jsx)("p",{className:"mb-2 text-xs leading-relaxed",children:a("desktop.compactionSummaryDescription")}),p.body?(0,r.jsx)(rM,{className:"!text-text-dim",children:p.body}):(0,r.jsx)("span",{className:"text-xs",children:a("desktop.noSummary")}),u&&(0,r.jsxs)("div",{className:"mt-3 border-t border-border pt-2 text-xs",children:[(0,r.jsx)("div",{className:"font-medium",children:a("desktop.fileContext",{context:u})}),p.modifiedFiles.length>0&&(0,r.jsx)(rB,{title:a("desktop.modifiedFiles"),files:p.modifiedFiles}),p.readFiles.length>0&&(0,r.jsx)(rB,{title:a("desktop.readFiles"),files:p.readFiles})]})]}),h&&(0,r.jsx)("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 top-0 z-10 h-6 bg-gradient-to-b from-bg to-transparent"}),m&&(0,r.jsx)("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 bottom-0 z-10 h-6 bg-gradient-to-t from-bg to-transparent"})]})]})}function rB({title:e,files:t}){return(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsx)("div",{className:"mb-1 font-mono text-[11px] font-medium text-text",children:e}),(0,r.jsx)("ul",{className:"max-h-45 overflow-auto rounded-sm border border-border bg-bg-subtle px-2 py-1.5 font-mono text-[11px] leading-relaxed",children:t.map(e=>(0,r.jsx)("li",{className:"break-all",children:e},e))})]})}function rU(e){let t,o=[],r=null,n=0,s=0,i=0,a=0,l=[],d=[],c=()=>({lineNo:null,text:"",type:"empty"}),p=()=>{if(!r){l=[],d=[];return}let e=Math.max(l.length,d.length);for(let t=0;t<e;t++){let e=l[t]?{lineNo:l[t].lineNo,text:l[t].text,type:"removed"}:c(),o=d[t]?{lineNo:d[t].lineNo,text:d[t].text,type:"added"}:c();r.rows.push({type:"line",left:e,right:o})}l=[],d=[]};for(let c of e.split(/\r?\n/)){if(!(i>0||a>0)){if(c.startsWith("--- ")){p(),t=r_(c.slice(4));continue}if(c.startsWith("+++ ")){p(),r={oldPath:t,newPath:r_(c.slice(4)),rows:[]},o.push(r);continue}}let e=c.match(/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);if(e){r||(r={rows:[]},o.push(r)),p(),n=Number(e[1]),s=Number(e[3]),i=void 0===e[2]?1:Number(e[2]),a=void 0===e[4]?1:Number(e[4]),r.rows.push({type:"hunk",text:c});continue}if(!r)continue;if(c.startsWith("\\ ")){p(),r.rows.push({type:"hunk",text:c});continue}if(0===i&&0===a){""!==c&&r.rows.push({type:"hunk",text:c});continue}let u=c[0],h=c.slice(1);" "===u?(p(),r.rows.push({type:"line",left:{lineNo:n++,text:h,type:"context"},right:{lineNo:s++,text:h,type:"context"}}),i>0&&i--,a>0&&a--):"-"===u?(l.push({lineNo:n++,text:h}),i>0&&i--):"+"===u?(d.push({lineNo:s++,text:h}),a>0&&a--):""!==c&&(p(),r.rows.push({type:"hunk",text:c}))}p();let u=o.filter(e=>e.rows.some(e=>"line"===e.type));return u.length>0?u:null}function r_(e){return e.split(" ")[0].trim()}let rq="pi-thinking-expanded-changed";function rV(){return"true"===window.localStorage.getItem("pi-thinking-expanded")}function rK({files:e,onOpenFile:t}){let{t:o}=(0,A.s)();return 0===e.length?null:(0,r.jsx)("div",{"aria-label":o("desktop.filesWritten"),style:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:6,marginTop:6},children:e.map(({filePath:e})=>{let n=ec(e);return(0,r.jsxs)("button",{type:"button",title:e,"aria-label":o("desktop.openWrittenFile",{name:n}),onClick:()=>t?.(e),style:{display:"inline-flex",alignItems:"center",gap:4,padding:"2px 8px",fontSize:12,fontFamily:"var(--font-mono)",color:"var(--text)",background:"var(--bg-subtle)",border:"1px solid var(--border)",borderRadius:6,cursor:"pointer"},children:[(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M9 1.5H4A1.5 1.5 0 0 0 2.5 3v10A1.5 1.5 0 0 0 4 14.5h8A1.5 1.5 0 0 0 13.5 13V6z"}),(0,r.jsx)("path",{d:"M9 1.5V6h4.5"})]}),(0,r.jsx)("span",{children:n})]},e)})})}var rG=o(35831),rJ=o(63522),rY=o(22540),rX=o(36462),rZ=o(42405),rQ=o(26131),r0=o(47142);let r1={flash:{cacheRead:.02,input:1,output:2,cacheWrite:0},pro:{cacheRead:.025,input:3,output:6,cacheWrite:0}};function r2(e){let t=(e??"").toLowerCase();return t.includes("deepseek-v4-flash")?"flash":t.includes("deepseek-v4-pro")?"pro":null}function r4(e){return null!==r2(e)}function r6(e,t){let o=r2(e);if(!o||!t)return 0;let r=r1[o],n=r5(t.input),s=r5(t.output),i=r5(t.cacheRead),a=r5(t.cacheWrite);return(i*r.cacheRead+n*r.input+s*r.output+a*r.cacheWrite)/1e6}function r8(e){var t;let o="number"==typeof(t=e)&&Number.isFinite(t)?t:0;return!Number.isFinite(o)||o<=0?"\xa50.00":o<.01?"<\xa50.01":o<1?`\xa5${o.toFixed(4)}`:`\xa5${o.toFixed(2)}`}function r5(e){return"number"==typeof e&&Number.isFinite(e)&&e>0?e:0}let r3=new Map;function r7(e,t,o){let r=`${e}:${t}:${o}`,n=r3.get(r);if(n)return r3.delete(r),r3.set(r,n),n;let s=fetch(`/api/sessions/${encodeURIComponent(e)}/entries/${encodeURIComponent(t)}/thinking?blockIndex=${o}`).then(async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);let t=await e.json();if("string"!=typeof t.thinking)throw Error("Invalid thinking response");return t.thinking}).catch(e=>{throw r3.delete(r),e});if(r3.set(r,s),r3.size>100){let e=r3.keys().next().value;e&&r3.delete(e)}return s}function r9(e){if(!e)return null;let t=new Date(e),o=new Date,r=t.getFullYear()===o.getFullYear()&&t.getMonth()===o.getMonth()&&t.getDate()===o.getDate(),n=t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});if(r)return n;let s=t.toLocaleDateString([],{month:"short",day:"numeric",year:t.getFullYear()!==o.getFullYear()?"numeric":void 0});return`${s} ${n}`}let ne=(0,n.memo)(function({message:e,isStreaming:t,toolResults:o,modelNames:n,cwd:s,onOpenFile:i,onQuoteReply:a,onOpenSession:l,entryId:d,searchBlock:c,onFork:p,forking:u,onNavigate:h,prevAssistantEntryId:g,onEditContent:m,showTimestamp:f,prevTimestamp:x,sessionId:k,onCreateTask:v,writtenFiles:y}){return"user"===e.role?(0,r.jsx)(nt,{message:e,cwd:s,onOpenFile:i,entryId:d,onFork:p,forking:u,onNavigate:h,prevAssistantEntryId:g,onEditContent:m,onCreateTask:v}):"assistant"===e.role?(0,r.jsx)(no,{message:e,isStreaming:t,toolResults:o,modelNames:n,cwd:s,onOpenFile:i,onQuoteReply:a,onOpenSession:l,showTimestamp:f,prevTimestamp:x,sessionId:k,entryId:d,onFork:p,forking:u,searchBlock:c,writtenFiles:y}):"toolResult"===e.role?null:"custom"===e.role?"compaction"===e.customType?(0,r.jsx)(rO,{content:e.content}):(0,r.jsx)(nm,{message:e,isStreaming:t,cwd:s,onOpenFile:i}):"bashExecution"===e.role?(0,r.jsx)(nf,{message:e,sessionId:k}):null},(e,t)=>e.message===t.message&&e.isStreaming===t.isStreaming&&function(e,t,o){if(t===o||"assistant"!==e.role)return!0;for(let r of e.content??[])if("toolCall"===r.type&&t?.get(r.toolCallId)!==o?.get(r.toolCallId))return!1;return!0}(e.message,e.toolResults,t.toolResults)&&e.modelNames===t.modelNames&&e.cwd===t.cwd&&e.onOpenFile===t.onOpenFile&&e.onQuoteReply===t.onQuoteReply&&e.onOpenSession===t.onOpenSession&&e.entryId===t.entryId&&e.searchBlock===t.searchBlock&&e.onFork===t.onFork&&e.forking===t.forking&&e.onNavigate===t.onNavigate&&e.prevAssistantEntryId===t.prevAssistantEntryId&&e.onEditContent===t.onEditContent&&e.onCreateTask===t.onCreateTask&&e.showTimestamp===t.showTimestamp&&e.prevTimestamp===t.prevTimestamp&&e.sessionId===t.sessionId&&e.writtenFiles===t.writtenFiles);function nt({message:e,cwd:t,onOpenFile:o,entryId:s,onFork:i,forking:a,onNavigate:l,prevAssistantEntryId:d,onEditContent:c,onCreateTask:p}){let{t:u}=(0,A.s)(),[h,g]=(0,n.useState)(!1),[f,x]=(0,n.useState)(!1),k="string"==typeof e.content?e.content:e.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n"),v="string"==typeof e.content?[]:e.content.filter(e=>"image"===e.type),y=v.length>0?k.replace(/(?<!\\)!\[[^\]]*\]\([^)]*\)/g,"").replace(/[ \t]*\n{3,}/g,"\n\n"):k,b=(y&&y.trim()?y.trim().startsWith("/")?y:function(e){let t=e.match(rA);if(!t)return null;let o=t[1],r=e.indexOf(rN),n="";if(-1!==r){let t=e.slice(r+rN.length);t.startsWith("\n\n")&&(n=t.slice(2).trim())}return n?`/skill:${o} ${n}`:`/skill:${o}`}(y):null)??y,w=r9(e.timestamp),j=!!s&&!!i,S=!!d&&!!l;return(0,r.jsxs)("div",{className:"chat-user-message chat-msg-in",onMouseEnter:()=>g(!0),onMouseLeave:()=>g(!1),children:[(0,r.jsx)("div",{className:"chat-user-bubble-wrap",children:(0,r.jsxs)("div",{className:"chat-user-bubble",children:[v.length>0&&(0,r.jsx)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginBottom:8*!!y},children:v.map((e,t)=>{let o=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,r.jsx)(rL,{src:o,children:(0,r.jsx)("img",{src:o,alt:"",style:{maxWidth:240,maxHeight:240,borderRadius:6,objectFit:"contain",display:"block",border:"1px solid rgba(59,130,246,0.15)"}})},t)})}),b&&(0,r.jsx)(rM,{className:"markdown-user-message",cwd:t,onOpenFile:o,children:b})]})}),(0,r.jsxs)("div",{className:"msg-actions",style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:6,marginTop:3},children:[(0,r.jsxs)("div",{style:{display:"flex",gap:3,opacity:+!!h,pointerEvents:h?"auto":"none",transition:"opacity 0.12s"},children:[(0,r.jsx)("button",{onClick:()=>{re(y).then(()=>{x(!0),setTimeout(()=>x(!1),1500)})},title:u("desktop.copyMessage"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,background:"none",border:"none",borderRadius:5,color:f?"var(--accent)":"var(--text-dim)",cursor:"pointer",transition:"color 0.12s"},onMouseEnter:e=>{f||(e.currentTarget.style.color="var(--accent)")},onMouseLeave:e=>{f||(e.currentTarget.style.color="var(--text-dim)")},children:f?(0,r.jsx)(m.S,{size:11}):(0,r.jsx)(or.T,{size:11})}),p&&y.trim()&&(0,r.jsx)("button",{onClick:()=>p(y,t),title:u("desktop.createTaskFromMessage"),"aria-label":u("desktop.createTaskFromMessage"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,background:"none",border:"none",borderRadius:5,color:"var(--text-dim)",cursor:"pointer",transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)"},children:(0,r.jsx)(rZ.X,{size:11})})]}),(j||S)&&(0,r.jsxs)("div",{className:"msg-actions",style:{display:"flex",gap:3,opacity:h||a?1:0,pointerEvents:h||a?"auto":"none",transition:"opacity 0.12s"},children:[S&&(0,r.jsx)("button",{onClick:()=>{l(d),c?.(e)},title:u("desktop.editFromHere"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,background:"none",border:"none",borderRadius:5,color:"var(--text-dim)",cursor:"pointer",transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)"},children:(0,r.jsx)(rG.S,{size:11})}),j&&(0,r.jsx)("button",{onClick:()=>{i(s)},disabled:a,title:u(a?"desktop.creatingNewSession":"desktop.newSessionFromHere"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,background:"none",border:"none",borderRadius:5,color:a?"var(--accent)":"var(--text-dim)",cursor:a?"not-allowed":"pointer",transition:"color 0.12s"},onMouseEnter:e=>{a||(e.currentTarget.style.color="var(--accent)")},onMouseLeave:e=>{a||(e.currentTarget.style.color="var(--text-dim)")},children:(0,r.jsx)(F.C,{size:11})})]}),w&&(0,r.jsx)("span",{style:{fontSize:11,color:h?"var(--text-muted)":"var(--text-dim)",opacity:h?1:.5,transition:"color 0.15s, opacity 0.15s"},children:w})]})]})}function no({message:e,isStreaming:t,toolResults:o,modelNames:s,cwd:i,onOpenFile:a,onQuoteReply:l,onOpenSession:d,showTimestamp:c,prevTimestamp:p,sessionId:u,entryId:h,onFork:g,forking:f,searchBlock:x,writtenFiles:k}){let{t:v}=(0,A.s)(),y=c?r9(e.timestamp):null,b=(e.content??[]).map((e,t)=>({block:e,originalIndex:t})).filter(({block:e})=>!tQ(e,{isStreaming:t})),w=b.map(({block:e})=>e),[j,S]=(0,n.useState)(!1),[C,T]=(0,n.useState)(!1),[R,z]=(0,n.useState)(!1),I=(0,n.useRef)(null),[M,P]=(0,n.useState)(null),E=(0,n.useRef)(b);E.current=b;let W=(0,n.useRef)(new Map),[D,N]=(0,n.useState)(new Map),L=(0,n.useMemo)(()=>{if(!e.timestamp||!p)return;let t=Math.round((e.timestamp-p)/1e3);return t>0?t:void 0},[e.timestamp,p]),$=(0,n.useMemo)(()=>{let t=new Map;if(!o||!e.timestamp)return t;for(let[r,n]of o)if(n.timestamp&&e.timestamp){let o=Math.round((n.timestamp-e.timestamp)/1e3);o>0&&t.set(r,o)}return t},[o,e.timestamp]),H=w.filter(e=>"text"===e.type).map(e=>e.text).join("\n"),O=function(e){let t=new Set;for(let o of e){if("toolCall"!==o.type)continue;let e=(o.toolName??"").toLowerCase();if("apply_patch"===e||e.includes("patch")||!(nh(o.toolName??"")||"write"===e||"create"===e||e.includes("file_write")||e.includes("create_file")||e.includes("multiedit")))continue;let r=o.input??{},n=r.filePath??r.file_path??r.path??r.file??r.destination??r.newFilePath??r.oldPath;"string"==typeof n&&n.trim()&&t.add(n)}return[...t]}(w),[B,U]=(0,n.useState)(!1);(0,n.useEffect)(()=>{if(!t){let e=new Date().getTime();N(t=>{let o=new Map(t);for(let[t,r]of W.current)o.has(t)||o.set(t,Math.round((e-r)/1e3));return o}),I.current=null,P(null);return}let e=setInterval(()=>{let e=E.current,t=e.map(({block:e})=>e),o=Date.now();e.forEach(({originalIndex:e})=>{W.current.has(e)||W.current.set(e,o)}),N(t=>{let r=!1,n=new Map(t);for(let t=0;t<e.length-1;t++){let s=e[t].originalIndex,i=e[t+1].originalIndex;if(!n.has(s)&&W.current.has(s)){let e=W.current.get(s),t=W.current.get(i)??o;n.set(s,Math.round((t-e)/1e3)),r=!0}}return r?n:t});let r=0;for(let e of t)"text"===e.type?r+=e.text?.length??0:"thinking"===e.type?r+=e.thinking?.length??0:"toolCall"===e.type&&(r+=JSON.stringify(e.input??{}).length);if(0===r)return;null===I.current&&(I.current=o);let n=(o-I.current)/1e3;n>.5&&P(r/4/n)},300);return()=>clearInterval(e)},[t]);let _=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:e.toLocaleString(),q="error"===e.stopReason&&e.errorMessage?e.errorMessage:null;return 0!==w.length||t||q?(0,r.jsxs)("div",{"data-message-role":"assistant","data-entry-id":h,className:["chat-assistant-message chat-msg-in",t?"is-streaming":""].filter(Boolean).join(" "),onMouseEnter:()=>S(!0),onMouseLeave:()=>S(!1),children:[t&&(0,r.jsx)("div",{className:"chat-assistant-meta",children:(()=>{let e,t=0;for(let e of w)"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 o=Math.round(t/4);return(0,r.jsx)(r.Fragment,{children:o>0&&(0,r.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4,color:"var(--text)"},title:v("desktop.estimatedStreamingTokenCount"),children:[(0,r.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:2,fontSize:11,fontWeight:400},children:[(0,r.jsx)(rX.g,{size:13}),o]}),null!==M&&(e=M>=50?"--accent-green":M>=30?"--accent-blue":M>=15?"--accent-orange":"--accent-red",(0,r.jsx)("span",{style:{marginLeft:6,padding:"1px 6px",borderRadius:4,background:`var(${e})`,color:"var(--bg)",fontSize:11,fontWeight:400},children:v("desktop.tokensPerSecond",{count:M.toFixed(1)})}))]})})})()}),(0,r.jsxs)("div",{className:"chat-assistant-content",children:[q&&(0,r.jsxs)("div",{className:"chat-assistant-error",role:"alert",children:[(0,r.jsx)(r0.M,{size:13,weight:"bold"}),(0,r.jsx)("span",{children:q})]}),b.map(({block:e,originalIndex:n})=>(0,r.jsx)(nr,{block:e,searchTarget:e===x,toolResults:o,isStreaming:t,streamingDuration:D.get(n)??("thinking"===e.type?L:void 0),toolCallDurations:$,cwd:i,onOpenFile:a,onQuoteReply:l,onOpenSession:d,sessionId:u,entryId:h,blockIndex:n},`${h??"stream"}-${n}`))]}),k&&k.length>0&&(0,r.jsx)(rK,{files:k,onOpenFile:a}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:4},children:[!t&&(e.provider||e.usage)&&(0,r.jsxs)("div",{style:{fontSize:11,color:j?"var(--text-muted)":"var(--text-dim)",opacity:j?1:.5,display:"flex",alignItems:"center",gap:5,flexWrap:"wrap",transition:"color 0.15s, opacity 0.15s"},children:[e.provider&&(0,r.jsx)("span",{children:s?.[`${e.provider}:${e.model}`]??s?.[e.model]??e.model}),e.usage&&e.usage.input>0&&(0,r.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:2},children:[(0,r.jsx)(rY.K,{size:10}),_(e.usage.input)]}),e.usage&&e.usage.output>0&&(0,r.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:2},children:[(0,r.jsx)(rJ.Z,{size:10}),_(e.usage.output)]}),e.usage&&e.usage.cacheRead>0&&(0,r.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:2},children:[(0,r.jsx)(rQ.b,{size:10}),_(e.usage.cacheRead)]}),e.usage&&e.usage.cost?.total>0&&(()=>{if(r4(e.model)){let t=r6(e.model,e.usage);return t<=0?null:(0,r.jsx)("span",{title:v("desktop.turnUsageByOfficialPrice"),children:r8(t)})}return(0,r.jsxs)("span",{children:["$",e.usage.cost.total.toFixed(4)]})})()]}),H&&!t&&(0,r.jsx)("button",{className:"msg-actions",onClick:()=>{re(H).then(()=>{T(!0),setTimeout(()=>T(!1),1500)})},title:v("desktop.copyMessage"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,background:"none",border:"none",borderRadius:5,color:C?"var(--accent)":"var(--text-dim)",cursor:"pointer",opacity:+!!j,pointerEvents:j?"auto":"none",transition:"opacity 0.12s, color 0.12s"},onMouseEnter:e=>{C||(e.currentTarget.style.color="var(--accent)")},onMouseLeave:e=>{C||(e.currentTarget.style.color="var(--text-dim)")},children:C?(0,r.jsx)(m.S,{size:11}):(0,r.jsx)(or.T,{size:11})}),H&&!t&&(0,r.jsx)("button",{className:"msg-actions",onClick:()=>{re(H.replace(/`([^`]+)`/g,"$1").replace(/```[^\n]*\n?/g,"\n").replace(/```/g,"\n").replace(/!\[([^\]]*)\]\([^)]*\)/g,"$1").replace(/\[([^\]]*)\]\([^)]*\)/g,"$1").replace(/(\*\*|__)(.*?)\1/g,"$2").replace(/(\*|_)([^*_]+)\1/g,"$2").replace(/~~(.*?)~~/g,"$1").replace(/^#{1,6}\s+/gm,"").replace(/^>\s?/gm,"").replace(/^(\s*)([-*+]|\d+\.)\s+/gm,"$1").replace(/^\s*\|?[\s:|-]+\|?\s*$/gm,"").replace(/\|/g," ").replace(/\n{3,}/g,"\n\n").trim()).then(()=>{z(!0),setTimeout(()=>z(!1),1500)})},title:v("desktop.copyPlainText"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,background:"none",border:"none",borderRadius:5,color:R?"var(--accent)":"var(--text-dim)",cursor:"pointer",opacity:+!!j,pointerEvents:j?"auto":"none",transition:"opacity 0.12s, color 0.12s"},onMouseEnter:e=>{R||(e.currentTarget.style.color="var(--accent)")},onMouseLeave:e=>{R||(e.currentTarget.style.color="var(--text-dim)")},children:R?(0,r.jsx)(m.S,{size:11}):(0,r.jsx)(rZ.X,{size:11})}),h&&g&&!t&&(0,r.jsx)("button",{className:"msg-actions",onClick:()=>g(h),disabled:f,title:f?v("desktop.creatingNewSession"):v("desktop.newSessionFromHere"),"aria-label":v("desktop.newSessionFromHere"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,background:"none",border:"none",borderRadius:5,color:f?"var(--accent)":"var(--text-dim)",cursor:f?"not-allowed":"pointer",opacity:+!!j,pointerEvents:j?"auto":"none",transition:"opacity 0.12s, color 0.12s"},children:(0,r.jsx)(F.C,{size:11})}),y&&!t&&(0,r.jsx)("span",{style:{fontSize:11,color:j?"var(--text-muted)":"var(--text-dim)",opacity:j?1:.5,marginLeft:"auto",transition:"color 0.15s, opacity 0.15s"},children:y}),O.length>0&&!t&&(0,r.jsxs)("span",{style:{position:"relative",display:"inline-flex",alignItems:"center"},children:[(0,r.jsxs)("button",{type:"button",onClick:()=>U(e=>!e),title:v("desktop.changedFiles",{count:O.length}),style:{display:"inline-flex",alignItems:"center",gap:4,padding:"1px 7px",border:"1px solid var(--border)",borderRadius:999,background:B?"var(--bg-hover)":"none",color:"var(--text-muted)",fontSize:10,cursor:"pointer",opacity:j||B?1:.5,transition:"opacity 0.12s, border-color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="var(--accent)"},onMouseLeave:e=>{B||(e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)")},children:[(0,r.jsx)(F.C,{size:10,"aria-hidden":"true"}),O.length]}),B&&(0,r.jsx)("span",{style:{position:"absolute",right:0,top:"calc(100% + 6px)",zIndex:30,minWidth:200,maxWidth:320,padding:"6px 0",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 8px 24px rgba(0,0,0,0.18)"},children:O.map(e=>(0,r.jsx)("button",{type:"button",onClick:()=>{U(!1),a?.(e)},style:{display:"block",width:"100%",padding:"5px 12px",background:"none",border:"none",color:"var(--text-muted)",fontSize:11,textAlign:"left",fontFamily:"var(--font-mono)",cursor:"pointer",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:e},e))})]})]})]}):null}function nr({block:e,searchTarget:t,toolResults:o,isStreaming:n,streamingDuration:s,toolCallDurations:i,cwd:a,onOpenFile:l,onQuoteReply:d,onOpenSession:c,sessionId:p,entryId:u,blockIndex:h}){if("text"===e.type)return(0,r.jsx)("div",{"data-message-text":!0,"data-search-target":t||void 0,children:(0,r.jsx)(nn,{block:e,isStreaming:n,cwd:a,onOpenFile:l,onQuoteReply:d})});if("thinking"===e.type)return(0,r.jsx)(ns,{block:e,duration:s,sessionId:p,entryId:u,blockIndex:h});if("toolCall"===e.type){let t=o?.get(e.toolCallId),n=i?.get(e.toolCallId);return(0,r.jsx)(na,{block:e,result:t,duration:n,onOpenSession:c})}return null}function nn({block:e,isStreaming:t,cwd:o,onOpenFile:n,onQuoteReply:s}){return(0,r.jsx)(rM,{isStreaming:t,cwd:o,onOpenFile:n,onQuoteReply:s,children:e.text})}function ns({block:e,duration:t,sessionId:o,entryId:s,blockIndex:i,contentOnly:a=!1,isStreaming:l,cwd:d,onOpenFile:c,className:p}){var u;let{t:h}=(0,A.s)(),[g,m]=(0,n.useState)(rV),[f,x]=(0,n.useState)(null),[k,v]=(0,n.useState)(!1),[y,b]=(0,n.useState)(null);return((0,n.useRef)(h).current=h,u=e.thinking,u.trimStart().match(/^[^\r\n]{0,240}/u)?.[0].trimEnd(),(0,n.useEffect)(()=>{let e=()=>m(rV());return window.addEventListener(rq,e),()=>window.removeEventListener(rq,e)},[]),(0,n.useEffect)(()=>{if(!g||!e.deferred||null!==f)return;if(!o||!s)return void b(h("desktop.thinkingContentUnavailable"));let t=5,r=()=>{v(!0),b(null),r7(o,s,i).then(e=>{x(e),v(!1)}).catch(e=>{t>1?(t--,setTimeout(r,2e3)):(v(!1),b(e instanceof Error?e.message:String(e)))})};r()},[g,e.deferred,f,o,s,i,h]),a)?(0,r.jsx)(ni,{block:e,sessionId:o,entryId:s,blockIndex:i,isStreaming:l,cwd:d,onOpenFile:c,className:p}):(0,r.jsxs)("div",{className:"thinking-block",children:[(0,r.jsxs)("button",{onClick:()=>m(e=>!e),className:"thinking-block-trigger","aria-expanded":g,children:[(0,r.jsx)("span",{className:`thinking-block-caret ${g?"is-expanded":""}`,"aria-hidden":"true",children:"›"}),(0,r.jsx)("span",{className:"thinking-block-icon","aria-hidden":"true",children:"✦"}),(0,r.jsx)("span",{children:h("desktop.thinking")}),void 0!==t&&(0,r.jsxs)("span",{style:{marginLeft:"auto",fontSize:11,color:"var(--text-dim)",fontVariantNumeric:"tabular-nums"},children:[t,"s"]})]}),g&&(0,r.jsx)("div",{className:`thinking-block-content ${y?"is-error":""}`,children:k?h("desktop.loadingThinking"):y??(e.deferred?f:e.thinking)}),void 0!==t&&(0,r.jsxs)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontVariantNumeric:"tabular-nums"},children:[t,"s"]})]})}function ni({block:e,sessionId:t,entryId:o,blockIndex:s,isStreaming:i,cwd:a,onOpenFile:l,className:d}){let{t:c}=(0,A.s)(),[p,u]=(0,n.useState)(null),[h,g]=(0,n.useState)(!0===e.deferred),[m,f]=(0,n.useState)(null);return((0,n.useEffect)(()=>{let r=!1,n=5;if(!e.deferred)return void g(!1);if(!t||!o){g(!1),f(c("desktop.thinkingContentUnavailable"));return}let i=()=>{r||(g(!0),f(null),r7(t,o,s).then(e=>{r||(u(e),g(!1))}).catch(e=>{r||(n>1?(n--,setTimeout(i,2e3)):(g(!1),f(e instanceof Error?e.message:String(e))))}))};return i(),()=>{r=!0}},[e.deferred,s,o,t,c]),h)?(0,r.jsx)("div",{className:"text-xs text-text-dim",children:c("desktop.loadingThinking")}):m?(0,r.jsx)("div",{className:"text-xs text-red-400",children:m}):(0,r.jsx)(rM,{isStreaming:i,cwd:a,onOpenFile:l,className:d,children:e.deferred?p??"":e.thinking})}let na=(0,n.memo)(function({block:e,result:t,duration:o,processStyle:s=!1,onOpenSession:i}){var a;let{t:l}=(0,A.s)(),[d,c]=(0,n.useState)(!1),p=(0,n.useMemo)(()=>JSON.stringify(e.input,null,2),[e.input]),u=nh(e.toolName),h=t&&!t.isError?function(e){var t;let o=e.details;if(!("object"==typeof(t=o)&&null!==t&&!Array.isArray(t)))return null;let r="string"==typeof o.patch?o.patch:null;if(r)return{text:r};let n="string"==typeof o.diff?o.diff:null;return n?{text:n}:null}(t):null,g=(0,n.useMemo)(()=>t?t.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n"):null,[t]),m=t?.content.filter(e=>"image"===e.type)??[],f=null!==g&&("(no output)"===g.trim()||""===g.trim()),x=t?.isError??!1,k=(a=t?.details)&&"object"==typeof a&&"pi-web-subagent"===a.kind&&"string"==typeof a.sessionId?t.details:null;return(0,r.jsxs)("div",{className:`tool-call-block ${s?"is-process":""} ${x?"is-error":""}`,children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"stretch",minWidth:0},children:[(0,r.jsxs)("button",{onClick:()=>c(e=>!e),className:"tool-call-trigger","aria-expanded":d,style:{flex:1,minWidth:0},children:[(0,r.jsx)("span",{className:"tool-call-name",children:e.toolName}),(0,r.jsx)("span",{className:"tool-call-preview",children:function(e){let t=e.input;if(!t||"object"!=typeof t)return"";let o=Object.keys(t);return 0===o.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[o[0]]).slice(0,120)}(e)}),void 0!==o&&(0,r.jsxs)("span",{style:{fontSize:11,color:"var(--text-dim)",flexShrink:0,fontVariantNumeric:"tabular-nums"},children:[o,"s"]}),(0,r.jsx)("span",{className:`tool-call-caret ${d?"is-expanded":""}`,"aria-hidden":"true",children:(0,r.jsx)(b.J,{size:12})})]}),k&&i&&(0,r.jsx)("button",{type:"button",className:"tool-call-open-session",onClick:()=>i(k.sessionId),title:l("subagent.open"),"aria-label":l("subagent.open"),children:(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M15 3h6v6"}),(0,r.jsx)("path",{d:"M10 14 21 3"}),(0,r.jsx)("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"})]})})]}),d&&!u&&(0,r.jsx)("pre",{className:"tool-call-input",children:p}),d&&t&&(h?(0,r.jsx)(nl,{diff:h,processStyle:s}):(0,r.jsx)(ng,{text:g??"",images:m,isEmpty:f,isError:x,processStyle:s}))]})});function nl({diff:e,processStyle:t=!1}){return(0,r.jsx)("div",{style:{borderTop:t?"1px solid var(--border)":"1px solid rgba(34,197,94,0.15)",background:"var(--bg)"},children:(0,r.jsx)(nd,{text:e.text})})}function nd({text:e}){let{t}=(0,A.s)(),o=(0,n.useMemo)(()=>rU(e),[e]);if(!o)return(0,r.jsx)(nu,{text:e});let s=o.length>1;return(0,r.jsx)("div",{style:{maxHeight:560,overflowY:"auto",overflowX:"hidden",background:"var(--bg)"},children:o.map((e,o)=>(0,r.jsxs)("div",{style:{minWidth:0,borderTop:0===o?"none":"1px solid var(--border)",fontFamily:"var(--font-mono)",fontSize:"calc(12px + var(--chat-font-size-offset, 0px))",lineHeight:1.55},children:[s&&(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(0, 1fr)",position:"sticky",top:0,zIndex:1,background:"var(--bg-panel)",borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)(nc,{title:e.oldPath||t("desktop.before"),side:"left"}),(0,r.jsx)(nc,{title:e.newPath||t("desktop.after"),side:"right"})]}),(0,r.jsx)("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(0, 1fr)"},children:e.rows.map((e,t)=>"hunk"===e.type?null:(0,r.jsxs)("div",{style:{display:"contents"},children:[(0,r.jsx)(np,{cell:e.left,side:"left"}),(0,r.jsx)(np,{cell:e.right,side:"right"})]},t))})]},o))})}function nc({title:e,side:t}){return(0,r.jsx)("div",{title:e,style:{padding:"5px 10px",color:"var(--text-dim)",borderRight:"left"===t?"1px solid var(--border)":"none",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e})}function np({cell:e,side:t}){let o="added"===e.type?"rgba(34,197,94,0.12)":"removed"===e.type?"rgba(248,113,113,0.13)":"empty"===e.type?"var(--bg-subtle)":"transparent",n="added"===e.type?"+":"removed"===e.type?"-":" ",s="added"===e.type?"#22c55e":"removed"===e.type?"#f87171":"var(--text-dim)";return(0,r.jsxs)("div",{style:{display:"flex",minWidth:0,background:o,borderRight:"left"===t?"1px solid var(--border)":"none"},children:[(0,r.jsx)("span",{style:{width:42,padding:"0 6px",textAlign:"right",color:"var(--text-dim)",userSelect:"none",background:"var(--bg-panel)",borderRight:"1px solid var(--border)",flexShrink:0},children:e.lineNo??""}),(0,r.jsx)("span",{style:{width:18,padding:"0 5px",color:s,userSelect:"none",fontWeight:"context"===e.type||"empty"===e.type?400:700,flexShrink:0},children:n}),(0,r.jsx)("span",{style:{flex:1,minWidth:0,padding:"0 10px 0 0",color:"empty"===e.type?"var(--text-dim)":"var(--text)",whiteSpace:"pre-wrap",overflowWrap:"anywhere"},children:e.text||"\xa0"})]})}function nu({text:e}){let t=e.split(/\r?\n/);return(0,r.jsx)("div",{style:{maxHeight:520,overflowY:"auto",overflowX:"hidden",fontFamily:"var(--font-mono)",fontSize:"calc(12px + var(--chat-font-size-offset, 0px))",lineHeight:1.55,minWidth:0},children:t.map((e,t)=>{let o=e.startsWith("@@")?"hunk":e.startsWith("+")&&!e.startsWith("+++")?"added":e.startsWith("-")&&!e.startsWith("---")?"removed":"context";return(0,r.jsxs)("div",{style:{display:"flex",background:"added"===o?"rgba(34,197,94,0.12)":"removed"===o?"rgba(248,113,113,0.13)":"hunk"===o?"rgba(96,165,250,0.12)":"transparent",borderLeft:"added"===o?"3px solid #22c55e":"removed"===o?"3px solid #f87171":"hunk"===o?"3px solid var(--accent)":"3px solid transparent"},children:[(0,r.jsx)("span",{style:{width:48,padding:"0 8px",color:"var(--text-dim)",background:"var(--bg-panel)",borderRight:"1px solid var(--border)",textAlign:"right",userSelect:"none",flexShrink:0},children:t+1}),(0,r.jsx)("span",{style:{padding:"0 10px",whiteSpace:"pre-wrap",overflowWrap:"anywhere",color:"added"===o?"#22c55e":"removed"===o?"#f87171":"hunk"===o?"var(--accent)":"var(--text)"},children:e||"\xa0"})]},t)})})}function nh(e){let t=e.toLowerCase();return"edit"===t||t.startsWith("edit_")||t.endsWith(".edit")||t.endsWith("_edit")||t.includes("str_replace")||t.includes("replace_editor")}function ng({text:e,images:t=[],isEmpty:o,isError:s,processStyle:i=!1}){let{t:a}=(0,A.s)(),[l,d]=(0,n.useState)(!1),c=!o&&e.length>8e3&&!l,p=c?e.slice(0,8e3):e,u=!o||0===t.length;return(0,r.jsxs)("div",{style:{borderTop:`1px solid ${i?"var(--border)":s?"rgba(248,113,113,0.3)":"rgba(34,197,94,0.15)"}`,background:i?"var(--bg-subtle)":s?"rgba(248,113,113,0.04)":"var(--bg-subtle)"},children:[t.length>0&&(0,r.jsx)("div",{style:{display:"flex",gap:8,flexWrap:"wrap",padding:"10px",background:"var(--bg)"},children:t.map((e,t)=>{let o=nx(e);return o?(0,r.jsx)(rL,{src:o,children:(0,r.jsx)("img",{src:o,alt:`Tool result image ${t+1}`,loading:"lazy",style:{display:"block",maxWidth:"min(100%, 720px)",maxHeight:520,borderRadius:6,objectFit:"contain",border:"1px solid var(--border)"}})},`${o}-${t}`):null})}),u&&(0,r.jsx)("pre",{style:{margin:0,padding:"8px 10px",color:s?"#f87171":o?"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:o?"italic":"normal",opacity:o?.6:1},children:o?a("desktop.noOutput"):p}),c&&(0,r.jsx)("button",{onClick:()=>d(!0),style:{display:"block",margin:"6px 8px 8px",padding:"4px 10px",border:"1px solid var(--border)",borderRadius:5,background:"transparent",color:"var(--text-dim)",fontSize:11,cursor:"pointer"},children:a("desktop.loadFullOutput")})]})}function nm({message:e,isStreaming:t,cwd:o,onOpenFile:s}){var i,a,l,d,c,p;let u,{t:h}=(0,A.s)(),g=!1===e.display,[m,f]=(0,n.useState)(!g),[x,k]=(0,n.useState)(!1),[v,y]=(0,n.useState)(!1),b="string"==typeof(i=e.content)?i:i.filter(e=>"text"===e.type).map(e=>e.text).join("\n"),w="string"==typeof(a=e.content)?[]:a.filter(e=>"image"===e.type),j=void 0!==e.details,S=j?function(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}(e.details):"",C=(l=e.customType,d=h("desktop.extension"),l||d),T=r9(e.timestamp);return(0,r.jsx)("div",{style:{marginBottom:16},children:(0,r.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,overflow:"hidden",background:g?"var(--bg-subtle)":"var(--bg)",opacity:g&&!m?.82:1},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"7px 10px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",fontSize:12},children:[(0,r.jsx)("span",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)",fontSize:11,fontWeight:650},children:C}),g&&(0,r.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:h("desktop.hiddenExtensionMessage")}),T&&(0,r.jsx)("span",{style:{marginLeft:"auto",color:"var(--text-dim)",fontSize:10},children:T})]}),m?(0,r.jsxs)("div",{style:{padding:"6px 9px"},children:[w.length>0&&(0,r.jsx)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginBottom:8*!!b},children:w.map((e,t)=>{let o=nx(e);return o?(0,r.jsx)(rL,{src:o,children:(0,r.jsx)("img",{src:o,alt:"",style:{maxWidth:240,maxHeight:240,borderRadius:6,objectFit:"contain",display:"block",border:"1px solid var(--border)"}})},t):null})}),b?(0,r.jsx)(rM,{className:"markdown-custom-message",isStreaming:t,cwd:o,onOpenFile:s,children:b}):(0,r.jsx)("span",{style:{color:"var(--text-dim)",fontSize:12},children:h("desktop.noMessage")})]}):(0,r.jsx)("button",{onClick:()=>f(!0),style:{display:"block",width:"100%",padding:"8px 10px",border:"none",background:"transparent",color:"var(--text-dim)",cursor:"pointer",fontSize:12,textAlign:"left"},children:b?(c=b,p=h("desktop.showExtensionMessage"),(u=c.replace(/\s+/g," ").trim())?u.length>140?`${u.slice(0,140)}...`:u:p):h("desktop.showExtensionMessage")}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"4px 9px",borderTop:"1px solid var(--border)",background:"var(--bg-subtle)"},children:[b||S?(0,r.jsx)("button",{onClick:()=>{re(b||S).then(()=>{y(!0),setTimeout(()=>y(!1),1500)})},style:{padding:"3px 7px",border:"none",background:"none",color:v?"var(--accent)":"var(--text-dim)",cursor:"pointer",fontSize:11},children:h(v?"desktop.copied":"desktop.copy")}):null,(j||g)&&(0,r.jsx)("button",{onClick:()=>{g?f(e=>!e):k(e=>!e)},style:{marginLeft:"auto",padding:"3px 7px",border:"none",background:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:11},children:h(g?m?"desktop.collapse":"desktop.expand":x?"desktop.hideDetails":"desktop.showDetails")})]}),j&&(g&&m||!g&&x)&&(0,r.jsx)("pre",{style:{margin:0,padding:"9px 10px",borderTop:"1px solid var(--border)",background:"var(--bg)",color:"var(--text-muted)",fontSize:"calc(12px + var(--chat-font-size-offset, 0px))",lineHeight:1.5,whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:360,overflow:"auto",fontFamily:"var(--font-mono)"},children:S})]})})}function nf({message:e,sessionId:t}){let{t:o}=(0,A.s)(),[s,i]=(0,n.useState)(null),[a,l]=(0,n.useState)(!1),[d,c]=(0,n.useState)(null),p=!e.output&&void 0===e.exitCode&&!e.cancelled,u=e.cancelled||void 0!==e.exitCode&&0!==e.exitCode,h=t&&e.fullOutputPath?`/api/agent/${encodeURIComponent(t)}/bash-output?path=${encodeURIComponent(e.fullOutputPath)}`:null,g=s??e.output,m=async()=>{if(h){l(!0),c(null);try{let e=await fetch(h),t=await e.json();if(!e.ok||!t.success)throw Error(t.error??`HTTP ${e.status}`);i(t.data?.output??"")}catch(e){c(e instanceof Error?e.message:String(e))}finally{l(!1)}}},f=e.excludeFromContext?"bash (local)":"bash",x={type:"toolCall",toolCallId:`bash-${e.timestamp??e.command}`,toolName:f,input:{command:e.command}},k=p?void 0:{role:"toolResult",toolCallId:x.toolCallId,toolName:f,content:g?[{type:"text",text:g}]:[],isError:u,timestamp:e.timestamp};return(0,r.jsxs)("div",{style:{margin:"6px 0"},children:[(0,r.jsx)(na,{block:x,result:k}),e.truncated&&h&&null===s&&(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:4},children:[(0,r.jsx)("button",{type:"button",onClick:()=>void m(),disabled:a,style:{padding:"3px 8px",border:"1px solid var(--border)",borderRadius:4,background:"none",color:"var(--text-muted)",cursor:a?"wait":"pointer",fontSize:11},children:o(a?"desktop.loading":"desktop.loadFullOutput")}),(0,r.jsx)("a",{href:`${h}&download=1`,style:{fontSize:11,color:"var(--accent)"},children:o("desktop.download")})]}),d&&(0,r.jsx)("div",{style:{marginTop:4,color:"var(--accent-red)",fontSize:11},children:d})]})}function nx(e){return 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}`:""}var nk=o(35828),nv=o(61719),ny=o(259);function nb({open:e,planText:t,onExecute:o,onFeedback:s,onExit:i,onClose:a,busy:l=!1}){let{t:d}=(0,A.s)(),[c,p]=(0,n.useState)(!1),[u,h]=(0,n.useState)(""),[g,m]=(0,n.useState)(!0),f=(0,n.useRef)(null);return((0,n.useEffect)(()=>{e&&(p(!1),h(""),m(!0))},[e]),(0,n.useEffect)(()=>{c&&f.current?.focus()},[c]),e)?(0,r.jsxs)("div",{role:"region","aria-label":d("tasks.planReviewTitle"),style:{maxWidth:820,margin:"12px auto 8px",border:"1px solid color-mix(in srgb, var(--accent) 28%, var(--border))",borderRadius:12,background:"var(--bg-panel)",animation:"plan-card-in 0.18s ease-out",overflow:"hidden"},children:[c&&(0,r.jsxs)("div",{style:{padding:"10px 14px",display:"flex",flexDirection:"column",gap:6,borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)("label",{style:{fontSize:11.5,color:"var(--text-muted)"},children:d("tasks.planReviewFeedbackLabel")}),(0,r.jsx)("textarea",{ref:f,value:u,onChange:e=>h(e.target.value),placeholder:d("tasks.planReviewFeedbackPlaceholder"),rows:2,style:{width:"100%",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"8px 10px",color:"var(--text)",fontSize:12.5,outline:"none",fontFamily:"inherit",resize:"vertical"}}),(0,r.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:6},children:[(0,r.jsx)("button",{type:"button",onClick:()=>p(!1),disabled:l,style:{padding:"5px 10px",borderRadius:6,background:"none",border:"1px solid var(--border)",color:"var(--text-muted)",fontSize:11.5,cursor:l?"not-allowed":"pointer"},children:d("i18n.cancel")}),(0,r.jsx)("button",{type:"button",onClick:()=>{u.trim()&&s(u.trim())},disabled:l||!u.trim(),style:{padding:"5px 12px",borderRadius:6,background:"var(--accent)",color:"#fff",border:"none",fontSize:11.5,fontWeight:600,cursor:l||!u.trim()?"not-allowed":"pointer"},children:d("tasks.planReviewSendFeedback")})]})]}),t&&t.trim()?(0,r.jsxs)("div",{style:{padding:"0 14px 10px"},children:[(0,r.jsxs)("button",{type:"button",onClick:()=>m(e=>!e),style:{display:"flex",alignItems:"center",gap:6,background:"none",border:"none",padding:"6px 0",cursor:"pointer",color:"var(--text-muted)",fontSize:11.5,fontFamily:"var(--font-mono)"},children:[(0,r.jsx)("span",{style:{transform:g?"rotate(90deg)":"none",transition:"transform 0.12s"},children:"›"}),d(g?"tasks.planReviewHidePlan":"tasks.planReviewShowPlan")]}),g&&(0,r.jsx)("div",{style:{maxHeight:320,overflow:"auto",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"10px 12px",fontSize:12.5,lineHeight:1.65,color:"var(--text)",whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"var(--font-mono)"},children:t.trim()})]}):null,(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"6px 10px"},children:[(0,r.jsx)(nk.y,{size:14,weight:"fill",color:"var(--accent)","aria-hidden":"true"}),(0,r.jsx)("span",{style:{fontSize:12,fontWeight:650,color:"var(--text)",marginRight:8,flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d("tasks.planReviewTitle")}),(0,r.jsxs)("button",{type:"button",onClick:o,disabled:l,title:d("tasks.planReviewExecute"),style:{display:"inline-flex",alignItems:"center",gap:5,padding:"6px 12px",borderRadius:7,background:"var(--accent)",color:"#fff",border:"none",fontSize:12,fontWeight:650,cursor:l?"not-allowed":"pointer",transition:"opacity 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.opacity="0.88")},onMouseLeave:e=>{e.currentTarget.style.opacity="1"},children:[(0,r.jsx)(nv.r,{size:13,weight:"fill","aria-hidden":"true"}),d("tasks.planReviewExecute")]}),(0,r.jsxs)("button",{type:"button",onClick:()=>{c?p(!1):(p(!0),requestAnimationFrame(()=>f.current?.focus()))},disabled:l,title:d("tasks.planReviewSuggest"),style:{display:"inline-flex",alignItems:"center",gap:5,padding:"6px 10px",borderRadius:7,background:c?"var(--bg-selected)":"none",border:c?"1px solid var(--accent)":"1px solid var(--border)",color:c?"var(--accent)":"var(--text)",fontSize:12,fontWeight:550,cursor:l?"not-allowed":"pointer",transition:"background 0.12s"},onMouseEnter:e=>{l||c||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{c||(e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text)")},children:[(0,r.jsx)(C.S,{size:12,"aria-hidden":"true"}),d("tasks.planReviewSuggest")]}),(0,r.jsxs)("button",{type:"button",onClick:()=>{p(!1),i()},disabled:l,title:d("tasks.planReviewExit"),style:{display:"inline-flex",alignItems:"center",gap:5,padding:"6px 8px",borderRadius:7,background:"none",border:"none",color:"var(--text-muted)",fontSize:12,cursor:l?"not-allowed":"pointer"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:[(0,r.jsx)(ny.f,{size:12,"aria-hidden":"true"}),d("tasks.planReviewExit")]}),(0,r.jsx)("button",{type:"button",onClick:a,disabled:l,title:d("i18n.close"),style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:24,height:24,padding:0,background:"none",border:"none",color:"var(--text-muted)",fontSize:12,cursor:l?"not-allowed":"pointer",borderRadius:5},onMouseEnter:e=>{l||(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:"✕"})]})]}):null}var nw=o(19336);let nj={idle:"#6b7280",running:"#10b981",paused:"#d97706",blocked:"#ea580c",budget_limited:"#ef4444",complete:"#6b7280"},nS=new Set(["paused","blocked"]);function nC(e){let t=Math.abs(e);return t>=1e6?`${(e/1e6).toFixed(2)}M`:t>=1e3?`${(e/1e3).toFixed(1)}K`:`${e}`}function nT(e){switch(e){case"running":return"active";case"paused":return"paused";case"blocked":return"stalled";case"budget_limited":return"budget limited";case"complete":return"complete";default:return"idle"}}function nR({goalState:e,onPause:t,onResume:o,onStop:s,onEdit:i}){let{t:a}=(0,A.s)(),[l,d]=(0,n.useState)(!1),[c,p]=(0,n.useState)(""),u=(0,n.useRef)(null),[h,g]=(0,n.useState)(()=>Date.now());if((0,n.useEffect)(()=>{if("running"!==e.status)return;let t=setInterval(()=>g(Date.now()),1e3);return()=>clearInterval(t)},[e.status]),(0,n.useEffect)(()=>{l&&u.current&&(u.current.focus(),u.current.select())},[l]),"idle"===e.status||"complete"===e.status)return null;let m=nj[e.status]??"var(--text-muted)",f="running"===e.status,x=nS.has(e.status),k="running"===e.status,v=e.timeUsedSeconds??0;k&&e.startedAt&&(v=Math.floor((h-e.startedAt)/1e3));let y=null!=e.tokenBudget?`${nC(e.tokensUsed)}/${nC(e.tokenBudget)}`:nC(e.tokensUsed),b=()=>{d(!1),p("")},w=()=>{let t=c.trim();t&&t!==e.goalText?(i(t),d(!1),p("")):b()},j=(e,t,o)=>(0,r.jsx)("button",{type:"button",onClick:t,style:{padding:"3px 9px",borderRadius:5,border:`1px solid ${o?"var(--accent)":"var(--border)"}`,background:o?"var(--accent)":"var(--bg)",color:o?"#fff":"var(--text-muted)",cursor:"pointer",fontSize:12,lineHeight:1.4,fontFamily:"var(--font-mono)",whiteSpace:"nowrap",flexShrink:0},children:e});return(0,r.jsxs)("div",{style:{flexShrink:0,display:"flex",flexDirection:"column",gap:6,padding:"8px 10px",borderTop:`1px solid ${m}55`,borderBottom:`1px solid ${m}55`,background:`color-mix(in srgb, ${m} 5%, transparent)`,minWidth:0},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,r.jsx)(nw.d,{size:13,weight:"fill",color:m,"aria-hidden":"true"}),(0,r.jsx)("span",{title:nT(e.status),style:{flexShrink:0,width:8,height:8,borderRadius:"50%",background:m}}),(0,r.jsx)("span",{style:{flexShrink:0,fontSize:11,fontFamily:"var(--font-mono)",color:m,textTransform:"uppercase",letterSpacing:.4},children:nT(e.status)}),(0,r.jsxs)("span",{style:{flex:1,fontSize:11,fontFamily:"var(--font-mono)",color:"var(--text-dim)",whiteSpace:"nowrap",textAlign:"right",minWidth:0,overflow:"hidden",textOverflow:"ellipsis"},children:[function(e){let t=Math.max(0,Math.floor(e));if(t<60)return`${t}s`;let o=Math.floor(t/60);if(o<60)return`${o}m`;let r=Math.floor(o/60),n=o%60;if(r>=24){let e=Math.floor(r/24);return`${e}d ${r%24}h`}return 0===n?`${r}h`:`${r}h ${n}m`}(v)," \xb7 ",y,"t",null!=e.tokenBudget?" \xb7 "+a("desktop.goalBudget"):""]}),(0,r.jsxs)("div",{style:{display:"flex",gap:4,flexShrink:0},children:[f&&j(a("desktop.goalPauseShort"),t,!1),x&&j(a("desktop.goalResumeShort"),o,!0),!l&&j(a("desktop.goalEdit"),()=>{p(e.goalText??""),d(!0)},!1),j("✕",s,!1)]})]}),l?(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[(0,r.jsx)("textarea",{ref:u,value:c,onChange:e=>p(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.metaKey||e.ctrlKey)?(e.preventDefault(),w()):"Escape"===e.key&&(e.preventDefault(),b())},rows:3,style:{width:"100%",padding:"6px 8px",borderRadius:6,border:"1px solid var(--accent)",background:"var(--bg)",color:"var(--text)",fontSize:13,lineHeight:1.5,fontFamily:"var(--font-sans)",resize:"vertical",outline:"none",boxSizing:"border-box"}}),(0,r.jsxs)("div",{style:{display:"flex",gap:6,justifyContent:"flex-end"},children:[j(a("desktop.goalCancel"),b,!1),j(a("desktop.goalSave"),w,!0)]}),(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:a("desktop.goalEditHint")})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{style:{fontSize:13,color:"var(--text)",lineHeight:1.5,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:e.goalText??a("desktop.goalRunning")}),k&&(0,r.jsxs)("div",{style:{display:"flex",gap:10,fontSize:10,color:"var(--text-muted)",fontFamily:"var(--font-mono)",flexWrap:"wrap"},children:[(0,r.jsxs)("span",{children:[a("desktop.goalTurns"),": ",e.turnsUsed,"/",e.turnsLimit]}),e.noProgressTurns>0&&(0,r.jsx)("span",{children:a("desktop.goalNoProgress",{n:e.noProgressTurns})})]})]})]})}var nz=o(77229);function nI({request:e,queuedCount:t=0,busy:o=!1,onResolve:s}){let{t:i}=(0,A.s)(),[a,l]=(0,n.useState)(""),d=(0,n.useRef)(null),[c,p]=(0,n.useState)(!1);if((0,n.useEffect)(()=>{e&&(l(""),p(!1))},[e?.id]),!e)return null;let u=function(e){if(null==e)return"{}";if("string"==typeof e)return e;try{return JSON.stringify(e,null,2)}catch{return String(e)}}(e.args),g=u.length>4e3;return(0,r.jsx)("div",{style:{position:"fixed",left:0,right:0,bottom:130,zIndex:1300,display:"flex",justifyContent:"center",pointerEvents:"none",padding:"0 14px"},children:(0,r.jsxs)("div",{role:"dialog","aria-modal":"false","aria-label":"工具调用审批",style:{pointerEvents:"auto",width:"min(380px, 100%)",maxHeight:"min(60vh, 400px)",display:"flex",flexDirection:"column",background:"var(--bg-panel)",border:"1px solid color-mix(in srgb, #f59e0b 32%, var(--border))",borderRadius:12,boxShadow:"0 12px 36px rgba(0,0,0,0.28)",animation:"plan-card-in 0.18s ease-out",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"14px 16px",borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)(nz.Z,{size:18,weight:"fill",color:"var(--accent)","aria-hidden":"true"}),(0,r.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,r.jsxs)("div",{style:{fontSize:14,fontWeight:650,color:"var(--text)"},children:[i("approval.title"),t>0&&(0,r.jsxs)("span",{style:{marginLeft:8,fontSize:11,fontWeight:500,color:"var(--text-muted)"},children:["+",t," ",i("approval.queued")]})]}),(0,r.jsx)("div",{style:{fontSize:11.5,color:"var(--text-muted)",marginTop:1},children:i("approval.subtitle")})]}),(0,r.jsx)("button",{type:"button","aria-label":i("i18n.close"),onClick:()=>s(!1,"Dismissed"),disabled:o,style:{display:"flex",alignItems:"center",justifyContent:"center",width:26,height:26,padding:0,background:"none",border:"none",borderRadius:6,color:"var(--text-muted)",cursor:o?"not-allowed":"pointer"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:(0,r.jsx)(h.u,{size:14,"aria-hidden":"true"})})]}),(0,r.jsxs)("div",{style:{padding:"14px 16px",overflowY:"auto",flex:1},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:10},children:[(0,r.jsx)("span",{style:{display:"inline-flex",alignItems:"center",padding:"3px 10px",borderRadius:6,background:"var(--bg-selected)",color:"var(--text)",fontSize:12.5,fontWeight:600,fontFamily:"var(--font-mono)"},children:e.toolName}),e.args&&"object"==typeof e.args&&"command"in e.args?(0,r.jsx)("span",{style:{fontSize:11.5,color:"var(--text-muted)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:String(e.args.command??"")}):null]}),(0,r.jsx)("div",{style:{background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"10px 12px",maxHeight:220,overflow:"auto"},children:(0,r.jsx)("pre",{style:{margin:0,fontSize:11.5,lineHeight:1.55,color:"var(--text-muted)",fontFamily:"var(--font-mono)",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:g?`${u.slice(0,4e3)}
27
- …`:u})}),c&&(0,r.jsx)("textarea",{ref:d,value:a,onChange:e=>l(e.target.value),placeholder:i("approval.reasonPlaceholder"),rows:2,style:{width:"100%",marginTop:10,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"8px 10px",color:"var(--text)",fontSize:12.5,outline:"none",fontFamily:"inherit",resize:"vertical"}})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6,padding:"10px 14px",borderTop:"1px solid var(--border)"},children:[(0,r.jsxs)("button",{type:"button",onClick:()=>s(!0),disabled:o,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,width:"100%",padding:"9px 14px",borderRadius:8,background:"var(--accent)",color:"#fff",border:"none",fontSize:12.5,fontWeight:650,cursor:o?"not-allowed":"pointer",transition:"opacity 0.12s"},onMouseEnter:e=>{o||(e.currentTarget.style.opacity="0.88")},onMouseLeave:e=>{e.currentTarget.style.opacity="1"},children:[(0,r.jsx)(m.S,{size:14,weight:"bold","aria-hidden":"true"}),i("approval.allow")]}),(0,r.jsxs)("button",{type:"button",onClick:()=>{p(e=>!e),c||requestAnimationFrame(()=>d.current?.focus())},disabled:o,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,width:"100%",padding:"9px 14px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12.5,fontWeight:550,cursor:o?"not-allowed":"pointer",transition:"background 0.12s"},onMouseEnter:e=>{o||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,r.jsx)(h.u,{size:13,"aria-hidden":"true"}),i(c?"approval.hideReason":"approval.denyWithReason")]}),(0,r.jsx)("button",{type:"button",onClick:()=>s(!1,a.trim()||void 0),disabled:o,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,width:"100%",padding:"8px 14px",borderRadius:8,background:"none",border:"none",color:"var(--text-muted)",fontSize:12,cursor:o?"not-allowed":"pointer"},onMouseEnter:e=>{o||(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:i("approval.deny")})]})]})})}let nM="pi:create-task-from-text",nP=null,nE="pi-process-display-mode-v2",nW="tabs",nF="pi-process-display-mode-change";function nD(){try{let e=window.sessionStorage.getItem(nE);return"timeline"===e||"tabs"===e?e:nW}catch{return nW}}function nA(e){return window.addEventListener(nF,e),()=>window.removeEventListener(nF,e)}function nN(){return nW}function nL(e,t){if(!e)return!1;let o=new Set(t.map(e=>e.toLowerCase()));return Object.keys(e).some(e=>o.has(e.toLowerCase()))}function n$(e,t){if(!e)return;let o=new Set(t.map(e=>e.toLowerCase()));for(let[t,r]of Object.entries(e)){if(!o.has(t.toLowerCase())||"string"!=typeof r)continue;let e=r.trim();if(e)return e}}function nH(e){return"object"==typeof e&&null!==e?e:{}}function nO(e){return"add"===e||"added"===e||"create"===e?"create":"delete"===e||"deleted"===e||"remove"===e||"removed"===e?"delete":"update"===e||"modified"===e||"edit"===e||"move"===e?"edit":void 0}function nB(e){if(0!==e.length)return 1===new Set(e).size?e[0]:"edit"}function nU(e){if(Array.isArray(e))return nB(e.map(e=>nO(nH(e).type||nH(e).status||nH(e).changeType)).filter(e=>!!e))}function n_(e){if(!e)return;let t=(e.match(/^\*\*\* Add File:/gm)||[]).length,o=(e.match(/^\*\*\* Delete File:/gm)||[]).length,r=(e.match(/^\*\*\* (Update File|Move to):/gm)||[]).length;if(t||o||r){let e=[];if(t)for(let o=0;o<t;o++)e.push("create");if(o)for(let t=0;t<o;t++)e.push("delete");if(r)for(let t=0;t<r;t++)e.push("edit");return nB(e)}return/^@@ -0,0 \+\d+/m.test(e)?"create":/^@@ -\d+(?:,\d+)? \+0,0/m.test(e)?"delete":void 0}function nq(e){let t=n$(e.args,["path","file","filePath","filepath"]);if(t)return t;let o=n$(e.metadata,["relativePath","filePath","filepath","path","file"]);if(o)return o;let r=n$(Array.isArray(e.metadata?.files)?nH(e.metadata.files[0]):{},["relativePath","filePath","filepath","path","file"]);if(r)return r}function nV(e){return e.split(/[\\/]/).filter(Boolean).pop()||e}let nK=new Set(["cd","chdir","pwd","echo","set","export","source",".","pushd","popd","dirs"]),nG=new Set(["timeout"]),nJ=new Set(["ls","dir","ll","la","l","tree","eza","exa"]),nY=new Set(["rg","grep","egrep","fgrep","ack","ag","ripgrep"]),nX=new Set(["find","fd","fdfind","locate","mlocate","glob"]),nZ=new Set(["cat","head","tail","less","more","bat","nl","wc"]),nQ=new Set(["curl","wget","fetch","http","xh","httpx"]),n0=new Set(["rm","del","rmdir","unlink","erase"]),n1=new Set(["cp","mv","copy","move","rename","ren"]);var n2=o(36705),n4=o(94366),n6=o(66129),n8=o(2152),n5=o(59304),n3=o(8727),n7=o(60721),n9=o(47208),se=o(95951),st=o(29886),so=o(86756);function sr(e,t){var o,r,n;let s,i,a,l,d,c,p,u,h,g="string"==typeof(l=e.input.label)&&l.trim()?l:e.toolName;if("error"===e.status)return{displayLabel:g,iconName:"warning",tone:void 0};let m=(d=[(r=o={toolName:e.toolName,label:"string"==typeof e.input.label?e.input.label:void 0,args:e.input,result:"string"==typeof e.result?e.result:void 0}).toolName,r.title,r.label].filter(Boolean).join("\n").toLowerCase(),c=nL(o.args,["path","file","filePath","filepath"]),p=nL(o.args,["content","oldString","old_string","newString","new_string","patch","diff","edits","text"]),u=nL(o.args,["command","cmd","script"]),h=nL(o.args,["pattern","query"]),u||/\b(bash|shell|terminal|command|run|exec|execute|python|node|npm|pnpm|yarn|cargo|go|pytest|test|build|make|git|docker|kubectl|curl|wget)\b/i.test(d)?"command_execution":/\b(todo|todowrite|todo_write|write_todo|task_list|task\s*list)\b/i.test(d)?"todo_update":/\b(edit|write|patch|apply|modify|replace|update|create|delete|remove|insert|rename|move)\b/i.test(d)||c&&p?"document_change":"ls"===(s=o.toolName.toLowerCase())||"list"===s||"dir"===s||s.startsWith("list_")||s.endsWith("_list")||s.includes("list_directory")||s.includes("list_dir")||/\b(ls|list\s*directory|list\s*dir|dir\s*list|listdir)\b/i.test(d)?"directory_list":"find"===(i=o.toolName.toLowerCase())||"glob"===i||"scan"===i||i.includes("file_search")||i.includes("file_find")||i.startsWith("find_")||i.startsWith("glob_")||i.startsWith("scan_")||/\b(find[_\s]*files?|file[_\s]*find|glob|scan[_\s]*files?)\b/i.test(d)?"file_find":/\b(grep|rg|search|semantic|fuzzy|ripgrep)\b/i.test(d)||(a=o.toolName.toLowerCase()).includes("grep")||a.includes("search")||a.includes("fuzzy")||a.includes("ripgrep")||h&&!p&&!u?"document_search":/\b(read|view|open|cat|show|display)\b/i.test(d)||c&&!p&&!u?"document_read":void 0),f="toolbox";if("document_change"===m){let o,r,s,i=(r=nH((o=(n={toolName:e.toolName,label:"string"==typeof e.input.label?e.input.label:void 0,args:e.input,result:"string"==typeof e.result?e.result:void 0}).metadata||{}).filediff),s=function(e){if(!e)return{};try{return nH(JSON.parse(e))}catch{return{}}}(n.result),nU(o.files)??nU(s.files)??nO(o.type||o.status||o.changeType)??(!1===o.exists?"create":void 0)??(!0===o.exists?"edit":void 0)??n_("string"==typeof o.diff?o.diff:"")??n_("string"==typeof o.patch?o.patch:"")??n_("string"==typeof r.patch?r.patch:"")??n_("string"==typeof n.args?.patchText?n.args.patchText:"")??function(e){if(!e)return;let t=e.split(/\r?\n/).map(e=>e.trim()).filter(e=>/^[ADM]\s+/.test(e));if(0!==t.length)return nB(t.map(e=>e.startsWith("A ")?"create":e.startsWith("D ")?"delete":"edit"))}(n.result)??function(e){if(!e)return;let t=e.trim().replace(/\s+/g," ").toLowerCase();return/^(?:rm|del|erase|unlink)\b/.test(t)||/^remove-item\b/.test(t)?"delete":/^mkdir\b/.test(t)?"create":void 0}("string"==typeof n.args?.command?n.args.command:void 0)??"edit");f="create"===i?"filePlus":"delete"===i?"trash":"pencilSimpleLine";let a=t("create"===i?"desktop.processStepFileCreate":"delete"===i?"desktop.processStepFileDelete":"desktop.processStepFileEdit"),l=nq({toolName:e.toolName,label:"string"==typeof e.input.label?e.input.label:void 0,args:e.input,result:"string"==typeof e.result?e.result:void 0});return l?{displayLabel:`${a} ${nV(l)}`,iconName:f,target:l,tone:m,typeLabel:a}:{displayLabel:`${a}: ${g}`.slice(0,100),iconName:f,tone:m,typeLabel:a}}if("document_read"===m){f="bookOpen";let o=t("desktop.processStepFileRead"),r=nq({toolName:e.toolName,label:"string"==typeof e.input.label?e.input.label:void 0,args:e.input,result:"string"==typeof e.result?e.result:void 0});return r?{displayLabel:`${o} ${nV(r)}`,iconName:f,target:r,tone:m,typeLabel:o}:{displayLabel:g,iconName:f,tone:m,typeLabel:o}}if("document_search"===m){f="magnifyingGlass";let o=t("desktop.processStepSearch"),r="string"==typeof e.input.pattern?e.input.pattern:"string"==typeof e.input.query?e.input.query:"";return r?{displayLabel:`${o} "${r.slice(0,60)}"`,iconName:f,tone:m,typeLabel:o}:{displayLabel:g,iconName:f,tone:m,typeLabel:o}}if("directory_list"===m){f="folder";let o=t("desktop.processStepList"),r=nq({toolName:e.toolName,label:"string"==typeof e.input.label?e.input.label:void 0,args:e.input,result:"string"==typeof e.result?e.result:void 0});return r?{displayLabel:`${o} ${nV(r)}`,iconName:f,target:r,tone:m,typeLabel:o}:{displayLabel:g,iconName:f,tone:m,typeLabel:o}}if("file_find"===m){f="magnifyingGlass";let o=t("desktop.processStepFind"),r="string"==typeof e.input.pattern?e.input.pattern:"string"==typeof e.input.glob?e.input.glob:"";return r?{displayLabel:`${o} "${r.slice(0,60)}"`,iconName:f,tone:m,typeLabel:o}:{displayLabel:g,iconName:f,tone:m,typeLabel:o}}if("command_execution"===m){let o="string"==typeof e.input.command?e.input.command:"string"==typeof e.input.cmd?e.input.cmd:"";if(o){let e=function(e){let t=e.split(/&&|\n|;(?!;)|(?<!\|)\|(?!\|)/),o=e.split(/\s+/)[0]?.replace(/^[.\\/]+/,"")||"sh";for(let e of t){var r;let t=(r=e.trim(),r.match(/"[^"]+"|'[^']+'|\S+/g)?.map(e=>e.replace(/^(["'])(.*)\1$/,"$2"))??[]);if(0===t.length)continue;let o=0;for(;o<t.length&&(nK.has(t[o].toLowerCase())||nG.has(t[o].toLowerCase()));){let e=t[o].toLowerCase();if((o+=1)<t.length&&["cd","chdir","pushd"].includes(e)&&(o+=1),"timeout"===e)for(;o<t.length&&(t[o].startsWith("-")||/^\d/.test(t[o]));)o++}if(o>=t.length)continue;let n=t[o].replace(/^[.\\/]+/,"").toLowerCase(),s=n.split(/[/\\]/).pop()||n,i=o+1;for(;i<t.length&&t[i].startsWith("-");)i+=1;let a=i<t.length?t[i]:void 0;if(nJ.has(s))return{kind:"list",binary:s,argument:a};if(nY.has(s))return{kind:"search",binary:s,argument:a};if(nX.has(s))return{kind:"find",binary:s,argument:a};if(nZ.has(s))return{kind:"read",binary:s,argument:a};if(nQ.has(s))return{kind:"fetch",binary:s,argument:a};if(n0.has(s))return{kind:"delete",binary:s,argument:a};if(n1.has(s))return{kind:"copy",binary:s,argument:a};return{kind:"run",binary:s,argument:a}}return{kind:"run",binary:o}}(o);if("list"===e.kind){f="folder";let o=t("desktop.processStepList"),r=e.argument?` ${e.argument}`:"";return{displayLabel:`${o}${r}`,iconName:f,tone:m,typeLabel:o}}if("search"===e.kind){f="magnifyingGlass";let o=t("desktop.processStepSearch"),r=e.argument?` "${e.argument.slice(0,60)}"`:"";return{displayLabel:`${o}${r}`,iconName:f,tone:m,typeLabel:o}}if("find"===e.kind){f="magnifyingGlass";let o=t("desktop.processStepFind"),r=e.argument?` "${e.argument.slice(0,60)}"`:"";return{displayLabel:`${o}${r}`,iconName:f,tone:m,typeLabel:o}}if("read"===e.kind){f="bookOpen";let o=t("desktop.processStepRead"),r=e.argument?` ${e.argument}`:"";return{displayLabel:`${o}${r}`,iconName:f,tone:m,typeLabel:o,target:e.argument||void 0}}if("fetch"===e.kind){f="download";let o=t("desktop.processStepFetch"),r=e.argument?` ${e.argument.slice(0,80)}`:"";return{displayLabel:`${o}${r}`,iconName:f,tone:m,typeLabel:o}}if("delete"===e.kind){f="trash";let o=t("desktop.processStepDelete"),r=e.argument?` ${e.argument}`:"";return{displayLabel:`${o}${r}`,iconName:f,tone:m,typeLabel:o}}if("copy"===e.kind){f="copy";let o=t("desktop.processStepCopy"),r=e.argument?` ${e.argument}`:"";return{displayLabel:`${o}${r}`,iconName:f,tone:m,typeLabel:o}}f="terminal";let r=t("desktop.processStepCommand"),n=e.argument?`${e.binary} ${e.argument.length>60?e.argument.slice(0,57)+"...":e.argument}`:e.binary;return{displayLabel:`${r} ${n}`,iconName:f,tone:m,typeLabel:r}}return{displayLabel:g,iconName:f="terminal",tone:m}}return"todo_update"===m?{displayLabel:g,iconName:f="checklist",tone:m,typeLabel:t("desktop.processStepTodo")}:{displayLabel:g,iconName:f,tone:m}}function sn({expanded:e}){return(0,r.jsx)(b.J,{size:12,className:`shrink-0 transition-all duration-150 ${e?"rotate-90":""}`})}function ss(e,t=14){switch(e){case"brain":return(0,r.jsx)(n2.$,{size:t});case"bookOpen":return(0,r.jsx)(n4.R,{size:t});case"magnifyingGlass":return(0,r.jsx)(u.$,{size:t});case"pencilSimpleLine":return(0,r.jsx)(n9.B,{size:t});case"filePlus":return(0,r.jsx)(G.u,{size:t});case"trash":return(0,r.jsx)(T.u,{size:t});case"folder":return(0,r.jsx)(n5.sj,{size:t});case"download":return(0,r.jsx)(E.e,{size:t});case"copy":return(0,r.jsx)(n8.t,{size:t});case"terminal":return(0,r.jsx)(st.k,{size:t});case"toolbox":default:return(0,r.jsx)(so.D,{size:t});case"image":return(0,r.jsx)(n3.x,{size:t});case"listBullets":case"checklist":return(0,r.jsx)(n7.j,{size:t});case"warning":case"circleX":return(0,r.jsx)(r0.M,{size:t})}}function si({step:e,ts:t}){if("thinking"===e.kind)return ss("brain");if("image"===e.kind)return ss("image");if("custom"===e.kind)return ss("listBullets");if("toolGroup"===e.kind)return ss(e.iconName);let{iconName:o}=sr(e.block,t);return ss(o)}function sa({targets:e,typeLabel:t,count:o,label:n}){if(0===e.length)return(0,r.jsx)("span",{className:"max-w-52 truncate",title:n,children:n});if(2===e.length)return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"shrink-0",children:t}),(0,r.jsx)(sl,{filePath:e[0]}),(0,r.jsx)(sl,{filePath:e[1]})]});let s=e[0].split(".").pop()?.toLowerCase()||"",i=[],a=new Set([s]);for(let t=1;t<e.length&&i.length<2;t++){let o=e[t].split(".").pop()?.toLowerCase()||"";a.has(o)||(a.add(o),i.push({key:e[t],node:ea(e[t],12)}))}return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"shrink-0",children:t}),i.length>0&&(0,r.jsx)("span",{className:"shrink-0 inline-flex gap-px",children:i.map(e=>(0,r.jsx)("span",{className:"inline-flex",children:e.node},e.key))}),(0,r.jsx)(sl,{filePath:e[0]}),(0,r.jsxs)("span",{className:"shrink-0 text-[10px] tabular-nums text-text-dim",children:["+",o-1]})]})}function sl({filePath:e}){let t=e.split(/[\\/]/).filter(Boolean).pop()||e;return(0,r.jsxs)("span",{className:"process-file-tag",title:e,children:[ea(e,12),(0,r.jsx)("span",{children:t})]})}function sd({mode:e}){return"timeline"===e?(0,r.jsx)(se.D,{size:14}):(0,r.jsx)(n6.j,{size:14})}function sc({step:e,cwd:t,onOpenFile:o,sessionId:n,ts:s,isStreaming:i}){let a;if("thinking"===e.kind)return(0,r.jsx)(sp,{blocks:e.blocks,cwd:t,onOpenFile:o,sessionId:n,isStreaming:i});if("tool"===e.kind)return(0,r.jsxs)("div",{className:"space-y-2",children:[e.leadBlocks.length>0&&(0,r.jsx)(sp,{blocks:e.leadBlocks,cwd:t,onOpenFile:o,sessionId:n,isStreaming:i}),(0,r.jsx)(na,{block:{type:"toolCall",toolCallId:e.block.toolCallId,toolName:e.block.toolName,input:e.block.input},result:e.block.result,duration:e.block.duration,processStyle:!0})]});if("toolGroup"===e.kind)return(0,r.jsx)("div",{className:"space-y-2",children:e.blocks.map((s,a)=>(0,r.jsxs)("div",{children:[e.leadBlocks[a]&&e.leadBlocks[a].length>0&&(0,r.jsx)("div",{className:"mb-2",children:(0,r.jsx)(sp,{blocks:e.leadBlocks[a],cwd:t,onOpenFile:o,sessionId:n,isStreaming:i})}),(0,r.jsx)(na,{block:{type:"toolCall",toolCallId:s.toolCallId,toolName:s.toolName,input:s.input},result:s.result,duration:s.duration,processStyle:!0})]},s.id))});if("custom"===e.kind)return(0,r.jsx)(ne,{message:e.block.message,cwd:t,onOpenFile:o,isStreaming:i});let l="url"===(a=e.block.source).type?a.url:a.data?`data:${a.media_type??"image/png"};base64,${a.data}`:void 0;return l?(0,r.jsx)("img",{src:l,alt:s("desktop.processOutput"),className:"max-h-72 max-w-full rounded border border-border object-contain"}):null}function sp({blocks:e,cwd:t,onOpenFile:o,sessionId:n,isStreaming:s}){return(0,r.jsx)("div",{className:"space-y-2 pr-2",children:e.map(e=>"text"===e.type?(0,r.jsx)(rM,{cwd:t,onOpenFile:o,className:"!text-text-dim",isStreaming:s,children:e.text},e.id):(0,r.jsx)(ns,{block:{type:"thinking",thinking:e.thinking,deferred:e.deferred},sessionId:n,entryId:e.origin.sourceEntryId,blockIndex:e.origin.sourceBlockIndex??0,contentOnly:!0,cwd:t,onOpenFile:o,className:"!text-text-dim",isStreaming:s},e.id))})}function su({blocks:e,isStreaming:t,defaultExpanded:o=!1,onAutoExpanded:s,cwd:i,onOpenFile:a,sessionId:l,tokenRate:d=null}){let c,{t:p}=(0,A.s)(),u=(0,n.useCallback)(e=>p(e),[p]),h=(0,n.useMemo)(()=>(function(e,t,o=!1){let r=[],n=[],s=()=>{0!==n.length&&(r.push({kind:"thinking",id:n.map(e=>e.id).join("+"),label:t("desktop.processStepThinking"),blocks:n}),n=[])};for(let o of e){if("thinking"===o.type||"text"===o.type){n.push(o);continue}if("toolCall"===o.type){let{displayLabel:e}=sr(o,t);r.push({kind:"tool",id:o.id,label:e,block:o,leadBlocks:n}),n=[];continue}s(),"custom"===o.type?r.push({kind:"custom",id:o.id,label:o.customType.replace(/[_-]+/g," ").replace(/\b\w/g,e=>e.toUpperCase()),block:o}):"image"===o.type&&r.push({kind:"image",id:o.id,label:t("desktop.processOutput"),block:o})}s();try{return function(e,t,o){if(e.length<2)return e;let r=[],n=0;for(;n<e.length;){let s,i=e[n];if("tool"!==i.kind||"error"===i.block.status){r.push(i),n++;continue}let a=sr(i.block,t).tone;if(!a){r.push(i),n++;continue}let l=n+1;for(;l<e.length&&"tool"===e[l].kind;){let o=e[l];if("error"===o.block.status||sr(o.block,t).tone!==a)break;l++}if(o&&l===e.length&&l>n+1&&l--,l-n<2){r.push(i),n++;continue}let d=e.slice(n,l),c=d.map(e=>sr(e.block,t)),p=c[0].iconName,u=c[0].typeLabel||"",h=d.map(e=>e.block),g=c.map(e=>e.displayLabel),m=c.map(e=>e.target||""),f=c.map(e=>{if(e.target)return nV(e.target);let t=e.displayLabel;return e.typeLabel&&t.startsWith(e.typeLabel+" ")?t.slice(e.typeLabel.length+1):t}),x=new Set,k=new Set,v=[],y=[];for(let e=0;e<f.length;e++){let t=f[e];x.has(t)||(x.add(t),v.push(t));let o=m[e];o&&!k.has(o)&&(k.add(o),y.push(o))}let b=d.length;s=2===b&&2===v.length?`${u} ${v[0]}, ${v[1]}`:1===v.length?1===b?`${u} ${v[0]}`:`${u} ${v[0]} \xd7${b}`:2===v.length?`${u} ${v[0]}, ${v[1]}`:`${u} ${v[0]} +${v.length-1}`,r.push({kind:"toolGroup",id:h.map(e=>e.id).join("+"),label:s,blocks:h,leadBlocks:d.map(e=>e.leadBlocks),iconName:p,tone:a,typeLabel:u,targetLabels:g,targets:y}),n=l}return r}(r,t,o)}catch(e){return console.error("[ProcessGroup] mergeConsecutiveToolSteps crashed:",e),r}})(e,u,t),[e,u,t]),[g,m]=(0,n.useState)(t||o),[f,x]=(0,n.useState)({}),{displayMode:k,setDisplayMode:v}={displayMode:(0,n.useSyncExternalStore)(nA,nD,nN),setDisplayMode:(0,n.useCallback)(e=>{try{window.sessionStorage.setItem(nE,e)}catch{}window.dispatchEvent(new Event(nF))},[])},[y,b]=(0,n.useState)(0),[w,j]=(0,n.useState)(!1),[S,C]=(0,n.useState)(!1),T=(0,n.useRef)(null),R=(0,n.useRef)(!1),z=(0,n.useRef)(!1),I=(0,n.useRef)(!1),M=(0,n.useRef)(!1),P=(0,n.useRef)(!1),E=(0,n.useRef)(0);(0,n.useEffect)(()=>{if(t){R.current=!0,z.current||m(!0);return}if(!R.current)return;P.current=!1,z.current=!1,x({}),m(!1);let e=window.setTimeout(()=>m(!1),300);return R.current=!1,()=>window.clearTimeout(e)},[t]),(0,n.useEffect)(()=>{if(o&&!t&&!M.current&&h.length>0){let e=h[h.length-1];M.current=!0,x({[e.id]:!0}),window.requestAnimationFrame(()=>s?.())}},[o,t,s,h]),(0,n.useEffect)(()=>{if(0===h.length)return;let e=h[h.length-1];b(e=>I.current&&e<h.length?e:h.length-1),t&&x(t=>!0===t[e.id]&&1===Object.keys(t).length?t:{[e.id]:!0})},[t,h]);let W=(0,n.useCallback)(()=>{let e=T.current;e&&(j(t=>{let o=e.scrollTop>0;return t===o?t:o}),C(t=>{let o=e.scrollHeight-e.scrollTop-e.clientHeight>1;return t===o?t:o}))},[]),F=(0,n.useCallback)(()=>{if(Date.now()<E.current)return;let e=T.current;e&&(P.current=e.scrollHeight-e.scrollTop-e.clientHeight>4)},[]);if((0,n.useEffect)(()=>{let e=T.current;if(!e||!g)return;let t=new ResizeObserver(W);return e.addEventListener("scroll",W,{passive:!0}),t.observe(e),e.firstElementChild&&t.observe(e.firstElementChild),W(),()=>{e.removeEventListener("scroll",W),t.disconnect()}},[y,g,k,t,f,h.length,W]),(0,n.useEffect)(()=>{let e=T.current;if(e&&g)return e.addEventListener("scroll",F,{passive:!0}),()=>e.removeEventListener("scroll",F)},[g,k,F]),(0,n.useEffect)(()=>{t&&T.current&&(P.current||(E.current=Date.now()+100,T.current.scrollTop=T.current.scrollHeight,W()))},[e,t,W]),0===h.length)return null;let D=h.reduce((e,t)=>"tool"===t.kind?e+1:"toolGroup"===t.kind?e+t.blocks.length:e,0),N=h.reduce((e,t)=>"tool"===t.kind&&"error"===t.block.status?e+1:"toolGroup"===t.kind?e+t.blocks.filter(e=>"error"===e.status).length:e,0),L=e.filter(e=>"thinking"===e.type||"text"===e.type).length,$=h.filter(e=>"custom"===e.kind).length,H=1===h.length&&"thinking"===h[0].kind&&!t,O=1===h.length&&("tool"===h[0].kind||"toolGroup"===h[0].kind)&&!t;if(t)c=p("desktop.processWorking");else if(H){let e=function(e){let t;if("thinking"===e.kind){for(let o of e.blocks)"thinking"===o.type&&"number"==typeof o.duration&&(t=(t??0)+o.duration);return t}}(h[0]);c=void 0!==e?p("desktop.processThoughtDone",{duration:e}):p("desktop.processThoughtDoneNoDuration")}else if(O){let e=h[0];if("toolGroup"===e.kind){let t=e.blocks.reduce((e,t)=>e+(t.duration??0),0);c=t>0?`${e.label} ${t}s`:e.label}else{let t=e.block,o=sr(t,u),r=t.duration;c=void 0!==r?`${o.displayLabel} ${r}s`:o.displayLabel}}else{let e=[];if(D){let t=1===D?p("desktop.processToolCount",{count:D}):p("desktop.processToolsCount",{count:D});e.push(N>0?t+p("desktop.processFailedCount",{failed:N}):t)}L&&e.push(1===L?p("desktop.processThoughtCount",{count:L}):p("desktop.processThoughtsCount",{count:L})),$&&e.push(1===$?p("desktop.processCustomCount",{count:$}):p("desktop.processCustomsCount",{count:$})),c=e.length>0?p("desktop.processUsed",{summary:e.join(" \xb7 ")}):p("desktop.processCompleted")}return(0,r.jsxs)("div",{className:"group/process relative mb-3 min-w-0",children:[(0,r.jsxs)("div",{className:"group/summary-row flex items-center justify-between",children:[(0,r.jsxs)("button",{type:"button",onClick:()=>m(e=>{let o=!e;return z.current=t&&!o,o}),className:"group/summary flex min-w-0 items-center gap-1.5 text-left text-sm leading-relaxed text-text-muted transition-colors hover:text-text","aria-expanded":g,children:[(0,r.jsx)("span",{className:"truncate",children:c}),t&&null!=d&&d>0&&(0,r.jsx)("span",{className:"shrink-0 text-xs tabular-nums text-text-dim",children:p("desktop.tokensPerSecond",{count:d>=10?String(Math.round(d)):d.toFixed(1)})}),(0,r.jsx)("span",{className:`opacity-0 transition-opacity group-hover/summary:opacity-60 ${g?"rotate-90":""}`,children:(0,r.jsx)(sn,{expanded:!1})})]}),!H&&(0,r.jsx)("button",{type:"button",onClick:()=>{v("timeline"===k?"tabs":"timeline"),m(!0)},className:`shrink-0 p-1 text-text-dim transition-colors hover:text-text group-hover/summary-row:opacity-100 pointer-events-none group-hover/summary-row:pointer-events-auto ${"timeline"===k?"opacity-60":"opacity-0"}`,title:"timeline"===k?p("desktop.processTabMode"):p("desktop.processTimelineMode"),children:(0,r.jsx)(sd,{mode:k})})]}),g&&(0,r.jsx)("div",{className:"overflow-hidden",children:H?(0,r.jsxs)("div",{className:"relative mt-2",children:[(0,r.jsx)("div",{ref:T,className:"max-h-[280px] overflow-y-auto pr-2",children:(0,r.jsx)(sc,{step:h[0],cwd:i,onOpenFile:a,sessionId:l,ts:u,isStreaming:t})}),w&&(0,r.jsx)("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 top-0 z-10 h-6 bg-gradient-to-b from-bg to-transparent"}),S&&(0,r.jsx)("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 bottom-0 z-10 h-6 bg-gradient-to-t from-bg to-transparent"})]}):"timeline"===k?(0,r.jsxs)("div",{className:"relative mt-2",children:[w&&(0,r.jsx)("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 top-0 z-10 h-6 bg-gradient-to-b from-bg to-transparent"}),S&&(0,r.jsx)("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 bottom-0 z-10 h-6 bg-gradient-to-t from-bg to-transparent"}),(0,r.jsx)("div",{ref:T,className:t?"max-h-[320px] overflow-y-auto":"",children:(0,r.jsxs)("div",{className:"relative ml-5 space-y-2",children:[(0,r.jsx)("div",{className:"absolute -left-3 -top-1.5 h-4 w-2 rounded-bl border-b border-l border-border"}),h.map((e,o)=>{let n=f[e.id]??!1,s="thinking"===e.kind?e.blocks.some(e=>"text"===e.type?e.text.trim().length>0:e.deferred||e.thinking.trim().length>0):"toolGroup"!==e.kind||e.blocks.length>0,d="tool"===e.kind&&"error"===e.block.status||"toolGroup"===e.kind&&e.blocks.some(e=>"error"===e.status),c="tool"===e.kind?sr(e.block,u):null,g="toolGroup"!==e.kind&&c?.target!==void 0&&c?.typeLabel!==void 0;return(0,r.jsxs)("div",{className:"group/step relative min-w-0",children:[o<h.length-1&&(0,r.jsx)("span",{className:"absolute bottom-[-9px] left-[7px] top-[22px] border-l border-border"}),(0,r.jsxs)("button",{type:"button",onClick:()=>s&&x(t=>({...t,[e.id]:!n})),className:`flex w-full min-w-0 items-center gap-1.5 text-left text-sm leading-relaxed transition-colors ${s?"cursor-pointer":"cursor-default"} ${d?"text-red-400 hover:text-red-300":"text-text-dim hover:text-text-muted"}`,children:[(0,r.jsx)("span",{className:"shrink-0",children:(0,r.jsx)(si,{step:e,ts:u})}),"toolGroup"===e.kind&&e.targets.length>0?(0,r.jsx)(sa,{targets:e.targets,typeLabel:e.typeLabel,count:e.blocks.length,label:e.label}):g?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"shrink-0",children:c.typeLabel}),(0,r.jsx)(sl,{filePath:c.target})]}):(0,r.jsx)("span",{className:"truncate",title:"toolGroup"===e.kind?e.targetLabels.join("\n"):void 0,children:e.label}),"tool"===e.kind&&void 0!==e.block.duration&&(0,r.jsxs)("span",{className:"shrink-0 text-[11px] tabular-nums text-text-dim",children:[e.block.duration,"s"]}),d&&(0,r.jsx)("span",{className:"shrink-0 text-[11px] font-medium text-red-400",children:p("desktop.processFailedStep")}),s&&(0,r.jsx)("span",{className:`ml-0.5 shrink-0 opacity-0 transition-opacity group-hover/step:opacity-50 ${n?"rotate-90":""}`,children:(0,r.jsx)(sn,{expanded:!1})})]}),n&&s&&(0,r.jsx)("div",{className:"ml-5 mt-1.5 overflow-hidden",children:(0,r.jsx)(sc,{step:e,cwd:i,onOpenFile:a,sessionId:l,ts:u,isStreaming:t})})]},e.id)})]})})]}):(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"mt-2 flex flex-wrap gap-1",children:h.map((e,o)=>{let n="tool"===e.kind&&"error"===e.block.status||"toolGroup"===e.kind&&e.blocks.some(e=>"error"===e.status),s="tool"===e.kind?sr(e.block,u):null,i="toolGroup"!==e.kind&&s?.target!==void 0&&s?.typeLabel!==void 0,a=t&&o===h.length-1,l=y===o;return(0,r.jsxs)("button",{type:"button",onClick:()=>{o===h.length-1&&t?(I.current=!1,P.current=!1):I.current=!0,b(o)},"data-has-file-target":i?"true":void 0,title:"toolGroup"===e.kind?e.targetLabels.join("\n"):void 0,className:`process-tab flex items-center gap-1 font-mono text-xs transition-colors ${l?n?"process-tab-error":"process-tab-active":"text-text-dim hover:text-text"}${a?" process-tab-streaming":""}`,children:[(0,r.jsx)(si,{step:e,ts:u}),"toolGroup"===e.kind&&e.targets.length>0?(0,r.jsx)(sa,{targets:e.targets,typeLabel:e.typeLabel,count:e.blocks.length,label:e.label}):i?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"shrink-0",children:s.typeLabel}),(0,r.jsx)(sl,{filePath:s.target})]}):(0,r.jsx)("span",{className:`truncate ${"toolGroup"===e.kind?"max-w-64":"max-w-52"}`,title:"toolGroup"===e.kind?e.targetLabels.join("\n"):void 0,children:e.label})]},e.id)})}),(0,r.jsxs)("div",{className:"relative mt-2",children:[(0,r.jsx)("div",{ref:T,className:"max-h-[280px] overflow-y-auto pr-2",children:h[y]&&(0,r.jsx)(sc,{step:h[y],cwd:i,onOpenFile:a,sessionId:l,ts:u,isStreaming:t})}),w&&(0,r.jsx)("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 top-0 z-10 h-6 bg-gradient-to-b from-bg to-transparent"}),S&&(0,r.jsx)("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 bottom-0 z-10 h-6 bg-gradient-to-t from-bg to-transparent"})]})]})})]})}let sh=new Map;function sg(e){var t;return{value:e.value,images:e.images.map(e=>({...e})),pastedBlocks:(t=e.pastedBlocks)?t.map(e=>({...e})):void 0}}function sm(e){let t=sh.get(e);return t?sg(t):null}function sf(e,t){if(!t.value&&0===t.images.length)return void sh.delete(e);for(sh.delete(e),sh.set(e,sg(t));sh.size>100;){let e=sh.keys().next().value;if(void 0===e)break;sh.delete(e)}}function sx(e){let t=e.trim();if(!t.startsWith("file://"))return t;try{let e=new URL(t),o=decodeURIComponent(e.pathname);return/^\/[a-zA-Z]:[\\/]/.test(o)?o=o.slice(1):e.host&&"localhost"!==e.host&&(o=`//${e.host}${o}`),o}catch{let e=t.replace(/^file:\/\/(localhost)?/,"");try{e=decodeURIComponent(e)}catch{}return/^\/[a-zA-Z]:[\\/]/.test(e)&&(e=e.slice(1)),e}}let sk=["text/uri-list","x-special/nautilus-clipboard","x-special/gnome-copied-files","x-special/mate-copied-files","x-special/xfce4-copied-files","application/x-kde-cutselection","public.file-url","text/x-moz-url","application/x-moz-file"];function sv(e){var t;if(!e||"object"!=typeof e||"image"!==e.type||"string"!=typeof e.data||"string"!=typeof e.mimeType||(t=e.mimeType,!/^image\/[A-Za-z0-9][A-Za-z0-9!#$&^_.+-]*$/.test(t)))return!1;let o=function(e){if(!e||e.length%4!=0)return null;let t=e.endsWith("==")?2:+!!e.endsWith("="),o=e.length-t,r=null;for(let t=0;t<o;t+=1){var n;let o=(n=e.charCodeAt(t))>=65&&n<=90?n-65:n>=97&&n<=122?n-97+26:n>=48&&n<=57?n-48+52:43===n?62:47===n?63:null;if(null===o)return null;r=o}for(let t=o;t<e.length;t+=1)if("="!==e[t])return null;return 2===t&&r%16!=0||1===t&&r%4!=0?null:e.length/4*3-t}(e.data);return null!==o&&o<=0xa00000}function sy(e){let t=/(?:^|\s)@"([^"\n]*)$/.exec(e);if(t)return{start:e.length-(t[1].length+2),query:t[1],quoted:!0};let o=/(?:^|\s)@([^\s"]*)$/.exec(e);return o?{start:e.length-(o[1].length+1),query:o[1],quoted:!1}:null}function sb(e){let t=0;for(let o=0;o<e.length;o++)"/"===e[o]&&t++;return t}function sw(e,t){if(!e)return!0;let o=0;for(let r=0;r<t.length&&o<e.length;r++)t[r]===e[o]&&o++;return o===e.length}function sj(e,t){let o=t?`${e}/`:e;return o.includes(" ")?`@"${o}" `:`@${o} `}var sS=o(23084),sC=o(70312),sT=o(37597),sR=o(49560),sz=o(21163),sI=o(4615),sM=o(25248),sP=o(58506),sE=o(41789),sW=o(87124),sF=o(65098),sD=o(93587);function sA(e,t,o){let s=({size:n=16,style:s})=>(0,r.jsxs)("svg",{fill:t.fill,fillRule:t.fillRule,height:n,style:{flex:"none",lineHeight:1,...s},viewBox:"0 0 24 24",width:n,xmlns:"http://www.w3.org/2000/svg",children:[(0,r.jsx)("title",{children:e}),o]});return s.displayName=`${e}Icon`,(0,n.memo)(s)}let sN=sA("Anthropic",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M13.827 3.52h3.603L24 20h-3.603l-6.57-16.48zm-7.258 0h3.767L16.906 20h-3.674l-1.343-3.461H5.017l-1.344 3.46H0L6.57 3.522zm4.132 9.959L8.453 7.687 6.205 13.48H10.7z"})})),sL=sA("OpenAI",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M9.205 8.658v-2.26c0-.19.072-.333.238-.428l4.543-2.616c.619-.357 1.356-.523 2.117-.523 2.854 0 4.662 2.212 4.662 4.566 0 .167 0 .357-.024.547l-4.71-2.759a.797.797 0 00-.856 0l-5.97 3.473zm10.609 8.8V12.06c0-.333-.143-.57-.429-.737l-5.97-3.473 1.95-1.118a.433.433 0 01.476 0l4.543 2.617c1.309.76 2.189 2.378 2.189 3.948 0 1.808-1.07 3.473-2.76 4.163zM7.802 12.703l-1.95-1.142c-.167-.095-.239-.238-.239-.428V5.899c0-2.545 1.95-4.472 4.591-4.472 1 0 1.927.333 2.712.928L8.23 5.067c-.285.166-.428.404-.428.737v6.898zM12 15.128l-2.795-1.57v-3.33L12 8.658l2.795 1.57v3.33L12 15.128zm1.796 7.23c-1 0-1.927-.332-2.712-.927l4.686-2.712c.285-.166.428-.404.428-.737v-6.898l1.974 1.142c.167.095.238.238.238.428v5.233c0 2.545-1.974 4.472-4.614 4.472zm-5.637-5.303l-4.544-2.617c-1.308-.761-2.188-2.378-2.188-3.948A4.482 4.482 0 014.21 6.327v5.423c0 .333.143.571.428.738l5.947 3.449-1.95 1.118a.432.432 0 01-.476 0zm-.262 3.9c-2.688 0-4.662-2.021-4.662-4.519 0-.19.024-.38.047-.57l4.686 2.71c.286.167.571.167.856 0l5.97-3.448v2.26c0 .19-.07.333-.237.428l-4.543 2.616c-.619.357-1.356.523-2.117.523zm5.899 2.83a5.947 5.947 0 005.827-4.756C22.287 18.339 24 15.84 24 13.296c0-1.665-.713-3.282-1.998-4.448.119-.5.19-.999.19-1.498 0-3.401-2.759-5.947-5.946-5.947-.642 0-1.26.095-1.88.31A5.962 5.962 0 0010.205 0a5.947 5.947 0 00-5.827 4.757C1.713 5.447 0 7.945 0 10.49c0 1.666.713 3.283 1.998 4.448-.119.5-.19 1-.19 1.499 0 3.401 2.759 5.946 5.946 5.946.642 0 1.26-.095 1.88-.309a5.96 5.96 0 004.162 1.713z"})})),s$=sA("Google",{},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{d:"M23 12.245c0-.905-.075-1.565-.236-2.25h-10.54v4.083h6.186c-.124 1.014-.797 2.542-2.294 3.569l-.021.136 3.332 2.53.23.022C21.779 18.417 23 15.593 23 12.245z",fill:"#4285F4"}),(0,r.jsx)("path",{d:"M12.225 23c3.03 0 5.574-.978 7.433-2.665l-3.542-2.688c-.948.648-2.22 1.1-3.891 1.1a6.745 6.745 0 01-6.386-4.572l-.132.011-3.465 2.628-.045.124C4.043 20.531 7.835 23 12.225 23z",fill:"#34A853"}),(0,r.jsx)("path",{d:"M5.84 14.175A6.65 6.65 0 015.463 12c0-.758.138-1.491.361-2.175l-.006-.147-3.508-2.67-.115.054A10.831 10.831 0 001 12c0 1.772.436 3.447 1.197 4.938l3.642-2.763z",fill:"#FBBC05"}),(0,r.jsx)("path",{d:"M12.225 5.253c2.108 0 3.529.892 4.34 1.638l3.167-3.031C17.787 2.088 15.255 1 12.225 1 7.834 1 4.043 3.469 2.197 7.062l3.63 2.763a6.77 6.77 0 016.398-4.572z",fill:"#EB4335"})]})),sH=sA("DeepSeek",{},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M23.748 4.482c-.254-.124-.364.113-.512.234-.051.039-.094.09-.137.136-.372.397-.806.657-1.373.626-.829-.046-1.537.214-2.163.848-.133-.782-.575-1.248-1.247-1.548-.352-.156-.708-.311-.955-.65-.172-.241-.219-.51-.305-.774-.055-.16-.11-.323-.293-.35-.2-.031-.278.136-.356.276-.313.572-.434 1.202-.422 1.84.027 1.436.633 2.58 1.838 3.393.137.093.172.187.129.323-.082.28-.18.552-.266.833-.055.179-.137.217-.329.14a5.526 5.526 0 01-1.736-1.18c-.857-.828-1.631-1.742-2.597-2.458a11.365 11.365 0 00-.689-.471c-.985-.957.13-1.743.388-1.836.27-.098.093-.432-.779-.428-.872.004-1.67.295-2.687.684a3.055 3.055 0 01-.465.137 9.597 9.597 0 00-2.883-.102c-1.885.21-3.39 1.102-4.497 2.623C.082 8.606-.231 10.684.152 12.85c.403 2.284 1.569 4.175 3.36 5.653 1.858 1.533 3.997 2.284 6.438 2.14 1.482-.085 3.133-.284 4.994-1.86.47.234.962.327 1.78.397.63.059 1.236-.03 1.705-.128.735-.156.684-.837.419-.961-2.155-1.004-1.682-.595-2.113-.926 1.096-1.296 2.746-2.642 3.392-7.003.05-.347.007-.565 0-.845-.004-.17.035-.237.23-.256a4.173 4.173 0 001.545-.475c1.396-.763 1.96-2.015 2.093-3.517.02-.23-.004-.467-.247-.588zM11.581 18c-2.089-1.642-3.102-2.183-3.52-2.16-.392.024-.321.471-.235.763.09.288.207.486.371.739.114.167.192.416-.113.603-.673.416-1.842-.14-1.897-.167-1.361-.802-2.5-1.86-3.301-3.307-.774-1.393-1.224-2.887-1.298-4.482-.02-.386.093-.522.477-.592a4.696 4.696 0 011.529-.039c2.132.312 3.946 1.265 5.468 2.774.868.86 1.525 1.887 2.202 2.891.72 1.066 1.494 2.082 2.48 2.914.348.292.625.514.891.677-.802.09-2.14.11-3.054-.614zm1-6.44a.306.306 0 01.415-.287.302.302 0 01.2.288.306.306 0 01-.31.307.303.303 0 01-.304-.308zm3.11 1.596c-.2.081-.399.151-.59.16a1.245 1.245 0 01-.798-.254c-.274-.23-.47-.358-.552-.758a1.73 1.73 0 01.016-.588c.07-.327-.008-.537-.239-.727-.187-.156-.426-.199-.688-.199a.559.559 0 01-.254-.078c-.11-.054-.2-.19-.114-.358.028-.054.16-.186.192-.21.356-.202.767-.136 1.146.016.352.144.618.408 1.001.782.391.451.462.576.685.914.176.265.336.537.445.848.067.195-.019.354-.25.452z",fill:"#4D6BFE"})})),sO=sA("Groq",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M12.036 2c-3.853-.035-7 3-7.036 6.781-.035 3.782 3.055 6.872 6.908 6.907h2.42v-2.566h-2.292c-2.407.028-4.38-1.866-4.408-4.23-.029-2.362 1.901-4.298 4.308-4.326h.1c2.407 0 4.358 1.915 4.365 4.278v6.305c0 2.342-1.944 4.25-4.323 4.279a4.375 4.375 0 01-3.033-1.252l-1.851 1.818A7 7 0 0012.029 22h.092c3.803-.056 6.858-3.083 6.879-6.816v-6.5C18.907 4.963 15.817 2 12.036 2z"})})),sB=sA("Mistral",{},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{d:"M3.428 3.4h3.429v3.428H3.428V3.4zm13.714 0h3.43v3.428h-3.43V3.4z",fill:"gold"}),(0,r.jsx)("path",{d:"M3.428 6.828h6.857v3.429H3.429V6.828zm10.286 0h6.857v3.429h-6.857V6.828z",fill:"#FFAF00"}),(0,r.jsx)("path",{d:"M3.428 10.258h17.144v3.428H3.428v-3.428z",fill:"#FF8205"}),(0,r.jsx)("path",{d:"M3.428 13.686h3.429v3.428H3.428v-3.428zm6.858 0h3.429v3.428h-3.429v-3.428zm6.856 0h3.43v3.428h-3.43v-3.428z",fill:"#FA500F"}),(0,r.jsx)("path",{d:"M0 17.114h10.286v3.429H0v-3.429zm13.714 0H24v3.429H13.714v-3.429z",fill:"#E10500"})]})),sU=sA("Moonshot",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M1.052 16.916l9.539 2.552a21.007 21.007 0 00.06 2.033l5.956 1.593a11.997 11.997 0 01-5.586.865l-.18-.016-.044-.004-.084-.009-.094-.01a11.605 11.605 0 01-.157-.02l-.107-.014-.11-.016a11.962 11.962 0 01-.32-.051l-.042-.008-.075-.013-.107-.02-.07-.015-.093-.019-.075-.016-.095-.02-.097-.023-.094-.022-.068-.017-.088-.022-.09-.024-.095-.025-.082-.023-.109-.03-.062-.02-.084-.025-.093-.028-.105-.034-.058-.019-.08-.026-.09-.031-.066-.024a6.293 6.293 0 01-.044-.015l-.068-.025-.101-.037-.057-.022-.08-.03-.087-.035-.088-.035-.079-.032-.095-.04-.063-.028-.063-.027a5.655 5.655 0 01-.041-.018l-.066-.03-.103-.047-.052-.024-.096-.046-.062-.03-.084-.04-.086-.044-.093-.047-.052-.027-.103-.055-.057-.03-.058-.032a6.49 6.49 0 01-.046-.026l-.094-.053-.06-.034-.051-.03-.072-.041-.082-.05-.093-.056-.052-.032-.084-.053-.061-.039-.079-.05-.07-.047-.053-.035a7.785 7.785 0 01-.054-.036l-.044-.03-.044-.03a6.066 6.066 0 01-.04-.028l-.057-.04-.076-.054-.069-.05-.074-.054-.056-.042-.076-.057-.076-.059-.086-.067-.045-.035-.064-.052-.074-.06-.089-.073-.046-.039-.046-.039a7.516 7.516 0 01-.043-.037l-.045-.04-.061-.053-.07-.062-.068-.06-.062-.058-.067-.062-.053-.05-.088-.084a13.28 13.28 0 01-.099-.097l-.029-.028-.041-.042-.069-.07-.05-.051-.05-.053a6.457 6.457 0 01-.168-.179l-.08-.088-.062-.07-.071-.08-.042-.049-.053-.062-.058-.068-.046-.056a7.175 7.175 0 01-.027-.033l-.045-.055-.066-.082-.041-.052-.05-.064-.02-.025a11.99 11.99 0 01-1.44-2.402zm-1.02-5.794l11.353 3.037a20.468 20.468 0 00-.469 2.011l10.817 2.894a12.076 12.076 0 01-1.845 2.005L.657 15.923l-.016-.046-.035-.104a11.965 11.965 0 01-.05-.153l-.007-.023a11.896 11.896 0 01-.207-.741l-.03-.126-.018-.08-.021-.097-.018-.081-.018-.09-.017-.084-.018-.094c-.026-.141-.05-.283-.071-.426l-.017-.118-.011-.083-.013-.102a12.01 12.01 0 01-.019-.161l-.005-.047a12.12 12.12 0 01-.034-2.145zm1.593-5.15l11.948 3.196c-.368.605-.705 1.231-1.01 1.875l11.295 3.022c-.142.82-.368 1.612-.668 2.365l-11.55-3.09L.124 10.26l.015-.1.008-.049.01-.067.015-.087.018-.098c.026-.148.056-.295.088-.442l.028-.124.02-.085.024-.097c.022-.09.045-.18.07-.268l.028-.102.023-.083.03-.1.025-.082.03-.096.026-.082.031-.095a11.896 11.896 0 011.01-2.232zm4.442-4.4L17.352 4.59a20.77 20.77 0 00-1.688 1.721l7.823 2.093c.267.852.442 1.744.513 2.665L2.106 5.213l.045-.065.027-.04.04-.055.046-.065.055-.076.054-.072.064-.086.05-.065.057-.073.055-.07.06-.074.055-.069.065-.077.054-.066.066-.077.053-.06.072-.082.053-.06.067-.074.054-.058.073-.078.058-.06.063-.067.168-.17.1-.098.059-.056.076-.071a12.084 12.084 0 012.272-1.677zM12.017 0h.097l.082.001.069.001.054.002.068.002.046.001.076.003.047.002.06.003.054.002.087.005.105.007.144.011.088.007.044.004.077.008.082.008.047.005.102.012.05.006.108.014.081.01.042.006.065.01.207.032.07.012.065.011.14.026.092.018.11.022.046.01.075.016.041.01L14.7.3l.042.01.065.015.049.012.071.017.096.024.112.03.113.03.113.032.05.015.07.02.078.024.073.023.05.016.05.016.076.025.099.033.102.036.048.017.064.023.093.034.11.041.116.045.1.04.047.02.06.024.041.018.063.026.04.018.057.025.11.048.1.046.074.035.075.036.06.028.092.046.091.045.102.052.053.028.049.026.046.024.06.033.041.022.052.029.088.05.106.06.087.051.057.034.053.032.096.059.088.055.098.062.036.024.064.041.084.056.04.027.062.042.062.043.023.017c.054.037.108.075.161.114l.083.06.065.048.056.043.086.065.082.064.04.03.05.041.086.069.079.065.085.071c.712.6 1.353 1.283 1.909 2.031L7.222.994l.062-.027.065-.028.081-.034.086-.035c.113-.045.227-.09.341-.131l.096-.035.093-.033.084-.03.096-.031c.087-.03.176-.058.264-.085l.091-.027.086-.025.102-.03.085-.023.1-.026L9.04.37l.09-.023.091-.022.095-.022.09-.02.098-.021.091-.02.095-.018.092-.018.1-.018.091-.016.098-.017.092-.014.097-.015.092-.013.102-.013.091-.012.105-.012.09-.01.105-.01c.093-.01.186-.018.28-.024l.106-.008.09-.005.11-.006.093-.004.1-.004.097-.002.099-.002.197-.002z"})})),s_=sA("Minimax",{},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("defs",{children:(0,r.jsxs)("linearGradient",{id:"pi-minimax-lobe-icons-minimax-_R_0_",x1:"0%",x2:"100.182%",y1:"50.057%",y2:"50.057%",children:[(0,r.jsx)("stop",{offset:"0%","stop-color":"#E2167E"}),(0,r.jsx)("stop",{offset:"100%","stop-color":"#FE603C"})]})}),(0,r.jsx)("path",{d:"M16.278 2c1.156 0 2.093.927 2.093 2.07v12.501a.74.74 0 00.744.709.74.74 0 00.743-.709V9.099a2.06 2.06 0 012.071-2.049A2.06 2.06 0 0124 9.1v6.561a.649.649 0 01-.652.645.649.649 0 01-.653-.645V9.1a.762.762 0 00-.766-.758.762.762 0 00-.766.758v7.472a2.037 2.037 0 01-2.048 2.026 2.037 2.037 0 01-2.048-2.026v-12.5a.785.785 0 00-.788-.753.785.785 0 00-.789.752l-.001 15.904A2.037 2.037 0 0113.441 22a2.037 2.037 0 01-2.048-2.026V18.04c0-.356.292-.645.652-.645.36 0 .652.289.652.645v1.934c0 .263.142.506.372.638.23.131.514.131.744 0a.734.734 0 00.372-.638V4.07c0-1.143.937-2.07 2.093-2.07zm-5.674 0c1.156 0 2.093.927 2.093 2.07v11.523a.648.648 0 01-.652.645.648.648 0 01-.652-.645V4.07a.785.785 0 00-.789-.78.785.785 0 00-.789.78v14.013a2.06 2.06 0 01-2.07 2.048 2.06 2.06 0 01-2.071-2.048V9.1a.762.762 0 00-.766-.758.762.762 0 00-.766.758v3.8a2.06 2.06 0 01-2.071 2.049A2.06 2.06 0 010 12.9v-1.378c0-.357.292-.646.652-.646.36 0 .653.29.653.646V12.9c0 .418.343.757.766.757s.766-.339.766-.757V9.099a2.06 2.06 0 012.07-2.048 2.06 2.06 0 012.071 2.048v8.984c0 .419.343.758.767.758.423 0 .766-.339.766-.758V4.07c0-1.143.937-2.07 2.093-2.07z",fill:"url(#pi-minimax-lobe-icons-minimax-_R_0_)","fill-rule":"nonzero"})]})),sq=sA("Fireworks",{},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{"clip-rule":"evenodd",d:"M14.8 5l-2.801 6.795L9.195 5H7.397l3.072 7.428a1.64 1.64 0 003.038.002L16.598 5H14.8zm1.196 10.352l5.124-5.244-.699-1.669-5.596 5.739a1.664 1.664 0 00-.343 1.807 1.642 1.642 0 001.516 1.012L16 17l8-.02-.699-1.669-7.303.041h-.002zM2.88 10.104l.699-1.669 5.596 5.739c.468.479.603 1.189.343 1.807a1.643 1.643 0 01-1.516 1.012l-8-.018-.002.002.699-1.669 7.303.042-5.122-5.246z",fill:"#5019C5","fill-rule":"evenodd"})})),sV=sA("HuggingFace",{},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{d:"M2.25 11.535c0-3.407 1.847-6.554 4.844-8.258a9.822 9.822 0 019.687 0c2.997 1.704 4.844 4.851 4.844 8.258 0 5.266-4.337 9.535-9.687 9.535S2.25 16.8 2.25 11.535z",fill:"#FF9D0B"}),(0,r.jsx)("path",{d:"M11.938 20.086c4.797 0 8.687-3.829 8.687-8.551 0-4.722-3.89-8.55-8.687-8.55-4.798 0-8.688 3.828-8.688 8.55 0 4.722 3.89 8.55 8.688 8.55z",fill:"#FFD21E"}),(0,r.jsx)("path",{d:"M11.875 15.113c2.457 0 3.25-2.156 3.25-3.263 0-.576-.393-.394-1.023-.089-.582.283-1.365.675-2.224.675-1.798 0-3.25-1.693-3.25-.586 0 1.107.79 3.263 3.25 3.263h-.003z",fill:"#FF323D"}),(0,r.jsx)("path",{d:"M14.76 9.21c.32.108.445.753.767.585.447-.233.707-.708.659-1.204a1.235 1.235 0 00-.879-1.059 1.262 1.262 0 00-1.33.394c-.322.384-.377.92-.14 1.36.153.283.638-.177.925-.079l-.002.003zm-5.887 0c-.32.108-.448.753-.768.585a1.226 1.226 0 01-.658-1.204c.048-.495.395-.913.878-1.059a1.262 1.262 0 011.33.394c.322.384.377.92.14 1.36-.152.283-.64-.177-.925-.079l.003.003zm1.12 5.34a2.166 2.166 0 011.325-1.106c.07-.02.144.06.219.171l.192.306c.069.1.139.175.209.175.074 0 .15-.074.223-.172l.205-.302c.08-.11.157-.188.234-.165.537.168.986.536 1.25 1.026.932-.724 1.275-1.905 1.275-2.633 0-.508-.306-.426-.81-.19l-.616.296c-.52.24-1.148.48-1.824.48-.676 0-1.302-.24-1.823-.48l-.589-.283c-.52-.248-.838-.342-.838.177 0 .703.32 1.831 1.187 2.56l.18.14z",fill:"#3A3B45"}),(0,r.jsx)("path",{d:"M17.812 10.366a.806.806 0 00.813-.8c0-.441-.364-.8-.813-.8a.806.806 0 00-.812.8c0 .442.364.8.812.8zm-11.624 0a.806.806 0 00.812-.8c0-.441-.364-.8-.812-.8a.806.806 0 00-.813.8c0 .442.364.8.813.8zM4.515 13.073c-.405 0-.765.162-1.017.46a1.455 1.455 0 00-.333.925 1.801 1.801 0 00-.485-.074c-.387 0-.737.146-.985.409a1.41 1.41 0 00-.2 1.722 1.302 1.302 0 00-.447.694c-.06.222-.12.69.2 1.166a1.267 1.267 0 00-.093 1.236c.238.533.81.958 1.89 1.405l.24.096c.768.3 1.473.492 1.478.494.89.243 1.808.375 2.732.394 1.465 0 2.513-.443 3.115-1.314.93-1.342.842-2.575-.274-3.763l-.151-.154c-.692-.684-1.155-1.69-1.25-1.912-.195-.655-.71-1.383-1.562-1.383-.46.007-.889.233-1.15.605-.25-.31-.495-.553-.715-.694a1.87 1.87 0 00-.993-.312zm14.97 0c.405 0 .767.162 1.017.46.216.262.333.588.333.925.158-.047.322-.071.487-.074.388 0 .738.146.985.409a1.41 1.41 0 01.2 1.722c.22.178.377.422.445.694.06.222.12.69-.2 1.166.244.37.279.836.093 1.236-.238.533-.81.958-1.889 1.405l-.239.096c-.77.3-1.475.492-1.48.494-.89.243-1.808.375-2.732.394-1.465 0-2.513-.443-3.115-1.314-.93-1.342-.842-2.575.274-3.763l.151-.154c.695-.684 1.157-1.69 1.252-1.912.195-.655.708-1.383 1.56-1.383.46.007.889.233 1.15.605.25-.31.495-.553.718-.694.244-.162.523-.265.814-.3l.176-.012z",fill:"#FF9D0B"}),(0,r.jsx)("path",{d:"M9.785 20.132c.688-.994.638-1.74-.305-2.667-.945-.928-1.495-2.288-1.495-2.288s-.205-.788-.672-.714c-.468.074-.81 1.25.17 1.971.977.721-.195 1.21-.573.534-.375-.677-1.405-2.416-1.94-2.751-.532-.332-.907-.148-.782.541.125.687 2.357 2.35 2.14 2.707-.218.362-.983-.42-.983-.42S2.953 14.9 2.43 15.46c-.52.558.398 1.026 1.7 1.803 1.308.778 1.41.985 1.225 1.28-.187.295-3.07-2.1-3.34-1.083-.27 1.011 2.943 1.304 2.745 2.006-.2.7-2.265-1.324-2.685-.537-.425.79 2.913 1.718 2.94 1.725 1.075.276 3.813.859 4.77-.522zm4.432 0c-.687-.994-.64-1.74.305-2.667.943-.928 1.493-2.288 1.493-2.288s.205-.788.675-.714c.465.074.807 1.25-.17 1.971-.98.721.195 1.21.57.534.377-.677 1.407-2.416 1.94-2.751.532-.332.91-.148.782.541-.125.687-2.355 2.35-2.137 2.707.215.362.98-.42.98-.42S21.05 14.9 21.57 15.46c.52.558-.395 1.026-1.7 1.803-1.308.778-1.408.985-1.225 1.28.187.295 3.07-2.1 3.34-1.083.27 1.011-2.94 1.304-2.743 2.006.2.7 2.263-1.324 2.685-.537.423.79-2.912 1.718-2.94 1.725-1.077.276-3.815.859-4.77-.522z",fill:"#FFD21E"})]})),sK=sA("Cerebras",{fill:"currentColor"},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{"clip-rule":"evenodd",d:"M14.121 2.701a9.299 9.299 0 000 18.598V22.7c-5.91 0-10.7-4.791-10.7-10.701S8.21 1.299 14.12 1.299V2.7zm4.752 3.677A7.353 7.353 0 109.42 17.643l-.901 1.074a8.754 8.754 0 01-1.08-12.334 8.755 8.755 0 0112.335-1.08l-.901 1.075zm-2.255.844a5.407 5.407 0 00-5.048 9.563l-.656 1.24a6.81 6.81 0 016.358-12.043l-.654 1.24zM14.12 8.539a3.46 3.46 0 100 6.922v1.402a4.863 4.863 0 010-9.726v1.402z",fill:"#F15A29","fill-rule":"evenodd"}),(0,r.jsx)("path",{d:"M15.407 10.836a2.24 2.24 0 00-.51-.409 1.084 1.084 0 00-.544-.152c-.255 0-.483.047-.684.14a1.58 1.58 0 00-.84.912c-.074.203-.11.416-.11.631 0 .218.036.43.11.631a1.594 1.594 0 00.84.913c.2.093.43.14.684.14.216 0 .417-.046.602-.135.188-.09.35-.225.475-.392l.928 1.006c-.14.14-.3.261-.482.363a3.367 3.367 0 01-1.083.38c-.17.026-.317.04-.44.04a3.315 3.315 0 01-1.182-.21 2.825 2.825 0 01-.961-.597 2.816 2.816 0 01-.644-.929 2.987 2.987 0 01-.238-1.21c0-.444.08-.847.238-1.21.15-.35.368-.666.643-.929.278-.261.605-.464.962-.596a3.315 3.315 0 011.182-.21c.355 0 .712.068 1.072.204.361.138.685.36.944.649l-.962.97z"})]})),sG=sA("OpenRouter",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M18.654 3.87a5.087 5.087 0 110 10.174L23.7 19.09c.64.641.187 1.737-.72 1.737H8.48a8.479 8.479 0 010-16.958h10.175zM8.479 7.26a5.087 5.087 0 100 10.176 5.087 5.087 0 000-10.175z"})})),sJ=sA("XAI",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M6.469 8.776L16.512 23h-4.464L2.005 8.776H6.47zm-.004 7.9l2.233 3.164L6.467 23H2l4.465-6.324zM22 2.582V23h-3.659V7.764L22 2.582zM22 1l-9.952 14.095-2.233-3.163L17.533 1H22z"})})),sY=sA("Cloudflare",{},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{d:"M16.493 17.4c.135-.52.08-.983-.161-1.338-.215-.328-.592-.519-1.05-.519l-8.663-.109a.148.148 0 01-.135-.082c-.027-.054-.027-.109-.027-.163.027-.082.108-.164.189-.164l8.744-.11c1.05-.054 2.153-.9 2.556-1.937l.511-1.31c.027-.055.027-.11.027-.164C17.92 8.91 15.66 7 12.942 7c-2.503 0-4.628 1.638-5.381 3.903a2.432 2.432 0 00-1.803-.491c-1.21.109-2.153 1.092-2.287 2.32-.027.328 0 .628.054.9C1.56 13.688 0 15.326 0 17.319c0 .19.027.355.027.545 0 .082.08.137.161.137h15.983c.08 0 .188-.055.215-.164l.107-.437",fill:"#F38020"}),(0,r.jsx)("path",{d:"M19.238 11.75h-.242c-.054 0-.108.054-.135.109l-.35 1.2c-.134.52-.08.983.162 1.338.215.328.592.518 1.05.518l1.855.11c.054 0 .108.027.135.082.027.054.027.109.027.163-.027.082-.108.164-.188.164l-1.91.11c-1.05.054-2.153.9-2.557 1.937l-.134.355c-.027.055.026.137.107.137h6.592c.081 0 .162-.055.162-.137.107-.41.188-.846.188-1.31-.027-2.62-2.153-4.777-4.762-4.777",fill:"#FCAD32"})]})),sX=sA("Vercel",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M12 0l12 20.785H0L12 0z"})})),sZ=sA("GithubCopilot",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M19.245 5.364c1.322 1.36 1.877 3.216 2.11 5.817.622 0 1.2.135 1.592.654l.73.964c.21.278.323.61.323.955v2.62c0 .339-.173.669-.453.868C20.239 19.602 16.157 21.5 12 21.5c-4.6 0-9.205-2.583-11.547-4.258-.28-.2-.452-.53-.453-.868v-2.62c0-.345.113-.679.321-.956l.73-.963c.392-.517.974-.654 1.593-.654l.029-.297c.25-2.446.81-4.213 2.082-5.52 2.461-2.54 5.71-2.851 7.146-2.864h.198c1.436.013 4.685.323 7.146 2.864zm-7.244 4.328c-.284 0-.613.016-.962.05-.123.447-.305.85-.57 1.108-1.05 1.023-2.316 1.18-2.994 1.18-.638 0-1.306-.13-1.851-.464-.516.165-1.012.403-1.044.996a65.882 65.882 0 00-.063 2.884l-.002.48c-.002.563-.005 1.126-.013 1.69.002.326.204.63.51.765 2.482 1.102 4.83 1.657 6.99 1.657 2.156 0 4.504-.555 6.985-1.657a.854.854 0 00.51-.766c.03-1.682.006-3.372-.076-5.053-.031-.596-.528-.83-1.046-.996-.546.333-1.212.464-1.85.464-.677 0-1.942-.157-2.993-1.18-.266-.258-.447-.661-.57-1.108-.32-.032-.64-.049-.96-.05zm-2.525 4.013c.539 0 .976.426.976.95v1.753c0 .525-.437.95-.976.95a.964.964 0 01-.976-.95v-1.752c0-.525.437-.951.976-.951zm5 0c.539 0 .976.426.976.95v1.753c0 .525-.437.95-.976.95a.964.964 0 01-.976-.95v-1.752c0-.525.437-.951.976-.951zM7.635 5.087c-1.05.102-1.935.438-2.385.906-.975 1.037-.765 3.668-.21 4.224.405.394 1.17.657 1.995.657h.09c.649-.013 1.785-.176 2.73-1.11.435-.41.705-1.433.675-2.47-.03-.834-.27-1.52-.63-1.813-.39-.336-1.275-.482-2.265-.394zm6.465.394c-.36.292-.6.98-.63 1.813-.03 1.037.24 2.06.675 2.47.968.957 2.136 1.104 2.776 1.11h.044c.825 0 1.59-.263 1.995-.657.555-.556.765-3.187-.21-4.224-.45-.468-1.335-.804-2.385-.906-.99-.088-1.875.058-2.265.394zM12 7.615c-.24 0-.525.015-.84.044.03.16.045.336.06.526l-.001.159a2.94 2.94 0 01-.014.25c.225-.022.425-.027.612-.028h.366c.187 0 .387.006.612.028-.015-.146-.015-.277-.015-.409.015-.19.03-.365.06-.526a9.29 9.29 0 00-.84-.044z"})})),sQ=sA("Aws",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{d:"M6.763 11.212c0 .296.032.535.088.71.064.176.144.368.256.576.04.063.056.127.056.183 0 .08-.048.16-.152.24l-.503.335a.383.383 0 01-.208.072c-.08 0-.16-.04-.239-.112a2.47 2.47 0 01-.287-.375 6.18 6.18 0 01-.248-.471c-.622.734-1.405 1.101-2.347 1.101-.67 0-1.205-.191-1.596-.574-.39-.384-.59-.894-.59-1.533 0-.678.24-1.23.726-1.644.487-.415 1.133-.623 1.955-.623.272 0 .551.024.846.064.296.04.6.104.918.176v-.583c0-.607-.127-1.03-.375-1.277-.255-.248-.686-.367-1.3-.367-.28 0-.568.031-.863.103-.295.072-.583.16-.862.272a2.4 2.4 0 01-.28.104.488.488 0 01-.127.023c-.112 0-.168-.08-.168-.247v-.391c0-.128.016-.224.056-.28a.597.597 0 01.224-.167 4.577 4.577 0 011.005-.36 4.84 4.84 0 011.246-.151c.95 0 1.644.216 2.091.647.44.43.662 1.085.662 1.963v2.586h.016zm-3.24 1.214c.263 0 .534-.048.822-.144a1.78 1.78 0 00.758-.51 1.27 1.27 0 00.272-.512c.047-.191.08-.423.08-.694v-.335a6.66 6.66 0 00-.735-.136 6.02 6.02 0 00-.75-.048c-.535 0-.926.104-1.19.32-.263.215-.39.518-.39.917 0 .375.095.655.295.846.191.2.47.296.838.296zm6.41.862c-.144 0-.24-.024-.304-.08-.064-.048-.12-.16-.168-.311L7.586 6.726a1.398 1.398 0 01-.072-.32c0-.128.064-.2.191-.2h.783c.151 0 .255.025.31.08.065.048.113.16.16.312l1.342 5.284 1.245-5.284c.04-.16.088-.264.151-.312a.549.549 0 01.32-.08h.638c.152 0 .256.025.32.08.063.048.12.16.151.312l1.261 5.348 1.381-5.348c.048-.16.104-.264.16-.312a.52.52 0 01.311-.08h.743c.127 0 .2.065.2.2 0 .04-.009.08-.017.128a1.137 1.137 0 01-.056.2l-1.923 6.17c-.048.16-.104.263-.168.311a.51.51 0 01-.303.08h-.687c-.15 0-.255-.024-.32-.08-.063-.056-.119-.16-.15-.32L12.32 7.747l-1.23 5.14c-.04.16-.087.264-.15.32-.065.056-.177.08-.32.08l-.686.001zm10.256.215c-.415 0-.83-.048-1.229-.143-.399-.096-.71-.2-.918-.32-.128-.071-.215-.151-.247-.223a.563.563 0 01-.048-.224v-.407c0-.167.064-.247.183-.247.048 0 .096.008.144.024.048.016.12.048.2.08.271.12.566.215.878.279.32.064.63.096.95.096.502 0 .894-.088 1.165-.264a.86.86 0 00.415-.758.777.777 0 00-.215-.559c-.144-.151-.416-.287-.807-.415l-1.157-.36c-.583-.183-1.014-.454-1.277-.813a1.902 1.902 0 01-.4-1.158c0-.335.073-.63.216-.886.144-.255.335-.479.575-.654.24-.184.51-.32.83-.415.32-.096.655-.136 1.006-.136.175 0 .36.008.535.032.183.024.35.056.518.088.16.04.312.08.455.127.144.048.256.096.336.144a.69.69 0 01.24.2.43.43 0 01.071.263v.375c0 .168-.064.256-.184.256a.83.83 0 01-.303-.096 3.652 3.652 0 00-1.532-.311c-.455 0-.815.071-1.062.223-.248.152-.375.383-.375.71 0 .224.08.416.24.567.16.152.454.304.877.44l1.134.358c.574.184.99.44 1.237.767.247.327.367.702.367 1.117 0 .343-.072.655-.207.926a2.157 2.157 0 01-.583.703c-.248.2-.543.343-.886.447-.36.111-.734.167-1.142.167z"}),(0,r.jsx)("path",{d:"M.378 15.475c3.384 1.963 7.56 3.153 11.877 3.153 2.914 0 6.114-.607 9.06-1.852.44-.2.814.287.383.607-2.626 1.94-6.442 2.969-9.722 2.969-4.598 0-8.74-1.7-11.87-4.526-.247-.223-.024-.527.272-.351zm23.531-.2c.287.36-.08 2.826-1.485 4.007-.215.184-.423.088-.327-.151l.175-.439c.343-.88.802-2.198.52-2.555-.336-.43-2.22-.207-3.074-.103-.255.032-.295-.192-.063-.36 1.5-1.053 3.967-.75 4.254-.399z",fill:"#F90"})]})),s0=sA("Azure",{},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{d:"M7.242 1.613A1.11 1.11 0 018.295.857h6.977L8.03 22.316a1.11 1.11 0 01-1.052.755h-5.43a1.11 1.11 0 01-1.053-1.466L7.242 1.613z",fill:"url(#pi-azure-lobe-icons-azure-0-_R_0_)"}),(0,r.jsx)("path",{d:"M18.397 15.296H7.4a.51.51 0 00-.347.882l7.066 6.595c.206.192.477.298.758.298h6.226l-2.706-7.775z",fill:"#0078D4"}),(0,r.jsx)("path",{d:"M15.272.857H7.497L0 23.071h7.775l1.596-4.73 5.068 4.73h6.665l-2.707-7.775h-7.998L15.272.857z",fill:"url(#pi-azure-lobe-icons-azure-1-_R_0_)"}),(0,r.jsx)("path",{d:"M17.193 1.613a1.11 1.11 0 00-1.052-.756h-7.81.035c.477 0 .9.304 1.052.756l6.748 19.992a1.11 1.11 0 01-1.052 1.466h-.12 7.895a1.11 1.11 0 001.052-1.466L17.193 1.613z",fill:"url(#pi-azure-lobe-icons-azure-2-_R_0_)"}),(0,r.jsxs)("defs",{children:[(0,r.jsxs)("linearGradient",{gradientUnits:"userSpaceOnUse",id:"pi-azure-lobe-icons-azure-0-_R_0_",x1:"8.247",x2:"1.002",y1:"1.626",y2:"23.03",children:[(0,r.jsx)("stop",{"stop-color":"#114A8B"}),(0,r.jsx)("stop",{offset:"1","stop-color":"#0669BC"})]}),(0,r.jsxs)("linearGradient",{gradientUnits:"userSpaceOnUse",id:"pi-azure-lobe-icons-azure-1-_R_0_",x1:"14.042",x2:"12.324",y1:"15.302",y2:"15.888",children:[(0,r.jsx)("stop",{"stop-opacity":".3"}),(0,r.jsx)("stop",{offset:".071","stop-opacity":".2"}),(0,r.jsx)("stop",{offset:".321","stop-opacity":".1"}),(0,r.jsx)("stop",{offset:".623","stop-opacity":".05"}),(0,r.jsx)("stop",{offset:"1","stop-opacity":"0"})]}),(0,r.jsxs)("linearGradient",{gradientUnits:"userSpaceOnUse",id:"pi-azure-lobe-icons-azure-2-_R_0_",x1:"12.841",x2:"20.793",y1:"1.626",y2:"22.814",children:[(0,r.jsx)("stop",{"stop-color":"#3CCBF4"}),(0,r.jsx)("stop",{offset:"1","stop-color":"#2892DF"})]})]})]})),s1=sA("Kimi",{},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{d:"M21.846 0a1.923 1.923 0 110 3.846H20.15a.226.226 0 01-.227-.226V1.923C19.923.861 20.784 0 21.846 0z",fill:"#1783FF"}),(0,r.jsx)("path",{d:"M11.065 11.199l7.257-7.2c.137-.136.06-.41-.116-.41H14.3a.164.164 0 00-.117.051l-7.82 7.756c-.122.12-.302.013-.302-.179V3.82c0-.127-.083-.23-.185-.23H3.186c-.103 0-.186.103-.186.23V19.77c0 .128.083.23.186.23h2.69c.103 0 .186-.102.186-.23v-3.25c0-.069.025-.135.069-.178l2.424-2.406a.158.158 0 01.205-.023l6.484 4.772a7.677 7.677 0 003.453 1.283c.108.012.2-.095.2-.23v-3.06c0-.117-.07-.212-.164-.227a5.028 5.028 0 01-2.027-.807l-5.613-4.064c-.117-.078-.132-.279-.028-.381z",fill:"#fff"})]})),s2=sA("Qwen",{},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{d:"M12.604 1.34c.393.69.784 1.382 1.174 2.075a.18.18 0 00.157.091h5.552c.174 0 .322.11.446.327l1.454 2.57c.19.337.24.478.024.837-.26.43-.513.864-.76 1.3l-.367.658c-.106.196-.223.28-.04.512l2.652 4.637c.172.301.111.494-.043.77-.437.785-.882 1.564-1.335 2.34-.159.272-.352.375-.68.37-.777-.016-1.552-.01-2.327.016a.099.099 0 00-.081.05 575.097 575.097 0 01-2.705 4.74c-.169.293-.38.363-.725.364-.997.003-2.002.004-3.017.002a.537.537 0 01-.465-.271l-1.335-2.323a.09.09 0 00-.083-.049H4.982c-.285.03-.553-.001-.805-.092l-1.603-2.77a.543.543 0 01-.002-.54l1.207-2.12a.198.198 0 000-.197 550.951 550.951 0 01-1.875-3.272l-.79-1.395c-.16-.31-.173-.496.095-.965.465-.813.927-1.625 1.387-2.436.132-.234.304-.334.584-.335a338.3 338.3 0 012.589-.001.124.124 0 00.107-.063l2.806-4.895a.488.488 0 01.422-.246c.524-.001 1.053 0 1.583-.006L11.704 1c.341-.003.724.032.9.34zm-3.432.403a.06.06 0 00-.052.03L6.254 6.788a.157.157 0 01-.135.078H3.253c-.056 0-.07.025-.041.074l5.81 10.156c.025.042.013.062-.034.063l-2.795.015a.218.218 0 00-.2.116l-1.32 2.31c-.044.078-.021.118.068.118l5.716.008c.046 0 .08.02.104.061l1.403 2.454c.046.081.092.082.139 0l5.006-8.76.783-1.382a.055.055 0 01.096 0l1.424 2.53a.122.122 0 00.107.062l2.763-.02a.04.04 0 00.035-.02.041.041 0 000-.04l-2.9-5.086a.108.108 0 010-.113l.293-.507 1.12-1.977c.024-.041.012-.062-.035-.062H9.2c-.059 0-.073-.026-.043-.077l1.434-2.505a.107.107 0 000-.114L9.225 1.774a.06.06 0 00-.053-.031zm6.29 8.02c.046 0 .058.02.034.06l-.832 1.465-2.613 4.585a.056.056 0 01-.05.029.058.058 0 01-.05-.029L8.498 9.841c-.02-.034-.01-.052.028-.054l.216-.012 6.722-.012z",fill:"url(#pi-qwen-lobe-icons-qwen-_R_0_)","fill-rule":"nonzero"}),(0,r.jsx)("defs",{children:(0,r.jsxs)("linearGradient",{id:"pi-qwen-lobe-icons-qwen-_R_0_",x1:"0%",x2:"100%",y1:"0%",y2:"0%",children:[(0,r.jsx)("stop",{offset:"0%","stop-color":"#6336E7","stop-opacity":".84"}),(0,r.jsx)("stop",{offset:"100%","stop-color":"#6F69F7","stop-opacity":".84"})]})})]})),s4=sA("Zhipu",{},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M11.991 23.503a.24.24 0 00-.244.248.24.24 0 00.244.249.24.24 0 00.245-.249.24.24 0 00-.22-.247l-.025-.001zM9.671 5.365a1.697 1.697 0 011.099 2.132l-.071.172-.016.04-.018.054c-.07.16-.104.32-.104.498-.035.71.47 1.279 1.186 1.314h.366c1.309.053 2.338 1.173 2.286 2.523-.052 1.332-1.152 2.38-2.478 2.327h-.174c-.715.018-1.274.64-1.239 1.368 0 .124.018.23.053.337.209.373.54.658.96.8.75.23 1.517-.125 1.9-.782l.018-.035c.402-.64 1.17-.96 1.92-.711.854.284 1.378 1.226 1.099 2.167a1.661 1.661 0 01-2.077 1.102 1.711 1.711 0 01-.907-.711l-.017-.035c-.2-.323-.463-.58-.851-.711l-.056-.018a1.646 1.646 0 00-1.954.746 1.66 1.66 0 01-1.065.764 1.677 1.677 0 01-1.989-1.279c-.209-.906.332-1.83 1.257-2.043a1.51 1.51 0 01.296-.035h.018c.68-.071 1.151-.622 1.116-1.333a1.307 1.307 0 00-.227-.693 2.515 2.515 0 01-.366-1.403 2.39 2.39 0 01.366-1.208c.14-.195.21-.444.227-.693.018-.71-.506-1.261-1.186-1.332l-.07-.018a1.43 1.43 0 01-.299-.07l-.05-.019a1.7 1.7 0 01-1.047-2.114 1.68 1.68 0 012.094-1.101zm-5.575 10.11c.26-.264.639-.367.994-.27.355.096.633.379.728.74.095.362-.007.748-.267 1.013-.402.41-1.053.41-1.455 0a1.062 1.062 0 010-1.482zm14.845-.294c.359-.09.738.024.992.297.254.274.344.665.237 1.025-.107.36-.396.634-.756.718-.551.128-1.1-.22-1.23-.781a1.05 1.05 0 01.757-1.26zm-.064-4.39c.314.32.49.753.49 1.206 0 .452-.176.886-.49 1.206-.315.32-.74.5-1.185.5-.444 0-.87-.18-1.184-.5a1.727 1.727 0 010-2.412 1.654 1.654 0 012.369 0zm-11.243.163c.364.484.447 1.128.218 1.691a1.665 1.665 0 01-2.188.923c-.855-.36-1.26-1.358-.907-2.228a1.68 1.68 0 011.33-1.038c.593-.08 1.183.169 1.547.652zm11.545-4.221c.368 0 .708.2.892.524.184.324.184.724 0 1.048a1.026 1.026 0 01-.892.524c-.568 0-1.03-.47-1.03-1.048 0-.579.462-1.048 1.03-1.048zm-14.358 0c.368 0 .707.2.891.524.184.324.184.724 0 1.048a1.026 1.026 0 01-.891.524c-.569 0-1.03-.47-1.03-1.048 0-.579.461-1.048 1.03-1.048zm10.031-1.475c.925 0 1.675.764 1.675 1.706s-.75 1.705-1.675 1.705-1.674-.763-1.674-1.705c0-.942.75-1.706 1.674-1.706zm-2.626-.684c.362-.082.653-.356.761-.718a1.062 1.062 0 00-.238-1.028 1.017 1.017 0 00-.996-.294c-.547.14-.881.7-.752 1.257.13.558.675.907 1.225.783zm0 16.876c.359-.087.644-.36.75-.72a1.062 1.062 0 00-.237-1.019 1.018 1.018 0 00-.985-.301 1.037 1.037 0 00-.762.717c-.108.361-.017.754.239 1.028.245.263.606.377.953.305l.043-.01zM17.19 3.5a.631.631 0 00.628-.64c0-.355-.279-.64-.628-.64a.631.631 0 00-.628.64c0 .355.28.64.628.64zm-10.38 0a.631.631 0 00.628-.64c0-.355-.28-.64-.628-.64a.631.631 0 00-.628.64c0 .355.279.64.628.64zm-5.182 7.852a.631.631 0 00-.628.64c0 .354.28.639.628.639a.63.63 0 00.627-.606l.001-.034a.62.62 0 00-.628-.64zm5.182 9.13a.631.631 0 00-.628.64c0 .355.279.64.628.64a.631.631 0 00.628-.64c0-.355-.28-.64-.628-.64zm10.38.018a.631.631 0 00-.628.64c0 .355.28.64.628.64a.631.631 0 00.628-.64c0-.355-.279-.64-.628-.64zm5.182-9.148a.631.631 0 00-.628.64c0 .354.279.639.628.639a.631.631 0 00.628-.64c0-.355-.28-.64-.628-.64zm-.384-4.992a.24.24 0 00.244-.249.24.24 0 00-.244-.249.24.24 0 00-.244.249c0 .142.122.249.244.249zM11.991.497a.24.24 0 00.245-.248A.24.24 0 0011.99 0a.24.24 0 00-.244.249c0 .133.108.236.223.247l.021.001zM2.011 6.36a.24.24 0 00.245-.249.24.24 0 00-.244-.249.24.24 0 00-.244.249.24.24 0 00.244.249zm0 11.263a.24.24 0 00-.243.248.24.24 0 00.244.249.24.24 0 00.244-.249.252.252 0 00-.244-.248zm19.995-.018a.24.24 0 00-.245.248.24.24 0 00.245.25.24.24 0 00.244-.25.252.252 0 00-.244-.248z",fill:"#3859FF","fill-rule":"nonzero"})})),s6=sA("Cohere",{},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{"clip-rule":"evenodd",d:"M8.128 14.099c.592 0 1.77-.033 3.398-.703 1.897-.781 5.672-2.2 8.395-3.656 1.905-1.018 2.74-2.366 2.74-4.18A4.56 4.56 0 0018.1 1H7.549A6.55 6.55 0 001 7.55c0 3.617 2.745 6.549 7.128 6.549z",fill:"#39594D","fill-rule":"evenodd"}),(0,r.jsx)("path",{"clip-rule":"evenodd",d:"M9.912 18.61a4.387 4.387 0 012.705-4.052l3.323-1.38c3.361-1.394 7.06 1.076 7.06 4.715a5.104 5.104 0 01-5.105 5.104l-3.597-.001a4.386 4.386 0 01-4.386-4.387z",fill:"#D18EE2","fill-rule":"evenodd"}),(0,r.jsx)("path",{d:"M4.776 14.962A3.775 3.775 0 001 18.738v.489a3.776 3.776 0 007.551 0v-.49a3.775 3.775 0 00-3.775-3.775z",fill:"#FF7759"})]})),s8=sA("Perplexity",{},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M19.785 0v7.272H22.5V17.62h-2.935V24l-7.037-6.194v6.145h-1.091v-6.152L4.392 24v-6.465H1.5V7.188h2.884V0l7.053 6.494V.19h1.09v6.49L19.786 0zm-7.257 9.044v7.319l5.946 5.234V14.44l-5.946-5.397zm-1.099-.08l-5.946 5.398v7.235l5.946-5.234V8.965zm8.136 7.58h1.844V8.349H13.46l6.105 5.54v2.655zm-8.982-8.28H2.59v8.195h1.8v-2.576l6.192-5.62zM5.475 2.476v4.71h5.115l-5.115-4.71zm13.219 0l-5.115 4.71h5.115v-4.71z",fill:"#22B8CD","fill-rule":"nonzero"})})),s5=sA("Together",{},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{d:"M23.197 4.503A6 6 0 0015 2.307a5.973 5.973 0 00-2.995 4.933l5.996.008v.515h-5.996c.039.937.298 1.87.8 2.74a6 6 0 1010.39-6z",fill:"#EF2CC1"}),(0,r.jsx)("path",{d:"M.805 4.5A6 6 0 003 12.697a5.972 5.972 0 005.77.127L5.779 7.627l.446-.257 2.997 5.192A6 6 0 10.804 4.5z",fill:"#CAAEF5"}),(0,r.jsx)("path",{d:"M12 23.894a6 6 0 005.999-6c0-2.13-1.1-3.996-2.775-5.06l-3.005 5.189-.444-.258 2.997-5.192A6 6 0 1012 23.894z",fill:"#FC4C02"})]})),s3=sA("Grok",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M9.27 15.29l7.978-5.897c.391-.29.95-.177 1.137.272.98 2.369.542 5.215-1.41 7.169-1.951 1.954-4.667 2.382-7.149 1.406l-2.711 1.257c3.889 2.661 8.611 2.003 11.562-.953 2.341-2.344 3.066-5.539 2.388-8.42l.006.007c-.983-4.232.242-5.924 2.75-9.383.06-.082.12-.164.179-.248l-3.301 3.305v-.01L9.267 15.292M7.623 16.723c-2.792-2.67-2.31-6.801.071-9.184 1.761-1.763 4.647-2.483 7.166-1.425l2.705-1.25a7.808 7.808 0 00-1.829-1A8.975 8.975 0 005.984 5.83c-2.533 2.536-3.33 6.436-1.962 9.764 1.022 2.487-.653 4.246-2.34 6.022-.599.63-1.199 1.259-1.682 1.925l7.62-6.815"})})),s7=sA("AntGroup",{},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{d:"M9.797 6.282a.451.451 0 01-.336-.315 1.019 1.019 0 010-.505c.156-.86.3-1.725.501-2.577.14-.7.42-1.367.823-1.96.305-.431.75-.746 1.262-.89.877-.217 1.24.629.937 1.348-.259.593-.877.914-1.334 1.348-.835.795-1.096 2.14-1.336 3.212a.427.427 0 01-.186.277.437.437 0 01-.331.062z",fill:"url(#pi-antgroup-lobe-icons-antgroup-0-_R_0_)",transform:"translate(3)"}),(0,r.jsx)("path",{d:"M6.334 4.672c.33-.121.682.146.946.297.278.145.587.219.901.214.231.01.466 0 .688.018 4.098.176 7.484 3.22 8.05 7.237.565 4.016-1.852 7.859-5.745 9.134-3.894 1.276-8.153-.38-10.126-3.935A8.339 8.339 0 013.133 7.081c.348-.278.716-.53 1.102-.755a8.404 8.404 0 001.318-.79c.28-.243.45-.742.781-.864zm4.406 2.15c-2.841.003-4.898 2.533-4.628 5.642.27 3.109 2.781 5.641 5.613 5.665 2.832.024 4.932-2.512 4.658-5.644-.273-3.133-2.802-5.666-5.643-5.663zm.357.57a4.707 4.707 0 013.304 1.446 5.703 5.703 0 011.643 3.49 4.841 4.841 0 01-1.141 3.705v.015a3.923 3.923 0 01-2.808 1.303 4.664 4.664 0 01-3.367-1.387 5.678 5.678 0 01-1.71-3.518 4.832 4.832 0 011.14-3.753 3.923 3.923 0 012.813-1.3h.126z",fill:"url(#pi-antgroup-lobe-icons-antgroup-1-_R_0_)",transform:"translate(3)"}),(0,r.jsx)("path",{d:"M2.346 2.054a1.26 1.26 0 01.384-.594.842.842 0 011.165.11c.694.82.169 2.078.142 3.02.013.805.208 1.597.57 2.318.084.134.147.279.186.43a.539.539 0 01-.3.577c-.345.17-.568-.19-.709-.446-.324-.6-.617-1.216-.877-1.846a8.698 8.698 0 01-.618-1.987 7.523 7.523 0 01-.051-.37 3.717 3.717 0 01-.024-.34 2.506 2.506 0 01.132-.872z",fill:"url(#pi-antgroup-lobe-icons-antgroup-2-_R_0_)",transform:"translate(3)"}),(0,r.jsxs)("defs",{children:[(0,r.jsxs)("linearGradient",{id:"pi-antgroup-lobe-icons-antgroup-0-_R_0_",x1:"31.373%",x2:"61.365%",y1:"95.551%",y2:"-.348%",children:[(0,r.jsx)("stop",{offset:"0%","stop-color":"#06F"}),(0,r.jsx)("stop",{offset:"20%","stop-color":"#1677FF"}),(0,r.jsx)("stop",{offset:"100%","stop-color":"#04A6FF"})]}),(0,r.jsxs)("linearGradient",{id:"pi-antgroup-lobe-icons-antgroup-1-_R_0_",x1:"4.366%",x2:"94.359%",y1:"65.982%",y2:"32.918%",children:[(0,r.jsx)("stop",{offset:"0%","stop-color":"#06F"}),(0,r.jsx)("stop",{offset:"20%","stop-color":"#1677FF"}),(0,r.jsx)("stop",{offset:"100%","stop-color":"#04A6FF"})]}),(0,r.jsxs)("linearGradient",{id:"pi-antgroup-lobe-icons-antgroup-2-_R_0_",x1:"56.255%",x2:"45.986%",y1:"99.257%",y2:"1.384%",children:[(0,r.jsx)("stop",{offset:"0%","stop-color":"#06F"}),(0,r.jsx)("stop",{offset:"20%","stop-color":"#1677FF"}),(0,r.jsx)("stop",{offset:"100%","stop-color":"#04A6FF"})]})]})]})),s9=sA("Nvidia",{},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M10.212 8.976V7.62c.127-.01.256-.017.388-.021 3.596-.117 5.957 3.184 5.957 3.184s-2.548 3.647-5.282 3.647a3.227 3.227 0 01-1.063-.175v-4.109c1.4.174 1.681.812 2.523 2.258l1.873-1.627a4.905 4.905 0 00-3.67-1.846 6.594 6.594 0 00-.729.044m0-4.476v2.025c.13-.01.259-.019.388-.024 5.002-.174 8.261 4.226 8.261 4.226s-3.743 4.69-7.643 4.69c-.338 0-.675-.031-1.007-.092v1.25c.278.038.558.057.838.057 3.629 0 6.253-1.91 8.794-4.169.421.347 2.146 1.193 2.501 1.564-2.416 2.083-8.048 3.763-11.24 3.763-.308 0-.603-.02-.894-.048V19.5H24v-15H10.21zm0 9.756v1.068c-3.356-.616-4.287-4.21-4.287-4.21a7.173 7.173 0 014.287-2.138v1.172h-.005a3.182 3.182 0 00-2.502 1.178s.615 2.276 2.507 2.931m-5.961-3.3c1.436-1.935 3.604-3.148 5.961-3.336V6.523C5.81 6.887 2 10.723 2 10.723s2.158 6.427 8.21 7.015v-1.166C5.77 16 4.25 10.958 4.25 10.958h-.002z",fill:"#74B71B","fill-rule":"nonzero"})})),ie=sA("OpenCode",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M16 6H8v12h8V6zm4 16H4V2h16v20z"})})),it=sA("XiaomiMiMo",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M.958 15.936a.459.459 0 01.459.44v2.729a.46.46 0 01-.918 0v-2.729a.459.459 0 01.459-.44zm4.814-2.035a.46.46 0 01.553.45v4.754a.458.458 0 11-.918 0V15.48L3.74 17.202a.462.462 0 01-.655.016.462.462 0 01-.065-.082L.628 14.67a.459.459 0 01.658-.637l2.124 2.187 2.127-2.188a.46.46 0 01.235-.13zm2.068.004a.46.46 0 01.458.445v4.755a.46.46 0 01-.458.458.459.459 0 01-.458-.458V14.35a.459.459 0 01.458-.445zm1.973 2.014a.46.46 0 01.46.457v2.729a.46.46 0 01-.784.324.46.46 0 01-.134-.324v-2.729a.46.46 0 01.458-.458zm.002-2.045a.458.458 0 01.328.157l2.127 2.19 2.125-2.19a.459.459 0 01.784.318v4.756a.46.46 0 01-.455.458.46.46 0 01-.458-.458V15.48l-1.667 1.723a.46.46 0 01-.65.008l-.005-.005c0-.002-.002-.002-.004-.003l-2.455-2.534a.46.46 0 01-.008-.667.461.461 0 01.338-.128zm6.797 1.206a.46.46 0 01.53.651A1.966 1.966 0 0019.81 18.4a.462.462 0 01.623.18.46.46 0 01-.181.624 2.863 2.863 0 01-1.38.353l-.142-.004a2.88 2.88 0 01-2.393-4.263.461.461 0 01.274-.21zm.864-.931a2.884 2.884 0 013.915 3.914.46.46 0 01-.402.24l-.057-.004a.458.458 0 01-.164-.055.46.46 0 01-.182-.622 1.967 1.967 0 00-2.669-2.67.459.459 0 11-.441-.803zM9.59 6.368c1.481 0 1.696 1.202 1.696 1.654v2.648h-.917v-.432c-.26.346-.792.535-1.36.535-.133 0-1.289-.03-1.384-1.136-.082-.932.675-1.61 2.053-1.61h.691c0-.563-.367-.886-.983-.886-.44.013-.864.174-1.2.458l-.36-.664c.484-.379 1.012-.567 1.764-.567zm4.427.1c1.263 0 2.082.97 2.083 2.15 0 1.181-.824 2.154-2.083 2.154-1.26 0-2.084-.972-2.084-2.152 0-1.18.82-2.153 2.084-2.153zm6.801.015c.68 0 1.202.465 1.197 1.548v2.642H21.1V8.29c0-.312-.002-.98-.63-.98s-.628.667-.628.838v2.524h-.89V8.148c0-.17-.001-.838-.63-.838-.628 0-.628.668-.628.98v2.383h-.917v-4.03h.917V7a1.22 1.22 0 01.947-.516c.398 0 .76.193.982.686a1.321 1.321 0 011.195-.686zm-18.093.872l1.457-1.772H5.32L3.311 8.07l2.14 2.602H4.24L2.725 8.796 1.21 10.672H0L2.138 8.07.13 5.583h1.138l1.458 1.772zm4.149 3.317h-.916V6.644h.916v4.028zm16.99 0h-.916V6.644h.916v4.028zM9.925 8.71c-1.055 0-1.359.412-1.326.742.032.329.324.537.757.537a1.013 1.013 0 001.014-.968l.002-.31h-.447zM14.018 7.3c-.663 0-1.184.487-1.184 1.32 0 .832.52 1.32 1.184 1.32.662 0 1.182-.49 1.182-1.32 0-.832-.52-1.32-1.182-1.32zM6.417 5.001a.568.568 0 01.587.582.588.588 0 01-1.175 0A.57.57 0 016.417 5zm16.991 0a.57.57 0 01.592.582.588.588 0 01-1.174 0 .57.57 0 01.357-.542.572.572 0 01.225-.04z"})})),io=sA("ZAI",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M12.105 2L9.927 4.953H.653L2.83 2h9.276zM23.254 19.048L21.078 22h-9.242l2.174-2.952h9.244zM24 2L9.264 22H0L14.736 2H24z"})})),ir={anthropic:{Icon:sN,hasColor:!1},openai:{Icon:sL,hasColor:!1},"openai-codex":{Icon:sL,hasColor:!1},reqtoken:{Icon:sL,hasColor:!1},google:{Icon:s$,hasColor:!0},"google-vertex":{Icon:s$,hasColor:!0},"ant-ling":{Icon:s7,hasColor:!0},deepseek:{Icon:sH,hasColor:!0},groq:{Icon:sO,hasColor:!1},mistral:{Icon:sB,hasColor:!0},moonshotai:{Icon:sU,hasColor:!1},"moonshotai-cn":{Icon:sU,hasColor:!1},moonshot:{Icon:sU,hasColor:!1},minimax:{Icon:s_,hasColor:!0},"minimax-cn":{Icon:s_,hasColor:!0},fireworks:{Icon:sq,hasColor:!0},huggingface:{Icon:sV,hasColor:!0},cerebras:{Icon:sK,hasColor:!0},openrouter:{Icon:sG,hasColor:!1},xai:{Icon:sJ,hasColor:!1},"cloudflare-ai-gateway":{Icon:sY,hasColor:!0},"cloudflare-workers-ai":{Icon:sY,hasColor:!0},"vercel-ai-gateway":{Icon:sX,hasColor:!1},"github-copilot":{Icon:sZ,hasColor:!1},"amazon-bedrock":{Icon:sQ,hasColor:!0},"azure-openai-responses":{Icon:s0,hasColor:!0},"kimi-coding":{Icon:s1,hasColor:!0},nvidia:{Icon:s9,hasColor:!0},opencode:{Icon:ie,hasColor:!1},"opencode-go":{Icon:ie,hasColor:!1},qwen:{Icon:s2,hasColor:!0},xiaomi:{Icon:it,hasColor:!1},"xiaomi-token-plan-ams":{Icon:it,hasColor:!1},"xiaomi-token-plan-cn":{Icon:it,hasColor:!1},"xiaomi-token-plan-sgp":{Icon:it,hasColor:!1},zai:{Icon:io,hasColor:!1},"zai-coding-cn":{Icon:io,hasColor:!1},zhipu:{Icon:s4,hasColor:!0},cohere:{Icon:s6,hasColor:!0},perplexity:{Icon:s8,hasColor:!0},together:{Icon:s5,hasColor:!0},grok:{Icon:s3,hasColor:!1}};function is({id:e,size:t=14}){let o=ir[e];return o?o.hasColor?(0,r.jsx)(o.Icon,{size:t}):(0,r.jsx)(o.Icon,{size:t,style:{color:"currentColor"}}):(0,r.jsx)(z.G,{size:t,weight:"regular","aria-hidden":"true"})}var ii=o(61394),ia=o(21418);let il=[{value:"normal",Icon:ii.f,titleKey:"modes.collabNormalTitle",descKey:"modes.collabNormalDesc"},{value:"plan",Icon:ia._,titleKey:"modes.collabPlanTitle",descKey:"modes.collabPlanDesc"},{value:"goal",Icon:nw.d,titleKey:"modes.collabGoalTitle",descKey:"modes.collabGoalDesc"}],id={normal:ii.f,plan:ia._,goal:nw.d};function ic({collaborationMode:e,onCollaborationModeChange:t,disabled:o=!1}){let s,{t:i}=(0,A.s)(),[a,l]=(0,n.useState)(null),[d,c]=(0,n.useState)(null),[p,u]=(0,n.useState)({}),h=(0,n.useRef)(null),g=(0,n.useRef)(null);(0,n.useEffect)(()=>()=>{null!==g.current&&window.clearTimeout(g.current)},[]);let f=(0,n.useCallback)(e=>{c(e),window.requestAnimationFrame(()=>l(t=>t===e?null:t)),null!==g.current&&window.clearTimeout(g.current),g.current=window.setTimeout(()=>c(null),150)},[]),x=()=>window.visualViewport?.height??window.innerHeight,v=id[e],y="plan"===e?i("modes.collabPlan"):"goal"===e?i("modes.collabGoal"):i("modes.collabNormal");return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{style:{display:"flex",alignItems:"center",gap:2},children:(0,r.jsxs)("button",{ref:h,type:"button","aria-label":i("modes.collabNormalTitle"),title:i("modes.collabNormalTitle"),"aria-expanded":"collab"===a,onClick:(s="collab",()=>{if(o)return;let e=h.current;if(!e)return;let t=e.getBoundingClientRect();u(e=>({...e,[s]:{top:t.top,left:t.left,width:t.width}})),l(e=>e===s?null:s)}),disabled:o,style:{display:"flex",alignItems:"center",gap:3,padding:"3px 6px",height:24,background:"collab"===a?"var(--bg-hover)":"none",border:"none",borderRadius:6,color:"normal"!==e?"var(--accent)":"var(--text-muted)",cursor:o?"not-allowed":"pointer",fontSize:12,whiteSpace:"nowrap",opacity:o?.5:1,transition:"background 0.12s, color 0.12s"},children:[(0,r.jsx)(v,{size:13,weight:"normal"!==e?"fill":"regular",color:"normal"!==e?"var(--accent)":"var(--text-muted)","aria-hidden":"true"}),(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis"},children:y}),(0,r.jsx)(k.b,{size:10,weight:"bold","aria-hidden":"true",style:{transform:"collab"===a?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.12s",flexShrink:0}})]})}),(()=>{if("collab"!==a)return null;let n=p.collab;if(!n)return null;let s=Math.min(248,window.innerWidth-16),l=Math.min(n.left,window.innerWidth-s-8),c=x()-n.top+6,u=Math.min(300,Math.max(120,.55*x()));return(0,r.jsx)("div",{role:"menu",style:{position:"fixed",bottom:c,left:l,zIndex:2100,width:s,maxHeight:u,overflowY:"auto",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 12px 32px rgba(0,0,0,0.22)",padding:4,opacity:+("collab"!==d),transition:"opacity 0.12s"},children:il.map(n=>{let s=n.value===e,a=n.Icon;return(0,r.jsxs)("button",{type:"button",role:"menuitemradio","aria-checked":s,onClick:()=>{var o;return o=n.value,void(f("collab"),o!==e&&t(o))},disabled:o,style:{display:"flex",alignItems:"center",gap:10,width:"100%",padding:"8px 10px",background:s?"var(--bg-selected)":"none",border:"none",borderRadius:8,cursor:o?"not-allowed":"pointer",textAlign:"left",transition:"background 0.12s"},onMouseEnter:e=>{s||o||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{e.currentTarget.style.background=s?"var(--bg-selected)":"none"},children:[(0,r.jsx)(a,{size:16,weight:s?"fill":"regular",color:s?"var(--accent)":"var(--text-muted)","aria-hidden":"true"}),(0,r.jsxs)("span",{style:{flex:1,minWidth:0},children:[(0,r.jsx)("span",{style:{display:"block",fontSize:12.5,fontWeight:550,color:"var(--text)"},children:i(n.titleKey)}),(0,r.jsx)("span",{style:{display:"block",fontSize:10.5,color:"var(--text-muted)",marginTop:1,lineHeight:1.4},children:i(n.descKey)})]}),s&&(0,r.jsx)(m.S,{size:12,weight:"bold",color:"var(--accent)","aria-hidden":"true"})]},n.value)})})})()]})}let ip=["off","default","full"],iu={off:"none",default:"default",full:"full"},ih=new Intl.Collator(void 0,{numeric:!0,sensitivity:"base"});function ig(e,t){return ih.compare(e.name||e.modelId,t.name||t.modelId)||ih.compare(e.provider,t.provider)||ih.compare(e.modelId,t.modelId)}let im=["max","xhigh","high","medium","low","minimal","auto","off"];function ix({level:e,size:t=14}){if("off"===e)return(0,r.jsx)(sP.x,{size:t,weight:"regular",color:"var(--text-dim)"});if("auto"===e)return(0,r.jsx)(sD.I,{size:t,weight:"regular",color:"var(--accent)"});let o=["medium","high","xhigh","max"].includes(e),n="var(--accent)";return(0,r.jsxs)("span",{style:{position:"relative",display:"inline-flex"},children:[(0,r.jsx)(sP.x,{size:t,weight:o?"fill":"regular",color:n}),"high"===e&&(0,r.jsx)(v.c,{size:Math.round(.57*t),weight:"bold",color:n,style:{position:"absolute",right:-4,top:-1}}),"xhigh"===e&&(0,r.jsx)(g.C,{size:Math.round(.57*t),weight:"fill",color:n,style:{position:"absolute",right:-4,top:-1}}),"max"===e&&(0,r.jsxs)("span",{style:{position:"absolute",right:-6,top:-1,display:"inline-flex"},children:[(0,r.jsx)(g.C,{size:Math.round(.5*t),weight:"fill",color:n,style:{marginRight:-3}}),(0,r.jsx)(g.C,{size:Math.round(.5*t),weight:"fill",color:n})]})]})}function ik(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${Math.round(e/1e3)}k`:e.toLocaleString()}let iv=["builtin","extension","prompt","skill"],iy={builtin:0,extension:1,prompt:2,skill:3};function ib(e,t){let o=e.name.toLowerCase(),r=e.description?.toLowerCase()??"";return o===t?0:o.startsWith(t)?1:o.includes(t)?2:r.includes(t)?3:4}function iw(e,t){return"skill"===e.source&&e.name.startsWith("skill:")&&!0===t[e.name.slice(6)]}async function ij(e){let t=()=>{var t;return t=e.type,new Promise((o,r)=>{let n=new FileReader;n.onload=()=>{let e="string"==typeof n.result?n.result.split(",")[1]:void 0;e?o({data:e,mimeType:t}):r(Error("Failed to read image"))},n.onerror=r,n.readAsDataURL(e)})};if(!(e.size>1048576&&"image/gif"!==e.type)||"function"!=typeof createImageBitmap)return t();let o=await createImageBitmap(e).catch(()=>null);if(!o)return t();try{let r=Math.min(1,1024/Math.max(o.width,o.height)),n=document.createElement("canvas");n.width=Math.max(1,Math.round(o.width*r)),n.height=Math.max(1,Math.round(o.height*r));let s=n.getContext("2d");if(!s)return t();s.fillStyle="#fff",s.fillRect(0,0,n.width,n.height),s.drawImage(o,0,0,n.width,n.height);let i=n.toDataURL("image/jpeg",.85).split(",")[1];return i&&i.length<4*Math.ceil(e.size/3)?{data:i,mimeType:"image/jpeg"}:t()}catch{return t()}finally{o.close()}}function iS(e){return{data:e.data,mimeType:e.mimeType}}function iC(e,t){let o=e;for(let e of t)o=o.split(e.label).join(e.text);return o}function iT(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function iR(e){return{...e,previewUrl:`data:${e.mimeType};base64,${e.data}`}}function iz(e){e.previewUrl.startsWith("blob:")&&URL.revokeObjectURL(e.previewUrl)}function iI({kind:e,text:t,label:o,index:n,total:s,onMove:i,onRecall:a,onRemove:l}){let{t:d}=(0,A.s)(),c={display:"inline-flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,border:"none",borderRadius:4,color:"var(--text-dim)",background:"transparent",cursor:"pointer",flexShrink:0};return(0,r.jsxs)("div",{title:t,style:{display:"flex",alignItems:"center",gap:8,padding:"3px 10px",fontSize:12,color:"var(--text-muted)",minWidth:0},children:[(0,r.jsx)("span",{style:{flexShrink:0,fontSize:10,fontFamily:"var(--font-mono)",padding:"1px 7px",borderRadius:999,border:`1px solid ${"steer"===e?"color-mix(in srgb, var(--accent) 45%, transparent)":"var(--border)"}`,color:"steer"===e?"var(--accent)":"var(--text-dim)"},children:o}),(0,r.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:t}),i&&s>1&&(0,r.jsxs)("span",{style:{display:"inline-flex",gap:1,flexShrink:0},children:[(0,r.jsx)("button",{type:"button","aria-label":d("desktop.queueMoveUp"),title:d("desktop.queueMoveUp"),disabled:0===n,onClick:()=>i(-1),style:{...c,opacity:0===n?.3:1},children:"↑"}),(0,r.jsx)("button",{type:"button","aria-label":d("desktop.queueMoveDown"),title:d("desktop.queueMoveDown"),disabled:n===s-1,onClick:()=>i(1),style:{...c,opacity:n===s-1?.3:1},children:"↓"})]}),a&&(0,r.jsx)("button",{type:"button","aria-label":d("desktop.queueRecallOne"),title:d("desktop.queueRecallOne"),onClick:a,style:c,children:(0,r.jsx)(sC.Y,{size:13})}),l&&(0,r.jsx)("button",{type:"button","aria-label":d("desktop.queueRemove"),title:d("desktop.queueRemove"),onClick:l,style:c,children:(0,r.jsx)(h.u,{size:13})})]})}let iM=(0,n.memo)((0,n.forwardRef)(function({onSend:e,onBash:t,onAbort:o,onSteer:s,onFollowUp:i,isStreaming:a,model:l,modelNames:d,modelList:c,modelScopeWarnings:p,modelsError:f,onRetryModels:x,onModelChange:y,compactResult:w,toolPreset:j,onToolPresetChange:S,planMode:z=!1,onPlanModeChange:M,collaborationMode:P="normal",toolApprovalMode:E="auto",onCollaborationModeChange:W,goalState:F,onGoalStart:D,onGoalPause:N,onGoalResume:L,onGoalStop:$,thinkingLevel:H,onThinkingLevelChange:B,availableThinkingLevels:U,thinkingLevelMap:_,retryInfo:q,queuedMessages:V,inputHistory:K=[],onRecallQueue:G,onMoveQueue:J,onRecallOne:Y,onRequeueAt:X,onRemoveQueueItem:Z,slashCommands:Q,slashCommandsLoading:ee,onLoadSlashCommands:et,onBuiltinCommand:er,onAudioUnlock:en,onPromptWithStreamingBehavior:es,draftKey:ei,cwd:el,tasksBoardEnabled:ed=!0},ec){var ep;let eu,eh,eg,em,ef,ex,ek,ev,ey,eb,ew,ej,eS,eC,eT,eR,ez,eI,eM,eP,eE,eW,eF,eD=O(),{t:eA}=(0,A.s)(),eN={auto:"auto",off:"off",minimal:"minimal",low:"low",medium:"medium",high:"high",xhigh:"xhigh",max:"max"},eL={off:eA("desktop.toolOff"),default:eA("desktop.toolDefault"),full:eA("desktop.toolFull")},e$=[{name:"compact",description:eA("desktop.compactCommandDescription"),source:"builtin"},{name:"reload",description:eA("desktop.reloadCommandDescription"),source:"builtin"},{name:"name",description:eA("desktop.nameCommandDescription"),source:"builtin"},{name:"session",description:eA("desktop.sessionCommandDescription"),source:"builtin"},{name:"copy",description:eA("desktop.copyCommandDescription"),source:"builtin"}],eH={builtin:eA("desktop.builtIn"),extension:eA("desktop.extensions"),prompt:eA("desktop.prompts"),skill:eA("desktop.commandSkills")},[eO,eB]=(0,n.useState)(()=>ei?sm(ei)?.value??"":""),[eU,e_]=(0,n.useState)(()=>ei?sm(ei)?.pastedBlocks??[]:[]),[eq,eV]=(0,n.useState)([]),eK=n.useMemo(()=>{try{var e;return e=eA("desktop.pastedLabel",{id:"\0A\0",lines:"\0B\0"}),RegExp(e.split("\0A\0").join("(\\d+)").split("\0B\0").join("(\\d+)").split("(\\d+)").map(iT).join("(\\d+)"),"g")}catch{return null}},[eA]),[eG,eJ]=(0,n.useState)(null),eY=(0,n.useRef)(null),eX=(0,n.useRef)(0),[eZ,eQ]=(0,n.useState)(!1),[e0,e1]=(0,n.useState)(null),[e2,e4]=(0,n.useState)({height:0,width:0,offsetTop:0}),[e6,e8]=(0,n.useState)(""),[e5,e3]=(0,n.useState)(()=>{try{let e=localStorage.getItem("pi-favorite-models");return e?new Set(JSON.parse(e)):new Set}catch{return new Set}}),[e7,e9]=(0,n.useState)(new Set),[te,tt]=(0,n.useState)(!1),[to,tr]=(0,n.useState)(null),[tn,ts]=(0,n.useState)(!1),[ti,ta]=(0,n.useState)(null),[tl,td]=(0,n.useState)(!1),[tc,tp]=(0,n.useState)(null),[tu,th]=(0,n.useState)(()=>ei?sm(ei)?.images.map(iR)??[]:[]),tg=eO.trimStart(),tm=0===tu.length&&tg.startsWith("!"),tf=tm&&tg.startsWith("!!"),[tx,tk]=(0,n.useState)(!1),[tv,ty]=(0,n.useState)(0),[tb,tw]=(0,n.useState)({}),[tj,tS]=(0,n.useState)(()=>{try{return"ctrl-enter"===localStorage.getItem("pi-input-shortcut")?"ctrl-enter":"enter"}catch{return"enter"}}),[tC,tT]=(0,n.useState)(null),[tR,tz]=(0,n.useState)(!1),[tI,tM]=(0,n.useState)(0),[tP,tE]=(0,n.useState)(!1),[tW,tF]=(0,n.useState)(0),[tD,tA]=(0,n.useState)(null),[tN,tL]=(0,n.useState)(!1),[t$,tH]=(0,n.useState)(null),tO=(0,n.useRef)(null),tB=(0,n.useRef)(null),tU=(0,n.useRef)(null),t_=(0,n.useRef)(null),tq=(0,n.useRef)(null),tV=(0,n.useRef)(null),tK=(0,n.useRef)(null),tG=(0,n.useRef)(null),tJ=(0,n.useRef)(null),tY=(0,n.useRef)(null),tX=(0,n.useRef)(!1),tZ=(0,n.useRef)(0),tQ=(0,n.useRef)(!1),t0=(0,n.useRef)([]),t1=(0,n.useRef)([]),t2=(0,n.useRef)([]),t4=(0,n.useRef)(null),t6=(0,n.useRef)(null),t8=(0,n.useRef)(ei),t5=(0,n.useRef)(eO),t3=(0,n.useRef)(tu),t7=(0,n.useRef)(eU),t9=(0,n.useRef)(null),[oe,ot]=(0,n.useState)(!1);t5.current=eO,t3.current=tu,t7.current=eU,(0,n.useImperativeHandle)(ec,()=>({insertIfEmpty(e){let t=tO.current;(t?t.value:eO).trim()||(eB(e),tT(null),requestAnimationFrame(()=>{t&&(t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)}))},replaceMessage(e){var t,o;let r=tO.current;t=r?r.value:eO,o=t3.current.length,t.trim()||0!==o||(eB("string"==typeof e.content?e.content:e.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n")),tT(null),tE(!1),th(t=>(t.forEach(iz),(("string"==typeof e.content?[]:e.content.flatMap(e=>{if("image"!==e.type)return[];let t=e.source?.type==="base64"?e.source.data:e.data,o=e.source?.type==="base64"?e.source.media_type:e.mimeType;return"string"!=typeof t||"string"!=typeof o?[]:sv({type:"image",data:t,mimeType:o})?[{data:t,mimeType:o}]:[]}))??[]).filter(sv).slice(0,10).map(iR))),requestAnimationFrame(()=>{r&&(r.focus(),r.style.height="auto",r.style.height=`${Math.min(r.scrollHeight,200)}px`)}))},prependText(e){if(!e.trim())return;let t=tO.current,o=[e,t?t.value:eO].filter(e=>e.trim()).join("\n\n");eB(o),tT(null),requestAnimationFrame(()=>{t&&(t.focus(),t.setSelectionRange(o.length,o.length),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)})},insertText(e){let t=tO.current;if(!t)return void eB(t=>t+(t?" ":"")+e);let o=t.selectionStart??t.value.length,r=t.selectionEnd??t.value.length,n=t.value.slice(0,o),s=t.value.slice(r),i=n.length>0&&!n.endsWith(" ")?" ":"";eB(n+i+e+s),tT(null),requestAnimationFrame(()=>{if(!t)return;let r=o+i.length+e.length;t.setSelectionRange(r,r),t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`})},addImages(e){oo(e)},addFiles(e,t){let o=function(e,t,o){let r=e.map(()=>null),n=t.split(/\r?\n/).map(e=>e.trim()).filter(e=>e&&!e.startsWith("#")).filter(e=>e.startsWith("file://"));if(n.length===e.length){for(let t=0;t<e.length;t+=1)r[t]=function(e){let t;if(!e.startsWith("file://"))return null;try{t=decodeURIComponent(e.slice(7))}catch{return null}return t?(/^\/[A-Za-z]:[\\/]/.test(t)&&(t=t.slice(1)),t):null}(n[t]);return r}if(1===e.length&&o.trim()){let e=o.trim();(e.startsWith("/")||e.startsWith("~")||/^[A-Za-z]:[\\/]/.test(e))&&(r[0]=e)}return r}(e,t?.getData("text/uri-list")??"",t?.getData("text/plain")??""),r=e.filter(e=>e.type.startsWith("image/")),n=e.map((e,t)=>e.type.startsWith("image/")?null:o[t]??e.name).filter(e=>!!e);if(r.length&&oo(r),n.length&&!a){let e=n.join(" ");eB(t=>t+(t&&!t.endsWith(" ")?" ":"")+e)}},measureHeight:()=>tV.current?.getBoundingClientRect().height??0}));let oo=(0,n.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/"));if(!t.length)return;let o=await Promise.all(t.map(async e=>({...await ij(e),previewUrl:URL.createObjectURL(e)})));th(e=>[...e,...o])},[]),or=(0,n.useCallback)((e,t)=>{e3(o=>{let r=`${e}:${t}`,n=new Set(o);return n.has(r)?n.delete(r):n.add(r),localStorage.setItem("pi-favorite-models",JSON.stringify([...n])),n})},[]),on=(0,n.useCallback)(e=>{e9(t=>{let o=new Set(t);return o.has(e)?o.delete(e):o.add(e),o})},[]),os=(0,n.useCallback)(e=>{th(t=>{let o=[...t],[r]=o.splice(e,1);return r&&iz(r),o})},[]),oi=(0,n.useCallback)(()=>{th(e=>(e.forEach(iz),[]))},[]),oa=(0,n.useCallback)(()=>{var e;eB(""),tT(null),e_([]),eV([]),ei&&sh.delete(ei),t8.current&&t8.current!==ei&&(e=t8.current,sh.delete(e)),oi(),tO.current&&(tO.current.style.height="auto")},[oi,ei]),ol=(0,n.useCallback)(async(e,t,o)=>{await J?.(e,t,t+o)},[J]),od=(0,n.useCallback)(async(e,t)=>{await Z?.(e,t)},[Z]),oc=(0,n.useCallback)(async(e,t)=>{let o=await Y?.(e,t);if(!o)return;t9.current={kind:e,index:t,text:o.text,images:o.images},ot(!0);let r=tO.current?.value??eO,n=[o.text,r].filter(e=>e.trim()).join("\n\n");eB(n),tT(null),requestAnimationFrame(()=>{let e=tO.current;e&&(e.focus(),e.setSelectionRange(n.length,n.length),e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)})},[Y,eO]);(0,n.useEffect)(()=>{ei&&t8.current===ei&&sf(ei,{value:eO,images:tu.map(iS),pastedBlocks:eU.length?eU:void 0})},[tu,ei,eO,eU]),(0,n.useEffect)(()=>{let e=t8.current;if(e===ei)return;e&&sf(e,{value:t5.current,images:t3.current.map(iS),pastedBlocks:t7.current.length?t7.current:void 0});let t=ei?sm(ei):null;t8.current=ei,eB(t?.value??""),tT(null),e_(t?.pastedBlocks??[]),eV([]),th(e=>(e.forEach(iz),t?.images.map(iR)??[]))},[ei]),(0,n.useEffect)(()=>{let e=tO.current;e&&(e.style.height="auto",eO&&(e.style.height=`${Math.min(e.scrollHeight,200)}px`))},[eO]),(0,n.useEffect)(()=>{let e=()=>{try{tS("ctrl-enter"===localStorage.getItem("pi-input-shortcut")?"ctrl-enter":"enter")}catch{tS("enter")}};return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)},[]),(0,n.useEffect)(()=>()=>{t3.current.forEach(iz)},[]);let op=(0,n.useCallback)(e=>{let t;if(!eK)return null;for(eK.lastIndex=0;null!==(t=eK.exec(e));){let e=t[0];if(!(t7.current.some(t=>t.label===e)||t7.current.some(t=>t.text.includes(e))))return e}return null},[eK]),ou=(0,n.useCallback)(()=>{eJ(eA("desktop.pastedMissingContent")),eY.current&&clearTimeout(eY.current),eY.current=setTimeout(()=>eJ(null),5e3)},[eA]),oh=(0,n.useCallback)(async()=>{let o=iC(eO,eU),r=o.trim();if(!r&&!tu.length)return;if(op(o))return void ou();if(a)return;en?.();let n=t9.current;if(n&&X){if(t9.current=null,ot(!1),!await X(n.kind,n.index,r,tu.length?tu.map(iS):n.images)){t9.current={...n,text:r},ot(!0);return}oa();return}if(!tu.length&&r.startsWith("!")&&t){let e=r.startsWith("!!"),o=r.slice(e?2:1).trim();if(!o)return;t(o,e),oa();return}if(!tu.length&&r.startsWith("/")&&er){let e=await er(r);if(e.handled){e.error||oa();return}}e(r,tu.length?tu:void 0),oa()},[eO,eU,tu,a,t,er,e,oa,en,X,op,ou]),og=eO.startsWith("/")&&!/\s/.test(eO.slice(1))?eO.slice(1).toLowerCase():null,{commands:om,groups:of}=(ep=null===og?[]:[...a?[]:e$,...Q??[]].filter(e=>{let t=e.name.toLowerCase(),o=e.description?.toLowerCase()??"";return t.includes(og)||o.includes(og)}).sort((e,t)=>{let o=ib(e,og)-ib(t,og);return 0!==o?o:iy[e.source]-iy[t.source]||ih.compare(e.name,t.name)}),eu=0,{commands:(eh=iv.map(e=>{let t=ep.filter(t=>t.source===e),o="skill"===e?[...t.filter(e=>!iw(e,tb)),...t.filter(e=>iw(e,tb))]:t;return{source:e,items:o.map(e=>({command:e,index:eu++}))}}).filter(e=>e.items.length>0)).flatMap(e=>e.items.map(({command:e})=>e)),groups:eh});(0,n.useEffect)(()=>{if(!tx||!el)return;let e=!1;return fetch(`/api/skills?cwd=${encodeURIComponent(el)}`).then(e=>e.ok?e.json():null).then(t=>{!e&&t&&tw(Object.fromEntries(t.skills.map(e=>[e.name,e.disableModelInvocation])))}).catch(()=>{}),()=>{e=!0}},[el,tx]);let ox=`${om.length} ${eA(og?1===om.length?"desktop.match":"desktop.matches":1===om.length?"desktop.command":"desktop.commands")}`,ok=!!eO.trim()||tu.length>0,ov=(0,n.useCallback)((e,t)=>{if(!el)return void tT(null);let o=t??e.length;tT(sy(e.slice(0,o)))},[el]),[oy,ob]=(0,n.useState)(null),ow=(0,n.useRef)(oy);ow.current=oy;let[oj,oS]=(0,n.useState)([]),oC=(0,n.useRef)(!1),oT=(0,n.useCallback)(async()=>{try{let e=await fetch("/api/snippets");if(!e.ok)return;let t=await e.json();oS(t.snippets??[]),oC.current=!0}catch{}},[]);(0,n.useEffect)(()=>{oT();let e=()=>void oT();return window.addEventListener("pi:snippets-changed",e),()=>window.removeEventListener("pi:snippets-changed",e)},[oT]);let oR=oy?.query??null,oz=n.useMemo(()=>{if(null===oR||!1===oC.current)return[];let e=oR.toLowerCase();return oj.filter(t=>t.name.toLowerCase().includes(e))},[oR,oj]),[oI,oM]=(0,n.useState)(0);(0,n.useEffect)(()=>{oM(0)},[oR]);let oP=(0,n.useCallback)((e,t)=>{var o;let r,n=t??e.length,s=(o=e.slice(0,n),(r=/(?:^|[\s(])(#[\w-]+)$/.exec(o))?{start:o.length-r[1].length,end:o.length,query:r[1].slice(1)}:null);ob(s),s&&oM(0)},[]),oE=(0,n.useCallback)(e=>{let t=ow.current;if(!t)return;let o=eO.slice(0,t.start),r=eO.slice(t.end);eB(o+e.content+r),ob(null);let n=o.length+e.content.length;requestAnimationFrame(()=>{let e=tO.current;e&&(e.focus(),e.setSelectionRange(n,n))})},[eO]),oW=(0,n.useCallback)(e=>{let t=oz[e];t&&oE(t)},[oz,oE]),oF=tC?.query??null,oD=n.useMemo(()=>null!==oF&&tD&&tD.cwd===el?function(e,t,o=20){let r=t.toLowerCase();if(!r)return e.slice(0,o);let n=[];for(let t of e){let e=function(e,t){let o=e.path.toLowerCase(),r=0;if(t.includes("/"))o===t?r=100:o.startsWith(t)?r=80:o.includes(t)?r=50:sw(t,o)&&(r=10);else{let e=o.lastIndexOf("/"),n=-1===e?o:o.slice(e+1);n===t?r=100:n.startsWith(t)?r=80:n.includes(t)?r=50:o.includes(t)?r=30:sw(t,o)&&(r=10)}return e.isDir&&r>0&&(r+=10),r}(t,r);e>0&&n.push({entry:t,score:e})}return n.sort((e,t)=>t.score-e.score||sb(e.entry.path)-sb(t.entry.path)||e.entry.path.localeCompare(t.entry.path)),n.slice(0,o).map(e=>e.entry)}(tD.entries,oF):[],[oF,tD,el]),oA=!!(oF&&tD?.truncated&&tD.cwd===el);(0,n.useEffect)(()=>{if(!oA||!el||!oF)return;let e=setTimeout(()=>{fetch(`/api/file-index?cwd=${encodeURIComponent(el)}&q=${encodeURIComponent(oF)}`).then(e=>{if(!e.ok)throw Error(`file search failed: ${e.status}`);return e.json()}).then(e=>tH({cwd:el,query:oF,matches:e.matches??[]})).catch(()=>{})},150);return()=>clearTimeout(e)},[oA,oF,el]);let oN=oA&&null!==t$&&t$.cwd===el&&t$.query===oF,oL=oN?t$.matches:oD,o$=null===tC?null:`${tC.start}:${+!!tC.quoted}:${tC.query}`;(0,n.useEffect)(()=>{if(null===o$){tz(!1),tM(0);return}tz(!0),tM(0)},[o$]);let oH=null!==tC;(0,n.useEffect)(()=>{if(!oH||!el)return;let e=t4.current;e&&e.cwd===el&&Date.now()-e.fetchedAt<1e4||t6.current===el||(t6.current=el,tL(!0),fetch(`/api/file-index?cwd=${encodeURIComponent(el)}`).then(e=>{if(!e.ok)throw Error(`file index failed: ${e.status}`);return e.json()}).then(e=>{tA({cwd:el,entries:function(e){let t=new Set;for(let o of e){let e=o.indexOf("/");for(;-1!==e;)t.add(o.slice(0,e)),e=o.indexOf("/",e+1)}let o=[];for(let e of t)o.push({path:e,isDir:!0});for(let t of e)t&&o.push({path:t,isDir:!1});return o.sort((e,t)=>sb(e.path)-sb(t.path)||e.path.localeCompare(t.path)),o}(e.files??[]),truncated:!!e.truncated}),t4.current={cwd:el,fetchedAt:Date.now()}}).catch(()=>{t4.current=null}).finally(()=>{t6.current=null,tL(!1)}))},[oH,el]);let oO=(0,n.useCallback)(e=>{if(!tC)return;let t=tO.current,o=t?.selectionStart??eO.length,r=eO.slice(0,tC.start),n=eO.slice(o);tC.quoted&&n.startsWith('"')&&(n=n.slice(1));let s=function(e,t,o=!1){let r=t?`${e}/`:e,n=o||r.includes(" ");if(t){let e=n?`@"${r}"`:`@${r}`;return{text:e,cursorOffset:n?e.length-1:e.length}}let s=n?`@"${r}" `:`@${r} `;return{text:s,cursorOffset:s.length}}(e.path,e.isDir,tC.quoted),i=r+s.text+n,a=r.length+s.cursorOffset;eB(i),tT(sy(i.slice(0,a))),requestAnimationFrame(()=>{let e=tO.current;e&&(e.focus(),e.setSelectionRange(a,a),e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)})},[tC,eO]);(0,n.useEffect)(()=>{tI>=oL.length&&tM(Math.max(0,oL.length-1))},[oL.length,tI]),(0,n.useEffect)(()=>{t1.current.length=oL.length},[oL.length]),(0,n.useEffect)(()=>{tR&&t1.current[tI]?.scrollIntoView({block:"nearest",inline:"nearest"})},[tI,tR]);let oB=(0,n.useCallback)(e=>{eB(e),tT(null),tE(!1),tF(0),requestAnimationFrame(()=>{let t=tO.current;t&&(t.focus(),t.setSelectionRange(e.length,e.length),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)})},[]),oU=(0,n.useCallback)(e=>{let t=`/${e.name} `;eB(t),tk(!1),ty(0),requestAnimationFrame(()=>{let e=tO.current;e&&(e.focus(),e.setSelectionRange(t.length,t.length),e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)})},[]),o_=(0,n.useCallback)(()=>{let e=tO.current;if(!e)return;let t=e.selectionStart??e.value.length,o=e.value.slice(0,t),r=e.value.slice(e.selectionEnd??t),n=o.length>0&&!o.endsWith(" ")?" ":"",s=o+n+"@"+r;eB(s);let i=t+n.length+1;ov(s,i),requestAnimationFrame(()=>{e&&(e.setSelectionRange(i,i),e.focus(),e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)})},[]),oq=(0,n.useCallback)(()=>{let e=tO.current;if(!e)return;let t=e.selectionStart??e.value.length,o=e.value.slice(0,t),r=e.value.slice(e.selectionEnd??t),n=o.length>0&&!o.endsWith(" ")?" ":"",s=o+n+"#"+r;eB(s),ov(s,t+n.length+1),requestAnimationFrame(()=>{e&&(e.setSelectionRange(t+n.length+1,t+n.length+1),e.focus(),e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)})},[]),oV=(0,n.useCallback)(()=>{let e=tO.current;if(!e)return;let t=e.selectionStart??e.value.length,o=e.value.slice(0,t),r=e.value.slice(e.selectionEnd??t),n=o.length>0&&!o.endsWith(" ")?" ":"";eB(o+n+"/"+r);let s=t+n.length+1;requestAnimationFrame(()=>{e&&(e.setSelectionRange(s,s),e.focus(),e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)})},[]),oK=(0,n.useCallback)(e=>{let t=iC(eO,eU);if(op(t))return void ou();let o=t.trim();if(o||tu.length){if(en?.(),o.startsWith("/")&&es){es(o,"steer"===e?"steer":"followUp",tu.length?tu:void 0),oa();return}"steer"===e&&s?s(o,tu.length?tu:void 0):"followup"===e&&i&&i(o,tu.length?tu:void 0),oa()}},[eO,eU,tu,es,s,i,oa,en,op,ou]),oG=(0,n.useCallback)(e=>{let t=om.length-1;if(t<0)return 0;if("left"===e)return Math.max(0,tv-1);if("right"===e)return Math.min(t,tv+1);let o=t0.current[tv];if(!o)return"down"===e?Math.min(t,tv+1):Math.max(0,tv-1);let r=o.getBoundingClientRect(),n=r.left+r.width/2,s=r.top+r.height/2,i=-1,a=1/0;for(let o=0;o<=t;o+=1){if(o===tv)continue;let t=t0.current[o];if(!t)continue;let r=t.getBoundingClientRect(),l=r.top+r.height/2-s;if("down"===e?l<=4:l>=-4)continue;let d=1e3*Math.abs(l)+Math.abs(r.left+r.width/2-n);d<a&&(i=o,a=d)}return i>=0?i:"down"===e?Math.min(t,tv+1):Math.max(0,tv-1)},[om.length,tv]),oJ=(0,n.useCallback)(e=>{let t=e.nativeEvent,r=Date.now()-tZ.current<100,n=tX.current||t.isComposing||229===t.keyCode;if("Enter"===e.key&&!e.shiftKey&&(n||r)){r&&e.preventDefault();return}if((e.ctrlKey||e.metaKey)&&!e.altKey&&!e.shiftKey&&"i"===e.key.toLowerCase()&&!n&&el){e.preventDefault();let t=e.currentTarget,o=t.selectionStart??t.value.length,r=t.selectionEnd??o,n=t.value.slice(0,o),s=t.value.slice(r),i=n&&!/[\s@]$/.test(n)?" ":"",a=`${n}${i}@${s}`,l=n.length+i.length+1;eB(a),tT(sy(a.slice(0,l))),tz(!0),requestAnimationFrame(()=>{t.focus(),t.setSelectionRange(l,l)});return}if(tP&&!n){if("ArrowDown"===e.key){e.preventDefault(),tF(e=>Math.min(Math.max(0,(K?.length??0)-1),e+1));return}if("ArrowUp"===e.key){e.preventDefault(),tF(e=>Math.max(0,e-1));return}if("Escape"===e.key){e.preventDefault(),tE(!1);return}if(("Tab"===e.key||"Enter"===e.key&&!e.shiftKey)&&K?.[tW]){e.preventDefault(),oB(K[tW]);return}}if(tx&&null!==og){if("ArrowDown"===e.key){e.preventDefault(),ty(oG("down"));return}if("ArrowUp"===e.key){e.preventDefault(),ty(oG("up"));return}if("ArrowRight"===e.key){e.preventDefault(),ty(oG("right"));return}if("ArrowLeft"===e.key){e.preventDefault(),ty(oG("left"));return}if("Escape"===e.key){e.preventDefault(),tk(!1);return}if(("Tab"===e.key||"Enter"===e.key&&!e.shiftKey)&&om[tv]){e.preventDefault(),oU(om[tv]);return}}if(tR&&null!==tC&&!n){if("ArrowDown"===e.key){e.preventDefault(),tM(e=>Math.min(Math.max(0,oL.length-1),e+1));return}if("ArrowUp"===e.key){e.preventDefault(),tM(e=>Math.max(0,e-1));return}if("Escape"===e.key){e.preventDefault(),tz(!1);return}if(("Tab"===e.key||"Enter"===e.key&&!e.shiftKey)&&oL[tI]){e.preventDefault(),oO(oL[tI]);return}}if(null!==oy&&oz.length>0&&!n){if("ArrowDown"===e.key){e.preventDefault(),oM(e=>Math.min(Math.max(0,oz.length-1),e+1));return}if("ArrowUp"===e.key){e.preventDefault(),oM(e=>Math.max(0,e-1));return}if("Escape"===e.key){e.preventDefault(),ob(null);return}if(("Tab"===e.key||"Enter"===e.key&&!e.shiftKey)&&oz[oI]){e.preventDefault(),oW(oI);return}}if("ArrowUp"===e.key&&!n&&!a&&(K?.length??0)>0&&0===eO.trim().length){e.preventDefault(),tk(!1),tz(!1),tF(0),tE(!0);return}if("Escape"===e.key&&!n&&a&&o){e.preventDefault(),o();return}if("Enter"===e.key&&!e.shiftKey){if("ctrl-enter"===tj&&!(e.ctrlKey||e.metaKey))return;e.preventDefault(),a&&(s||i)?oK(s?"steer":"followup"):oh()}},[a,s,i,o,tx,og,om,tv,oU,oK,oh,oG,tR,tC,oL,tI,oO,oy,oz,oI,oW,tj,el,tP,K,tW,oB,eO]),oY=(0,n.useCallback)(()=>{let e=tO.current;e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[]),oX=(0,n.useCallback)(e=>{let t=Array.from(e.clipboardData?.items??[]),o=t.filter(e=>e.type.startsWith("image/"));if(o.length){e.preventDefault(),oo(o.map(e=>e.getAsFile()).filter(e=>null!==e));return}let r=function(e,t){if(!e)return[];let o=[],r=Array.from(e.files??[]);for(let e of r){let t=e.path;"string"==typeof t&&t.trim()&&o.push(t.trim())}if(o.length>0)return Array.from(new Set(o));for(let t of Array.from(e.items??[]))if("file"===t.kind){let e=t.getAsFile(),r=e?.path;"string"==typeof r&&r.trim()&&o.push(r.trim())}if(o.length>0)return Array.from(new Set(o));for(let t of sk)try{let r=e.getData(t);if(r){let e=function(e){if(!e)return[];let t=e.split(/\r?\n/),o=[];for(let e of t){let t=e.trim();!(!t||t.startsWith("#"))&&"copy"!==t&&"cut"!==t&&(t.startsWith("file://")?o.push(sx(t)):(t.startsWith("/")||/^[a-zA-Z]:[\\/]/.test(t))&&o.push(t))}return o}(r);e.length>0&&o.push(...e)}}catch{}if(o.length>0)return Array.from(new Set(o));try{let t=e.getData("text/plain")||e.getData("text");if(t){let e=t.split(/\r?\n/).map(e=>e.trim()).filter(Boolean),r=e.filter(e=>e.startsWith("file://"));if(r.length>0&&r.length===e.length)for(let e of r)o.push(sx(e))}}catch{}if(o.length>0)return Array.from(new Set(o));if(t?.fallbackToFileName&&r.length>0)for(let e of r)e.name&&o.push(e.name);return Array.from(new Set(o))}(e.clipboardData,{fallbackToFileName:!0});if(r.length>0){e.preventDefault();let t=function(e,t=" "){return e&&0!==e.length?1===e.length?e[0]:e.map(e=>{let t=e.trim();return!/\s/.test(t)||t.startsWith('"')||t.startsWith("'")?t:`"${t}"`}).join(t):""}(r),o=tO.current,n=o?.selectionStart??eO.length,s=o?.selectionEnd??eO.length;eB(eO.slice(0,n)+t+eO.slice(s)),requestAnimationFrame(()=>{if(o){let e=n+t.length;o.selectionStart=e,o.selectionEnd=e,oY()}});return}if(!t.find(e=>e.type.startsWith("text/plain")))return;let n=e.clipboardData.getData("text/plain");if(!n)return;let s=n.split(/\r?\n/).length;if(n.length<2e3&&s<20)return;e.preventDefault();let i=`paste-${++eX.current}`,a=eA("desktop.pastedLabel",{id:eX.current,lines:s}),l=tO.current,d=l?.selectionStart??eO.length,c=l?.selectionEnd??eO.length,p=eO.slice(0,d),u=eO.slice(c),h=!(p.length>0)||p.endsWith("\n")||p.endsWith(" ")?"":"\n\n";eB(p+h+a+u),e_(e=>[...e,{id:i,label:a,text:n}]),requestAnimationFrame(()=>{if(!l)return;let e=d+h.length+a.length;l.setSelectionRange(e,e),l.focus()})},[oo,eA,eO,oY]);(0,n.useEffect)(()=>{tW>=(K?.length??0)&&tF(Math.max(0,(K?.length??0)-1))},[tW,K]),(0,n.useEffect)(()=>{t2.current.length=K?.length??0},[K]),(0,n.useEffect)(()=>{tP&&t2.current[tW]?.scrollIntoView({block:"nearest",inline:"nearest"})},[tW,tP]),(0,n.useEffect)(()=>{if(null===og){tk(!1),ty(0),tQ.current=!1;return}tk(!0),ty(0),!tQ.current&&et&&(tQ.current=!0,Promise.resolve(et()).catch(()=>{tQ.current=!1}))},[og,et]),(0,n.useEffect)(()=>{tv>=om.length&&ty(Math.max(0,om.length-1))},[om.length,tv]),(0,n.useEffect)(()=>{t0.current.length=om.length},[om.length]),(0,n.useEffect)(()=>{tx&&t0.current[tv]?.scrollIntoView({block:"nearest",inline:"nearest"})},[tv,tx]);let oZ=c&&c.length>0?c.map(e=>({provider:e.provider,modelId:e.id,name:e.name})).sort(ig):Object.entries(d??{}).map(([e,t])=>({provider:l?.provider??"unknown",modelId:e,name:t})).sort(ig),oQ=[];for(let e of oZ){let t=oQ.find(t=>t.provider===e.provider);t?t.options.push(e):oQ.push({provider:e.provider,options:[e]})}let o0=l?oZ.find(e=>e.modelId===l.modelId&&e.provider===l.provider)?.name??l.modelId:null,o1=w?Math.max(0,w.tokensBefore-w.estimatedTokensAfter):0,o2=w?`${eA("desktop.compacted")} ${ik(w.tokensBefore)} -> ${ik(w.estimatedTokensAfter)} ${eA("desktop.tokens")} (${ik(o1)} ${eA("desktop.saved")})`:null,o4="auto"!==(eg=H??"auto")&&_?_[eg]??eN[eg]:eN[eg],o6=Object.entries(iu).find(([,e])=>e===(j??"default"))?.[0],o8="plan"===j?eA("desktop.planModeLabel"):eL[o6??"default"];(0,n.useEffect)(()=>{let e=e=>{tB.current&&!tB.current.contains(e.target)&&tU.current&&!tU.current.contains(e.target)&&eQ(!1),tq.current&&!tq.current.contains(e.target)&&tt(!1),tK.current&&!tK.current.contains(e.target)&&td(!1),tG.current&&!tG.current.contains(e.target)&&ts(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,n.useEffect)(()=>{let e=null,t=()=>{e=null;let t=window.visualViewport;e4({height:t?.height??window.innerHeight,width:t?.width??window.innerWidth,offsetTop:t?.offsetTop??0})},o=()=>{null!==e&&window.cancelAnimationFrame(e),e=window.requestAnimationFrame(t)};return o(),window.addEventListener("resize",o),window.visualViewport?.addEventListener("resize",o),window.visualViewport?.addEventListener("scroll",o),window.addEventListener("focusin",o),window.addEventListener("focusout",o),window.addEventListener("pageshow",o),()=>{window.removeEventListener("resize",o),window.visualViewport?.removeEventListener("resize",o),window.visualViewport?.removeEventListener("scroll",o),window.removeEventListener("focusin",o),window.removeEventListener("focusout",o),window.removeEventListener("pageshow",o),null!==e&&window.cancelAnimationFrame(e)}},[]),(0,n.useEffect)(()=>{eZ&&t_.current?.focus()},[eZ]);let[o5,o3]=(0,n.useState)(null);return(0,n.useEffect)(()=>{if(!el||!ed)return void o3(null);let e=!1,t=async()=>{try{let t=await fetch("/api/tasks/projects"),{projects:o}=await t.json(),r=o.find(e=>el===e||el.startsWith(e+"/")||e.startsWith(el+"/"));if(!r){e||o3(null);return}let n=await (0,sS.Vk)(r);if(e)return;o3({running:n.filter(e=>["running","awaiting_input","preparing","merging"].includes(e.status)).length,todo:n.filter(e=>["todo","queued"].includes(e.status)).length})}catch{e||o3(null)}};t();let o=new EventSource("/api/tasks/events");return o.onmessage=()=>void t(),()=>{e=!0,o.close()}},[el,ed]),(0,r.jsxs)("div",{style:{flexShrink:0,background:"transparent",padding:"0 16px 15px",paddingRight:eD?16:34},children:[(0,r.jsx)("input",{ref:tY,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:e=>{oo(Array.from(e.target.files??[])),e.target.value=""}}),(0,r.jsxs)("div",{style:{maxWidth:820,margin:"0 auto"},children:[o5&&(o5.running>0||o5.todo>0)&&(0,r.jsxs)("button",{type:"button",onClick:()=>window.dispatchEvent(new CustomEvent("pi:open-tasks-view")),title:eA("desktop.taskStatusHint"),style:{display:"inline-flex",alignItems:"center",gap:6,marginBottom:8,padding:"3px 10px",borderRadius:999,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",fontSize:11,cursor:"pointer",transition:"border-color 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:[(0,r.jsx)(I.m,{size:12,"aria-hidden":"true"}),o5.running>0&&(0,r.jsxs)("span",{style:{color:"var(--accent)"},children:[o5.running," ",eA("desktop.taskRunning")]}),o5.running>0&&o5.todo>0&&(0,r.jsx)("span",{"aria-hidden":"true",children:"\xb7"}),o5.todo>0&&(0,r.jsxs)("span",{children:[o5.todo," ",eA("desktop.taskTodo")]})]}),p&&p.length>0&&(0,r.jsx)("div",{role:"status",style:{marginBottom:8,padding:"6px 10px",borderRadius:6,border:"1px solid color-mix(in srgb, var(--accent-orange) 45%, var(--border))",background:"color-mix(in srgb, var(--accent-orange) 9%, var(--bg-panel))",color:"var(--text-muted)",fontSize:12,lineHeight:1.45},children:p.join(" ")}),(V?.steering.length??0)+(V?.followUp.length??0)>0&&(0,r.jsxs)("div",{style:{marginBottom:8,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",padding:"5px 0"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,padding:"2px 8px 4px 10px"},children:[(0,r.jsxs)("span",{style:{fontSize:10,fontFamily:"var(--font-mono)",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:.4},children:[eA("desktop.queued")," \xb7 ",(V?.steering.length??0)+(V?.followUp.length??0)]}),G&&(0,r.jsxs)("button",{onClick:G,title:eA("desktop.recallQueuedMessages"),style:{display:"flex",alignItems:"center",gap:6,padding:"4px 12px",fontSize:12,color:"var(--text)",background:"transparent",border:"1px solid var(--border)",borderRadius:7,cursor:"pointer",transition:"background 0.12s, border-color 0.12s",whiteSpace:"nowrap"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.borderColor="color-mix(in srgb, var(--accent) 45%, var(--border))"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.borderColor="var(--border)"},children:[(0,r.jsx)(sC.Y,{size:13}),eA("desktop.recallToInput")]})]}),V?.steering.map((e,t)=>(0,r.jsx)(iI,{kind:"steer",label:eA("desktop.steer"),text:e,index:t,total:V.steering.length,onMove:J?e=>void ol("steer",t,e):void 0,onRecall:Y?()=>void oc("steer",t):void 0,onRemove:Z?()=>void od("steer",t):void 0},`steer-${t}`)),V?.followUp.map((e,t)=>(0,r.jsx)(iI,{kind:"follow-up",label:eA("desktop.followUp"),text:e,index:t,total:V.followUp.length,onMove:J?e=>void ol("followUp",t,e):void 0,onRecall:Y?()=>void oc("followUp",t):void 0,onRemove:Z?()=>void od("followUp",t):void 0},`followup-${t}`))]}),oe&&(0,r.jsx)("div",{style:{marginBottom:8,padding:"5px 10px",borderRadius:6,border:"1px solid color-mix(in srgb, var(--accent) 40%, var(--border))",background:"color-mix(in srgb, var(--accent) 8%, var(--bg-panel))",color:"var(--text-muted)",fontSize:12},children:eA("desktop.recalledEditing")}),q&&(0,r.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,r.jsx)(C.B,{size:11,style:{flexShrink:0}}),eA("desktop.retrying")," (",q.attempt,"/",q.maxAttempts,")…",q.errorMessage&&(0,r.jsxs)("span",{style:{opacity:.7,marginLeft:4},children:["— ",q.errorMessage]})]}),o2&&(0,r.jsxs)("div",{style:{marginBottom:8,padding:"5px 10px",background:"rgba(16,185,129,0.08)",border:"1px solid rgba(16,185,129,0.24)",borderRadius:6,fontSize:12,color:"rgba(5,150,105,0.95)",display:"flex",alignItems:"center",gap:6},children:[(0,r.jsx)(m.S,{size:11,style:{flexShrink:0}}),o2]}),tu.length>0&&(0,r.jsx)("div",{style:{display:"flex",gap:6,marginBottom:6,flexWrap:"wrap"},children:tu.map((e,t)=>(0,r.jsxs)("div",{style:{position:"relative",flexShrink:0},children:[(0,r.jsx)("img",{src:e.previewUrl,alt:"",style:{width:56,height:56,objectFit:"cover",borderRadius:6,border:"1px solid var(--border)",display:"block"}}),(0,r.jsx)("button",{onClick:()=>os(t),title:eA("desktop.removeImage"),"aria-label":eA("desktop.removeImage"),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,r.jsx)(h.u,{size:8})})]},t))}),(0,r.jsxs)("div",{style:{position:"relative"},children:[tP&&K.length>0&&(0,r.jsxs)("div",{style:{position:"absolute",left:0,right:0,bottom:"calc(100% + 8px)",zIndex:120,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -6px 20px rgba(0,0,0,0.12)",overflow:"hidden",maxHeight:"min(38vh, 300px)"},children:[(0,r.jsxs)("div",{style:{padding:"4px 8px",borderBottom:"1px solid var(--border)",display:"flex",justifyContent:"space-between",color:"var(--text-dim)",fontSize:11},children:[(0,r.jsx)("span",{children:eA("desktop.inputHistory")}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)"},children:eA("desktop.tabOrEnter")})]}),(0,r.jsx)("div",{style:{maxHeight:"calc(min(38vh, 300px) - 24px)",overflowY:"auto",padding:4},children:K.map((e,t)=>(0,r.jsxs)("button",{ref:e=>{t2.current[t]=e},type:"button",onMouseDown:t=>{t.preventDefault(),oB(e)},onMouseEnter:()=>tF(t),style:{width:"100%",display:"flex",alignItems:"flex-start",gap:8,padding:"5px 6px",border:"none",borderRadius:5,background:t===tW?"var(--bg-selected)":"transparent",color:"var(--text)",cursor:"pointer",textAlign:"left"},children:[(0,r.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11},children:t+1}),(0,r.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:12},children:e})]},`${t}:${e}`))})]}),tx&&null!==og&&(0,r.jsxs)("div",{style:{position:"absolute",left:0,right:0,bottom:"calc(100% + 8px)",zIndex:120,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -6px 20px rgba(0,0,0,0.12)",overflow:"hidden",maxHeight:"min(38vh, 300px)"},children:[(0,r.jsxs)("div",{style:{padding:"4px 8px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,fontSize:11,color:"var(--text-dim)"},children:[(0,r.jsx)("span",{children:ee?eA("desktop.loadingCommands"):`${eA("desktop.slashCommands")} \xb7 ${ox}`}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)"},children:eA("desktop.tabOrEnter")})]}),(0,r.jsx)("div",{style:{maxHeight:"calc(min(38vh, 300px) - 24px)",overflowY:"auto",padding:4},children:ee||0!==om.length?of.map(e=>(0,r.jsxs)("section",{style:{marginBottom:6},children:[(0,r.jsxs)("div",{style:{position:"sticky",top:-4,zIndex:1,display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,padding:"2px 0 4px",background:"var(--bg)",color:"var(--text-dim)",fontSize:10,fontWeight:600,textTransform:"uppercase"},children:[(0,r.jsx)("span",{children:eH[e.source]}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontWeight:500},children:e.items.length})]}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:1},children:e.items.map(({command:e,index:t})=>{let o=t===tv;return(0,r.jsxs)("button",{ref:e=>{t0.current[t]=e},type:"button",onMouseDown:t=>{t.preventDefault(),oU(e)},onMouseEnter:()=>ty(t),style:{width:"100%",display:"flex",alignItems:"center",gap:8,padding:"3px 6px",border:"none",borderRadius:5,background:o?"var(--bg-selected)":"none",color:"var(--text)",cursor:"pointer",textAlign:"left"},children:[(0,r.jsxs)("span",{style:{fontSize:12.5,fontFamily:"var(--font-mono)",whiteSpace:"nowrap",flexShrink:0},children:["/",e.name]}),e.description&&(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:e.description}),iw(e,tb)&&(0,r.jsx)("span",{style:{marginLeft:"auto",flexShrink:0,padding:"1px 5px",borderRadius:999,border:"1px solid var(--border)",color:"var(--text-dim)",fontSize:10},children:eA("desktop.dormant")})]},`${e.source}:${e.name}`)})})]},e.source)):(0,r.jsx)("div",{style:{padding:"2px 2px 2px",fontSize:12,color:"var(--text-dim)"},children:eA("desktop.noSlashCommands")})})]}),tR&&null!==tC&&(em=tN&&(!tD||tD.cwd!==el),ef=`${oL.length} ${eA(1===oL.length?"desktop.match":"desktop.matches")}`,ex=tD?.truncated&&!oN?tC.query?` \xb7 ${eA("desktop.searchingAllFiles")}`:` \xb7 ${eA("desktop.indexTruncated")}`:"",(0,r.jsxs)("div",{style:{position:"absolute",left:0,right:0,bottom:"calc(100% + 8px)",zIndex:120,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -6px 20px rgba(0,0,0,0.12)",overflow:"hidden",maxHeight:"min(30vh, 240px)"},children:[(0,r.jsxs)("div",{style:{padding:"4px 8px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,fontSize:11,color:"var(--text-dim)"},children:[(0,r.jsx)("span",{children:em?eA("desktop.loadingFiles"):`${eA("desktop.files")} \xb7 ${ef}${ex}`}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)"},children:eA("desktop.tabOrEnter")})]}),(0,r.jsx)("div",{style:{maxHeight:"calc(min(30vh, 240px) - 24px)",overflowY:"auto",padding:2},children:em||0!==oL.length?oL.map((e,t)=>{let o=t===tI,n=e.path.split("/").pop()??e.path,s=e.path.slice(0,e.path.length-n.length);return(0,r.jsxs)("button",{ref:e=>{t1.current[t]=e},type:"button",onMouseDown:t=>{t.preventDefault(),oO(e)},onMouseEnter:()=>tM(t),style:{width:"100%",display:"flex",alignItems:"center",gap:5,padding:"3px 6px",border:"none",borderRadius:5,background:o?"var(--bg-selected)":"none",color:"var(--text)",cursor:"pointer",textAlign:"left",fontSize:12.5,fontFamily:"var(--font-mono)"},children:[(0,r.jsx)("span",{style:{flexShrink:0,display:"flex",alignItems:"center"},children:e.isDir?(0,r.jsx)(eo,{size:14,name:n}):ea(n,14)}),(0,r.jsxs)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[s&&(0,r.jsx)("span",{style:{color:"var(--text-dim)"},children:s}),n,e.isDir&&(0,r.jsx)("span",{style:{color:"var(--text-dim)"},children:"/"})]})]},`${e.isDir?"d":"f"}:${e.path}`)}):(0,r.jsx)("div",{style:{padding:"4px 6px",fontSize:12,color:"var(--text-dim)"},children:oA&&!oN?eA("desktop.searching"):eA("desktop.noMatchingFiles")})})]})),null!==oy&&oz.length>0&&(0,r.jsxs)("div",{style:{position:"absolute",left:0,right:0,bottom:"calc(100% + 8px)",zIndex:120,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -6px 20px rgba(0,0,0,0.12)",overflow:"hidden",maxHeight:"min(30vh, 240px)"},children:[(0,r.jsx)("div",{style:{padding:"4px 8px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:(0,r.jsxs)("span",{style:{fontSize:11,color:"var(--text-dim)",fontWeight:600},children:[oz.length," ",eA("desktop.snippetMatches")]})}),(0,r.jsx)("div",{style:{maxHeight:"min(26vh, 210px)",overflowY:"auto"},children:oz.map((e,t)=>(0,r.jsxs)("button",{type:"button",onMouseEnter:()=>oM(t),onClick:()=>oW(t),style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"6px 10px",background:t===oI?"var(--bg-selected)":"none",border:"none",color:t===oI?"var(--accent)":"var(--text)",cursor:"pointer",fontSize:12,textAlign:"left"},children:[(0,r.jsx)("span",{style:{color:"var(--accent)",fontFamily:"var(--font-mono)",fontSize:11},children:"#"}),(0,r.jsx)("span",{style:{fontWeight:600,flexShrink:0},children:e.name}),(0,r.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-muted)",fontSize:11},children:e.content.split("\n")[0]})]},e.id))})]}),(0,r.jsxs)("div",{className:`chat-input-shell ${a&&(s||i)?"is-streaming":""} ${"yolo"===E?"is-yolo":""}`,ref:tV,onClick:e=>{e.target.closest("button, input, select, [role=button]")||tO.current?.focus()},style:{display:"flex",flexDirection:"column",alignItems:"stretch",gap:0,padding:0,transition:"border-color 0.15s, background 0.15s, box-shadow 0.15s"},children:[a&&(0,r.jsx)("div",{className:"chat-input-streaming-overlay hatch-45","aria-hidden":"true"}),a&&(s||i)&&(0,r.jsxs)("div",{className:"chat-input-streaming-actions",children:[s&&(0,r.jsx)("button",{type:"button",className:"chat-input-streaming-action chat-input-streaming-action-steer",onClick:()=>oK("steer"),disabled:!ok,title:eA("desktop.injectMessageNow"),"aria-label":eA("desktop.steer"),children:(0,r.jsx)(sT.A,{size:15})}),i&&(0,r.jsx)("button",{type:"button",className:"chat-input-streaming-action",onClick:()=>oK("followup"),disabled:!ok,title:eA("desktop.queueMessageAfterFinish"),"aria-label":eA("desktop.followUp"),children:(0,r.jsx)(sI.M,{size:15})})]}),eG&&(0,r.jsx)("div",{role:"alert",style:{margin:"0 0 6px",padding:"4px 8px",fontSize:11,lineHeight:1.5,color:"var(--error, #e5484d)",border:"1px solid var(--error, #e5484d)",borderRadius:6},children:eG}),eU.length>0&&(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:4,marginBottom:6},children:eU.map(e=>{let t=eq.includes(e.id);return(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"4px 8px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-secondary)",fontSize:11,color:"var(--text-muted)"},children:[(0,r.jsx)(sz.d,{size:12,"aria-hidden":"true"}),(0,r.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)"},children:e.label}),(0,r.jsx)("button",{type:"button",onClick:()=>eV(o=>t?o.filter(t=>t!==e.id):[...o,e.id]),title:eA(t?"desktop.pastedHidePreview":"desktop.pastedShowPreview"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:2,display:"flex"},children:(0,r.jsx)(sR.b,{size:12,"aria-hidden":"true"})}),(0,r.jsx)("button",{type:"button",onClick:()=>{e_(t=>t.filter(t=>t.id!==e.id)),eB(t=>t.split(e.label).join(""))},title:eA("desktop.pastedRemove"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:2,display:"flex"},children:(0,r.jsx)(T.u,{size:12,"aria-hidden":"true"})}),t&&(0,r.jsx)("div",{style:{position:"relative"},children:(0,r.jsx)("pre",{style:{position:"absolute",left:0,right:0,top:"calc(100% + 4px)",zIndex:50,maxHeight:200,overflow:"auto",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:6,padding:"8px 10px",fontSize:11,lineHeight:1.5,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:e.text})})]},e.id)})}),(0,r.jsxs)("div",{className:"chat-input-editor-row",style:{borderColor:tm?"var(--tool-bg)":void 0},children:["goal"===P&&F&&"idle"!==F.status&&(0,r.jsxs)("span",{style:{flexShrink:0,display:"inline-flex",alignItems:"center",gap:6,marginRight:8,padding:"2px 8px",borderRadius:6,background:"complete"===F.status?"color-mix(in srgb, var(--accent-green, #22c55e) 14%, transparent)":"blocked"===F.status||"paused"===F.status?"color-mix(in srgb, #f59e0b 14%, transparent)":"color-mix(in srgb, var(--accent) 12%, transparent)",color:"complete"===F.status?"var(--accent-green, #22c55e)":"blocked"===F.status||"paused"===F.status?"#f59e0b":"var(--accent)",fontSize:11,fontWeight:600,whiteSpace:"nowrap",userSelect:"none"},title:F.goalText??"",children:[(0,r.jsx)(nw.d,{size:12,weight:"fill","aria-hidden":"true"}),"running"===F.status&&(0,r.jsxs)("span",{children:[eA("desktop.goalRunning")," \xb7 ",F.turnsUsed,"/",F.turnsLimit]}),"complete"===F.status&&(0,r.jsx)("span",{children:eA("desktop.goalComplete")}),"blocked"===F.status&&(0,r.jsx)("span",{children:eA("desktop.goalBlocked")}),"paused"===F.status&&(0,r.jsx)("span",{children:eA("desktop.goalPaused")}),F.noProgressTurns>0&&"running"===F.status&&(0,r.jsxs)("span",{style:{opacity:.8},children:["\xb7 ",eA("desktop.goalNoProgress",{n:F.noProgressTurns})]}),"running"===F.status&&(0,r.jsx)("button",{type:"button",onClick:N,title:eA("desktop.goalPause"),"aria-label":eA("desktop.goalPause"),style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:16,height:16,padding:0,background:"none",border:"none",borderRadius:4,color:"inherit",cursor:"pointer",fontSize:11},children:eA("desktop.goalPauseShort")}),("paused"===F.status||"blocked"===F.status)&&(0,r.jsx)("button",{type:"button",onClick:L,title:eA("desktop.goalResume"),"aria-label":eA("desktop.goalResume"),style:{display:"inline-flex",alignItems:"center",justifyContent:"center",padding:"0 4px",background:"none",border:"none",borderRadius:4,color:"inherit",cursor:"pointer",fontSize:11,fontWeight:600},children:eA("desktop.goalResumeShort")}),(0,r.jsx)("button",{type:"button",onClick:$,title:eA("desktop.goalStop"),"aria-label":eA("desktop.goalStop"),style:{display:"inline-flex",alignItems:"center",justifyContent:"center",padding:"0 3px",background:"none",border:"none",borderRadius:4,color:"inherit",cursor:"pointer",fontSize:11,opacity:.75},children:"✕"})]}),(0,r.jsx)("textarea",{ref:tO,value:eO,spellCheck:!1,onChange:e=>{eB(e.target.value),ov(e.target.value,e.target.selectionStart),oP(e.target.value,e.target.selectionStart)},onSelect:e=>{let t=e.currentTarget;ov(t.value,t.selectionStart)},onKeyDown:oJ,onCompositionStart:()=>{tX.current=!0},onCompositionEnd:e=>{tX.current=!1,tZ.current=Date.now();let t=e.currentTarget;ov(t.value,t.selectionStart)},onInput:oY,onPaste:oX,placeholder:a&&(s||i)?eA("desktop.steerOrQueueFollowUp"):a?eA("desktop.agentRunning"):eA("desktop.messageWithCommands"),rows:1,className:"chat-input-textarea",style:{flex:1,background:"none",border:"none",outline:"none",resize:"none",color:"var(--text)",minHeight:24,maxHeight:200,padding:0,overflow:"auto"}})]}),tm&&(0,r.jsxs)("div",{style:{marginTop:4,padding:"2px 8px",fontSize:11,color:tf?"var(--text-muted)":"var(--accent)"},children:[eA("desktop.shellCommand")," \xb7 ",tf?eA("desktop.shellOutputLocal"):eA("desktop.shellOutputModel")]}),(0,r.jsxs)("div",{className:"chat-input-toolbar",style:{display:eD?"grid":"flex",gridTemplateColumns:eD?"auto auto minmax(0, 1fr)":void 0,alignItems:"center",gap:4},children:[(0,r.jsxs)("div",{ref:tG,className:"chat-input-toolbar-attach",style:{position:"relative"},children:[(0,r.jsx)("button",{onClick:e=>{let t=e.currentTarget.getBoundingClientRect();ta({top:t.top,left:t.left,width:t.width}),ts(e=>!e)},title:eA("desktop.attachMenu"),"aria-label":eA("desktop.attachMenu"),"aria-expanded":tn,style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:24,height:24,padding:0,background:tn?"var(--bg-hover)":"none",border:"none",borderRadius:6,color:tu.length?"var(--accent)":"var(--text-muted)",cursor:"pointer",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=tu.length?"var(--accent)":"var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background=tn?"var(--bg-hover)":"none",e.currentTarget.style.color=tu.length?"var(--accent)":"var(--text-muted)"},children:(0,r.jsx)(v.c,{size:14})}),tn&&ti&&(ek=[{id:"upload",label:eA("desktop.attachUpload"),desc:eA("desktop.attachUploadDesc"),icon:R.J},{id:"reference",label:eA("desktop.attachReference"),desc:eA("desktop.attachReferenceDesc"),icon:n5.sj},{id:"sessions",label:eA("desktop.attachSessions"),desc:eA("desktop.attachSessionsDesc"),icon:sM.v},{id:"slash",label:eA("desktop.attachCommands"),desc:eA("desktop.attachCommandsDesc"),icon:g.C}],ev=window.visualViewport?.height??window.innerHeight,ey=window.innerWidth,eb=Math.min(ti.left,ey-220-8),ew=ev-ti.top+6,(0,r.jsx)("div",{role:"menu",style:{position:"fixed",left:eb,bottom:ew,zIndex:1200,width:220,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:12,boxShadow:"0 12px 32px rgba(0,0,0,0.22)",padding:4},children:ek.map(e=>(0,r.jsxs)("button",{type:"button",role:"menuitem",onClick:()=>{ts(!1),"upload"===e.id?tY.current?.click():"reference"===e.id?o_():"sessions"===e.id?oq():"slash"===e.id&&oV()},style:{display:"flex",alignItems:"center",gap:10,width:"100%",padding:"8px 10px",background:e.active?"var(--bg-selected)":"none",border:"none",borderRadius:8,cursor:"pointer",textAlign:"left",transition:"background 0.12s"},onMouseEnter:t=>{e.active||(t.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:t=>{t.currentTarget.style.background=e.active?"var(--bg-selected)":"none"},children:[(0,r.jsx)(e.icon,{size:16,weight:e.active?"fill":"regular",color:e.active?"var(--accent)":"var(--text-muted)","aria-hidden":"true"}),(0,r.jsxs)("span",{style:{flex:1,minWidth:0},children:[(0,r.jsx)("span",{style:{display:"block",fontSize:12.5,fontWeight:550,color:"var(--text)"},children:e.label}),(0,r.jsx)("span",{style:{display:"block",fontSize:10.5,color:"var(--text-muted)",marginTop:1,lineHeight:1.4},children:e.desc})]}),e.active?(0,r.jsx)(m.S,{size:12,weight:"bold",color:"var(--accent)","aria-hidden":"true"}):null]},e.id))}))]}),(0,r.jsx)("div",{className:"chat-input-toolbar-left",style:{flex:"0 0 auto",minWidth:0,display:"flex",alignItems:"center",gap:2},children:!eD&&W&&(0,r.jsx)(ic,{collaborationMode:P,onCollaborationModeChange:W,disabled:a})}),!eD&&(0,r.jsx)("div",{className:"chat-input-toolbar-spacer",style:{flex:1}}),(0,r.jsx)("div",{ref:tJ,className:"chat-input-toolbar-controls",style:{flex:eD?"1 1 auto":"0 1 auto",minWidth:0,display:"flex",alignItems:"center",justifyContent:"flex-end",position:"relative",marginLeft:eD?0:"auto"},children:(0,r.jsxs)("div",{className:"chat-input-toolbar-actions",style:{display:"flex",alignItems:"center",gap:eD?1:2,flexWrap:"wrap",justifyContent:"flex-end",...eD?{flex:"1 1 auto",minWidth:0}:null},children:[B&&(0,r.jsxs)("div",{ref:tK,className:"chat-input-toolbar-thinking",style:{position:"relative"},children:[(0,r.jsxs)("button",{onClick:e=>{if(a)return;let t=e.currentTarget.getBoundingClientRect();tp({top:t.top,left:t.left,width:t.width}),td(e=>!e)},disabled:a,title:eA("desktop.changeReasoningLevel",{level:o4}),"aria-label":eA("desktop.reasoningLevel"),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,padding:eD?"0 5px":"3px 7px",width:eD?"auto":void 0,height:24,background:tl?"var(--bg-hover)":"none",border:"none",borderRadius:6,color:(H??"auto")==="off"?"var(--text-dim)":"var(--accent)",cursor:a?"not-allowed":"pointer",fontSize:12,opacity:a?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{a||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{e.currentTarget.style.background=tl?"var(--bg-hover)":"none"},children:[(0,r.jsx)(ix,{level:H??"auto"}),(0,r.jsx)("span",{style:{whiteSpace:"nowrap"},children:o4}),(0,r.jsx)(k.b,{size:11,weight:"bold","aria-hidden":"true",style:{transform:tl?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.12s"}})]}),tl&&tc&&(ej=window.visualViewport?.height??window.innerHeight,eC=Math.min(240,(eS=window.innerWidth)-16),eT=Math.min(tc.left,eS-eC-8),eR=ej-tc.top+4,ez=Math.min(360,Math.max(120,Math.min(tc.top-8,.6*ej))),(0,r.jsx)("div",{style:{position:"fixed",bottom:eR,left:eT,zIndex:2001,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 4px 24px rgba(0,0,0,0.12)",overflow:"hidden",minWidth:200,maxWidth:eC,maxHeight:ez,overflowY:"auto"},children:im.filter(e=>!U||"auto"===e||U.includes(e)).map(e=>{let t=(H??"auto")===e,o="auto"!==e&&_?_[e]:void 0,n=null!=o&&o!==e?o:eN[e],s=null!=o&&o!==e;return(0,r.jsxs)("button",{onClick:()=>{td(!1),t||B(e)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"6px 12px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--accent)":"var(--text)",cursor:"pointer",fontSize:12,textAlign:"left",fontFamily:"var(--font-mono)",whiteSpace:"nowrap"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,r.jsx)(ix,{level:e,size:14}),(0,r.jsxs)("span",{style:{flex:1},children:[n,s&&(0,r.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",marginLeft:5},children:["(",e,")"]})]}),t&&(0,r.jsx)(m.S,{size:12,weight:"bold",color:"var(--accent)",style:{flexShrink:0}})]},e)})}))]}),S&&"plan"===j&&(0,r.jsxs)("div",{ref:tq,className:"chat-input-toolbar-tools",style:{position:"relative"},children:[" ",(0,r.jsxs)("button",{onClick:e=>{if(a)return;let t=e.currentTarget.getBoundingClientRect();tr({top:t.top,left:t.left,width:t.width}),tt(e=>!e)},disabled:a,title:eA("desktop.changeToolPreset",{preset:o8}),"aria-label":eA("desktop.toolPreset"),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,padding:eD?"0 5px":"3px 7px",width:eD?"auto":void 0,height:24,background:te?"var(--bg-hover)":"none",border:"none",borderRadius:6,color:"var(--text-muted)",cursor:a?"not-allowed":"pointer",fontSize:12,opacity:a?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{a||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=te?"var(--bg-hover)":"none",e.currentTarget.style.color="var(--text-muted)"},children:[(0,r.jsx)("span",{style:{whiteSpace:"nowrap"},children:o8}),(0,r.jsx)(k.b,{size:11,weight:"bold","aria-hidden":"true",style:{transform:te?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.12s"}})]}),te&&to&&(eI=window.visualViewport?.height??window.innerHeight,eP=Math.min(200,(eM=window.innerWidth)-16),eE=Math.max(8,eM-(to.left+to.width)),eW=eI-to.top+6,eF=Math.min(320,Math.max(100,Math.min(to.top-8,.5*eI))),(0,r.jsx)("div",{style:{position:"fixed",bottom:eW,right:eE,zIndex:2001,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 4px 24px rgba(0,0,0,0.12)",overflow:"hidden",minWidth:120,maxWidth:eP,maxHeight:eF,overflowY:"auto"},children:ip.map(e=>{let t=iu[e],o="plan"!==j&&(j??"default")===t,n="off"===e?eA("desktop.noToolsReadOnly"):"default"===e?eA("desktop.fourBuiltInTools"):eA("desktop.allBuiltInTools");return(0,r.jsxs)("button",{onClick:()=>{tt(!1),o||S(t)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"6px 12px",background:o?"var(--bg-selected)":"none",border:"none",color:o?"var(--accent)":"var(--text)",cursor:"pointer",fontSize:12,textAlign:"left",fontFamily:"var(--font-mono)",whiteSpace:"nowrap"},onMouseEnter:e=>{o||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{o||(e.currentTarget.style.background="none")},children:[(0,r.jsx)("span",{style:{flex:1},children:eL[e]}),(0,r.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:n}),o&&(0,r.jsx)(m.S,{size:12,weight:"bold",color:"var(--accent)",style:{flexShrink:0}})]},e)})}))]}),oZ.length>0&&y&&(0,r.jsxs)("div",{ref:tB,className:"chat-input-toolbar-model",style:{position:"relative",flex:eD?"0 1 auto":void 0,minWidth:0},children:[(0,r.jsxs)("button",{onClick:e=>{let t=e.currentTarget.getBoundingClientRect();e1({top:t.top,left:t.left,width:t.width}),eZ||e8(""),eQ(e=>!e)},disabled:a,title:o0??void 0,style:{display:"flex",alignItems:"center",gap:6,justifyContent:eD?"flex-start":void 0,padding:eD?"4px 6px":"3px 7px",height:24,maxWidth:eD?"min(150px, 42vw)":"min(220px, 34vw)",overflow:"hidden",background:eZ?"var(--bg-hover)":"none",border:"none",borderRadius:6,color:"var(--text-muted)",cursor:a?"not-allowed":"pointer",fontSize:12,opacity:a?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{a||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=eZ?"var(--bg-hover)":"none",e.currentTarget.style.color="var(--text-muted)"},children:[(0,r.jsx)(is,{id:l?.provider??"unknown",size:14}),(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:o0??eA("desktop.selectModel")}),(0,r.jsx)(k.b,{size:11,weight:"bold","aria-hidden":"true",style:{flexShrink:0,transform:eZ?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.12s"}})]}),eZ&&e0&&(()=>{let e=e2.height||window.innerHeight,t=e2.width||window.innerWidth,o=e0.top-e2.offsetTop,n=Math.max(6,e-o+6),s=Math.min(400,Math.max(120,Math.min(o-8,.6*e))),i=Math.min(320,s),a=e0.width,d=Math.min(360,t-16),c=eD?{left:8,right:8,maxWidth:"calc(100vw - 16px)"}:{right:Math.max(8,t-(e0.left+e0.width)),width:"max-content",minWidth:Math.min(a,d),maxWidth:d},p=[];for(let e of[...e5]){let[t,o]=e.split(":",2),r=oZ.find(e=>e.provider===t&&e.modelId===o);r&&p.push(r)}let h=e6.trim().toLowerCase(),g=h.length>0,f=e=>e.name.toLowerCase().includes(h)||e.modelId.toLowerCase().includes(h)||e.provider.toLowerCase().includes(h),x=g?p.filter(f):p,v=x.length>0,w=g?oQ.map(e=>({...e,options:e.options.filter(f)})).filter(e=>e.options.length>0):oQ,j=v||w.length>0;return(0,r.jsxs)("div",{ref:tU,className:"chat-input-model-dropdown",style:{position:"fixed",bottom:n,...c,zIndex:2e3,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 4px 24px rgba(0,0,0,0.12)",overflow:"hidden",height:i,maxHeight:s,display:"flex",flexDirection:"column"},children:[(0,r.jsx)("div",{style:{borderBottom:"1px solid var(--border)",flexShrink:0},children:(0,r.jsxs)("div",{style:{position:"relative",display:"flex",alignItems:"center"},children:[(0,r.jsx)(u.$,{size:13,color:"var(--text-dim)",style:{position:"absolute",left:12,pointerEvents:"none"}}),(0,r.jsx)("input",{ref:t_,value:e6,onChange:e=>e8(e.target.value),onKeyDown:e=>{if("Escape"===e.key)e6?e8(""):eQ(!1);else if("ArrowDown"===e.key){let t=tU.current?.querySelector(".model-row button");t&&(e.preventDefault(),t.focus())}},placeholder:eA("desktop.searchModels"),"aria-label":eA("desktop.searchModels"),style:{width:"100%",padding:"5px 12px 5px 34px",background:"transparent",border:"none",outline:"none",color:"var(--text)",fontSize:12,fontFamily:"var(--font-mono)"}})]})}),(0,r.jsxs)("div",{style:{overflowY:"auto",flex:1,minHeight:0},children:[v&&(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{style:{padding:"6px 12px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:eA("desktop.favorites")}),x.map(e=>{let t=e.modelId===l?.modelId&&e.provider===l?.provider,o=e5.has(`${e.provider}:${e.modelId}`);return(0,r.jsx)("div",{className:"model-row",style:{display:"flex",alignItems:"center",width:"100%"},children:(0,r.jsxs)("button",{onClick:()=>{eQ(!1),y(e.provider,e.modelId)},style:{display:"flex",alignItems:"center",gap:8,flex:1,minWidth:0,padding:"6px 12px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--accent)":"var(--text)",cursor:"pointer",fontSize:12,textAlign:"left",fontFamily:"var(--font-mono)",whiteSpace:"nowrap",overflow:"hidden"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,r.jsx)(is,{id:e.provider,size:14}),(0,r.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",minWidth:0},children:e.name}),t&&(0,r.jsx)(m.S,{size:12,weight:"bold",color:"var(--accent)",style:{flexShrink:0}}),(0,r.jsx)("span",{onClick:t=>{t.stopPropagation(),or(e.provider,e.modelId)},className:"model-star",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,cursor:"pointer",color:o?"var(--accent)":"var(--text-dim)",opacity:+!!o,transition:"opacity 0.12s, color 0.12s"},onMouseEnter:e=>{e.stopPropagation(),e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.stopPropagation(),e.currentTarget.style.color=o?"var(--accent)":"var(--text-dim)"},title:o?eA("desktop.unfavorite"):eA("desktop.favorite"),"aria-label":o?eA("desktop.unfavorite"):eA("desktop.favorite"),children:(0,r.jsx)(sF.G,{size:12,weight:o?"fill":"regular"})})]})},`fav-${e.provider}:${e.modelId}`)}),(0,r.jsx)("div",{style:{borderTop:"1px solid var(--border)"}})]}),w.map((e,t)=>{let o=g||e7.has(e.provider),n=o?(0,r.jsx)(k.b,{size:10,color:"var(--text-dim)"}):(0,r.jsx)(b.J,{size:10,color:"var(--text-dim)"});return(0,r.jsxs)("div",{children:[(0,r.jsxs)("button",{onClick:()=>on(e.provider),title:e.provider,style:{display:"flex",alignItems:"center",gap:4,width:"100%",maxWidth:"100%",padding:"6px 12px 4px",background:"none",border:"none",cursor:"pointer",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",overflow:"hidden",whiteSpace:"nowrap",borderTop:t>0?"1px solid var(--border)":"none"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)"},children:[n,(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",minWidth:0},children:e.provider})]}),o&&e.options.map(e=>{let t=e.modelId===l?.modelId&&e.provider===l?.provider,o=e5.has(`${e.provider}:${e.modelId}`);return(0,r.jsx)("div",{className:"model-row",style:{display:"flex",alignItems:"center",width:"100%"},children:(0,r.jsxs)("button",{onClick:()=>{eQ(!1),y(e.provider,e.modelId)},style:{display:"flex",alignItems:"center",gap:8,flex:1,minWidth:0,padding:"6px 12px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--accent)":"var(--text)",cursor:"pointer",fontSize:12,textAlign:"left",fontFamily:"var(--font-mono)",whiteSpace:"nowrap",overflow:"hidden"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,r.jsx)(is,{id:e.provider,size:14}),(0,r.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",minWidth:0},children:e.name}),t&&(0,r.jsx)(m.S,{size:12,weight:"bold",color:"var(--accent)",style:{flexShrink:0}}),(0,r.jsx)("span",{onClick:t=>{t.stopPropagation(),or(e.provider,e.modelId)},className:"model-star",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,cursor:"pointer",color:o?"var(--accent)":"var(--text-dim)",opacity:+!!o,transition:"opacity 0.12s, color 0.12s"},onMouseEnter:e=>{e.stopPropagation(),e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.stopPropagation(),e.currentTarget.style.color=o?"var(--accent)":"var(--text-dim)"},title:o?eA("desktop.unfavorite"):eA("desktop.favorite"),"aria-label":o?eA("desktop.unfavorite"):eA("desktop.favorite"),children:(0,r.jsx)(sF.G,{size:12,weight:o?"fill":"regular"})})]})},`${e.provider}:${e.modelId}`)})]},e.provider)}),g&&!j&&(0,r.jsx)("div",{style:{padding:"14px 12px",textAlign:"center",fontSize:12,color:"var(--text-dim)"},children:eA("desktop.noModelsMatch")})]})]})})()]}),0===oZ.length&&f&&(0,r.jsxs)("div",{className:"chat-input-toolbar-model",title:`${eA("desktop.modelsLoadFailed")}: ${f}`,style:{display:"flex",alignItems:"center",gap:6,flex:eD?"1 1 auto":void 0,minWidth:0,padding:"3px 7px",height:24,background:"rgba(239,68,68,0.10)",border:"none",borderRadius:6,fontSize:12,overflow:"hidden"},children:[(0,r.jsx)(r0.M,{size:14,color:"#ef4444",weight:"fill",style:{flexShrink:0}}),(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0,color:"#ef4444"},children:eA("desktop.modelsLoadFailed")}),x&&(0,r.jsx)("button",{type:"button",onClick:x,style:{display:"inline-flex",alignItems:"center",gap:4,flexShrink:0,padding:"1px 6px",background:"rgba(239,68,68,0.14)",border:"none",borderRadius:4,color:"#ef4444",cursor:"pointer",fontSize:11,fontWeight:600,transition:"background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.24)"},onMouseLeave:e=>{e.currentTarget.style.background="rgba(239,68,68,0.14)"},children:eA("desktop.retry")})]}),0===oZ.length&&!f&&(0,r.jsxs)("div",{className:"chat-input-toolbar-model",title:eA("desktop.noModelsConfigured"),style:{display:"flex",alignItems:"center",gap:6,flex:eD?"1 1 auto":void 0,minWidth:0,padding:"3px 7px",height:24,background:"var(--bg-hover)",border:"none",borderRadius:6,color:"var(--text-dim)",fontSize:12,overflow:"hidden"},children:[(0,r.jsx)(r0.M,{size:14,color:"var(--text-dim)",style:{flexShrink:0}}),(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:eA("desktop.noModelsConfigured")})]}),!a&&(0,r.jsx)("button",{type:"button",onClick:oh,disabled:!eO.trim()&&!tu.length,className:"chat-input-send",title:eA("desktop.sendMessage"),"aria-label":eA("desktop.sendMessage"),children:(0,r.jsx)(sE.l,{size:14})}),a&&(0,r.jsxs)("button",{onClick:o,title:eA("desktop.stopAgent"),"aria-label":eA("desktop.stopAgent"),style:{display:"flex",alignItems:"center",gap:6,padding:"3px 7px",height:24,background:"rgba(239,68,68,0.12)",border:"none",borderRadius:6,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.20)"},onMouseLeave:e=>{e.currentTarget.style.background="rgba(239,68,68,0.12)"},children:[(0,r.jsx)(sW.d,{size:14}),eA("desktop.stop")]})]})})]})]})]})]})]})}));function iP(e){return!!e&&"string"==typeof e.type&&"string"==typeof e.data&&"string"==typeof e.mimeType}function iE(e){let t;if(!e||"object"!=typeof e)return null;let o=e.kind;return"steer"!==o&&"followUp"!==o||"string"!=typeof e.text?null:(Array.isArray(e.images)&&0===(t=e.images.filter(iP)).length&&(t=void 0),{kind:o,text:e.text,...t?{images:t}:{}})}function iW({items:e,sessionId:t,onResolve:o,onExport:s,onStageImport:i,onDismiss:a,mode:l="recovery"}){let{t:d}=(0,A.s)(),c=O(),[p,u]=(0,n.useState)(()=>new Set(e.map(e=>e.id))),[h,g]=(0,n.useState)(!1),[m,f]=(0,n.useState)(null),x=(0,n.useRef)(null);(0,n.useEffect)(()=>{u(new Set(e.map(e=>e.id)))},[e]);let k=e.filter(e=>p.has(e.id)),v=k.length===e.length&&e.length>0,y=e=>u(t=>{let o=new Set(t);return o.has(e)?o.delete(e):o.add(e),o}),b=async(e,t=!1)=>{if(0!==k.length){g(!0),f(null);try{await o("keep"===e?k.map(e=>e.id):[],"discard"===e?k.map(e=>e.id):[],t)}catch(e){f(e instanceof Error?e.message:String(e))}finally{g(!1)}}},w=async e=>{let o=await s();if(!o)return;let r=o.recovery.filter(e=>p.has(e.id));if(r.length){var n;let o,s,i,a,l,c,p;n={sessionId:t,source:"recovery"},s="md"===e?(((o=[]).push("# Queued messages export"),n.sessionId&&o.push(`- Session: ${n.sessionId}`),o.push(`- Source: ${"live"===n.source?"live queue":"pending recovery"}`),o.push(`- Exported: ${n.exportedAt??new Date().toISOString()}`),o.push(""),0===r.length)?o.push("_No entries._"):r.forEach((e,t)=>{var r;o.push(`## ${t+1}. ${"steer"===e.kind?"steer":"follow-up"} \xb7 ${new Date(e.queuedAt).toISOString()}`),e.text&&o.push(e.text),e.images?.length&&o.push(`> _${0===(r=e.images.length)?"":1===r?"(1 image)":`(${r} images)`}_`),o.push("")}),o.join("\n")):JSON.stringify({format:"pi-web-queue",version:1,exportedAt:n.exportedAt??new Date().toISOString(),source:n.source,sessionId:n.sessionId,entries:r.map(({kind:e,text:t,images:o})=>({kind:e,text:t,...o?.length?{images:o}:{}}))},null,2),i=new Date().toISOString().replace(/[:.]/g,"-").slice(0,19),a=`${n.sessionId??"session"}-queue-${n.source}-${i}.${e}`,l=new Blob([s],{type:"md"===e?"text/markdown;charset=utf-8":"application/json;charset=utf-8"}),c=URL.createObjectURL(l),(p=document.createElement("a")).href=c,p.download=a,p.click(),setTimeout(()=>URL.revokeObjectURL(c),1e3),f(d("desktop.queueExported",{count:r.length}))}},j=async e=>{let t=function(e){let t;try{t=JSON.parse(e)}catch{return[]}let o=Array.isArray(t)?t:t&&"object"==typeof t&&Array.isArray(t.entries)?t.entries:null;return o?o.map(iE).filter(e=>null!==e):[]}(await e.text());if(!t.length)return void f(d("desktop.queueImportEmpty"));let o=await i(t);f(null===o?d("desktop.queueImportEmpty"):d("desktop.queueImported",{count:o}))};return(0,r.jsxs)("div",{className:"fixed inset-0 z-[1000] flex items-center justify-center bg-black/40 p-3",role:"presentation",children:[(0,r.jsxs)("div",{role:"dialog","aria-modal":"true","aria-label":"import"===l?d("desktop.queueImportTitle"):d("desktop.queueRecoveryTitle"),className:"flex max-h-[88dvh] w-full max-w-2xl flex-col overflow-hidden rounded-xl border border-(--border) bg-(--bg) shadow-2xl",children:[(0,r.jsxs)("header",{className:"flex flex-wrap items-start gap-3 border-b border-(--border) bg-(--bg-panel) px-4 py-3",children:[(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsx)("h2",{className:"text-sm font-semibold text-(--text)",children:"import"===l?d("desktop.queueImportTitle"):d("desktop.queueRecoveryTitle")}),(0,r.jsx)("p",{className:"mt-1 text-xs leading-5 text-(--text-muted)",children:"import"===l?d("desktop.queueImportDescription"):d("desktop.queueRecoveryDescription")})]}),(0,r.jsxs)("div",{className:"flex items-center gap-1",children:[(0,r.jsx)("button",{type:"button",className:"markdown-code-action",onClick:()=>u(new Set(v?[]:e.map(e=>e.id))),children:v?d("desktop.selectNone"):d("desktop.selectAll")}),(0,r.jsx)("button",{type:"button",className:"markdown-code-action",disabled:h||0===k.length,onClick:()=>void w("json"),children:"JSON"}),(0,r.jsx)("button",{type:"button",className:"markdown-code-action",disabled:h||0===k.length,onClick:()=>void w("md"),children:"MD"}),(0,r.jsx)("button",{type:"button",className:"markdown-code-action",disabled:h,onClick:()=>x.current?.click(),children:d("desktop.import")}),(0,r.jsx)("button",{type:"button",className:"markdown-code-action",onClick:a,"aria-label":d("desktop.close"),children:"\xd7"})]})]}),(0,r.jsx)("div",{className:"grid flex-1 content-start gap-2 overflow-y-auto p-3",children:e.map(e=>{let t=p.has(e.id);return(0,r.jsxs)("button",{type:"button",onClick:()=>y(e.id),"aria-pressed":t,className:["flex w-full items-start gap-3 rounded-lg border p-3 text-left transition",t?"border-(--accent) bg-(--bg-selected)":"border-(--border) bg-(--bg-panel) hover:bg-(--bg-hover)"].join(" "),children:[(0,r.jsx)("input",{type:"checkbox",checked:t,onChange:()=>y(e.id),onClick:e=>e.stopPropagation(),className:"mt-1 accent-[var(--accent)]"}),(0,r.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,r.jsxs)("span",{className:"flex flex-wrap items-center gap-2 text-[11px] text-(--text-dim)",children:[(0,r.jsx)("span",{className:"rounded-full border border-(--border) px-2 py-0.5 font-mono uppercase",children:"steer"===e.kind?d("desktop.steer"):d("desktop.followUp")}),(0,r.jsx)("span",{children:new Date(e.queuedAt).toLocaleString()}),e.hasImages?(0,r.jsx)("span",{children:d("desktop.queueImages")}):null]}),(0,r.jsx)("span",{className:"mt-2 block whitespace-pre-wrap break-words border-l-2 border-(--border) pl-2 text-xs leading-5 text-(--text)",children:e.text||d("desktop.queueNoText")})]})]},e.id)})}),(0,r.jsxs)("footer",{className:["flex flex-wrap items-center gap-2 border-t border-(--border) px-4 py-3",c?"justify-stretch":"justify-end"].join(" "),children:[m?(0,r.jsx)("span",{className:"mr-auto text-xs text-(--text-muted)",children:m}):null,(0,r.jsx)("button",{type:"button",className:"rounded-md px-3 py-2 text-xs text-(--text-muted) hover:bg-(--bg-hover)",onClick:a,disabled:h,children:d("desktop.dismiss")}),(0,r.jsx)("button",{type:"button",className:"rounded-md border border-red-400/40 px-3 py-2 text-xs text-red-400 disabled:opacity-40",onClick:()=>void b("discard"),disabled:h||0===k.length,children:d("desktop.discard")}),(0,r.jsx)("button",{type:"button",className:"rounded-md border border-(--accent) px-3 py-2 text-xs text-(--accent) disabled:opacity-40",onClick:()=>void b("keep"),disabled:h||0===k.length,children:d("desktop.requeue")}),(0,r.jsx)("button",{type:"button",className:"rounded-md bg-(--accent) px-3 py-2 text-xs text-white disabled:opacity-40",onClick:()=>void b("keep",!0),disabled:h||0===k.length,children:d("desktop.requeueAndContinue")})]})]}),(0,r.jsx)("input",{ref:x,type:"file",accept:".json,application/json",className:"hidden",onChange:e=>{let t=e.target.files?.[0];t&&j(t),e.currentTarget.value=""}})]})}var iF=o(36405),iD=o(92185),iA=o(75877),iN=o(30830),iL=o(86965);function i$(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function iH(e){let t=e,o=t.compressedEntryIds?.length??0;for(;1===t.children.length;)t=t.children[0],o+=1+(t.compressedEntryIds?.length??0);return{node:t,skipped:o}}function iO({node:e,assistantLabel:t,activePathIds:o,depth:n,isLast:s,parentLines:i,onSelect:a}){let{node:l,skipped:d}=iH(e),c=o.has(l.entry.id),p=o.has(e.entry.id)||o.has(l.entry.id),u=function(e,t){if("message"===e.type&&"message"in e){let o=e.message,r=o.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"===o.role)return`[${t}]`}return e.type}(l.entry,t),h="message"===l.entry.type&&"message"in l.entry?l.entry.message.role:null;return(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",height:24,cursor:"pointer"},onClick:()=>a(l.entry.id),children:[i.map((e,t)=>(0,r.jsx)("div",{style:{width:16,flexShrink:0,position:"relative",height:"100%",alignSelf:"stretch"},children:e&&(0,r.jsx)("div",{style:{position:"absolute",left:7,top:0,bottom:0,width:1,background:"var(--border)"}})},t)),(0,r.jsxs)("div",{style:{width:16,flexShrink:0,position:"relative",height:"100%",alignSelf:"stretch"},children:[(0,r.jsx)("div",{style:{position:"absolute",left:7,top:0,bottom:s?"50%":0,width:1,background:"var(--border)"}}),(0,r.jsx)("div",{style:{position:"absolute",left:7,top:"50%",width:9,height:1,background:"var(--border)"}})]}),(0,r.jsx)("div",{style:{width:7,height:7,borderRadius:"50%",flexShrink:0,background:c?"var(--accent)":p?"var(--text-muted)":"var(--border)",border:c?"none":"1px solid var(--text-dim)",marginRight:6,transition:"background 0.12s"}}),h&&(0,r.jsx)("span",{style:{fontSize:9,fontFamily:"var(--font-mono)",color:"user"===h?"var(--accent)":"var(--text-dim)",background:"user"===h?"rgba(37,99,235,0.08)":"var(--bg-hover)",border:`1px solid ${"user"===h?"rgba(37,99,235,0.2)":"var(--border)"}`,borderRadius:3,padding:"0 4px",marginRight:5,flexShrink:0,lineHeight:"16px"},children:"user"===h?"U":"A"}),d>0&&(0,r.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",marginRight:5,flexShrink:0},children:["+",d]}),(0,r.jsx)("span",{style:{fontSize:11,color:c?"var(--text)":p?"var(--text-muted)":"var(--text-dim)",fontWeight:c?500:400,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,minWidth:0},children:u})]}),l.children.map((e,d)=>(0,r.jsx)(iO,{node:e,assistantLabel:t,activePathIds:o,depth:n+1,isLast:d===l.children.length-1,parentLines:[...i,!s],onSelect:a},e.entry.id))]})}function iB({tree:e,activeLeafId:t,onLeafChange:o,inline:s,containerRef:i,open:a,onToggle:l,hasSession:d,embedded:c}){let{t:p}=(0,A.s)(),[u,h]=(0,n.useState)(!1),g=void 0!==a?a:u,m=(0,n.useRef)(null),[f,x]=(0,n.useState)(null);(0,n.useEffect)(()=>{if(!g||!s)return;let e=i?.current??m.current;if(!e)return;let t=()=>{let t=e.getBoundingClientRect();x({top:t.bottom,left:t.left,width:t.width})};t();let o=new ResizeObserver(t);return o.observe(e),()=>o.disconnect()},[g,s,i]);let v=(0,n.useMemo)(()=>(function(e,t){if(!t)return new Set;let o=e.map(e=>({node:e,path:[e.entry.id]}));for(;o.length>0;){let{node:e,path:r}=o.pop();if(e.entry.id===t||e.compressedEntryIds?.includes(t))return new Set(r);for(let t of e.children)o.push({node:t,path:[...r,t.entry.id]})}return new Set})(e,t),[e,t]),b=(0,n.useCallback)(e=>{o(e)},[o]),w=d?!function(e){if(e.length>1)return!0;let t=[...e];for(;t.length>0;){let e=t.pop();if(e.children.length>1)return!0;for(let o of e.children)t.push(o)}return!1}(e)?p("desktop.sessionHasNoBranches"):null:p("desktop.noActiveSession"),j=e.length>0?iH(e[0]):null,S=j?.node??null,C=!w&&S&&S.children.length>1,T=(0,r.jsx)(y.Z,{size:16,"aria-hidden":"true",style:{flexShrink:0}}),R=(0,r.jsx)(k.a,{size:8,color:"var(--text-dim)","aria-hidden":"true",style:{marginLeft:1,transition:"transform 0.15s",transform:g?"rotate(180deg)":"none"}});return s?(0,r.jsxs)("div",{style:{height:"100%",display:"flex",alignItems:"stretch"},children:[(0,r.jsx)("button",{ref:m,className:"app-no-drag",onClick:()=>l?l():h(e=>!e),style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:g?"var(--bg-selected)":"none",border:"none",cursor:"pointer",color:g?"var(--text)":"var(--text-muted)",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background=g?"var(--bg-selected)":"none",e.currentTarget.style.color=g?"var(--text)":"var(--text-muted)"},title:p("desktop.branches"),"aria-label":p("desktop.branches"),"aria-pressed":g,children:T}),g&&f&&(0,r.jsx)("div",{className:"app-no-drag",style:{position:"fixed",top:f.top,left:f.left,width:f.width,background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",zIndex:500},children:C&&S?(0,r.jsx)("div",{style:{padding:"4px 12px 8px 12px",maxHeight:260,overflowY:"auto"},children:S.children.map((e,t)=>(0,r.jsx)(iO,{node:e,assistantLabel:p("desktop.assistant"),activePathIds:v,depth:0,isLast:t===S.children.length-1,parentLines:[],onSelect:b},e.entry.id))}):(0,r.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:w})})]}):c?C&&S?(0,r.jsx)("div",{style:{padding:"4px 8px 8px 8px"},children:S.children.map((e,t)=>(0,r.jsx)(iO,{node:e,assistantLabel:p("desktop.assistant"),activePathIds:v,depth:0,isLast:t===S.children.length-1,parentLines:[],onSelect:b},e.entry.id))}):(0,r.jsx)("div",{style:{padding:"10px 12px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:w??p("desktop.sessionHasNoBranches")}):(0,r.jsxs)("div",{style:{borderBottom:"1px solid var(--border)",background:"var(--bg)",flexShrink:0,position:"relative"},children:[(0,r.jsxs)("button",{onClick:()=>h(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:[T,(0,r.jsx)("span",{style:{color:"var(--text-muted)"},children:p("desktop.branches")}),R]}),g&&(0,r.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:C&&S?(0,r.jsx)("div",{style:{padding:"4px 12px 8px 12px",maxHeight:260,overflowY:"auto"},children:S.children.map((e,t)=>(0,r.jsx)(iO,{node:e,assistantLabel:p("desktop.assistant"),activePathIds:v,depth:0,isLast:t===S.children.length-1,parentLines:[],onSelect:b},e.entry.id))}):(0,r.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:w??p("desktop.sessionHasNoBranches")})})]})}var iU=o(45390),i_=o(33846);function iq({open:e,onOpenChange:t,cwd:o}){let{t:s}=(0,A.s)(),[i,a]=(0,n.useState)([]),[l,d]=(0,n.useState)(""),[c,p]=(0,n.useState)(!1),[u,g]=(0,n.useState)(null),[m,f]=(0,n.useState)(null),x=(0,n.useCallback)(async()=>{if(o)try{let e=await fetch(`/api/git/stash?${new URLSearchParams({cwd:o}).toString()}`,{cache:"no-store"});if(e.ok){let t=await e.json();a(t.entries)}}catch{}},[o]);if((0,n.useEffect)(()=>{e&&x()},[e,x]),!e)return null;let k=async(e,t)=>{p(!0),g(null),f(null);try{let r=await fetch(`/api/git/stash?${new URLSearchParams({cwd:o??""}).toString()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:e,message:l||void 0,ref:t})}),n=await r.json();r.ok&&n.ok?(f(n.output??s("tasks.stashDone")),d(""),x()):g(n.error??`HTTP ${r.status}`)}catch(e){g(e instanceof Error?e.message:String(e))}finally{p(!1)}};return(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:950,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.45)"},onMouseDown:e=>{e.target===e.currentTarget&&t(!1)},children:(0,r.jsxs)("div",{style:{width:"min(520px, calc(100vw - 48px))",maxHeight:"min(75vh, 560px)",overflow:"auto",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 16px 48px rgba(0,0,0,0.3)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 16px 0"},children:[(0,r.jsx)("h3",{style:{fontSize:15,fontWeight:600,margin:0},children:s("desktop.stashTitle")}),(0,r.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":s("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex"},children:(0,r.jsx)(h.X,{size:16,"aria-hidden":"true"})})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,padding:"14px 16px 16px"},children:[(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[(0,r.jsx)("input",{value:l,onChange:e=>d(e.target.value),placeholder:s("desktop.stashMessagePlaceholder"),style:{width:"100%",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"7px 10px",color:"var(--text)",fontSize:13,outline:"none",fontFamily:"inherit"}}),(0,r.jsxs)("button",{type:"button",onClick:()=>void k("push"),disabled:c,style:{alignSelf:"flex-start",display:"inline-flex",alignItems:"center",gap:5,padding:"7px 14px",borderRadius:8,background:"var(--accent)",color:"#fff",border:"none",fontSize:12,fontWeight:600,cursor:c?"not-allowed":"pointer"},children:[(0,r.jsx)(i_.c,{size:13,"aria-hidden":"true"}),s("desktop.stashPush")]})]}),u&&(0,r.jsx)("div",{style:{padding:"8px 10px",borderRadius:8,background:"rgba(239,68,68,0.10)",color:"#ef4444",fontSize:12,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:u}),m&&(0,r.jsx)("div",{style:{padding:"8px 10px",borderRadius:8,background:"rgba(34,197,94,0.10)",color:"#22c55e",fontSize:12,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:m}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column"},children:[(0,r.jsxs)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",marginBottom:6},children:[s("desktop.stashList")," (",i.length,")"]}),0===i.length?(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)"},children:s("desktop.stashEmpty")}):(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:i.map(e=>(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"7px 10px",borderRadius:8,border:"1px solid var(--border)",background:"var(--bg)"},children:[(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-muted)",flexShrink:0},children:e.index}),(0,r.jsx)("span",{style:{flex:1,minWidth:0,fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.message||e.ref}),(0,r.jsxs)("button",{type:"button",onClick:()=>void k("pop",e.ref),disabled:c,title:s("desktop.stashPop"),style:{display:"inline-flex",alignItems:"center",gap:3,padding:"4px 8px",borderRadius:6,border:"1px solid var(--border)",background:"none",color:"var(--text)",fontSize:11,cursor:c?"not-allowed":"pointer"},children:[(0,r.jsx)(C.S,{size:11,"aria-hidden":"true"}),s("desktop.stashPop")]}),(0,r.jsx)("button",{type:"button",onClick:()=>void k("drop",e.ref),disabled:c,title:s("desktop.stashDrop"),style:{display:"inline-flex",alignItems:"center",padding:"4px 8px",borderRadius:6,border:"1px solid var(--border)",background:"none",color:"#ef4444",fontSize:11,cursor:c?"not-allowed":"pointer"},children:s("desktop.stashDrop")})]},e.ref))})]})]})]})})}function iV({cwd:e}){let{t}=(0,A.s)(),[o,s]=(0,n.useState)(!1),[i,a]=(0,n.useState)("idle"),[l,d]=(0,n.useState)(null),[c,p]=(0,n.useState)(!1),u=(0,n.useCallback)(async()=>{if(e&&!o){s(!0),a("idle");try{let o=await fetch(`/api/git/push?${new URLSearchParams({cwd:e}).toString()}`,{method:"POST",cache:"no-store"}),r=await o.json();o.ok&&r.ok?(a("ok"),d(r.output||t("desktop.pushOk"))):(a("error"),d(r.error??t("desktop.pushFailed")))}catch(e){a("error"),d(e instanceof Error?e.message:t("desktop.pushFailed"))}finally{s(!1),setTimeout(()=>{a("idle"),d(null)},4e3)}}},[e,o,t]);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{type:"button",className:"session-info-bar-button",onClick:()=>void u(),disabled:!e||o,title:t("desktop.push"),"aria-label":t("desktop.push"),style:{position:"relative"},children:"ok"===i?(0,r.jsx)(nv.r,{size:13,color:"#22c55e",weight:"fill","aria-hidden":"true"}):"error"===i?(0,r.jsx)(iU.J,{size:13,color:"#ef4444",weight:"fill","aria-hidden":"true"}):(0,r.jsx)(i_.c,{size:13,"aria-hidden":"true"})}),(0,r.jsx)("button",{type:"button",className:"session-info-bar-button",onClick:()=>p(!0),disabled:!e,title:t("desktop.stash"),"aria-label":t("desktop.stash"),children:(0,r.jsx)(P.T,{size:13,"aria-hidden":"true"})}),l&&(0,r.jsx)("div",{style:{position:"fixed",bottom:60,left:"50%",transform:"translateX(-50%)",zIndex:1200,maxWidth:"60vw",padding:"8px 14px",borderRadius:8,background:"var(--bg-panel)",border:`1px solid ${"ok"===i?"#22c55e":"#ef4444"}`,boxShadow:"0 8px 24px rgba(0,0,0,0.2)",fontSize:12,color:"ok"===i?"#22c55e":"#ef4444",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:l}),(0,r.jsx)(iq,{open:c,onOpenChange:p,cwd:e})]})}function iK({onViewFullHistory:e,cwd:t,systemPrompt:o,sessionStats:s,contextUsage:i,hasSession:a,showChat:l,soundEnabled:d,onSoundToggle:c,onCompact:p,onAbortCompaction:u,isCompacting:h,compactError:g,branchTree:f,branchActiveLeafId:x,onBranchLeafChange:k,showSoundLabel:v,isDeepSeekOfficial:b,deepseekBalance:w,lastTurnUsage:j}){let{t:S}=(0,A.s)(),[C,T]=(0,n.useState)(null),R=(0,n.useCallback)(()=>T(null),[]),[z,I]=(0,n.useState)(null),M=(0,n.useRef)(null),P=(0,n.useCallback)((e,t)=>{re(t).then(()=>{M.current&&clearTimeout(M.current),I(e),M.current=setTimeout(()=>I(null),1400)})},[]),E=(0,n.useMemo)(()=>{if(!o)return 0;let e=0;for(let t of o){let o=t.codePointAt(0)??0;o>=19968&&o<=40959||o>=13312&&o<=19903||o>=131072&&o<=173791||o>=12352&&o<=12447||o>=12448&&o<=12543||o>=44032&&o<=55215?e+=1:e+=.25}return Math.max(1,Math.round(e))},[o]),W=(0,n.useMemo)(()=>{if(!w?.available||null==w.totalBalance)return S("desktop.balanceUnavailable");let e=Number(w.grantedBalance)||0,t=Number(w.toppedUpBalance)||0;return`${S("desktop.balance")}:${r8(Number(w.totalBalance)||0)}(${S("desktop.balanceGranted")}:${r8(e)} / ${S("desktop.balanceToppedUp")}:${r8(t)})`},[w,S]);if(!l)return null;let F=s?.tokens,D=s?.cost??0,N=s?.costCNY??0,L=s?.costUSD??0,$=[];N>0&&$.push(r8(N)),L>0&&$.push(L>=.01?`$${L.toFixed(2)}`:"<$0.01"),0===$.length&&D>0&&$.push(D>=.01?`$${D.toFixed(2)}`:"<$0.01");let H=$.length>0?$.join(" + "):null,O="var(--text-muted)";if(i?.contextWindow){let e=i.percent;null!==e&&e>90?O="#ef4444":null!==e&&e>70&&(O="rgba(234,179,8,0.95)")}let B=null!==o&&""!==o,U=s&&F&&(F.input>0||F.output>0),_=a&&k,q=[];if(F&&(q.push(`${S("desktop.sessionInfoInput")}: ${F.input.toLocaleString()}`),q.push(`${S("desktop.sessionInfoOutput")}: ${F.output.toLocaleString()}`),F.cacheRead>0&&q.push(`${S("desktop.sessionInfoCacheRead")}: ${F.cacheRead.toLocaleString()}`),F.cacheWrite>0&&q.push(`${S("desktop.sessionInfoCacheWrite")}: ${F.cacheWrite.toLocaleString()}`),N>0&&q.push(`${S("desktop.sessionInfoCostOfficial")}: ${r8(N)}`),L>0&&q.push(`${S("desktop.sessionInfoCost")}: $${L.toFixed(4)}`),N<=0&&L<=0&&D>0&&q.push(`${S("desktop.sessionInfoCost")}: $${D.toFixed(4)}`)),i?.contextWindow&&null!==i.percent){let e=i.percent,t=i.tokens;q.push(`${S("desktop.sessionInfoContext")}: ${null!==e?`${e.toFixed(1)}%`:"?"} ${null!==t?i$(t):"?"}/${i$(i.contextWindow)}`)}let V=q.join(" | ");return(0,r.jsxs)("div",{className:"session-info-bar",children:[t&&(0,r.jsx)(iV,{cwd:t}),c&&(0,r.jsxs)("button",{type:"button",className:"session-info-bar-button",onClick:c,title:d?S("desktop.disableCompletionSound"):S("desktop.enableCompletionSound"),"aria-label":d?S("desktop.disableCompletionSound"):S("desktop.enableCompletionSound"),children:[d?(0,r.jsx)(iF.Q,{size:13}):(0,r.jsx)(iD.l,{size:13}),v&&(0,r.jsx)("span",{style:{marginLeft:4},children:d?S("desktop.soundLabelOn"):S("desktop.soundLabelOff")})]}),a&&(0,r.jsx)("button",{type:"button",className:"session-info-bar-button",onClick:e,title:S("desktop.viewFullHistory"),"aria-label":S("desktop.viewFullHistory"),children:(0,r.jsx)(iA.n,{size:13,"aria-hidden":"true"})}),_&&(0,r.jsxs)("div",{className:"session-info-bar-popover-host",children:[(0,r.jsx)("button",{type:"button",className:`session-info-bar-button${"branches"===C?" is-active":""}`,onClick:()=>T(e=>"branches"===e?null:"branches"),title:S("desktop.branches"),"aria-label":S("desktop.branches"),"aria-pressed":"branches"===C,children:(0,r.jsx)(y.Z,{size:13,"aria-hidden":"true"})}),"branches"===C&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"session-info-bar-popover-cover",onClick:R}),(0,r.jsxs)("div",{className:"session-info-bar-popover is-branches",children:[(0,r.jsxs)("div",{className:"session-info-bar-popover-header",children:[(0,r.jsx)("span",{className:"session-info-bar-popover-title",children:S("desktop.branches")}),(0,r.jsx)("button",{type:"button",className:"session-info-bar-popover-close",onClick:R,title:S("i18n.close"),"aria-label":S("i18n.close"),children:"✕"})]}),(0,r.jsx)("div",{className:"session-info-bar-popover-body",children:(0,r.jsx)(iB,{tree:f??[],activeLeafId:x??null,onLeafChange:e=>{k(e),R()},hasSession:!0,embedded:!0})})]})]})]}),B&&(0,r.jsxs)("div",{className:"session-info-bar-popover-host",children:[(0,r.jsx)("button",{type:"button",className:`session-info-bar-button${"system"===C?" is-active":""}`,onClick:()=>T(e=>"system"===e?null:"system"),title:S("desktop.systemPrompt"),"aria-label":S("desktop.systemPrompt"),"aria-pressed":"system"===C,children:(0,r.jsx)(sz.i,{size:13,"aria-hidden":"true"})}),"system"===C&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"session-info-bar-popover-cover",onClick:R}),(0,r.jsxs)("div",{className:"session-info-bar-popover is-system",children:[(0,r.jsxs)("div",{className:"session-info-bar-popover-header",children:[(0,r.jsx)("span",{className:"session-info-bar-popover-title",children:S("desktop.systemPrompt")}),(0,r.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",marginLeft:8},children:["~",i$(E)," tokens"]}),(0,r.jsx)("div",{style:{flex:1}}),(0,r.jsx)("button",{type:"button",className:"session-info-bar-popover-close",onClick:R,title:S("i18n.close"),"aria-label":S("i18n.close"),children:"✕"})]}),(0,r.jsx)("div",{className:"session-info-bar-system-body",children:o?(0,r.jsx)(on.oz,{remarkPlugins:[ra.A],children:o}):(0,r.jsx)("span",{className:"session-info-bar-popover-empty",children:"System prompt is empty (tools are disabled)"})})]})]})]}),(0,r.jsx)("div",{className:"session-info-bar-spacer"}),p&&(0,r.jsxs)("div",{className:"session-info-bar-compact-wrap",children:[g&&(0,r.jsx)("div",{className:"session-info-bar-compact-error",children:g}),(0,r.jsx)("button",{type:"button",className:`session-info-bar-button${h?" is-compacting":""}`,onClick:h?u:p,title:h?S("desktop.stopCompaction"):S("desktop.compactContext"),"aria-label":h?S("desktop.stopCompaction"):S("desktop.compactContext"),children:h?(0,r.jsx)(sW.M,{size:13}):(0,r.jsx)(iN.C,{size:13})})]}),b&&w?.available&&null!=w.totalBalance&&(0,r.jsxs)("span",{className:"session-info-bar-token-chip",style:{color:"var(--text-muted)",cursor:"default"},title:W,children:[(0,r.jsx)(iL.u,{size:11,"aria-hidden":"true"}),S("desktop.balance")," ",r8(Number(w.totalBalance)||0)]}),U&&(0,r.jsxs)("div",{className:"session-info-bar-popover-host",children:[(0,r.jsxs)("button",{type:"button",className:`session-info-bar-button is-stats${"session"===C?" is-active":""}`,onClick:()=>T(e=>"session"===e?null:"session"),title:V||S("desktop.sessionInfo"),"aria-label":S("desktop.sessionInfo"),"aria-pressed":"session"===C,children:[F&&F.input>0&&(0,r.jsxs)("span",{className:"session-info-bar-token-chip",children:[(0,r.jsx)(rY.D,{size:10,"aria-hidden":"true"}),i$(F.input)]}),F&&F.output>0&&(0,r.jsxs)("span",{className:"session-info-bar-token-chip",children:[(0,r.jsx)(rJ.y,{size:10,"aria-hidden":"true"}),i$(F.output)]}),F&&F.cacheRead>0&&(0,r.jsxs)("span",{className:"session-info-bar-token-chip",children:[(0,r.jsx)(rQ.W,{size:10,"aria-hidden":"true"}),i$(F.cacheRead)]}),H&&(0,r.jsx)("span",{children:H}),i?.contextWindow&&null!==i.percent&&(0,r.jsx)("span",{className:"session-info-bar-token-chip",style:{color:O},children:(0,r.jsxs)("svg",{className:"session-info-bar-donut",width:"16",height:"16",viewBox:"0 0 16 16","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"8",cy:"8",r:"6.75",fill:"none",stroke:"var(--border)",strokeWidth:"2.5"}),(0,r.jsx)("circle",{className:"session-info-bar-donut-arc",cx:"8",cy:"8",r:"6.75",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",pathLength:100,strokeDasharray:100,strokeDashoffset:null===i.percent?0:100-Math.min(100,Math.max(0,i.percent)),transform:"rotate(-90 8 8)"})]})})]}),"session"===C&&s&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"session-info-bar-popover-cover",onClick:R}),(0,r.jsx)("div",{className:"session-info-bar-popover is-session",children:(0,r.jsx)("div",{className:"session-stats-body",children:(()=>{let e=s.tokens,t=i??s.contextUsage,o=(e,t)=>{let o=z===e;return(0,r.jsx)("button",{type:"button",className:`session-stats-copy${o?" is-copied":""}`,title:o?S("desktop.copied"):"file"===e?S("desktop.copyFilePath"):S("desktop.copySessionId"),onClick:()=>P(e,t),children:o?(0,r.jsx)(m.J,{size:12,"aria-hidden":"true"}):(0,r.jsx)(or.Q,{size:12,"aria-hidden":"true"})})},n=[];s.sessionName&&n.push((0,r.jsx)("div",{className:"session-stats-info-name",children:s.sessionName},"name")),n.push((0,r.jsxs)("div",{className:"session-stats-info-line",children:[(0,r.jsx)("span",{className:"session-stats-info-text",children:s.sessionFile?s.sessionFile.split(/[/\\]/).pop()??s.sessionFile:S("desktop.sessionInfoInMemory")}),s.sessionFile?o("file",s.sessionFile):null]},"file")),n.push((0,r.jsxs)("div",{className:"session-stats-info-line",children:[(0,r.jsx)("span",{className:"session-stats-info-text",children:s.sessionId}),o("id",s.sessionId)]},"id"));let a=[[S("desktop.sessionInfoUser"),s.userMessages.toLocaleString()],[S("desktop.sessionInfoAssistant"),s.assistantMessages.toLocaleString()],[S("desktop.sessionInfoToolCalls"),s.toolCalls.toLocaleString()],[S("desktop.sessionInfoToolResults"),s.toolResults.toLocaleString()],[S("desktop.sessionInfoTotal"),s.totalMessages.toLocaleString()]],l=[[S("desktop.sessionInfoInput"),e.input.toLocaleString()],[S("desktop.sessionInfoOutput"),e.output.toLocaleString()]];e.cacheRead>0&&l.push([S("desktop.sessionInfoCacheRead"),e.cacheRead.toLocaleString()]),e.cacheWrite>0&&l.push([S("desktop.sessionInfoCacheWrite"),e.cacheWrite.toLocaleString()]),l.push([S("desktop.sessionInfoTotal"),e.total.toLocaleString()]);let d=s.costCNY??0,c=s.costUSD??0;if(d>0&&l.push([S("desktop.sessionInfoCostOfficial"),r8(d)]),c>0&&l.push([S("desktop.sessionInfoCost"),`$${c.toFixed(4)}`]),d<=0&&c<=0&&s.cost>0&&l.push([S("desktop.sessionInfoCost"),`$${s.cost.toFixed(4)}`]),t?.contextWindow&&null!==t.percent){let e=t.percent,o=t.tokens;l.push([S("desktop.sessionInfoContext"),`${null!==e?`${e.toFixed(1)}%`:"?"} ${null!==o?i$(o):"?"}/${i$(t.contextWindow)}`])}(s.totalActiveMs??0)>0&&l.push([S("desktop.sessionInfoActiveTime"),function(e){if(e<=0)return"0s";let t=Math.floor(e/1e3),o=Math.floor(t/3600),r=Math.floor(t%3600/60),n=t%60;return o>0?`${o}h ${r}m`:r>0?`${r}m ${n}s`:`${n}s`}(s.totalActiveMs)]);let p=j?j.costCNY>0?r8(j.costCNY):j.costUSD>0?`$${j.costUSD.toFixed(4)}`:null:null,u=(e,t)=>(0,r.jsxs)("div",{className:"session-stats-row",children:[(0,r.jsx)("div",{className:"session-stats-label",children:e}),(0,r.jsx)("div",{className:"session-stats-value",children:t})]},e);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"session-stats-info-block",children:n}),(0,r.jsxs)("div",{className:"session-stats-side-by-side",children:[(0,r.jsxs)("div",{className:"session-stats-column",children:[(0,r.jsx)("div",{className:"session-stats-section-title",children:S("desktop.sessionInfoMessages")}),(0,r.jsx)("div",{className:"session-stats-compact-grid",children:a.map(([e,t])=>u(e,t))})]}),(0,r.jsxs)("div",{className:"session-stats-column",children:[(0,r.jsx)("div",{className:"session-stats-section-title",children:S("desktop.sessionInfoTokens")}),(0,r.jsx)("div",{className:"session-stats-compact-grid",children:l.map(([e,t])=>u(e,t))})]}),j&&(0,r.jsxs)("div",{className:"session-stats-column",children:[(0,r.jsx)("div",{className:"session-stats-section-title",children:S("desktop.turnUsageTitle")}),(0,r.jsxs)("div",{className:"session-stats-compact-grid",children:[u(S("desktop.sessionInfoInput"),j.input.toLocaleString()),u(S("desktop.sessionInfoOutput"),j.output.toLocaleString()),j.cacheRead>0&&u(S("desktop.sessionInfoCacheRead"),j.cacheRead.toLocaleString()),p&&u(S("desktop.sessionInfoCost"),p)]})]})]})]})})()})})]})]})]})}var iG=o(68635);function iJ({scrollElementRef:e,items:t,estimateSize:o=120,overscan:s=8,virtualizerRef:i}){let a=(0,iG.Te)({count:t.length,getScrollElement:()=>e.current,estimateSize:(0,n.useCallback)(()=>o,[o]),overscan:s});a.shouldAdjustScrollPositionOnItemSizeChange=()=>!1,i&&(i.current=a);let l=(0,n.useRef)(!1),d=(0,n.useRef)(a);d.current=a,(0,n.useEffect)(()=>{l.current||0===t.length||e.current&&(l.current=!0,d.current.scrollToIndex(t.length-1,{align:"end"}))},[t.length,e]);let c=a.getVirtualItems();return(0,r.jsx)("div",{style:{position:"relative",width:"100%",minWidth:0,height:a.getTotalSize()},children:c.map(e=>(0,r.jsx)("div",{"data-index":e.index,ref:a.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",minWidth:0,overflow:"hidden",transform:`translateY(${e.start}px)`},children:t[e.index]},e.key))})}function iY(e){return e.replace(/<\/?[\w:-]+\b[^>]*>/g," ").replace(/&lt;\/?[\w:-]+\b[^&]*?&gt;/gi," ").replace(/\s+/g," ").trim()}function iX(e){return"user"===e.role||"assistant"===e.role&&(e.content??[]).some(e=>"text"===e.type||"thinking"===e.type||"toolCall"===e.type)}function iZ({messages:e,streamingMessage:t,scrollContainer:o,messageRefs:s,onWidthChange:i,virtualizer:a}){var l;let[d,c]=(0,n.useState)(0),[p,u]=(0,n.useState)(1),[h,g]=(0,n.useState)(!1),[m,f]=(0,n.useState)([]),[x,k]=(0,n.useState)(!1),[v,y]=(0,n.useState)(null),[b,w]=(0,n.useState)(0),j=(0,n.useRef)(!1),S=(0,n.useRef)(null),C=(0,n.useMemo)(()=>t?[...e,t]:e,[e,t]),T=(0,n.useRef)(C);T.current=C;let R=(0,n.useCallback)(()=>{let e=o.current;if(!e)return;let t=e.scrollHeight,r=e.clientHeight,n=t-r;g(n>20),n<=0?(c(0),u(1)):(c(e.scrollTop/n),u(r/t))},[o]),z=(0,n.useRef)(null),I=(0,n.useRef)([]),M=(0,n.useRef)(a);M.current=a;let P=(0,n.useCallback)(()=>{z.current||(z.current=setTimeout(()=>{z.current=null;let e=o.current;if(!e)return;let t=e.scrollHeight;if(t<=0)return;let r=[],n=T.current,i=M.current;if(i){if(0>=i.totalHeight())return;let e=0,o=new Set;for(let s=0;s<n.length;s++){let a=n[s];if("user"!==a.role&&"assistant"!==a.role)continue;let l=i.refToItemIndex(e);if(e+=1,void 0===l||o.has(l)||!iX(a))continue;o.add(l);let d=i.getOffsetForIndex(l),c=i.sizeFor(l);r.push({topRatio:d/t,heightRatio:Math.max(c/t,1/t),msg:a,index:r.length})}}else{let o=s.current,i=0;for(let s=0;s<n.length;s++){let a=n[s];if("user"!==a.role&&"assistant"!==a.role)continue;let l=o?.[i];if(i++,iX(a)&&l){let o=l.getBoundingClientRect(),n=e.getBoundingClientRect(),s=o.top-n.top+e.scrollTop,i=o.height;r.push({topRatio:s/t,heightRatio:i/t,msg:a,index:r.length})}}}let a=I.current;a.length===r.length&&r.every((e,t)=>1e-6>Math.abs(e.topRatio-a[t].topRatio)&&1e-6>Math.abs(e.heightRatio-a[t].heightRatio))||(I.current=r,f(r))},150))},[o,s]);(0,n.useEffect)(()=>{let e=o.current;if(e)return e.addEventListener("scroll",R,{passive:!0}),()=>e.removeEventListener("scroll",R)},[o,R]),(0,n.useEffect)(()=>{let e=o.current;if(!e)return;let t=()=>{R(),P()},r=new ResizeObserver(t);return r.observe(e),e.firstElementChild&&r.observe(e.firstElementChild),t(),()=>{r.disconnect(),z.current&&(clearTimeout(z.current),z.current=null)}},[o,P,R]),(0,n.useEffect)(()=>{let e=setTimeout(()=>{R(),P()},50);return()=>clearTimeout(e)},[e.length,P,R]);let E=(0,n.useCallback)(e=>{let t=o.current;if(!t)return;let r=t.scrollHeight-t.clientHeight;r<=0||(t.scrollTop=Math.max(0,Math.min(1-p,e))/(1-p)*r)},[o,p]),W=(0,n.useCallback)(e=>{if(!h)return;j.current=!0;let t=e.currentTarget.getBoundingClientRect(),o=(e.clientY-t.top)/t.height,r=o-d*(1-p),n=r>=0&&r<=p?r:p/2;E(o-n);let s=e=>{j.current&&E((e.clientY-t.top)/t.height-n)},i=()=>{j.current=!1,window.removeEventListener("mousemove",s),window.removeEventListener("mouseup",i)};window.addEventListener("mousemove",s),window.addEventListener("mouseup",i)},[h,p,d,E]);(0,n.useEffect)(()=>{if(!h)return void w(0);let e=S.current;if(!e)return;let t=()=>w(e.clientHeight),o=new ResizeObserver(t);return o.observe(e),t(),()=>o.disconnect()},[h]);let F=(0,n.useMemo)(()=>{if(b<=0)return[];let e=[];return m.map(t=>{let o=t.topRatio*b,r=Math.max(3,Math.min(46,t.heightRatio*b)),n=Math.max(0,o-r/2),s=Math.min(b,o+r/2),i=e.findIndex(e=>n>=e+1);return -1===i?(i=e.length,e.push(s)):e[i]=s,{...t,displayTopPx:o,lane:i}})},[m,b]),D=Math.max(18,4+5*(l=(0,n.useMemo)(()=>F.reduce((e,t)=>Math.max(e,t.lane+1),1),[F]))+(l-1)*1);if((0,n.useEffect)(()=>{i?.(h?D:18)},[D,i,h]),(0,n.useEffect)(()=>()=>i?.(18),[i]),!h)return null;let A=d*(1-p)*100,N=100*p,L=null!==v&&F.length>0?F.reduce((e,t)=>Math.abs(t.displayTopPx/b-v)<Math.abs(F[e].displayTopPx/b-v)?t.index:e,0):null,$=null===L?null:F.find(e=>e.index===L)??null;return(0,r.jsxs)("div",{ref:S,onMouseDown:W,onMouseEnter:()=>k(!0),onMouseLeave:()=>{k(!1),y(null)},onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();y((e.clientY-t.top)/t.height)},style:{width:D,flexShrink:0,position:"relative",cursor:"pointer",userSelect:"none",background:"transparent",overflow:"visible"},children:[(0,r.jsx)("div",{style:{position:"absolute",left:1,right:1,top:`${A}%`,height:`${N}%`,background:"color-mix(in srgb, var(--text-muted) 14%, transparent)",pointerEvents:"none",zIndex:1}}),F.map(e=>{let t=function(e){if("user"===e.role)return"var(--accent)";let t=e.content??[];return t.some(e=>"toolCall"===e.type&&e.error)?"var(--accent-red)":t.some(e=>"toolCall"===e.type)?"var(--accent-green)":"var(--text-dim)"}(e.msg),o=x&&$?.index===e.index,n="user"===e.msg.role,s=Math.max(3,Math.min(46,e.heightRatio*b)),i=2+6*e.lane;return(0,r.jsx)("div",{style:{position:"absolute",top:e.displayTopPx,transform:"translateY(-50%)",left:i,width:5,height:s,display:"flex",alignItems:"stretch",cursor:"pointer",zIndex:function(e){if("user"===e.role)return 6;let t=e.content??[];return t.some(e=>"toolCall"===e.type&&e.error)?5:t.some(e=>"text"===e.type&&!!e.text?.trim())?4:t.some(e=>"toolCall"===e.type)?3:2}(e.msg)},children:(0,r.jsx)("div",{style:{width:"100%",height:"100%",borderRadius:1,background:t,opacity:o?1:n?.92:.72,transition:"opacity 0.1s, filter 0.1s",filter:o?"brightness(1.2)":"none"}})},e.index)}),x&&$&&(()=>{let e=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??[],o=t.filter(e=>"text"===e.type).map(e=>e.text).join(" ");if(o)return iY(o).slice(0,200);let r=t.filter(e=>"thinking"===e.type).map(e=>iY(e.thinking??"")).filter(Boolean).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""}($.msg);if(!e)return null;let t=function(e){if("user"===e.role)return"var(--minimap-preview-user-bg)";let t=e.content??[];return t.some(e=>"toolCall"===e.type&&e.error)?"var(--minimap-preview-error-bg)":t.some(e=>"toolCall"===e.type)?"var(--minimap-preview-tool-bg)":"var(--minimap-preview-default-bg)"}($.msg),o=Math.max(1,Math.min(5,Math.floor(b/120))),n=15*o+4,s=Math.max(n/2,Math.min(b-n/2,$.displayTopPx));return(0,r.jsx)("div",{style:{position:"absolute",top:s,transform:"translateY(-50%)",right:"100%",marginRight:6,background:t,border:"none",borderRadius:4,padding:"2px 7px",width:220,zIndex:100,pointerEvents:"none"},children:(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text)",lineHeight:"15px",display:"-webkit-box",WebkitBoxOrient:"vertical",WebkitLineClamp:o,overflow:"hidden",overflowWrap:"anywhere"},children:e})})})()]})}function iQ(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function i0(e){return function(e,t={}){if("assistant"!==e.role)return e;let o=e.content;if(!Array.isArray(o))return e;let r=o.map(e=>(function(e,t={}){if(!iQ(e)||"toolCall"!==e.type)return null;let o={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},r=t.includeStreamingRawInput?function(e){if("string"==typeof e.rawInput)return e.rawInput;if("string"==typeof e.partialJson)return e.partialJson;if("string"==typeof e.partialArgs)return e.partialArgs;let t=iQ(e.customInput)?e.customInput:null,o=t&&"string"==typeof t.property?t.property:null,r=iQ(e.arguments)?e.arguments:null;return o&&r&&"string"==typeof r[o]?r[o]:void 0}(e):void 0;return void 0===r?o:{...o,rawInput:r}})(e,t)??e);return{...e,content:r}}(e)}class i1 extends Error{constructor(e,t,o,r){super(e),this.status=t,this.code=o,this.accepted=r,this.name="AgentCommandError"}}class i2 extends Error{constructor(e,t,o){super(e),this.commandType=t,this.timeoutMs=o,this.name="AgentCommandTimeoutError"}}let i4=new Set(["compact","bash"]);async function i6(e,t,o={}){let r,n=function(e,t){if(void 0!==t.timeoutMs)return t.timeoutMs;let o="string"==typeof e.type?e.type:"";return 3e4*!i4.has(o)}(t,o),s=n>0?new AbortController:void 0,i=s?setTimeout(()=>s.abort(),n):void 0;try{r=await fetch(`/api/agent/${encodeURIComponent(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),...s?{signal:s.signal}:{}})}catch(e){if(s?.signal.aborted)throw new i2(`Agent command "${String(t.type??"unknown")}" timed out after ${n}ms`,String(t.type??"unknown"),n);throw e}finally{i&&clearTimeout(i)}let a=await r.json().catch(()=>({}));if(!r.ok||a.error)throw new i1(a.error??`HTTP ${r.status}`,r.status,a.code,a.accepted);return a.data}var i8=o(14755);function i5(e){if(!e)return 0;let t=0;for(let o of e){let e=o.codePointAt(0)??0;e>=19968&&e<=40959||e>=13312&&e<=19903||e>=131072&&e<=173791||e>=12352&&e<=12447||e>=12448&&e<=12543||e>=44032&&e<=55215?t+=1:t+=.25}return Math.max(0,Math.round(t))}function i3(){return"u">typeof performance?performance.now():Date.now()}function i7(e,t){switch(t.type){case"start":return{isStreaming:!0,streamingMessage:null};case"update":return{isStreaming:!0,streamingMessage:t.message};case"end":case"reset":return{isStreaming:!1,streamingMessage:null};default:return e}}function i9(e){return e?"running_command"===e.phase||e.isBashRunning?{kind:"running_command"}:"waiting_model"===e.phase||e.isStreaming||e.isPromptRunning||e.isCompacting?{kind:"waiting_model"}:null:null}function ae(e,t){return e.length===t.length&&e.every((e,o)=>e===t[o])}function at(e){return{steering:e?.steering??[],followUp:e?.followUp??[]}}let ao=`You are in PLAN MODE. Work as a read-only planning assistant.
27
+ …`:u})}),c&&(0,r.jsx)("textarea",{ref:d,value:a,onChange:e=>l(e.target.value),placeholder:i("approval.reasonPlaceholder"),rows:2,style:{width:"100%",marginTop:10,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"8px 10px",color:"var(--text)",fontSize:12.5,outline:"none",fontFamily:"inherit",resize:"vertical"}})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6,padding:"10px 14px",borderTop:"1px solid var(--border)"},children:[(0,r.jsxs)("button",{type:"button",onClick:()=>s(!0),disabled:o,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,width:"100%",padding:"9px 14px",borderRadius:8,background:"var(--accent)",color:"#fff",border:"none",fontSize:12.5,fontWeight:650,cursor:o?"not-allowed":"pointer",transition:"opacity 0.12s"},onMouseEnter:e=>{o||(e.currentTarget.style.opacity="0.88")},onMouseLeave:e=>{e.currentTarget.style.opacity="1"},children:[(0,r.jsx)(m.S,{size:14,weight:"bold","aria-hidden":"true"}),i("approval.allow")]}),(0,r.jsxs)("button",{type:"button",onClick:()=>{p(e=>!e),c||requestAnimationFrame(()=>d.current?.focus())},disabled:o,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,width:"100%",padding:"9px 14px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12.5,fontWeight:550,cursor:o?"not-allowed":"pointer",transition:"background 0.12s"},onMouseEnter:e=>{o||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,r.jsx)(h.u,{size:13,"aria-hidden":"true"}),i(c?"approval.hideReason":"approval.denyWithReason")]}),(0,r.jsx)("button",{type:"button",onClick:()=>s(!1,a.trim()||void 0),disabled:o,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,width:"100%",padding:"8px 14px",borderRadius:8,background:"none",border:"none",color:"var(--text-muted)",fontSize:12,cursor:o?"not-allowed":"pointer"},onMouseEnter:e=>{o||(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:i("approval.deny")})]})]})})}let nM="pi:create-task-from-text",nP=null,nE="pi-process-display-mode-v2",nW="tabs",nF="pi-process-display-mode-change";function nD(){try{let e=window.sessionStorage.getItem(nE);return"timeline"===e||"tabs"===e?e:nW}catch{return nW}}function nA(e){return window.addEventListener(nF,e),()=>window.removeEventListener(nF,e)}function nN(){return nW}function nL(e,t){if(!e)return!1;let o=new Set(t.map(e=>e.toLowerCase()));return Object.keys(e).some(e=>o.has(e.toLowerCase()))}function n$(e,t){if(!e)return;let o=new Set(t.map(e=>e.toLowerCase()));for(let[t,r]of Object.entries(e)){if(!o.has(t.toLowerCase())||"string"!=typeof r)continue;let e=r.trim();if(e)return e}}function nH(e){return"object"==typeof e&&null!==e?e:{}}function nO(e){return"add"===e||"added"===e||"create"===e?"create":"delete"===e||"deleted"===e||"remove"===e||"removed"===e?"delete":"update"===e||"modified"===e||"edit"===e||"move"===e?"edit":void 0}function nB(e){if(0!==e.length)return 1===new Set(e).size?e[0]:"edit"}function nU(e){if(Array.isArray(e))return nB(e.map(e=>nO(nH(e).type||nH(e).status||nH(e).changeType)).filter(e=>!!e))}function n_(e){if(!e)return;let t=(e.match(/^\*\*\* Add File:/gm)||[]).length,o=(e.match(/^\*\*\* Delete File:/gm)||[]).length,r=(e.match(/^\*\*\* (Update File|Move to):/gm)||[]).length;if(t||o||r){let e=[];if(t)for(let o=0;o<t;o++)e.push("create");if(o)for(let t=0;t<o;t++)e.push("delete");if(r)for(let t=0;t<r;t++)e.push("edit");return nB(e)}return/^@@ -0,0 \+\d+/m.test(e)?"create":/^@@ -\d+(?:,\d+)? \+0,0/m.test(e)?"delete":void 0}function nq(e){let t=n$(e.args,["path","file","filePath","filepath"]);if(t)return t;let o=n$(e.metadata,["relativePath","filePath","filepath","path","file"]);if(o)return o;let r=n$(Array.isArray(e.metadata?.files)?nH(e.metadata.files[0]):{},["relativePath","filePath","filepath","path","file"]);if(r)return r}function nV(e){return e.split(/[\\/]/).filter(Boolean).pop()||e}let nK=new Set(["cd","chdir","pwd","echo","set","export","source",".","pushd","popd","dirs"]),nG=new Set(["timeout"]),nJ=new Set(["ls","dir","ll","la","l","tree","eza","exa"]),nY=new Set(["rg","grep","egrep","fgrep","ack","ag","ripgrep"]),nX=new Set(["find","fd","fdfind","locate","mlocate","glob"]),nZ=new Set(["cat","head","tail","less","more","bat","nl","wc"]),nQ=new Set(["curl","wget","fetch","http","xh","httpx"]),n0=new Set(["rm","del","rmdir","unlink","erase"]),n1=new Set(["cp","mv","copy","move","rename","ren"]);var n2=o(36705),n4=o(94366),n6=o(66129),n8=o(2152),n5=o(59304),n3=o(8727),n7=o(60721),n9=o(47208),se=o(95951),st=o(29886),so=o(86756);function sr(e,t){var o,r,n;let s,i,a,l,d,c,p,u,h,g="string"==typeof(l=e.input.label)&&l.trim()?l:e.toolName;if("error"===e.status)return{displayLabel:g,iconName:"warning",tone:void 0};let m=(d=[(r=o={toolName:e.toolName,label:"string"==typeof e.input.label?e.input.label:void 0,args:e.input,result:"string"==typeof e.result?e.result:void 0}).toolName,r.title,r.label].filter(Boolean).join("\n").toLowerCase(),c=nL(o.args,["path","file","filePath","filepath"]),p=nL(o.args,["content","oldString","old_string","newString","new_string","patch","diff","edits","text"]),u=nL(o.args,["command","cmd","script"]),h=nL(o.args,["pattern","query"]),u||/\b(bash|shell|terminal|command|run|exec|execute|python|node|npm|pnpm|yarn|cargo|go|pytest|test|build|make|git|docker|kubectl|curl|wget)\b/i.test(d)?"command_execution":/\b(todo|todowrite|todo_write|write_todo|task_list|task\s*list)\b/i.test(d)?"todo_update":/\b(edit|write|patch|apply|modify|replace|update|create|delete|remove|insert|rename|move)\b/i.test(d)||c&&p?"document_change":"ls"===(s=o.toolName.toLowerCase())||"list"===s||"dir"===s||s.startsWith("list_")||s.endsWith("_list")||s.includes("list_directory")||s.includes("list_dir")||/\b(ls|list\s*directory|list\s*dir|dir\s*list|listdir)\b/i.test(d)?"directory_list":"find"===(i=o.toolName.toLowerCase())||"glob"===i||"scan"===i||i.includes("file_search")||i.includes("file_find")||i.startsWith("find_")||i.startsWith("glob_")||i.startsWith("scan_")||/\b(find[_\s]*files?|file[_\s]*find|glob|scan[_\s]*files?)\b/i.test(d)?"file_find":/\b(grep|rg|search|semantic|fuzzy|ripgrep)\b/i.test(d)||(a=o.toolName.toLowerCase()).includes("grep")||a.includes("search")||a.includes("fuzzy")||a.includes("ripgrep")||h&&!p&&!u?"document_search":/\b(read|view|open|cat|show|display)\b/i.test(d)||c&&!p&&!u?"document_read":void 0),f="toolbox";if("document_change"===m){let o,r,s,i=(r=nH((o=(n={toolName:e.toolName,label:"string"==typeof e.input.label?e.input.label:void 0,args:e.input,result:"string"==typeof e.result?e.result:void 0}).metadata||{}).filediff),s=function(e){if(!e)return{};try{return nH(JSON.parse(e))}catch{return{}}}(n.result),nU(o.files)??nU(s.files)??nO(o.type||o.status||o.changeType)??(!1===o.exists?"create":void 0)??(!0===o.exists?"edit":void 0)??n_("string"==typeof o.diff?o.diff:"")??n_("string"==typeof o.patch?o.patch:"")??n_("string"==typeof r.patch?r.patch:"")??n_("string"==typeof n.args?.patchText?n.args.patchText:"")??function(e){if(!e)return;let t=e.split(/\r?\n/).map(e=>e.trim()).filter(e=>/^[ADM]\s+/.test(e));if(0!==t.length)return nB(t.map(e=>e.startsWith("A ")?"create":e.startsWith("D ")?"delete":"edit"))}(n.result)??function(e){if(!e)return;let t=e.trim().replace(/\s+/g," ").toLowerCase();return/^(?:rm|del|erase|unlink)\b/.test(t)||/^remove-item\b/.test(t)?"delete":/^mkdir\b/.test(t)?"create":void 0}("string"==typeof n.args?.command?n.args.command:void 0)??"edit");f="create"===i?"filePlus":"delete"===i?"trash":"pencilSimpleLine";let a=t("create"===i?"desktop.processStepFileCreate":"delete"===i?"desktop.processStepFileDelete":"desktop.processStepFileEdit"),l=nq({toolName:e.toolName,label:"string"==typeof e.input.label?e.input.label:void 0,args:e.input,result:"string"==typeof e.result?e.result:void 0});return l?{displayLabel:`${a} ${nV(l)}`,iconName:f,target:l,tone:m,typeLabel:a}:{displayLabel:`${a}: ${g}`.slice(0,100),iconName:f,tone:m,typeLabel:a}}if("document_read"===m){f="bookOpen";let o=t("desktop.processStepFileRead"),r=nq({toolName:e.toolName,label:"string"==typeof e.input.label?e.input.label:void 0,args:e.input,result:"string"==typeof e.result?e.result:void 0});return r?{displayLabel:`${o} ${nV(r)}`,iconName:f,target:r,tone:m,typeLabel:o}:{displayLabel:g,iconName:f,tone:m,typeLabel:o}}if("document_search"===m){f="magnifyingGlass";let o=t("desktop.processStepSearch"),r="string"==typeof e.input.pattern?e.input.pattern:"string"==typeof e.input.query?e.input.query:"";return r?{displayLabel:`${o} "${r.slice(0,60)}"`,iconName:f,tone:m,typeLabel:o}:{displayLabel:g,iconName:f,tone:m,typeLabel:o}}if("directory_list"===m){f="folder";let o=t("desktop.processStepList"),r=nq({toolName:e.toolName,label:"string"==typeof e.input.label?e.input.label:void 0,args:e.input,result:"string"==typeof e.result?e.result:void 0});return r?{displayLabel:`${o} ${nV(r)}`,iconName:f,target:r,tone:m,typeLabel:o}:{displayLabel:g,iconName:f,tone:m,typeLabel:o}}if("file_find"===m){f="magnifyingGlass";let o=t("desktop.processStepFind"),r="string"==typeof e.input.pattern?e.input.pattern:"string"==typeof e.input.glob?e.input.glob:"";return r?{displayLabel:`${o} "${r.slice(0,60)}"`,iconName:f,tone:m,typeLabel:o}:{displayLabel:g,iconName:f,tone:m,typeLabel:o}}if("command_execution"===m){let o="string"==typeof e.input.command?e.input.command:"string"==typeof e.input.cmd?e.input.cmd:"";if(o){let e=function(e){let t=e.split(/&&|\n|;(?!;)|(?<!\|)\|(?!\|)/),o=e.split(/\s+/)[0]?.replace(/^[.\\/]+/,"")||"sh";for(let e of t){var r;let t=(r=e.trim(),r.match(/"[^"]+"|'[^']+'|\S+/g)?.map(e=>e.replace(/^(["'])(.*)\1$/,"$2"))??[]);if(0===t.length)continue;let o=0;for(;o<t.length&&(nK.has(t[o].toLowerCase())||nG.has(t[o].toLowerCase()));){let e=t[o].toLowerCase();if((o+=1)<t.length&&["cd","chdir","pushd"].includes(e)&&(o+=1),"timeout"===e)for(;o<t.length&&(t[o].startsWith("-")||/^\d/.test(t[o]));)o++}if(o>=t.length)continue;let n=t[o].replace(/^[.\\/]+/,"").toLowerCase(),s=n.split(/[/\\]/).pop()||n,i=o+1;for(;i<t.length&&t[i].startsWith("-");)i+=1;let a=i<t.length?t[i]:void 0;if(nJ.has(s))return{kind:"list",binary:s,argument:a};if(nY.has(s))return{kind:"search",binary:s,argument:a};if(nX.has(s))return{kind:"find",binary:s,argument:a};if(nZ.has(s))return{kind:"read",binary:s,argument:a};if(nQ.has(s))return{kind:"fetch",binary:s,argument:a};if(n0.has(s))return{kind:"delete",binary:s,argument:a};if(n1.has(s))return{kind:"copy",binary:s,argument:a};return{kind:"run",binary:s,argument:a}}return{kind:"run",binary:o}}(o);if("list"===e.kind){f="folder";let o=t("desktop.processStepList"),r=e.argument?` ${e.argument}`:"";return{displayLabel:`${o}${r}`,iconName:f,tone:m,typeLabel:o}}if("search"===e.kind){f="magnifyingGlass";let o=t("desktop.processStepSearch"),r=e.argument?` "${e.argument.slice(0,60)}"`:"";return{displayLabel:`${o}${r}`,iconName:f,tone:m,typeLabel:o}}if("find"===e.kind){f="magnifyingGlass";let o=t("desktop.processStepFind"),r=e.argument?` "${e.argument.slice(0,60)}"`:"";return{displayLabel:`${o}${r}`,iconName:f,tone:m,typeLabel:o}}if("read"===e.kind){f="bookOpen";let o=t("desktop.processStepRead"),r=e.argument?` ${e.argument}`:"";return{displayLabel:`${o}${r}`,iconName:f,tone:m,typeLabel:o,target:e.argument||void 0}}if("fetch"===e.kind){f="download";let o=t("desktop.processStepFetch"),r=e.argument?` ${e.argument.slice(0,80)}`:"";return{displayLabel:`${o}${r}`,iconName:f,tone:m,typeLabel:o}}if("delete"===e.kind){f="trash";let o=t("desktop.processStepDelete"),r=e.argument?` ${e.argument}`:"";return{displayLabel:`${o}${r}`,iconName:f,tone:m,typeLabel:o}}if("copy"===e.kind){f="copy";let o=t("desktop.processStepCopy"),r=e.argument?` ${e.argument}`:"";return{displayLabel:`${o}${r}`,iconName:f,tone:m,typeLabel:o}}f="terminal";let r=t("desktop.processStepCommand"),n=e.argument?`${e.binary} ${e.argument.length>60?e.argument.slice(0,57)+"...":e.argument}`:e.binary;return{displayLabel:`${r} ${n}`,iconName:f,tone:m,typeLabel:r}}return{displayLabel:g,iconName:f="terminal",tone:m}}return"todo_update"===m?{displayLabel:g,iconName:f="checklist",tone:m,typeLabel:t("desktop.processStepTodo")}:{displayLabel:g,iconName:f,tone:m}}function sn({expanded:e}){return(0,r.jsx)(b.J,{size:12,className:`shrink-0 transition-all duration-150 ${e?"rotate-90":""}`})}function ss(e,t=14){switch(e){case"brain":return(0,r.jsx)(n2.$,{size:t});case"bookOpen":return(0,r.jsx)(n4.R,{size:t});case"magnifyingGlass":return(0,r.jsx)(u.$,{size:t});case"pencilSimpleLine":return(0,r.jsx)(n9.B,{size:t});case"filePlus":return(0,r.jsx)(G.u,{size:t});case"trash":return(0,r.jsx)(T.u,{size:t});case"folder":return(0,r.jsx)(n5.sj,{size:t});case"download":return(0,r.jsx)(E.e,{size:t});case"copy":return(0,r.jsx)(n8.t,{size:t});case"terminal":return(0,r.jsx)(st.k,{size:t});case"toolbox":default:return(0,r.jsx)(so.D,{size:t});case"image":return(0,r.jsx)(n3.x,{size:t});case"listBullets":case"checklist":return(0,r.jsx)(n7.j,{size:t});case"warning":case"circleX":return(0,r.jsx)(r0.M,{size:t})}}function si({step:e,ts:t}){if("thinking"===e.kind)return ss("brain");if("image"===e.kind)return ss("image");if("custom"===e.kind)return ss("listBullets");if("toolGroup"===e.kind)return ss(e.iconName);let{iconName:o}=sr(e.block,t);return ss(o)}function sa({targets:e,typeLabel:t,count:o,label:n}){if(0===e.length)return(0,r.jsx)("span",{className:"max-w-52 truncate",title:n,children:n});if(2===e.length)return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"shrink-0",children:t}),(0,r.jsx)(sl,{filePath:e[0]}),(0,r.jsx)(sl,{filePath:e[1]})]});let s=e[0].split(".").pop()?.toLowerCase()||"",i=[],a=new Set([s]);for(let t=1;t<e.length&&i.length<2;t++){let o=e[t].split(".").pop()?.toLowerCase()||"";a.has(o)||(a.add(o),i.push({key:e[t],node:ea(e[t],12)}))}return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"shrink-0",children:t}),i.length>0&&(0,r.jsx)("span",{className:"shrink-0 inline-flex gap-px",children:i.map(e=>(0,r.jsx)("span",{className:"inline-flex",children:e.node},e.key))}),(0,r.jsx)(sl,{filePath:e[0]}),(0,r.jsxs)("span",{className:"shrink-0 text-[10px] tabular-nums text-text-dim",children:["+",o-1]})]})}function sl({filePath:e}){let t=e.split(/[\\/]/).filter(Boolean).pop()||e;return(0,r.jsxs)("span",{className:"process-file-tag",title:e,children:[ea(e,12),(0,r.jsx)("span",{children:t})]})}function sd({mode:e}){return"timeline"===e?(0,r.jsx)(se.D,{size:14}):(0,r.jsx)(n6.j,{size:14})}function sc({step:e,cwd:t,onOpenFile:o,sessionId:n,ts:s,isStreaming:i}){let a;if("thinking"===e.kind)return(0,r.jsx)(sp,{blocks:e.blocks,cwd:t,onOpenFile:o,sessionId:n,isStreaming:i});if("tool"===e.kind)return(0,r.jsxs)("div",{className:"space-y-2",children:[e.leadBlocks.length>0&&(0,r.jsx)(sp,{blocks:e.leadBlocks,cwd:t,onOpenFile:o,sessionId:n,isStreaming:i}),(0,r.jsx)(na,{block:{type:"toolCall",toolCallId:e.block.toolCallId,toolName:e.block.toolName,input:e.block.input},result:e.block.result,duration:e.block.duration,processStyle:!0})]});if("toolGroup"===e.kind)return(0,r.jsx)("div",{className:"space-y-2",children:e.blocks.map((s,a)=>(0,r.jsxs)("div",{children:[e.leadBlocks[a]&&e.leadBlocks[a].length>0&&(0,r.jsx)("div",{className:"mb-2",children:(0,r.jsx)(sp,{blocks:e.leadBlocks[a],cwd:t,onOpenFile:o,sessionId:n,isStreaming:i})}),(0,r.jsx)(na,{block:{type:"toolCall",toolCallId:s.toolCallId,toolName:s.toolName,input:s.input},result:s.result,duration:s.duration,processStyle:!0})]},s.id))});if("custom"===e.kind)return(0,r.jsx)(ne,{message:e.block.message,cwd:t,onOpenFile:o,isStreaming:i});let l="url"===(a=e.block.source).type?a.url:a.data?`data:${a.media_type??"image/png"};base64,${a.data}`:void 0;return l?(0,r.jsx)("img",{src:l,alt:s("desktop.processOutput"),className:"max-h-72 max-w-full rounded border border-border object-contain"}):null}function sp({blocks:e,cwd:t,onOpenFile:o,sessionId:n,isStreaming:s}){return(0,r.jsx)("div",{className:"space-y-2 pr-2",children:e.map(e=>"text"===e.type?(0,r.jsx)(rM,{cwd:t,onOpenFile:o,className:"!text-text-dim",isStreaming:s,children:e.text},e.id):(0,r.jsx)(ns,{block:{type:"thinking",thinking:e.thinking,deferred:e.deferred},sessionId:n,entryId:e.origin.sourceEntryId,blockIndex:e.origin.sourceBlockIndex??0,contentOnly:!0,cwd:t,onOpenFile:o,className:"!text-text-dim",isStreaming:s},e.id))})}function su({blocks:e,isStreaming:t,defaultExpanded:o=!1,onAutoExpanded:s,cwd:i,onOpenFile:a,sessionId:l,tokenRate:d=null}){let c,{t:p}=(0,A.s)(),u=(0,n.useCallback)(e=>p(e),[p]),h=(0,n.useMemo)(()=>(function(e,t,o=!1){let r=[],n=[],s=()=>{0!==n.length&&(r.push({kind:"thinking",id:n.map(e=>e.id).join("+"),label:t("desktop.processStepThinking"),blocks:n}),n=[])};for(let o of e){if("thinking"===o.type||"text"===o.type){n.push(o);continue}if("toolCall"===o.type){let{displayLabel:e}=sr(o,t);r.push({kind:"tool",id:o.id,label:e,block:o,leadBlocks:n}),n=[];continue}s(),"custom"===o.type?r.push({kind:"custom",id:o.id,label:o.customType.replace(/[_-]+/g," ").replace(/\b\w/g,e=>e.toUpperCase()),block:o}):"image"===o.type&&r.push({kind:"image",id:o.id,label:t("desktop.processOutput"),block:o})}s();try{return function(e,t,o){if(e.length<2)return e;let r=[],n=0;for(;n<e.length;){let s,i=e[n];if("tool"!==i.kind||"error"===i.block.status){r.push(i),n++;continue}let a=sr(i.block,t).tone;if(!a){r.push(i),n++;continue}let l=n+1;for(;l<e.length&&"tool"===e[l].kind;){let o=e[l];if("error"===o.block.status||sr(o.block,t).tone!==a)break;l++}if(o&&l===e.length&&l>n+1&&l--,l-n<2){r.push(i),n++;continue}let d=e.slice(n,l),c=d.map(e=>sr(e.block,t)),p=c[0].iconName,u=c[0].typeLabel||"",h=d.map(e=>e.block),g=c.map(e=>e.displayLabel),m=c.map(e=>e.target||""),f=c.map(e=>{if(e.target)return nV(e.target);let t=e.displayLabel;return e.typeLabel&&t.startsWith(e.typeLabel+" ")?t.slice(e.typeLabel.length+1):t}),x=new Set,k=new Set,v=[],y=[];for(let e=0;e<f.length;e++){let t=f[e];x.has(t)||(x.add(t),v.push(t));let o=m[e];o&&!k.has(o)&&(k.add(o),y.push(o))}let b=d.length;s=2===b&&2===v.length?`${u} ${v[0]}, ${v[1]}`:1===v.length?1===b?`${u} ${v[0]}`:`${u} ${v[0]} \xd7${b}`:2===v.length?`${u} ${v[0]}, ${v[1]}`:`${u} ${v[0]} +${v.length-1}`,r.push({kind:"toolGroup",id:h.map(e=>e.id).join("+"),label:s,blocks:h,leadBlocks:d.map(e=>e.leadBlocks),iconName:p,tone:a,typeLabel:u,targetLabels:g,targets:y}),n=l}return r}(r,t,o)}catch(e){return console.error("[ProcessGroup] mergeConsecutiveToolSteps crashed:",e),r}})(e,u,t),[e,u,t]),[g,m]=(0,n.useState)(t||o),[f,x]=(0,n.useState)({}),{displayMode:k,setDisplayMode:v}={displayMode:(0,n.useSyncExternalStore)(nA,nD,nN),setDisplayMode:(0,n.useCallback)(e=>{try{window.sessionStorage.setItem(nE,e)}catch{}window.dispatchEvent(new Event(nF))},[])},[y,b]=(0,n.useState)(0),[w,j]=(0,n.useState)(!1),[S,C]=(0,n.useState)(!1),T=(0,n.useRef)(null),R=(0,n.useRef)(!1),z=(0,n.useRef)(!1),I=(0,n.useRef)(!1),M=(0,n.useRef)(!1),P=(0,n.useRef)(!1),E=(0,n.useRef)(0);(0,n.useEffect)(()=>{if(t){R.current=!0,z.current||m(!0);return}if(!R.current)return;P.current=!1,z.current=!1,x({}),m(!1);let e=window.setTimeout(()=>m(!1),300);return R.current=!1,()=>window.clearTimeout(e)},[t]),(0,n.useEffect)(()=>{if(o&&!t&&!M.current&&h.length>0){let e=h[h.length-1];M.current=!0,x({[e.id]:!0}),window.requestAnimationFrame(()=>s?.())}},[o,t,s,h]),(0,n.useEffect)(()=>{if(0===h.length)return;let e=h[h.length-1];b(e=>I.current&&e<h.length?e:h.length-1),t&&x(t=>!0===t[e.id]&&1===Object.keys(t).length?t:{[e.id]:!0})},[t,h]);let W=(0,n.useCallback)(()=>{let e=T.current;e&&(j(t=>{let o=e.scrollTop>0;return t===o?t:o}),C(t=>{let o=e.scrollHeight-e.scrollTop-e.clientHeight>1;return t===o?t:o}))},[]),F=(0,n.useCallback)(()=>{if(Date.now()<E.current)return;let e=T.current;e&&(P.current=e.scrollHeight-e.scrollTop-e.clientHeight>4)},[]);if((0,n.useEffect)(()=>{let e=T.current;if(!e||!g)return;let t=new ResizeObserver(W);return e.addEventListener("scroll",W,{passive:!0}),t.observe(e),e.firstElementChild&&t.observe(e.firstElementChild),W(),()=>{e.removeEventListener("scroll",W),t.disconnect()}},[y,g,k,t,f,h.length,W]),(0,n.useEffect)(()=>{let e=T.current;if(e&&g)return e.addEventListener("scroll",F,{passive:!0}),()=>e.removeEventListener("scroll",F)},[g,k,F]),(0,n.useEffect)(()=>{t&&T.current&&(P.current||(E.current=Date.now()+100,T.current.scrollTop=T.current.scrollHeight,W()))},[e,t,W]),0===h.length)return null;let D=h.reduce((e,t)=>"tool"===t.kind?e+1:"toolGroup"===t.kind?e+t.blocks.length:e,0),N=h.reduce((e,t)=>"tool"===t.kind&&"error"===t.block.status?e+1:"toolGroup"===t.kind?e+t.blocks.filter(e=>"error"===e.status).length:e,0),L=e.filter(e=>"thinking"===e.type||"text"===e.type).length,$=h.filter(e=>"custom"===e.kind).length,H=1===h.length&&"thinking"===h[0].kind&&!t,O=1===h.length&&("tool"===h[0].kind||"toolGroup"===h[0].kind)&&!t;if(t)c=p("desktop.processWorking");else if(H){let e=function(e){let t;if("thinking"===e.kind){for(let o of e.blocks)"thinking"===o.type&&"number"==typeof o.duration&&(t=(t??0)+o.duration);return t}}(h[0]);c=void 0!==e?p("desktop.processThoughtDone",{duration:e}):p("desktop.processThoughtDoneNoDuration")}else if(O){let e=h[0];if("toolGroup"===e.kind){let t=e.blocks.reduce((e,t)=>e+(t.duration??0),0);c=t>0?`${e.label} ${t}s`:e.label}else{let t=e.block,o=sr(t,u),r=t.duration;c=void 0!==r?`${o.displayLabel} ${r}s`:o.displayLabel}}else{let e=[];if(D){let t=1===D?p("desktop.processToolCount",{count:D}):p("desktop.processToolsCount",{count:D});e.push(N>0?t+p("desktop.processFailedCount",{failed:N}):t)}L&&e.push(1===L?p("desktop.processThoughtCount",{count:L}):p("desktop.processThoughtsCount",{count:L})),$&&e.push(1===$?p("desktop.processCustomCount",{count:$}):p("desktop.processCustomsCount",{count:$})),c=e.length>0?p("desktop.processUsed",{summary:e.join(" \xb7 ")}):p("desktop.processCompleted")}return(0,r.jsxs)("div",{className:"group/process relative mb-3 min-w-0",children:[(0,r.jsxs)("div",{className:"group/summary-row flex items-center justify-between",children:[(0,r.jsxs)("button",{type:"button",onClick:()=>m(e=>{let o=!e;return z.current=t&&!o,o}),className:"group/summary flex min-w-0 items-center gap-1.5 text-left text-sm leading-relaxed text-text-muted transition-colors hover:text-text","aria-expanded":g,children:[(0,r.jsx)("span",{className:"truncate",children:c}),t&&null!=d&&d>0&&(0,r.jsx)("span",{className:"shrink-0 text-xs tabular-nums text-text-dim",children:p("desktop.tokensPerSecond",{count:d>=10?String(Math.round(d)):d.toFixed(1)})}),(0,r.jsx)("span",{className:`opacity-0 transition-opacity group-hover/summary:opacity-60 ${g?"rotate-90":""}`,children:(0,r.jsx)(sn,{expanded:!1})})]}),!H&&(0,r.jsx)("button",{type:"button",onClick:()=>{v("timeline"===k?"tabs":"timeline"),m(!0)},className:`shrink-0 p-1 text-text-dim transition-colors hover:text-text group-hover/summary-row:opacity-100 pointer-events-none group-hover/summary-row:pointer-events-auto ${"timeline"===k?"opacity-60":"opacity-0"}`,title:"timeline"===k?p("desktop.processTabMode"):p("desktop.processTimelineMode"),children:(0,r.jsx)(sd,{mode:k})})]}),g&&(0,r.jsx)("div",{className:"overflow-hidden",children:H?(0,r.jsxs)("div",{className:"relative mt-2",children:[(0,r.jsx)("div",{ref:T,className:"max-h-[280px] overflow-y-auto pr-2",children:(0,r.jsx)(sc,{step:h[0],cwd:i,onOpenFile:a,sessionId:l,ts:u,isStreaming:t})}),w&&(0,r.jsx)("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 top-0 z-10 h-6 bg-gradient-to-b from-bg to-transparent"}),S&&(0,r.jsx)("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 bottom-0 z-10 h-6 bg-gradient-to-t from-bg to-transparent"})]}):"timeline"===k?(0,r.jsxs)("div",{className:"relative mt-2",children:[w&&(0,r.jsx)("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 top-0 z-10 h-6 bg-gradient-to-b from-bg to-transparent"}),S&&(0,r.jsx)("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 bottom-0 z-10 h-6 bg-gradient-to-t from-bg to-transparent"}),(0,r.jsx)("div",{ref:T,className:t?"max-h-[320px] overflow-y-auto":"",children:(0,r.jsxs)("div",{className:"relative ml-5 space-y-2",children:[(0,r.jsx)("div",{className:"absolute -left-3 -top-1.5 h-4 w-2 rounded-bl border-b border-l border-border"}),h.map((e,o)=>{let n=f[e.id]??!1,s="thinking"===e.kind?e.blocks.some(e=>"text"===e.type?e.text.trim().length>0:e.deferred||e.thinking.trim().length>0):"toolGroup"!==e.kind||e.blocks.length>0,d="tool"===e.kind&&"error"===e.block.status||"toolGroup"===e.kind&&e.blocks.some(e=>"error"===e.status),c="tool"===e.kind?sr(e.block,u):null,g="toolGroup"!==e.kind&&c?.target!==void 0&&c?.typeLabel!==void 0;return(0,r.jsxs)("div",{className:"group/step relative min-w-0",children:[o<h.length-1&&(0,r.jsx)("span",{className:"absolute bottom-[-9px] left-[7px] top-[22px] border-l border-border"}),(0,r.jsxs)("button",{type:"button",onClick:()=>s&&x(t=>({...t,[e.id]:!n})),className:`flex w-full min-w-0 items-center gap-1.5 text-left text-sm leading-relaxed transition-colors ${s?"cursor-pointer":"cursor-default"} ${d?"text-red-400 hover:text-red-300":"text-text-dim hover:text-text-muted"}`,children:[(0,r.jsx)("span",{className:"shrink-0",children:(0,r.jsx)(si,{step:e,ts:u})}),"toolGroup"===e.kind&&e.targets.length>0?(0,r.jsx)(sa,{targets:e.targets,typeLabel:e.typeLabel,count:e.blocks.length,label:e.label}):g?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"shrink-0",children:c.typeLabel}),(0,r.jsx)(sl,{filePath:c.target})]}):(0,r.jsx)("span",{className:"truncate",title:"toolGroup"===e.kind?e.targetLabels.join("\n"):void 0,children:e.label}),"tool"===e.kind&&void 0!==e.block.duration&&(0,r.jsxs)("span",{className:"shrink-0 text-[11px] tabular-nums text-text-dim",children:[e.block.duration,"s"]}),d&&(0,r.jsx)("span",{className:"shrink-0 text-[11px] font-medium text-red-400",children:p("desktop.processFailedStep")}),s&&(0,r.jsx)("span",{className:`ml-0.5 shrink-0 opacity-0 transition-opacity group-hover/step:opacity-50 ${n?"rotate-90":""}`,children:(0,r.jsx)(sn,{expanded:!1})})]}),n&&s&&(0,r.jsx)("div",{className:"ml-5 mt-1.5 overflow-hidden",children:(0,r.jsx)(sc,{step:e,cwd:i,onOpenFile:a,sessionId:l,ts:u,isStreaming:t})})]},e.id)})]})})]}):(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"mt-2 flex flex-wrap gap-1",children:h.map((e,o)=>{let n="tool"===e.kind&&"error"===e.block.status||"toolGroup"===e.kind&&e.blocks.some(e=>"error"===e.status),s="tool"===e.kind?sr(e.block,u):null,i="toolGroup"!==e.kind&&s?.target!==void 0&&s?.typeLabel!==void 0,a=t&&o===h.length-1,l=y===o;return(0,r.jsxs)("button",{type:"button",onClick:()=>{o===h.length-1&&t?(I.current=!1,P.current=!1):I.current=!0,b(o)},"data-has-file-target":i?"true":void 0,title:"toolGroup"===e.kind?e.targetLabels.join("\n"):void 0,className:`process-tab flex items-center gap-1 font-mono text-xs transition-colors ${l?n?"process-tab-error":"process-tab-active":"text-text-dim hover:text-text"}${a?" process-tab-streaming":""}`,children:[(0,r.jsx)(si,{step:e,ts:u}),"toolGroup"===e.kind&&e.targets.length>0?(0,r.jsx)(sa,{targets:e.targets,typeLabel:e.typeLabel,count:e.blocks.length,label:e.label}):i?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"shrink-0",children:s.typeLabel}),(0,r.jsx)(sl,{filePath:s.target})]}):(0,r.jsx)("span",{className:`truncate ${"toolGroup"===e.kind?"max-w-64":"max-w-52"}`,title:"toolGroup"===e.kind?e.targetLabels.join("\n"):void 0,children:e.label})]},e.id)})}),(0,r.jsxs)("div",{className:"relative mt-2",children:[(0,r.jsx)("div",{ref:T,className:"max-h-[280px] overflow-y-auto pr-2",children:h[y]&&(0,r.jsx)(sc,{step:h[y],cwd:i,onOpenFile:a,sessionId:l,ts:u,isStreaming:t})}),w&&(0,r.jsx)("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 top-0 z-10 h-6 bg-gradient-to-b from-bg to-transparent"}),S&&(0,r.jsx)("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 bottom-0 z-10 h-6 bg-gradient-to-t from-bg to-transparent"})]})]})})]})}let sh=new Map;function sg(e){var t;return{value:e.value,images:e.images.map(e=>({...e})),pastedBlocks:(t=e.pastedBlocks)?t.map(e=>({...e})):void 0}}function sm(e){let t=sh.get(e);return t?sg(t):null}function sf(e,t){if(!t.value&&0===t.images.length)return void sh.delete(e);for(sh.delete(e),sh.set(e,sg(t));sh.size>100;){let e=sh.keys().next().value;if(void 0===e)break;sh.delete(e)}}function sx(e){let t=e.trim();if(!t.startsWith("file://"))return t;try{let e=new URL(t),o=decodeURIComponent(e.pathname);return/^\/[a-zA-Z]:[\\/]/.test(o)?o=o.slice(1):e.host&&"localhost"!==e.host&&(o=`//${e.host}${o}`),o}catch{let e=t.replace(/^file:\/\/(localhost)?/,"");try{e=decodeURIComponent(e)}catch{}return/^\/[a-zA-Z]:[\\/]/.test(e)&&(e=e.slice(1)),e}}let sk=["text/uri-list","x-special/nautilus-clipboard","x-special/gnome-copied-files","x-special/mate-copied-files","x-special/xfce4-copied-files","application/x-kde-cutselection","public.file-url","text/x-moz-url","application/x-moz-file"];function sv(e){var t;if(!e||"object"!=typeof e||"image"!==e.type||"string"!=typeof e.data||"string"!=typeof e.mimeType||(t=e.mimeType,!/^image\/[A-Za-z0-9][A-Za-z0-9!#$&^_.+-]*$/.test(t)))return!1;let o=function(e){if(!e||e.length%4!=0)return null;let t=e.endsWith("==")?2:+!!e.endsWith("="),o=e.length-t,r=null;for(let t=0;t<o;t+=1){var n;let o=(n=e.charCodeAt(t))>=65&&n<=90?n-65:n>=97&&n<=122?n-97+26:n>=48&&n<=57?n-48+52:43===n?62:47===n?63:null;if(null===o)return null;r=o}for(let t=o;t<e.length;t+=1)if("="!==e[t])return null;return 2===t&&r%16!=0||1===t&&r%4!=0?null:e.length/4*3-t}(e.data);return null!==o&&o<=0xa00000}function sy(e){let t=/(?:^|\s)@"([^"\n]*)$/.exec(e);if(t)return{start:e.length-(t[1].length+2),query:t[1],quoted:!0};let o=/(?:^|\s)@([^\s"]*)$/.exec(e);return o?{start:e.length-(o[1].length+1),query:o[1],quoted:!1}:null}function sb(e){let t=0;for(let o=0;o<e.length;o++)"/"===e[o]&&t++;return t}function sw(e,t){if(!e)return!0;let o=0;for(let r=0;r<t.length&&o<e.length;r++)t[r]===e[o]&&o++;return o===e.length}function sj(e,t){let o=t?`${e}/`:e;return o.includes(" ")?`@"${o}" `:`@${o} `}var sS=o(23084),sC=o(70312),sT=o(37597),sR=o(49560),sz=o(21163),sI=o(4615),sM=o(25248),sP=o(58506),sE=o(41789),sW=o(87124),sF=o(65098),sD=o(93587);function sA(e,t,o){let s=({size:n=16,style:s})=>(0,r.jsxs)("svg",{fill:t.fill,fillRule:t.fillRule,height:n,style:{flex:"none",lineHeight:1,...s},viewBox:"0 0 24 24",width:n,xmlns:"http://www.w3.org/2000/svg",children:[(0,r.jsx)("title",{children:e}),o]});return s.displayName=`${e}Icon`,(0,n.memo)(s)}let sN=sA("Anthropic",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M13.827 3.52h3.603L24 20h-3.603l-6.57-16.48zm-7.258 0h3.767L16.906 20h-3.674l-1.343-3.461H5.017l-1.344 3.46H0L6.57 3.522zm4.132 9.959L8.453 7.687 6.205 13.48H10.7z"})})),sL=sA("OpenAI",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M9.205 8.658v-2.26c0-.19.072-.333.238-.428l4.543-2.616c.619-.357 1.356-.523 2.117-.523 2.854 0 4.662 2.212 4.662 4.566 0 .167 0 .357-.024.547l-4.71-2.759a.797.797 0 00-.856 0l-5.97 3.473zm10.609 8.8V12.06c0-.333-.143-.57-.429-.737l-5.97-3.473 1.95-1.118a.433.433 0 01.476 0l4.543 2.617c1.309.76 2.189 2.378 2.189 3.948 0 1.808-1.07 3.473-2.76 4.163zM7.802 12.703l-1.95-1.142c-.167-.095-.239-.238-.239-.428V5.899c0-2.545 1.95-4.472 4.591-4.472 1 0 1.927.333 2.712.928L8.23 5.067c-.285.166-.428.404-.428.737v6.898zM12 15.128l-2.795-1.57v-3.33L12 8.658l2.795 1.57v3.33L12 15.128zm1.796 7.23c-1 0-1.927-.332-2.712-.927l4.686-2.712c.285-.166.428-.404.428-.737v-6.898l1.974 1.142c.167.095.238.238.238.428v5.233c0 2.545-1.974 4.472-4.614 4.472zm-5.637-5.303l-4.544-2.617c-1.308-.761-2.188-2.378-2.188-3.948A4.482 4.482 0 014.21 6.327v5.423c0 .333.143.571.428.738l5.947 3.449-1.95 1.118a.432.432 0 01-.476 0zm-.262 3.9c-2.688 0-4.662-2.021-4.662-4.519 0-.19.024-.38.047-.57l4.686 2.71c.286.167.571.167.856 0l5.97-3.448v2.26c0 .19-.07.333-.237.428l-4.543 2.616c-.619.357-1.356.523-2.117.523zm5.899 2.83a5.947 5.947 0 005.827-4.756C22.287 18.339 24 15.84 24 13.296c0-1.665-.713-3.282-1.998-4.448.119-.5.19-.999.19-1.498 0-3.401-2.759-5.947-5.946-5.947-.642 0-1.26.095-1.88.31A5.962 5.962 0 0010.205 0a5.947 5.947 0 00-5.827 4.757C1.713 5.447 0 7.945 0 10.49c0 1.666.713 3.283 1.998 4.448-.119.5-.19 1-.19 1.499 0 3.401 2.759 5.946 5.946 5.946.642 0 1.26-.095 1.88-.309a5.96 5.96 0 004.162 1.713z"})})),s$=sA("Google",{},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{d:"M23 12.245c0-.905-.075-1.565-.236-2.25h-10.54v4.083h6.186c-.124 1.014-.797 2.542-2.294 3.569l-.021.136 3.332 2.53.23.022C21.779 18.417 23 15.593 23 12.245z",fill:"#4285F4"}),(0,r.jsx)("path",{d:"M12.225 23c3.03 0 5.574-.978 7.433-2.665l-3.542-2.688c-.948.648-2.22 1.1-3.891 1.1a6.745 6.745 0 01-6.386-4.572l-.132.011-3.465 2.628-.045.124C4.043 20.531 7.835 23 12.225 23z",fill:"#34A853"}),(0,r.jsx)("path",{d:"M5.84 14.175A6.65 6.65 0 015.463 12c0-.758.138-1.491.361-2.175l-.006-.147-3.508-2.67-.115.054A10.831 10.831 0 001 12c0 1.772.436 3.447 1.197 4.938l3.642-2.763z",fill:"#FBBC05"}),(0,r.jsx)("path",{d:"M12.225 5.253c2.108 0 3.529.892 4.34 1.638l3.167-3.031C17.787 2.088 15.255 1 12.225 1 7.834 1 4.043 3.469 2.197 7.062l3.63 2.763a6.77 6.77 0 016.398-4.572z",fill:"#EB4335"})]})),sH=sA("DeepSeek",{},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M23.748 4.482c-.254-.124-.364.113-.512.234-.051.039-.094.09-.137.136-.372.397-.806.657-1.373.626-.829-.046-1.537.214-2.163.848-.133-.782-.575-1.248-1.247-1.548-.352-.156-.708-.311-.955-.65-.172-.241-.219-.51-.305-.774-.055-.16-.11-.323-.293-.35-.2-.031-.278.136-.356.276-.313.572-.434 1.202-.422 1.84.027 1.436.633 2.58 1.838 3.393.137.093.172.187.129.323-.082.28-.18.552-.266.833-.055.179-.137.217-.329.14a5.526 5.526 0 01-1.736-1.18c-.857-.828-1.631-1.742-2.597-2.458a11.365 11.365 0 00-.689-.471c-.985-.957.13-1.743.388-1.836.27-.098.093-.432-.779-.428-.872.004-1.67.295-2.687.684a3.055 3.055 0 01-.465.137 9.597 9.597 0 00-2.883-.102c-1.885.21-3.39 1.102-4.497 2.623C.082 8.606-.231 10.684.152 12.85c.403 2.284 1.569 4.175 3.36 5.653 1.858 1.533 3.997 2.284 6.438 2.14 1.482-.085 3.133-.284 4.994-1.86.47.234.962.327 1.78.397.63.059 1.236-.03 1.705-.128.735-.156.684-.837.419-.961-2.155-1.004-1.682-.595-2.113-.926 1.096-1.296 2.746-2.642 3.392-7.003.05-.347.007-.565 0-.845-.004-.17.035-.237.23-.256a4.173 4.173 0 001.545-.475c1.396-.763 1.96-2.015 2.093-3.517.02-.23-.004-.467-.247-.588zM11.581 18c-2.089-1.642-3.102-2.183-3.52-2.16-.392.024-.321.471-.235.763.09.288.207.486.371.739.114.167.192.416-.113.603-.673.416-1.842-.14-1.897-.167-1.361-.802-2.5-1.86-3.301-3.307-.774-1.393-1.224-2.887-1.298-4.482-.02-.386.093-.522.477-.592a4.696 4.696 0 011.529-.039c2.132.312 3.946 1.265 5.468 2.774.868.86 1.525 1.887 2.202 2.891.72 1.066 1.494 2.082 2.48 2.914.348.292.625.514.891.677-.802.09-2.14.11-3.054-.614zm1-6.44a.306.306 0 01.415-.287.302.302 0 01.2.288.306.306 0 01-.31.307.303.303 0 01-.304-.308zm3.11 1.596c-.2.081-.399.151-.59.16a1.245 1.245 0 01-.798-.254c-.274-.23-.47-.358-.552-.758a1.73 1.73 0 01.016-.588c.07-.327-.008-.537-.239-.727-.187-.156-.426-.199-.688-.199a.559.559 0 01-.254-.078c-.11-.054-.2-.19-.114-.358.028-.054.16-.186.192-.21.356-.202.767-.136 1.146.016.352.144.618.408 1.001.782.391.451.462.576.685.914.176.265.336.537.445.848.067.195-.019.354-.25.452z",fill:"#4D6BFE"})})),sO=sA("Groq",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M12.036 2c-3.853-.035-7 3-7.036 6.781-.035 3.782 3.055 6.872 6.908 6.907h2.42v-2.566h-2.292c-2.407.028-4.38-1.866-4.408-4.23-.029-2.362 1.901-4.298 4.308-4.326h.1c2.407 0 4.358 1.915 4.365 4.278v6.305c0 2.342-1.944 4.25-4.323 4.279a4.375 4.375 0 01-3.033-1.252l-1.851 1.818A7 7 0 0012.029 22h.092c3.803-.056 6.858-3.083 6.879-6.816v-6.5C18.907 4.963 15.817 2 12.036 2z"})})),sB=sA("Mistral",{},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{d:"M3.428 3.4h3.429v3.428H3.428V3.4zm13.714 0h3.43v3.428h-3.43V3.4z",fill:"gold"}),(0,r.jsx)("path",{d:"M3.428 6.828h6.857v3.429H3.429V6.828zm10.286 0h6.857v3.429h-6.857V6.828z",fill:"#FFAF00"}),(0,r.jsx)("path",{d:"M3.428 10.258h17.144v3.428H3.428v-3.428z",fill:"#FF8205"}),(0,r.jsx)("path",{d:"M3.428 13.686h3.429v3.428H3.428v-3.428zm6.858 0h3.429v3.428h-3.429v-3.428zm6.856 0h3.43v3.428h-3.43v-3.428z",fill:"#FA500F"}),(0,r.jsx)("path",{d:"M0 17.114h10.286v3.429H0v-3.429zm13.714 0H24v3.429H13.714v-3.429z",fill:"#E10500"})]})),sU=sA("Moonshot",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M1.052 16.916l9.539 2.552a21.007 21.007 0 00.06 2.033l5.956 1.593a11.997 11.997 0 01-5.586.865l-.18-.016-.044-.004-.084-.009-.094-.01a11.605 11.605 0 01-.157-.02l-.107-.014-.11-.016a11.962 11.962 0 01-.32-.051l-.042-.008-.075-.013-.107-.02-.07-.015-.093-.019-.075-.016-.095-.02-.097-.023-.094-.022-.068-.017-.088-.022-.09-.024-.095-.025-.082-.023-.109-.03-.062-.02-.084-.025-.093-.028-.105-.034-.058-.019-.08-.026-.09-.031-.066-.024a6.293 6.293 0 01-.044-.015l-.068-.025-.101-.037-.057-.022-.08-.03-.087-.035-.088-.035-.079-.032-.095-.04-.063-.028-.063-.027a5.655 5.655 0 01-.041-.018l-.066-.03-.103-.047-.052-.024-.096-.046-.062-.03-.084-.04-.086-.044-.093-.047-.052-.027-.103-.055-.057-.03-.058-.032a6.49 6.49 0 01-.046-.026l-.094-.053-.06-.034-.051-.03-.072-.041-.082-.05-.093-.056-.052-.032-.084-.053-.061-.039-.079-.05-.07-.047-.053-.035a7.785 7.785 0 01-.054-.036l-.044-.03-.044-.03a6.066 6.066 0 01-.04-.028l-.057-.04-.076-.054-.069-.05-.074-.054-.056-.042-.076-.057-.076-.059-.086-.067-.045-.035-.064-.052-.074-.06-.089-.073-.046-.039-.046-.039a7.516 7.516 0 01-.043-.037l-.045-.04-.061-.053-.07-.062-.068-.06-.062-.058-.067-.062-.053-.05-.088-.084a13.28 13.28 0 01-.099-.097l-.029-.028-.041-.042-.069-.07-.05-.051-.05-.053a6.457 6.457 0 01-.168-.179l-.08-.088-.062-.07-.071-.08-.042-.049-.053-.062-.058-.068-.046-.056a7.175 7.175 0 01-.027-.033l-.045-.055-.066-.082-.041-.052-.05-.064-.02-.025a11.99 11.99 0 01-1.44-2.402zm-1.02-5.794l11.353 3.037a20.468 20.468 0 00-.469 2.011l10.817 2.894a12.076 12.076 0 01-1.845 2.005L.657 15.923l-.016-.046-.035-.104a11.965 11.965 0 01-.05-.153l-.007-.023a11.896 11.896 0 01-.207-.741l-.03-.126-.018-.08-.021-.097-.018-.081-.018-.09-.017-.084-.018-.094c-.026-.141-.05-.283-.071-.426l-.017-.118-.011-.083-.013-.102a12.01 12.01 0 01-.019-.161l-.005-.047a12.12 12.12 0 01-.034-2.145zm1.593-5.15l11.948 3.196c-.368.605-.705 1.231-1.01 1.875l11.295 3.022c-.142.82-.368 1.612-.668 2.365l-11.55-3.09L.124 10.26l.015-.1.008-.049.01-.067.015-.087.018-.098c.026-.148.056-.295.088-.442l.028-.124.02-.085.024-.097c.022-.09.045-.18.07-.268l.028-.102.023-.083.03-.1.025-.082.03-.096.026-.082.031-.095a11.896 11.896 0 011.01-2.232zm4.442-4.4L17.352 4.59a20.77 20.77 0 00-1.688 1.721l7.823 2.093c.267.852.442 1.744.513 2.665L2.106 5.213l.045-.065.027-.04.04-.055.046-.065.055-.076.054-.072.064-.086.05-.065.057-.073.055-.07.06-.074.055-.069.065-.077.054-.066.066-.077.053-.06.072-.082.053-.06.067-.074.054-.058.073-.078.058-.06.063-.067.168-.17.1-.098.059-.056.076-.071a12.084 12.084 0 012.272-1.677zM12.017 0h.097l.082.001.069.001.054.002.068.002.046.001.076.003.047.002.06.003.054.002.087.005.105.007.144.011.088.007.044.004.077.008.082.008.047.005.102.012.05.006.108.014.081.01.042.006.065.01.207.032.07.012.065.011.14.026.092.018.11.022.046.01.075.016.041.01L14.7.3l.042.01.065.015.049.012.071.017.096.024.112.03.113.03.113.032.05.015.07.02.078.024.073.023.05.016.05.016.076.025.099.033.102.036.048.017.064.023.093.034.11.041.116.045.1.04.047.02.06.024.041.018.063.026.04.018.057.025.11.048.1.046.074.035.075.036.06.028.092.046.091.045.102.052.053.028.049.026.046.024.06.033.041.022.052.029.088.05.106.06.087.051.057.034.053.032.096.059.088.055.098.062.036.024.064.041.084.056.04.027.062.042.062.043.023.017c.054.037.108.075.161.114l.083.06.065.048.056.043.086.065.082.064.04.03.05.041.086.069.079.065.085.071c.712.6 1.353 1.283 1.909 2.031L7.222.994l.062-.027.065-.028.081-.034.086-.035c.113-.045.227-.09.341-.131l.096-.035.093-.033.084-.03.096-.031c.087-.03.176-.058.264-.085l.091-.027.086-.025.102-.03.085-.023.1-.026L9.04.37l.09-.023.091-.022.095-.022.09-.02.098-.021.091-.02.095-.018.092-.018.1-.018.091-.016.098-.017.092-.014.097-.015.092-.013.102-.013.091-.012.105-.012.09-.01.105-.01c.093-.01.186-.018.28-.024l.106-.008.09-.005.11-.006.093-.004.1-.004.097-.002.099-.002.197-.002z"})})),s_=sA("Minimax",{},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("defs",{children:(0,r.jsxs)("linearGradient",{id:"pi-minimax-lobe-icons-minimax-_R_0_",x1:"0%",x2:"100.182%",y1:"50.057%",y2:"50.057%",children:[(0,r.jsx)("stop",{offset:"0%","stop-color":"#E2167E"}),(0,r.jsx)("stop",{offset:"100%","stop-color":"#FE603C"})]})}),(0,r.jsx)("path",{d:"M16.278 2c1.156 0 2.093.927 2.093 2.07v12.501a.74.74 0 00.744.709.74.74 0 00.743-.709V9.099a2.06 2.06 0 012.071-2.049A2.06 2.06 0 0124 9.1v6.561a.649.649 0 01-.652.645.649.649 0 01-.653-.645V9.1a.762.762 0 00-.766-.758.762.762 0 00-.766.758v7.472a2.037 2.037 0 01-2.048 2.026 2.037 2.037 0 01-2.048-2.026v-12.5a.785.785 0 00-.788-.753.785.785 0 00-.789.752l-.001 15.904A2.037 2.037 0 0113.441 22a2.037 2.037 0 01-2.048-2.026V18.04c0-.356.292-.645.652-.645.36 0 .652.289.652.645v1.934c0 .263.142.506.372.638.23.131.514.131.744 0a.734.734 0 00.372-.638V4.07c0-1.143.937-2.07 2.093-2.07zm-5.674 0c1.156 0 2.093.927 2.093 2.07v11.523a.648.648 0 01-.652.645.648.648 0 01-.652-.645V4.07a.785.785 0 00-.789-.78.785.785 0 00-.789.78v14.013a2.06 2.06 0 01-2.07 2.048 2.06 2.06 0 01-2.071-2.048V9.1a.762.762 0 00-.766-.758.762.762 0 00-.766.758v3.8a2.06 2.06 0 01-2.071 2.049A2.06 2.06 0 010 12.9v-1.378c0-.357.292-.646.652-.646.36 0 .653.29.653.646V12.9c0 .418.343.757.766.757s.766-.339.766-.757V9.099a2.06 2.06 0 012.07-2.048 2.06 2.06 0 012.071 2.048v8.984c0 .419.343.758.767.758.423 0 .766-.339.766-.758V4.07c0-1.143.937-2.07 2.093-2.07z",fill:"url(#pi-minimax-lobe-icons-minimax-_R_0_)","fill-rule":"nonzero"})]})),sq=sA("Fireworks",{},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{"clip-rule":"evenodd",d:"M14.8 5l-2.801 6.795L9.195 5H7.397l3.072 7.428a1.64 1.64 0 003.038.002L16.598 5H14.8zm1.196 10.352l5.124-5.244-.699-1.669-5.596 5.739a1.664 1.664 0 00-.343 1.807 1.642 1.642 0 001.516 1.012L16 17l8-.02-.699-1.669-7.303.041h-.002zM2.88 10.104l.699-1.669 5.596 5.739c.468.479.603 1.189.343 1.807a1.643 1.643 0 01-1.516 1.012l-8-.018-.002.002.699-1.669 7.303.042-5.122-5.246z",fill:"#5019C5","fill-rule":"evenodd"})})),sV=sA("HuggingFace",{},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{d:"M2.25 11.535c0-3.407 1.847-6.554 4.844-8.258a9.822 9.822 0 019.687 0c2.997 1.704 4.844 4.851 4.844 8.258 0 5.266-4.337 9.535-9.687 9.535S2.25 16.8 2.25 11.535z",fill:"#FF9D0B"}),(0,r.jsx)("path",{d:"M11.938 20.086c4.797 0 8.687-3.829 8.687-8.551 0-4.722-3.89-8.55-8.687-8.55-4.798 0-8.688 3.828-8.688 8.55 0 4.722 3.89 8.55 8.688 8.55z",fill:"#FFD21E"}),(0,r.jsx)("path",{d:"M11.875 15.113c2.457 0 3.25-2.156 3.25-3.263 0-.576-.393-.394-1.023-.089-.582.283-1.365.675-2.224.675-1.798 0-3.25-1.693-3.25-.586 0 1.107.79 3.263 3.25 3.263h-.003z",fill:"#FF323D"}),(0,r.jsx)("path",{d:"M14.76 9.21c.32.108.445.753.767.585.447-.233.707-.708.659-1.204a1.235 1.235 0 00-.879-1.059 1.262 1.262 0 00-1.33.394c-.322.384-.377.92-.14 1.36.153.283.638-.177.925-.079l-.002.003zm-5.887 0c-.32.108-.448.753-.768.585a1.226 1.226 0 01-.658-1.204c.048-.495.395-.913.878-1.059a1.262 1.262 0 011.33.394c.322.384.377.92.14 1.36-.152.283-.64-.177-.925-.079l.003.003zm1.12 5.34a2.166 2.166 0 011.325-1.106c.07-.02.144.06.219.171l.192.306c.069.1.139.175.209.175.074 0 .15-.074.223-.172l.205-.302c.08-.11.157-.188.234-.165.537.168.986.536 1.25 1.026.932-.724 1.275-1.905 1.275-2.633 0-.508-.306-.426-.81-.19l-.616.296c-.52.24-1.148.48-1.824.48-.676 0-1.302-.24-1.823-.48l-.589-.283c-.52-.248-.838-.342-.838.177 0 .703.32 1.831 1.187 2.56l.18.14z",fill:"#3A3B45"}),(0,r.jsx)("path",{d:"M17.812 10.366a.806.806 0 00.813-.8c0-.441-.364-.8-.813-.8a.806.806 0 00-.812.8c0 .442.364.8.812.8zm-11.624 0a.806.806 0 00.812-.8c0-.441-.364-.8-.812-.8a.806.806 0 00-.813.8c0 .442.364.8.813.8zM4.515 13.073c-.405 0-.765.162-1.017.46a1.455 1.455 0 00-.333.925 1.801 1.801 0 00-.485-.074c-.387 0-.737.146-.985.409a1.41 1.41 0 00-.2 1.722 1.302 1.302 0 00-.447.694c-.06.222-.12.69.2 1.166a1.267 1.267 0 00-.093 1.236c.238.533.81.958 1.89 1.405l.24.096c.768.3 1.473.492 1.478.494.89.243 1.808.375 2.732.394 1.465 0 2.513-.443 3.115-1.314.93-1.342.842-2.575-.274-3.763l-.151-.154c-.692-.684-1.155-1.69-1.25-1.912-.195-.655-.71-1.383-1.562-1.383-.46.007-.889.233-1.15.605-.25-.31-.495-.553-.715-.694a1.87 1.87 0 00-.993-.312zm14.97 0c.405 0 .767.162 1.017.46.216.262.333.588.333.925.158-.047.322-.071.487-.074.388 0 .738.146.985.409a1.41 1.41 0 01.2 1.722c.22.178.377.422.445.694.06.222.12.69-.2 1.166.244.37.279.836.093 1.236-.238.533-.81.958-1.889 1.405l-.239.096c-.77.3-1.475.492-1.48.494-.89.243-1.808.375-2.732.394-1.465 0-2.513-.443-3.115-1.314-.93-1.342-.842-2.575.274-3.763l.151-.154c.695-.684 1.157-1.69 1.252-1.912.195-.655.708-1.383 1.56-1.383.46.007.889.233 1.15.605.25-.31.495-.553.718-.694.244-.162.523-.265.814-.3l.176-.012z",fill:"#FF9D0B"}),(0,r.jsx)("path",{d:"M9.785 20.132c.688-.994.638-1.74-.305-2.667-.945-.928-1.495-2.288-1.495-2.288s-.205-.788-.672-.714c-.468.074-.81 1.25.17 1.971.977.721-.195 1.21-.573.534-.375-.677-1.405-2.416-1.94-2.751-.532-.332-.907-.148-.782.541.125.687 2.357 2.35 2.14 2.707-.218.362-.983-.42-.983-.42S2.953 14.9 2.43 15.46c-.52.558.398 1.026 1.7 1.803 1.308.778 1.41.985 1.225 1.28-.187.295-3.07-2.1-3.34-1.083-.27 1.011 2.943 1.304 2.745 2.006-.2.7-2.265-1.324-2.685-.537-.425.79 2.913 1.718 2.94 1.725 1.075.276 3.813.859 4.77-.522zm4.432 0c-.687-.994-.64-1.74.305-2.667.943-.928 1.493-2.288 1.493-2.288s.205-.788.675-.714c.465.074.807 1.25-.17 1.971-.98.721.195 1.21.57.534.377-.677 1.407-2.416 1.94-2.751.532-.332.91-.148.782.541-.125.687-2.355 2.35-2.137 2.707.215.362.98-.42.98-.42S21.05 14.9 21.57 15.46c.52.558-.395 1.026-1.7 1.803-1.308.778-1.408.985-1.225 1.28.187.295 3.07-2.1 3.34-1.083.27 1.011-2.94 1.304-2.743 2.006.2.7 2.263-1.324 2.685-.537.423.79-2.912 1.718-2.94 1.725-1.077.276-3.815.859-4.77-.522z",fill:"#FFD21E"})]})),sK=sA("Cerebras",{fill:"currentColor"},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{"clip-rule":"evenodd",d:"M14.121 2.701a9.299 9.299 0 000 18.598V22.7c-5.91 0-10.7-4.791-10.7-10.701S8.21 1.299 14.12 1.299V2.7zm4.752 3.677A7.353 7.353 0 109.42 17.643l-.901 1.074a8.754 8.754 0 01-1.08-12.334 8.755 8.755 0 0112.335-1.08l-.901 1.075zm-2.255.844a5.407 5.407 0 00-5.048 9.563l-.656 1.24a6.81 6.81 0 016.358-12.043l-.654 1.24zM14.12 8.539a3.46 3.46 0 100 6.922v1.402a4.863 4.863 0 010-9.726v1.402z",fill:"#F15A29","fill-rule":"evenodd"}),(0,r.jsx)("path",{d:"M15.407 10.836a2.24 2.24 0 00-.51-.409 1.084 1.084 0 00-.544-.152c-.255 0-.483.047-.684.14a1.58 1.58 0 00-.84.912c-.074.203-.11.416-.11.631 0 .218.036.43.11.631a1.594 1.594 0 00.84.913c.2.093.43.14.684.14.216 0 .417-.046.602-.135.188-.09.35-.225.475-.392l.928 1.006c-.14.14-.3.261-.482.363a3.367 3.367 0 01-1.083.38c-.17.026-.317.04-.44.04a3.315 3.315 0 01-1.182-.21 2.825 2.825 0 01-.961-.597 2.816 2.816 0 01-.644-.929 2.987 2.987 0 01-.238-1.21c0-.444.08-.847.238-1.21.15-.35.368-.666.643-.929.278-.261.605-.464.962-.596a3.315 3.315 0 011.182-.21c.355 0 .712.068 1.072.204.361.138.685.36.944.649l-.962.97z"})]})),sG=sA("OpenRouter",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M18.654 3.87a5.087 5.087 0 110 10.174L23.7 19.09c.64.641.187 1.737-.72 1.737H8.48a8.479 8.479 0 010-16.958h10.175zM8.479 7.26a5.087 5.087 0 100 10.176 5.087 5.087 0 000-10.175z"})})),sJ=sA("XAI",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M6.469 8.776L16.512 23h-4.464L2.005 8.776H6.47zm-.004 7.9l2.233 3.164L6.467 23H2l4.465-6.324zM22 2.582V23h-3.659V7.764L22 2.582zM22 1l-9.952 14.095-2.233-3.163L17.533 1H22z"})})),sY=sA("Cloudflare",{},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{d:"M16.493 17.4c.135-.52.08-.983-.161-1.338-.215-.328-.592-.519-1.05-.519l-8.663-.109a.148.148 0 01-.135-.082c-.027-.054-.027-.109-.027-.163.027-.082.108-.164.189-.164l8.744-.11c1.05-.054 2.153-.9 2.556-1.937l.511-1.31c.027-.055.027-.11.027-.164C17.92 8.91 15.66 7 12.942 7c-2.503 0-4.628 1.638-5.381 3.903a2.432 2.432 0 00-1.803-.491c-1.21.109-2.153 1.092-2.287 2.32-.027.328 0 .628.054.9C1.56 13.688 0 15.326 0 17.319c0 .19.027.355.027.545 0 .082.08.137.161.137h15.983c.08 0 .188-.055.215-.164l.107-.437",fill:"#F38020"}),(0,r.jsx)("path",{d:"M19.238 11.75h-.242c-.054 0-.108.054-.135.109l-.35 1.2c-.134.52-.08.983.162 1.338.215.328.592.518 1.05.518l1.855.11c.054 0 .108.027.135.082.027.054.027.109.027.163-.027.082-.108.164-.188.164l-1.91.11c-1.05.054-2.153.9-2.557 1.937l-.134.355c-.027.055.026.137.107.137h6.592c.081 0 .162-.055.162-.137.107-.41.188-.846.188-1.31-.027-2.62-2.153-4.777-4.762-4.777",fill:"#FCAD32"})]})),sX=sA("Vercel",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M12 0l12 20.785H0L12 0z"})})),sZ=sA("GithubCopilot",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M19.245 5.364c1.322 1.36 1.877 3.216 2.11 5.817.622 0 1.2.135 1.592.654l.73.964c.21.278.323.61.323.955v2.62c0 .339-.173.669-.453.868C20.239 19.602 16.157 21.5 12 21.5c-4.6 0-9.205-2.583-11.547-4.258-.28-.2-.452-.53-.453-.868v-2.62c0-.345.113-.679.321-.956l.73-.963c.392-.517.974-.654 1.593-.654l.029-.297c.25-2.446.81-4.213 2.082-5.52 2.461-2.54 5.71-2.851 7.146-2.864h.198c1.436.013 4.685.323 7.146 2.864zm-7.244 4.328c-.284 0-.613.016-.962.05-.123.447-.305.85-.57 1.108-1.05 1.023-2.316 1.18-2.994 1.18-.638 0-1.306-.13-1.851-.464-.516.165-1.012.403-1.044.996a65.882 65.882 0 00-.063 2.884l-.002.48c-.002.563-.005 1.126-.013 1.69.002.326.204.63.51.765 2.482 1.102 4.83 1.657 6.99 1.657 2.156 0 4.504-.555 6.985-1.657a.854.854 0 00.51-.766c.03-1.682.006-3.372-.076-5.053-.031-.596-.528-.83-1.046-.996-.546.333-1.212.464-1.85.464-.677 0-1.942-.157-2.993-1.18-.266-.258-.447-.661-.57-1.108-.32-.032-.64-.049-.96-.05zm-2.525 4.013c.539 0 .976.426.976.95v1.753c0 .525-.437.95-.976.95a.964.964 0 01-.976-.95v-1.752c0-.525.437-.951.976-.951zm5 0c.539 0 .976.426.976.95v1.753c0 .525-.437.95-.976.95a.964.964 0 01-.976-.95v-1.752c0-.525.437-.951.976-.951zM7.635 5.087c-1.05.102-1.935.438-2.385.906-.975 1.037-.765 3.668-.21 4.224.405.394 1.17.657 1.995.657h.09c.649-.013 1.785-.176 2.73-1.11.435-.41.705-1.433.675-2.47-.03-.834-.27-1.52-.63-1.813-.39-.336-1.275-.482-2.265-.394zm6.465.394c-.36.292-.6.98-.63 1.813-.03 1.037.24 2.06.675 2.47.968.957 2.136 1.104 2.776 1.11h.044c.825 0 1.59-.263 1.995-.657.555-.556.765-3.187-.21-4.224-.45-.468-1.335-.804-2.385-.906-.99-.088-1.875.058-2.265.394zM12 7.615c-.24 0-.525.015-.84.044.03.16.045.336.06.526l-.001.159a2.94 2.94 0 01-.014.25c.225-.022.425-.027.612-.028h.366c.187 0 .387.006.612.028-.015-.146-.015-.277-.015-.409.015-.19.03-.365.06-.526a9.29 9.29 0 00-.84-.044z"})})),sQ=sA("Aws",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{d:"M6.763 11.212c0 .296.032.535.088.71.064.176.144.368.256.576.04.063.056.127.056.183 0 .08-.048.16-.152.24l-.503.335a.383.383 0 01-.208.072c-.08 0-.16-.04-.239-.112a2.47 2.47 0 01-.287-.375 6.18 6.18 0 01-.248-.471c-.622.734-1.405 1.101-2.347 1.101-.67 0-1.205-.191-1.596-.574-.39-.384-.59-.894-.59-1.533 0-.678.24-1.23.726-1.644.487-.415 1.133-.623 1.955-.623.272 0 .551.024.846.064.296.04.6.104.918.176v-.583c0-.607-.127-1.03-.375-1.277-.255-.248-.686-.367-1.3-.367-.28 0-.568.031-.863.103-.295.072-.583.16-.862.272a2.4 2.4 0 01-.28.104.488.488 0 01-.127.023c-.112 0-.168-.08-.168-.247v-.391c0-.128.016-.224.056-.28a.597.597 0 01.224-.167 4.577 4.577 0 011.005-.36 4.84 4.84 0 011.246-.151c.95 0 1.644.216 2.091.647.44.43.662 1.085.662 1.963v2.586h.016zm-3.24 1.214c.263 0 .534-.048.822-.144a1.78 1.78 0 00.758-.51 1.27 1.27 0 00.272-.512c.047-.191.08-.423.08-.694v-.335a6.66 6.66 0 00-.735-.136 6.02 6.02 0 00-.75-.048c-.535 0-.926.104-1.19.32-.263.215-.39.518-.39.917 0 .375.095.655.295.846.191.2.47.296.838.296zm6.41.862c-.144 0-.24-.024-.304-.08-.064-.048-.12-.16-.168-.311L7.586 6.726a1.398 1.398 0 01-.072-.32c0-.128.064-.2.191-.2h.783c.151 0 .255.025.31.08.065.048.113.16.16.312l1.342 5.284 1.245-5.284c.04-.16.088-.264.151-.312a.549.549 0 01.32-.08h.638c.152 0 .256.025.32.08.063.048.12.16.151.312l1.261 5.348 1.381-5.348c.048-.16.104-.264.16-.312a.52.52 0 01.311-.08h.743c.127 0 .2.065.2.2 0 .04-.009.08-.017.128a1.137 1.137 0 01-.056.2l-1.923 6.17c-.048.16-.104.263-.168.311a.51.51 0 01-.303.08h-.687c-.15 0-.255-.024-.32-.08-.063-.056-.119-.16-.15-.32L12.32 7.747l-1.23 5.14c-.04.16-.087.264-.15.32-.065.056-.177.08-.32.08l-.686.001zm10.256.215c-.415 0-.83-.048-1.229-.143-.399-.096-.71-.2-.918-.32-.128-.071-.215-.151-.247-.223a.563.563 0 01-.048-.224v-.407c0-.167.064-.247.183-.247.048 0 .096.008.144.024.048.016.12.048.2.08.271.12.566.215.878.279.32.064.63.096.95.096.502 0 .894-.088 1.165-.264a.86.86 0 00.415-.758.777.777 0 00-.215-.559c-.144-.151-.416-.287-.807-.415l-1.157-.36c-.583-.183-1.014-.454-1.277-.813a1.902 1.902 0 01-.4-1.158c0-.335.073-.63.216-.886.144-.255.335-.479.575-.654.24-.184.51-.32.83-.415.32-.096.655-.136 1.006-.136.175 0 .36.008.535.032.183.024.35.056.518.088.16.04.312.08.455.127.144.048.256.096.336.144a.69.69 0 01.24.2.43.43 0 01.071.263v.375c0 .168-.064.256-.184.256a.83.83 0 01-.303-.096 3.652 3.652 0 00-1.532-.311c-.455 0-.815.071-1.062.223-.248.152-.375.383-.375.71 0 .224.08.416.24.567.16.152.454.304.877.44l1.134.358c.574.184.99.44 1.237.767.247.327.367.702.367 1.117 0 .343-.072.655-.207.926a2.157 2.157 0 01-.583.703c-.248.2-.543.343-.886.447-.36.111-.734.167-1.142.167z"}),(0,r.jsx)("path",{d:"M.378 15.475c3.384 1.963 7.56 3.153 11.877 3.153 2.914 0 6.114-.607 9.06-1.852.44-.2.814.287.383.607-2.626 1.94-6.442 2.969-9.722 2.969-4.598 0-8.74-1.7-11.87-4.526-.247-.223-.024-.527.272-.351zm23.531-.2c.287.36-.08 2.826-1.485 4.007-.215.184-.423.088-.327-.151l.175-.439c.343-.88.802-2.198.52-2.555-.336-.43-2.22-.207-3.074-.103-.255.032-.295-.192-.063-.36 1.5-1.053 3.967-.75 4.254-.399z",fill:"#F90"})]})),s0=sA("Azure",{},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{d:"M7.242 1.613A1.11 1.11 0 018.295.857h6.977L8.03 22.316a1.11 1.11 0 01-1.052.755h-5.43a1.11 1.11 0 01-1.053-1.466L7.242 1.613z",fill:"url(#pi-azure-lobe-icons-azure-0-_R_0_)"}),(0,r.jsx)("path",{d:"M18.397 15.296H7.4a.51.51 0 00-.347.882l7.066 6.595c.206.192.477.298.758.298h6.226l-2.706-7.775z",fill:"#0078D4"}),(0,r.jsx)("path",{d:"M15.272.857H7.497L0 23.071h7.775l1.596-4.73 5.068 4.73h6.665l-2.707-7.775h-7.998L15.272.857z",fill:"url(#pi-azure-lobe-icons-azure-1-_R_0_)"}),(0,r.jsx)("path",{d:"M17.193 1.613a1.11 1.11 0 00-1.052-.756h-7.81.035c.477 0 .9.304 1.052.756l6.748 19.992a1.11 1.11 0 01-1.052 1.466h-.12 7.895a1.11 1.11 0 001.052-1.466L17.193 1.613z",fill:"url(#pi-azure-lobe-icons-azure-2-_R_0_)"}),(0,r.jsxs)("defs",{children:[(0,r.jsxs)("linearGradient",{gradientUnits:"userSpaceOnUse",id:"pi-azure-lobe-icons-azure-0-_R_0_",x1:"8.247",x2:"1.002",y1:"1.626",y2:"23.03",children:[(0,r.jsx)("stop",{"stop-color":"#114A8B"}),(0,r.jsx)("stop",{offset:"1","stop-color":"#0669BC"})]}),(0,r.jsxs)("linearGradient",{gradientUnits:"userSpaceOnUse",id:"pi-azure-lobe-icons-azure-1-_R_0_",x1:"14.042",x2:"12.324",y1:"15.302",y2:"15.888",children:[(0,r.jsx)("stop",{"stop-opacity":".3"}),(0,r.jsx)("stop",{offset:".071","stop-opacity":".2"}),(0,r.jsx)("stop",{offset:".321","stop-opacity":".1"}),(0,r.jsx)("stop",{offset:".623","stop-opacity":".05"}),(0,r.jsx)("stop",{offset:"1","stop-opacity":"0"})]}),(0,r.jsxs)("linearGradient",{gradientUnits:"userSpaceOnUse",id:"pi-azure-lobe-icons-azure-2-_R_0_",x1:"12.841",x2:"20.793",y1:"1.626",y2:"22.814",children:[(0,r.jsx)("stop",{"stop-color":"#3CCBF4"}),(0,r.jsx)("stop",{offset:"1","stop-color":"#2892DF"})]})]})]})),s1=sA("Kimi",{},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{d:"M21.846 0a1.923 1.923 0 110 3.846H20.15a.226.226 0 01-.227-.226V1.923C19.923.861 20.784 0 21.846 0z",fill:"#1783FF"}),(0,r.jsx)("path",{d:"M11.065 11.199l7.257-7.2c.137-.136.06-.41-.116-.41H14.3a.164.164 0 00-.117.051l-7.82 7.756c-.122.12-.302.013-.302-.179V3.82c0-.127-.083-.23-.185-.23H3.186c-.103 0-.186.103-.186.23V19.77c0 .128.083.23.186.23h2.69c.103 0 .186-.102.186-.23v-3.25c0-.069.025-.135.069-.178l2.424-2.406a.158.158 0 01.205-.023l6.484 4.772a7.677 7.677 0 003.453 1.283c.108.012.2-.095.2-.23v-3.06c0-.117-.07-.212-.164-.227a5.028 5.028 0 01-2.027-.807l-5.613-4.064c-.117-.078-.132-.279-.028-.381z",fill:"#fff"})]})),s2=sA("Qwen",{},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{d:"M12.604 1.34c.393.69.784 1.382 1.174 2.075a.18.18 0 00.157.091h5.552c.174 0 .322.11.446.327l1.454 2.57c.19.337.24.478.024.837-.26.43-.513.864-.76 1.3l-.367.658c-.106.196-.223.28-.04.512l2.652 4.637c.172.301.111.494-.043.77-.437.785-.882 1.564-1.335 2.34-.159.272-.352.375-.68.37-.777-.016-1.552-.01-2.327.016a.099.099 0 00-.081.05 575.097 575.097 0 01-2.705 4.74c-.169.293-.38.363-.725.364-.997.003-2.002.004-3.017.002a.537.537 0 01-.465-.271l-1.335-2.323a.09.09 0 00-.083-.049H4.982c-.285.03-.553-.001-.805-.092l-1.603-2.77a.543.543 0 01-.002-.54l1.207-2.12a.198.198 0 000-.197 550.951 550.951 0 01-1.875-3.272l-.79-1.395c-.16-.31-.173-.496.095-.965.465-.813.927-1.625 1.387-2.436.132-.234.304-.334.584-.335a338.3 338.3 0 012.589-.001.124.124 0 00.107-.063l2.806-4.895a.488.488 0 01.422-.246c.524-.001 1.053 0 1.583-.006L11.704 1c.341-.003.724.032.9.34zm-3.432.403a.06.06 0 00-.052.03L6.254 6.788a.157.157 0 01-.135.078H3.253c-.056 0-.07.025-.041.074l5.81 10.156c.025.042.013.062-.034.063l-2.795.015a.218.218 0 00-.2.116l-1.32 2.31c-.044.078-.021.118.068.118l5.716.008c.046 0 .08.02.104.061l1.403 2.454c.046.081.092.082.139 0l5.006-8.76.783-1.382a.055.055 0 01.096 0l1.424 2.53a.122.122 0 00.107.062l2.763-.02a.04.04 0 00.035-.02.041.041 0 000-.04l-2.9-5.086a.108.108 0 010-.113l.293-.507 1.12-1.977c.024-.041.012-.062-.035-.062H9.2c-.059 0-.073-.026-.043-.077l1.434-2.505a.107.107 0 000-.114L9.225 1.774a.06.06 0 00-.053-.031zm6.29 8.02c.046 0 .058.02.034.06l-.832 1.465-2.613 4.585a.056.056 0 01-.05.029.058.058 0 01-.05-.029L8.498 9.841c-.02-.034-.01-.052.028-.054l.216-.012 6.722-.012z",fill:"url(#pi-qwen-lobe-icons-qwen-_R_0_)","fill-rule":"nonzero"}),(0,r.jsx)("defs",{children:(0,r.jsxs)("linearGradient",{id:"pi-qwen-lobe-icons-qwen-_R_0_",x1:"0%",x2:"100%",y1:"0%",y2:"0%",children:[(0,r.jsx)("stop",{offset:"0%","stop-color":"#6336E7","stop-opacity":".84"}),(0,r.jsx)("stop",{offset:"100%","stop-color":"#6F69F7","stop-opacity":".84"})]})})]})),s4=sA("Zhipu",{},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M11.991 23.503a.24.24 0 00-.244.248.24.24 0 00.244.249.24.24 0 00.245-.249.24.24 0 00-.22-.247l-.025-.001zM9.671 5.365a1.697 1.697 0 011.099 2.132l-.071.172-.016.04-.018.054c-.07.16-.104.32-.104.498-.035.71.47 1.279 1.186 1.314h.366c1.309.053 2.338 1.173 2.286 2.523-.052 1.332-1.152 2.38-2.478 2.327h-.174c-.715.018-1.274.64-1.239 1.368 0 .124.018.23.053.337.209.373.54.658.96.8.75.23 1.517-.125 1.9-.782l.018-.035c.402-.64 1.17-.96 1.92-.711.854.284 1.378 1.226 1.099 2.167a1.661 1.661 0 01-2.077 1.102 1.711 1.711 0 01-.907-.711l-.017-.035c-.2-.323-.463-.58-.851-.711l-.056-.018a1.646 1.646 0 00-1.954.746 1.66 1.66 0 01-1.065.764 1.677 1.677 0 01-1.989-1.279c-.209-.906.332-1.83 1.257-2.043a1.51 1.51 0 01.296-.035h.018c.68-.071 1.151-.622 1.116-1.333a1.307 1.307 0 00-.227-.693 2.515 2.515 0 01-.366-1.403 2.39 2.39 0 01.366-1.208c.14-.195.21-.444.227-.693.018-.71-.506-1.261-1.186-1.332l-.07-.018a1.43 1.43 0 01-.299-.07l-.05-.019a1.7 1.7 0 01-1.047-2.114 1.68 1.68 0 012.094-1.101zm-5.575 10.11c.26-.264.639-.367.994-.27.355.096.633.379.728.74.095.362-.007.748-.267 1.013-.402.41-1.053.41-1.455 0a1.062 1.062 0 010-1.482zm14.845-.294c.359-.09.738.024.992.297.254.274.344.665.237 1.025-.107.36-.396.634-.756.718-.551.128-1.1-.22-1.23-.781a1.05 1.05 0 01.757-1.26zm-.064-4.39c.314.32.49.753.49 1.206 0 .452-.176.886-.49 1.206-.315.32-.74.5-1.185.5-.444 0-.87-.18-1.184-.5a1.727 1.727 0 010-2.412 1.654 1.654 0 012.369 0zm-11.243.163c.364.484.447 1.128.218 1.691a1.665 1.665 0 01-2.188.923c-.855-.36-1.26-1.358-.907-2.228a1.68 1.68 0 011.33-1.038c.593-.08 1.183.169 1.547.652zm11.545-4.221c.368 0 .708.2.892.524.184.324.184.724 0 1.048a1.026 1.026 0 01-.892.524c-.568 0-1.03-.47-1.03-1.048 0-.579.462-1.048 1.03-1.048zm-14.358 0c.368 0 .707.2.891.524.184.324.184.724 0 1.048a1.026 1.026 0 01-.891.524c-.569 0-1.03-.47-1.03-1.048 0-.579.461-1.048 1.03-1.048zm10.031-1.475c.925 0 1.675.764 1.675 1.706s-.75 1.705-1.675 1.705-1.674-.763-1.674-1.705c0-.942.75-1.706 1.674-1.706zm-2.626-.684c.362-.082.653-.356.761-.718a1.062 1.062 0 00-.238-1.028 1.017 1.017 0 00-.996-.294c-.547.14-.881.7-.752 1.257.13.558.675.907 1.225.783zm0 16.876c.359-.087.644-.36.75-.72a1.062 1.062 0 00-.237-1.019 1.018 1.018 0 00-.985-.301 1.037 1.037 0 00-.762.717c-.108.361-.017.754.239 1.028.245.263.606.377.953.305l.043-.01zM17.19 3.5a.631.631 0 00.628-.64c0-.355-.279-.64-.628-.64a.631.631 0 00-.628.64c0 .355.28.64.628.64zm-10.38 0a.631.631 0 00.628-.64c0-.355-.28-.64-.628-.64a.631.631 0 00-.628.64c0 .355.279.64.628.64zm-5.182 7.852a.631.631 0 00-.628.64c0 .354.28.639.628.639a.63.63 0 00.627-.606l.001-.034a.62.62 0 00-.628-.64zm5.182 9.13a.631.631 0 00-.628.64c0 .355.279.64.628.64a.631.631 0 00.628-.64c0-.355-.28-.64-.628-.64zm10.38.018a.631.631 0 00-.628.64c0 .355.28.64.628.64a.631.631 0 00.628-.64c0-.355-.279-.64-.628-.64zm5.182-9.148a.631.631 0 00-.628.64c0 .354.279.639.628.639a.631.631 0 00.628-.64c0-.355-.28-.64-.628-.64zm-.384-4.992a.24.24 0 00.244-.249.24.24 0 00-.244-.249.24.24 0 00-.244.249c0 .142.122.249.244.249zM11.991.497a.24.24 0 00.245-.248A.24.24 0 0011.99 0a.24.24 0 00-.244.249c0 .133.108.236.223.247l.021.001zM2.011 6.36a.24.24 0 00.245-.249.24.24 0 00-.244-.249.24.24 0 00-.244.249.24.24 0 00.244.249zm0 11.263a.24.24 0 00-.243.248.24.24 0 00.244.249.24.24 0 00.244-.249.252.252 0 00-.244-.248zm19.995-.018a.24.24 0 00-.245.248.24.24 0 00.245.25.24.24 0 00.244-.25.252.252 0 00-.244-.248z",fill:"#3859FF","fill-rule":"nonzero"})})),s6=sA("Cohere",{},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{"clip-rule":"evenodd",d:"M8.128 14.099c.592 0 1.77-.033 3.398-.703 1.897-.781 5.672-2.2 8.395-3.656 1.905-1.018 2.74-2.366 2.74-4.18A4.56 4.56 0 0018.1 1H7.549A6.55 6.55 0 001 7.55c0 3.617 2.745 6.549 7.128 6.549z",fill:"#39594D","fill-rule":"evenodd"}),(0,r.jsx)("path",{"clip-rule":"evenodd",d:"M9.912 18.61a4.387 4.387 0 012.705-4.052l3.323-1.38c3.361-1.394 7.06 1.076 7.06 4.715a5.104 5.104 0 01-5.105 5.104l-3.597-.001a4.386 4.386 0 01-4.386-4.387z",fill:"#D18EE2","fill-rule":"evenodd"}),(0,r.jsx)("path",{d:"M4.776 14.962A3.775 3.775 0 001 18.738v.489a3.776 3.776 0 007.551 0v-.49a3.775 3.775 0 00-3.775-3.775z",fill:"#FF7759"})]})),s8=sA("Perplexity",{},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M19.785 0v7.272H22.5V17.62h-2.935V24l-7.037-6.194v6.145h-1.091v-6.152L4.392 24v-6.465H1.5V7.188h2.884V0l7.053 6.494V.19h1.09v6.49L19.786 0zm-7.257 9.044v7.319l5.946 5.234V14.44l-5.946-5.397zm-1.099-.08l-5.946 5.398v7.235l5.946-5.234V8.965zm8.136 7.58h1.844V8.349H13.46l6.105 5.54v2.655zm-8.982-8.28H2.59v8.195h1.8v-2.576l6.192-5.62zM5.475 2.476v4.71h5.115l-5.115-4.71zm13.219 0l-5.115 4.71h5.115v-4.71z",fill:"#22B8CD","fill-rule":"nonzero"})})),s5=sA("Together",{},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{d:"M23.197 4.503A6 6 0 0015 2.307a5.973 5.973 0 00-2.995 4.933l5.996.008v.515h-5.996c.039.937.298 1.87.8 2.74a6 6 0 1010.39-6z",fill:"#EF2CC1"}),(0,r.jsx)("path",{d:"M.805 4.5A6 6 0 003 12.697a5.972 5.972 0 005.77.127L5.779 7.627l.446-.257 2.997 5.192A6 6 0 10.804 4.5z",fill:"#CAAEF5"}),(0,r.jsx)("path",{d:"M12 23.894a6 6 0 005.999-6c0-2.13-1.1-3.996-2.775-5.06l-3.005 5.189-.444-.258 2.997-5.192A6 6 0 1012 23.894z",fill:"#FC4C02"})]})),s3=sA("Grok",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M9.27 15.29l7.978-5.897c.391-.29.95-.177 1.137.272.98 2.369.542 5.215-1.41 7.169-1.951 1.954-4.667 2.382-7.149 1.406l-2.711 1.257c3.889 2.661 8.611 2.003 11.562-.953 2.341-2.344 3.066-5.539 2.388-8.42l.006.007c-.983-4.232.242-5.924 2.75-9.383.06-.082.12-.164.179-.248l-3.301 3.305v-.01L9.267 15.292M7.623 16.723c-2.792-2.67-2.31-6.801.071-9.184 1.761-1.763 4.647-2.483 7.166-1.425l2.705-1.25a7.808 7.808 0 00-1.829-1A8.975 8.975 0 005.984 5.83c-2.533 2.536-3.33 6.436-1.962 9.764 1.022 2.487-.653 4.246-2.34 6.022-.599.63-1.199 1.259-1.682 1.925l7.62-6.815"})})),s7=sA("AntGroup",{},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{d:"M9.797 6.282a.451.451 0 01-.336-.315 1.019 1.019 0 010-.505c.156-.86.3-1.725.501-2.577.14-.7.42-1.367.823-1.96.305-.431.75-.746 1.262-.89.877-.217 1.24.629.937 1.348-.259.593-.877.914-1.334 1.348-.835.795-1.096 2.14-1.336 3.212a.427.427 0 01-.186.277.437.437 0 01-.331.062z",fill:"url(#pi-antgroup-lobe-icons-antgroup-0-_R_0_)",transform:"translate(3)"}),(0,r.jsx)("path",{d:"M6.334 4.672c.33-.121.682.146.946.297.278.145.587.219.901.214.231.01.466 0 .688.018 4.098.176 7.484 3.22 8.05 7.237.565 4.016-1.852 7.859-5.745 9.134-3.894 1.276-8.153-.38-10.126-3.935A8.339 8.339 0 013.133 7.081c.348-.278.716-.53 1.102-.755a8.404 8.404 0 001.318-.79c.28-.243.45-.742.781-.864zm4.406 2.15c-2.841.003-4.898 2.533-4.628 5.642.27 3.109 2.781 5.641 5.613 5.665 2.832.024 4.932-2.512 4.658-5.644-.273-3.133-2.802-5.666-5.643-5.663zm.357.57a4.707 4.707 0 013.304 1.446 5.703 5.703 0 011.643 3.49 4.841 4.841 0 01-1.141 3.705v.015a3.923 3.923 0 01-2.808 1.303 4.664 4.664 0 01-3.367-1.387 5.678 5.678 0 01-1.71-3.518 4.832 4.832 0 011.14-3.753 3.923 3.923 0 012.813-1.3h.126z",fill:"url(#pi-antgroup-lobe-icons-antgroup-1-_R_0_)",transform:"translate(3)"}),(0,r.jsx)("path",{d:"M2.346 2.054a1.26 1.26 0 01.384-.594.842.842 0 011.165.11c.694.82.169 2.078.142 3.02.013.805.208 1.597.57 2.318.084.134.147.279.186.43a.539.539 0 01-.3.577c-.345.17-.568-.19-.709-.446-.324-.6-.617-1.216-.877-1.846a8.698 8.698 0 01-.618-1.987 7.523 7.523 0 01-.051-.37 3.717 3.717 0 01-.024-.34 2.506 2.506 0 01.132-.872z",fill:"url(#pi-antgroup-lobe-icons-antgroup-2-_R_0_)",transform:"translate(3)"}),(0,r.jsxs)("defs",{children:[(0,r.jsxs)("linearGradient",{id:"pi-antgroup-lobe-icons-antgroup-0-_R_0_",x1:"31.373%",x2:"61.365%",y1:"95.551%",y2:"-.348%",children:[(0,r.jsx)("stop",{offset:"0%","stop-color":"#06F"}),(0,r.jsx)("stop",{offset:"20%","stop-color":"#1677FF"}),(0,r.jsx)("stop",{offset:"100%","stop-color":"#04A6FF"})]}),(0,r.jsxs)("linearGradient",{id:"pi-antgroup-lobe-icons-antgroup-1-_R_0_",x1:"4.366%",x2:"94.359%",y1:"65.982%",y2:"32.918%",children:[(0,r.jsx)("stop",{offset:"0%","stop-color":"#06F"}),(0,r.jsx)("stop",{offset:"20%","stop-color":"#1677FF"}),(0,r.jsx)("stop",{offset:"100%","stop-color":"#04A6FF"})]}),(0,r.jsxs)("linearGradient",{id:"pi-antgroup-lobe-icons-antgroup-2-_R_0_",x1:"56.255%",x2:"45.986%",y1:"99.257%",y2:"1.384%",children:[(0,r.jsx)("stop",{offset:"0%","stop-color":"#06F"}),(0,r.jsx)("stop",{offset:"20%","stop-color":"#1677FF"}),(0,r.jsx)("stop",{offset:"100%","stop-color":"#04A6FF"})]})]})]})),s9=sA("Nvidia",{},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M10.212 8.976V7.62c.127-.01.256-.017.388-.021 3.596-.117 5.957 3.184 5.957 3.184s-2.548 3.647-5.282 3.647a3.227 3.227 0 01-1.063-.175v-4.109c1.4.174 1.681.812 2.523 2.258l1.873-1.627a4.905 4.905 0 00-3.67-1.846 6.594 6.594 0 00-.729.044m0-4.476v2.025c.13-.01.259-.019.388-.024 5.002-.174 8.261 4.226 8.261 4.226s-3.743 4.69-7.643 4.69c-.338 0-.675-.031-1.007-.092v1.25c.278.038.558.057.838.057 3.629 0 6.253-1.91 8.794-4.169.421.347 2.146 1.193 2.501 1.564-2.416 2.083-8.048 3.763-11.24 3.763-.308 0-.603-.02-.894-.048V19.5H24v-15H10.21zm0 9.756v1.068c-3.356-.616-4.287-4.21-4.287-4.21a7.173 7.173 0 014.287-2.138v1.172h-.005a3.182 3.182 0 00-2.502 1.178s.615 2.276 2.507 2.931m-5.961-3.3c1.436-1.935 3.604-3.148 5.961-3.336V6.523C5.81 6.887 2 10.723 2 10.723s2.158 6.427 8.21 7.015v-1.166C5.77 16 4.25 10.958 4.25 10.958h-.002z",fill:"#74B71B","fill-rule":"nonzero"})})),ie=sA("OpenCode",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M16 6H8v12h8V6zm4 16H4V2h16v20z"})})),it=sA("XiaomiMiMo",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M.958 15.936a.459.459 0 01.459.44v2.729a.46.46 0 01-.918 0v-2.729a.459.459 0 01.459-.44zm4.814-2.035a.46.46 0 01.553.45v4.754a.458.458 0 11-.918 0V15.48L3.74 17.202a.462.462 0 01-.655.016.462.462 0 01-.065-.082L.628 14.67a.459.459 0 01.658-.637l2.124 2.187 2.127-2.188a.46.46 0 01.235-.13zm2.068.004a.46.46 0 01.458.445v4.755a.46.46 0 01-.458.458.459.459 0 01-.458-.458V14.35a.459.459 0 01.458-.445zm1.973 2.014a.46.46 0 01.46.457v2.729a.46.46 0 01-.784.324.46.46 0 01-.134-.324v-2.729a.46.46 0 01.458-.458zm.002-2.045a.458.458 0 01.328.157l2.127 2.19 2.125-2.19a.459.459 0 01.784.318v4.756a.46.46 0 01-.455.458.46.46 0 01-.458-.458V15.48l-1.667 1.723a.46.46 0 01-.65.008l-.005-.005c0-.002-.002-.002-.004-.003l-2.455-2.534a.46.46 0 01-.008-.667.461.461 0 01.338-.128zm6.797 1.206a.46.46 0 01.53.651A1.966 1.966 0 0019.81 18.4a.462.462 0 01.623.18.46.46 0 01-.181.624 2.863 2.863 0 01-1.38.353l-.142-.004a2.88 2.88 0 01-2.393-4.263.461.461 0 01.274-.21zm.864-.931a2.884 2.884 0 013.915 3.914.46.46 0 01-.402.24l-.057-.004a.458.458 0 01-.164-.055.46.46 0 01-.182-.622 1.967 1.967 0 00-2.669-2.67.459.459 0 11-.441-.803zM9.59 6.368c1.481 0 1.696 1.202 1.696 1.654v2.648h-.917v-.432c-.26.346-.792.535-1.36.535-.133 0-1.289-.03-1.384-1.136-.082-.932.675-1.61 2.053-1.61h.691c0-.563-.367-.886-.983-.886-.44.013-.864.174-1.2.458l-.36-.664c.484-.379 1.012-.567 1.764-.567zm4.427.1c1.263 0 2.082.97 2.083 2.15 0 1.181-.824 2.154-2.083 2.154-1.26 0-2.084-.972-2.084-2.152 0-1.18.82-2.153 2.084-2.153zm6.801.015c.68 0 1.202.465 1.197 1.548v2.642H21.1V8.29c0-.312-.002-.98-.63-.98s-.628.667-.628.838v2.524h-.89V8.148c0-.17-.001-.838-.63-.838-.628 0-.628.668-.628.98v2.383h-.917v-4.03h.917V7a1.22 1.22 0 01.947-.516c.398 0 .76.193.982.686a1.321 1.321 0 011.195-.686zm-18.093.872l1.457-1.772H5.32L3.311 8.07l2.14 2.602H4.24L2.725 8.796 1.21 10.672H0L2.138 8.07.13 5.583h1.138l1.458 1.772zm4.149 3.317h-.916V6.644h.916v4.028zm16.99 0h-.916V6.644h.916v4.028zM9.925 8.71c-1.055 0-1.359.412-1.326.742.032.329.324.537.757.537a1.013 1.013 0 001.014-.968l.002-.31h-.447zM14.018 7.3c-.663 0-1.184.487-1.184 1.32 0 .832.52 1.32 1.184 1.32.662 0 1.182-.49 1.182-1.32 0-.832-.52-1.32-1.182-1.32zM6.417 5.001a.568.568 0 01.587.582.588.588 0 01-1.175 0A.57.57 0 016.417 5zm16.991 0a.57.57 0 01.592.582.588.588 0 01-1.174 0 .57.57 0 01.357-.542.572.572 0 01.225-.04z"})})),io=sA("ZAI",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M12.105 2L9.927 4.953H.653L2.83 2h9.276zM23.254 19.048L21.078 22h-9.242l2.174-2.952h9.244zM24 2L9.264 22H0L14.736 2H24z"})})),ir={anthropic:{Icon:sN,hasColor:!1},openai:{Icon:sL,hasColor:!1},"openai-codex":{Icon:sL,hasColor:!1},reqtoken:{Icon:sL,hasColor:!1},google:{Icon:s$,hasColor:!0},"google-vertex":{Icon:s$,hasColor:!0},"ant-ling":{Icon:s7,hasColor:!0},deepseek:{Icon:sH,hasColor:!0},groq:{Icon:sO,hasColor:!1},mistral:{Icon:sB,hasColor:!0},moonshotai:{Icon:sU,hasColor:!1},"moonshotai-cn":{Icon:sU,hasColor:!1},moonshot:{Icon:sU,hasColor:!1},minimax:{Icon:s_,hasColor:!0},"minimax-cn":{Icon:s_,hasColor:!0},fireworks:{Icon:sq,hasColor:!0},huggingface:{Icon:sV,hasColor:!0},cerebras:{Icon:sK,hasColor:!0},openrouter:{Icon:sG,hasColor:!1},xai:{Icon:sJ,hasColor:!1},"cloudflare-ai-gateway":{Icon:sY,hasColor:!0},"cloudflare-workers-ai":{Icon:sY,hasColor:!0},"vercel-ai-gateway":{Icon:sX,hasColor:!1},"github-copilot":{Icon:sZ,hasColor:!1},"amazon-bedrock":{Icon:sQ,hasColor:!0},"azure-openai-responses":{Icon:s0,hasColor:!0},"kimi-coding":{Icon:s1,hasColor:!0},nvidia:{Icon:s9,hasColor:!0},opencode:{Icon:ie,hasColor:!1},"opencode-go":{Icon:ie,hasColor:!1},qwen:{Icon:s2,hasColor:!0},xiaomi:{Icon:it,hasColor:!1},"xiaomi-token-plan-ams":{Icon:it,hasColor:!1},"xiaomi-token-plan-cn":{Icon:it,hasColor:!1},"xiaomi-token-plan-sgp":{Icon:it,hasColor:!1},zai:{Icon:io,hasColor:!1},"zai-coding-cn":{Icon:io,hasColor:!1},zhipu:{Icon:s4,hasColor:!0},cohere:{Icon:s6,hasColor:!0},perplexity:{Icon:s8,hasColor:!0},together:{Icon:s5,hasColor:!0},grok:{Icon:s3,hasColor:!1}};function is({id:e,size:t=14}){let o=ir[e];return o?o.hasColor?(0,r.jsx)(o.Icon,{size:t}):(0,r.jsx)(o.Icon,{size:t,style:{color:"currentColor"}}):(0,r.jsx)(z.G,{size:t,weight:"regular","aria-hidden":"true"})}var ii=o(61394),ia=o(21418);let il=[{value:"normal",Icon:ii.f,titleKey:"modes.collabNormalTitle",descKey:"modes.collabNormalDesc"},{value:"plan",Icon:ia._,titleKey:"modes.collabPlanTitle",descKey:"modes.collabPlanDesc"},{value:"goal",Icon:nw.d,titleKey:"modes.collabGoalTitle",descKey:"modes.collabGoalDesc"}],id={normal:ii.f,plan:ia._,goal:nw.d};function ic({collaborationMode:e,onCollaborationModeChange:t,disabled:o=!1}){let s,{t:i}=(0,A.s)(),[a,l]=(0,n.useState)(null),[d,c]=(0,n.useState)(null),[p,u]=(0,n.useState)({}),h=(0,n.useRef)(null),g=(0,n.useRef)(null);(0,n.useEffect)(()=>()=>{null!==g.current&&window.clearTimeout(g.current)},[]);let f=(0,n.useCallback)(e=>{c(e),window.requestAnimationFrame(()=>l(t=>t===e?null:t)),null!==g.current&&window.clearTimeout(g.current),g.current=window.setTimeout(()=>c(null),150)},[]),x=()=>window.visualViewport?.height??window.innerHeight,v=id[e],y="plan"===e?i("modes.collabPlan"):"goal"===e?i("modes.collabGoal"):i("modes.collabNormal");return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{style:{display:"flex",alignItems:"center",gap:2},children:(0,r.jsxs)("button",{ref:h,type:"button","aria-label":i("modes.collabNormalTitle"),title:i("modes.collabNormalTitle"),"aria-expanded":"collab"===a,onClick:(s="collab",()=>{if(o)return;let e=h.current;if(!e)return;let t=e.getBoundingClientRect();u(e=>({...e,[s]:{top:t.top,left:t.left,width:t.width}})),l(e=>e===s?null:s)}),disabled:o,style:{display:"flex",alignItems:"center",gap:3,padding:"3px 6px",height:24,background:"collab"===a?"var(--bg-hover)":"none",border:"none",borderRadius:6,color:"normal"!==e?"var(--accent)":"var(--text-muted)",cursor:o?"not-allowed":"pointer",fontSize:12,whiteSpace:"nowrap",opacity:o?.5:1,transition:"background 0.12s, color 0.12s"},children:[(0,r.jsx)(v,{size:13,weight:"normal"!==e?"fill":"regular",color:"normal"!==e?"var(--accent)":"var(--text-muted)","aria-hidden":"true"}),(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis"},children:y}),(0,r.jsx)(k.b,{size:10,weight:"bold","aria-hidden":"true",style:{transform:"collab"===a?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.12s",flexShrink:0}})]})}),(()=>{if("collab"!==a)return null;let n=p.collab;if(!n)return null;let s=Math.min(248,window.innerWidth-16),l=Math.min(n.left,window.innerWidth-s-8),c=x()-n.top+6,u=Math.min(300,Math.max(120,.55*x()));return(0,r.jsx)("div",{role:"menu",style:{position:"fixed",bottom:c,left:l,zIndex:2100,width:s,maxHeight:u,overflowY:"auto",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 12px 32px rgba(0,0,0,0.22)",padding:4,opacity:+("collab"!==d),transition:"opacity 0.12s"},children:il.map(n=>{let s=n.value===e,a=n.Icon;return(0,r.jsxs)("button",{type:"button",role:"menuitemradio","aria-checked":s,onClick:()=>{var o;return o=n.value,void(f("collab"),o!==e&&t(o))},disabled:o,style:{display:"flex",alignItems:"center",gap:10,width:"100%",padding:"8px 10px",background:s?"var(--bg-selected)":"none",border:"none",borderRadius:8,cursor:o?"not-allowed":"pointer",textAlign:"left",transition:"background 0.12s"},onMouseEnter:e=>{s||o||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{e.currentTarget.style.background=s?"var(--bg-selected)":"none"},children:[(0,r.jsx)(a,{size:16,weight:s?"fill":"regular",color:s?"var(--accent)":"var(--text-muted)","aria-hidden":"true"}),(0,r.jsxs)("span",{style:{flex:1,minWidth:0},children:[(0,r.jsx)("span",{style:{display:"block",fontSize:12.5,fontWeight:550,color:"var(--text)"},children:i(n.titleKey)}),(0,r.jsx)("span",{style:{display:"block",fontSize:10.5,color:"var(--text-muted)",marginTop:1,lineHeight:1.4},children:i(n.descKey)})]}),s&&(0,r.jsx)(m.S,{size:12,weight:"bold",color:"var(--accent)","aria-hidden":"true"})]},n.value)})})})()]})}let ip=["off","default","full"],iu={off:"none",default:"default",full:"full"},ih=new Intl.Collator(void 0,{numeric:!0,sensitivity:"base"});function ig(e,t){return ih.compare(e.name||e.modelId,t.name||t.modelId)||ih.compare(e.provider,t.provider)||ih.compare(e.modelId,t.modelId)}let im=["max","xhigh","high","medium","low","minimal","auto","off"];function ix({level:e,size:t=14}){if("off"===e)return(0,r.jsx)(sP.x,{size:t,weight:"regular",color:"var(--text-dim)"});if("auto"===e)return(0,r.jsx)(sD.I,{size:t,weight:"regular",color:"var(--accent)"});let o=["medium","high","xhigh","max"].includes(e),n="var(--accent)";return(0,r.jsxs)("span",{style:{position:"relative",display:"inline-flex"},children:[(0,r.jsx)(sP.x,{size:t,weight:o?"fill":"regular",color:n}),"high"===e&&(0,r.jsx)(v.c,{size:Math.round(.57*t),weight:"bold",color:n,style:{position:"absolute",right:-4,top:-1}}),"xhigh"===e&&(0,r.jsx)(g.C,{size:Math.round(.57*t),weight:"fill",color:n,style:{position:"absolute",right:-4,top:-1}}),"max"===e&&(0,r.jsxs)("span",{style:{position:"absolute",right:-6,top:-1,display:"inline-flex"},children:[(0,r.jsx)(g.C,{size:Math.round(.5*t),weight:"fill",color:n,style:{marginRight:-3}}),(0,r.jsx)(g.C,{size:Math.round(.5*t),weight:"fill",color:n})]})]})}function ik(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${Math.round(e/1e3)}k`:e.toLocaleString()}let iv=["builtin","extension","prompt","skill"],iy={builtin:0,extension:1,prompt:2,skill:3};function ib(e,t){let o=e.name.toLowerCase(),r=e.description?.toLowerCase()??"";return o===t?0:o.startsWith(t)?1:o.includes(t)?2:r.includes(t)?3:4}function iw(e,t){return"skill"===e.source&&e.name.startsWith("skill:")&&!0===t[e.name.slice(6)]}async function ij(e){let t=()=>{var t;return t=e.type,new Promise((o,r)=>{let n=new FileReader;n.onload=()=>{let e="string"==typeof n.result?n.result.split(",")[1]:void 0;e?o({data:e,mimeType:t}):r(Error("Failed to read image"))},n.onerror=r,n.readAsDataURL(e)})};if(!(e.size>1048576&&"image/gif"!==e.type)||"function"!=typeof createImageBitmap)return t();let o=await createImageBitmap(e).catch(()=>null);if(!o)return t();try{let r=Math.min(1,1024/Math.max(o.width,o.height)),n=document.createElement("canvas");n.width=Math.max(1,Math.round(o.width*r)),n.height=Math.max(1,Math.round(o.height*r));let s=n.getContext("2d");if(!s)return t();s.fillStyle="#fff",s.fillRect(0,0,n.width,n.height),s.drawImage(o,0,0,n.width,n.height);let i=n.toDataURL("image/jpeg",.85).split(",")[1];return i&&i.length<4*Math.ceil(e.size/3)?{data:i,mimeType:"image/jpeg"}:t()}catch{return t()}finally{o.close()}}function iS(e){return{data:e.data,mimeType:e.mimeType}}function iC(e,t){let o=e;for(let e of t)o=o.split(e.label).join(e.text);return o}function iT(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function iR(e){return{...e,previewUrl:`data:${e.mimeType};base64,${e.data}`}}function iz(e){e.previewUrl.startsWith("blob:")&&URL.revokeObjectURL(e.previewUrl)}function iI({kind:e,text:t,label:o,index:n,total:s,onMove:i,onRecall:a,onRemove:l}){let{t:d}=(0,A.s)(),c={display:"inline-flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,border:"none",borderRadius:4,color:"var(--text-dim)",background:"transparent",cursor:"pointer",flexShrink:0};return(0,r.jsxs)("div",{title:t,style:{display:"flex",alignItems:"center",gap:8,padding:"3px 10px",fontSize:12,color:"var(--text-muted)",minWidth:0},children:[(0,r.jsx)("span",{style:{flexShrink:0,fontSize:10,fontFamily:"var(--font-mono)",padding:"1px 7px",borderRadius:999,border:`1px solid ${"steer"===e?"color-mix(in srgb, var(--accent) 45%, transparent)":"var(--border)"}`,color:"steer"===e?"var(--accent)":"var(--text-dim)"},children:o}),(0,r.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:t}),i&&s>1&&(0,r.jsxs)("span",{style:{display:"inline-flex",gap:1,flexShrink:0},children:[(0,r.jsx)("button",{type:"button","aria-label":d("desktop.queueMoveUp"),title:d("desktop.queueMoveUp"),disabled:0===n,onClick:()=>i(-1),style:{...c,opacity:0===n?.3:1},children:"↑"}),(0,r.jsx)("button",{type:"button","aria-label":d("desktop.queueMoveDown"),title:d("desktop.queueMoveDown"),disabled:n===s-1,onClick:()=>i(1),style:{...c,opacity:n===s-1?.3:1},children:"↓"})]}),a&&(0,r.jsx)("button",{type:"button","aria-label":d("desktop.queueRecallOne"),title:d("desktop.queueRecallOne"),onClick:a,style:c,children:(0,r.jsx)(sC.Y,{size:13})}),l&&(0,r.jsx)("button",{type:"button","aria-label":d("desktop.queueRemove"),title:d("desktop.queueRemove"),onClick:l,style:c,children:(0,r.jsx)(h.u,{size:13})})]})}let iM=(0,n.memo)((0,n.forwardRef)(function({onSend:e,onBash:t,onAbort:o,onSteer:s,onFollowUp:i,isStreaming:a,model:l,modelNames:d,modelList:c,modelScopeWarnings:p,modelsError:f,onRetryModels:x,onModelChange:y,compactResult:w,toolPreset:j,onToolPresetChange:S,planMode:z=!1,onPlanModeChange:M,collaborationMode:P="normal",toolApprovalMode:E="auto",onCollaborationModeChange:W,goalState:F,onGoalStart:D,onGoalPause:N,onGoalResume:L,onGoalStop:$,thinkingLevel:H,onThinkingLevelChange:B,availableThinkingLevels:U,thinkingLevelMap:_,retryInfo:q,queuedMessages:V,inputHistory:K=[],onRecallQueue:G,onMoveQueue:J,onRecallOne:Y,onRequeueAt:X,onRemoveQueueItem:Z,slashCommands:Q,slashCommandsLoading:ee,onLoadSlashCommands:et,onBuiltinCommand:er,onAudioUnlock:en,onPromptWithStreamingBehavior:es,draftKey:ei,cwd:el,tasksBoardEnabled:ed=!0},ec){var ep;let eu,eh,eg,em,ef,ex,ek,ev,ey,eb,ew,ej,eS,eC,eT,eR,ez,eI,eM,eP,eE,eW,eF,eD=O(),{t:eA}=(0,A.s)(),eN={auto:"auto",off:"off",minimal:"minimal",low:"low",medium:"medium",high:"high",xhigh:"xhigh",max:"max"},eL={off:eA("desktop.toolOff"),default:eA("desktop.toolDefault"),full:eA("desktop.toolFull")},e$=[{name:"compact",description:eA("desktop.compactCommandDescription"),source:"builtin"},{name:"reload",description:eA("desktop.reloadCommandDescription"),source:"builtin"},{name:"name",description:eA("desktop.nameCommandDescription"),source:"builtin"},{name:"session",description:eA("desktop.sessionCommandDescription"),source:"builtin"},{name:"copy",description:eA("desktop.copyCommandDescription"),source:"builtin"}],eH={builtin:eA("desktop.builtIn"),extension:eA("desktop.extensions"),prompt:eA("desktop.prompts"),skill:eA("desktop.commandSkills")},[eO,eB]=(0,n.useState)(()=>ei?sm(ei)?.value??"":""),[eU,e_]=(0,n.useState)(()=>ei?sm(ei)?.pastedBlocks??[]:[]),[eq,eV]=(0,n.useState)([]),eK=n.useMemo(()=>{try{var e;return e=eA("desktop.pastedLabel",{id:"\0A\0",lines:"\0B\0"}),RegExp(e.split("\0A\0").join("(\\d+)").split("\0B\0").join("(\\d+)").split("(\\d+)").map(iT).join("(\\d+)"),"g")}catch{return null}},[eA]),[eG,eJ]=(0,n.useState)(null),eY=(0,n.useRef)(null),eX=(0,n.useRef)(0),[eZ,eQ]=(0,n.useState)(!1),[e0,e1]=(0,n.useState)(null),[e2,e4]=(0,n.useState)({height:0,width:0,offsetTop:0}),[e6,e8]=(0,n.useState)(""),[e5,e3]=(0,n.useState)(()=>{try{let e=localStorage.getItem("pi-favorite-models");return e?new Set(JSON.parse(e)):new Set}catch{return new Set}}),[e7,e9]=(0,n.useState)(new Set),[te,tt]=(0,n.useState)(!1),[to,tr]=(0,n.useState)(null),[tn,ts]=(0,n.useState)(!1),[ti,ta]=(0,n.useState)(null),[tl,td]=(0,n.useState)(!1),[tc,tp]=(0,n.useState)(null),[tu,th]=(0,n.useState)(()=>ei?sm(ei)?.images.map(iR)??[]:[]),tg=eO.trimStart(),tm=0===tu.length&&tg.startsWith("!"),tf=tm&&tg.startsWith("!!"),[tx,tk]=(0,n.useState)(!1),[tv,ty]=(0,n.useState)(0),[tb,tw]=(0,n.useState)({}),[tj,tS]=(0,n.useState)(()=>{try{return"ctrl-enter"===localStorage.getItem("pi-input-shortcut")?"ctrl-enter":"enter"}catch{return"enter"}}),[tC,tT]=(0,n.useState)(null),[tR,tz]=(0,n.useState)(!1),[tI,tM]=(0,n.useState)(0),[tP,tE]=(0,n.useState)(!1),[tW,tF]=(0,n.useState)(0),[tD,tA]=(0,n.useState)(null),[tN,tL]=(0,n.useState)(!1),[t$,tH]=(0,n.useState)(null),tO=(0,n.useRef)(null),tB=(0,n.useRef)(null),tU=(0,n.useRef)(null),t_=(0,n.useRef)(null),tq=(0,n.useRef)(null),tV=(0,n.useRef)(null),tK=(0,n.useRef)(null),tG=(0,n.useRef)(null),tJ=(0,n.useRef)(null),tY=(0,n.useRef)(null),tX=(0,n.useRef)(!1),tZ=(0,n.useRef)(0),tQ=(0,n.useRef)(!1),t0=(0,n.useRef)([]),t1=(0,n.useRef)([]),t2=(0,n.useRef)([]),t4=(0,n.useRef)(null),t6=(0,n.useRef)(null),t8=(0,n.useRef)(ei),t5=(0,n.useRef)(eO),t3=(0,n.useRef)(tu),t7=(0,n.useRef)(eU),t9=(0,n.useRef)(null),[oe,ot]=(0,n.useState)(!1);t5.current=eO,t3.current=tu,t7.current=eU,(0,n.useImperativeHandle)(ec,()=>({insertIfEmpty(e){let t=tO.current;(t?t.value:eO).trim()||(eB(e),tT(null),requestAnimationFrame(()=>{t&&(t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)}))},replaceMessage(e){var t,o;let r=tO.current;t=r?r.value:eO,o=t3.current.length,t.trim()||0!==o||(eB("string"==typeof e.content?e.content:e.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n")),tT(null),tE(!1),th(t=>(t.forEach(iz),(("string"==typeof e.content?[]:e.content.flatMap(e=>{if("image"!==e.type)return[];let t=e.source?.type==="base64"?e.source.data:e.data,o=e.source?.type==="base64"?e.source.media_type:e.mimeType;return"string"!=typeof t||"string"!=typeof o?[]:sv({type:"image",data:t,mimeType:o})?[{data:t,mimeType:o}]:[]}))??[]).filter(sv).slice(0,10).map(iR))),requestAnimationFrame(()=>{r&&(r.focus(),r.style.height="auto",r.style.height=`${Math.min(r.scrollHeight,200)}px`)}))},prependText(e){if(!e.trim())return;let t=tO.current,o=[e,t?t.value:eO].filter(e=>e.trim()).join("\n\n");eB(o),tT(null),requestAnimationFrame(()=>{t&&(t.focus(),t.setSelectionRange(o.length,o.length),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)})},insertText(e){let t=tO.current;if(!t)return void eB(t=>t+(t?" ":"")+e);let o=t.selectionStart??t.value.length,r=t.selectionEnd??t.value.length,n=t.value.slice(0,o),s=t.value.slice(r),i=n.length>0&&!n.endsWith(" ")?" ":"";eB(n+i+e+s),tT(null),requestAnimationFrame(()=>{if(!t)return;let r=o+i.length+e.length;t.setSelectionRange(r,r),t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`})},addImages(e){oo(e)},addFiles(e,t){let o=function(e,t,o){let r=e.map(()=>null),n=t.split(/\r?\n/).map(e=>e.trim()).filter(e=>e&&!e.startsWith("#")).filter(e=>e.startsWith("file://"));if(n.length===e.length){for(let t=0;t<e.length;t+=1)r[t]=function(e){let t;if(!e.startsWith("file://"))return null;try{t=decodeURIComponent(e.slice(7))}catch{return null}return t?(/^\/[A-Za-z]:[\\/]/.test(t)&&(t=t.slice(1)),t):null}(n[t]);return r}if(1===e.length&&o.trim()){let e=o.trim();(e.startsWith("/")||e.startsWith("~")||/^[A-Za-z]:[\\/]/.test(e))&&(r[0]=e)}return r}(e,t?.getData("text/uri-list")??"",t?.getData("text/plain")??""),r=e.filter(e=>e.type.startsWith("image/")),n=e.map((e,t)=>e.type.startsWith("image/")?null:o[t]??e.name).filter(e=>!!e);if(r.length&&oo(r),n.length&&!a){let e=n.join(" ");eB(t=>t+(t&&!t.endsWith(" ")?" ":"")+e)}},measureHeight:()=>tV.current?.getBoundingClientRect().height??0}));let oo=(0,n.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/"));if(!t.length)return;let o=await Promise.all(t.map(async e=>({...await ij(e),previewUrl:URL.createObjectURL(e)})));th(e=>[...e,...o])},[]),or=(0,n.useCallback)((e,t)=>{e3(o=>{let r=`${e}:${t}`,n=new Set(o);return n.has(r)?n.delete(r):n.add(r),localStorage.setItem("pi-favorite-models",JSON.stringify([...n])),n})},[]),on=(0,n.useCallback)(e=>{e9(t=>{let o=new Set(t);return o.has(e)?o.delete(e):o.add(e),o})},[]),os=(0,n.useCallback)(e=>{th(t=>{let o=[...t],[r]=o.splice(e,1);return r&&iz(r),o})},[]),oi=(0,n.useCallback)(()=>{th(e=>(e.forEach(iz),[]))},[]),oa=(0,n.useCallback)(()=>{var e;eB(""),tT(null),e_([]),eV([]),ei&&sh.delete(ei),t8.current&&t8.current!==ei&&(e=t8.current,sh.delete(e)),oi(),tO.current&&(tO.current.style.height="auto")},[oi,ei]),ol=(0,n.useCallback)(async(e,t,o)=>{await J?.(e,t,t+o)},[J]),od=(0,n.useCallback)(async(e,t)=>{await Z?.(e,t)},[Z]),oc=(0,n.useCallback)(async(e,t)=>{let o=await Y?.(e,t);if(!o)return;t9.current={kind:e,index:t,text:o.text,images:o.images},ot(!0);let r=tO.current?.value??eO,n=[o.text,r].filter(e=>e.trim()).join("\n\n");eB(n),tT(null),requestAnimationFrame(()=>{let e=tO.current;e&&(e.focus(),e.setSelectionRange(n.length,n.length),e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)})},[Y,eO]);(0,n.useEffect)(()=>{ei&&t8.current===ei&&sf(ei,{value:eO,images:tu.map(iS),pastedBlocks:eU.length?eU:void 0})},[tu,ei,eO,eU]),(0,n.useEffect)(()=>{let e=t8.current;if(e===ei)return;e&&sf(e,{value:t5.current,images:t3.current.map(iS),pastedBlocks:t7.current.length?t7.current:void 0});let t=ei?sm(ei):null;t8.current=ei,eB(t?.value??""),tT(null),e_(t?.pastedBlocks??[]),eV([]),th(e=>(e.forEach(iz),t?.images.map(iR)??[]))},[ei]),(0,n.useEffect)(()=>{let e=tO.current;e&&(e.style.height="auto",eO&&(e.style.height=`${Math.min(e.scrollHeight,200)}px`))},[eO]),(0,n.useEffect)(()=>{let e=()=>{try{tS("ctrl-enter"===localStorage.getItem("pi-input-shortcut")?"ctrl-enter":"enter")}catch{tS("enter")}};return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)},[]),(0,n.useEffect)(()=>()=>{t3.current.forEach(iz)},[]);let op=(0,n.useCallback)(e=>{let t;if(!eK)return null;for(eK.lastIndex=0;null!==(t=eK.exec(e));){let e=t[0];if(!(t7.current.some(t=>t.label===e)||t7.current.some(t=>t.text.includes(e))))return e}return null},[eK]),ou=(0,n.useCallback)(()=>{eJ(eA("desktop.pastedMissingContent")),eY.current&&clearTimeout(eY.current),eY.current=setTimeout(()=>eJ(null),5e3)},[eA]),oh=(0,n.useCallback)(async()=>{let o=iC(eO,eU),r=o.trim();if(!r&&!tu.length)return;if(op(o))return void ou();if(a)return;en?.();let n=t9.current;if(n&&X){if(t9.current=null,ot(!1),!await X(n.kind,n.index,r,tu.length?tu.map(iS):n.images)){t9.current={...n,text:r},ot(!0);return}oa();return}if(!tu.length&&r.startsWith("!")&&t){let e=r.startsWith("!!"),o=r.slice(e?2:1).trim();if(!o)return;t(o,e),oa();return}if(!tu.length&&r.startsWith("/")&&er){let e=await er(r);if(e.handled){e.error||oa();return}}e(r,tu.length?tu:void 0),oa()},[eO,eU,tu,a,t,er,e,oa,en,X,op,ou]),og=eO.startsWith("/")&&!/\s/.test(eO.slice(1))?eO.slice(1).toLowerCase():null,{commands:om,groups:of}=(ep=null===og?[]:[...a?[]:e$,...Q??[]].filter(e=>{let t=e.name.toLowerCase(),o=e.description?.toLowerCase()??"";return t.includes(og)||o.includes(og)}).sort((e,t)=>{let o=ib(e,og)-ib(t,og);return 0!==o?o:iy[e.source]-iy[t.source]||ih.compare(e.name,t.name)}),eu=0,{commands:(eh=iv.map(e=>{let t=ep.filter(t=>t.source===e),o="skill"===e?[...t.filter(e=>!iw(e,tb)),...t.filter(e=>iw(e,tb))]:t;return{source:e,items:o.map(e=>({command:e,index:eu++}))}}).filter(e=>e.items.length>0)).flatMap(e=>e.items.map(({command:e})=>e)),groups:eh});(0,n.useEffect)(()=>{if(!tx||!el)return;let e=!1;return fetch(`/api/skills?cwd=${encodeURIComponent(el)}`).then(e=>e.ok?e.json():null).then(t=>{!e&&t&&tw(Object.fromEntries(t.skills.map(e=>[e.name,e.disableModelInvocation])))}).catch(()=>{}),()=>{e=!0}},[el,tx]);let ox=`${om.length} ${eA(og?1===om.length?"desktop.match":"desktop.matches":1===om.length?"desktop.command":"desktop.commands")}`,ok=!!eO.trim()||tu.length>0,ov=(0,n.useCallback)((e,t)=>{if(!el)return void tT(null);let o=t??e.length;tT(sy(e.slice(0,o)))},[el]),[oy,ob]=(0,n.useState)(null),ow=(0,n.useRef)(oy);ow.current=oy;let[oj,oS]=(0,n.useState)([]),oC=(0,n.useRef)(!1),oT=(0,n.useCallback)(async()=>{try{let e=await fetch("/api/snippets");if(!e.ok)return;let t=await e.json();oS(t.snippets??[]),oC.current=!0}catch{}},[]);(0,n.useEffect)(()=>{oT();let e=()=>void oT();return window.addEventListener("pi:snippets-changed",e),()=>window.removeEventListener("pi:snippets-changed",e)},[oT]);let oR=oy?.query??null,oz=n.useMemo(()=>{if(null===oR||!1===oC.current)return[];let e=oR.toLowerCase();return oj.filter(t=>t.name.toLowerCase().includes(e))},[oR,oj]),[oI,oM]=(0,n.useState)(0);(0,n.useEffect)(()=>{oM(0)},[oR]);let oP=(0,n.useCallback)((e,t)=>{var o;let r,n=t??e.length,s=(o=e.slice(0,n),(r=/(?:^|[\s(])(#[\w-]+)$/.exec(o))?{start:o.length-r[1].length,end:o.length,query:r[1].slice(1)}:null);ob(s),s&&oM(0)},[]),oE=(0,n.useCallback)(e=>{let t=ow.current;if(!t)return;let o=eO.slice(0,t.start),r=eO.slice(t.end);eB(o+e.content+r),ob(null);let n=o.length+e.content.length;requestAnimationFrame(()=>{let e=tO.current;e&&(e.focus(),e.setSelectionRange(n,n))})},[eO]),oW=(0,n.useCallback)(e=>{let t=oz[e];t&&oE(t)},[oz,oE]),oF=tC?.query??null,oD=n.useMemo(()=>null!==oF&&tD&&tD.cwd===el?function(e,t,o=20){let r=t.toLowerCase();if(!r)return e.slice(0,o);let n=[];for(let t of e){let e=function(e,t){let o=e.path.toLowerCase(),r=0;if(t.includes("/"))o===t?r=100:o.startsWith(t)?r=80:o.includes(t)?r=50:sw(t,o)&&(r=10);else{let e=o.lastIndexOf("/"),n=-1===e?o:o.slice(e+1);n===t?r=100:n.startsWith(t)?r=80:n.includes(t)?r=50:o.includes(t)?r=30:sw(t,o)&&(r=10)}return e.isDir&&r>0&&(r+=10),r}(t,r);e>0&&n.push({entry:t,score:e})}return n.sort((e,t)=>t.score-e.score||sb(e.entry.path)-sb(t.entry.path)||e.entry.path.localeCompare(t.entry.path)),n.slice(0,o).map(e=>e.entry)}(tD.entries,oF):[],[oF,tD,el]),oA=!!(oF&&tD?.truncated&&tD.cwd===el);(0,n.useEffect)(()=>{if(!oA||!el||!oF)return;let e=setTimeout(()=>{fetch(`/api/file-index?cwd=${encodeURIComponent(el)}&q=${encodeURIComponent(oF)}`).then(e=>{if(!e.ok)throw Error(`file search failed: ${e.status}`);return e.json()}).then(e=>tH({cwd:el,query:oF,matches:e.matches??[]})).catch(()=>{})},150);return()=>clearTimeout(e)},[oA,oF,el]);let oN=oA&&null!==t$&&t$.cwd===el&&t$.query===oF,oL=oN?t$.matches:oD,o$=null===tC?null:`${tC.start}:${+!!tC.quoted}:${tC.query}`;(0,n.useEffect)(()=>{if(null===o$){tz(!1),tM(0);return}tz(!0),tM(0)},[o$]);let oH=null!==tC;(0,n.useEffect)(()=>{if(!oH||!el)return;let e=t4.current;e&&e.cwd===el&&Date.now()-e.fetchedAt<1e4||t6.current===el||(t6.current=el,tL(!0),fetch(`/api/file-index?cwd=${encodeURIComponent(el)}`).then(e=>{if(!e.ok)throw Error(`file index failed: ${e.status}`);return e.json()}).then(e=>{tA({cwd:el,entries:function(e){let t=new Set;for(let o of e){let e=o.indexOf("/");for(;-1!==e;)t.add(o.slice(0,e)),e=o.indexOf("/",e+1)}let o=[];for(let e of t)o.push({path:e,isDir:!0});for(let t of e)t&&o.push({path:t,isDir:!1});return o.sort((e,t)=>sb(e.path)-sb(t.path)||e.path.localeCompare(t.path)),o}(e.files??[]),truncated:!!e.truncated}),t4.current={cwd:el,fetchedAt:Date.now()}}).catch(()=>{t4.current=null}).finally(()=>{t6.current=null,tL(!1)}))},[oH,el]);let oO=(0,n.useCallback)(e=>{if(!tC)return;let t=tO.current,o=t?.selectionStart??eO.length,r=eO.slice(0,tC.start),n=eO.slice(o);tC.quoted&&n.startsWith('"')&&(n=n.slice(1));let s=function(e,t,o=!1){let r=t?`${e}/`:e,n=o||r.includes(" ");if(t){let e=n?`@"${r}"`:`@${r}`;return{text:e,cursorOffset:n?e.length-1:e.length}}let s=n?`@"${r}" `:`@${r} `;return{text:s,cursorOffset:s.length}}(e.path,e.isDir,tC.quoted),i=r+s.text+n,a=r.length+s.cursorOffset;eB(i),tT(sy(i.slice(0,a))),requestAnimationFrame(()=>{let e=tO.current;e&&(e.focus(),e.setSelectionRange(a,a),e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)})},[tC,eO]);(0,n.useEffect)(()=>{tI>=oL.length&&tM(Math.max(0,oL.length-1))},[oL.length,tI]),(0,n.useEffect)(()=>{t1.current.length=oL.length},[oL.length]),(0,n.useEffect)(()=>{tR&&t1.current[tI]?.scrollIntoView({block:"nearest",inline:"nearest"})},[tI,tR]);let oB=(0,n.useCallback)(e=>{eB(e),tT(null),tE(!1),tF(0),requestAnimationFrame(()=>{let t=tO.current;t&&(t.focus(),t.setSelectionRange(e.length,e.length),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)})},[]),oU=(0,n.useCallback)(e=>{let t=`/${e.name} `;eB(t),tk(!1),ty(0),requestAnimationFrame(()=>{let e=tO.current;e&&(e.focus(),e.setSelectionRange(t.length,t.length),e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)})},[]),o_=(0,n.useCallback)(()=>{let e=tO.current;if(!e)return;let t=e.selectionStart??e.value.length,o=e.value.slice(0,t),r=e.value.slice(e.selectionEnd??t),n=o.length>0&&!o.endsWith(" ")?" ":"",s=o+n+"@"+r;eB(s);let i=t+n.length+1;ov(s,i),requestAnimationFrame(()=>{e&&(e.setSelectionRange(i,i),e.focus(),e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)})},[]),oq=(0,n.useCallback)(()=>{let e=tO.current;if(!e)return;let t=e.selectionStart??e.value.length,o=e.value.slice(0,t),r=e.value.slice(e.selectionEnd??t),n=o.length>0&&!o.endsWith(" ")?" ":"",s=o+n+"#"+r;eB(s),ov(s,t+n.length+1),requestAnimationFrame(()=>{e&&(e.setSelectionRange(t+n.length+1,t+n.length+1),e.focus(),e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)})},[]),oV=(0,n.useCallback)(()=>{let e=tO.current;if(!e)return;let t=e.selectionStart??e.value.length,o=e.value.slice(0,t),r=e.value.slice(e.selectionEnd??t),n=o.length>0&&!o.endsWith(" ")?" ":"";eB(o+n+"/"+r);let s=t+n.length+1;requestAnimationFrame(()=>{e&&(e.setSelectionRange(s,s),e.focus(),e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)})},[]),oK=(0,n.useCallback)(e=>{let t=iC(eO,eU);if(op(t))return void ou();let o=t.trim();if(o||tu.length){if(en?.(),o.startsWith("/")&&es){es(o,"steer"===e?"steer":"followUp",tu.length?tu:void 0),oa();return}"steer"===e&&s?s(o,tu.length?tu:void 0):"followup"===e&&i&&i(o,tu.length?tu:void 0),oa()}},[eO,eU,tu,es,s,i,oa,en,op,ou]),oG=(0,n.useCallback)(e=>{let t=om.length-1;if(t<0)return 0;if("left"===e)return Math.max(0,tv-1);if("right"===e)return Math.min(t,tv+1);let o=t0.current[tv];if(!o)return"down"===e?Math.min(t,tv+1):Math.max(0,tv-1);let r=o.getBoundingClientRect(),n=r.left+r.width/2,s=r.top+r.height/2,i=-1,a=1/0;for(let o=0;o<=t;o+=1){if(o===tv)continue;let t=t0.current[o];if(!t)continue;let r=t.getBoundingClientRect(),l=r.top+r.height/2-s;if("down"===e?l<=4:l>=-4)continue;let d=1e3*Math.abs(l)+Math.abs(r.left+r.width/2-n);d<a&&(i=o,a=d)}return i>=0?i:"down"===e?Math.min(t,tv+1):Math.max(0,tv-1)},[om.length,tv]),oJ=(0,n.useCallback)(e=>{let t=e.nativeEvent,r=Date.now()-tZ.current<100,n=tX.current||t.isComposing||229===t.keyCode;if("Enter"===e.key&&!e.shiftKey&&(n||r)){r&&e.preventDefault();return}if((e.ctrlKey||e.metaKey)&&!e.altKey&&!e.shiftKey&&"i"===e.key.toLowerCase()&&!n&&el){e.preventDefault();let t=e.currentTarget,o=t.selectionStart??t.value.length,r=t.selectionEnd??o,n=t.value.slice(0,o),s=t.value.slice(r),i=n&&!/[\s@]$/.test(n)?" ":"",a=`${n}${i}@${s}`,l=n.length+i.length+1;eB(a),tT(sy(a.slice(0,l))),tz(!0),requestAnimationFrame(()=>{t.focus(),t.setSelectionRange(l,l)});return}if(tP&&!n){if("ArrowDown"===e.key){e.preventDefault(),tF(e=>Math.min(Math.max(0,(K?.length??0)-1),e+1));return}if("ArrowUp"===e.key){e.preventDefault(),tF(e=>Math.max(0,e-1));return}if("Escape"===e.key){e.preventDefault(),tE(!1);return}if(("Tab"===e.key||"Enter"===e.key&&!e.shiftKey)&&K?.[tW]){e.preventDefault(),oB(K[tW]);return}}if(tx&&null!==og){if("ArrowDown"===e.key){e.preventDefault(),ty(oG("down"));return}if("ArrowUp"===e.key){e.preventDefault(),ty(oG("up"));return}if("ArrowRight"===e.key){e.preventDefault(),ty(oG("right"));return}if("ArrowLeft"===e.key){e.preventDefault(),ty(oG("left"));return}if("Escape"===e.key){e.preventDefault(),tk(!1);return}if(("Tab"===e.key||"Enter"===e.key&&!e.shiftKey)&&om[tv]){e.preventDefault(),oU(om[tv]);return}}if(tR&&null!==tC&&!n){if("ArrowDown"===e.key){e.preventDefault(),tM(e=>Math.min(Math.max(0,oL.length-1),e+1));return}if("ArrowUp"===e.key){e.preventDefault(),tM(e=>Math.max(0,e-1));return}if("Escape"===e.key){e.preventDefault(),tz(!1);return}if(("Tab"===e.key||"Enter"===e.key&&!e.shiftKey)&&oL[tI]){e.preventDefault(),oO(oL[tI]);return}}if(null!==oy&&oz.length>0&&!n){if("ArrowDown"===e.key){e.preventDefault(),oM(e=>Math.min(Math.max(0,oz.length-1),e+1));return}if("ArrowUp"===e.key){e.preventDefault(),oM(e=>Math.max(0,e-1));return}if("Escape"===e.key){e.preventDefault(),ob(null);return}if(("Tab"===e.key||"Enter"===e.key&&!e.shiftKey)&&oz[oI]){e.preventDefault(),oW(oI);return}}if("ArrowUp"===e.key&&!n&&!a&&(K?.length??0)>0&&0===eO.trim().length){e.preventDefault(),tk(!1),tz(!1),tF(0),tE(!0);return}if("Escape"===e.key&&!n&&a&&o){e.preventDefault(),o();return}if("Enter"===e.key&&!e.shiftKey){if("ctrl-enter"===tj&&!(e.ctrlKey||e.metaKey))return;e.preventDefault(),a&&(s||i)?oK(s?"steer":"followup"):oh()}},[a,s,i,o,tx,og,om,tv,oU,oK,oh,oG,tR,tC,oL,tI,oO,oy,oz,oI,oW,tj,el,tP,K,tW,oB,eO]),oY=(0,n.useCallback)(()=>{let e=tO.current;e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[]),oX=(0,n.useCallback)(e=>{let t=Array.from(e.clipboardData?.items??[]),o=t.filter(e=>e.type.startsWith("image/"));if(o.length){e.preventDefault(),oo(o.map(e=>e.getAsFile()).filter(e=>null!==e));return}let r=function(e,t){if(!e)return[];let o=[],r=Array.from(e.files??[]);for(let e of r){let t=e.path;"string"==typeof t&&t.trim()&&o.push(t.trim())}if(o.length>0)return Array.from(new Set(o));for(let t of Array.from(e.items??[]))if("file"===t.kind){let e=t.getAsFile(),r=e?.path;"string"==typeof r&&r.trim()&&o.push(r.trim())}if(o.length>0)return Array.from(new Set(o));for(let t of sk)try{let r=e.getData(t);if(r){let e=function(e){if(!e)return[];let t=e.split(/\r?\n/),o=[];for(let e of t){let t=e.trim();!(!t||t.startsWith("#"))&&"copy"!==t&&"cut"!==t&&(t.startsWith("file://")?o.push(sx(t)):(t.startsWith("/")||/^[a-zA-Z]:[\\/]/.test(t))&&o.push(t))}return o}(r);e.length>0&&o.push(...e)}}catch{}if(o.length>0)return Array.from(new Set(o));try{let t=e.getData("text/plain")||e.getData("text");if(t){let e=t.split(/\r?\n/).map(e=>e.trim()).filter(Boolean),r=e.filter(e=>e.startsWith("file://"));if(r.length>0&&r.length===e.length)for(let e of r)o.push(sx(e))}}catch{}if(o.length>0)return Array.from(new Set(o));if(t?.fallbackToFileName&&r.length>0)for(let e of r)e.name&&o.push(e.name);return Array.from(new Set(o))}(e.clipboardData,{fallbackToFileName:!0});if(r.length>0){e.preventDefault();let t=function(e,t=" "){return e&&0!==e.length?1===e.length?e[0]:e.map(e=>{let t=e.trim();return!/\s/.test(t)||t.startsWith('"')||t.startsWith("'")?t:`"${t}"`}).join(t):""}(r),o=tO.current,n=o?.selectionStart??eO.length,s=o?.selectionEnd??eO.length;eB(eO.slice(0,n)+t+eO.slice(s)),requestAnimationFrame(()=>{if(o){let e=n+t.length;o.selectionStart=e,o.selectionEnd=e,oY()}});return}if(!t.find(e=>e.type.startsWith("text/plain")))return;let n=e.clipboardData.getData("text/plain");if(!n)return;let s=n.split(/\r?\n/).length;if(n.length<2e3&&s<20)return;e.preventDefault();let i=`paste-${++eX.current}`,a=eA("desktop.pastedLabel",{id:eX.current,lines:s}),l=tO.current,d=l?.selectionStart??eO.length,c=l?.selectionEnd??eO.length,p=eO.slice(0,d),u=eO.slice(c),h=!(p.length>0)||p.endsWith("\n")||p.endsWith(" ")?"":"\n\n";eB(p+h+a+u),e_(e=>[...e,{id:i,label:a,text:n}]),requestAnimationFrame(()=>{if(!l)return;let e=d+h.length+a.length;l.setSelectionRange(e,e),l.focus()})},[oo,eA,eO,oY]);(0,n.useEffect)(()=>{tW>=(K?.length??0)&&tF(Math.max(0,(K?.length??0)-1))},[tW,K]),(0,n.useEffect)(()=>{t2.current.length=K?.length??0},[K]),(0,n.useEffect)(()=>{tP&&t2.current[tW]?.scrollIntoView({block:"nearest",inline:"nearest"})},[tW,tP]),(0,n.useEffect)(()=>{if(null===og){tk(!1),ty(0),tQ.current=!1;return}tk(!0),ty(0),!tQ.current&&et&&(tQ.current=!0,Promise.resolve(et()).catch(()=>{tQ.current=!1}))},[og,et]),(0,n.useEffect)(()=>{tv>=om.length&&ty(Math.max(0,om.length-1))},[om.length,tv]),(0,n.useEffect)(()=>{t0.current.length=om.length},[om.length]),(0,n.useEffect)(()=>{tx&&t0.current[tv]?.scrollIntoView({block:"nearest",inline:"nearest"})},[tv,tx]);let oZ=c&&c.length>0?c.map(e=>({provider:e.provider,modelId:e.id,name:e.name})).sort(ig):Object.entries(d??{}).map(([e,t])=>({provider:l?.provider??"unknown",modelId:e,name:t})).sort(ig),oQ=[];for(let e of oZ){let t=oQ.find(t=>t.provider===e.provider);t?t.options.push(e):oQ.push({provider:e.provider,options:[e]})}let o0=l?oZ.find(e=>e.modelId===l.modelId&&e.provider===l.provider)?.name??l.modelId:null,o1=w?Math.max(0,w.tokensBefore-w.estimatedTokensAfter):0,o2=w?`${eA("desktop.compacted")} ${ik(w.tokensBefore)} -> ${ik(w.estimatedTokensAfter)} ${eA("desktop.tokens")} (${ik(o1)} ${eA("desktop.saved")})`:null,o4="auto"!==(eg=H??"auto")&&_?_[eg]??eN[eg]:eN[eg],o6=Object.entries(iu).find(([,e])=>e===(j??"default"))?.[0],o8="plan"===j?eA("desktop.planModeLabel"):eL[o6??"default"];(0,n.useEffect)(()=>{let e=e=>{tB.current&&!tB.current.contains(e.target)&&tU.current&&!tU.current.contains(e.target)&&eQ(!1),tq.current&&!tq.current.contains(e.target)&&tt(!1),tK.current&&!tK.current.contains(e.target)&&td(!1),tG.current&&!tG.current.contains(e.target)&&ts(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,n.useEffect)(()=>{let e=null,t=()=>{e=null;let t=window.visualViewport;e4({height:t?.height??window.innerHeight,width:t?.width??window.innerWidth,offsetTop:t?.offsetTop??0})},o=()=>{null!==e&&window.cancelAnimationFrame(e),e=window.requestAnimationFrame(t)};return o(),window.addEventListener("resize",o),window.visualViewport?.addEventListener("resize",o),window.visualViewport?.addEventListener("scroll",o),window.addEventListener("focusin",o),window.addEventListener("focusout",o),window.addEventListener("pageshow",o),()=>{window.removeEventListener("resize",o),window.visualViewport?.removeEventListener("resize",o),window.visualViewport?.removeEventListener("scroll",o),window.removeEventListener("focusin",o),window.removeEventListener("focusout",o),window.removeEventListener("pageshow",o),null!==e&&window.cancelAnimationFrame(e)}},[]),(0,n.useEffect)(()=>{eZ&&t_.current?.focus()},[eZ]);let[o5,o3]=(0,n.useState)(null);return(0,n.useEffect)(()=>{if(!el||!ed)return void o3(null);let e=!1,t=async()=>{try{let t=await fetch("/api/tasks/projects"),{projects:o}=await t.json(),r=o.find(e=>el===e||el.startsWith(e+"/")||e.startsWith(el+"/"));if(!r){e||o3(null);return}let n=await (0,sS.Vk)(r);if(e)return;o3({running:n.filter(e=>["running","awaiting_input","preparing","merging"].includes(e.status)).length,todo:n.filter(e=>["todo","queued"].includes(e.status)).length})}catch{e||o3(null)}};t();let o=new EventSource("/api/tasks/events");return o.onmessage=()=>void t(),()=>{e=!0,o.close()}},[el,ed]),(0,r.jsxs)("div",{style:{flexShrink:0,background:"transparent",padding:"0 16px 15px",paddingRight:eD?16:34},children:[(0,r.jsx)("input",{ref:tY,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:e=>{oo(Array.from(e.target.files??[])),e.target.value=""}}),(0,r.jsxs)("div",{style:{maxWidth:820,margin:"0 auto"},children:[o5&&(o5.running>0||o5.todo>0)&&(0,r.jsxs)("button",{type:"button",onClick:()=>window.dispatchEvent(new CustomEvent("pi:open-tasks-view")),title:eA("desktop.taskStatusHint"),style:{display:"inline-flex",alignItems:"center",gap:6,marginBottom:8,padding:"3px 10px",borderRadius:999,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",fontSize:11,cursor:"pointer",transition:"border-color 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:[(0,r.jsx)(I.m,{size:12,"aria-hidden":"true"}),o5.running>0&&(0,r.jsxs)("span",{style:{color:"var(--accent)"},children:[o5.running," ",eA("desktop.taskRunning")]}),o5.running>0&&o5.todo>0&&(0,r.jsx)("span",{"aria-hidden":"true",children:"\xb7"}),o5.todo>0&&(0,r.jsxs)("span",{children:[o5.todo," ",eA("desktop.taskTodo")]})]}),p&&p.length>0&&(0,r.jsx)("div",{role:"status",style:{marginBottom:8,padding:"6px 10px",borderRadius:6,border:"1px solid color-mix(in srgb, var(--accent-orange) 45%, var(--border))",background:"color-mix(in srgb, var(--accent-orange) 9%, var(--bg-panel))",color:"var(--text-muted)",fontSize:12,lineHeight:1.45},children:p.join(" ")}),(V?.steering.length??0)+(V?.followUp.length??0)>0&&(0,r.jsxs)("div",{style:{marginBottom:8,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",padding:"5px 0"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,padding:"2px 8px 4px 10px"},children:[(0,r.jsxs)("span",{style:{fontSize:10,fontFamily:"var(--font-mono)",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:.4},children:[eA("desktop.queued")," \xb7 ",(V?.steering.length??0)+(V?.followUp.length??0)]}),G&&(0,r.jsxs)("button",{onClick:G,title:eA("desktop.recallQueuedMessages"),style:{display:"flex",alignItems:"center",gap:6,padding:"4px 12px",fontSize:12,color:"var(--text)",background:"transparent",border:"1px solid var(--border)",borderRadius:7,cursor:"pointer",transition:"background 0.12s, border-color 0.12s",whiteSpace:"nowrap"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.borderColor="color-mix(in srgb, var(--accent) 45%, var(--border))"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.borderColor="var(--border)"},children:[(0,r.jsx)(sC.Y,{size:13}),eA("desktop.recallToInput")]})]}),V?.steering.map((e,t)=>(0,r.jsx)(iI,{kind:"steer",label:eA("desktop.steer"),text:e,index:t,total:V.steering.length,onMove:J?e=>void ol("steer",t,e):void 0,onRecall:Y?()=>void oc("steer",t):void 0,onRemove:Z?()=>void od("steer",t):void 0},`steer-${t}`)),V?.followUp.map((e,t)=>(0,r.jsx)(iI,{kind:"follow-up",label:eA("desktop.followUp"),text:e,index:t,total:V.followUp.length,onMove:J?e=>void ol("followUp",t,e):void 0,onRecall:Y?()=>void oc("followUp",t):void 0,onRemove:Z?()=>void od("followUp",t):void 0},`followup-${t}`))]}),oe&&(0,r.jsx)("div",{style:{marginBottom:8,padding:"5px 10px",borderRadius:6,border:"1px solid color-mix(in srgb, var(--accent) 40%, var(--border))",background:"color-mix(in srgb, var(--accent) 8%, var(--bg-panel))",color:"var(--text-muted)",fontSize:12},children:eA("desktop.recalledEditing")}),q&&(0,r.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,r.jsx)(C.B,{size:11,style:{flexShrink:0}}),eA("desktop.retrying")," (",q.attempt,"/",q.maxAttempts,")…",q.errorMessage&&(0,r.jsxs)("span",{style:{opacity:.7,marginLeft:4},children:["— ",q.errorMessage]})]}),o2&&(0,r.jsxs)("div",{style:{marginBottom:8,padding:"5px 10px",background:"rgba(16,185,129,0.08)",border:"1px solid rgba(16,185,129,0.24)",borderRadius:6,fontSize:12,color:"rgba(5,150,105,0.95)",display:"flex",alignItems:"center",gap:6},children:[(0,r.jsx)(m.S,{size:11,style:{flexShrink:0}}),o2]}),tu.length>0&&(0,r.jsx)("div",{style:{display:"flex",gap:6,marginBottom:6,flexWrap:"wrap"},children:tu.map((e,t)=>(0,r.jsxs)("div",{style:{position:"relative",flexShrink:0},children:[(0,r.jsx)("img",{src:e.previewUrl,alt:"",style:{width:56,height:56,objectFit:"cover",borderRadius:6,border:"1px solid var(--border)",display:"block"}}),(0,r.jsx)("button",{onClick:()=>os(t),title:eA("desktop.removeImage"),"aria-label":eA("desktop.removeImage"),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,r.jsx)(h.u,{size:8})})]},t))}),(0,r.jsxs)("div",{style:{position:"relative"},children:[tP&&K.length>0&&(0,r.jsxs)("div",{style:{position:"absolute",left:0,right:0,bottom:"calc(100% + 8px)",zIndex:120,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -6px 20px rgba(0,0,0,0.12)",overflow:"hidden",maxHeight:"min(38vh, 300px)"},children:[(0,r.jsxs)("div",{style:{padding:"4px 8px",borderBottom:"1px solid var(--border)",display:"flex",justifyContent:"space-between",color:"var(--text-dim)",fontSize:11},children:[(0,r.jsx)("span",{children:eA("desktop.inputHistory")}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)"},children:eA("desktop.tabOrEnter")})]}),(0,r.jsx)("div",{style:{maxHeight:"calc(min(38vh, 300px) - 24px)",overflowY:"auto",padding:4},children:K.map((e,t)=>(0,r.jsxs)("button",{ref:e=>{t2.current[t]=e},type:"button",onMouseDown:t=>{t.preventDefault(),oB(e)},onMouseEnter:()=>tF(t),style:{width:"100%",display:"flex",alignItems:"flex-start",gap:8,padding:"5px 6px",border:"none",borderRadius:5,background:t===tW?"var(--bg-selected)":"transparent",color:"var(--text)",cursor:"pointer",textAlign:"left"},children:[(0,r.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11},children:t+1}),(0,r.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:12},children:e})]},`${t}:${e}`))})]}),tx&&null!==og&&(0,r.jsxs)("div",{style:{position:"absolute",left:0,right:0,bottom:"calc(100% + 8px)",zIndex:120,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -6px 20px rgba(0,0,0,0.12)",overflow:"hidden",maxHeight:"min(38vh, 300px)"},children:[(0,r.jsxs)("div",{style:{padding:"4px 8px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,fontSize:11,color:"var(--text-dim)"},children:[(0,r.jsx)("span",{children:ee?eA("desktop.loadingCommands"):`${eA("desktop.slashCommands")} \xb7 ${ox}`}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)"},children:eA("desktop.tabOrEnter")})]}),(0,r.jsx)("div",{style:{maxHeight:"calc(min(38vh, 300px) - 24px)",overflowY:"auto",padding:4},children:ee||0!==om.length?of.map(e=>(0,r.jsxs)("section",{style:{marginBottom:6},children:[(0,r.jsxs)("div",{style:{position:"sticky",top:-4,zIndex:1,display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,padding:"2px 0 4px",background:"var(--bg)",color:"var(--text-dim)",fontSize:10,fontWeight:600,textTransform:"uppercase"},children:[(0,r.jsx)("span",{children:eH[e.source]}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontWeight:500},children:e.items.length})]}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:1},children:e.items.map(({command:e,index:t})=>{let o=t===tv;return(0,r.jsxs)("button",{ref:e=>{t0.current[t]=e},type:"button",onMouseDown:t=>{t.preventDefault(),oU(e)},onMouseEnter:()=>ty(t),style:{width:"100%",display:"flex",alignItems:"center",gap:8,padding:"3px 6px",border:"none",borderRadius:5,background:o?"var(--bg-selected)":"none",color:"var(--text)",cursor:"pointer",textAlign:"left"},children:[(0,r.jsxs)("span",{style:{fontSize:12.5,fontFamily:"var(--font-mono)",whiteSpace:"nowrap",flexShrink:0},children:["/",e.name]}),e.description&&(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:e.description}),iw(e,tb)&&(0,r.jsx)("span",{style:{marginLeft:"auto",flexShrink:0,padding:"1px 5px",borderRadius:999,border:"1px solid var(--border)",color:"var(--text-dim)",fontSize:10},children:eA("desktop.dormant")})]},`${e.source}:${e.name}`)})})]},e.source)):(0,r.jsx)("div",{style:{padding:"2px 2px 2px",fontSize:12,color:"var(--text-dim)"},children:eA("desktop.noSlashCommands")})})]}),tR&&null!==tC&&(em=tN&&(!tD||tD.cwd!==el),ef=`${oL.length} ${eA(1===oL.length?"desktop.match":"desktop.matches")}`,ex=tD?.truncated&&!oN?tC.query?` \xb7 ${eA("desktop.searchingAllFiles")}`:` \xb7 ${eA("desktop.indexTruncated")}`:"",(0,r.jsxs)("div",{style:{position:"absolute",left:0,right:0,bottom:"calc(100% + 8px)",zIndex:120,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -6px 20px rgba(0,0,0,0.12)",overflow:"hidden",maxHeight:"min(30vh, 240px)"},children:[(0,r.jsxs)("div",{style:{padding:"4px 8px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,fontSize:11,color:"var(--text-dim)"},children:[(0,r.jsx)("span",{children:em?eA("desktop.loadingFiles"):`${eA("desktop.files")} \xb7 ${ef}${ex}`}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)"},children:eA("desktop.tabOrEnter")})]}),(0,r.jsx)("div",{style:{maxHeight:"calc(min(30vh, 240px) - 24px)",overflowY:"auto",padding:2},children:em||0!==oL.length?oL.map((e,t)=>{let o=t===tI,n=e.path.split("/").pop()??e.path,s=e.path.slice(0,e.path.length-n.length);return(0,r.jsxs)("button",{ref:e=>{t1.current[t]=e},type:"button",onMouseDown:t=>{t.preventDefault(),oO(e)},onMouseEnter:()=>tM(t),style:{width:"100%",display:"flex",alignItems:"center",gap:5,padding:"3px 6px",border:"none",borderRadius:5,background:o?"var(--bg-selected)":"none",color:"var(--text)",cursor:"pointer",textAlign:"left",fontSize:12.5,fontFamily:"var(--font-mono)"},children:[(0,r.jsx)("span",{style:{flexShrink:0,display:"flex",alignItems:"center"},children:e.isDir?(0,r.jsx)(eo,{size:14,name:n}):ea(n,14)}),(0,r.jsxs)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[s&&(0,r.jsx)("span",{style:{color:"var(--text-dim)"},children:s}),n,e.isDir&&(0,r.jsx)("span",{style:{color:"var(--text-dim)"},children:"/"})]})]},`${e.isDir?"d":"f"}:${e.path}`)}):(0,r.jsx)("div",{style:{padding:"4px 6px",fontSize:12,color:"var(--text-dim)"},children:oA&&!oN?eA("desktop.searching"):eA("desktop.noMatchingFiles")})})]})),null!==oy&&oz.length>0&&(0,r.jsxs)("div",{style:{position:"absolute",left:0,right:0,bottom:"calc(100% + 8px)",zIndex:120,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -6px 20px rgba(0,0,0,0.12)",overflow:"hidden",maxHeight:"min(30vh, 240px)"},children:[(0,r.jsx)("div",{style:{padding:"4px 8px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:(0,r.jsxs)("span",{style:{fontSize:11,color:"var(--text-dim)",fontWeight:600},children:[oz.length," ",eA("desktop.snippetMatches")]})}),(0,r.jsx)("div",{style:{maxHeight:"min(26vh, 210px)",overflowY:"auto"},children:oz.map((e,t)=>(0,r.jsxs)("button",{type:"button",onMouseEnter:()=>oM(t),onClick:()=>oW(t),style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"6px 10px",background:t===oI?"var(--bg-selected)":"none",border:"none",color:t===oI?"var(--accent)":"var(--text)",cursor:"pointer",fontSize:12,textAlign:"left"},children:[(0,r.jsx)("span",{style:{color:"var(--accent)",fontFamily:"var(--font-mono)",fontSize:11},children:"#"}),(0,r.jsx)("span",{style:{fontWeight:600,flexShrink:0},children:e.name}),(0,r.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-muted)",fontSize:11},children:e.content.split("\n")[0]})]},e.id))})]}),(0,r.jsxs)("div",{className:`chat-input-shell ${a&&(s||i)?"is-streaming":""} ${"yolo"===E?"is-yolo":""}`,ref:tV,onClick:e=>{e.target.closest("button, input, select, [role=button]")||tO.current?.focus()},style:{display:"flex",flexDirection:"column",alignItems:"stretch",gap:0,padding:0,transition:"border-color 0.15s, background 0.15s, box-shadow 0.15s"},children:[a&&(0,r.jsx)("div",{className:"chat-input-streaming-overlay hatch-45","aria-hidden":"true"}),a&&(s||i)&&(0,r.jsxs)("div",{className:"chat-input-streaming-actions",children:[s&&(0,r.jsx)("button",{type:"button",className:"chat-input-streaming-action chat-input-streaming-action-steer",onClick:()=>oK("steer"),disabled:!ok,title:eA("desktop.injectMessageNow"),"aria-label":eA("desktop.steer"),children:(0,r.jsx)(sT.A,{size:15})}),i&&(0,r.jsx)("button",{type:"button",className:"chat-input-streaming-action",onClick:()=>oK("followup"),disabled:!ok,title:eA("desktop.queueMessageAfterFinish"),"aria-label":eA("desktop.followUp"),children:(0,r.jsx)(sI.M,{size:15})})]}),eG&&(0,r.jsx)("div",{role:"alert",style:{margin:"0 0 6px",padding:"4px 8px",fontSize:11,lineHeight:1.5,color:"var(--error, #e5484d)",border:"1px solid var(--error, #e5484d)",borderRadius:6},children:eG}),eU.length>0&&(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:4,marginBottom:6},children:eU.map(e=>{let t=eq.includes(e.id);return(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"4px 8px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-secondary)",fontSize:11,color:"var(--text-muted)"},children:[(0,r.jsx)(sz.d,{size:12,"aria-hidden":"true"}),(0,r.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)"},children:e.label}),(0,r.jsx)("button",{type:"button",onClick:()=>eV(o=>t?o.filter(t=>t!==e.id):[...o,e.id]),title:eA(t?"desktop.pastedHidePreview":"desktop.pastedShowPreview"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:2,display:"flex"},children:(0,r.jsx)(sR.b,{size:12,"aria-hidden":"true"})}),(0,r.jsx)("button",{type:"button",onClick:()=>{e_(t=>t.filter(t=>t.id!==e.id)),eB(t=>t.split(e.label).join(""))},title:eA("desktop.pastedRemove"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:2,display:"flex"},children:(0,r.jsx)(T.u,{size:12,"aria-hidden":"true"})}),t&&(0,r.jsx)("div",{style:{position:"relative"},children:(0,r.jsx)("pre",{style:{position:"absolute",left:0,right:0,top:"calc(100% + 4px)",zIndex:50,maxHeight:200,overflow:"auto",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:6,padding:"8px 10px",fontSize:11,lineHeight:1.5,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:e.text})})]},e.id)})}),(0,r.jsxs)("div",{className:"chat-input-editor-row",style:{borderColor:tm?"var(--tool-bg)":void 0},children:["goal"===P&&F&&"idle"!==F.status&&(0,r.jsxs)("span",{style:{flexShrink:0,display:"inline-flex",alignItems:"center",gap:6,marginRight:8,padding:"2px 8px",borderRadius:6,background:"complete"===F.status?"color-mix(in srgb, var(--accent-green, #22c55e) 14%, transparent)":"blocked"===F.status||"paused"===F.status?"color-mix(in srgb, #f59e0b 14%, transparent)":"color-mix(in srgb, var(--accent) 12%, transparent)",color:"complete"===F.status?"var(--accent-green, #22c55e)":"blocked"===F.status||"paused"===F.status?"#f59e0b":"var(--accent)",fontSize:11,fontWeight:600,whiteSpace:"nowrap",userSelect:"none"},title:F.goalText??"",children:[(0,r.jsx)(nw.d,{size:12,weight:"fill","aria-hidden":"true"}),"running"===F.status&&(0,r.jsxs)("span",{children:[eA("desktop.goalRunning")," \xb7 ",F.turnsUsed,"/",F.turnsLimit]}),"complete"===F.status&&(0,r.jsx)("span",{children:eA("desktop.goalComplete")}),"blocked"===F.status&&(0,r.jsx)("span",{children:eA("desktop.goalBlocked")}),"paused"===F.status&&(0,r.jsx)("span",{children:eA("desktop.goalPaused")}),F.noProgressTurns>0&&"running"===F.status&&(0,r.jsxs)("span",{style:{opacity:.8},children:["\xb7 ",eA("desktop.goalNoProgress",{n:F.noProgressTurns})]}),"running"===F.status&&(0,r.jsx)("button",{type:"button",onClick:N,title:eA("desktop.goalPause"),"aria-label":eA("desktop.goalPause"),style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:16,height:16,padding:0,background:"none",border:"none",borderRadius:4,color:"inherit",cursor:"pointer",fontSize:11},children:eA("desktop.goalPauseShort")}),("paused"===F.status||"blocked"===F.status)&&(0,r.jsx)("button",{type:"button",onClick:L,title:eA("desktop.goalResume"),"aria-label":eA("desktop.goalResume"),style:{display:"inline-flex",alignItems:"center",justifyContent:"center",padding:"0 4px",background:"none",border:"none",borderRadius:4,color:"inherit",cursor:"pointer",fontSize:11,fontWeight:600},children:eA("desktop.goalResumeShort")}),(0,r.jsx)("button",{type:"button",onClick:$,title:eA("desktop.goalStop"),"aria-label":eA("desktop.goalStop"),style:{display:"inline-flex",alignItems:"center",justifyContent:"center",padding:"0 3px",background:"none",border:"none",borderRadius:4,color:"inherit",cursor:"pointer",fontSize:11,opacity:.75},children:"✕"})]}),(0,r.jsx)("textarea",{ref:tO,value:eO,spellCheck:!1,onChange:e=>{eB(e.target.value),ov(e.target.value,e.target.selectionStart),oP(e.target.value,e.target.selectionStart)},onSelect:e=>{let t=e.currentTarget;ov(t.value,t.selectionStart)},onKeyDown:oJ,onCompositionStart:()=>{tX.current=!0},onCompositionEnd:e=>{tX.current=!1,tZ.current=Date.now();let t=e.currentTarget;ov(t.value,t.selectionStart)},onInput:oY,onPaste:oX,placeholder:a&&(s||i)?eA("desktop.steerOrQueueFollowUp"):a?eA("desktop.agentRunning"):eA("desktop.messageWithCommands"),rows:1,className:"chat-input-textarea",style:{flex:1,background:"none",border:"none",outline:"none",resize:"none",color:"var(--text)",minHeight:24,maxHeight:200,padding:0,overflow:"auto"}})]}),tm&&(0,r.jsxs)("div",{style:{marginTop:4,padding:"2px 8px",fontSize:11,color:tf?"var(--text-muted)":"var(--accent)"},children:[eA("desktop.shellCommand")," \xb7 ",tf?eA("desktop.shellOutputLocal"):eA("desktop.shellOutputModel")]}),(0,r.jsxs)("div",{className:"chat-input-toolbar",style:{display:eD?"grid":"flex",gridTemplateColumns:eD?"auto auto minmax(0, 1fr)":void 0,alignItems:"center",gap:4},children:[(0,r.jsxs)("div",{ref:tG,className:"chat-input-toolbar-attach",style:{position:"relative"},children:[(0,r.jsx)("button",{onClick:e=>{let t=e.currentTarget.getBoundingClientRect();ta({top:t.top,left:t.left,width:t.width}),ts(e=>!e)},title:eA("desktop.attachMenu"),"aria-label":eA("desktop.attachMenu"),"aria-expanded":tn,style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:24,height:24,padding:0,background:tn?"var(--bg-hover)":"none",border:"none",borderRadius:6,color:tu.length?"var(--accent)":"var(--text-muted)",cursor:"pointer",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=tu.length?"var(--accent)":"var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background=tn?"var(--bg-hover)":"none",e.currentTarget.style.color=tu.length?"var(--accent)":"var(--text-muted)"},children:(0,r.jsx)(v.c,{size:14})}),tn&&ti&&(ek=[{id:"upload",label:eA("desktop.attachUpload"),desc:eA("desktop.attachUploadDesc"),icon:R.J},{id:"reference",label:eA("desktop.attachReference"),desc:eA("desktop.attachReferenceDesc"),icon:n5.sj},{id:"sessions",label:eA("desktop.attachSessions"),desc:eA("desktop.attachSessionsDesc"),icon:sM.v},{id:"slash",label:eA("desktop.attachCommands"),desc:eA("desktop.attachCommandsDesc"),icon:g.C}],ev=window.visualViewport?.height??window.innerHeight,ey=window.innerWidth,eb=Math.min(ti.left,ey-220-8),ew=ev-ti.top+6,(0,r.jsx)("div",{role:"menu",style:{position:"fixed",left:eb,bottom:ew,zIndex:1200,width:220,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:12,boxShadow:"0 12px 32px rgba(0,0,0,0.22)",padding:4},children:ek.map(e=>(0,r.jsxs)("button",{type:"button",role:"menuitem",onClick:()=>{ts(!1),"upload"===e.id?tY.current?.click():"reference"===e.id?o_():"sessions"===e.id?oq():"slash"===e.id&&oV()},style:{display:"flex",alignItems:"center",gap:10,width:"100%",padding:"8px 10px",background:e.active?"var(--bg-selected)":"none",border:"none",borderRadius:8,cursor:"pointer",textAlign:"left",transition:"background 0.12s"},onMouseEnter:t=>{e.active||(t.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:t=>{t.currentTarget.style.background=e.active?"var(--bg-selected)":"none"},children:[(0,r.jsx)(e.icon,{size:16,weight:e.active?"fill":"regular",color:e.active?"var(--accent)":"var(--text-muted)","aria-hidden":"true"}),(0,r.jsxs)("span",{style:{flex:1,minWidth:0},children:[(0,r.jsx)("span",{style:{display:"block",fontSize:12.5,fontWeight:550,color:"var(--text)"},children:e.label}),(0,r.jsx)("span",{style:{display:"block",fontSize:10.5,color:"var(--text-muted)",marginTop:1,lineHeight:1.4},children:e.desc})]}),e.active?(0,r.jsx)(m.S,{size:12,weight:"bold",color:"var(--accent)","aria-hidden":"true"}):null]},e.id))}))]}),(0,r.jsx)("div",{className:"chat-input-toolbar-left",style:{flex:"0 0 auto",minWidth:0,display:"flex",alignItems:"center",gap:2},children:!eD&&W&&(0,r.jsx)(ic,{collaborationMode:P,onCollaborationModeChange:W,disabled:a})}),!eD&&(0,r.jsx)("div",{className:"chat-input-toolbar-spacer",style:{flex:1}}),(0,r.jsx)("div",{ref:tJ,className:"chat-input-toolbar-controls",style:{flex:eD?"1 1 auto":"0 1 auto",minWidth:0,display:"flex",alignItems:"center",justifyContent:"flex-end",position:"relative",marginLeft:eD?0:"auto"},children:(0,r.jsxs)("div",{className:"chat-input-toolbar-actions",style:{display:"flex",alignItems:"center",gap:eD?1:2,flexWrap:"wrap",justifyContent:"flex-end",...eD?{flex:"1 1 auto",minWidth:0}:null},children:[B&&(0,r.jsxs)("div",{ref:tK,className:"chat-input-toolbar-thinking",style:{position:"relative"},children:[(0,r.jsxs)("button",{onClick:e=>{if(a)return;let t=e.currentTarget.getBoundingClientRect();tp({top:t.top,left:t.left,width:t.width}),td(e=>!e)},disabled:a,title:eA("desktop.changeReasoningLevel",{level:o4}),"aria-label":eA("desktop.reasoningLevel"),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,padding:eD?"0 5px":"3px 7px",width:eD?"auto":void 0,height:24,background:tl?"var(--bg-hover)":"none",border:"none",borderRadius:6,color:(H??"auto")==="off"?"var(--text-dim)":"var(--accent)",cursor:a?"not-allowed":"pointer",fontSize:12,opacity:a?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{a||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{e.currentTarget.style.background=tl?"var(--bg-hover)":"none"},children:[(0,r.jsx)(ix,{level:H??"auto"}),(0,r.jsx)("span",{style:{whiteSpace:"nowrap"},children:o4}),(0,r.jsx)(k.b,{size:11,weight:"bold","aria-hidden":"true",style:{transform:tl?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.12s"}})]}),tl&&tc&&(ej=window.visualViewport?.height??window.innerHeight,eC=Math.min(240,(eS=window.innerWidth)-16),eT=Math.min(tc.left,eS-eC-8),eR=ej-tc.top+4,ez=Math.min(360,Math.max(120,Math.min(tc.top-8,.6*ej))),(0,r.jsx)("div",{style:{position:"fixed",bottom:eR,left:eT,zIndex:2001,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 4px 24px rgba(0,0,0,0.12)",overflow:"hidden",minWidth:200,maxWidth:eC,maxHeight:ez,overflowY:"auto"},children:im.filter(e=>!U||"auto"===e||U.includes(e)).map(e=>{let t=(H??"auto")===e,o="auto"!==e&&_?_[e]:void 0,n=null!=o&&o!==e?o:eN[e],s=null!=o&&o!==e;return(0,r.jsxs)("button",{onClick:()=>{td(!1),t||B(e)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"6px 12px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--accent)":"var(--text)",cursor:"pointer",fontSize:12,textAlign:"left",fontFamily:"var(--font-mono)",whiteSpace:"nowrap"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,r.jsx)(ix,{level:e,size:14}),(0,r.jsxs)("span",{style:{flex:1},children:[n,s&&(0,r.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",marginLeft:5},children:["(",e,")"]})]}),t&&(0,r.jsx)(m.S,{size:12,weight:"bold",color:"var(--accent)",style:{flexShrink:0}})]},e)})}))]}),S&&"plan"===j&&(0,r.jsxs)("div",{ref:tq,className:"chat-input-toolbar-tools",style:{position:"relative"},children:[" ",(0,r.jsxs)("button",{onClick:e=>{if(a)return;let t=e.currentTarget.getBoundingClientRect();tr({top:t.top,left:t.left,width:t.width}),tt(e=>!e)},disabled:a,title:eA("desktop.changeToolPreset",{preset:o8}),"aria-label":eA("desktop.toolPreset"),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,padding:eD?"0 5px":"3px 7px",width:eD?"auto":void 0,height:24,background:te?"var(--bg-hover)":"none",border:"none",borderRadius:6,color:"var(--text-muted)",cursor:a?"not-allowed":"pointer",fontSize:12,opacity:a?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{a||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=te?"var(--bg-hover)":"none",e.currentTarget.style.color="var(--text-muted)"},children:[(0,r.jsx)("span",{style:{whiteSpace:"nowrap"},children:o8}),(0,r.jsx)(k.b,{size:11,weight:"bold","aria-hidden":"true",style:{transform:te?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.12s"}})]}),te&&to&&(eI=window.visualViewport?.height??window.innerHeight,eP=Math.min(200,(eM=window.innerWidth)-16),eE=Math.max(8,eM-(to.left+to.width)),eW=eI-to.top+6,eF=Math.min(320,Math.max(100,Math.min(to.top-8,.5*eI))),(0,r.jsx)("div",{style:{position:"fixed",bottom:eW,right:eE,zIndex:2001,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 4px 24px rgba(0,0,0,0.12)",overflow:"hidden",minWidth:120,maxWidth:eP,maxHeight:eF,overflowY:"auto"},children:ip.map(e=>{let t=iu[e],o="plan"!==j&&(j??"default")===t,n="off"===e?eA("desktop.noToolsReadOnly"):"default"===e?eA("desktop.fourBuiltInTools"):eA("desktop.allBuiltInTools");return(0,r.jsxs)("button",{onClick:()=>{tt(!1),o||S(t)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"6px 12px",background:o?"var(--bg-selected)":"none",border:"none",color:o?"var(--accent)":"var(--text)",cursor:"pointer",fontSize:12,textAlign:"left",fontFamily:"var(--font-mono)",whiteSpace:"nowrap"},onMouseEnter:e=>{o||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{o||(e.currentTarget.style.background="none")},children:[(0,r.jsx)("span",{style:{flex:1},children:eL[e]}),(0,r.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:n}),o&&(0,r.jsx)(m.S,{size:12,weight:"bold",color:"var(--accent)",style:{flexShrink:0}})]},e)})}))]}),oZ.length>0&&y&&(0,r.jsxs)("div",{ref:tB,className:"chat-input-toolbar-model",style:{position:"relative",flex:eD?"0 1 auto":void 0,minWidth:0},children:[(0,r.jsxs)("button",{onClick:e=>{let t=e.currentTarget.getBoundingClientRect();e1({top:t.top,left:t.left,width:t.width}),eZ||e8(""),eQ(e=>!e)},disabled:a,title:o0??void 0,style:{display:"flex",alignItems:"center",gap:6,justifyContent:eD?"flex-start":void 0,padding:eD?"4px 6px":"3px 7px",height:24,maxWidth:eD?"min(150px, 42vw)":"min(220px, 34vw)",overflow:"hidden",background:eZ?"var(--bg-hover)":"none",border:"none",borderRadius:6,color:"var(--text-muted)",cursor:a?"not-allowed":"pointer",fontSize:12,opacity:a?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{a||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=eZ?"var(--bg-hover)":"none",e.currentTarget.style.color="var(--text-muted)"},children:[(0,r.jsx)(is,{id:l?.provider??"unknown",size:14}),(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:o0??eA("desktop.selectModel")}),(0,r.jsx)(k.b,{size:11,weight:"bold","aria-hidden":"true",style:{flexShrink:0,transform:eZ?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.12s"}})]}),eZ&&e0&&(()=>{let e=e2.height||window.innerHeight,t=e2.width||window.innerWidth,o=e0.top-e2.offsetTop,n=Math.max(6,e-o+6),s=Math.min(400,Math.max(120,Math.min(o-8,.6*e))),i=Math.min(320,s),a=e0.width,d=Math.min(360,t-16),c=eD?{left:8,right:8,maxWidth:"calc(100vw - 16px)"}:{right:Math.max(8,t-(e0.left+e0.width)),width:"max-content",minWidth:Math.min(a,d),maxWidth:d},p=[];for(let e of[...e5]){let[t,o]=e.split(":",2),r=oZ.find(e=>e.provider===t&&e.modelId===o);r&&p.push(r)}let h=e6.trim().toLowerCase(),g=h.length>0,f=e=>e.name.toLowerCase().includes(h)||e.modelId.toLowerCase().includes(h)||e.provider.toLowerCase().includes(h),x=g?p.filter(f):p,v=x.length>0,w=g?oQ.map(e=>({...e,options:e.options.filter(f)})).filter(e=>e.options.length>0):oQ,j=v||w.length>0;return(0,r.jsxs)("div",{ref:tU,className:"chat-input-model-dropdown",style:{position:"fixed",bottom:n,...c,zIndex:2e3,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 4px 24px rgba(0,0,0,0.12)",overflow:"hidden",height:i,maxHeight:s,display:"flex",flexDirection:"column"},children:[(0,r.jsx)("div",{style:{borderBottom:"1px solid var(--border)",flexShrink:0},children:(0,r.jsxs)("div",{style:{position:"relative",display:"flex",alignItems:"center"},children:[(0,r.jsx)(u.$,{size:13,color:"var(--text-dim)",style:{position:"absolute",left:12,pointerEvents:"none"}}),(0,r.jsx)("input",{ref:t_,value:e6,onChange:e=>e8(e.target.value),onKeyDown:e=>{if("Escape"===e.key)e6?e8(""):eQ(!1);else if("ArrowDown"===e.key){let t=tU.current?.querySelector(".model-row button");t&&(e.preventDefault(),t.focus())}},placeholder:eA("desktop.searchModels"),"aria-label":eA("desktop.searchModels"),style:{width:"100%",padding:"5px 12px 5px 34px",background:"transparent",border:"none",outline:"none",color:"var(--text)",fontSize:12,fontFamily:"var(--font-mono)"}})]})}),(0,r.jsxs)("div",{style:{overflowY:"auto",flex:1,minHeight:0},children:[v&&(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{style:{padding:"6px 12px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:eA("desktop.favorites")}),x.map(e=>{let t=e.modelId===l?.modelId&&e.provider===l?.provider,o=e5.has(`${e.provider}:${e.modelId}`);return(0,r.jsx)("div",{className:"model-row",style:{display:"flex",alignItems:"center",width:"100%"},children:(0,r.jsxs)("button",{onClick:()=>{eQ(!1),y(e.provider,e.modelId)},style:{display:"flex",alignItems:"center",gap:8,flex:1,minWidth:0,padding:"6px 12px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--accent)":"var(--text)",cursor:"pointer",fontSize:12,textAlign:"left",fontFamily:"var(--font-mono)",whiteSpace:"nowrap",overflow:"hidden"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,r.jsx)(is,{id:e.provider,size:14}),(0,r.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",minWidth:0},children:e.name}),t&&(0,r.jsx)(m.S,{size:12,weight:"bold",color:"var(--accent)",style:{flexShrink:0}}),(0,r.jsx)("span",{onClick:t=>{t.stopPropagation(),or(e.provider,e.modelId)},className:"model-star",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,cursor:"pointer",color:o?"var(--accent)":"var(--text-dim)",opacity:+!!o,transition:"opacity 0.12s, color 0.12s"},onMouseEnter:e=>{e.stopPropagation(),e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.stopPropagation(),e.currentTarget.style.color=o?"var(--accent)":"var(--text-dim)"},title:o?eA("desktop.unfavorite"):eA("desktop.favorite"),"aria-label":o?eA("desktop.unfavorite"):eA("desktop.favorite"),children:(0,r.jsx)(sF.G,{size:12,weight:o?"fill":"regular"})})]})},`fav-${e.provider}:${e.modelId}`)}),(0,r.jsx)("div",{style:{borderTop:"1px solid var(--border)"}})]}),w.map((e,t)=>{let o=g||e7.has(e.provider),n=o?(0,r.jsx)(k.b,{size:10,color:"var(--text-dim)"}):(0,r.jsx)(b.J,{size:10,color:"var(--text-dim)"});return(0,r.jsxs)("div",{children:[(0,r.jsxs)("button",{onClick:()=>on(e.provider),title:e.provider,style:{display:"flex",alignItems:"center",gap:4,width:"100%",maxWidth:"100%",padding:"6px 12px 4px",background:"none",border:"none",cursor:"pointer",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",overflow:"hidden",whiteSpace:"nowrap",borderTop:t>0?"1px solid var(--border)":"none"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)"},children:[n,(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",minWidth:0},children:e.provider})]}),o&&e.options.map(e=>{let t=e.modelId===l?.modelId&&e.provider===l?.provider,o=e5.has(`${e.provider}:${e.modelId}`);return(0,r.jsx)("div",{className:"model-row",style:{display:"flex",alignItems:"center",width:"100%"},children:(0,r.jsxs)("button",{onClick:()=>{eQ(!1),y(e.provider,e.modelId)},style:{display:"flex",alignItems:"center",gap:8,flex:1,minWidth:0,padding:"6px 12px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--accent)":"var(--text)",cursor:"pointer",fontSize:12,textAlign:"left",fontFamily:"var(--font-mono)",whiteSpace:"nowrap",overflow:"hidden"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,r.jsx)(is,{id:e.provider,size:14}),(0,r.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",minWidth:0},children:e.name}),t&&(0,r.jsx)(m.S,{size:12,weight:"bold",color:"var(--accent)",style:{flexShrink:0}}),(0,r.jsx)("span",{onClick:t=>{t.stopPropagation(),or(e.provider,e.modelId)},className:"model-star",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,cursor:"pointer",color:o?"var(--accent)":"var(--text-dim)",opacity:+!!o,transition:"opacity 0.12s, color 0.12s"},onMouseEnter:e=>{e.stopPropagation(),e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.stopPropagation(),e.currentTarget.style.color=o?"var(--accent)":"var(--text-dim)"},title:o?eA("desktop.unfavorite"):eA("desktop.favorite"),"aria-label":o?eA("desktop.unfavorite"):eA("desktop.favorite"),children:(0,r.jsx)(sF.G,{size:12,weight:o?"fill":"regular"})})]})},`${e.provider}:${e.modelId}`)})]},e.provider)}),g&&!j&&(0,r.jsx)("div",{style:{padding:"14px 12px",textAlign:"center",fontSize:12,color:"var(--text-dim)"},children:eA("desktop.noModelsMatch")})]})]})})()]}),0===oZ.length&&f&&(0,r.jsxs)("div",{className:"chat-input-toolbar-model",title:`${eA("desktop.modelsLoadFailed")}: ${f}`,style:{display:"flex",alignItems:"center",gap:6,flex:eD?"1 1 auto":void 0,minWidth:0,padding:"3px 7px",height:24,background:"rgba(239,68,68,0.10)",border:"none",borderRadius:6,fontSize:12,overflow:"hidden"},children:[(0,r.jsx)(r0.M,{size:14,color:"#ef4444",weight:"fill",style:{flexShrink:0}}),(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0,color:"#ef4444"},children:eA("desktop.modelsLoadFailed")}),x&&(0,r.jsx)("button",{type:"button",onClick:x,style:{display:"inline-flex",alignItems:"center",gap:4,flexShrink:0,padding:"1px 6px",background:"rgba(239,68,68,0.14)",border:"none",borderRadius:4,color:"#ef4444",cursor:"pointer",fontSize:11,fontWeight:600,transition:"background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.24)"},onMouseLeave:e=>{e.currentTarget.style.background="rgba(239,68,68,0.14)"},children:eA("desktop.retry")})]}),0===oZ.length&&!f&&(0,r.jsxs)("div",{className:"chat-input-toolbar-model",title:eA("desktop.noModelsConfigured"),style:{display:"flex",alignItems:"center",gap:6,flex:eD?"1 1 auto":void 0,minWidth:0,padding:"3px 7px",height:24,background:"var(--bg-hover)",border:"none",borderRadius:6,color:"var(--text-dim)",fontSize:12,overflow:"hidden"},children:[(0,r.jsx)(r0.M,{size:14,color:"var(--text-dim)",style:{flexShrink:0}}),(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:eA("desktop.noModelsConfigured")})]}),!a&&(0,r.jsx)("button",{type:"button",onClick:oh,disabled:!eO.trim()&&!tu.length,className:"chat-input-send",title:eA("desktop.sendMessage"),"aria-label":eA("desktop.sendMessage"),children:(0,r.jsx)(sE.l,{size:14})}),a&&(0,r.jsxs)("button",{onClick:o,title:eA("desktop.stopAgent"),"aria-label":eA("desktop.stopAgent"),style:{display:"flex",alignItems:"center",gap:6,padding:"3px 7px",height:24,background:"rgba(239,68,68,0.12)",border:"none",borderRadius:6,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.20)"},onMouseLeave:e=>{e.currentTarget.style.background="rgba(239,68,68,0.12)"},children:[(0,r.jsx)(sW.d,{size:14}),eA("desktop.stop")]})]})})]})]})]})]})]})}));function iP(e){return!!e&&"string"==typeof e.type&&"string"==typeof e.data&&"string"==typeof e.mimeType}function iE(e){let t;if(!e||"object"!=typeof e)return null;let o=e.kind;return"steer"!==o&&"followUp"!==o||"string"!=typeof e.text?null:(Array.isArray(e.images)&&0===(t=e.images.filter(iP)).length&&(t=void 0),{kind:o,text:e.text,...t?{images:t}:{}})}function iW({items:e,sessionId:t,onResolve:o,onExport:s,onStageImport:i,onDismiss:a,mode:l="recovery"}){let{t:d}=(0,A.s)(),c=O(),[p,u]=(0,n.useState)(()=>new Set(e.map(e=>e.id))),[h,g]=(0,n.useState)(!1),[m,f]=(0,n.useState)(null),x=(0,n.useRef)(null);(0,n.useEffect)(()=>{u(new Set(e.map(e=>e.id)))},[e]);let k=e.filter(e=>p.has(e.id)),v=k.length===e.length&&e.length>0,y=e=>u(t=>{let o=new Set(t);return o.has(e)?o.delete(e):o.add(e),o}),b=async(e,t=!1)=>{if(0!==k.length){g(!0),f(null);try{await o("keep"===e?k.map(e=>e.id):[],"discard"===e?k.map(e=>e.id):[],t)}catch(e){f(e instanceof Error?e.message:String(e))}finally{g(!1)}}},w=async e=>{let o=await s();if(!o)return;let r=o.recovery.filter(e=>p.has(e.id));if(r.length){var n;let o,s,i,a,l,c,p;n={sessionId:t,source:"recovery"},s="md"===e?(((o=[]).push("# Queued messages export"),n.sessionId&&o.push(`- Session: ${n.sessionId}`),o.push(`- Source: ${"live"===n.source?"live queue":"pending recovery"}`),o.push(`- Exported: ${n.exportedAt??new Date().toISOString()}`),o.push(""),0===r.length)?o.push("_No entries._"):r.forEach((e,t)=>{var r;o.push(`## ${t+1}. ${"steer"===e.kind?"steer":"follow-up"} \xb7 ${new Date(e.queuedAt).toISOString()}`),e.text&&o.push(e.text),e.images?.length&&o.push(`> _${0===(r=e.images.length)?"":1===r?"(1 image)":`(${r} images)`}_`),o.push("")}),o.join("\n")):JSON.stringify({format:"pi-web-queue",version:1,exportedAt:n.exportedAt??new Date().toISOString(),source:n.source,sessionId:n.sessionId,entries:r.map(({kind:e,text:t,images:o})=>({kind:e,text:t,...o?.length?{images:o}:{}}))},null,2),i=new Date().toISOString().replace(/[:.]/g,"-").slice(0,19),a=`${n.sessionId??"session"}-queue-${n.source}-${i}.${e}`,l=new Blob([s],{type:"md"===e?"text/markdown;charset=utf-8":"application/json;charset=utf-8"}),c=URL.createObjectURL(l),(p=document.createElement("a")).href=c,p.download=a,p.click(),setTimeout(()=>URL.revokeObjectURL(c),1e3),f(d("desktop.queueExported",{count:r.length}))}},j=async e=>{let t=function(e){let t;try{t=JSON.parse(e)}catch{return[]}let o=Array.isArray(t)?t:t&&"object"==typeof t&&Array.isArray(t.entries)?t.entries:null;return o?o.map(iE).filter(e=>null!==e):[]}(await e.text());if(!t.length)return void f(d("desktop.queueImportEmpty"));let o=await i(t);f(null===o?d("desktop.queueImportEmpty"):d("desktop.queueImported",{count:o}))};return(0,r.jsxs)("div",{className:"fixed inset-0 z-[1000] flex items-center justify-center bg-black/40 p-3",role:"presentation",children:[(0,r.jsxs)("div",{role:"dialog","aria-modal":"true","aria-label":"import"===l?d("desktop.queueImportTitle"):d("desktop.queueRecoveryTitle"),className:"flex max-h-[88dvh] w-full max-w-2xl flex-col overflow-hidden rounded-xl border border-(--border) bg-(--bg) shadow-2xl",children:[(0,r.jsxs)("header",{className:"flex flex-wrap items-start gap-3 border-b border-(--border) bg-(--bg-panel) px-4 py-3",children:[(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsx)("h2",{className:"text-sm font-semibold text-(--text)",children:"import"===l?d("desktop.queueImportTitle"):d("desktop.queueRecoveryTitle")}),(0,r.jsx)("p",{className:"mt-1 text-xs leading-5 text-(--text-muted)",children:"import"===l?d("desktop.queueImportDescription"):d("desktop.queueRecoveryDescription")})]}),(0,r.jsxs)("div",{className:"flex items-center gap-1",children:[(0,r.jsx)("button",{type:"button",className:"markdown-code-action",onClick:()=>u(new Set(v?[]:e.map(e=>e.id))),children:v?d("desktop.selectNone"):d("desktop.selectAll")}),(0,r.jsx)("button",{type:"button",className:"markdown-code-action",disabled:h||0===k.length,onClick:()=>void w("json"),children:"JSON"}),(0,r.jsx)("button",{type:"button",className:"markdown-code-action",disabled:h||0===k.length,onClick:()=>void w("md"),children:"MD"}),(0,r.jsx)("button",{type:"button",className:"markdown-code-action",disabled:h,onClick:()=>x.current?.click(),children:d("desktop.import")}),(0,r.jsx)("button",{type:"button",className:"markdown-code-action",onClick:a,"aria-label":d("desktop.close"),children:"\xd7"})]})]}),(0,r.jsx)("div",{className:"grid flex-1 content-start gap-2 overflow-y-auto p-3",children:e.map(e=>{let t=p.has(e.id);return(0,r.jsxs)("button",{type:"button",onClick:()=>y(e.id),"aria-pressed":t,className:["flex w-full items-start gap-3 rounded-lg border p-3 text-left transition",t?"border-(--accent) bg-(--bg-selected)":"border-(--border) bg-(--bg-panel) hover:bg-(--bg-hover)"].join(" "),children:[(0,r.jsx)("input",{type:"checkbox",checked:t,onChange:()=>y(e.id),onClick:e=>e.stopPropagation(),className:"mt-1 accent-[var(--accent)]"}),(0,r.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,r.jsxs)("span",{className:"flex flex-wrap items-center gap-2 text-[11px] text-(--text-dim)",children:[(0,r.jsx)("span",{className:"rounded-full border border-(--border) px-2 py-0.5 font-mono uppercase",children:"steer"===e.kind?d("desktop.steer"):d("desktop.followUp")}),(0,r.jsx)("span",{children:new Date(e.queuedAt).toLocaleString()}),e.hasImages?(0,r.jsx)("span",{children:d("desktop.queueImages")}):null]}),(0,r.jsx)("span",{className:"mt-2 block whitespace-pre-wrap break-words border-l-2 border-(--border) pl-2 text-xs leading-5 text-(--text)",children:e.text||d("desktop.queueNoText")})]})]},e.id)})}),(0,r.jsxs)("footer",{className:["flex flex-wrap items-center gap-2 border-t border-(--border) px-4 py-3",c?"justify-stretch":"justify-end"].join(" "),children:[m?(0,r.jsx)("span",{className:"mr-auto text-xs text-(--text-muted)",children:m}):null,(0,r.jsx)("button",{type:"button",className:"rounded-md px-3 py-2 text-xs text-(--text-muted) hover:bg-(--bg-hover)",onClick:a,disabled:h,children:d("desktop.dismiss")}),(0,r.jsx)("button",{type:"button",className:"rounded-md border border-red-400/40 px-3 py-2 text-xs text-red-400 disabled:opacity-40",onClick:()=>void b("discard"),disabled:h||0===k.length,children:d("desktop.discard")}),(0,r.jsx)("button",{type:"button",className:"rounded-md border border-(--accent) px-3 py-2 text-xs text-(--accent) disabled:opacity-40",onClick:()=>void b("keep"),disabled:h||0===k.length,children:d("desktop.requeue")}),(0,r.jsx)("button",{type:"button",className:"rounded-md bg-(--accent) px-3 py-2 text-xs text-white disabled:opacity-40",onClick:()=>void b("keep",!0),disabled:h||0===k.length,children:d("desktop.requeueAndContinue")})]})]}),(0,r.jsx)("input",{ref:x,type:"file",accept:".json,application/json",className:"hidden",onChange:e=>{let t=e.target.files?.[0];t&&j(t),e.currentTarget.value=""}})]})}var iF=o(36405),iD=o(92185),iA=o(75877),iN=o(30830),iL=o(86965);function i$(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function iH(e){let t=e,o=t.compressedEntryIds?.length??0;for(;1===t.children.length;)t=t.children[0],o+=1+(t.compressedEntryIds?.length??0);return{node:t,skipped:o}}function iO({node:e,assistantLabel:t,activePathIds:o,depth:n,isLast:s,parentLines:i,onSelect:a}){let{node:l,skipped:d}=iH(e),c=o.has(l.entry.id),p=o.has(e.entry.id)||o.has(l.entry.id),u=function(e,t){if("message"===e.type&&"message"in e){let o=e.message,r=o.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"===o.role)return`[${t}]`}return e.type}(l.entry,t),h="message"===l.entry.type&&"message"in l.entry?l.entry.message.role:null;return(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",height:24,cursor:"pointer"},onClick:()=>a(l.entry.id),children:[i.map((e,t)=>(0,r.jsx)("div",{style:{width:16,flexShrink:0,position:"relative",height:"100%",alignSelf:"stretch"},children:e&&(0,r.jsx)("div",{style:{position:"absolute",left:7,top:0,bottom:0,width:1,background:"var(--border)"}})},t)),(0,r.jsxs)("div",{style:{width:16,flexShrink:0,position:"relative",height:"100%",alignSelf:"stretch"},children:[(0,r.jsx)("div",{style:{position:"absolute",left:7,top:0,bottom:s?"50%":0,width:1,background:"var(--border)"}}),(0,r.jsx)("div",{style:{position:"absolute",left:7,top:"50%",width:9,height:1,background:"var(--border)"}})]}),(0,r.jsx)("div",{style:{width:7,height:7,borderRadius:"50%",flexShrink:0,background:c?"var(--accent)":p?"var(--text-muted)":"var(--border)",border:c?"none":"1px solid var(--text-dim)",marginRight:6,transition:"background 0.12s"}}),h&&(0,r.jsx)("span",{style:{fontSize:9,fontFamily:"var(--font-mono)",color:"user"===h?"var(--accent)":"var(--text-dim)",background:"user"===h?"rgba(37,99,235,0.08)":"var(--bg-hover)",border:`1px solid ${"user"===h?"rgba(37,99,235,0.2)":"var(--border)"}`,borderRadius:3,padding:"0 4px",marginRight:5,flexShrink:0,lineHeight:"16px"},children:"user"===h?"U":"A"}),d>0&&(0,r.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",marginRight:5,flexShrink:0},children:["+",d]}),(0,r.jsx)("span",{style:{fontSize:11,color:c?"var(--text)":p?"var(--text-muted)":"var(--text-dim)",fontWeight:c?500:400,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,minWidth:0},children:u})]}),l.children.map((e,d)=>(0,r.jsx)(iO,{node:e,assistantLabel:t,activePathIds:o,depth:n+1,isLast:d===l.children.length-1,parentLines:[...i,!s],onSelect:a},e.entry.id))]})}function iB({tree:e,activeLeafId:t,onLeafChange:o,inline:s,containerRef:i,open:a,onToggle:l,hasSession:d,embedded:c}){let{t:p}=(0,A.s)(),[u,h]=(0,n.useState)(!1),g=void 0!==a?a:u,m=(0,n.useRef)(null),[f,x]=(0,n.useState)(null);(0,n.useEffect)(()=>{if(!g||!s)return;let e=i?.current??m.current;if(!e)return;let t=()=>{let t=e.getBoundingClientRect();x({top:t.bottom,left:t.left,width:t.width})};t();let o=new ResizeObserver(t);return o.observe(e),()=>o.disconnect()},[g,s,i]);let v=(0,n.useMemo)(()=>(function(e,t){if(!t)return new Set;let o=e.map(e=>({node:e,path:[e.entry.id]}));for(;o.length>0;){let{node:e,path:r}=o.pop();if(e.entry.id===t||e.compressedEntryIds?.includes(t))return new Set(r);for(let t of e.children)o.push({node:t,path:[...r,t.entry.id]})}return new Set})(e,t),[e,t]),b=(0,n.useCallback)(e=>{o(e)},[o]),w=d?!function(e){if(e.length>1)return!0;let t=[...e];for(;t.length>0;){let e=t.pop();if(e.children.length>1)return!0;for(let o of e.children)t.push(o)}return!1}(e)?p("desktop.sessionHasNoBranches"):null:p("desktop.noActiveSession"),j=e.length>0?iH(e[0]):null,S=j?.node??null,C=!w&&S&&S.children.length>1,T=(0,r.jsx)(y.Z,{size:16,"aria-hidden":"true",style:{flexShrink:0}}),R=(0,r.jsx)(k.a,{size:8,color:"var(--text-dim)","aria-hidden":"true",style:{marginLeft:1,transition:"transform 0.15s",transform:g?"rotate(180deg)":"none"}});return s?(0,r.jsxs)("div",{style:{height:"100%",display:"flex",alignItems:"stretch"},children:[(0,r.jsx)("button",{ref:m,className:"app-no-drag",onClick:()=>l?l():h(e=>!e),style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:g?"var(--bg-selected)":"none",border:"none",cursor:"pointer",color:g?"var(--text)":"var(--text-muted)",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background=g?"var(--bg-selected)":"none",e.currentTarget.style.color=g?"var(--text)":"var(--text-muted)"},title:p("desktop.branches"),"aria-label":p("desktop.branches"),"aria-pressed":g,children:T}),g&&f&&(0,r.jsx)("div",{className:"app-no-drag",style:{position:"fixed",top:f.top,left:f.left,width:f.width,background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",zIndex:500},children:C&&S?(0,r.jsx)("div",{style:{padding:"4px 12px 8px 12px",maxHeight:260,overflowY:"auto"},children:S.children.map((e,t)=>(0,r.jsx)(iO,{node:e,assistantLabel:p("desktop.assistant"),activePathIds:v,depth:0,isLast:t===S.children.length-1,parentLines:[],onSelect:b},e.entry.id))}):(0,r.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:w})})]}):c?C&&S?(0,r.jsx)("div",{style:{padding:"4px 8px 8px 8px"},children:S.children.map((e,t)=>(0,r.jsx)(iO,{node:e,assistantLabel:p("desktop.assistant"),activePathIds:v,depth:0,isLast:t===S.children.length-1,parentLines:[],onSelect:b},e.entry.id))}):(0,r.jsx)("div",{style:{padding:"10px 12px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:w??p("desktop.sessionHasNoBranches")}):(0,r.jsxs)("div",{style:{borderBottom:"1px solid var(--border)",background:"var(--bg)",flexShrink:0,position:"relative"},children:[(0,r.jsxs)("button",{onClick:()=>h(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:[T,(0,r.jsx)("span",{style:{color:"var(--text-muted)"},children:p("desktop.branches")}),R]}),g&&(0,r.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:C&&S?(0,r.jsx)("div",{style:{padding:"4px 12px 8px 12px",maxHeight:260,overflowY:"auto"},children:S.children.map((e,t)=>(0,r.jsx)(iO,{node:e,assistantLabel:p("desktop.assistant"),activePathIds:v,depth:0,isLast:t===S.children.length-1,parentLines:[],onSelect:b},e.entry.id))}):(0,r.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:w??p("desktop.sessionHasNoBranches")})})]})}var iU=o(45390),i_=o(33846);function iq({open:e,onOpenChange:t,cwd:o}){let{t:s}=(0,A.s)(),[i,a]=(0,n.useState)([]),[l,d]=(0,n.useState)(""),[c,p]=(0,n.useState)(!1),[u,g]=(0,n.useState)(null),[m,f]=(0,n.useState)(null),x=(0,n.useCallback)(async()=>{if(o)try{let e=await fetch(`/api/git/stash?${new URLSearchParams({cwd:o}).toString()}`,{cache:"no-store"});if(e.ok){let t=await e.json();a(t.entries)}}catch{}},[o]);if((0,n.useEffect)(()=>{e&&x()},[e,x]),!e)return null;let k=async(e,t)=>{p(!0),g(null),f(null);try{let r=await fetch(`/api/git/stash?${new URLSearchParams({cwd:o??""}).toString()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:e,message:l||void 0,ref:t})}),n=await r.json();r.ok&&n.ok?(f(n.output??s("tasks.stashDone")),d(""),x()):g(n.error??`HTTP ${r.status}`)}catch(e){g(e instanceof Error?e.message:String(e))}finally{p(!1)}};return(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:950,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.45)"},onMouseDown:e=>{e.target===e.currentTarget&&t(!1)},children:(0,r.jsxs)("div",{style:{width:"min(520px, calc(100vw - 48px))",maxHeight:"min(75vh, 560px)",overflow:"auto",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 16px 48px rgba(0,0,0,0.3)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 16px 0"},children:[(0,r.jsx)("h3",{style:{fontSize:15,fontWeight:600,margin:0},children:s("desktop.stashTitle")}),(0,r.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":s("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex"},children:(0,r.jsx)(h.X,{size:16,"aria-hidden":"true"})})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,padding:"14px 16px 16px"},children:[(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[(0,r.jsx)("input",{value:l,onChange:e=>d(e.target.value),placeholder:s("desktop.stashMessagePlaceholder"),style:{width:"100%",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"7px 10px",color:"var(--text)",fontSize:13,outline:"none",fontFamily:"inherit"}}),(0,r.jsxs)("button",{type:"button",onClick:()=>void k("push"),disabled:c,style:{alignSelf:"flex-start",display:"inline-flex",alignItems:"center",gap:5,padding:"7px 14px",borderRadius:8,background:"var(--accent)",color:"#fff",border:"none",fontSize:12,fontWeight:600,cursor:c?"not-allowed":"pointer"},children:[(0,r.jsx)(i_.c,{size:13,"aria-hidden":"true"}),s("desktop.stashPush")]})]}),u&&(0,r.jsx)("div",{style:{padding:"8px 10px",borderRadius:8,background:"rgba(239,68,68,0.10)",color:"#ef4444",fontSize:12,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:u}),m&&(0,r.jsx)("div",{style:{padding:"8px 10px",borderRadius:8,background:"rgba(34,197,94,0.10)",color:"#22c55e",fontSize:12,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:m}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column"},children:[(0,r.jsxs)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",marginBottom:6},children:[s("desktop.stashList")," (",i.length,")"]}),0===i.length?(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)"},children:s("desktop.stashEmpty")}):(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:i.map(e=>(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"7px 10px",borderRadius:8,border:"1px solid var(--border)",background:"var(--bg)"},children:[(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-muted)",flexShrink:0},children:e.index}),(0,r.jsx)("span",{style:{flex:1,minWidth:0,fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.message||e.ref}),(0,r.jsxs)("button",{type:"button",onClick:()=>void k("pop",e.ref),disabled:c,title:s("desktop.stashPop"),style:{display:"inline-flex",alignItems:"center",gap:3,padding:"4px 8px",borderRadius:6,border:"1px solid var(--border)",background:"none",color:"var(--text)",fontSize:11,cursor:c?"not-allowed":"pointer"},children:[(0,r.jsx)(C.S,{size:11,"aria-hidden":"true"}),s("desktop.stashPop")]}),(0,r.jsx)("button",{type:"button",onClick:()=>void k("drop",e.ref),disabled:c,title:s("desktop.stashDrop"),style:{display:"inline-flex",alignItems:"center",padding:"4px 8px",borderRadius:6,border:"1px solid var(--border)",background:"none",color:"#ef4444",fontSize:11,cursor:c?"not-allowed":"pointer"},children:s("desktop.stashDrop")})]},e.ref))})]})]})]})})}function iV({cwd:e}){let{t}=(0,A.s)(),[o,s]=(0,n.useState)(!1),[i,a]=(0,n.useState)("idle"),[l,d]=(0,n.useState)(null),[c,p]=(0,n.useState)(!1),u=(0,n.useCallback)(async()=>{if(e&&!o){s(!0),a("idle");try{let o=await fetch(`/api/git/push?${new URLSearchParams({cwd:e}).toString()}`,{method:"POST",cache:"no-store"}),r=await o.json();o.ok&&r.ok?(a("ok"),d(r.output||t("desktop.pushOk"))):(a("error"),d(r.error??t("desktop.pushFailed")))}catch(e){a("error"),d(e instanceof Error?e.message:t("desktop.pushFailed"))}finally{s(!1),setTimeout(()=>{a("idle"),d(null)},4e3)}}},[e,o,t]);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{type:"button",className:"session-info-bar-button",onClick:()=>void u(),disabled:!e||o,title:t("desktop.push"),"aria-label":t("desktop.push"),style:{position:"relative"},children:"ok"===i?(0,r.jsx)(nv.r,{size:13,color:"#22c55e",weight:"fill","aria-hidden":"true"}):"error"===i?(0,r.jsx)(iU.J,{size:13,color:"#ef4444",weight:"fill","aria-hidden":"true"}):(0,r.jsx)(i_.c,{size:13,"aria-hidden":"true"})}),(0,r.jsx)("button",{type:"button",className:"session-info-bar-button",onClick:()=>p(!0),disabled:!e,title:t("desktop.stash"),"aria-label":t("desktop.stash"),children:(0,r.jsx)(P.T,{size:13,"aria-hidden":"true"})}),l&&(0,r.jsx)("div",{style:{position:"fixed",bottom:60,left:"50%",transform:"translateX(-50%)",zIndex:1200,maxWidth:"60vw",padding:"8px 14px",borderRadius:8,background:"var(--bg-panel)",border:`1px solid ${"ok"===i?"#22c55e":"#ef4444"}`,boxShadow:"0 8px 24px rgba(0,0,0,0.2)",fontSize:12,color:"ok"===i?"#22c55e":"#ef4444",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:l}),(0,r.jsx)(iq,{open:c,onOpenChange:p,cwd:e})]})}function iK({onViewFullHistory:e,cwd:t,systemPrompt:o,sessionStats:s,contextUsage:i,hasSession:a,showChat:l,soundEnabled:d,onSoundToggle:c,onCompact:p,onAbortCompaction:u,isCompacting:h,compactError:g,branchTree:f,branchActiveLeafId:x,onBranchLeafChange:k,showSoundLabel:v,isDeepSeekOfficial:b,deepseekBalance:w,lastTurnUsage:j}){let{t:S}=(0,A.s)(),[C,T]=(0,n.useState)(null),R=(0,n.useCallback)(()=>T(null),[]),[z,I]=(0,n.useState)(null),M=(0,n.useRef)(null),P=(0,n.useCallback)((e,t)=>{re(t).then(()=>{M.current&&clearTimeout(M.current),I(e),M.current=setTimeout(()=>I(null),1400)})},[]),E=(0,n.useMemo)(()=>{if(!o)return 0;let e=0;for(let t of o){let o=t.codePointAt(0)??0;o>=19968&&o<=40959||o>=13312&&o<=19903||o>=131072&&o<=173791||o>=12352&&o<=12447||o>=12448&&o<=12543||o>=44032&&o<=55215?e+=1:e+=.25}return Math.max(1,Math.round(e))},[o]),W=(0,n.useMemo)(()=>{if(!w?.available||null==w.totalBalance)return S("desktop.balanceUnavailable");let e=Number(w.grantedBalance)||0,t=Number(w.toppedUpBalance)||0;return`${S("desktop.balance")}:${r8(Number(w.totalBalance)||0)}(${S("desktop.balanceGranted")}:${r8(e)} / ${S("desktop.balanceToppedUp")}:${r8(t)})`},[w,S]);if(!l)return null;let F=s?.tokens,D=s?.cost??0,N=s?.costCNY??0,L=s?.costUSD??0,$=[];N>0&&$.push(r8(N)),L>0&&$.push(L>=.01?`$${L.toFixed(2)}`:"<$0.01"),0===$.length&&D>0&&$.push(D>=.01?`$${D.toFixed(2)}`:"<$0.01");let H=$.length>0?$.join(" + "):null,O="var(--text-muted)";if(i?.contextWindow){let e=i.percent;null!==e&&e>90?O="#ef4444":null!==e&&e>70&&(O="rgba(234,179,8,0.95)")}let B=null!==o&&""!==o,U=s&&F&&(F.input>0||F.output>0),_=a&&k,q=[];if(F&&(q.push(`${S("desktop.sessionInfoInput")}: ${F.input.toLocaleString()}`),q.push(`${S("desktop.sessionInfoOutput")}: ${F.output.toLocaleString()}`),F.cacheRead>0&&q.push(`${S("desktop.sessionInfoCacheRead")}: ${F.cacheRead.toLocaleString()}`),F.cacheWrite>0&&q.push(`${S("desktop.sessionInfoCacheWrite")}: ${F.cacheWrite.toLocaleString()}`),N>0&&q.push(`${S("desktop.sessionInfoCostOfficial")}: ${r8(N)}`),L>0&&q.push(`${S("desktop.sessionInfoCost")}: $${L.toFixed(4)}`),N<=0&&L<=0&&D>0&&q.push(`${S("desktop.sessionInfoCost")}: $${D.toFixed(4)}`)),i?.contextWindow&&null!==i.percent){let e=i.percent,t=i.tokens;q.push(`${S("desktop.sessionInfoContext")}: ${null!==e?`${e.toFixed(1)}%`:"?"} ${null!==t?i$(t):"?"}/${i$(i.contextWindow)}`)}let V=q.join(" | ");return(0,r.jsxs)("div",{className:"session-info-bar",children:[t&&(0,r.jsx)(iV,{cwd:t}),c&&(0,r.jsxs)("button",{type:"button",className:"session-info-bar-button",onClick:c,title:d?S("desktop.disableCompletionSound"):S("desktop.enableCompletionSound"),"aria-label":d?S("desktop.disableCompletionSound"):S("desktop.enableCompletionSound"),children:[d?(0,r.jsx)(iF.Q,{size:13}):(0,r.jsx)(iD.l,{size:13}),v&&(0,r.jsx)("span",{style:{marginLeft:4},children:d?S("desktop.soundLabelOn"):S("desktop.soundLabelOff")})]}),a&&(0,r.jsx)("button",{type:"button",className:"session-info-bar-button",onClick:e,title:S("desktop.viewFullHistory"),"aria-label":S("desktop.viewFullHistory"),children:(0,r.jsx)(iA.n,{size:13,"aria-hidden":"true"})}),_&&(0,r.jsxs)("div",{className:"session-info-bar-popover-host",children:[(0,r.jsx)("button",{type:"button",className:`session-info-bar-button${"branches"===C?" is-active":""}`,onClick:()=>T(e=>"branches"===e?null:"branches"),title:S("desktop.branches"),"aria-label":S("desktop.branches"),"aria-pressed":"branches"===C,children:(0,r.jsx)(y.Z,{size:13,"aria-hidden":"true"})}),"branches"===C&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"session-info-bar-popover-cover",onClick:R}),(0,r.jsxs)("div",{className:"session-info-bar-popover is-branches",children:[(0,r.jsxs)("div",{className:"session-info-bar-popover-header",children:[(0,r.jsx)("span",{className:"session-info-bar-popover-title",children:S("desktop.branches")}),(0,r.jsx)("button",{type:"button",className:"session-info-bar-popover-close",onClick:R,title:S("i18n.close"),"aria-label":S("i18n.close"),children:"✕"})]}),(0,r.jsx)("div",{className:"session-info-bar-popover-body",children:(0,r.jsx)(iB,{tree:f??[],activeLeafId:x??null,onLeafChange:e=>{k(e),R()},hasSession:!0,embedded:!0})})]})]})]}),B&&(0,r.jsxs)("div",{className:"session-info-bar-popover-host",children:[(0,r.jsx)("button",{type:"button",className:`session-info-bar-button${"system"===C?" is-active":""}`,onClick:()=>T(e=>"system"===e?null:"system"),title:S("desktop.systemPrompt"),"aria-label":S("desktop.systemPrompt"),"aria-pressed":"system"===C,children:(0,r.jsx)(sz.i,{size:13,"aria-hidden":"true"})}),"system"===C&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"session-info-bar-popover-cover",onClick:R}),(0,r.jsxs)("div",{className:"session-info-bar-popover is-system",children:[(0,r.jsxs)("div",{className:"session-info-bar-popover-header",children:[(0,r.jsx)("span",{className:"session-info-bar-popover-title",children:S("desktop.systemPrompt")}),(0,r.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",marginLeft:8},children:["~",i$(E)," tokens"]}),(0,r.jsx)("div",{style:{flex:1}}),(0,r.jsx)("button",{type:"button",className:"session-info-bar-popover-close",onClick:R,title:S("i18n.close"),"aria-label":S("i18n.close"),children:"✕"})]}),(0,r.jsx)("div",{className:"session-info-bar-system-body",children:o?(0,r.jsx)(on.oz,{remarkPlugins:[ra.A],children:o}):(0,r.jsx)("span",{className:"session-info-bar-popover-empty",children:"System prompt is empty (tools are disabled)"})})]})]})]}),(0,r.jsx)("div",{className:"session-info-bar-spacer"}),p&&(0,r.jsxs)("div",{className:"session-info-bar-compact-wrap",children:[g&&(0,r.jsx)("div",{className:"session-info-bar-compact-error",children:g}),(0,r.jsx)("button",{type:"button",className:`session-info-bar-button${h?" is-compacting":""}`,onClick:h?u:p,title:h?S("desktop.stopCompaction"):S("desktop.compactContext"),"aria-label":h?S("desktop.stopCompaction"):S("desktop.compactContext"),children:h?(0,r.jsx)(sW.M,{size:13}):(0,r.jsx)(iN.C,{size:13})})]}),b&&w?.available&&null!=w.totalBalance&&(0,r.jsxs)("span",{className:"session-info-bar-token-chip",style:{color:"var(--text-muted)",cursor:"default"},title:W,children:[(0,r.jsx)(iL.u,{size:11,"aria-hidden":"true"}),S("desktop.balance")," ",r8(Number(w.totalBalance)||0)]}),U&&(0,r.jsxs)("div",{className:"session-info-bar-popover-host",children:[(0,r.jsxs)("button",{type:"button",className:`session-info-bar-button is-stats${"session"===C?" is-active":""}`,onClick:()=>T(e=>"session"===e?null:"session"),title:V||S("desktop.sessionInfo"),"aria-label":S("desktop.sessionInfo"),"aria-pressed":"session"===C,children:[F&&F.input>0&&(0,r.jsxs)("span",{className:"session-info-bar-token-chip",children:[(0,r.jsx)(rY.D,{size:10,"aria-hidden":"true"}),i$(F.input)]}),F&&F.output>0&&(0,r.jsxs)("span",{className:"session-info-bar-token-chip",children:[(0,r.jsx)(rJ.y,{size:10,"aria-hidden":"true"}),i$(F.output)]}),F&&F.cacheRead>0&&(0,r.jsxs)("span",{className:"session-info-bar-token-chip",children:[(0,r.jsx)(rQ.W,{size:10,"aria-hidden":"true"}),i$(F.cacheRead)]}),H&&(0,r.jsx)("span",{children:H}),i?.contextWindow&&null!==i.percent&&(0,r.jsx)("span",{className:"session-info-bar-token-chip",style:{color:O},children:(0,r.jsxs)("svg",{className:"session-info-bar-donut",width:"16",height:"16",viewBox:"0 0 16 16","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"8",cy:"8",r:"6.75",fill:"none",stroke:"var(--border)",strokeWidth:"2.5"}),(0,r.jsx)("circle",{className:"session-info-bar-donut-arc",cx:"8",cy:"8",r:"6.75",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",pathLength:100,strokeDasharray:100,strokeDashoffset:null===i.percent?0:100-Math.min(100,Math.max(0,i.percent)),transform:"rotate(-90 8 8)"})]})})]}),"session"===C&&s&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"session-info-bar-popover-cover",onClick:R}),(0,r.jsx)("div",{className:"session-info-bar-popover is-session",children:(0,r.jsx)("div",{className:"session-stats-body",children:(()=>{let e=s.tokens,t=i??s.contextUsage,o=(e,t)=>{let o=z===e;return(0,r.jsx)("button",{type:"button",className:`session-stats-copy${o?" is-copied":""}`,title:o?S("desktop.copied"):"file"===e?S("desktop.copyFilePath"):S("desktop.copySessionId"),onClick:()=>P(e,t),children:o?(0,r.jsx)(m.J,{size:12,"aria-hidden":"true"}):(0,r.jsx)(or.Q,{size:12,"aria-hidden":"true"})})},n=[];s.sessionName&&n.push((0,r.jsx)("div",{className:"session-stats-info-name",children:s.sessionName},"name")),n.push((0,r.jsxs)("div",{className:"session-stats-info-line",children:[(0,r.jsx)("span",{className:"session-stats-info-text",children:s.sessionFile?s.sessionFile.split(/[/\\]/).pop()??s.sessionFile:S("desktop.sessionInfoInMemory")}),s.sessionFile?o("file",s.sessionFile):null]},"file")),n.push((0,r.jsxs)("div",{className:"session-stats-info-line",children:[(0,r.jsx)("span",{className:"session-stats-info-text",children:s.sessionId}),o("id",s.sessionId)]},"id"));let a=[[S("desktop.sessionInfoUser"),s.userMessages.toLocaleString()],[S("desktop.sessionInfoAssistant"),s.assistantMessages.toLocaleString()],[S("desktop.sessionInfoToolCalls"),s.toolCalls.toLocaleString()],[S("desktop.sessionInfoToolResults"),s.toolResults.toLocaleString()],[S("desktop.sessionInfoTotal"),s.totalMessages.toLocaleString()]],l=[[S("desktop.sessionInfoInput"),e.input.toLocaleString()],[S("desktop.sessionInfoOutput"),e.output.toLocaleString()]];e.cacheRead>0&&l.push([S("desktop.sessionInfoCacheRead"),e.cacheRead.toLocaleString()]),e.cacheWrite>0&&l.push([S("desktop.sessionInfoCacheWrite"),e.cacheWrite.toLocaleString()]),l.push([S("desktop.sessionInfoTotal"),e.total.toLocaleString()]);let d=s.costCNY??0,c=s.costUSD??0;if(d>0&&l.push([S("desktop.sessionInfoCostOfficial"),r8(d)]),c>0&&l.push([S("desktop.sessionInfoCost"),`$${c.toFixed(4)}`]),d<=0&&c<=0&&s.cost>0&&l.push([S("desktop.sessionInfoCost"),`$${s.cost.toFixed(4)}`]),t?.contextWindow&&null!==t.percent){let e=t.percent,o=t.tokens;l.push([S("desktop.sessionInfoContext"),`${null!==e?`${e.toFixed(1)}%`:"?"} ${null!==o?i$(o):"?"}/${i$(t.contextWindow)}`])}(s.totalActiveMs??0)>0&&l.push([S("desktop.sessionInfoActiveTime"),function(e){if(e<=0)return"0s";let t=Math.floor(e/1e3),o=Math.floor(t/3600),r=Math.floor(t%3600/60),n=t%60;return o>0?`${o}h ${r}m`:r>0?`${r}m ${n}s`:`${n}s`}(s.totalActiveMs)]);let p=j?j.costCNY>0?r8(j.costCNY):j.costUSD>0?`$${j.costUSD.toFixed(4)}`:null:null,u=(e,t)=>(0,r.jsxs)("div",{className:"session-stats-row",children:[(0,r.jsx)("div",{className:"session-stats-label",children:e}),(0,r.jsx)("div",{className:"session-stats-value",children:t})]},e);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"session-stats-info-block",children:n}),(0,r.jsxs)("div",{className:"session-stats-side-by-side",children:[(0,r.jsxs)("div",{className:"session-stats-column",children:[(0,r.jsx)("div",{className:"session-stats-section-title",children:S("desktop.sessionInfoMessages")}),(0,r.jsx)("div",{className:"session-stats-compact-grid",children:a.map(([e,t])=>u(e,t))})]}),(0,r.jsxs)("div",{className:"session-stats-column",children:[(0,r.jsx)("div",{className:"session-stats-section-title",children:S("desktop.sessionInfoTokens")}),(0,r.jsx)("div",{className:"session-stats-compact-grid",children:l.map(([e,t])=>u(e,t))})]}),j&&(0,r.jsxs)("div",{className:"session-stats-column",children:[(0,r.jsx)("div",{className:"session-stats-section-title",children:S("desktop.turnUsageTitle")}),(0,r.jsxs)("div",{className:"session-stats-compact-grid",children:[u(S("desktop.sessionInfoInput"),j.input.toLocaleString()),u(S("desktop.sessionInfoOutput"),j.output.toLocaleString()),j.cacheRead>0&&u(S("desktop.sessionInfoCacheRead"),j.cacheRead.toLocaleString()),p&&u(S("desktop.sessionInfoCost"),p)]})]})]})]})})()})})]})]})]})}var iG=o(68635);function iJ({scrollElementRef:e,items:t,itemKeys:o,estimateSize:s=120,overscan:i=8,virtualizerRef:a}){let l=(0,iG.Te)({count:t.length,getScrollElement:()=>e.current,estimateSize:(0,n.useCallback)(()=>s,[s]),overscan:i,getItemKey:(0,n.useCallback)(e=>o[e]??`idx-${e}`,[o])});l.shouldAdjustScrollPositionOnItemSizeChange=()=>!1,a&&(a.current=l);let d=(0,n.useRef)(!1),c=(0,n.useRef)(l);c.current=l,(0,n.useEffect)(()=>{d.current||0===t.length||e.current&&(d.current=!0,c.current.scrollToIndex(t.length-1,{align:"end"}))},[t.length,e]);let p=l.getVirtualItems();return(0,r.jsx)("div",{style:{position:"relative",width:"100%",minWidth:0,height:l.getTotalSize()},children:p.map(e=>(0,r.jsx)("div",{"data-index":e.index,ref:l.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",minWidth:0,overflow:"hidden",transform:`translateY(${e.start}px)`},children:t[e.index]},e.key))})}function iY(e){return e.replace(/<\/?[\w:-]+\b[^>]*>/g," ").replace(/&lt;\/?[\w:-]+\b[^&]*?&gt;/gi," ").replace(/\s+/g," ").trim()}function iX(e){return"user"===e.role||"assistant"===e.role&&(e.content??[]).some(e=>"text"===e.type||"thinking"===e.type||"toolCall"===e.type)}function iZ({messages:e,streamingMessage:t,scrollContainer:o,messageRefs:s,onWidthChange:i,virtualizer:a}){var l;let[d,c]=(0,n.useState)(0),[p,u]=(0,n.useState)(1),[h,g]=(0,n.useState)(!1),[m,f]=(0,n.useState)([]),[x,k]=(0,n.useState)(!1),[v,y]=(0,n.useState)(null),[b,w]=(0,n.useState)(0),j=(0,n.useRef)(!1),S=(0,n.useRef)(null),C=(0,n.useMemo)(()=>t?[...e,t]:e,[e,t]),T=(0,n.useRef)(C);T.current=C;let R=(0,n.useCallback)(()=>{let e=o.current;if(!e)return;let t=e.scrollHeight,r=e.clientHeight,n=t-r;g(n>20),n<=0?(c(0),u(1)):(c(e.scrollTop/n),u(r/t))},[o]),z=(0,n.useRef)(null),I=(0,n.useRef)([]),M=(0,n.useRef)(a);M.current=a;let P=(0,n.useCallback)(()=>{z.current||(z.current=setTimeout(()=>{z.current=null;let e=o.current;if(!e)return;let t=e.scrollHeight;if(t<=0)return;let r=[],n=T.current,i=M.current;if(i){if(0>=i.totalHeight())return;let e=0,o=new Set;for(let s=0;s<n.length;s++){let a=n[s];if("user"!==a.role&&"assistant"!==a.role)continue;let l=i.refToItemIndex(e);if(e+=1,void 0===l||o.has(l)||!iX(a))continue;o.add(l);let d=i.getOffsetForIndex(l),c=i.sizeFor(l);r.push({topRatio:d/t,heightRatio:Math.max(c/t,1/t),msg:a,index:r.length})}}else{let o=s.current,i=0;for(let s=0;s<n.length;s++){let a=n[s];if("user"!==a.role&&"assistant"!==a.role)continue;let l=o?.[i];if(i++,iX(a)&&l){let o=l.getBoundingClientRect(),n=e.getBoundingClientRect(),s=o.top-n.top+e.scrollTop,i=o.height;r.push({topRatio:s/t,heightRatio:i/t,msg:a,index:r.length})}}}let a=I.current;a.length===r.length&&r.every((e,t)=>1e-6>Math.abs(e.topRatio-a[t].topRatio)&&1e-6>Math.abs(e.heightRatio-a[t].heightRatio))||(I.current=r,f(r))},150))},[o,s]);(0,n.useEffect)(()=>{let e=o.current;if(e)return e.addEventListener("scroll",R,{passive:!0}),()=>e.removeEventListener("scroll",R)},[o,R]),(0,n.useEffect)(()=>{let e=o.current;if(!e)return;let t=()=>{R(),P()},r=new ResizeObserver(t);return r.observe(e),e.firstElementChild&&r.observe(e.firstElementChild),t(),()=>{r.disconnect(),z.current&&(clearTimeout(z.current),z.current=null)}},[o,P,R]),(0,n.useEffect)(()=>{let e=setTimeout(()=>{R(),P()},50);return()=>clearTimeout(e)},[e.length,P,R]);let E=(0,n.useCallback)(e=>{let t=o.current;if(!t)return;let r=t.scrollHeight-t.clientHeight;r<=0||(t.scrollTop=Math.max(0,Math.min(1-p,e))/(1-p)*r)},[o,p]),W=(0,n.useCallback)(e=>{if(!h)return;j.current=!0;let t=e.currentTarget.getBoundingClientRect(),o=(e.clientY-t.top)/t.height,r=o-d*(1-p),n=r>=0&&r<=p?r:p/2;E(o-n);let s=e=>{j.current&&E((e.clientY-t.top)/t.height-n)},i=()=>{j.current=!1,window.removeEventListener("mousemove",s),window.removeEventListener("mouseup",i)};window.addEventListener("mousemove",s),window.addEventListener("mouseup",i)},[h,p,d,E]);(0,n.useEffect)(()=>{if(!h)return void w(0);let e=S.current;if(!e)return;let t=()=>w(e.clientHeight),o=new ResizeObserver(t);return o.observe(e),t(),()=>o.disconnect()},[h]);let F=(0,n.useMemo)(()=>{if(b<=0)return[];let e=[];return m.map(t=>{let o=t.topRatio*b,r=Math.max(3,Math.min(46,t.heightRatio*b)),n=Math.max(0,o-r/2),s=Math.min(b,o+r/2),i=e.findIndex(e=>n>=e+1);return -1===i?(i=e.length,e.push(s)):e[i]=s,{...t,displayTopPx:o,lane:i}})},[m,b]),D=Math.max(18,4+5*(l=(0,n.useMemo)(()=>F.reduce((e,t)=>Math.max(e,t.lane+1),1),[F]))+(l-1)*1);if((0,n.useEffect)(()=>{i?.(h?D:18)},[D,i,h]),(0,n.useEffect)(()=>()=>i?.(18),[i]),!h)return null;let A=d*(1-p)*100,N=100*p,L=null!==v&&F.length>0?F.reduce((e,t)=>Math.abs(t.displayTopPx/b-v)<Math.abs(F[e].displayTopPx/b-v)?t.index:e,0):null,$=null===L?null:F.find(e=>e.index===L)??null;return(0,r.jsxs)("div",{ref:S,onMouseDown:W,onMouseEnter:()=>k(!0),onMouseLeave:()=>{k(!1),y(null)},onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();y((e.clientY-t.top)/t.height)},style:{width:D,flexShrink:0,position:"relative",cursor:"pointer",userSelect:"none",background:"transparent",overflow:"visible"},children:[(0,r.jsx)("div",{style:{position:"absolute",left:1,right:1,top:`${A}%`,height:`${N}%`,background:"color-mix(in srgb, var(--text-muted) 14%, transparent)",pointerEvents:"none",zIndex:1}}),F.map(e=>{let t=function(e){if("user"===e.role)return"var(--accent)";let t=e.content??[];return t.some(e=>"toolCall"===e.type&&e.error)?"var(--accent-red)":t.some(e=>"toolCall"===e.type)?"var(--accent-green)":"var(--text-dim)"}(e.msg),o=x&&$?.index===e.index,n="user"===e.msg.role,s=Math.max(3,Math.min(46,e.heightRatio*b)),i=2+6*e.lane;return(0,r.jsx)("div",{style:{position:"absolute",top:e.displayTopPx,transform:"translateY(-50%)",left:i,width:5,height:s,display:"flex",alignItems:"stretch",cursor:"pointer",zIndex:function(e){if("user"===e.role)return 6;let t=e.content??[];return t.some(e=>"toolCall"===e.type&&e.error)?5:t.some(e=>"text"===e.type&&!!e.text?.trim())?4:t.some(e=>"toolCall"===e.type)?3:2}(e.msg)},children:(0,r.jsx)("div",{style:{width:"100%",height:"100%",borderRadius:1,background:t,opacity:o?1:n?.92:.72,transition:"opacity 0.1s, filter 0.1s",filter:o?"brightness(1.2)":"none"}})},e.index)}),x&&$&&(()=>{let e=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??[],o=t.filter(e=>"text"===e.type).map(e=>e.text).join(" ");if(o)return iY(o).slice(0,200);let r=t.filter(e=>"thinking"===e.type).map(e=>iY(e.thinking??"")).filter(Boolean).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""}($.msg);if(!e)return null;let t=function(e){if("user"===e.role)return"var(--minimap-preview-user-bg)";let t=e.content??[];return t.some(e=>"toolCall"===e.type&&e.error)?"var(--minimap-preview-error-bg)":t.some(e=>"toolCall"===e.type)?"var(--minimap-preview-tool-bg)":"var(--minimap-preview-default-bg)"}($.msg),o=Math.max(1,Math.min(5,Math.floor(b/120))),n=15*o+4,s=Math.max(n/2,Math.min(b-n/2,$.displayTopPx));return(0,r.jsx)("div",{style:{position:"absolute",top:s,transform:"translateY(-50%)",right:"100%",marginRight:6,background:t,border:"none",borderRadius:4,padding:"2px 7px",width:220,zIndex:100,pointerEvents:"none"},children:(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text)",lineHeight:"15px",display:"-webkit-box",WebkitBoxOrient:"vertical",WebkitLineClamp:o,overflow:"hidden",overflowWrap:"anywhere"},children:e})})})()]})}function iQ(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function i0(e){return function(e,t={}){if("assistant"!==e.role)return e;let o=e.content;if(!Array.isArray(o))return e;let r=o.map(e=>(function(e,t={}){if(!iQ(e)||"toolCall"!==e.type)return null;let o={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},r=t.includeStreamingRawInput?function(e){if("string"==typeof e.rawInput)return e.rawInput;if("string"==typeof e.partialJson)return e.partialJson;if("string"==typeof e.partialArgs)return e.partialArgs;let t=iQ(e.customInput)?e.customInput:null,o=t&&"string"==typeof t.property?t.property:null,r=iQ(e.arguments)?e.arguments:null;return o&&r&&"string"==typeof r[o]?r[o]:void 0}(e):void 0;return void 0===r?o:{...o,rawInput:r}})(e,t)??e);return{...e,content:r}}(e)}class i1 extends Error{constructor(e,t,o,r){super(e),this.status=t,this.code=o,this.accepted=r,this.name="AgentCommandError"}}class i2 extends Error{constructor(e,t,o){super(e),this.commandType=t,this.timeoutMs=o,this.name="AgentCommandTimeoutError"}}let i4=new Set(["compact","bash"]);async function i6(e,t,o={}){let r,n=function(e,t){if(void 0!==t.timeoutMs)return t.timeoutMs;let o="string"==typeof e.type?e.type:"";return 3e4*!i4.has(o)}(t,o),s=n>0?new AbortController:void 0,i=s?setTimeout(()=>s.abort(),n):void 0;try{r=await fetch(`/api/agent/${encodeURIComponent(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),...s?{signal:s.signal}:{}})}catch(e){if(s?.signal.aborted)throw new i2(`Agent command "${String(t.type??"unknown")}" timed out after ${n}ms`,String(t.type??"unknown"),n);throw e}finally{i&&clearTimeout(i)}let a=await r.json().catch(()=>({}));if(!r.ok||a.error)throw new i1(a.error??`HTTP ${r.status}`,r.status,a.code,a.accepted);return a.data}var i8=o(14755);function i5(e){if(!e)return 0;let t=0;for(let o of e){let e=o.codePointAt(0)??0;e>=19968&&e<=40959||e>=13312&&e<=19903||e>=131072&&e<=173791||e>=12352&&e<=12447||e>=12448&&e<=12543||e>=44032&&e<=55215?t+=1:t+=.25}return Math.max(0,Math.round(t))}function i3(){return"u">typeof performance?performance.now():Date.now()}function i7(e,t){switch(t.type){case"start":return{isStreaming:!0,streamingMessage:null};case"update":return{isStreaming:!0,streamingMessage:t.message};case"end":case"reset":return{isStreaming:!1,streamingMessage:null};default:return e}}function i9(e){return e?"running_command"===e.phase||e.isBashRunning?{kind:"running_command"}:"waiting_model"===e.phase||e.isStreaming||e.isPromptRunning||e.isCompacting?{kind:"waiting_model"}:null:null}function ae(e,t){return e.length===t.length&&e.every((e,o)=>e===t[o])}function at(e){return{steering:e?.steering??[],followUp:e?.followUp??[]}}let ao=`You are in PLAN MODE. Work as a read-only planning assistant.
28
28
  - Analyze, read, search and reason about the codebase; do NOT modify any files.
29
29
  - Do NOT run shell commands that mutate state, install packages, or start servers.
30
30
  - When you have enough understanding, produce a concrete, step-by-step implementation plan.
31
31
  - Structure the plan with clear phases, the files involved, and any risks or open questions.
32
- - Do not write code yet — the plan itself is the deliverable.`,ar=["You are in PLAN MODE.","<economy-profile>","<delivery-profile>","<goal-profile>"],an=new Set(["ArrowUp","ArrowDown","PageUp","PageDown","Home","End"," ","Space","Spacebar"]);class as extends Error{constructor(e){super("timeout"===e?"Timed out connecting to the agent event stream. Please try again.":"Failed to connect to the agent event stream. Please try again."),this.status=e,this.name="EventStreamConnectionError"}}function ai(e){return new Promise(t=>setTimeout(t,e))}function aa(e){let t=e.findIndex(e=>!e.exiting);return -1===t?e:e.map((e,o)=>o===t?{...e,exiting:!0}:e)}function al(e,t){switch(t.type){case"add":if(e.visible.some(e=>e.exiting)||e.visible.length>=5)return{visible:e.visible.some(e=>e.exiting)?e.visible:aa(e.visible),pending:[...e.pending,t.notice]};return{...e,visible:[...e.visible,t.notice]};case"mark_oldest_exiting":return{...e,visible:aa(e.visible)};case"remove":return function(e,t){let o=e,r=t;for(;r.length>0&&o.length<5;){let[e,...t]=r;o=[...o,e],r=t}return r.length>0&&!o.some(e=>e.exiting)&&(o=aa(o)),{visible:o,pending:r}}(e.visible.filter(e=>e.id!==t.id),e.pending);default:return e}}function ad(e){if(!e||"object"!=typeof e||"image"!==e.type)return"";let t=e.source;return t&&"object"==typeof t?["url"===t.type?"url":"base64","string"==typeof t.media_type?t.media_type:"","string"==typeof t.data?t.data:"","string"==typeof t.url?t.url:""].join(":"):["base64","string"==typeof e.mimeType?e.mimeType:"","string"==typeof e.data?e.data:"",""].join(":")}function ac(e){let t,o=e.content;return"string"==typeof o?JSON.stringify({text:o,images:[]}):Array.isArray(o)?JSON.stringify({text:"string"==typeof(t=e.content)?t:Array.isArray(t)?t.map(e=>e&&"object"==typeof e&&"text"===e.type&&"string"==typeof e.text?e.text:"").filter(Boolean).join("\n"):"",images:o.map(ad).filter(Boolean)}):JSON.stringify({text:"",images:[]})}function ap(e,t){return e&&"object"==typeof e?"number"!=typeof e.tokensBefore||"number"!=typeof e.estimatedTokensAfter?null:{reason:t,tokensBefore:e.tokensBefore,estimatedTokensAfter:e.estimatedTokensAfter}:null}let au="pi-web:modes-global-default",ah="pi:open-tasks-view";function ag({session:e,newSessionCwd:t,onAgentEnd:s,onSessionCreated:i,onSessionForked:l,modelsRefreshKey:d,chatInputRef:c,onBranchDataChange:p,onSystemPromptChange:u,onSessionStatsChange:h,onSessionStatsPanelOpen:g,onContextUsageChange:m,onOpenFile:f,onWorkspaceControlsHostChange:x,onViewFullHistory:k,systemPrompt:v,tasksBoardEnabled:y,onOpenSession:b}){var w;let j,{soundEnabled:S,onSoundToggle:C,playDoneSound:T,unlockAudio:R}=function(){let[e,t]=(0,n.useState)(()=>{let e=localStorage.getItem("pi-sound-enabled");return null===e||"true"===e}),o=(0,n.useRef)(e);(0,n.useEffect)(()=>{o.current=e},[e]);let r=(0,n.useRef)(null),s=(0,n.useCallback)(()=>{if(r.current&&"closed"!==r.current.state)return r.current;try{r.current=new AudioContext}catch{return null}return r.current},[]),i=(0,n.useCallback)((e=!1)=>{if(!e&&!o.current)return;let t=s();t&&"suspended"===t.state&&t.resume().catch(()=>{})},[s]);return{soundEnabled:e,onSoundToggle:(0,n.useCallback)(()=>{let e=!o.current;e&&i(!0),o.current=e,localStorage.setItem("pi-sound-enabled",String(e)),t(e)},[i]),playDoneSound:(0,n.useCallback)(()=>{if(!o.current)return;let e=s();if(!e)return;let t=()=>{try{let t;t=e.currentTime,[523.25,659.25].forEach((o,r)=>{let n=e.createOscillator(),s=e.createGain();n.connect(s),s.connect(e.destination),n.type="sine",n.frequency.value=o;let i=t+.18*r;s.gain.setValueAtTime(0,i),s.gain.linearRampToValueAtTime(.18,i+.02),s.gain.exponentialRampToValueAtTime(.001,i+.45),n.start(i),n.stop(i+.45)})}catch{}};"suspended"===e.state?e.resume().then(t).catch(()=>{}):t()},[s]),unlockAudio:i,soundEnabledRef:o}}(),z=O(),{t:I}=(0,A.s)(),M=(0,n.useRef)(T);M.current=T;let P=(0,n.useRef)(S);P.current=S;let E=(0,n.useRef)(null),W=(0,n.useCallback)(()=>{P.current&&M.current(),s?.()},[s]),F=(0,n.useCallback)(e=>{let t=e;if("string"==typeof e.content){let o=tM(e.content);o&&(t={...e,content:o})}c?.current?.replaceMessage(t)},[c]),D=(0,n.useCallback)(e=>{c?.current?.prependText(e)},[c]),N=(0,n.useCallback)((e,t)=>{nP={text:e,projectRoot:t??null},window.dispatchEvent(new CustomEvent(nM)),window.dispatchEvent(new Event(ah))},[]),{loading:L,error:$,messages:H,entryIds:B,streamState:U,agentRunning:_,bashRunning:q,pendingBash:V,modelNames:K,modelList:G,modelThinkingLevels:J,modelThinkingLevelMaps:Y,modelScopeWarnings:X,modelsError:Z,reloadModels:Q,toolPreset:ee,thinkingLevel:et,retryInfo:eo,contextUsage:er,forkingEntryId:en,isCompacting:es,compactError:ei,compactResult:ea,displayModel:el,sessionStats:ed,tokenRate:ec,slashCommands:ep,slashCommandsLoading:eu,queuedMessages:eh,pendingRecovery:eg,recoveryIsImport:em,notices:ef,extensionDialog:ex,extensionCustomUi:ek,extensionStatuses:ev,extensionWidgets:ey,respondToExtensionUi:eb,sendExtensionCustomInput:ew,agentPhase:ej,isNew:eS,branchTree:eC,activeLeafId:eT,handleLeafChange:eR,sessionIdRef:ez,messagesEndRef:eI,scrollContainerRef:eM,lastUserMsgRef:eP,pendingScrollToUserRef:eE,initialScrollDoneRef:eW,scrollUserMsgToTop:eF,handleSend:eD,executeBash:eA,handleAbort:eN,handleFork:eL,handleNavigate:e$,handleModelChange:eH,handleCompact:eO,handleSteer:eB,handleFollowUp:eU,handlePromptWithStreamingBehavior:e_,handleAbortCompaction:eq,handleRecallQueue:eV,resolveRecovery:eK,exportQueueData:eG,stageQueueImport:eJ,moveQueuedMessage:eY,recallQueuedMessage:eX,requeueAt:eZ,removeQueuedMessage:eQ,handleBuiltinSlashCommand:e0,handleToolPresetChange:e1,handleThinkingLevelChange:e2,loadSlashCommands:e4,planMode:e6,handlePlanModeChange:e8,collaborationMode:e5,toolApprovalMode:e3,handleCollaborationModeChange:e7,approvalRequests:e9,resolveApproval:te,goalState:tt,handleGoalStart:to,handleGoalPause:tr,handleGoalResume:tn,handleGoalStop:ts,handleGoalEdit:ti,historyCursor:ta,hasEarlierMessages:tl,loadContext:td}=function(e){let{session:t,newSessionCwd:r,onAgentEnd:s,onSessionCreated:i,onSessionForked:a,modelsRefreshKey:l,onBranchDataChange:d,onSystemPromptChange:c,onSessionStatsPanelOpen:p}=e,u=null===t&&null!==r,h=`${t?.id??"new"}\0${r??t?.cwd??""}`,[g,m]=(0,n.useState)(null),f=(0,n.useRef)(null),x=(0,n.useRef)(0),k=(0,n.useRef)(null),[v,y]=(0,n.useState)(!u),[b,w]=(0,n.useState)(null),[j,S]=(0,n.useState)(null),[C,T]=(0,n.useState)([]),[R,z]=(0,n.useState)([]),[I,M]=(0,n.useState)(null),[P,E]=(0,n.useState)(!1),[W,F]=(0,n.useReducer)(i7,{isStreaming:!1,streamingMessage:null}),D=(0,n.useRef)(!1);D.current=W.isStreaming;let[A,N]=(0,n.useState)(null),L=(0,n.useRef)({lastChars:0,window:[]}),$=(0,n.useCallback)(()=>{L.current={lastChars:0,window:[]},N(null)},[]),H=(0,n.useCallback)(e=>{if(!e||"assistant"!==e.role)return 0;let t=e.content;if(!Array.isArray(t))return 0;let o=0;for(let e of t)"string"==typeof e?o+=i5(e):e&&"object"==typeof e&&("string"==typeof e.text?o+=i5(e.text):"string"==typeof e.thinking&&(o+=i5(e.thinking)));return o},[]),O=(0,n.useCallback)(e=>{let t=H(e),o=L.current;if(t===o.lastChars)return;let r=Date.now(),n=Math.max(0,t-o.lastChars);o.lastChars=t,o.window.push({at:r,chars:n});let s=r-1e3;for(;o.window.length>0&&o.window[0].at<s;)o.window.shift();let i=o.window.reduce((e,t)=>e+t.chars,0),a=o.window.length>0?r-o.window[0].at:0;a<200||N(Math.max(0,Math.round(i/Math.max(1,a)*1e4)/10))},[H]),[B,U]=(0,n.useState)(!1),[_,q]=(0,n.useState)(!1),[V,K]=(0,n.useState)(null),[G,J]=(0,n.useState)({}),[Y,X]=(0,n.useState)([]),[Z,Q]=(0,n.useState)({}),[ee,et]=(0,n.useState)({}),[eo,er]=(0,n.useState)([]),[en,es]=(0,n.useState)(null),[ei,ea]=(0,n.useState)(null),[el,ed]=(0,n.useState)(null),[ec,ep]=(0,n.useState)("full"),[eu,eh]=(0,n.useState)(!1),eg=(0,n.useRef)("default"),em=(0,n.useRef)(!1);(0,n.useEffect)(()=>{em.current=eu},[eu]);let[ef,ex]=(0,n.useState)(()=>(function(){try{let e=window.localStorage.getItem(au);if(!e)return null;let t=JSON.parse(e),o=t.permissionRules;return{collaborationMode:tw(t.collaborationMode),tokenMode:tj(t.tokenMode),toolApprovalMode:tS(t.toolApprovalMode),permissionRules:{allow:Array.isArray(o?.allow)?o.allow:[],ask:Array.isArray(o?.ask)?o.ask:[],deny:Array.isArray(o?.deny)?o.deny:[]}}}catch{return null}})()??{collaborationMode:tv,tokenMode:ty,toolApprovalMode:tb,permissionRules:{allow:[],ask:[],deny:[]}}),ek=(0,n.useRef)(null),ev=(0,n.useRef)(!1),ey=(0,n.useRef)(t?.id??null);ey.current=t?.id??null,(0,n.useEffect)(()=>{let e=!1,t=async()=>{let t=ey.current,o=t?`?session=${encodeURIComponent(t)}`:"";try{let r=await fetch(`/api/modes${o}`);if(!r.ok||e)return;let n=await r.json();if(e)return;let s={collaborationMode:tw(n.collaborationMode),tokenMode:tj(n.tokenMode),toolApprovalMode:tS(n.toolApprovalMode),permissionRules:{allow:Array.isArray(n.permissionRules?.allow)?n.permissionRules.allow:[],ask:Array.isArray(n.permissionRules?.ask)?n.permissionRules.ask:[],deny:Array.isArray(n.permissionRules?.deny)?n.permissionRules.deny:[]}};if(!ev.current&&t&&"plan"===s.collaborationMode){let o=await fetch("/api/modes").catch(()=>null);if(!e&&o?.ok){let r=await o.json().catch(()=>null);if(!e&&r){let e=s.collaborationMode;(s={...s,collaborationMode:tw(r.collaborationMode)}).collaborationMode!==e&&fetch(`/api/modes?session=${encodeURIComponent(t)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)}).catch(()=>{})}}}ev.current=!0,ex(s),t||function(e){try{window.localStorage.setItem(au,JSON.stringify(e))}catch{}}(s)}catch{}};t();let o=()=>void t();return window.addEventListener("pi:modes-changed",o),()=>{e=!0,ev.current=!1,window.removeEventListener("pi:modes-changed",o)}},[t?.id]);let eb=ef.collaborationMode,ew=ef.tokenMode,ej=ef.toolApprovalMode,eS=ef.permissionRules,eC=(0,n.useRef)(eb),eT=(0,n.useRef)(ew),eR=(0,n.useRef)(ej),ez=(0,n.useRef)(ef.permissionRules),eI=(0,n.useRef)(null),eM=(0,n.useRef)({sessionKey:"",signature:""}),eP=(0,n.useRef)(ef);(0,n.useEffect)(()=>{eP.current=ef},[ef]),(0,n.useEffect)(()=>{eR.current=ej},[ej]),(0,n.useEffect)(()=>{ez.current=ef.permissionRules},[ef.permissionRules]),(0,n.useEffect)(()=>{eC.current=eb,eM.current={sessionKey:"",signature:""}},[eb]),(0,n.useEffect)(()=>{eT.current=ew,eM.current={sessionKey:"",signature:""}},[ew]);let[eE,eW]=(0,n.useState)([]),eF=(0,n.useRef)([]);(0,n.useEffect)(()=>{eF.current=eE},[eE]);let[eD,eA]=(0,n.useState)({status:"idle",goalText:null,turnsUsed:0,turnsLimit:10,noProgressTurns:0,noProgressLimit:4,tokensUsed:0,tokenBudget:null,timeUsedSeconds:0}),eN=(0,n.useRef)(eD);(0,n.useEffect)(()=>{eN.current=eD},[eD]);let eL=(0,n.useRef)(!1),[e$,eH]=(0,n.useState)("auto"),[eO,eB]=(0,n.useState)(null),[eU,e_]=(0,n.useState)(null),[eq,eV]=(0,n.useState)(null),[eK,eG]=(0,n.useState)(null),[eJ,eY]=(0,n.useState)(null),[eX,eZ]=(0,n.useState)(null),[eQ,e0]=(0,n.useState)(!1),[e1,e2]=(0,n.useState)(null),[e4,e6]=(0,n.useState)(null),[e8,e5]=(0,n.useState)(null),[e3,e7]=(0,n.useState)(!1),[e9,te]=(0,n.useState)([]),[tt,to]=(0,n.useState)(!1),[tr,tn]=(0,n.useReducer)(al,{visible:[],pending:[]}),[ts,ti]=(0,n.useState)(null),[ta,tl]=(0,n.useState)(null),[td,tc]=(0,n.useState)(null),[tp,tu]=(0,n.useState)([]),[th,tg]=(0,n.useState)([]),[tm,tf]=(0,n.useState)({steering:[],followUp:[]}),tx=(0,n.useCallback)(e=>{tf(t=>{let o="function"==typeof e?e(t):e;return ae(t.steering,o.steering)&&ae(t.followUp,o.followUp)?t:o})},[]),[tk,tP]=(0,n.useState)([]),tE=(0,n.useCallback)(e=>{tP(t=>{let o="function"==typeof e?e(t):e;return t.length===o.length&&t.every((e,t)=>{let r=o[t];return e.id===r.id&&e.kind===r.kind&&e.text===r.text&&e.hasImages===r.hasImages})?t:o})},[]),[tW,tF]=(0,n.useState)(!1),tD=(0,n.useRef)(null),tA=(0,n.useCallback)(()=>{tD.current&&clearTimeout(tD.current),tD.current=setTimeout(async()=>{tD.current=null;let e=t_.current;if(e)try{let t=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(!t.ok)return;let o=await t.json();o.state?.queuedMessages!==void 0&&tx(at(o.state.queuedMessages))}catch{}},8e3)},[tx]),tN=(0,n.useCallback)(()=>{tD.current&&(clearTimeout(tD.current),tD.current=null)},[]),tL=(0,n.useRef)(null),t$=(0,n.useRef)(null),tH=(0,n.useRef)(null),tO=(0,n.useRef)(null),tB=(0,n.useRef)(0),tU=(0,n.useRef)(!1),t_=(0,n.useRef)(t?.id??null),tq=(0,n.useRef)(!1),tV=(0,n.useRef)(!1),tK=(0,n.useRef)(!1),tG=(0,n.useRef)(-1),tJ=(0,n.useRef)(!0),tY=(0,n.useRef)(!1),tX=(0,n.useRef)(!1),tZ=(0,n.useRef)(!1),tQ=(0,n.useRef)(null),t0=(0,n.useRef)(!1),t1=(0,n.useRef)(null),t2=(0,n.useRef)(!1),t4=(0,n.useRef)(!0),t6=(0,n.useRef)(!0),t8=(0,n.useRef)(0),t5=(0,n.useRef)(0),t3=(0,n.useRef)(null),t7=(0,n.useRef)(null),t9=(0,n.useRef)(null),oe=(0,n.useRef)(!1),ot=(0,n.useRef)(0),oo=(0,n.useRef)(null),or=(0,n.useRef)(0),on=(0,n.useRef)(0),os=(0,n.useRef)(null),oi=(0,n.useRef)(h);oi.current=h;let oa=(0,n.useRef)(null),ol=(0,n.useRef)(null),od=(0,n.useRef)(null);od.current||(od.current=function(e,t={}){let o,r=1e3/Math.max(1,t.maxUpdatesPerSecond??30),n=t.now??i3,s=t.requestFrame??("function"==typeof requestAnimationFrame?requestAnimationFrame:void 0),i=t.cancelFrame??("function"==typeof cancelAnimationFrame?cancelAnimationFrame:void 0),a=t.setTimer??setTimeout,l=t.clearTimer??clearTimeout,d=!1,c=!1,p=null,u=null,h=null,g=()=>{null!==p&&(i?.(p),p=null),null!==u&&(l(u),u=null)},m=(t,r)=>{if(!c||d)return;let n=o;c=!1,o=void 0,h=t;let s=()=>{d||e(n)};r&&"function"==typeof queueMicrotask?queueMicrotask(s):s()},f=()=>{if(!d&&c&&null===p&&null===u){if(!s){let e=null===h?r:n()-h;u=a(()=>{u=null,m(n(),!0),f()},Math.max(0,r-e));return}p=s(e=>{if(p=null,d||!c)return;let t=null===h?r:e-h;if(t<r){u=a(()=>{u=null,f()},r-t);return}m(e,!0),f()})}};return{enqueue(e){d||(o=e,c=!0,f())},flush(){!d&&c&&(g(),m(n(),!1),f())},reset(){g(),c=!1,o=void 0,h=null},destroy(){d||(d=!0,g(),c=!1,o=void 0)}}}(e=>{F({type:"update",message:e})}));let oc=(0,n.useCallback)(()=>{od.current?.reset()},[]),op=(0,n.useCallback)(e=>{od.current?.enqueue(e)},[]),ou=e.setToolPreset??ep,oh=g?.context.model,og=oh&&oh.provider&&oh.modelId?oh:null,om=eJ??og??eX??null,of=u?ei??el:om,ox=(0,n.useMemo)(()=>{if(ts)return{...ts,totalActiveMs:g?.totalActiveMs};if(t&&g&&void 0===g.stats)return null;let e={input:0,output:0,cacheRead:0,cacheWrite:0,total:0},o=0,r=0,n=0,s=0,i=0,a=0,l=0;for(let t of C){if("user"===t.role&&(s+=1),"toolResult"===t.role&&(a+=1),"assistant"!==t.role)continue;i+=1;let d=t.usage;if(l+=t.content.filter(e=>"toolCall"===e.type).length,!d)continue;e.input+=d.input??0,e.output+=d.output??0,e.cacheRead+=d.cacheRead??0,e.cacheWrite+=d.cacheWrite??0;let c=d.cost?.total??0;o+=c,r4(t.model)?r+=r6(t.model,d):n+=c}let d=g?.stats;return(d&&(e.input=Math.max(e.input,d.tokens.input),e.output=Math.max(e.output,d.tokens.output),e.cacheRead=Math.max(e.cacheRead,d.tokens.cacheRead),e.cacheWrite=Math.max(e.cacheWrite,d.tokens.cacheWrite),n=Math.max(n,d.cost),s=Math.max(s,d.userMessages),i=Math.max(i,d.assistantMessages),a=Math.max(a,d.toolResults),l=Math.max(l,d.toolCalls)),e.total=e.input+e.output+e.cacheRead+e.cacheWrite,0!==e.total||0!==C.length||d)?{sessionFile:g?.filePath||void 0,sessionId:t_.current??t?.id??"",sessionName:t?.name,userMessages:s,assistantMessages:i,toolCalls:l,toolResults:a,totalMessages:d?Math.max(C.length,d.totalMessages):C.length,tokens:e,cost:o,costCNY:r,costUSD:n,totalActiveMs:g?.totalActiveMs,...eU?{contextUsage:eU}:{}}:null},[C,ts,eU,g?.filePath,g?.totalActiveMs,g?.stats,t?.id,t?.name]),ok=(0,n.useCallback)(async(e,t=!1,o=!1)=>{let r=x.current,n=!1;try{let s;t&&y(!0),f.current?.abort(),r=x.current+1,x.current=r;let i=new AbortController;f.current=i;let a=new URLSearchParams({deferThinking:"1",deferMedia:"1",view:"initial"}),l=async()=>{let t=new AbortController,o=setTimeout(()=>t.abort(),3e4),r=()=>t.abort();i.signal.addEventListener("abort",r,{once:!0});try{return await fetch(`/api/sessions/${encodeURIComponent(e)}?${a}`,{signal:t.signal})}finally{clearTimeout(o),i.signal.removeEventListener("abort",r)}};try{s=await l()}catch(e){if(!(e instanceof DOMException&&"AbortError"===e.name))throw e;if(i.signal.aborted)return null;s=await l()}if(404===s.status)return t&&(m(null),S(null),T([]),z([]),M(null),E(!1),w(null)),null;if(!s.ok)throw Error(`HTTP ${s.status}`);let d=await s.json();if(t_.current!==e||x.current!==r)return null;m(d),k.current?.abort();let c=new AbortController;if(k.current=c,fetch(`/api/sessions/${encodeURIComponent(e)}/details`,{signal:c.signal}).then(async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return await e.json()}).then(t=>{t_.current!==e||x.current!==r||c.signal.aborted||m(o=>o?.sessionId===e?{...o,...t}:o)}).catch(e=>{"AbortError"!==e.name&&console.warn("Failed to load session details",e)}),S(d.leafId),T(d.context.messages),z(d.context.entryIds??[]),tq.current||(t5.current=Date.now()+700),M(d.context.oldestEntryId),E(d.context.hasMore),eY(e=>e?d.context.model&&e.provider===d.context.model.provider&&e.modelId===d.context.model.modelId?null:e:null),w(null),d.context.thinkingLevel&&"off"!==d.context.thinkingLevel&&eH(d.context.thinkingLevel),n=!0,t&&y(!1),!o)return null;try{let t,o=new AbortController,n=setTimeout(()=>o.abort(),2e4);try{t=await fetch(`/api/sessions/${encodeURIComponent(e)}/state`,{signal:o.signal})}finally{clearTimeout(n)}if(!t.ok)throw Error(`HTTP ${t.status}`);let s=await t.json();if(t_.current!==e||x.current!==r)return null;let i=s.state;if(i){if(void 0!==i.contextUsage&&e_(i.contextUsage??null),void 0!==i.systemPrompt&&eV(i.systemPrompt??null),void 0!==i.thinkingLevel&&eH(i.thinkingLevel??"auto"),void 0!==i.extensionStatuses&&tu(i.extensionStatuses??[]),void 0!==i.extensionWidgets&&tg(i.extensionWidgets??[]),void 0!==i.queuedMessages&&tx(at(i.queuedMessages)),void 0!==i.pendingRecovery&&tE(i.pendingRecovery??[]),void 0!==i.goalState){let e=i.goalState;e&&(eN.current=e,eA(e))}}else s.running||tx({steering:[],followUp:[]});return s}catch(e){return console.error("Failed to load agent state:",e),null}}catch(t){let e=t instanceof DOMException&&"AbortError"===t.name;if(n)return console.warn("Failed to load auxiliary session state",t),null;return w(e?"Timed out loading this conversation. Please try again.":String(t)),null}finally{t&&!n&&x.current===r&&y(!1)}},[tE,tx]);(0,n.useEffect)(()=>{if(!t||!v)return;let e=window.setTimeout(()=>{tJ.current&&t_.current&&v&&(f.current?.abort(),k.current?.abort(),y(!1),w("Timed out loading this conversation. Please try again."))},35e3);return()=>window.clearTimeout(e)},[v,t]);let ov=(0,n.useCallback)(async(e,t,o)=>{try{let r=new URLSearchParams({deferThinking:"1",deferMedia:"1"});t&&r.set("leafId",t),o&&r.set("before",o);let n=`/api/sessions/${encodeURIComponent(e)}/context?${r}`,s=await fetch(n);if(!s.ok)throw Error(`HTTP ${s.status}`);let i=await s.json();if(t_.current!==e)return;M(i.context.oldestEntryId),E(i.context.hasMore),m(t=>{if(!t||t.sessionId!==e)return t;let r=o?{...t.context,messages:[...i.context.messages,...t.context.messages],entryIds:[...i.context.entryIds,...t.context.entryIds],oldestEntryId:i.context.oldestEntryId,hasMore:i.context.hasMore}:i.context;return{...t,context:r}}),o?(T(e=>[...i.context.messages,...e]),z(e=>[...i.context.entryIds,...e])):(T(i.context.messages),z(i.context.entryIds??[]))}catch(e){console.error("Failed to load context:",e)}},[]),oy=(0,n.useCallback)(async e=>{try{let t=await i6(e,{type:"get_tools"});if(t){let{getPresetFromTools:r}=await Promise.resolve().then(o.bind(o,14755)),n=r(t);"plan"!==n||em.current?ou(n):(await i6(e,{type:"set_tools",toolNames:(0,i8.xG)("default")}).catch(()=>{}),ou("default"))}}catch(e){console.error("Failed to load tools:",e)}},[ou]),ob=(0,n.useCallback)((e=0,t="(no messages)")=>{let o=t_.current;u&&r&&o&&!oe.current&&(oe.current=!0,i?.({id:o,path:"",cwd:r,name:void 0,created:new Date().toISOString(),modified:new Date().toISOString(),messageCount:e,firstMessage:t}))},[u,r,i]),ow=(0,n.useCallback)(async()=>{if(t_.current||!u||!r)return t_.current;if(t9.current)return t9.current;let e=(async()=>{let e,t=oa.current,o=ol.current;t&&eZ(t);let n=(0,i8.xG)(ec),s=new AbortController,i=setTimeout(()=>s.abort(),3e4);try{e=await fetch("/api/agent/new",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:r,type:"ensure_session",toolNames:n,...t?{provider:t.provider,modelId:t.modelId}:{},...o?{thinkingLevel:o}:{}}),signal:s.signal})}catch(e){if(s.signal.aborted)throw Error("Timed out creating a new session after 30s. The agent service may still be starting up — please try again.");throw e}finally{clearTimeout(i)}if(!e.ok){let t=await e.json().catch(()=>null);throw Error(t?.error??`HTTP ${e.status}`)}let a=await e.json();t_.current=a.sessionId;let l=ek.current;return l&&(ek.current=null,fetch(`/api/modes?session=${encodeURIComponent(a.sessionId)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)}).catch(e=>{console.error("Failed to persist pending mode settings:",e)})),a.model&&oa.current===t&&(eZ(a.model),t||ed(a.model)),a.thinkingLevel&&ol.current===o&&eH(a.thinkingLevel),a.sessionId})();t9.current=e;try{return await e}finally{t9.current=null}},[u,r,ec]),oj=(0,n.useCallback)(async()=>{let e=t_.current??await ow();if(!e)return te([]),[];to(!0);try{let t=await i6(e,{type:"get_commands"}),o=t?.commands??[];return te(o),o}catch(e){return console.error("Failed to load slash commands:",e),te([]),[]}finally{to(!1)}},[ow]),oS=(0,n.useCallback)(()=>{tB.current+=1,tU.current=!1,tO.current&&(clearTimeout(tO.current),tO.current=null)},[]),oC=(0,n.useCallback)(()=>{tL.current?.close(),tL.current=null,t$.current=null,tH.current=null},[]),oT=(0,n.useCallback)(e=>{oC();let t=new EventSource(`/api/agent/${encodeURIComponent(e)}/events`);tL.current=t,t$.current=e;let o=new Promise(o=>{let r=!1,n=e=>{r||(r=!0,clearTimeout(s),tH.current?.source===t&&(tH.current.pending=!1),o({status:e,source:t}))},s=setTimeout(()=>n("timeout"),3e4);t.onmessage=e=>{try{let t=JSON.parse(e.data);"connected"===t.type&&n("connected"),tQ.current?.(t)}catch{}},t.onerror=()=>{if(t.readyState!==EventSource.CLOSED||(n("closed"),tL.current!==t||!tq.current&&!tU.current))return;tL.current=null,t$.current=null,tH.current=null;let o=tB.current;setTimeout(()=>{o===tB.current&&!tL.current&&(tq.current||tU.current)&&oT(e)},1e3)}});return tH.current={source:t,promise:o,pending:!0},o},[oC]),oR=(0,n.useCallback)(async e=>{let t=tL.current;if(t&&t$.current===e){if(t.readyState===EventSource.OPEN)return;let e=tH.current;if(e?.source===t&&e.pending&&(await e.promise,tL.current===t&&t.readyState===EventSource.OPEN))return}let o=await oT(e);if("connected"!==o.status&&o.source.readyState!==EventSource.OPEN)throw tL.current===o.source&&(tL.current=null),t$.current===e&&(t$.current=null),tH.current?.source===o.source&&(tH.current=null),o.source.close(),new as(o.status)},[oT]),oz=(0,n.useCallback)(async(e,t)=>{let o=t_.current;if(tl(t=>t?.id===e.id?null:t),o)try{await i6(o,{type:"extension_ui_response",id:e.id,...t})}catch(e){console.error("Failed to send extension UI response:",e)}},[]),oI=(0,n.useCallback)(async(e,t)=>{let o=t_.current;if(o)try{await i6(o,{type:"extension_ui_input",id:e.id,data:t})}catch(e){console.error("Failed to send extension custom UI input:",e)}},[]),oM=(0,n.useCallback)(e=>{let t=e.message.trim();if(!t)return;let o=e.type??"info";("error"===o||"warning"===o)&&fetch("/api/logs",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({level:o,source:"agent-notice",sessionId:t_.current??void 0,message:t})}).catch(()=>{}),tn({type:"add",notice:{id:e.id??("u">typeof crypto&&"function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2)}`),message:t,type:o}})},[]),oP=(0,n.useCallback)(t=>{switch(t.method){case"select":case"confirm":case"input":case"editor":tl(t);break;case"notify":oM({id:t.id,message:function(e){if(!("u">typeof document&&("zh-CN"===document.documentElement.lang||"zh"===document.documentElement.lang)))return e;let t=e.trim();return t.startsWith("Plan mode enabled")?"已启用计划模式:只读分析与产出计划,不修改文件。":t.startsWith("Plan mode disabled")?"已退出计划模式。":t.startsWith("No completed plan is available")?"当前没有可用的已完成计划。":t.startsWith("Unable to send Plan-mode message")?`无法发送计划模式消息:${t.replace(/^Unable to send Plan-mode message:\s*/,"")}`:e}(t.message),type:t.notifyType??"info"});break;case"setStatus":tu(e=>{let o=e.filter(e=>e.key!==t.statusKey);return t.statusText?[...o,{key:t.statusKey,text:t.statusText}]:o});break;case"setWidget":tg(e=>{let o=e.filter(e=>e.key!==t.widgetKey);return t.widgetLines?[...o,{key:t.widgetKey,lines:t.widgetLines,placement:t.widgetPlacement??"aboveEditor"}]:o});break;case"setTitle":t.title&&(document.title=t.title);break;case"set_editor_text":e.chatInputRef?.current?.insertText(t.text);break;case"custom":tc(e=>t.closed?e?.id===t.id?null:e:t)}},[oM,e.chatInputRef]),oE=(0,n.useRef)(null),oW=(0,n.useCallback)(()=>{null!==oE.current&&(cancelAnimationFrame(oE.current),oE.current=null)},[]),oF=(0,n.useCallback)(()=>{oc(),oW();let e=tq.current;return tq.current=!1,U(!1),e5(null),eB(null),F({type:"end"}),e},[oW,oc]),oD=(0,n.useCallback)(e=>tG.current!==e&&(tG.current=e,s?.(),!0),[s]),oA=(0,n.useCallback)(e=>{oS(),tU.current=!0;let t=tB.current,o=async()=>{if(t===tB.current&&t_.current===e&&tU.current)try{let r=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(!r.ok)throw Error(`HTTP ${r.status}`);let n=await r.json();if(t!==tB.current||t_.current!==e||!tU.current)return;let s=n.state;if(n.running&&s&&(s.isStreaming||s.isPromptRunning)){tU.current=!1,tO.current=null,tV.current=!!s?.isStreaming,tK.current=!!s?.isPromptRunning,tq.current=!0,U(!0),e5(i9(s));return}if(n.running&&s?.isCompacting){e0(!0),tO.current=setTimeout(()=>void o(),600);return}tU.current=!1,tO.current=null,oC()}catch{if(t!==tB.current||t_.current!==e||!tU.current)return;tO.current=setTimeout(()=>void o(),600)}};tO.current=setTimeout(()=>void o(),12e4)},[oS,oC]),oN=(0,n.useCallback)(async(e=t_.current,t=ot.current)=>{if(ot.current===t)try{e&&await ok(e)}finally{if(ot.current!==t)return;let o=tK.current,r=tV.current;tK.current=!1,tV.current=!1,oo.current=null;let n=oF();o?oD(t):r&&n&&s?.(),e&&oA(e)}},[ok,oD,s,oA,oF]),oL=(0,n.useCallback)(async(e,t=ot.current)=>{await ai(800);let o=Date.now(),r=0;for(;Date.now()-o<2e4;){if(!tJ.current||ot.current!==t)return;try{let n=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(n.ok){r=0;let s=await n.json(),i=s.state;if(!(s.running&&i&&(i.isStreaming||i.isPromptRunning)))return void await oN(e,t);o=Date.now()}else r+=1}catch{r+=1}if(r>=3){if(ot.current!==t)return;oM({type:"error",message:"Cannot reach the pi-web service. Make sure it is running, then refresh the page."}),tK.current=!1,oo.current=null,oF();return}await ai(3e3)}ot.current===t&&(oM({type:"error",message:"Message delivery could not be confirmed. Refresh the page to see the latest state."}),tK.current=!1,oo.current=null,oF())},[oM,oN,oF]),o$=(0,n.useCallback)(async e=>{if(!tq.current&&!D.current)return;let t=ot.current;try{let o=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(!o.ok)return;let r=await o.json();if(ot.current!==t)return;let n=r.state;if(e0(n?.isCompacting??!1),tK.current||e5(i9(n)),tx(at(n?.queuedMessages)),tE(n?.pendingRecovery??[]),r.running&&n&&(n.isStreaming||n.isPromptRunning||n.isBashRunning||n.isCompacting)||!tq.current&&!D.current)return;if(n&&(void 0!==n.contextUsage&&e_(n.contextUsage??null),void 0!==n.systemPrompt&&eV(n.systemPrompt??null),void 0!==n.extensionStatuses&&tu(n.extensionStatuses??[]),void 0!==n.extensionWidgets&&tg(n.extensionWidgets??[]),void 0!==n.goalState)){let e=n.goalState;e&&(eN.current=e,eA(e))}await oN(e,t)}catch{}},[oN,tE,tx]);(0,n.useEffect)(()=>{if(!B&&!W.isStreaming)return;let e=()=>{let e=t_.current;e&&o$(e)},t=()=>{"visible"===document.visibilityState&&e()},o=setInterval(e,15e3);return document.addEventListener("visibilitychange",t),window.addEventListener("online",e),()=>{clearInterval(o),document.removeEventListener("visibilitychange",t),window.removeEventListener("online",e)}},[B,W.isStreaming,o$]),(0,n.useEffect)(()=>{tq.current=B,B||e7(!1)},[B]);let oH=(0,n.useCallback)((t="smooth")=>{t5.current=Date.now()+700;let o=t7.current,r=t3.current;if(!o||!r)return;let n=Math.max(88,e.chatInputRef?.current?.measureHeight?.()??0),s=()=>{if(!o||!r)return;let e=Math.max(0,r.getBoundingClientRect().top-o.getBoundingClientRect().top+o.scrollTop-96-o.clientHeight+n);o.scrollTo({top:e,behavior:t})};s(),("instant"===t||"auto"===t)&&window.setTimeout(()=>{o&&r&&t6.current&&s()},200)},[]),oO=(0,n.useCallback)(()=>{null===oE.current&&(oE.current=requestAnimationFrame(()=>{oE.current=null,requestAnimationFrame(()=>{if(!tq.current||Date.now()<t8.current)return;let e=t7.current;if(e){let{scrollTop:t,clientHeight:o,scrollHeight:r}=e;t6.current=t+o>=r-150}t6.current&&oH("auto")})}))},[oH]);tQ.current=(0,n.useCallback)(e=>{switch(e.type){case"agent_start":oc(),$(),oS(),tq.current||(tY.current=!1),tV.current=!0,tq.current=!0,U(!0),e5({kind:"waiting_model"}),F({type:"start"}),oO();break;case"agent_end":{if(oc(),$(),!tq.current)break;if(e5(tm.steering.length>0||tm.followUp.length>0?{kind:"waiting_model"}:null),eB(null),F({type:"end"}),!0!==e.willRetry){let t=e.messages??[];for(let e=t.length-1;e>=0;e--){let o=t[e];if(o?.role==="assistant"){"error"===o.stopReason&&o.errorMessage&&oM({type:"error",message:o.errorMessage});break}}}let t=t_.current;if(t){let e=ot.current;ok(t),fetch(`/api/agent/${encodeURIComponent(t)}`).then(e=>e.ok?e.json():void 0).then(t=>{if(ot.current!==e)return;let o=t?.state;if(o?.contextUsage!==void 0&&e_(o.contextUsage??null),o?.systemPrompt!==void 0&&eV(o.systemPrompt??null),o?.extensionStatuses!==void 0&&tu(o.extensionStatuses??[]),o?.extensionWidgets!==void 0&&tg(o.extensionWidgets??[]),tx(at(o?.queuedMessages)),tE(o?.pendingRecovery??[]),o?.goalState!==void 0){let e=o.goalState;e&&(eN.current=e,eA(e))}}).catch(()=>{})}break}case"agent_settled":{let e=tV.current;if(tV.current=!1,!e||tK.current)break;let t=t_.current,o=oF();e0(!1),t&&(ok(t),oA(t)),o&&!tY.current&&s?.(),tY.current=!1;break}case"goal_state_changed":{let t=e.goalState;t&&(eN.current=t,eA(t));break}case"prompt_done":{let e=ot.current,t=tK.current;tK.current=!1,oo.current=null;let o=oD(e);if(o&&(tY.current=!0),!t&&!o)break;let r=t_.current;r&&ok(r),!tV.current&&(oF(),r&&oA(r));break}case"tool_approval_request":{let t={id:String(e.id??""),toolName:String(e.toolName??""),args:e.args};if(!t.id)break;eW(e=>e.some(e=>e.id===t.id)?e:[...e,t]);break}case"tool_approval_resolved":{let t=String(e.id??"");if(!t)break;eW(e=>e.filter(e=>e.id!==t));break}case"prompt_error":oM({type:"error",message:e.errorMessage??"Command failed"});break;case"extension_error":oM({type:"error",message:e.error??"Extension command failed"});break;case"message_start":case"message_update":{if(!tq.current)break;let t=e.message;if(t?.role==="user")break;t&&(O(t),op(i0(t))),e5(e=>null===e?e:null),oO();break}case"message_end":{if(!tq.current)break;let t=e.message;if(t&&"user"===t.role){let e=i0(t);if("user"===e.role&&"content"in e){let t=e.content;if("string"==typeof t)ar.some(e=>t.startsWith(e))&&(e={...e,content:tM(t)});else if(Array.isArray(t)){let o=t.filter(e=>"text"===e.type)[0];o&&"string"==typeof o.text&&ar.some(e=>o.text?.startsWith(e))&&(e={...e,content:t.map((e,t)=>{if("text"!==e.type||0!==t)return e;let o=tM(e.text??"");return{...e,text:o}})})}}let o=ac(e),r=oo.current;T(t=>{let n=t[t.length-1];return r&&n?.role==="user"&&ac(n)===r?(oo.current=null,r===o?t:[...t.slice(0,-1),e]):[...t,e]})}else t&&T(e=>[...e,i0(t)]);oc(),F({type:"reset"}),e5({kind:"waiting_model"});break}case"tool_execution_start":{let t=e.toolCallId,o=e.toolName;e5(e=>{let r=e?.kind==="running_tools"?[...e.tools]:[];return r.some(e=>e.id===t)||r.push({id:t,name:o}),{kind:"running_tools",tools:r}});break}case"tool_execution_end":{let t=e.toolCallId;e5(e=>{if(e?.kind!=="running_tools")return e;let o=e.tools.filter(e=>e.id!==t);return 0===o.length?{kind:"waiting_model"}:{kind:"running_tools",tools:o}});break}case"entry_appended":break;case"queue_update":tx({steering:[...e.steering??[]],followUp:[...e.followUp??[]]}),(e.steering??[]).length>0||(e.followUp??[]).length>0?tA():tN();break;case"state_sync":{let t=e.state;if(!t)break;if(e0(t.isCompacting??!1),tK.current||e5(i9(t)),tx(at(t.queuedMessages)),tE(t.pendingRecovery??[]),void 0!==t.contextUsage&&e_(t.contextUsage??null),void 0!==t.systemPrompt&&eV(t.systemPrompt??null),void 0!==t.extensionStatuses&&tu(t.extensionStatuses??[]),void 0!==t.extensionWidgets&&tg(t.extensionWidgets??[]),void 0!==t.goalState){let e=t.goalState;e&&(eN.current=e,eA(e))}if(t.isStreaming||t.isPromptRunning||t.isBashRunning||t.isCompacting){let e=tq.current;tq.current=!0,U(!0),e||F({type:"start"})}else if(tq.current&&!tK.current){let e=t_.current;e&&oN(e,ot.current)}break}case"auto_retry_start":eB({attempt:e.attempt,maxAttempts:e.maxAttempts,errorMessage:e.errorMessage});break;case"auto_retry_end":eB(null);break;case"auto_compaction_start":case"compaction_start":e0(!0),e2(null),e6(null);break;case"auto_compaction_end":case"compaction_end":e0(!1),e.errorMessage?(e2(e.errorMessage),e6(null)):!e.aborted&&(e6(ap(e.result,e.reason??"auto")),t_.current&&ok(t_.current));break;case"extension_ui_request":oP(e)}},[oM,oS,oW,oN,oP,ok,oD,s,tm,oA,oO,oF,op,oc,tA,tN,O,$,tE,tx]),(0,n.useEffect)(()=>{let e=new EventSource("/api/events");return e.onmessage=e=>{try{let t=JSON.parse(e.data);if(!t||!t.type||!t.payload||t.sessionId!==t_.current||tL.current?.readyState===EventSource.OPEN)return;tQ.current?.(t.payload)}catch{}},()=>e.close()},[]);let oB=(0,n.useCallback)(async(o,n)=>{let s,i=o.trim();if(!i&&!n?.length)return;if(tq.current||tX.current)return void console.warn("[pi-web] Send dropped: a previous run is still marked active",{agentRunning:tq.current,bashRunning:tX.current,sessionId:t_.current});let a=!n?.length&&i.startsWith("/"),l=ot.current+1;oS(),oc(),tK.current=!0;let d=function(e){let t=[];if("plan"===e.collaborationMode&&t.push(tT),"economy"===e.tokenMode&&t.push(tR),"delivery"===e.tokenMode&&t.push(tz),"goal"===e.collaborationMode){let o=e.goalText?.trim();t.push(o?`${tI}
32
+ - Do not write code yet — the plan itself is the deliverable.`,ar=["You are in PLAN MODE.","<economy-profile>","<delivery-profile>","<goal-profile>"],an=new Set(["ArrowUp","ArrowDown","PageUp","PageDown","Home","End"," ","Space","Spacebar"]);class as extends Error{constructor(e){super("timeout"===e?"Timed out connecting to the agent event stream. Please try again.":"Failed to connect to the agent event stream. Please try again."),this.status=e,this.name="EventStreamConnectionError"}}function ai(e){return new Promise(t=>setTimeout(t,e))}function aa(e){let t=e.findIndex(e=>!e.exiting);return -1===t?e:e.map((e,o)=>o===t?{...e,exiting:!0}:e)}function al(e,t){switch(t.type){case"add":if(e.visible.some(e=>e.exiting)||e.visible.length>=5)return{visible:e.visible.some(e=>e.exiting)?e.visible:aa(e.visible),pending:[...e.pending,t.notice]};return{...e,visible:[...e.visible,t.notice]};case"mark_oldest_exiting":return{...e,visible:aa(e.visible)};case"remove":return function(e,t){let o=e,r=t;for(;r.length>0&&o.length<5;){let[e,...t]=r;o=[...o,e],r=t}return r.length>0&&!o.some(e=>e.exiting)&&(o=aa(o)),{visible:o,pending:r}}(e.visible.filter(e=>e.id!==t.id),e.pending);default:return e}}function ad(e){if(!e||"object"!=typeof e||"image"!==e.type)return"";let t=e.source;return t&&"object"==typeof t?["url"===t.type?"url":"base64","string"==typeof t.media_type?t.media_type:"","string"==typeof t.data?t.data:"","string"==typeof t.url?t.url:""].join(":"):["base64","string"==typeof e.mimeType?e.mimeType:"","string"==typeof e.data?e.data:"",""].join(":")}function ac(e){let t,o=e.content;return"string"==typeof o?JSON.stringify({text:o,images:[]}):Array.isArray(o)?JSON.stringify({text:"string"==typeof(t=e.content)?t:Array.isArray(t)?t.map(e=>e&&"object"==typeof e&&"text"===e.type&&"string"==typeof e.text?e.text:"").filter(Boolean).join("\n"):"",images:o.map(ad).filter(Boolean)}):JSON.stringify({text:"",images:[]})}function ap(e,t){return e&&"object"==typeof e?"number"!=typeof e.tokensBefore||"number"!=typeof e.estimatedTokensAfter?null:{reason:t,tokensBefore:e.tokensBefore,estimatedTokensAfter:e.estimatedTokensAfter}:null}let au="pi-web:modes-global-default",ah="pi:open-tasks-view";function ag({session:e,newSessionCwd:t,onAgentEnd:s,onSessionCreated:i,onSessionForked:l,modelsRefreshKey:d,chatInputRef:c,onBranchDataChange:p,onSystemPromptChange:u,onSessionStatsChange:h,onSessionStatsPanelOpen:g,onContextUsageChange:m,onOpenFile:f,onWorkspaceControlsHostChange:x,onViewFullHistory:k,systemPrompt:v,tasksBoardEnabled:y,onOpenSession:b}){var w;let j,{soundEnabled:S,onSoundToggle:C,playDoneSound:T,unlockAudio:R}=function(){let[e,t]=(0,n.useState)(()=>{let e=localStorage.getItem("pi-sound-enabled");return null===e||"true"===e}),o=(0,n.useRef)(e);(0,n.useEffect)(()=>{o.current=e},[e]);let r=(0,n.useRef)(null),s=(0,n.useCallback)(()=>{if(r.current&&"closed"!==r.current.state)return r.current;try{r.current=new AudioContext}catch{return null}return r.current},[]),i=(0,n.useCallback)((e=!1)=>{if(!e&&!o.current)return;let t=s();t&&"suspended"===t.state&&t.resume().catch(()=>{})},[s]);return{soundEnabled:e,onSoundToggle:(0,n.useCallback)(()=>{let e=!o.current;e&&i(!0),o.current=e,localStorage.setItem("pi-sound-enabled",String(e)),t(e)},[i]),playDoneSound:(0,n.useCallback)(()=>{if(!o.current)return;let e=s();if(!e)return;let t=()=>{try{let t;t=e.currentTime,[523.25,659.25].forEach((o,r)=>{let n=e.createOscillator(),s=e.createGain();n.connect(s),s.connect(e.destination),n.type="sine",n.frequency.value=o;let i=t+.18*r;s.gain.setValueAtTime(0,i),s.gain.linearRampToValueAtTime(.18,i+.02),s.gain.exponentialRampToValueAtTime(.001,i+.45),n.start(i),n.stop(i+.45)})}catch{}};"suspended"===e.state?e.resume().then(t).catch(()=>{}):t()},[s]),unlockAudio:i,soundEnabledRef:o}}(),z=O(),{t:I}=(0,A.s)(),M=(0,n.useRef)(T);M.current=T;let P=(0,n.useRef)(S);P.current=S;let E=(0,n.useRef)(null),W=(0,n.useCallback)(()=>{P.current&&M.current(),s?.()},[s]),F=(0,n.useCallback)(e=>{let t=e;if("string"==typeof e.content){let o=tM(e.content);o&&(t={...e,content:o})}c?.current?.replaceMessage(t)},[c]),D=(0,n.useCallback)(e=>{c?.current?.prependText(e)},[c]),N=(0,n.useCallback)((e,t)=>{nP={text:e,projectRoot:t??null},window.dispatchEvent(new CustomEvent(nM)),window.dispatchEvent(new Event(ah))},[]),{loading:L,error:$,messages:H,entryIds:B,streamState:U,agentRunning:_,bashRunning:q,pendingBash:V,modelNames:K,modelList:G,modelThinkingLevels:J,modelThinkingLevelMaps:Y,modelScopeWarnings:X,modelsError:Z,reloadModels:Q,toolPreset:ee,thinkingLevel:et,retryInfo:eo,contextUsage:er,forkingEntryId:en,isCompacting:es,compactError:ei,compactResult:ea,displayModel:el,sessionStats:ed,tokenRate:ec,slashCommands:ep,slashCommandsLoading:eu,queuedMessages:eh,pendingRecovery:eg,recoveryIsImport:em,notices:ef,extensionDialog:ex,extensionCustomUi:ek,extensionStatuses:ev,extensionWidgets:ey,respondToExtensionUi:eb,sendExtensionCustomInput:ew,agentPhase:ej,isNew:eS,branchTree:eC,activeLeafId:eT,handleLeafChange:eR,sessionIdRef:ez,messagesEndRef:eI,scrollContainerRef:eM,lastUserMsgRef:eP,pendingScrollToUserRef:eE,initialScrollDoneRef:eW,scrollUserMsgToTop:eF,handleSend:eD,executeBash:eA,handleAbort:eN,handleFork:eL,handleNavigate:e$,handleModelChange:eH,handleCompact:eO,handleSteer:eB,handleFollowUp:eU,handlePromptWithStreamingBehavior:e_,handleAbortCompaction:eq,handleRecallQueue:eV,resolveRecovery:eK,exportQueueData:eG,stageQueueImport:eJ,moveQueuedMessage:eY,recallQueuedMessage:eX,requeueAt:eZ,removeQueuedMessage:eQ,handleBuiltinSlashCommand:e0,handleToolPresetChange:e1,handleThinkingLevelChange:e2,loadSlashCommands:e4,planMode:e6,handlePlanModeChange:e8,collaborationMode:e5,toolApprovalMode:e3,handleCollaborationModeChange:e7,approvalRequests:e9,resolveApproval:te,goalState:tt,handleGoalStart:to,handleGoalPause:tr,handleGoalResume:tn,handleGoalStop:ts,handleGoalEdit:ti,historyCursor:ta,hasEarlierMessages:tl,loadContext:td}=function(e){let{session:t,newSessionCwd:r,onAgentEnd:s,onSessionCreated:i,onSessionForked:a,modelsRefreshKey:l,onBranchDataChange:d,onSystemPromptChange:c,onSessionStatsPanelOpen:p}=e,u=null===t&&null!==r,h=`${t?.id??"new"}\0${r??t?.cwd??""}`,[g,m]=(0,n.useState)(null),f=(0,n.useRef)(null),x=(0,n.useRef)(0),k=(0,n.useRef)(null),[v,y]=(0,n.useState)(!u),[b,w]=(0,n.useState)(null),[j,S]=(0,n.useState)(null),[C,T]=(0,n.useState)([]),[R,z]=(0,n.useState)([]),[I,M]=(0,n.useState)(null),[P,E]=(0,n.useState)(!1),[W,F]=(0,n.useReducer)(i7,{isStreaming:!1,streamingMessage:null}),D=(0,n.useRef)(!1);D.current=W.isStreaming;let[A,N]=(0,n.useState)(null),L=(0,n.useRef)({lastChars:0,window:[]}),$=(0,n.useCallback)(()=>{L.current={lastChars:0,window:[]},N(null)},[]),H=(0,n.useCallback)(e=>{if(!e||"assistant"!==e.role)return 0;let t=e.content;if(!Array.isArray(t))return 0;let o=0;for(let e of t)"string"==typeof e?o+=i5(e):e&&"object"==typeof e&&("string"==typeof e.text?o+=i5(e.text):"string"==typeof e.thinking&&(o+=i5(e.thinking)));return o},[]),O=(0,n.useCallback)(e=>{let t=H(e),o=L.current;if(t===o.lastChars)return;let r=Date.now(),n=Math.max(0,t-o.lastChars);o.lastChars=t,o.window.push({at:r,chars:n});let s=r-1e3;for(;o.window.length>0&&o.window[0].at<s;)o.window.shift();let i=o.window.reduce((e,t)=>e+t.chars,0),a=o.window.length>0?r-o.window[0].at:0;a<200||N(Math.max(0,Math.round(i/Math.max(1,a)*1e4)/10))},[H]),[B,U]=(0,n.useState)(!1),[_,q]=(0,n.useState)(!1),[V,K]=(0,n.useState)(null),[G,J]=(0,n.useState)({}),[Y,X]=(0,n.useState)([]),[Z,Q]=(0,n.useState)({}),[ee,et]=(0,n.useState)({}),[eo,er]=(0,n.useState)([]),[en,es]=(0,n.useState)(null),[ei,ea]=(0,n.useState)(null),[el,ed]=(0,n.useState)(null),[ec,ep]=(0,n.useState)("full"),[eu,eh]=(0,n.useState)(!1),eg=(0,n.useRef)("default"),em=(0,n.useRef)(!1);(0,n.useEffect)(()=>{em.current=eu},[eu]);let[ef,ex]=(0,n.useState)(()=>(function(){try{let e=window.localStorage.getItem(au);if(!e)return null;let t=JSON.parse(e),o=t.permissionRules;return{collaborationMode:tw(t.collaborationMode),tokenMode:tj(t.tokenMode),toolApprovalMode:tS(t.toolApprovalMode),permissionRules:{allow:Array.isArray(o?.allow)?o.allow:[],ask:Array.isArray(o?.ask)?o.ask:[],deny:Array.isArray(o?.deny)?o.deny:[]}}}catch{return null}})()??{collaborationMode:tv,tokenMode:ty,toolApprovalMode:tb,permissionRules:{allow:[],ask:[],deny:[]}}),ek=(0,n.useRef)(null),ev=(0,n.useRef)(!1),ey=(0,n.useRef)(t?.id??null);ey.current=t?.id??null,(0,n.useEffect)(()=>{let e=!1,t=async()=>{let t=ey.current,o=t?`?session=${encodeURIComponent(t)}`:"";try{let r=await fetch(`/api/modes${o}`);if(!r.ok||e)return;let n=await r.json();if(e)return;let s={collaborationMode:tw(n.collaborationMode),tokenMode:tj(n.tokenMode),toolApprovalMode:tS(n.toolApprovalMode),permissionRules:{allow:Array.isArray(n.permissionRules?.allow)?n.permissionRules.allow:[],ask:Array.isArray(n.permissionRules?.ask)?n.permissionRules.ask:[],deny:Array.isArray(n.permissionRules?.deny)?n.permissionRules.deny:[]}};if(!ev.current&&t&&"plan"===s.collaborationMode){let o=await fetch("/api/modes").catch(()=>null);if(!e&&o?.ok){let r=await o.json().catch(()=>null);if(!e&&r){let e=s.collaborationMode;(s={...s,collaborationMode:tw(r.collaborationMode)}).collaborationMode!==e&&fetch(`/api/modes?session=${encodeURIComponent(t)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)}).catch(()=>{})}}}ev.current=!0,ex(s),t||function(e){try{window.localStorage.setItem(au,JSON.stringify(e))}catch{}}(s)}catch{}};t();let o=()=>void t();return window.addEventListener("pi:modes-changed",o),()=>{e=!0,ev.current=!1,window.removeEventListener("pi:modes-changed",o)}},[t?.id]);let eb=ef.collaborationMode,ew=ef.tokenMode,ej=ef.toolApprovalMode,eS=ef.permissionRules,eC=(0,n.useRef)(eb),eT=(0,n.useRef)(ew),eR=(0,n.useRef)(ej),ez=(0,n.useRef)(ef.permissionRules),eI=(0,n.useRef)(null),eM=(0,n.useRef)({sessionKey:"",signature:""}),eP=(0,n.useRef)(ef);(0,n.useEffect)(()=>{eP.current=ef},[ef]),(0,n.useEffect)(()=>{eR.current=ej},[ej]),(0,n.useEffect)(()=>{ez.current=ef.permissionRules},[ef.permissionRules]),(0,n.useEffect)(()=>{eC.current=eb,eM.current={sessionKey:"",signature:""}},[eb]),(0,n.useEffect)(()=>{eT.current=ew,eM.current={sessionKey:"",signature:""}},[ew]);let[eE,eW]=(0,n.useState)([]),eF=(0,n.useRef)([]);(0,n.useEffect)(()=>{eF.current=eE},[eE]);let[eD,eA]=(0,n.useState)({status:"idle",goalText:null,turnsUsed:0,turnsLimit:10,noProgressTurns:0,noProgressLimit:4,tokensUsed:0,tokenBudget:null,timeUsedSeconds:0}),eN=(0,n.useRef)(eD);(0,n.useEffect)(()=>{eN.current=eD},[eD]);let eL=(0,n.useRef)(!1),[e$,eH]=(0,n.useState)("auto"),[eO,eB]=(0,n.useState)(null),[eU,e_]=(0,n.useState)(null),[eq,eV]=(0,n.useState)(null),[eK,eG]=(0,n.useState)(null),[eJ,eY]=(0,n.useState)(null),[eX,eZ]=(0,n.useState)(null),[eQ,e0]=(0,n.useState)(!1),[e1,e2]=(0,n.useState)(null),[e4,e6]=(0,n.useState)(null),[e8,e5]=(0,n.useState)(null),[e3,e7]=(0,n.useState)(!1),[e9,te]=(0,n.useState)([]),[tt,to]=(0,n.useState)(!1),[tr,tn]=(0,n.useReducer)(al,{visible:[],pending:[]}),[ts,ti]=(0,n.useState)(null),[ta,tl]=(0,n.useState)(null),[td,tc]=(0,n.useState)(null),[tp,tu]=(0,n.useState)([]),[th,tg]=(0,n.useState)([]),[tm,tf]=(0,n.useState)({steering:[],followUp:[]}),tx=(0,n.useCallback)(e=>{tf(t=>{let o="function"==typeof e?e(t):e;return ae(t.steering,o.steering)&&ae(t.followUp,o.followUp)?t:o})},[]),[tk,tP]=(0,n.useState)([]),tE=(0,n.useCallback)(e=>{tP(t=>{let o="function"==typeof e?e(t):e;return t.length===o.length&&t.every((e,t)=>{let r=o[t];return e.id===r.id&&e.kind===r.kind&&e.text===r.text&&e.hasImages===r.hasImages})?t:o})},[]),[tW,tF]=(0,n.useState)(!1),tD=(0,n.useRef)(null),tA=(0,n.useCallback)(()=>{tD.current&&clearTimeout(tD.current),tD.current=setTimeout(async()=>{tD.current=null;let e=t_.current;if(e)try{let t=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(!t.ok)return;let o=await t.json();o.state?.queuedMessages!==void 0&&tx(at(o.state.queuedMessages))}catch{}},8e3)},[tx]),tN=(0,n.useCallback)(()=>{tD.current&&(clearTimeout(tD.current),tD.current=null)},[]),tL=(0,n.useRef)(null),t$=(0,n.useRef)(null),tH=(0,n.useRef)(null),tO=(0,n.useRef)(null),tB=(0,n.useRef)(0),tU=(0,n.useRef)(!1),t_=(0,n.useRef)(t?.id??null),tq=(0,n.useRef)(!1),tV=(0,n.useRef)(!1),tK=(0,n.useRef)(!1),tG=(0,n.useRef)(-1),tJ=(0,n.useRef)(!0),tY=(0,n.useRef)(!1),tX=(0,n.useRef)(!1),tZ=(0,n.useRef)(!1),tQ=(0,n.useRef)(null),t0=(0,n.useRef)(!1),t1=(0,n.useRef)(null),t2=(0,n.useRef)(!1),t4=(0,n.useRef)(!0),t6=(0,n.useRef)(!0),t8=(0,n.useRef)(0),t5=(0,n.useRef)(0),t3=(0,n.useRef)(null),t7=(0,n.useRef)(null),t9=(0,n.useRef)(null),oe=(0,n.useRef)(!1),ot=(0,n.useRef)(0),oo=(0,n.useRef)(null),or=(0,n.useRef)(0),on=(0,n.useRef)(0),os=(0,n.useRef)(null),oi=(0,n.useRef)(h);oi.current=h;let oa=(0,n.useRef)(null),ol=(0,n.useRef)(null),od=(0,n.useRef)(null);od.current||(od.current=function(e,t={}){let o,r=1e3/Math.max(1,t.maxUpdatesPerSecond??30),n=t.now??i3,s=t.requestFrame??("function"==typeof requestAnimationFrame?requestAnimationFrame:void 0),i=t.cancelFrame??("function"==typeof cancelAnimationFrame?cancelAnimationFrame:void 0),a=t.setTimer??setTimeout,l=t.clearTimer??clearTimeout,d=!1,c=!1,p=null,u=null,h=null,g=()=>{null!==p&&(i?.(p),p=null),null!==u&&(l(u),u=null)},m=(t,r)=>{if(!c||d)return;let n=o;c=!1,o=void 0,h=t;let s=()=>{d||e(n)};r&&"function"==typeof queueMicrotask?queueMicrotask(s):s()},f=()=>{if(!d&&c&&null===p&&null===u){if(!s){let e=null===h?r:n()-h;u=a(()=>{u=null,m(n(),!0),f()},Math.max(0,r-e));return}p=s(e=>{if(p=null,d||!c)return;let t=null===h?r:e-h;if(t<r){u=a(()=>{u=null,f()},r-t);return}m(e,!0),f()})}};return{enqueue(e){d||(o=e,c=!0,f())},flush(){!d&&c&&(g(),m(n(),!1),f())},reset(){g(),c=!1,o=void 0,h=null},destroy(){d||(d=!0,g(),c=!1,o=void 0)}}}(e=>{F({type:"update",message:e})}));let oc=(0,n.useCallback)(()=>{od.current?.reset()},[]),op=(0,n.useCallback)(e=>{od.current?.enqueue(e)},[]),ou=e.setToolPreset??ep,oh=g?.context.model,og=oh&&oh.provider&&oh.modelId?oh:null,om=eJ??og??eX??null,of=u?ei??el:om,ox=(0,n.useMemo)(()=>{if(ts)return{...ts,totalActiveMs:g?.totalActiveMs};if(t&&g&&void 0===g.stats)return null;let e={input:0,output:0,cacheRead:0,cacheWrite:0,total:0},o=0,r=0,n=0,s=0,i=0,a=0,l=0;for(let t of C){if("user"===t.role&&(s+=1),"toolResult"===t.role&&(a+=1),"assistant"!==t.role)continue;i+=1;let d=t.usage;if(l+=t.content.filter(e=>"toolCall"===e.type).length,!d)continue;e.input+=d.input??0,e.output+=d.output??0,e.cacheRead+=d.cacheRead??0,e.cacheWrite+=d.cacheWrite??0;let c=d.cost?.total??0;o+=c,r4(t.model)?r+=r6(t.model,d):n+=c}let d=g?.stats;return(d&&(e.input=Math.max(e.input,d.tokens.input),e.output=Math.max(e.output,d.tokens.output),e.cacheRead=Math.max(e.cacheRead,d.tokens.cacheRead),e.cacheWrite=Math.max(e.cacheWrite,d.tokens.cacheWrite),n=Math.max(n,d.cost),s=Math.max(s,d.userMessages),i=Math.max(i,d.assistantMessages),a=Math.max(a,d.toolResults),l=Math.max(l,d.toolCalls)),e.total=e.input+e.output+e.cacheRead+e.cacheWrite,0!==e.total||0!==C.length||d)?{sessionFile:g?.filePath||void 0,sessionId:t_.current??t?.id??"",sessionName:t?.name,userMessages:s,assistantMessages:i,toolCalls:l,toolResults:a,totalMessages:d?Math.max(C.length,d.totalMessages):C.length,tokens:e,cost:o,costCNY:r,costUSD:n,totalActiveMs:g?.totalActiveMs,...eU?{contextUsage:eU}:{}}:null},[C,ts,eU,g?.filePath,g?.totalActiveMs,g?.stats,t?.id,t?.name]),ok=(0,n.useCallback)(async(e,t=!1,o=!1)=>{let r=x.current,n=!1;try{let s;t&&y(!0),f.current?.abort(),r=x.current+1,x.current=r;let i=new AbortController;f.current=i;let a=new URLSearchParams({deferThinking:"1",deferMedia:"1",view:"initial"}),l=async()=>{let t=new AbortController,o=setTimeout(()=>t.abort(),3e4),r=()=>t.abort();i.signal.addEventListener("abort",r,{once:!0});try{return await fetch(`/api/sessions/${encodeURIComponent(e)}?${a}`,{signal:t.signal})}finally{clearTimeout(o),i.signal.removeEventListener("abort",r)}};try{s=await l()}catch(e){if(!(e instanceof DOMException&&"AbortError"===e.name))throw e;if(i.signal.aborted)return null;s=await l()}if(404===s.status)return t&&(m(null),S(null),T([]),z([]),M(null),E(!1),w(null)),null;if(!s.ok)throw Error(`HTTP ${s.status}`);let d=await s.json();if(t_.current!==e||x.current!==r)return null;m(d),k.current?.abort();let c=new AbortController;if(k.current=c,fetch(`/api/sessions/${encodeURIComponent(e)}/details`,{signal:c.signal}).then(async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return await e.json()}).then(t=>{t_.current!==e||x.current!==r||c.signal.aborted||m(o=>o?.sessionId===e?{...o,...t}:o)}).catch(e=>{"AbortError"!==e.name&&console.warn("Failed to load session details",e)}),S(d.leafId),T(d.context.messages),z(d.context.entryIds??[]),tq.current||(t5.current=Date.now()+700),M(d.context.oldestEntryId),E(d.context.hasMore),eY(e=>e?d.context.model&&e.provider===d.context.model.provider&&e.modelId===d.context.model.modelId?null:e:null),w(null),d.context.thinkingLevel&&"off"!==d.context.thinkingLevel&&eH(d.context.thinkingLevel),n=!0,t&&y(!1),!o)return null;try{let t,o=new AbortController,n=setTimeout(()=>o.abort(),2e4);try{t=await fetch(`/api/sessions/${encodeURIComponent(e)}/state`,{signal:o.signal})}finally{clearTimeout(n)}if(!t.ok)throw Error(`HTTP ${t.status}`);let s=await t.json();if(t_.current!==e||x.current!==r)return null;let i=s.state;if(i){if(void 0!==i.contextUsage&&e_(i.contextUsage??null),void 0!==i.systemPrompt&&eV(i.systemPrompt??null),void 0!==i.thinkingLevel&&eH(i.thinkingLevel??"auto"),void 0!==i.extensionStatuses&&tu(i.extensionStatuses??[]),void 0!==i.extensionWidgets&&tg(i.extensionWidgets??[]),void 0!==i.queuedMessages&&tx(at(i.queuedMessages)),void 0!==i.pendingRecovery&&tE(i.pendingRecovery??[]),void 0!==i.goalState){let e=i.goalState;e&&(eN.current=e,eA(e))}}else s.running||tx({steering:[],followUp:[]});return s}catch(e){return console.error("Failed to load agent state:",e),null}}catch(t){let e=t instanceof DOMException&&"AbortError"===t.name;if(n)return console.warn("Failed to load auxiliary session state",t),null;return w(e?"Timed out loading this conversation. Please try again.":String(t)),null}finally{t&&!n&&x.current===r&&y(!1)}},[tE,tx]);(0,n.useEffect)(()=>{if(!t||!v)return;let e=window.setTimeout(()=>{tJ.current&&t_.current&&v&&(f.current?.abort(),k.current?.abort(),y(!1),w("Timed out loading this conversation. Please try again."))},35e3);return()=>window.clearTimeout(e)},[v,t]);let ov=(0,n.useCallback)(async(e,t,o)=>{try{let r=new URLSearchParams({deferThinking:"1",deferMedia:"1"});t&&r.set("leafId",t),o&&r.set("before",o);let n=`/api/sessions/${encodeURIComponent(e)}/context?${r}`,s=await fetch(n);if(!s.ok)throw Error(`HTTP ${s.status}`);let i=await s.json();if(t_.current!==e)return;M(i.context.oldestEntryId),E(i.context.hasMore),m(t=>{if(!t||t.sessionId!==e)return t;let r=o?{...t.context,messages:[...i.context.messages,...t.context.messages],entryIds:[...i.context.entryIds,...t.context.entryIds],oldestEntryId:i.context.oldestEntryId,hasMore:i.context.hasMore}:i.context;return{...t,context:r}}),o?(T(e=>[...i.context.messages,...e]),z(e=>[...i.context.entryIds,...e])):(T(i.context.messages),z(i.context.entryIds??[]))}catch(e){console.error("Failed to load context:",e)}},[]),oy=(0,n.useCallback)(async e=>{try{let t=await i6(e,{type:"get_tools"});if(t){let{getPresetFromTools:r}=await Promise.resolve().then(o.bind(o,14755)),n=r(t);"plan"!==n||em.current?ou(n):(await i6(e,{type:"set_tools",toolNames:(0,i8.xG)("default")}).catch(()=>{}),ou("default"))}}catch(e){console.error("Failed to load tools:",e)}},[ou]),ob=(0,n.useCallback)((e=0,t="(no messages)")=>{let o=t_.current;u&&r&&o&&!oe.current&&(oe.current=!0,i?.({id:o,path:"",cwd:r,name:void 0,created:new Date().toISOString(),modified:new Date().toISOString(),messageCount:e,firstMessage:t}))},[u,r,i]),ow=(0,n.useCallback)(async()=>{if(t_.current||!u||!r)return t_.current;if(t9.current)return t9.current;let e=(async()=>{let e,t=oa.current,o=ol.current;t&&eZ(t);let n=(0,i8.xG)(ec),s=new AbortController,i=setTimeout(()=>s.abort(),3e4);try{e=await fetch("/api/agent/new",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:r,type:"ensure_session",toolNames:n,...t?{provider:t.provider,modelId:t.modelId}:{},...o?{thinkingLevel:o}:{}}),signal:s.signal})}catch(e){if(s.signal.aborted)throw Error("Timed out creating a new session after 30s. The agent service may still be starting up — please try again.");throw e}finally{clearTimeout(i)}if(!e.ok){let t=await e.json().catch(()=>null);throw Error(t?.error??`HTTP ${e.status}`)}let a=await e.json();t_.current=a.sessionId;let l=ek.current;return l&&(ek.current=null,fetch(`/api/modes?session=${encodeURIComponent(a.sessionId)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)}).catch(e=>{console.error("Failed to persist pending mode settings:",e)})),a.model&&oa.current===t&&(eZ(a.model),t||ed(a.model)),a.thinkingLevel&&ol.current===o&&eH(a.thinkingLevel),a.sessionId})();t9.current=e;try{return await e}finally{t9.current=null}},[u,r,ec]),oj=(0,n.useCallback)(async()=>{let e=t_.current??await ow();if(!e)return te([]),[];to(!0);try{let t=await i6(e,{type:"get_commands"}),o=t?.commands??[];return te(o),o}catch(e){return console.error("Failed to load slash commands:",e),te([]),[]}finally{to(!1)}},[ow]),oS=(0,n.useCallback)(()=>{tB.current+=1,tU.current=!1,tO.current&&(clearTimeout(tO.current),tO.current=null)},[]),oC=(0,n.useCallback)(()=>{tL.current?.close(),tL.current=null,t$.current=null,tH.current=null},[]),oT=(0,n.useCallback)(e=>{oC();let t=new EventSource(`/api/agent/${encodeURIComponent(e)}/events`);tL.current=t,t$.current=e;let o=new Promise(o=>{let r=!1,n=e=>{r||(r=!0,clearTimeout(s),tH.current?.source===t&&(tH.current.pending=!1),o({status:e,source:t}))},s=setTimeout(()=>n("timeout"),3e4);t.onmessage=e=>{try{let t=JSON.parse(e.data);"connected"===t.type&&n("connected"),tQ.current?.(t)}catch{}},t.onerror=()=>{if(t.readyState!==EventSource.CLOSED||(n("closed"),tL.current!==t||!tq.current&&!tU.current))return;tL.current=null,t$.current=null,tH.current=null;let o=tB.current;setTimeout(()=>{o===tB.current&&!tL.current&&(tq.current||tU.current)&&oT(e)},1e3)}});return tH.current={source:t,promise:o,pending:!0},o},[oC]),oR=(0,n.useCallback)(async e=>{let t=tL.current;if(t&&t$.current===e){if(t.readyState===EventSource.OPEN)return;let e=tH.current;if(e?.source===t&&e.pending&&(await e.promise,tL.current===t&&t.readyState===EventSource.OPEN))return}let o=await oT(e);if("connected"!==o.status&&o.source.readyState!==EventSource.OPEN)throw tL.current===o.source&&(tL.current=null),t$.current===e&&(t$.current=null),tH.current?.source===o.source&&(tH.current=null),o.source.close(),new as(o.status)},[oT]),oz=(0,n.useCallback)(async(e,t)=>{let o=t_.current;if(tl(t=>t?.id===e.id?null:t),o)try{await i6(o,{type:"extension_ui_response",id:e.id,...t})}catch(e){console.error("Failed to send extension UI response:",e)}},[]),oI=(0,n.useCallback)(async(e,t)=>{let o=t_.current;if(o)try{await i6(o,{type:"extension_ui_input",id:e.id,data:t})}catch(e){console.error("Failed to send extension custom UI input:",e)}},[]),oM=(0,n.useCallback)(e=>{let t=e.message.trim();if(!t)return;let o=e.type??"info";("error"===o||"warning"===o)&&fetch("/api/logs",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({level:o,source:"agent-notice",sessionId:t_.current??void 0,message:t})}).catch(()=>{}),tn({type:"add",notice:{id:e.id??("u">typeof crypto&&"function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2)}`),message:t,type:o}})},[]),oP=(0,n.useCallback)(t=>{switch(t.method){case"select":case"confirm":case"input":case"editor":tl(t);break;case"notify":oM({id:t.id,message:function(e){if(!("u">typeof document&&("zh-CN"===document.documentElement.lang||"zh"===document.documentElement.lang)))return e;let t=e.trim();return t.startsWith("Plan mode enabled")?"已启用计划模式:只读分析与产出计划,不修改文件。":t.startsWith("Plan mode disabled")?"已退出计划模式。":t.startsWith("No completed plan is available")?"当前没有可用的已完成计划。":t.startsWith("Unable to send Plan-mode message")?`无法发送计划模式消息:${t.replace(/^Unable to send Plan-mode message:\s*/,"")}`:e}(t.message),type:t.notifyType??"info"});break;case"setStatus":tu(e=>{let o=e.filter(e=>e.key!==t.statusKey);return t.statusText?[...o,{key:t.statusKey,text:t.statusText}]:o});break;case"setWidget":tg(e=>{let o=e.filter(e=>e.key!==t.widgetKey);return t.widgetLines?[...o,{key:t.widgetKey,lines:t.widgetLines,placement:t.widgetPlacement??"aboveEditor"}]:o});break;case"setTitle":t.title&&(document.title=t.title);break;case"set_editor_text":e.chatInputRef?.current?.insertText(t.text);break;case"custom":tc(e=>t.closed?e?.id===t.id?null:e:t)}},[oM,e.chatInputRef]),oE=(0,n.useRef)(null),oW=(0,n.useCallback)(()=>{null!==oE.current&&(cancelAnimationFrame(oE.current),oE.current=null)},[]),oF=(0,n.useCallback)(()=>{oc(),oW();let e=tq.current;return tq.current=!1,U(!1),e5(null),eB(null),F({type:"end"}),e},[oW,oc]),oD=(0,n.useCallback)(e=>tG.current!==e&&(tG.current=e,s?.(),!0),[s]),oA=(0,n.useCallback)(e=>{oS(),tU.current=!0;let t=tB.current,o=async()=>{if(t===tB.current&&t_.current===e&&tU.current)try{let r=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(!r.ok)throw Error(`HTTP ${r.status}`);let n=await r.json();if(t!==tB.current||t_.current!==e||!tU.current)return;let s=n.state;if(n.running&&s&&(s.isStreaming||s.isPromptRunning)){tU.current=!1,tO.current=null,tV.current=!!s?.isStreaming,tK.current=!!s?.isPromptRunning,tq.current=!0,U(!0),e5(i9(s));return}if(n.running&&s?.isCompacting){e0(!0),tO.current=setTimeout(()=>void o(),600);return}tU.current=!1,tO.current=null,oC()}catch{if(t!==tB.current||t_.current!==e||!tU.current)return;tO.current=setTimeout(()=>void o(),600)}};tO.current=setTimeout(()=>void o(),12e4)},[oS,oC]),oN=(0,n.useCallback)(async(e=t_.current,t=ot.current)=>{if(ot.current===t)try{e&&await ok(e)}finally{if(ot.current!==t)return;let o=tK.current,r=tV.current;tK.current=!1,tV.current=!1,oo.current=null;let n=oF();o?oD(t):r&&n&&s?.(),e&&oA(e)}},[ok,oD,s,oA,oF]),oL=(0,n.useCallback)(async(e,t=ot.current)=>{await ai(800);let o=Date.now(),r=0;for(;Date.now()-o<2e4;){if(!tJ.current||ot.current!==t)return;try{let n=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(n.ok){r=0;let s=await n.json(),i=s.state;if(!(s.running&&i&&(i.isStreaming||i.isPromptRunning)))return void await oN(e,t);o=Date.now()}else r+=1}catch{r+=1}if(r>=3){if(ot.current!==t)return;oM({type:"error",message:"Cannot reach the pi-web service. Make sure it is running, then refresh the page."}),tK.current=!1,oo.current=null,oF();return}await ai(3e3)}ot.current===t&&(oM({type:"error",message:"Message delivery could not be confirmed. Refresh the page to see the latest state."}),tK.current=!1,oo.current=null,oF())},[oM,oN,oF]),o$=(0,n.useCallback)(async e=>{if(!tq.current&&!D.current)return;let t=ot.current;try{let o=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(!o.ok)return;let r=await o.json();if(ot.current!==t)return;let n=r.state;if(e0(n?.isCompacting??!1),tK.current||e5(i9(n)),tx(at(n?.queuedMessages)),tE(n?.pendingRecovery??[]),r.running&&n&&(n.isStreaming||n.isPromptRunning||n.isBashRunning||n.isCompacting)||!tq.current&&!D.current)return;if(n&&(void 0!==n.contextUsage&&e_(n.contextUsage??null),void 0!==n.systemPrompt&&eV(n.systemPrompt??null),void 0!==n.extensionStatuses&&tu(n.extensionStatuses??[]),void 0!==n.extensionWidgets&&tg(n.extensionWidgets??[]),void 0!==n.goalState)){let e=n.goalState;e&&(eN.current=e,eA(e))}await oN(e,t)}catch{}},[oN,tE,tx]);(0,n.useEffect)(()=>{if(!B&&!W.isStreaming)return;let e=()=>{let e=t_.current;e&&o$(e)},t=()=>{"visible"===document.visibilityState&&e()},o=setInterval(e,15e3);return document.addEventListener("visibilitychange",t),window.addEventListener("online",e),()=>{clearInterval(o),document.removeEventListener("visibilitychange",t),window.removeEventListener("online",e)}},[B,W.isStreaming,o$]),(0,n.useEffect)(()=>{tq.current=B,B||e7(!1)},[B]);let oH=(0,n.useCallback)((t="smooth")=>{t5.current=Date.now()+700;let o=t7.current,r=t3.current;if(!o||!r)return;let n=Math.max(88,e.chatInputRef?.current?.measureHeight?.()??0),s=()=>{if(!o||!r)return;let e=Math.max(0,r.getBoundingClientRect().top-o.getBoundingClientRect().top+o.scrollTop-96-o.clientHeight+n);o.scrollTo({top:e,behavior:t})};s(),("instant"===t||"auto"===t)&&window.setTimeout(()=>{o&&r&&t6.current&&s()},200)},[]),oO=(0,n.useCallback)(()=>{null===oE.current&&(oE.current=requestAnimationFrame(()=>{oE.current=null,requestAnimationFrame(()=>{if(!tq.current||Date.now()<t8.current)return;let e=t7.current;if(e){let{scrollTop:t,clientHeight:o,scrollHeight:r}=e;t6.current=t+o>=r-150}t6.current&&oH("auto")})}))},[oH]);tQ.current=(0,n.useCallback)(e=>{switch(e.type){case"agent_start":oc(),$(),oS(),tq.current||(tY.current=!1),tV.current=!0,tq.current=!0,U(!0),e5({kind:"waiting_model"}),F({type:"start"}),oO();break;case"agent_end":{if(oc(),$(),!tq.current)break;let t=tm.steering.length>0||tm.followUp.length>0;if(e5(t?{kind:"waiting_model"}:null),eB(null),F({type:"end"}),!0!==e.willRetry){let t=e.messages??[];for(let e=t.length-1;e>=0;e--){let o=t[e];if(o?.role==="assistant"){"error"===o.stopReason&&o.errorMessage&&oM({type:"error",message:o.errorMessage});break}}}let o=t_.current;if(o){let r=ot.current;t||!0===e.willRetry||ok(o),fetch(`/api/agent/${encodeURIComponent(o)}`).then(e=>e.ok?e.json():void 0).then(e=>{if(ot.current!==r)return;let t=e?.state;if(t?.contextUsage!==void 0&&e_(t.contextUsage??null),t?.systemPrompt!==void 0&&eV(t.systemPrompt??null),t?.extensionStatuses!==void 0&&tu(t.extensionStatuses??[]),t?.extensionWidgets!==void 0&&tg(t.extensionWidgets??[]),tx(at(t?.queuedMessages)),tE(t?.pendingRecovery??[]),t?.goalState!==void 0){let e=t.goalState;e&&(eN.current=e,eA(e))}}).catch(()=>{})}break}case"agent_settled":{let e=tV.current;if(tV.current=!1,!e||tK.current)break;let t=t_.current,o=oF();e0(!1),t&&(ok(t),oA(t)),o&&!tY.current&&s?.(),tY.current=!1;break}case"goal_state_changed":{let t=e.goalState;t&&(eN.current=t,eA(t));break}case"prompt_done":{let e=ot.current,t=tK.current;tK.current=!1,oo.current=null;let o=oD(e);if(o&&(tY.current=!0),!t&&!o)break;let r=t_.current;r&&!tV.current&&ok(r),!tV.current&&(oF(),r&&oA(r));break}case"tool_approval_request":{let t={id:String(e.id??""),toolName:String(e.toolName??""),args:e.args};if(!t.id)break;eW(e=>e.some(e=>e.id===t.id)?e:[...e,t]);break}case"tool_approval_resolved":{let t=String(e.id??"");if(!t)break;eW(e=>e.filter(e=>e.id!==t));break}case"prompt_error":oM({type:"error",message:e.errorMessage??"Command failed"});break;case"extension_error":oM({type:"error",message:e.error??"Extension command failed"});break;case"message_start":case"message_update":{if(!tq.current)break;let t=e.message;if(t?.role==="user")break;t&&(O(t),op(i0(t))),e5(e=>null===e?e:null),oO();break}case"message_end":{if(!tq.current)break;let t=e.message;if(t&&"user"===t.role){let e=i0(t);if("user"===e.role&&"content"in e){let t=e.content;if("string"==typeof t)ar.some(e=>t.startsWith(e))&&(e={...e,content:tM(t)});else if(Array.isArray(t)){let o=t.filter(e=>"text"===e.type)[0];o&&"string"==typeof o.text&&ar.some(e=>o.text?.startsWith(e))&&(e={...e,content:t.map((e,t)=>{if("text"!==e.type||0!==t)return e;let o=tM(e.text??"");return{...e,text:o}})})}}let o=ac(e),r=oo.current;T(t=>{let n=t[t.length-1];return r&&n?.role==="user"&&ac(n)===r?(oo.current=null,r===o?t:[...t.slice(0,-1),e]):[...t,e]})}else t&&T(e=>[...e,i0(t)]);oc(),F({type:"reset"}),e5({kind:"waiting_model"});break}case"tool_execution_start":{let t=e.toolCallId,o=e.toolName;e5(e=>{let r=e?.kind==="running_tools"?[...e.tools]:[];return r.some(e=>e.id===t)||r.push({id:t,name:o}),{kind:"running_tools",tools:r}});break}case"tool_execution_end":{let t=e.toolCallId;e5(e=>{if(e?.kind!=="running_tools")return e;let o=e.tools.filter(e=>e.id!==t);return 0===o.length?{kind:"waiting_model"}:{kind:"running_tools",tools:o}});break}case"entry_appended":break;case"queue_update":tx({steering:[...e.steering??[]],followUp:[...e.followUp??[]]}),(e.steering??[]).length>0||(e.followUp??[]).length>0?tA():tN();break;case"state_sync":{let t=e.state;if(!t)break;if(e0(t.isCompacting??!1),tK.current||e5(i9(t)),tx(at(t.queuedMessages)),tE(t.pendingRecovery??[]),void 0!==t.contextUsage&&e_(t.contextUsage??null),void 0!==t.systemPrompt&&eV(t.systemPrompt??null),void 0!==t.extensionStatuses&&tu(t.extensionStatuses??[]),void 0!==t.extensionWidgets&&tg(t.extensionWidgets??[]),void 0!==t.goalState){let e=t.goalState;e&&(eN.current=e,eA(e))}if(t.isStreaming||t.isPromptRunning||t.isBashRunning||t.isCompacting){let e=tq.current;tq.current=!0,U(!0),e||F({type:"start"})}else if(tq.current&&!tK.current){let e=t_.current;e&&oN(e,ot.current)}break}case"auto_retry_start":eB({attempt:e.attempt,maxAttempts:e.maxAttempts,errorMessage:e.errorMessage});break;case"auto_retry_end":eB(null);break;case"auto_compaction_start":case"compaction_start":e0(!0),e2(null),e6(null);break;case"auto_compaction_end":case"compaction_end":e0(!1),e.errorMessage?(e2(e.errorMessage),e6(null)):e.aborted||(e6(ap(e.result,e.reason??"auto")),t_.current&&!tq.current&&ok(t_.current));break;case"extension_ui_request":oP(e)}},[oM,oS,oW,oN,oP,ok,oD,s,tm,oA,oO,oF,op,oc,tA,tN,O,$,tE,tx]),(0,n.useEffect)(()=>{let e=new EventSource("/api/events");return e.onmessage=e=>{try{let t=JSON.parse(e.data);if(!t||!t.type||!t.payload||t.sessionId!==t_.current||tL.current?.readyState===EventSource.OPEN)return;tQ.current?.(t.payload)}catch{}},()=>e.close()},[]);let oB=(0,n.useCallback)(async(o,n)=>{let s,i=o.trim();if(!i&&!n?.length)return;if(tq.current||tX.current)return void console.warn("[pi-web] Send dropped: a previous run is still marked active",{agentRunning:tq.current,bashRunning:tX.current,sessionId:t_.current});let a=!n?.length&&i.startsWith("/"),l=ot.current+1;oS(),oc(),tK.current=!0;let d=function(e){let t=[];if("plan"===e.collaborationMode&&t.push(tT),"economy"===e.tokenMode&&t.push(tR),"delivery"===e.tokenMode&&t.push(tz),"goal"===e.collaborationMode){let o=e.goalText?.trim();t.push(o?`${tI}
33
33
 
34
34
  Goal: ${o}`:tI)}return t.join("\n\n")}({collaborationMode:eC.current,tokenMode:eT.current,goalText:"goal"===eC.current?eI.current??void 0:void 0}),c=d||!em.current||a?"":ao,p=d||c,h=[eC.current,eT.current,em.current?"legacy-plan":"",p?String(p.length):""].join("|"),g=t?.id??"new";p&&(eM.current.sessionKey!==g||eM.current.signature!==h)?(eM.current={sessionKey:g,signature:h},s=`${p}
35
35
 
36
- ${o}`):s=o;let m=s,f=n?.map(e=>({type:"image",source:{type:"base64",media_type:e.mimeType,data:e.data}})),x={role:"user",content:f?.length?[...o.trim()?[{type:"text",text:o}]:[],...f]:o,timestamp:Date.now()};T(e=>[...e,x]),oo.current=ac(x),ot.current=l,"goal"!==eC.current||a||(eI.current=i,eA(e=>({...e,status:"running",goalText:i,turnsUsed:0,noProgressTurns:0,tokensUsed:0})),eL.current=!0),tq.current=!0,U(!0),e5(a?{kind:"running_command"}:{kind:"waiting_model"}),F({type:"start"}),t2.current=!0,e7(!0),t4.current=!0;let k=n?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType})),v=null,y=!1;try{if(u&&r){let e=t_.current??await t9.current,t=e??await ow();if(t){v=t,ob(1,o),ei&&(eZ(ei),e&&await i6(t,{type:"set_model",provider:ei.provider,modelId:ei.modelId}));let r=await Promise.race([oR(t).then(()=>!0).catch(()=>!1),ai(4e3).then(()=>!1)]);y=!0,await i6(t,{type:"prompt",message:m,...k?.length?{images:k}:{}}),r||oL(t,l),"goal"!==eC.current||a||i6(t,{type:"goal_start",goalText:i}).catch(()=>{})}else throw Error("Unable to create a session for this message")}else if(t){v=t.id;let e=await Promise.race([oR(t.id).then(()=>!0).catch(()=>!1),ai(4e3).then(()=>!1)]);y=!0,await i6(t.id,{type:"prompt",message:m,...k?.length?{images:k}:{}}),e||oL(t.id,l),"goal"!==eC.current||a||i6(t.id,{type:"goal_start",goalText:i}).catch(()=>{})}a&&v&&oL(v,l)}catch(t){if(console.error("Failed to send message:",t),y&&v)return void oL(v,l);if(tK.current=!1,oC(),t instanceof as){let e=oo.current;e&&T(t=>{let o=t[t.length-1];return o?.role==="user"&&ac(o)===e?t.slice(0,-1):t}),oM({type:"error",message:t.message})}else{let o=oo.current;o&&T(e=>{let t=e[e.length-1];return t?.role==="user"&&ac(t)===o?e.slice(0,-1):e}),e.chatInputRef?.current?.replaceMessage?.(x),oM({type:"error",message:`Failed to send message: ${t instanceof Error?t.message:String(t)}`})}oo.current=null,tq.current=!1,U(!1),e5(null),F({type:"end"})}},[u,r,ei,t,ow,oR,ob,oL,oM,oS,oC,oc]),oU=(0,n.useCallback)(async(o,r)=>{if(tq.current||tX.current)return;let n=`${r?"!!":"!"}${o}`;tX.current=!0,K({command:o,excludeFromContext:r}),q(!0);try{let e=t_.current??t?.id??await ow();if(!e)throw Error("Unable to create a session for the shell command");ob(1,n),await i6(e,{type:"bash",command:o,excludeFromContext:r}),await ok(e)}catch(t){console.error("Failed to execute shell command:",t),oM({type:"error",message:t instanceof Error?t.message:String(t)}),e.chatInputRef?.current?.insertIfEmpty(n)}finally{tX.current=!1,K(null),q(!1)}},[oM,ow,ok,e.chatInputRef,ob,t]),o_=(0,n.useCallback)(async()=>{let e=t_.current;if(e)try{await i6(e,{type:tX.current?"abort_bash":"abort"})}catch(e){console.error("Failed to abort:",e)}},[]),oq=(0,n.useCallback)(async e=>{let t=t_.current;if(t){eG(e);try{let{cancelled:o,newSessionId:r}=await i6(t,{type:"fork",entryId:e})??{};!o&&r&&a?.(r)}catch(e){console.error("Fork failed:",e)}finally{eG(null)}}},[a]),oV=(0,n.useCallback)(async e=>{let t=t_.current;t&&(i6(t,{type:"navigate_tree",targetId:e}).catch(()=>{}),S(e),await ov(t,e))},[ov]),oK=(0,n.useCallback)(async e=>{S(e);let t=t_.current;t&&(await ov(t,e),e&&i6(t,{type:"navigate_tree",targetId:e}).catch(()=>{}))},[ov]),oG=(0,n.useCallback)(async(e,t)=>{if(u){let o={provider:e,modelId:t};oa.current=o,ea(o),eZ(o);let r=t_.current??await t9.current;if(!r)return;try{await i6(r,{type:"set_model",provider:e,modelId:t})}catch(e){console.error("Failed to set model:",e)}return}let o=t_.current;if(!o)return;let r=++or.current,n=eJ??g?.context.model??null;eY({provider:e,modelId:t});try{await i6(o,{type:"set_model",provider:e,modelId:t})}catch(o){console.error("Failed to set model:",o),or.current===r&&(eY(n&&(n.provider!==e||n.modelId!==t)?n:null),oM({type:"error",message:o instanceof Error?o.message:String(o)}))}},[oM,eJ,g?.context.model,u,ea]),oJ=(0,n.useCallback)(async()=>{let e=t_.current;if(e&&!eQ){e0(!0),e2(null),e6(null);try{let t=await i6(e,{type:"compact"});e6(ap(t,"manual")),await ok(e,!0)}catch(e){e2(e instanceof Error?e.message:String(e)),e6(null)}finally{e0(!1)}}},[eQ,ok]),oY=(0,n.useCallback)(async e=>{let o=++on.current,n=r??t?.cwd??"",s=n?`/api/models?cwd=${encodeURIComponent(n)}`:"/api/models",i=os.current;i?.abort();let a=new AbortController;os.current=a;let l=()=>a.abort();e?.aborted?a.abort():e?.addEventListener("abort",l,{once:!0});try{let e=await fetch(s,{signal:a.signal});if(!e.ok){let t=`HTTP ${e.status}`;try{let o=await e.json();o?.error&&(t=o.error)}catch{}throw Error(t)}let t=await e.json();if(o!==on.current||h!==oi.current)return;es(null),J(t.models),Q(t.thinkingLevels??{}),et(t.thinkingLevelMaps??{}),er(t.modelScopeWarnings??[]);let r=t.modelList??[];if(X(r),u&&!t_.current){let e=(t.defaultModel?r.find(e=>e.id===t.defaultModel?.modelId&&e.provider===t.defaultModel?.provider):void 0)??r[0];ed(e?{provider:e.provider,modelId:e.id}:null);let o=e?t.thinkingLevelPins?.[`${e.provider}/${e.id}`]:void 0;null===ol.current&&eH(o??"auto")}}catch(e){if(a.signal.aborted||o!==on.current||h!==oi.current)return;es(e instanceof Error?e.message:String(e))}finally{e?.removeEventListener("abort",l),os.current===a&&(os.current=null)}},[u,h,r,t?.cwd]),oX=(0,n.useCallback)(async e=>{if(!e.startsWith("/"))return{handled:!1};let t=e.match(/^\/([^\s]+)(?:\s+([\s\S]*))?$/);if(!t)return{handled:!1};let[,o,r=""]=t,n=r.trim(),s=t_.current??await ow(),i=e=>(e.handled&&(e.error?oM({type:"error",message:e.error}):"openSessionStats"!==e.action&&oM({type:"success",message:e.message??"Command completed"})),e);try{switch(o){case"compact":{if(!s||eQ)return i({handled:!0,error:"No active session to compact"});e0(!0),e2(null),e6(null);let e=await i6(s,{type:"compact",...n?{customInstructions:n}:{}});return e6(ap(e,"manual")),await ok(s,!0)&&ob(),i({handled:!0,message:"Compacted context"})}case"reload":if(!s)return i({handled:!0,error:"No active session to reload"});return await i6(s,{type:"reload"}),await Promise.all([ok(s,!1,!0),oy(s),oj(),oY()]),i({handled:!0,message:"Reloaded session resources"});case"name":if(!s)return i({handled:!0,error:"No active session to name"});if(!n)return i({handled:!0,error:"Usage: /name <name>"});return await i6(s,{type:"set_session_name",name:tM(n)}),await ok(s)&&ob(),i({handled:!0,message:`Session renamed to ${n}`});case"session":{if(!s)return i({handled:!0,error:"No active session"});let e=await i6(s,{type:"get_session_stats"});return e&&ti(e),p?.(),i({handled:!0,action:"openSessionStats"})}case"copy":{if(!s)return i({handled:!0,error:"No active session"});let e=await i6(s,{type:"get_last_assistant_text"}),t=e?.text??"";if(!t)return i({handled:!0,error:"No assistant message to copy"});return await navigator.clipboard.writeText(t),i({handled:!0,message:"Copied last assistant message"})}default:return{handled:!1}}}catch(e){return i({handled:!0,error:e instanceof Error?e.message:String(e)})}finally{"compact"===o&&e0(!1)}},[oM,ow,eQ,oY,ok,oj,oy,ob,p]),oZ=(0,n.useCallback)(async e=>{let t=!1;try{let o=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(o.ok){let e=await o.json(),r=e.state;if(e.running&&r&&(r.isStreaming||r.isPromptRunning||r.isBashRunning||r.isCompacting))return;t=!0}}catch{}t?oF():oL(e)},[oL,oF]),oQ=(0,n.useCallback)(async(e,t)=>{let o=t_.current;if(!o)return;let r=t?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType}));tq.current=!0,U(!0),e5(e=>e??{kind:"waiting_model"});try{await i6(o,{type:"steer",message:e,...r?.length?{images:r}:{}})}catch(e){console.error("Failed to steer:",e),oZ(o)}},[oZ]),o0=(0,n.useCallback)(async(e,t,o)=>{let r=t_.current;if(!r)return;let n=o?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType}));tq.current=!0,U(!0),e5(e=>e??{kind:"waiting_model"});try{await i6(r,{type:"prompt",message:e,streamingBehavior:t,...n?.length?{images:n}:{}})}catch(e){console.error("Failed to queue prompt:",e),oZ(r)}},[oZ]),o1=(0,n.useCallback)(async(e,t)=>{let o=t_.current;if(!o)return;let r=t?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType}));tq.current=!0,U(!0),e5(e=>e??{kind:"waiting_model"});try{await i6(o,{type:"follow_up",message:e,...r?.length?{images:r}:{}})}catch(e){console.error("Failed to follow up:",e),oZ(o)}},[oZ]),o2=(0,n.useCallback)(async()=>{let e=t_.current;if(e)try{await i6(e,{type:"abort_compaction"})}catch(e){console.error("Failed to abort compaction:",e)}},[]),o4=(0,n.useCallback)(async()=>{let t=t_.current;if(t)try{let o=await i6(t,{type:"clear_queue"});tx({steering:[],followUp:[]});let r=[...o?.steering??[],...o?.followUp??[]];r.length>0&&e.chatInputRef?.current?.prependText(r.join("\n\n"))}catch(e){console.error("Failed to recall queued messages:",e),oM({type:"error",message:"Failed to recall queued messages"})}},[e.chatInputRef,oM,tx]);(0,n.useEffect)(()=>{0===tk.length&&tF(!1)},[tk.length]);let o6=(0,n.useCallback)(async(e,t,o=!1)=>{let r=t_.current;if(!r)return tk;try{let n=await i6(r,{type:"resolve_recovery",keep:e,discard:t,continueRun:o}),s=n?.remaining??[];return tE(s),o&&e.length>0&&(async()=>{try{let e=await fetch(`/api/agent/${encodeURIComponent(r)}`);if(!e.ok)return;let t=await e.json(),o=t.state;if(!t.running||!o||!o.isStreaming&&!o.isPromptRunning)return;tV.current=!!o.isStreaming,tK.current=!!o.isPromptRunning,tq.current=!0,U(!0),e5(i9(o)),F({type:"start"}),oT(r),!o.isStreaming&&o.isPromptRunning&&oL(r)}catch{}})(),s}catch(e){return console.error("Failed to resolve queued message recovery:",e),oM({type:"error",message:"Failed to resolve queued message recovery"}),tk}},[tk,oM,oT,oL,tE]),o8=(0,n.useCallback)(async()=>{let e=t_.current;if(!e)return null;try{return await i6(e,{type:"export_queue"})}catch(e){return console.error("Failed to export queue:",e),oM({type:"error",message:"Failed to export queue"}),null}},[oM]),o5=(0,n.useCallback)(async e=>{let t=t_.current;if(!t)return null;try{let o=await i6(t,{type:"import_queue",entries:e});return o&&tx(at(o)),o?.imported??0}catch(e){return console.error("Failed to import queue:",e),oM({type:"error",message:"Failed to import queue"}),null}},[oM,tx]),o3=(0,n.useCallback)(async e=>{let t=t_.current;if(!t)return null;try{let o=await i6(t,{type:"stage_recovery",entries:e});return o?.pendingRecovery&&tE(o.pendingRecovery),(o?.staged??0)>0&&tF(!0),o?.staged??0}catch(e){return console.error("Failed to stage imported queue:",e),oM({type:"error",message:"Failed to stage imported queue"}),null}},[oM,tE]),o7=(0,n.useCallback)(async(e,t,o)=>{let r=t_.current;if(!r)return!1;try{let n=await i6(r,{type:"move_queue",kind:e,fromIndex:t,toIndex:o});return n&&tx(at(n)),!0}catch(e){return console.error("Failed to move queued message:",e),oM({type:"error",message:e instanceof Error?e.message:"Failed to move queued message"}),!1}},[oM,tx]),o9=(0,n.useCallback)(async(e,t)=>{let o=t_.current;if(!o)return null;try{let r=await i6(o,{type:"recall_queue_item",kind:e,index:t});return r&&(void 0!==r.steering||void 0!==r.followUp)&&tx(at(r)),r?.entry?{text:r.entry.text,images:r.entry.images?.map(({data:e,mimeType:t})=>({data:e,mimeType:t}))}:null}catch(e){return console.error("Failed to recall queued message:",e),oM({type:"error",message:e instanceof Error?e.message:"Failed to recall queued message"}),null}},[oM,tx]),re=(0,n.useCallback)(async(e,t,o,r)=>{let n=t_.current;if(!n)return!1;try{let s=await i6(n,{type:"requeue_at",kind:e,index:t,text:o,images:r?.map(({data:e,mimeType:t})=>({type:"image",data:e,mimeType:t}))});return s&&tx(at(s)),!0}catch(e){return console.error("Failed to requeue message:",e),oM({type:"error",message:e instanceof Error?e.message:"Failed to requeue message"}),!1}},[oM,tx]),rt=(0,n.useCallback)(async(e,t)=>{let o=t_.current;if(!o)return!1;try{let r=await i6(o,{type:"remove_queue_item",kind:e,index:t});return r&&tx(at(r)),!0}catch(e){return console.error("Failed to remove queued message:",e),oM({type:"error",message:e instanceof Error?e.message:"Failed to remove queued message"}),!1}},[oM,tx]),ro=(0,n.useCallback)(async e=>{if(ol.current="auto"===e?null:e,eH(e),"auto"===e)return;let t=t_.current??await t9.current;if(t)try{await i6(t,{type:"set_thinking_level",level:e})}catch(e){console.error("Failed to set thinking level:",e)}},[]),rr=(0,n.useCallback)(async e=>{let t=(0,i8.xG)(e);ou(e);let o=t_.current??await t9.current;if(o)try{await i6(o,{type:"set_tools",toolNames:t})}catch(e){console.error("Failed to set tools:",e)}},[ou]),rn=(0,n.useRef)(0),rs=(0,n.useCallback)(async e=>{let t=t_.current??await t9.current,o=++rn.current;if(e){if(eg.current="plan"===ec?"default":ec,eh(!0),em.current=!0,eM.current={sessionKey:"",signature:""},t)try{if(await i6(t,{type:"prompt",message:"/plan"}),rn.current!==o)return}catch(e){if(rn.current!==o)return;console.error("Failed to enter plan mode:",e)}}else if(eh(!1),em.current=!1,eM.current={sessionKey:"",signature:""},t){try{if(await i6(t,{type:"prompt",message:"/plan exit"}),rn.current!==o)return}catch(e){if(rn.current!==o)return;console.error("Failed to exit plan mode:",e)}if(rn.current!==o)return;try{let e=eg.current;await i6(t,{type:"set_tools",toolNames:(0,i8.xG)(e)})}catch(e){console.error("Failed to restore tools after plan exit:",e)}}},[ec]),ri=(0,n.useCallback)(e=>{ex(e);let t=t_.current;if(!t){ek.current=e;return}ek.current=null,fetch(`/api/modes?session=${encodeURIComponent(t)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).catch(e=>{console.error("Failed to persist mode settings:",e)})},[]),ra=(0,n.useCallback)(e=>{if(ri({...eP.current,collaborationMode:tw(e)}),eC.current=tw(e),eM.current={sessionKey:"",signature:""},"goal"!==e){eI.current=null,eL.current=!1,eA(e=>"idle"===e.status?e:{...e,status:"idle",goalText:null});let e=t_.current;e&&i6(e,{type:"goal_stop"}).catch(()=>{})}},[ri]),rl=(0,n.useCallback)(async e=>{ri({...eP.current,tokenMode:tj(e)});let t=t_.current??await t9.current;if(t)try{if("economy"!==e||em.current){if("economy"!==e){let e=em.current?i8.SC:(0,i8.xG)("plan"===ec?"default":ec);await i6(t,{type:"set_tools",toolNames:e})}}else await i6(t,{type:"set_tools",toolNames:[...tC]})}catch(e){console.error("Failed to apply token mode tools:",e)}},[ri,ec]),rd=(0,n.useCallback)(async e=>{ri({...eP.current,toolApprovalMode:tS(e)});let t=t_.current??await t9.current;if(t)try{await i6(t,{type:"set_approval_mode",mode:tS(e)})}catch(e){console.error("Failed to apply approval mode:",e)}},[ri]),rc=(0,n.useCallback)(async e=>{ri({...eP.current,permissionRules:e});let t=t_.current??await t9.current;if(t)try{await i6(t,{type:"set_approval_policy",policy:e})}catch(e){console.error("Failed to apply permission rules:",e)}},[ri]),rp=(0,n.useCallback)(async(e,t,o)=>{let r=t_.current;if(r)try{await i6(r,{type:"resolve_approval",id:e,approve:t,reason:o})}catch(e){console.error("Failed to resolve approval:",e)}finally{eW(t=>t.filter(t=>t.id!==e))}},[]),ru=(0,n.useCallback)(e=>{eI.current=e},[]),rh=(0,n.useCallback)(e=>{let t=e.trim();if(!t)return;eI.current=t,eA(e=>({...e,status:"running",goalText:t,turnsUsed:0,noProgressTurns:0,tokensUsed:0,startedAt:Date.now()}));let o=t_.current;o&&i6(o,{type:"goal_start",goalText:t}).catch(()=>{})},[]),rg=(0,n.useCallback)(()=>{if("running"!==eN.current.status)return;eA(e=>({...e,status:"paused"}));let e=t_.current;e&&i6(e,{type:"goal_pause"}).catch(()=>{})},[]),rm=(0,n.useCallback)(()=>{let e=eN.current;if("paused"!==e.status&&"blocked"!==e.status)return;eA(e=>({...e,status:"running"}));let t=t_.current;t&&i6(t,{type:"goal_resume"}).catch(()=>{})},[]),rf=(0,n.useCallback)(()=>{eL.current=!1,eI.current=null,eA(e=>({...e,status:"idle",goalText:null,turnsUsed:0,noProgressTurns:0}));let e=t_.current;e&&i6(e,{type:"goal_stop"}).catch(()=>{})},[]),rx=(0,n.useCallback)(e=>{let t=e.trim();if(!t)return;eA(e=>({...e,goalText:t}));let o=t_.current;o&&i6(o,{type:"goal_edit",goalText:t}).catch(()=>{})},[]),rk=(0,n.useCallback)(()=>{let e=t7.current,t=t1.current;if(!e||!t)return;let o=t.getBoundingClientRect().top-e.getBoundingClientRect().top+e.scrollTop,r=Math.max(0,e.scrollHeight-e.clientHeight),n=Math.min(Math.max(0,o-16),r);t6.current=n>=r-150,t5.current=Date.now()+700,e.scrollTo({top:n,behavior:"smooth"})},[]),rv=(0,n.useCallback)(e=>{if(e instanceof KeyboardEvent){if(!an.has(e.key)||e.target instanceof Element&&e.target.closest("input, textarea, [contenteditable='true']"))return}else if(e instanceof PointerEvent){let t=t7.current;if(t&&e.target instanceof Element&&!t.contains(e.target))return}t8.current=Date.now()+1200},[]),ry=(0,n.useCallback)(()=>{let e=t7.current;if(e){let{scrollTop:t,clientHeight:o,scrollHeight:r}=e;t6.current=t+o>=r-150}if(Date.now()<t8.current){t4.current=!1;return}Date.now()<t5.current||(t4.current=!1)},[]);(0,n.useEffect)(()=>{if(tJ.current=!0,t){t_.current=t.id;let e=eR.current,o=ez.current;("auto"!==e||o.allow.length||o.ask.length||o.deny.length)&&(i6(t.id,{type:"set_approval_mode",mode:e}).catch(()=>{}),i6(t.id,{type:"set_approval_policy",policy:o}).catch(()=>{}));let r=e=>{!tZ.current&&(tZ.current=!0,e.isBashRunning&&(tX.current=!0,q(!0)),oy(t.id),(e.isStreaming||e.isPromptRunning)&&(tV.current=!!e.isStreaming,tK.current=!!e.isPromptRunning,tq.current=!0,U(!0),e5(i9(e)),F({type:"start"}),oT(t.id),!e.isStreaming&&e.isPromptRunning&&oL(t.id)))};(async()=>{try{let e,o=new AbortController,n=setTimeout(()=>o.abort(),2e4);try{e=await fetch(`/api/sessions/${encodeURIComponent(t.id)}/state`,{signal:o.signal})}finally{clearTimeout(n)}if(!e.ok)throw Error(`HTTP ${e.status}`);let s=await e.json();if(!tJ.current||t_.current!==t.id)return;s.running&&s.state&&r(s.state)}catch{}})(),ok(t.id,!0,!0).then(e=>{e?.running&&e.state&&r(e.state),e?.state&&(void 0!==e.state.isCompacting&&e0(e.state.isCompacting),void 0!==e.state.contextUsage&&e_(e.state.contextUsage??null),void 0!==e.state.systemPrompt&&eV(e.state.systemPrompt??null),void 0!==e.state.thinkingLevel&&eH(e.state.thinkingLevel??"auto"),void 0!==e.state.extensionStatuses&&tu(e.state.extensionStatuses??[]),void 0!==e.state.extensionWidgets&&tg(e.state.extensionWidgets??[]),void 0!==e.state.queuedMessages&&tx(at(e.state.queuedMessages)),void 0!==e.state.pendingRecovery&&tE(e.state.pendingRecovery??[])),e?.running||(async()=>{for(let e=0;e<5;e++){if(e>0&&await new Promise(e=>setTimeout(e,2e3)),!tJ.current||t_.current!==t.id||tq.current)return;try{let e=await fetch(`/api/agent/${encodeURIComponent(t.id)}`);if(!e.ok)continue;let o=await e.json();if(!tJ.current||t_.current!==t.id)return;if(o?.running&&o.state)return void r(o.state)}catch{}}})()})}return()=>{tJ.current=!1,f.current?.abort(),k.current?.abort(),oc(),tN(),oS(),oC()}},[oc]),(0,n.useEffect)(()=>{c?.(eq)},[eq,c]),(0,n.useEffect)(()=>{d&&d(g?.tree??[],j,oK)},[g?.tree,j,oK,d]),(0,n.useEffect)(()=>(window.addEventListener("keydown",rv),window.addEventListener("pointerdown",rv,{passive:!0}),()=>{window.removeEventListener("keydown",rv),window.removeEventListener("pointerdown",rv)}),[rv]),(0,n.useEffect)(()=>{let e=t7.current;if(e)return e.addEventListener("wheel",rv,{passive:!0}),e.addEventListener("touchstart",rv,{passive:!0}),e.addEventListener("scroll",ry,{passive:!0}),()=>{e.removeEventListener("wheel",rv),e.removeEventListener("touchstart",rv),e.removeEventListener("scroll",ry)}},[C.length,v,ry,rv]),(0,n.useEffect)(()=>{C.length>0&&(t2.current?(t0.current=!0,t1.current&&(t2.current=!1,rk())):v||!t0.current?(v||(t0.current=!0),oH("instant")):!tq.current&&(t4.current||t6.current)&&(oH("smooth"),rj(e=>e+1)))},[C.length,v,B,oH,rk]);let rb=(0,n.useRef)(null),[rw,rj]=(0,n.useState)(0),rS=`${t?.id??null}#${rw}`;(0,n.useEffect)(()=>{let e;if(v){rb.current=null;return}if(0===C.length||rb.current===rS)return;rb.current=rS;let t=!1,o=!1,r=-1,n=0,s=Date.now(),i=()=>{if(t||o)return;let a=t7.current;if(a){if(Date.now()<t8.current){let{scrollTop:e,clientHeight:t,scrollHeight:r}=a;if(e+t<r-150){o=!0;return}}if(oH("instant"),a.scrollHeight===r){if((n+=1)>=4||Date.now()-s>=3e4)return}else if(r=a.scrollHeight,n=0,Date.now()-s>=3e4)return;e=window.setTimeout(i,n>0?500:250)}};return e=window.setTimeout(i,250),()=>{t=!0,void 0!==e&&window.clearTimeout(e)}},[v,oH,rS]),(0,n.useEffect)(()=>{let e=new AbortController;return oY(e.signal).catch(e=>{if(e instanceof DOMException&&"AbortError"===e.name)return}),()=>e.abort()},[oY,l]),(0,n.useEffect)(()=>{if(!en)return;let e=()=>{"visible"===document.visibilityState&&oY()};return document.addEventListener("visibilitychange",e),window.addEventListener("online",e),()=>{document.removeEventListener("visibilitychange",e),window.removeEventListener("online",e)}},[en,oY]),(0,n.useEffect)(()=>{if(!e1)return;let e=setTimeout(()=>e2(null),3e3);return()=>clearTimeout(e)},[e1]),(0,n.useEffect)(()=>{if(!e4)return;let e=setTimeout(()=>e6(null),6e3);return()=>clearTimeout(e)},[e4]),(0,n.useEffect)(()=>{if(0===tr.visible.length)return;let e=tr.visible.find(e=>e.exiting);if(e){let t=setTimeout(()=>{tn({type:"remove",id:e.id})},180);return()=>clearTimeout(t)}if(!tr.visible[0])return;let t=setTimeout(()=>{tn({type:"mark_oldest_exiting"})},5e3);return()=>clearTimeout(t)},[tr.visible]),(0,n.useEffect)(()=>{ti(null)},[C.length,eU?.tokens,eU?.percent,eU?.contextWindow]);let rC=g?.tree??[];return{data:g,loading:v,error:b,activeLeafId:j,messages:C,entryIds:R,historyCursor:I,hasEarlierMessages:P,streamState:W,agentRunning:B,bashRunning:_,pendingBash:V,modelNames:G,modelList:Y,modelThinkingLevels:Z,modelThinkingLevelMaps:ee,modelScopeWarnings:eo,modelsError:en,newSessionModel:ei,toolPreset:ec,thinkingLevel:e$,retryInfo:eO,contextUsage:eU,systemPrompt:eq,forkingEntryId:eK,isCompacting:eQ,compactError:e1,compactResult:e4,currentModel:om,displayModel:of,sessionStats:ox,tokenRate:A,planMode:eu,collaborationMode:eb,tokenMode:ew,toolApprovalMode:ej,permissionRules:eS,modeSettings:ef,approvalRequests:eE,handleCollaborationModeChange:ra,handleTokenModeChange:rl,handleToolApprovalModeChange:rd,handlePermissionRulesChange:rc,resolveApproval:rp,setActiveGoalText:ru,goalState:eD,handleGoalStart:rh,handleGoalPause:rg,handleGoalResume:rm,handleGoalStop:rf,handleGoalEdit:rx,slashCommands:e9,slashCommandsLoading:tt,queuedMessages:tm,pendingRecovery:tk,recoveryIsImport:tW,notices:tr.visible,extensionDialog:ta,extensionCustomUi:td,extensionStatuses:tp,extensionWidgets:th,respondToExtensionUi:oz,sendExtensionCustomInput:oI,agentPhase:e8,isNew:u,promptAnchorActive:e3,branchTree:rC,sessionIdRef:t_,eventSourceRef:tL,messagesEndRef:t3,scrollContainerRef:t7,lastUserMsgRef:t1,pendingScrollToUserRef:t2,initialScrollDoneRef:t0,scrollUserMsgToTop:rk,handleSend:oB,executeBash:oU,handleAbort:o_,handleFork:oq,handleNavigate:oV,handleModelChange:oG,handleCompact:oJ,handleSteer:oQ,handleFollowUp:o1,handlePromptWithStreamingBehavior:o0,handleAbortCompaction:o2,handleRecallQueue:o4,resolveRecovery:o6,exportQueueData:o8,importQueueData:o5,stageQueueImport:o3,moveQueuedMessage:o7,recallQueuedMessage:o9,requeueAt:re,removeQueuedMessage:rt,handleBuiltinSlashCommand:oX,handleToolPresetChange:rr,handleThinkingLevelChange:ro,handlePlanModeChange:rs,loadTools:oy,loadSlashCommands:oj,reloadModels:oY,setActiveLeafId:S,setData:m,setMessages:T,loadContext:ov,dispatch:F,setAgentRunning:U,setForkingEntryId:eG,handleLeafChange:oK,handleAgentEventRef:tQ}}({session:e,newSessionCwd:t,onAgentEnd:W,onSessionCreated:i,onSessionForked:l,modelsRefreshKey:d,chatInputRef:c,onBranchDataChange:p,onSystemPromptChange:u,onSessionStatsPanelOpen:g}),[tc,tp]=(0,n.useState)(!1);(0,n.useEffect)(()=>{0===eg.length&&tp(!1)},[eg.length]);let{balance:tu,refresh:th,refreshSoon:tg}=function(){let[e,t]=(0,n.useState)(null),[o,r]=(0,n.useState)(!1),s=(0,n.useRef)(null),i=(0,n.useRef)(null),a=(0,n.useRef)(!0);(0,n.useEffect)(()=>(a.current=!0,()=>{a.current=!1,i.current&&clearTimeout(i.current),s.current?.abort()}),[]);let l=(0,n.useRef)(null),d=(0,n.useCallback)(async()=>{s.current?.abort();let e=new AbortController;s.current=e;try{let o=await fetch("/api/deepseek/balance",{signal:e.signal,cache:"no-store"}),n=await o.json();if(!a.current)return;if(n?.available&&null!=n.totalBalance){let e=l.current;(null===e||e.available!==n.available||e.reason!==n.reason||e.currency!==n.currency||e.totalBalance!==n.totalBalance||e.grantedBalance!==n.grantedBalance||e.toppedUpBalance!==n.toppedUpBalance)&&(l.current=n,t(n)),r(!1)}else null===l.current&&r(!0)}catch{if(!a.current)return;null===l.current&&r(!0)}},[]),c=(0,n.useCallback)(()=>{i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{i.current=null,d()},2e3)},[d]);return{balance:e,failed:o,refresh:d,refreshSoon:c}}(),tm=el?.provider==="deepseek",tf=(0,n.useRef)(null);(0,n.useEffect)(()=>{tm&&th()},[tm,th]),(0,n.useEffect)(()=>{if(tm)for(let e=H.length-1;e>=0;e--){let t=H[e];if("assistant"!==t.role||!t.usage)continue;let o=`${e}:${B[e]??""}`;o!==tf.current&&(tf.current=o,tg());break}},[H,B,tm,tg]);let tx=(0,n.useMemo)(()=>{let e=H.findLast(e=>"assistant"===e.role&&!!e.usage);if(!e?.usage)return null;let t=e.usage;return{model:e.model??"",input:t.input??0,output:t.output??0,cacheRead:t.cacheRead??0,costCNY:r4(e.model)?r6(e.model,t):0,costUSD:r4(e.model)?0:t.cost?.total??0}},[H]),[tk,tP]=(0,n.useState)(!1),[tE,tW]=(0,n.useState)(null),tF=(0,n.useRef)(!1);(0,n.useEffect)(()=>{if(!e6){tF.current=!1;return}if(_){tF.current=!0;return}tF.current&&(tF.current=!1,tW(function(e){for(let t=e.length-1;t>=0;t--){let o=e[t];if("assistant"!==o.role)continue;let r=o.content;if("string"==typeof r&&r.trim())return r;if(Array.isArray(r)){let e=r.filter(e=>"text"===e.type).map(e=>e.text??"").join("\n").trim();if(e)return e}}for(let t=e.length-1;t>=0;t--){let o=e[t];if("toolResult"!==o.role)continue;let r=o.content,n="string"==typeof r?r:Array.isArray(r)?r.map(e=>e.text??"").join("\n"):"";if(!n)continue;let s=n.match(/\*\*Proposed Plan\*\*\s*\n+([\s\S]+)/i);if(s?.[1]?.trim())return s[1].trim()}return null}(H)??null),tP(!0))},[_,e6,H]);let tD=(0,n.useCallback)(()=>{tP(!1);let e=tA.current;"plan"===e5&&e7("normal"),e8(!1).then(()=>{e&&eD(I("tasks.planReviewExecutePrompt",{plan:e}))})},[e8,eD,I,e5,e7]),tA=(0,n.useRef)(null);(0,n.useEffect)(()=>{tA.current=tE},[tE]);let tN=(0,n.useCallback)(e=>{tP(!1),eB(e)},[eB]),tL=(0,n.useCallback)(()=>{tP(!1),"plan"===e5&&e7("normal"),e8(!1)},[e8,e5,e7]);(0,n.useEffect)(()=>{ex&&E.current!==ex.id&&(E.current=ex.id,P.current&&M.current())},[ex]),(0,n.useEffect)(()=>(a=_||q?eN:null,()=>void(a=null)),[_,q,eN]);let[t$,tH]=(0,n.useState)(!1),[tO,tB]=(0,n.useState)(!1),[tU,t_]=(0,n.useState)(!1),tq=(0,n.useCallback)(()=>{let e=eM.current;if(!e)return;let t=e.scrollHeight-e.scrollTop-e.clientHeight;tH(e.scrollTop>1),tB(t>1),t_(t>240)},[eM]),tV=(0,n.useCallback)(()=>{window.requestAnimationFrame(()=>{let e=eM.current,t=eI.current;if(!e||!t)return;let o=Math.max(88,c?.current?.measureHeight?.()??0),r=()=>{if(!e||!t)return;let r=Math.max(0,t.getBoundingClientRect().top-e.getBoundingClientRect().top+e.scrollTop-96-e.clientHeight+o);e.scrollTo({top:r,behavior:"auto"})};r(),tq(),window.setTimeout(r,200)})},[eI,eM,tq,c]);(0,n.useEffect)(()=>{let e=eM.current;if(!e)return;let t=new ResizeObserver(tq);return t.observe(e),e.firstElementChild&&t.observe(e.firstElementChild),e.addEventListener("scroll",tq,{passive:!0}),tq(),()=>{e.removeEventListener("scroll",tq),t.disconnect()}},[H.length,eM,tq]);let tK=(0,n.useRef)(!1);(0,n.useEffect)(()=>{let t=eM.current;if(!t)return;let o=()=>{if(tK.current||!tl||!ta||t.scrollTop>8)return;let o=e?.id;if(!o)return;tK.current=!0;let r=t.scrollHeight-t.scrollTop;td(o,eT,ta).finally(()=>{tK.current=!1,requestAnimationFrame(()=>{let e=t.scrollHeight-r;Math.abs(t.scrollTop-e)>1&&t.scrollTo({top:e,behavior:"auto"})})})};return t.addEventListener("scroll",o,{passive:!0}),()=>t.removeEventListener("scroll",o)},[eM,ta,tl,td,e?.id,eT]);let tG=(0,n.useRef)(null),tJ=(0,n.useRef)([]),tY=(0,n.useMemo)(()=>({getOffsetForIndex:e=>tG.current?.getOffsetForIndex(e)?.[0]??0,sizeFor:e=>{let t=tG.current;if(!t)return 0;let o=t.measurementsCache[e];return o?.size??t.options.estimateSize?.(e)??0},totalHeight:()=>tG.current?.getTotalSize()??0,refToItemIndex:e=>tJ.current[e],itemCount:tJ.current.length}),[]),tX=ed?[ed.sessionId,ed.sessionFile??"",ed.sessionName??"",ed.userMessages,ed.assistantMessages,ed.toolCalls,ed.toolResults,ed.totalMessages,ed.tokens.input,ed.tokens.output,ed.tokens.cacheRead,ed.tokens.cacheWrite,ed.tokens.total,ed.cost??0,ed.totalActiveMs??0].join("|"):null,tZ=(0,n.useRef)(ed);tZ.current=ed,(0,n.useEffect)(()=>{h?.(tZ.current)},[tX,h]),(0,n.useEffect)(()=>()=>{h?.(null)},[h]);let tQ=er?`${er.percent??"null"}|${er.contextWindow}|${er.tokens??"null"}`:null,t0=(0,n.useRef)(er);t0.current=er,(0,n.useEffect)(()=>{m?.(t0.current)},[tQ,m]),(0,n.useEffect)(()=>()=>{m?.(null)},[m]);let{isDragOver:t2,handleDragEnter:t4,handleDragOver:t6,handleDragLeave:t3,handleDrop:t7}=function(e){let[t,o]=(0,n.useState)(!1),r=(0,n.useRef)(0),s=(0,n.useCallback)(e=>{e.dataTransfer.files.length&&(e.preventDefault(),r.current+=1,o(!0))},[]),i=(0,n.useCallback)(e=>{e.dataTransfer.files.length&&e.preventDefault()},[]);return{isDragOver:t,handleDragEnter:s,handleDragOver:i,handleDragLeave:(0,n.useCallback)(()=>{r.current-=1,r.current<=0&&(r.current=0,o(!1))},[]),handleDrop:(0,n.useCallback)(t=>{t.preventDefault(),r.current=0,o(!1),e(Array.from(t.dataTransfer.files),t.dataTransfer)},[e])}}((0,n.useCallback)((e,t)=>{if(_){let t=e.filter(e=>e.type.startsWith("image/"));t.length&&c?.current?.addImages(t);return}c?.current?.addFiles(e,t)},[_,c])),oe=H.filter(e=>"user"===e.role||"assistant"===e.role),or=(0,n.useMemo)(()=>{let e=new Set,t=[];for(let r=H.length-1;r>=0&&t.length<50;r-=1){var o;let n="user"!==(o=H[r]).role?null:("string"==typeof o.content?o.content:o.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n")).trim()||null;!n||e.has(n)||(e.add(n),t.push(n))}return t},[H]),on=(w=oe.length,(j=(0,n.useRef)([])).current=Array(w).fill(null).map((e,t)=>j.current[t]??null),j),os=eS&&0===H.length&&!U.isStreaming&&!_,oi=e?.cwd??t??void 0,oa=(0,n.useMemo)(()=>(function(e,t,o){let r=new Map;for(let t of e)"toolResult"===t.role&&r.set(t.toolCallId,t);let n=-1;for(let t=e.length-1;t>=0;t--)if("user"===e[t].role){n=t;break}let s=new Map,i=0;e.forEach((e,t)=>{("user"===e.role||"assistant"===e.role)&&s.set(t,i++)});let a=[];for(let n=0;n<e.length;){let s,i=e[n],l="custom"===i.role&&"compaction"===i.customType;if(0===n&&"user"!==i.role&&!l){let o=1;for(;o<e.length&&"user"!==e[o].role;)o+=1;let s=Array.from({length:o},(e,t)=>t).filter(t=>ot(e[t])),i=t5(e,t,s,r);if(i.length>0){a.push({kind:"turn",userIdx:-1,endIdx:o,startsCompactionTurn:!1,finalAssistantIdx:-1,visibleProcessIndices:s,processBlocks:i,finalAnswerMessage:null,writtenFiles:void 0}),n=o;continue}}if("user"!==i.role&&!l){a.push({kind:"single",idx:n}),n+=1;continue}let d=n,c=d+1;for(;c<e.length&&"user"!==e[c].role;)c+=1;let p=function(e,t,o){for(let n=o-1;n>t;n--){var r;if("assistant"===(r=e[n]).role&&t1(r).answerBlocks.some(e=>"image"===e.type||"text"===e.type&&e.text.trim().length>0))return n}for(let r=o-1;r>t;r--)if(e[r]?.role==="assistant")return r;return -1}(e,d,c);if(-1===p){let o=Array.from({length:c-d-1},(e,t)=>d+1+t).filter(t=>ot(e[t])),s=t5(e,t,o,r);a.push({kind:"turn",userIdx:d,endIdx:c,startsCompactionTurn:l,finalAssistantIdx:p,visibleProcessIndices:o,processBlocks:s,finalAnswerMessage:null,writtenFiles:void 0}),n=c;continue}let u=[];for(let e=d+1;e<p;e++)u.push(e);let h=u.filter(t=>ot(e[t])),g=e[p],m=t1(g),f=m.processBlocks.length>0?oo(g,m.processBlocks,{omitUsage:!0}):null,x=m.answerBlocks.length>0?oo(g,m.answerBlocks):null,k=t5(e,t,h,r);if(f&&(k=k.concat(t8(g,{messageIndex:p,entryId:t[p],toolResults:r}).processBlocks)),x){let t=[];for(let o=d+1;o<=p;o++){let r=e[o];if(r?.role==="assistant")for(let e of r.content??[])t.push(e)}s=function(e,t,o){let r=new Set,n=[];for(let s of e){if("toolCall"!==s.type||!function(e){let t,o;return"write"===(t=e.toLowerCase())||t.startsWith("write_")||t.endsWith(".write")||t.endsWith("_write")||"edit"===(o=e.toLowerCase())||o.startsWith("edit_")||o.endsWith(".edit")||o.endsWith("_edit")||o.includes("str_replace")||o.includes("replace_editor")}(s.toolName))continue;let e=t?.get(s.toolCallId);if(!e||e.isError)continue;let i=function(e){if(!e)return null;let t=e.file_path??e.path;return"string"==typeof t&&t.length>0?t:null}(s.input);if(!i)continue;let a=function(e,t){let o;if(!e)return null;let r=/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith("\\\\")||void 0!==t&&(/^[a-zA-Z]:[\\/]/.test(t)||t.startsWith("\\\\")),n=e=>r?e.replace(/\\/g,"/"):e,s=n(e),i=t?n(t).replace(/\/+$/,""):void 0,a=/^[a-zA-Z]:\//.test(s),l=s.startsWith("//");if(a||l)o=s;else if(s.startsWith("/")){let e=i?.match(/^([a-zA-Z]:)(?:\/|$)/)?.[1]??i?.match(/^(\/\/[^/]+\/[^/]+)(?:\/|$)/)?.[1];o=e?`${e}${s}`:s}else{if(!i)return null;o=`${i}/${s}`}return t9(o)}(i,o);a&&(r.has(a)||(r.add(a),n.push({filePath:a})))}return n}(t,r,o)}a.push({kind:"turn",userIdx:d,endIdx:c,startsCompactionTurn:l,finalAssistantIdx:p,visibleProcessIndices:h,processBlocks:k,finalAnswerMessage:x,writtenFiles:s}),n=c}return{toolResultsMap:r,lastUserIdx:n,visibleRefIndexByMessage:s,items:a}})(H,B,oi),[H,B,oi]),ol=el?J[`${el.provider}:${el.modelId}`]??null:null,od=el?Y[`${el.provider}:${el.modelId}`]??null:null,oc=(0,n.useCallback)(()=>{Q()},[Q]),op=(0,n.useCallback)(e=>{e8(e),e&&"plan"!==e5?e7("plan"):e||"plan"!==e5||e7("normal")},[e8,e7,e5]),ou=(0,n.useCallback)(e=>{e7(e),"plan"!==e||e6?"plan"!==e&&e6&&e8(!1):e8(!0)},[e7,e8,e6]),oh=e?.relation?.kind==="subagent"?(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",gap:8,padding:"14px 16px",borderTop:"1px solid var(--border)",color:"var(--text-dim)",fontSize:12},children:[(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("rect",{x:"3",y:"11",width:"18",height:"10",rx:"2"}),(0,r.jsx)("circle",{cx:"12",cy:"5",r:"2"}),(0,r.jsx)("path",{d:"M12 7v4"})]}),I("subagent.readOnlyNotice")]}):(0,r.jsx)(iM,{ref:c,onSend:eD,onBash:eA,tasksBoardEnabled:y,onAbort:eN,onSteer:_?eB:void 0,onFollowUp:_?eU:void 0,onPromptWithStreamingBehavior:_?e_:void 0,isStreaming:_,model:el,modelNames:K,modelList:G,modelScopeWarnings:X,modelsError:Z,onRetryModels:oc,onModelChange:eH,compactResult:ea,toolPreset:ee,onToolPresetChange:e||eS?e1:void 0,planMode:e6,onPlanModeChange:op,collaborationMode:e5,toolApprovalMode:e3,onCollaborationModeChange:ou,goalState:tt,onGoalStart:to,onGoalPause:tr,onGoalResume:tn,onGoalStop:ts,thinkingLevel:et,onThinkingLevelChange:e||eS?e2:void 0,availableThinkingLevels:ol,thinkingLevelMap:od,retryInfo:eo,queuedMessages:eh,inputHistory:or,onRecallQueue:eV,onMoveQueue:eY,onRecallOne:eX,onRequeueAt:eZ,onRemoveQueueItem:eQ,slashCommands:ep,slashCommandsLoading:eu,onLoadSlashCommands:e4,onBuiltinCommand:e0,onAudioUnlock:R,draftKey:e?.id??(t?`new:${t}`:void 0),cwd:e?.cwd??t}),og=ey.filter(e=>"belowEditor"!==e.placement),om=ey.filter(e=>"belowEditor"===e.placement),of=es?I("desktop.compacting"):function(e,t){if(e?.kind==="running_tools"){let o=e.tools.map(e=>e.name);return 0===o.length?t("desktop.runningTool"):t("desktop.runningTools",{tools:o.length<=3?o.join(", "):`${o.slice(0,2).join(", ")} (+${o.length-2})`})}return e?.kind==="waiting_model"?t("desktop.waitingForModel"):e?.kind==="running_command"?t("desktop.runningCommand"):null}(ej,I);return L?(0,r.jsx)("div",{className:"flex h-full items-center justify-center text-text-muted",children:I("desktop.loadingSession")}):$?(0,r.jsx)("div",{className:"flex h-full items-center justify-center text-red-400",children:$}):(0,r.jsxs)("div",{className:"relative flex h-full min-w-0 flex-col overflow-hidden",onDragEnter:t4,onDragOver:t6,onDragLeave:t3,onDrop:t7,children:[t2&&(0,r.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,r.jsx)("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",children:[0,.8,1.6].map(e=>(0,r.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,r.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,r.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,r.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,r.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,r.jsxs)("g",{stroke:"rgba(37,99,235,0.45)",strokeWidth:"1.4",strokeLinecap:"round",children:[(0,r.jsx)("line",{x1:"96",y1:"46",x2:"96",y2:"43"}),(0,r.jsx)("line",{x1:"96",y1:"70",x2:"96",y2:"73"}),(0,r.jsx)("line",{x1:"84",y1:"58",x2:"81",y2:"58"}),(0,r.jsx)("line",{x1:"108",y1:"58",x2:"111",y2:"58"}),(0,r.jsx)("line",{x1:"87.5",y1:"49.5",x2:"85.4",y2:"47.4"}),(0,r.jsx)("line",{x1:"104.5",y1:"66.5",x2:"106.6",y2:"68.6"}),(0,r.jsx)("line",{x1:"104.5",y1:"49.5",x2:"106.6",y2:"47.4"}),(0,r.jsx)("line",{x1:"87.5",y1:"66.5",x2:"85.4",y2:"68.6"})]})]})]}),ex&&(0,r.jsx)(ak,{request:ex,onRespond:eb}),ek&&(0,r.jsx)(av,{request:ek,onInput:ew}),!eS&&eg.length>0&&!tc&&(0,r.jsx)(iW,{items:eg,sessionId:e?.id,onResolve:eK,onExport:eG,onStageImport:eJ,onDismiss:()=>tp(!0),mode:em?"import":"recovery"}),e9.length>0&&(0,r.jsx)(nI,{request:e9[0]??null,queuedCount:Math.max(0,e9.length-1),busy:!1,onResolve:(e,t)=>{let o=e9[0];o&&te(o.id,e,t)}}),os?(0,r.jsx)("div",{className:"flex flex-1 flex-col items-center justify-center overflow-y-auto",children:(0,r.jsxs)("div",{className:"w-full max-w-[820px]",children:[(0,r.jsx)("div",{style:{display:"flex",justifyContent:"center",marginBottom:28},children:(0,r.jsxs)("svg",{fill:"currentColor",fillRule:"evenodd",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",style:{width:64,height:64,color:"var(--accent)",opacity:.85},"aria-label":"Pi",children:[(0,r.jsx)("title",{children:"Pi"}),(0,r.jsx)("path",{clipRule:"evenodd",d:"M1 1h16.5v11H12v5.5H6.5V23H1V1zm5.5 5.5V12H12V6.5H6.5z"}),(0,r.jsx)("path",{d:"M17.5 12H23v11h-5.5V12z"})]})}),z&&(0,r.jsxs)("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",gap:10,marginBottom:18,marginTop:-14},children:[(0,r.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:["web ",(0,r.jsxs)("span",{style:{color:"var(--text)"},children:["v","0.17.0"]})]}),(0,r.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:["pi ",(0,r.jsxs)("span",{style:{color:"var(--text)"},children:["v","0.85.1"]})]})]}),(0,r.jsx)("div",{style:{padding:"0 34px 6px 7px",paddingRight:z?16:34},children:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12},children:[(0,r.jsx)("div",{ref:x,style:{display:"flex",alignItems:"center",minWidth:0,flex:1,minHeight:48}}),(0,r.jsxs)("div",{style:{display:z?"none":"flex",flexDirection:"column",alignItems:"flex-end",gap:2,flexShrink:0},children:[(0,r.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:["web ",(0,r.jsxs)("span",{style:{color:"var(--text)"},children:["v","0.17.0"]})]}),(0,r.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:["pi ",(0,r.jsxs)("span",{style:{color:"var(--text)"},children:["v","0.85.1"]})]})]})]})}),(0,r.jsx)("div",{style:{padding:"0 16px",paddingRight:z?16:34},children:(0,r.jsx)(ax,{notices:ef,align:"right"})}),"goal"===e5&&(0,r.jsx)(nR,{goalState:tt,onPause:tr,onResume:tn,onStop:ts,onEdit:ti}),oh,(0,r.jsx)("div",{style:{padding:"0 16px 6px",paddingRight:z?16:34,marginTop:-15},children:(0,r.jsx)(iK,{onViewFullHistory:k,cwd:oi,systemPrompt:v,sessionStats:ed,contextUsage:er,hasSession:!!e,showChat:!0,showSoundLabel:!0,soundEnabled:S,onSoundToggle:C,onCompact:e?eO:void 0,onAbortCompaction:eq,isCompacting:es,compactError:ei,isDeepSeekOfficial:tm,deepseekBalance:tu,lastTurnUsage:tx})})]})}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"relative flex flex-1 overflow-hidden z-0",children:[(0,r.jsx)("div",{style:{position:"absolute",top:12,left:0,right:18*!z,zIndex:40,padding:"0 16px",pointerEvents:"none"},children:(0,r.jsx)("div",{style:{maxWidth:820,margin:"0 auto"},children:(0,r.jsx)(ax,{notices:ef,floating:!0,align:"right"})})}),(0,r.jsxs)("div",{className:"relative flex-1 min-h-0 min-w-0",children:[(0,r.jsx)("div",{ref:eM,className:"h-full min-w-0 overflow-x-hidden overflow-y-auto pt-4 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:(0,r.jsx)("div",{style:{minWidth:0,padding:"0 16px"},children:(0,r.jsxs)("div",{style:{width:"100%",minWidth:0,maxWidth:820,margin:"0 auto"},children:[(0,r.jsx)(am,{statuses:ev}),(0,r.jsx)(af,{widgets:og}),(()=>{let{toolResultsMap:t,lastUserIdx:o,visibleRefIndexByMessage:n,items:s}=oa,i=(s,i={})=>{let a=i.messageOverride??H[s];if(!a)return null;let l="user"===a.role&&s>0&&"assistant"===H[s-1].role?B[s-1]:void 0,d="user"===a.role||"assistant"===a.role,c=n.get(s),p=i.keyPrefix??"message",u=!1;if("assistant"===a.role){u=!0;for(let e=s+1;e<H.length;e++){let t=H[e].role;if("user"===t)break;if("assistant"===t){u=!1;break}}u&&U.isStreaming&&s===H.length-1&&(u=!1)}void 0!==i.showTimestamp&&(u=i.showTimestamp);let h=(0,r.jsx)(ne,{message:a,toolResults:t,modelNames:K,cwd:oi,onOpenFile:f,entryId:B[s],onFork:_||eS||0===s&&"user"===a.role?void 0:eL,forking:en===B[s],onNavigate:_?void 0:e$,prevAssistantEntryId:_?void 0:l,onEditContent:F,onQuoteReply:D,onOpenSession:b,onCreateTask:N,showTimestamp:u,prevTimestamp:s>0?H[s-1].timestamp:void 0,sessionId:e?.id??ez.current??void 0,writtenFiles:i.writtenFiles},`${p}-view-${s}`);return d&&!1!==i.attachRef&&void 0!==c?(0,r.jsx)("div",{ref:e=>{on.current[c]=e,s===o&&(eP.current=e,e&&eE.current&&(eE.current=!1,eW.current=!0,eF()))},children:h},`${p}-${s}`):h},a=[],l=[],d=(e,t)=>{a.push(e),l.push(t)};for(let a of s){if("single"===a.kind){d(i(a.idx),n.get(a.idx));continue}let{userIdx:s,endIdx:l,startsCompactionTurn:c,finalAssistantIdx:p}=a;if((_||U.isStreaming)&&l===H.length&&(s===o||c)){s>=0&&d(i(s),n.get(s));let o=U.streamingMessage?.role==="assistant",a=[],c=!o&&p>=0?p:l;for(let e=s+1;e<c;e++)ot(H[e])&&a.push(e);let u=t5(H,B,a,t),h=null;if(!o&&p>=0){let e=H[p],o=t1(e,{isStreaming:!0}),r=t8(e,{messageIndex:p,entryId:B[p],toolResults:t,isStreaming:!0});u=u.concat(r.processBlocks),o.answerBlocks.length>0&&(h=oo(e,o.answerBlocks,{omitUsage:!0}))}if(o){let e=U.streamingMessage,o=t1(e,{isStreaming:!0}),r=t8(e,{messageIndex:H.length,toolResults:t,isStreaming:!0});u=u.concat(r.processBlocks),o.answerBlocks.length>0&&(h=oo(e,o.answerBlocks,{omitUsage:!0}))}if(u.length>0){let t=a.map(e=>n.get(e)).find(e=>"number"==typeof e);d((0,r.jsx)("div",{ref:void 0===t?void 0:e=>{on.current[t]=e},children:(0,r.jsx)(su,{blocks:u,isStreaming:_||U.isStreaming,cwd:oi,onOpenFile:f,sessionId:e?.id??ez.current??void 0,tokenRate:ec})},`live-process-group-${s}`),t)}h&&d((0,r.jsx)(ne,{message:h,isStreaming:!0,modelNames:K,cwd:oi,onOpenFile:f,onQuoteReply:D,onOpenSession:b},`live-answer-${s}`),p>=0?n.get(p):void 0);continue}if(-1===p&&0===a.processBlocks.length){for(let e=Math.max(0,s);e<l;e++)d(i(e),n.get(e));continue}s>=0&&d(i(s),n.get(s));let{processBlocks:u,finalAnswerMessage:h,writtenFiles:g,visibleProcessIndices:m}=a;if(u.length>0){let t=m.map(e=>n.get(e)).find(e=>"number"==typeof e)??(h?void 0:n.get(p));d((0,r.jsx)("div",{ref:void 0===t?void 0:e=>{on.current[t]=e},children:(0,r.jsx)(su,{blocks:u,isStreaming:!1,defaultExpanded:!1,onAutoExpanded:void 0,cwd:oi,onOpenFile:f,sessionId:e?.id??ez.current??void 0})},`process-group-${s}-${p}`),t)}h&&d(i(p,{messageOverride:h,writtenFiles:g}),n.get(p));for(let e=p+1;e<l;e++)d(i(e),n.get(e))}let c=[],p=l.map((e,t)=>({startRef:e,itemIdx:t})).filter(e=>void 0!==e.startRef);return p.forEach((e,t)=>{let o=p[t+1]?.startRef??oe.length;for(let t=e.startRef;t<o;t++)c[t]=e.itemIdx}),tJ.current=c,(0,r.jsx)(iJ,{scrollElementRef:eM,items:a,virtualizerRef:tG})})(),of&&(es||_&&!U.streamingMessage)&&(0,r.jsx)("div",{className:"py-2 text-[13px] text-text-muted",children:(0,r.jsxs)("span",{className:"animate-[pulse_1.5s_infinite]",children:[of,ej?.kind==="waiting_model"&&(0,r.jsx)("span",{style:{display:"inline-block",width:12,height:12,marginLeft:6,verticalAlign:"-2px",border:"1.5px solid var(--text-muted)",borderTopColor:"transparent",borderRadius:"50%",animation:"spin 0.6s linear infinite"}})]})}),V&&(0,r.jsx)(ne,{message:{role:"bashExecution",command:V.command,output:"",excludeFromContext:V.excludeFromContext},sessionId:e?.id??ez.current??void 0}),q&&!V&&(0,r.jsx)("div",{className:"py-2 text-[13px] text-text-muted",children:(0,r.jsx)("span",{className:"animate-[pulse_1.5s_infinite]",children:I("desktop.runningShellCommand")})}),(0,r.jsx)("div",{style:{height:96}}),(0,r.jsx)("div",{ref:eI}),(0,r.jsx)(nb,{open:tk,planText:tE,busy:_,onExecute:tD,onFeedback:tN,onExit:tL,onClose:()=>tP(!1)})]})})}),t$&&(0,r.jsx)("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 top-0 z-10 h-8 bg-gradient-to-b from-[var(--bg)] to-transparent"}),tO&&(0,r.jsx)("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 bottom-0 z-10 h-8 bg-gradient-to-t from-[var(--bg)] to-transparent"}),tU&&(0,r.jsxs)("button",{type:"button",onClick:()=>tV(),title:I("desktop.scrollToBottom"),"aria-label":I("desktop.scrollToBottom"),style:{position:"absolute",bottom:14,right:18,zIndex:20,display:"flex",alignItems:"center",gap:6,padding:"5px 10px",border:"1px solid var(--border)",borderRadius:999,background:"color-mix(in srgb, var(--bg-panel) 92%, transparent)",color:"var(--text-muted)",fontSize:11,fontWeight:600,cursor:"pointer",boxShadow:"0 4px 14px rgba(0,0,0,0.14)",backdropFilter:"blur(4px)",transition:"color 0.12s, border-color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:[(0,r.jsx)(rJ.Z,{size:12,weight:"bold","aria-hidden":"true"}),I("desktop.scrollToBottom")]})]}),z?null:(0,r.jsx)(iZ,{messages:H,streamingMessage:U.streamingMessage,scrollContainer:eM,messageRefs:on,virtualizer:tY})]}),(0,r.jsxs)("div",{className:"relative z-10",children:[(0,r.jsx)("div",{style:{padding:"0 16px",paddingRight:z?16:34},children:(0,r.jsx)("div",{style:{maxWidth:820,margin:"0 auto"},children:(0,r.jsx)(af,{widgets:om})})}),oh,(0,r.jsx)("div",{className:`session-info-bar-wrap${z?" is-mobile":""}`,children:(0,r.jsx)("div",{className:"session-info-bar-inner",children:(0,r.jsx)(iK,{onViewFullHistory:k,cwd:oi,systemPrompt:v,sessionStats:ed,contextUsage:er,hasSession:!!e,showChat:!0,soundEnabled:S,onSoundToggle:C,onCompact:e?eO:void 0,onAbortCompaction:eq,isCompacting:es,compactError:ei,branchTree:eC,branchActiveLeafId:eT,onBranchLeafChange:eR,isDeepSeekOfficial:tm,deepseekBalance:tu,lastTurnUsage:tx})})})]})]})]})}function am({statuses:e}){return 0===e.length?null:(0,r.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginBottom:10},children:e.map(e=>(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,maxWidth:"100%",padding:"4px 8px",border:"1px solid color-mix(in srgb, var(--accent) 24%, var(--border))",borderRadius:6,background:"color-mix(in srgb, var(--accent) 7%, var(--bg))",color:"var(--text-muted)",fontSize:12},children:[(0,r.jsx)("span",{style:{color:"var(--accent)",fontFamily:"var(--font-mono)",fontSize:11},children:e.key}),(0,r.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.text})]},e.key))})}function af({widgets:e}){return 0===e.length?null:(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8,marginBottom:10},children:e.map(e=>(0,r.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-panel)",overflow:"hidden"},children:[(0,r.jsx)("div",{style:{padding:"5px 9px",borderBottom:"1px solid var(--border)",color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)"},children:e.key}),(0,r.jsx)("pre",{style:{margin:0,padding:"8px 9px",color:"var(--text-muted)",fontSize:12,lineHeight:1.5,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"var(--font-mono)"},children:e.lines.join("\n")})]},e.key))})}function ax({notices:e,floating:t=!1,align:o="left"}){return 0===e.length?null:(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",alignItems:"right"===o?"flex-end":"stretch",marginBottom:10*!t},children:e.map((o,n)=>{let s="error"===o.type?"#ef4444":"warning"===o.type?"#d97706":"success"===o.type?"#10b981":"var(--accent)";return(0,r.jsxs)("div",{className:"notice-shelf-item",style:{display:"flex",alignItems:"center",gap:10,minHeight:44,maxHeight:180,marginBottom:6*(n!==e.length-1),overflowY:"auto",overflowX:"hidden",borderRadius:14,border:"1px solid color-mix(in srgb, var(--border) 70%, transparent)",background:"var(--bg)",color:"var(--text-muted)",width:"fit-content",maxWidth:"min(100%, 620px)",boxShadow:t?"0 1px 2px rgba(15,23,42,0.05), 0 10px 28px -14px rgba(15,23,42,0.24)":"0 1px 2px rgba(15,23,42,0.04), 0 8px 24px -12px rgba(15,23,42,0.10)",fontSize:13,lineHeight:1.45,transformOrigin:"top center",animation:o.exiting?"notice-shelf-out 0.18s ease-in forwards":"notice-shelf-in 0.18s ease-out both",padding:"0 12px"},children:[(0,r.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:s,flexShrink:0}}),(0,r.jsx)("span",{style:{padding:"10px 0",minWidth:0,maxWidth:"100%",overflowWrap:"anywhere",whiteSpace:"pre-wrap"},children:o.message})]},o.id)})})}function ak({request:e,onRespond:t}){let{t:o}=(0,A.s)(),[s,i]=(0,n.useState)("editor"===e.method?e.prefill??"":"");(0,n.useEffect)(()=>{i("editor"===e.method?e.prefill??"":"")},[e]);let a=()=>{"confirm"===e.method?t(e,{confirmed:!0}):t(e,{value:s})};return(0,r.jsx)("div",{style:{position:"absolute",inset:0,zIndex:90,display:"flex",alignItems:"center",justifyContent:"center",padding:20,background:"rgba(0,0,0,0.18)"},children:(0,r.jsxs)("div",{role:"dialog","aria-modal":"true",style:{width:"min(560px, 100%)",border:"1px solid var(--border)",borderRadius:8,background:"var(--bg)",boxShadow:"0 20px 60px rgba(0,0,0,0.28)",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{padding:"12px 14px",borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)("div",{style:{color:"var(--text)",fontSize:14,fontWeight:650},children:e.title}),(0,r.jsx)("div",{style:{marginTop:3,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)"},children:o("desktop.extensionRequest")})]}),(0,r.jsxs)("div",{style:{padding:14},children:["confirm"===e.method&&(0,r.jsx)("div",{style:{color:"var(--text-muted)",fontSize:13,lineHeight:1.6,whiteSpace:"pre-wrap"},children:e.message}),"select"===e.method&&(0,r.jsx)("div",{style:{display:"grid",gap:8},children:e.options.map(o=>(0,r.jsx)("button",{onClick:()=>t(e,{value:o}),style:{width:"100%",padding:"9px 10px",borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",cursor:"pointer",textAlign:"left",fontSize:13},children:o},o))}),"input"===e.method&&(0,r.jsx)("input",{autoFocus:!0,value:s,placeholder:e.placeholder,onChange:e=>i(e.target.value),onKeyDown:o=>{"Enter"===o.key&&a(),"Escape"===o.key&&t(e,{cancelled:!0})},style:{width:"100%",padding:"9px 10px",borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",outline:"none",fontSize:13}}),"editor"===e.method&&(0,r.jsx)("textarea",{autoFocus:!0,value:s,onChange:e=>i(e.target.value),onKeyDown:o=>{"Escape"===o.key&&t(e,{cancelled:!0}),(o.metaKey||o.ctrlKey)&&"Enter"===o.key&&a()},style:{width:"100%",minHeight:220,padding:10,borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",outline:"none",resize:"vertical",fontSize:13,lineHeight:1.55,fontFamily:"var(--font-mono)"}})]}),(0,r.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,padding:"10px 14px",borderTop:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,r.jsx)("button",{onClick:()=>t(e,{cancelled:!0}),style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text-muted)",cursor:"pointer"},children:o("desktop.cancel")}),"confirm"===e.method?(0,r.jsx)("button",{onClick:a,style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--accent)",background:"var(--accent)",color:"#fff",cursor:"pointer"},children:o("desktop.confirm")}):"select"!==e.method?(0,r.jsx)("button",{onClick:a,style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--accent)",background:"var(--accent)",color:"#fff",cursor:"pointer"},children:o("desktop.submit")}):null]})]})})}function av({request:e,onInput:t}){let{t:o}=(0,A.s)(),s=(0,n.useRef)(null),i=function(e){let t=/^[┌├└╭╰][─┬┴┼]+[┐┤┘╮╯]$/,o=[];for(let r of e){let e=tJ(r).trimEnd();if(t.test(e))continue;let n=r,s=tZ(n);("│"===s||"┃"===s)&&" "===tZ(n=tX(n,0))&&(n=tX(n,0));let i=function(e){let t=tY(e);for(let e=t.length-1;e>=0;e--)if(""!==t[e].char.trim())return e;return -1}(n),a=i>=0?tY(n)[i]?.char:void 0;("│"===a||"┃"===a)&&(n=tX(n,i)),o.push(function(e){let t=e;for(;;){let e=tY(t),o=e[e.length-1];if(!o||""!==o.char.trim())return t;t=t.slice(0,o.start)+t.slice(o.end)}}(n))}for(;o.length>0&&""===tJ(o[0]).trim();)o.shift();for(;o.length>0&&""===tJ(o[o.length-1]).trim();)o.pop();return o.length?o:e}(e.lines);return(0,n.useEffect)(()=>{s.current?.focus()},[e.id]),(0,r.jsx)("div",{style:{position:"absolute",inset:0,zIndex:95,display:"flex",alignItems:"center",justifyContent:"center",padding:20,background:"rgba(0,0,0,0.18)"},children:(0,r.jsxs)("div",{ref:s,tabIndex:0,role:"dialog","aria-modal":"true",onKeyDown:o=>{let r=function(e){if(e.ctrlKey&&!e.metaKey&&!e.altKey&&1===e.key.length){let t=e.key.toLowerCase();if(t>="a"&&t<="z")return String.fromCharCode(t.charCodeAt(0)-96)}switch(e.key){case"ArrowUp":return"\x1b[A";case"ArrowDown":return"\x1b[B";case"ArrowRight":return"\x1b[C";case"ArrowLeft":return"\x1b[D";case"Enter":return"\r";case"Escape":return"\x1b";case"Backspace":return"";case"Tab":return" ";case" ":return" ";default:if(!e.ctrlKey&&!e.metaKey&&!e.altKey&&1===e.key.length)return e.key;return null}}(o);r&&(o.preventDefault(),o.stopPropagation(),t(e,r))},style:{width:"min(920px, 100%)",maxHeight:"min(760px, calc(100vh - 40px))",border:"1px solid var(--border)",borderRadius:8,background:"var(--bg)",boxShadow:"0 20px 60px rgba(0,0,0,0.28)",overflow:"hidden",outline:"none"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:"10px 12px",borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)("div",{style:{color:"var(--text)",fontSize:13,fontWeight:650},children:o("desktop.extensionPanel")}),(0,r.jsx)("button",{onClick:()=>t(e,"\x03"),style:{padding:"5px 9px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:o("desktop.close")})]}),(0,r.jsx)("pre",{style:{margin:0,padding:14,maxHeight:"calc(min(760px, 100vh - 40px) - 48px)",overflow:"auto",background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:13,lineHeight:1.45,whiteSpace:"pre"},children:(i.length?i:[""]).map((e,t,o)=>{var s;return(0,r.jsxs)(n.Fragment,{children:[(s=`line-${t}`,(function(e){let t,o=[],r={},n=0;for(tV.lastIndex=0;null!==(t=tV.exec(e));)t.index>n&&o.push({text:e.slice(n,t.index),style:r}),r=function(e,t){let o={...e};for(let e=0;e<t.length;e++){let r=t[e];if(0===r)for(let e of Object.keys(o))delete o[e];else if(1===r)o.fontWeight=700;else if(2===r)o.opacity=.65;else if(3===r)o.fontStyle="italic";else if(4===r)o.textDecoration="underline";else if(22===r)delete o.fontWeight,delete o.opacity;else if(23===r)delete o.fontStyle;else if(24===r)delete o.textDecoration;else if(39===r)delete o.color;else if(49===r)delete o.backgroundColor;else if(r>=30&&r<=37)o.color=tK[r-30];else if(r>=90&&r<=97)o.color=tG[r-90];else if(r>=40&&r<=47)o.backgroundColor=tK[r-40];else if(r>=100&&r<=107)o.backgroundColor=tG[r-100];else if((38===r||48===r)&&2===t[e+1]){let[n,s,i]=[t[e+2],t[e+3],t[e+4]];[n,s,i].every(e=>"number"==typeof e&&Number.isFinite(e))&&(38===r?o.color=`rgb(${n}, ${s}, ${i})`:o.backgroundColor=`rgb(${n}, ${s}, ${i})`),e+=4}else if((38===r||48===r)&&5===t[e+1]){let n=function(e){if(e>=0&&e<8)return tK[e];if(e>=8&&e<16)return tG[e-8];if(e>=16&&e<=231){let t=e-16,o=Math.floor(t/36),r=Math.floor(t%36/6),n=e=>0===e?0:55+40*e;return`rgb(${n(o)}, ${n(r)}, ${n(t%6)})`}if(e>=232&&e<=255){let t=8+(e-232)*10;return`rgb(${t}, ${t}, ${t})`}}(t[e+2]);n&&(38===r?o.color=n:o.backgroundColor=n),e+=2}}return o}(r,t[1]?t[1].split(";").map(e=>Number(e||"0")):[0]),n=t.index+t[0].length;return n<e.length&&o.push({text:e.slice(n),style:r}),o})(e).map((e,t)=>Object.keys(e.style).length>0?(0,r.jsx)("span",{style:e.style,children:e.text},`${s}-${t}`):e.text)),t<o.length-1?"\n":null]},t)})})]})})}var ay=o(93549);let ab={png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml",bmp:"image/bmp",ico:"image/x-icon",avif:"image/avif"},aw={mp3:"audio/mpeg",wav:"audio/wav",ogg:"audio/ogg",oga:"audio/ogg",opus:"audio/ogg",m4a:"audio/mp4",aac:"audio/aac",flac:"audio/flac",weba:"audio/webm"};function aj(e){return(e.replace(/\\/g,"/").split("/").pop()??"").toLowerCase().split(".").pop()??""}function aS(e){let t=e.nodeType===Node.ELEMENT_NODE?e:e.parentElement;return t?.closest(".file-source-line[data-line-number]")??null}function aC(e,t){if(!t||t.isCollapsed||0===t.rangeCount)return null;let o=t.getRangeAt(0);if(!e.contains(o.startContainer)||!e.contains(o.endContainer))return null;let r=Number(aS(o.startContainer)?.dataset.lineNumber),n=Number(aS(o.endContainer)?.dataset.lineNumber);return Number.isInteger(r)&&Number.isInteger(n)?r<=n?{startLine:r,endLine:n}:{startLine:n,endLine:r}:null}function aT(e,t,o,r={}){let n=ed(e),s=new URLSearchParams({type:t});for(let[e,t]of(o&&s.set("sessionId",o),Object.entries(r)))void 0!==t&&s.set(e,String(t));return`/api/files/${n}?${s.toString()}`}function aR({filePath:e,sourceSessionId:t}){let{t:o}=(0,A.s)();return(0,r.jsx)("a",{href:aT(e,"download",t),download:ec(e),title:o("desktop.downloadFile"),style:{display:"flex",alignItems:"center",justifyContent:"center",height:20,padding:"0 5px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:4,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,textDecoration:"none"},children:(0,r.jsx)(E.z,{size:11,"aria-hidden":"true"})})}let az={fontFamily:"var(--font-mono)",fontSize:13,lineHeight:1.6,tabSize:2},aI={fontFamily:"var(--font-mono)",fontSize:13,lineHeight:1.6,padding:"12px 0 12px 16px",color:"var(--text-dim)",textAlign:"right",userSelect:"none"};async function aM(e,t){let o=await fetch(`/api/files/${ed(e)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t})});if(!o.ok)throw Error((await o.json().catch(()=>({}))).error??`HTTP ${o.status}`);let r=await o.json();return"number"==typeof r.size?r.size:0}let aP={delete:"3px solid var(--git-status-deleted)",add:"3px solid var(--git-status-added)",edit:"3px solid var(--git-status-modified)"},aE="var(--git-status-deleted-bg)",aW="var(--git-status-added-bg)",aF="var(--git-status-added)";function aD(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function aA({oldContent:e,newContent:t}){let{t:o}=(0,A.s)(),n=function(e,t){let o=e.length,r=t.length,n=o+r,s=Array(2*n+1).fill(0),i=[];for(let a=0;a<=n;a++){i.push([...s]);for(let l=-a;l<=a;l+=2){let d,c=(d=l===-a||l!==a&&s[l-1+n]<s[l+1+n]?s[l+1+n]:s[l-1+n]+1)-l;for(;d<o&&c<r&&e[d]===t[c];)d++,c++;if(s[l+n]=d,d>=o&&c>=r){let s=[],l=o,d=r;for(let o=a;o>0;o--){let r,a=i[o-1],c=l-d;r=c===-o||c!==o&&a[c-1+n]<a[c+1+n]?c+1:c-1;let p=a[r+n],u=p-r;for(;l>p&&d>u;)l--,d--,s.unshift({type:"unchanged",text:e[l]});o>0&&(l>p?(l--,s.unshift({type:"removed",text:e[l]})):(d--,s.unshift({type:"added",text:t[d]})))}for(;l>0&&d>0;)l--,d--,s.unshift({type:"unchanged",text:e[l]});return s}}}return[...e.map(e=>({type:"removed",text:e})),...t.map(e=>({type:"added",text:e}))]}(e.split("\n"),t.split("\n"));if(!n.some(e=>"unchanged"!==e.type))return(0,r.jsx)("div",{style:{padding:"12px 16px",fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:o("desktop.noChanges")});let s=new Set(n.flatMap((e,t)=>"unchanged"!==e.type?[t]:[])),i=new Set;for(let e of s)for(let t=Math.max(0,e-3);t<=Math.min(n.length-1,e+3);t++)i.add(t);let a=[],l=0;for(;l<n.length;)if(i.has(l)){let e=[];for(;l<n.length&&i.has(l);)e.push(n[l]),l++;a.push({hidden:!1,lines:e})}else{let e=0;for(;l<n.length&&!i.has(l);)e++,l++;a.push({hidden:!0,count:e})}let d=[],c=1;for(let e of n)"removed"===e.type?d.push(0):d.push(c++);let p=0;return(0,r.jsx)("div",{style:{fontFamily:"var(--font-mono)",fontSize:13,lineHeight:1.6,minWidth:"max-content"},children:a.map((e,t)=>{if(e.hidden){let n=(0,r.jsx)("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:o("desktop.unchangedLines",{count:e.count})},t);return p+=e.count,n}let n=[],s=[],i=[],a=()=>{if(s.length||i.length){let e=s.length&&i.length?"edit":s.length?"delete":"add";for(let t of s)n.push({key:t.key,kind:"removed",text:t.text,lineNo:null,block:e});for(let t of i)n.push({key:t.key,kind:"added",text:t.text,lineNo:t.lineNo,block:e});s=[],i=[]}};e.lines.forEach((e,o)=>{"unchanged"===e.type?(a(),n.push({key:`${t}:${o}`,kind:"context",text:e.text,lineNo:d[p+o],block:null})):"removed"===e.type?s.push({key:`${t}:${o}`,text:e.text}):i.push({key:`${t}:${o}`,text:e.text,lineNo:d[p+o]})}),a();let l=n.map(e=>{let t="removed"===e.kind?aE:"added"===e.kind?aW:"transparent",o=e.block?aP[e.block]:"3px solid transparent",n="added"===e.kind?aF:"var(--text-dim)";return(0,r.jsxs)("div",{style:{display:"flex",background:t,borderLeft:o},children:[(0,r.jsx)("span",{style:{minWidth:44,padding:"0 8px 0 16px",textAlign:"right",color:n,userSelect:"none",fontSize:11,lineHeight:1.6,flexShrink:0},children:e.lineNo??""}),(0,r.jsx)("span",{style:{flex:1,minWidth:0,padding:"0 8px 0 0",whiteSpace:"pre",color:"var(--text)"},children:e.text||"\xa0"})]},e.key)});return p+=e.lines.length,(0,r.jsx)("div",{children:l},t)})})}function aN({patch:e}){let t=rU(e);if(!t)return null;let o=[],n=[],s=[],i=()=>{if(n.length||s.length){let e=n.length&&s.length?"edit":n.length?"delete":"add";for(let t of n)o.push({key:t.key,kind:"removed",text:t.text,lineNo:null,block:e});for(let t of s)o.push({key:t.key,kind:"added",text:t.text,lineNo:t.lineNo,block:e});n=[],s=[]}};return t.forEach((e,t)=>{e.rows.forEach((e,r)=>{if("hunk"===e.type){i(),o.push({key:`${t}:${r}:h`,kind:"hunk",text:e.text,lineNo:null,block:null});return}let{left:a,right:l}=e;if("context"===a.type&&"context"===l.type){i(),o.push({key:`${t}:${r}:c`,kind:"context",text:a.text,lineNo:l.lineNo,block:null});return}"removed"===a.type&&n.push({key:`${t}:${r}:l`,text:a.text}),"added"===l.type&&s.push({key:`${t}:${r}:r`,text:l.text,lineNo:l.lineNo})})}),i(),(0,r.jsx)("div",{style:{fontFamily:"var(--font-mono)",fontSize:12,lineHeight:1.55,minWidth:"max-content"},children:o.map(e=>{if("hunk"===e.kind)return(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{style:{height:"1.55em"}}),(0,r.jsx)("div",{style:{padding:"3px 12px",color:"var(--accent-blue)",background:"var(--bg-secondary)"},children:e.text}),(0,r.jsx)("div",{style:{height:"1.55em"}})]},e.key);let t="removed"===e.kind?aE:"added"===e.kind?aW:"transparent",o=e.block?aP[e.block]:"3px solid transparent",n="added"===e.kind?aF:"var(--text-dim)";return(0,r.jsxs)("div",{style:{display:"flex",background:t,borderLeft:o},children:[(0,r.jsx)("span",{style:{width:44,flexShrink:0,padding:"0 8px 0 16px",textAlign:"right",color:n,userSelect:"none",fontSize:11},children:e.lineNo??""}),(0,r.jsx)("span",{style:{flex:1,minWidth:0,padding:"0 8px 0 0",whiteSpace:"pre",color:"var(--text)"},children:e.text||"\xa0"})]},e.key)})})}function aL({filePath:e,cwd:t,sourceSessionId:o}){let{t:s}=(0,A.s)(),[i,a]=(0,n.useState)(0),[l,d]=(0,n.useState)(null),[c,p]=(0,n.useState)(null),[u,h]=(0,n.useState)(null),g=(0,n.useRef)(null),m=ec(e).toLowerCase().split(".").pop()??"";(0,n.useEffect)(()=>{a(0),d(null),p(null),h(null),g.current&&(g.current.close(),g.current=null);let t=new EventSource(aT(e,"watch",o));return g.current=t,t.addEventListener("change",e=>{try{let t=JSON.parse(e.data);"number"==typeof t.size&&d(t.size)}catch{}a(e=>e+1)}),()=>{t.close(),g.current=null}},[e,o]);let f=aT(e,"read",o,i?{v:i}:void 0),x=null!=l?aD(l):null;return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,r.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,r.jsx)("span",{style:{fontFamily:"var(--font-mono)"},title:e,children:ep(e,t)}),(0,r.jsx)("span",{style:{marginLeft:"auto"},children:m||s("desktop.image")}),c&&(0,r.jsxs)("span",{children:[c.w," \xd7 ",c.h]}),x&&(0,r.jsx)("span",{children:x}),(0,r.jsx)(aR,{filePath:e,sourceSessionId:o})]}),(0,r.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:u?(0,r.jsx)("div",{style:{color:"#f87171",fontSize:13},children:u}):(0,r.jsx)("img",{src:f,alt:e,onLoad:e=>{let t=e.currentTarget;p({w:t.naturalWidth,h:t.naturalHeight})},onError:()=>h(s("desktop.failedToLoadImage")),style:{maxWidth:"100%",maxHeight:"100%",objectFit:"contain",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"}})})]})}function a$({filePath:e,cwd:t,sourceSessionId:o}){let{t:s}=(0,A.s)(),[i,a]=(0,n.useState)(0),[l,d]=(0,n.useState)(null),[c,p]=(0,n.useState)(null),[u,h]=(0,n.useState)(null),g=(0,n.useRef)(null),m=ec(e).toLowerCase().split(".").pop()??"";(0,n.useEffect)(()=>{a(0),d(null),p(null),h(null),g.current&&(g.current.close(),g.current=null);let t=new EventSource(aT(e,"watch",o));return g.current=t,t.addEventListener("change",e=>{try{let t=JSON.parse(e.data);"number"==typeof t.size&&d(t.size)}catch{}p(null),h(null),a(e=>e+1)}),()=>{t.close(),g.current=null}},[e,o]);let f=aT(e,"read",o,i?{v:i}:void 0);return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,r.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,r.jsx)("span",{style:{fontFamily:"var(--font-mono)"},title:e,children:ep(e,t)}),(0,r.jsx)("span",{style:{marginLeft:"auto"},children:m||s("desktop.audio")}),null!=c&&(0,r.jsx)("span",{children:function(e){if(!Number.isFinite(e))return"";let t=Math.round(e),o=Math.floor(t/60);return`${o}:${String(t%60).padStart(2,"0")}`}(c)}),null!=l&&(0,r.jsx)("span",{children:aD(l)}),(0,r.jsx)(aR,{filePath:e,sourceSessionId:o})]}),(0,r.jsx)("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",padding:24,background:"var(--bg-panel)"},children:(0,r.jsxs)("div",{style:{width:"min(680px, 100%)"},children:[u&&(0,r.jsx)("div",{style:{color:"#f87171",fontSize:13,marginBottom:12,textAlign:"center"},children:u}),(0,r.jsx)("audio",{controls:!0,preload:"metadata",src:f,onLoadedMetadata:e=>p(e.currentTarget.duration),onError:()=>h(s("desktop.failedToLoadAudio")),style:{width:"100%"}},f)]})})]})}function aH({filePath:e,cwd:t,sourceSessionId:o}){let{t:s}=(0,A.s)(),[i,a]=(0,n.useState)(0),[l,d]=(0,n.useState)(null),[c,p]=(0,n.useState)(null),u=(0,n.useRef)(null),h=aj(e),g="pdf"===h,m=g?aT(e,"read",o,i?{v:i}:void 0):aT(e,"preview",o,i?{v:i}:void 0);return(0,n.useEffect)(()=>{a(0),d(null),p(null),u.current&&(u.current.close(),u.current=null),fetch(aT(e,"meta",o)).then(e=>e.json()).then(e=>{e.error&&p(e.error),"number"==typeof e.size&&(d(e.size),!g&&e.size>0xa00000&&p(s("desktop.docxTooLargeForPreview")))}).catch(e=>p(String(e)));let t=new EventSource(aT(e,"watch",o));return u.current=t,t.addEventListener("change",e=>{try{let t=JSON.parse(e.data);if("number"==typeof t.size&&(d(t.size),!g&&t.size>0xa00000))return void p(s("desktop.docxTooLargeForPreview"))}catch{}p(null),a(e=>e+1)}),()=>{t.close(),u.current=null}},[e,g,o,s]),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,r.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,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:e,children:ep(e,t)}),(0,r.jsx)("span",{style:{marginLeft:"auto"},children:"docx"===h?s("desktop.docxPreview"):"pdf"}),null!=l&&(0,r.jsx)("span",{children:aD(l)}),(0,r.jsx)(aR,{filePath:e,sourceSessionId:o})]}),(0,r.jsx)("div",{style:{flex:1,minHeight:0,background:"var(--bg-panel)"},children:c?(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",padding:24,color:"#f87171",fontSize:13,textAlign:"center"},children:c}):(0,r.jsx)("iframe",{src:m,sandbox:g?void 0:"allow-same-origin",title:s("desktop.previewFile",{file:ec(e)}),style:{width:"100%",height:"100%",border:"none",background:g?"var(--bg)":"#eef1f5"}},m)})]})}function aO({filePath:e,cwd:t,sourceSessionId:o,onOpenFile:n,onAtMention:s,onMentionLines:i,initialDisplayMode:a,onFileSaved:l}){let d;return null!==(ab[aj(e)]??null)?(0,r.jsx)(aL,{filePath:e,cwd:t,sourceSessionId:o}):null!==(aw[aj(e)]??null)?(0,r.jsx)(a$,{filePath:e,cwd:t,sourceSessionId:o}):null!==("pdf"===(d=aj(e))||"docx"===d?d:null)?(0,r.jsx)(aH,{filePath:e,cwd:t,sourceSessionId:o}):(0,r.jsx)(aB,{filePath:e,cwd:t,sourceSessionId:o,onOpenFile:n,onAtMention:s,onMentionLines:i,initialDisplayMode:a,onFileSaved:l})}function aB({filePath:e,cwd:t,sourceSessionId:o,onOpenFile:s,onAtMention:i,onMentionLines:a,initialDisplayMode:l,onFileSaved:d}){let c,p,{t:u}=(0,A.s)(),[g,m]=(0,n.useState)(null),[x,k]=(0,n.useState)(null),[v,y]=(0,n.useState)(null),[b,w]=(0,n.useState)(!0),[j,S]=(0,n.useState)(null),[C,T]=(0,n.useState)(!1),[R,z]=(0,n.useState)("source"),[I,M]=(0,n.useState)(!1),[P,E]=(0,n.useState)(0),[W,F]=(0,n.useState)(null),D=(0,n.useRef)(null),N=(0,n.useRef)(null),[L,$]=(0,n.useState)(!1),[H,O]=(0,n.useState)(""),[B,U]=(0,n.useState)(""),[_,q]=(0,n.useState)(!1),[V,K]=(0,n.useState)(null),[G,J]=(0,n.useState)(!1),Y=(0,n.useRef)(null),X=(0,n.useRef)(null),Z=(0,n.useRef)(0),Q=(0,n.useRef)(!1);(0,n.useEffect)(()=>{Q.current=L},[L]);let ee=L&&H!==B,et=!!(g?.content&&g.content.includes("\0")),eo=(0,n.useCallback)(async e=>{if(!t)return void y(null);try{let o=new URLSearchParams({cwd:t,path:e}),r=await fetch(`/api/git/diff?${o.toString()}`),n=await r.json();y(r.ok&&n.supported&&"string"==typeof n.patch?n:null)}catch{y(null)}},[t]),er=(0,n.useCallback)((e,t=!1)=>fetch(aT(e,"read",o)).then(e=>e.json()).then(e=>e.error?(S(e.error),null):(t?(m(t=>(t&&k(t.content),e)),E(e=>e+1)):m(e),e)).catch(e=>(S(String(e)),null)),[o]);(0,n.useEffect)(()=>{w(!0),S(null),m(null),k(null),y(null),T(!1),z("source"),M(!1),E(0),$(!1),O(""),U(""),K(null),J(!1),q(!1),D.current&&(D.current.close(),D.current=null),er(e).then(e=>{(e?.language==="markdown"||e?.language==="html")&&"diff"!==l&&T(!0)}).finally(()=>w(!1)),eo(e);let t=new EventSource(aT(e,"watch",o));return D.current=t,t.addEventListener("change",()=>{Q.current?J(!0):(er(e,!0),eo(e))}),()=>{t.close(),D.current=null}},[e,er,eo,l,o]);let en=(0,n.useCallback)(()=>{g&&!et&&(O(g.content),U(g.content),K(null),J(!1),$(!0))},[g,et]),es=(0,n.useCallback)(()=>{$(!1),O(""),U(""),K(null),J(!1)},[]),ei=(0,n.useCallback)(()=>{(!ee||window.confirm(u("files.unsavedChanges")))&&es()},[ee,es,u]),ea=(0,n.useCallback)(async()=>{if(!g||_)return;let t=++Z.current;q(!0),K(null);try{let o=await aM(e,H);if(t!==Z.current)return;m(e=>e?{...e,content:H,size:o}:e),U(H),q(!1),es(),eo(e),d?.()}catch(e){if(t!==Z.current)return;K(e instanceof Error?e.message:String(e)),q(!1)}},[g,_,H,e,es,eo,d]);(0,n.useEffect)(()=>{if(!L)return;let e=e=>{if((e.metaKey||e.ctrlKey)&&"s"===e.key.toLowerCase()){e.preventDefault(),ea();return}"Escape"===e.key&&(e.preventDefault(),ei())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[L,ea,ei]),(0,n.useEffect)(()=>{if(!ee)return;let e=e=>{e.preventDefault(),e.returnValue=""};return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[ee]);let ed=(0,n.useCallback)(()=>{let e=Y.current,t=X.current;e&&t&&(t.scrollTop=e.scrollTop)},[]),ec=(0,n.useCallback)(e=>{if("Tab"!==e.key||e.metaKey||e.ctrlKey||e.altKey)return;e.preventDefault();let t=e.currentTarget,{selectionStart:o,selectionEnd:r}=t;O(t.value.slice(0,o)+" "+t.value.slice(r)),requestAnimationFrame(()=>{let e=Y.current;if(!e)return;let t=o+2;e.selectionStart=t,e.selectionEnd=t})},[]),eu=(0,n.useMemo)(()=>ru(g?.content??""),[g?.content]),eh=v?.supported===!0&&"string"==typeof v.patch;(0,n.useEffect)(()=>{"diff"===l&&eh&&z("diff")},[eh,l]);let em=eh&&v?.status==="deleted",ef=(0,n.useCallback)(o=>{a&&o&&a(ep(e,t),o.startLine,o.endLine)},[t,e,a]);if((0,n.useEffect)(()=>{let e=()=>{let e=N.current,t="source"===R&&!C;F(a&&t&&e?aC(e,window.getSelection()):null)};if(e(),a&&"source"===R&&!C)return document.addEventListener("selectionchange",e),()=>document.removeEventListener("selectionchange",e)},[g?.content,a,C,R]),(0,n.useEffect)(()=>{if(!a||"source"!==R||C)return;let e=e=>{if(e.repeat||"i"!==e.key.toLowerCase()||!e.metaKey&&!e.ctrlKey||e.altKey||e.shiftKey)return;let t=e.target;if(t instanceof Element&&t.closest("input, textarea, [contenteditable='true']"))return;let o=N.current,r=o?aC(o,window.getSelection()):null;r&&(e.preventDefault(),ef(r))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[ef,a,C,R]),b)return(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:u("desktop.loadingFile")});if(em&&!g)return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,r.jsx)("div",{style:{padding:"5px 16px",borderBottom:"1px solid var(--border)",color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11},title:e,children:ep(e,t)}),(0,r.jsx)("div",{style:{flex:1,overflow:"auto",background:"var(--bg)"},children:(0,r.jsx)(aN,{patch:v.patch})})]});if(j)return(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#f87171",fontSize:13},children:j});if(!g)return null;let ex="html"===g.language,ek="markdown"===g.language,ev=(p=(c=el(e).replace(/\/+$/,"")).lastIndexOf("/"))<0?"":0===p?"/":2===p&&/^[a-zA-Z]:\//.test(c)?c.slice(0,3):c.slice(0,p),ey=g.content.split("\n"),eb=null!==x&&x!==g.content||eh,ew=!em&&!et&&eg();return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,r.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,r.jsx)("span",{style:{fontFamily:"var(--font-mono)"},title:e,children:ep(e,t)}),(0,r.jsx)("span",{style:{marginLeft:"auto"},children:g.language}),"source"===R&&!L&&(0,r.jsx)("span",{children:u("desktop.lines",{count:ey.length})}),(0,r.jsx)("span",{children:aD(g.size)}),eb&&!L&&(0,r.jsxs)("div",{style:{display:"flex",borderRadius:5,overflow:"hidden",border:"1px solid var(--border)"},children:[(0,r.jsx)("button",{onClick:()=>z("source"),style:{padding:"2px 8px",fontSize:11,border:"none",cursor:"pointer",background:"source"===R?"var(--bg-selected)":"var(--bg-hover)",color:"source"===R?"var(--text)":"var(--text-muted)",fontWeight:"source"===R?600:400},children:u("desktop.source")}),(0,r.jsxs)("button",{onClick:()=>z("diff"),style:{padding:"2px 8px",fontSize:11,border:"none",borderLeft:"1px solid var(--border)",cursor:"pointer",background:"diff"===R?"var(--bg-selected)":"var(--bg-hover)",color:"diff"===R?"var(--text)":"var(--text-muted)",fontWeight:"diff"===R?600:400},children:[u("desktop.diff")," ",P>0&&(0,r.jsxs)("span",{style:{color:"var(--git-status-added)",marginLeft:2},children:["+",P]})]})]}),"source"===R&&!C&&!L&&(0,r.jsx)("button",{onClick:()=>M(e=>!e),title:I?u("desktop.disableWordWrap"):u("desktop.enableWordWrap"),style:{padding:"2px 8px",fontSize:11,cursor:"pointer",background:I?"var(--bg-selected)":"var(--bg-hover)",color:I?"var(--text)":"var(--text-muted)",border:"1px solid var(--border)",borderRadius:5,fontWeight:I?600:400},children:u("desktop.wrap")}),ex&&"source"===R&&!L&&(0,r.jsxs)("div",{style:{display:"flex",borderRadius:5,overflow:"hidden",border:"1px solid var(--border)"},children:[(0,r.jsx)("button",{onClick:()=>T(!1),style:{padding:"2px 8px",fontSize:11,border:"none",cursor:"pointer",background:C?"var(--bg-hover)":"var(--bg-selected)",color:C?"var(--text-muted)":"var(--text)",fontWeight:C?400:600},children:u("desktop.code")}),(0,r.jsx)("button",{onClick:()=>T(!0),style:{padding:"2px 8px",fontSize:11,border:"none",borderLeft:"1px solid var(--border)",cursor:"pointer",background:C?"var(--bg-selected)":"var(--bg-hover)",color:C?"var(--text)":"var(--text-muted)",fontWeight:C?600:400},children:u("desktop.preview")})]}),ek&&"source"===R&&!L&&(0,r.jsxs)("div",{style:{display:"flex",borderRadius:5,overflow:"hidden",border:"1px solid var(--border)"},children:[(0,r.jsx)("button",{onClick:()=>T(!0),style:{padding:"2px 8px",fontSize:11,border:"none",cursor:"pointer",background:C?"var(--bg-selected)":"var(--bg-hover)",color:C?"var(--text)":"var(--text-muted)",fontWeight:C?600:400},children:u("desktop.preview")}),(0,r.jsx)("button",{onClick:()=>T(!1),style:{padding:"2px 8px",fontSize:11,border:"none",borderLeft:"1px solid var(--border)",cursor:"pointer",background:C?"var(--bg-hover)":"var(--bg-selected)",color:C?"var(--text-muted)":"var(--text)",fontWeight:C?400:600},children:u("desktop.raw")})]}),L?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{type:"button",onClick:()=>void ea(),disabled:_,title:u("files.saveHint"),"aria-label":u("files.save"),style:{height:20,minWidth:20,padding:"0 5px",display:"inline-flex",alignItems:"center",justifyContent:"center",border:"1px solid var(--border)",borderRadius:4,background:"var(--bg-selected)",color:"var(--text)",cursor:"pointer"},children:(0,r.jsx)(ay.g,{size:13,"aria-hidden":"true"})}),(0,r.jsx)("button",{type:"button",onClick:ei,disabled:_,title:u("files.cancelEdit"),"aria-label":u("files.cancelEdit"),style:{height:20,minWidth:20,padding:"0 5px",display:"inline-flex",alignItems:"center",justifyContent:"center",border:"1px solid var(--border)",borderRadius:4,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer"},children:(0,r.jsx)(h.X,{size:13,"aria-hidden":"true"})})]}):"source"===R&&ew?(0,r.jsx)("button",{type:"button",onClick:en,title:u("files.edit"),"aria-label":u("files.edit"),style:{height:20,minWidth:20,padding:"0 5px",display:"inline-flex",alignItems:"center",justifyContent:"center",border:"1px solid var(--border)",borderRadius:4,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer"},children:(0,r.jsx)(f.I,{size:13,"aria-hidden":"true"})}):null,(i||a)&&!L&&(0,r.jsx)("button",{type:"button",onPointerDown:e=>e.preventDefault(),onClick:()=>{W&&a?ef(W):i?.(ep(e,t),!1)},title:W?u("desktop.mentionSelectedLines",{start:W.startLine,end:W.endLine}):u("desktop.mentionFile"),"aria-label":W?u("desktop.mentionSelectedLines",{start:W.startLine,end:W.endLine}):u("desktop.mentionFile"),style:{height:20,minWidth:20,padding:"0 5px",border:"1px solid var(--border)",borderRadius:4,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer"},children:"@"}),!L&&(0,r.jsx)(aR,{filePath:e,sourceSessionId:o})]}),(0,r.jsx)("div",{ref:N,style:{flex:1,overflow:"auto",background:"var(--bg)"},children:L?(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[G&&(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"5px 12px",borderBottom:"1px solid var(--border)",background:"rgba(214,168,75,0.14)",color:"#d6a84b",fontSize:11,flexShrink:0},children:[(0,r.jsx)("span",{style:{flex:1},children:u("files.externalModified")}),(0,r.jsx)("button",{type:"button",onClick:()=>{(!ee||window.confirm(u("files.reloadOverwriteConfirm")))&&er(e).then(e=>{e&&(O(e.content),U(e.content),J(!1))})},disabled:_,style:{padding:"2px 8px",fontSize:11,border:"1px solid #d6a84b",borderRadius:4,background:"transparent",color:"#d6a84b",cursor:"pointer"},children:u("files.reload")})]}),V&&(0,r.jsx)("div",{style:{padding:"5px 12px",borderBottom:"1px solid var(--border)",background:"rgba(248,113,113,0.14)",color:"#f87171",fontSize:11,flexShrink:0},children:u("files.saveFailed",{error:V})}),(0,r.jsxs)("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[(0,r.jsx)("div",{ref:X,"aria-hidden":"true",style:{...aI,height:"100%",overflow:"hidden",whiteSpace:"pre",pointerEvents:"none"},children:H.split("\n").map((e,t)=>`${t+1}
36
+ ${o}`):s=o;let m=s,f=n?.map(e=>({type:"image",source:{type:"base64",media_type:e.mimeType,data:e.data}})),x={role:"user",content:f?.length?[...o.trim()?[{type:"text",text:o}]:[],...f]:o,timestamp:Date.now()};T(e=>[...e,x]),oo.current=ac(x),ot.current=l,"goal"!==eC.current||a||(eI.current=i,eA(e=>({...e,status:"running",goalText:i,turnsUsed:0,noProgressTurns:0,tokensUsed:0})),eL.current=!0),tq.current=!0,U(!0),e5(a?{kind:"running_command"}:{kind:"waiting_model"}),F({type:"start"}),t2.current=!0,e7(!0),t4.current=!0;let k=n?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType})),v=null,y=!1;try{if(u&&r){let e=t_.current??await t9.current,t=e??await ow();if(t){v=t,ob(1,o),ei&&(eZ(ei),e&&await i6(t,{type:"set_model",provider:ei.provider,modelId:ei.modelId}));let r=await Promise.race([oR(t).then(()=>!0).catch(()=>!1),ai(4e3).then(()=>!1)]);y=!0,await i6(t,{type:"prompt",message:m,...k?.length?{images:k}:{}}),r||oL(t,l),"goal"!==eC.current||a||i6(t,{type:"goal_start",goalText:i}).catch(()=>{})}else throw Error("Unable to create a session for this message")}else if(t){v=t.id;let e=await Promise.race([oR(t.id).then(()=>!0).catch(()=>!1),ai(4e3).then(()=>!1)]);y=!0,await i6(t.id,{type:"prompt",message:m,...k?.length?{images:k}:{}}),e||oL(t.id,l),"goal"!==eC.current||a||i6(t.id,{type:"goal_start",goalText:i}).catch(()=>{})}a&&v&&oL(v,l)}catch(t){if(console.error("Failed to send message:",t),y&&v)return void oL(v,l);if(tK.current=!1,oC(),t instanceof as){let e=oo.current;e&&T(t=>{let o=t[t.length-1];return o?.role==="user"&&ac(o)===e?t.slice(0,-1):t}),oM({type:"error",message:t.message})}else{let o=oo.current;o&&T(e=>{let t=e[e.length-1];return t?.role==="user"&&ac(t)===o?e.slice(0,-1):e}),e.chatInputRef?.current?.replaceMessage?.(x),oM({type:"error",message:`Failed to send message: ${t instanceof Error?t.message:String(t)}`})}oo.current=null,tq.current=!1,U(!1),e5(null),F({type:"end"})}},[u,r,ei,t,ow,oR,ob,oL,oM,oS,oC,oc]),oU=(0,n.useCallback)(async(o,r)=>{if(tq.current||tX.current)return;let n=`${r?"!!":"!"}${o}`;tX.current=!0,K({command:o,excludeFromContext:r}),q(!0);try{let e=t_.current??t?.id??await ow();if(!e)throw Error("Unable to create a session for the shell command");ob(1,n),await i6(e,{type:"bash",command:o,excludeFromContext:r}),await ok(e)}catch(t){console.error("Failed to execute shell command:",t),oM({type:"error",message:t instanceof Error?t.message:String(t)}),e.chatInputRef?.current?.insertIfEmpty(n)}finally{tX.current=!1,K(null),q(!1)}},[oM,ow,ok,e.chatInputRef,ob,t]),o_=(0,n.useCallback)(async()=>{let e=t_.current;if(e)try{await i6(e,{type:tX.current?"abort_bash":"abort"})}catch(e){console.error("Failed to abort:",e)}},[]),oq=(0,n.useCallback)(async e=>{let t=t_.current;if(t){eG(e);try{let{cancelled:o,newSessionId:r}=await i6(t,{type:"fork",entryId:e})??{};!o&&r&&a?.(r)}catch(e){console.error("Fork failed:",e)}finally{eG(null)}}},[a]),oV=(0,n.useCallback)(async e=>{let t=t_.current;t&&(i6(t,{type:"navigate_tree",targetId:e}).catch(()=>{}),S(e),await ov(t,e))},[ov]),oK=(0,n.useCallback)(async e=>{S(e);let t=t_.current;t&&(await ov(t,e),e&&i6(t,{type:"navigate_tree",targetId:e}).catch(()=>{}))},[ov]),oG=(0,n.useCallback)(async(e,t)=>{if(u){let o={provider:e,modelId:t};oa.current=o,ea(o),eZ(o);let r=t_.current??await t9.current;if(!r)return;try{await i6(r,{type:"set_model",provider:e,modelId:t})}catch(e){console.error("Failed to set model:",e)}return}let o=t_.current;if(!o)return;let r=++or.current,n=eJ??g?.context.model??null;eY({provider:e,modelId:t});try{await i6(o,{type:"set_model",provider:e,modelId:t})}catch(o){console.error("Failed to set model:",o),or.current===r&&(eY(n&&(n.provider!==e||n.modelId!==t)?n:null),oM({type:"error",message:o instanceof Error?o.message:String(o)}))}},[oM,eJ,g?.context.model,u,ea]),oJ=(0,n.useCallback)(async()=>{let e=t_.current;if(e&&!eQ){e0(!0),e2(null),e6(null);try{let t=await i6(e,{type:"compact"});e6(ap(t,"manual")),await ok(e,!0)}catch(e){e2(e instanceof Error?e.message:String(e)),e6(null)}finally{e0(!1)}}},[eQ,ok]),oY=(0,n.useCallback)(async e=>{let o=++on.current,n=r??t?.cwd??"",s=n?`/api/models?cwd=${encodeURIComponent(n)}`:"/api/models",i=os.current;i?.abort();let a=new AbortController;os.current=a;let l=()=>a.abort();e?.aborted?a.abort():e?.addEventListener("abort",l,{once:!0});try{let e=await fetch(s,{signal:a.signal});if(!e.ok){let t=`HTTP ${e.status}`;try{let o=await e.json();o?.error&&(t=o.error)}catch{}throw Error(t)}let t=await e.json();if(o!==on.current||h!==oi.current)return;es(null),J(t.models),Q(t.thinkingLevels??{}),et(t.thinkingLevelMaps??{}),er(t.modelScopeWarnings??[]);let r=t.modelList??[];if(X(r),u&&!t_.current){let e=(t.defaultModel?r.find(e=>e.id===t.defaultModel?.modelId&&e.provider===t.defaultModel?.provider):void 0)??r[0];ed(e?{provider:e.provider,modelId:e.id}:null);let o=e?t.thinkingLevelPins?.[`${e.provider}/${e.id}`]:void 0;null===ol.current&&eH(o??"auto")}}catch(e){if(a.signal.aborted||o!==on.current||h!==oi.current)return;es(e instanceof Error?e.message:String(e))}finally{e?.removeEventListener("abort",l),os.current===a&&(os.current=null)}},[u,h,r,t?.cwd]),oX=(0,n.useCallback)(async e=>{if(!e.startsWith("/"))return{handled:!1};let t=e.match(/^\/([^\s]+)(?:\s+([\s\S]*))?$/);if(!t)return{handled:!1};let[,o,r=""]=t,n=r.trim(),s=t_.current??await ow(),i=e=>(e.handled&&(e.error?oM({type:"error",message:e.error}):"openSessionStats"!==e.action&&oM({type:"success",message:e.message??"Command completed"})),e);try{switch(o){case"compact":{if(!s||eQ)return i({handled:!0,error:"No active session to compact"});e0(!0),e2(null),e6(null);let e=await i6(s,{type:"compact",...n?{customInstructions:n}:{}});return e6(ap(e,"manual")),await ok(s,!0)&&ob(),i({handled:!0,message:"Compacted context"})}case"reload":if(!s)return i({handled:!0,error:"No active session to reload"});return await i6(s,{type:"reload"}),await Promise.all([ok(s,!1,!0),oy(s),oj(),oY()]),i({handled:!0,message:"Reloaded session resources"});case"name":if(!s)return i({handled:!0,error:"No active session to name"});if(!n)return i({handled:!0,error:"Usage: /name <name>"});return await i6(s,{type:"set_session_name",name:tM(n)}),await ok(s)&&ob(),i({handled:!0,message:`Session renamed to ${n}`});case"session":{if(!s)return i({handled:!0,error:"No active session"});let e=await i6(s,{type:"get_session_stats"});return e&&ti(e),p?.(),i({handled:!0,action:"openSessionStats"})}case"copy":{if(!s)return i({handled:!0,error:"No active session"});let e=await i6(s,{type:"get_last_assistant_text"}),t=e?.text??"";if(!t)return i({handled:!0,error:"No assistant message to copy"});return await navigator.clipboard.writeText(t),i({handled:!0,message:"Copied last assistant message"})}default:return{handled:!1}}}catch(e){return i({handled:!0,error:e instanceof Error?e.message:String(e)})}finally{"compact"===o&&e0(!1)}},[oM,ow,eQ,oY,ok,oj,oy,ob,p]),oZ=(0,n.useCallback)(async e=>{let t=!1;try{let o=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(o.ok){let e=await o.json(),r=e.state;if(e.running&&r&&(r.isStreaming||r.isPromptRunning||r.isBashRunning||r.isCompacting))return;t=!0}}catch{}t?oF():oL(e)},[oL,oF]),oQ=(0,n.useCallback)(async(e,t)=>{let o=t_.current;if(!o)return;let r=t?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType}));tq.current=!0,U(!0),e5(e=>e??{kind:"waiting_model"});try{await i6(o,{type:"steer",message:e,...r?.length?{images:r}:{}})}catch(e){console.error("Failed to steer:",e),oZ(o)}},[oZ]),o0=(0,n.useCallback)(async(e,t,o)=>{let r=t_.current;if(!r)return;let n=o?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType}));tq.current=!0,U(!0),e5(e=>e??{kind:"waiting_model"});try{await i6(r,{type:"prompt",message:e,streamingBehavior:t,...n?.length?{images:n}:{}})}catch(e){console.error("Failed to queue prompt:",e),oZ(r)}},[oZ]),o1=(0,n.useCallback)(async(e,t)=>{let o=t_.current;if(!o)return;let r=t?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType}));tq.current=!0,U(!0),e5(e=>e??{kind:"waiting_model"});try{await i6(o,{type:"follow_up",message:e,...r?.length?{images:r}:{}})}catch(e){console.error("Failed to follow up:",e),oZ(o)}},[oZ]),o2=(0,n.useCallback)(async()=>{let e=t_.current;if(e)try{await i6(e,{type:"abort_compaction"})}catch(e){console.error("Failed to abort compaction:",e)}},[]),o4=(0,n.useCallback)(async()=>{let t=t_.current;if(t)try{let o=await i6(t,{type:"clear_queue"});tx({steering:[],followUp:[]});let r=[...o?.steering??[],...o?.followUp??[]];r.length>0&&e.chatInputRef?.current?.prependText(r.join("\n\n"))}catch(e){console.error("Failed to recall queued messages:",e),oM({type:"error",message:"Failed to recall queued messages"})}},[e.chatInputRef,oM,tx]);(0,n.useEffect)(()=>{0===tk.length&&tF(!1)},[tk.length]);let o6=(0,n.useCallback)(async(e,t,o=!1)=>{let r=t_.current;if(!r)return tk;try{let n=await i6(r,{type:"resolve_recovery",keep:e,discard:t,continueRun:o}),s=n?.remaining??[];return tE(s),o&&e.length>0&&(async()=>{try{let e=await fetch(`/api/agent/${encodeURIComponent(r)}`);if(!e.ok)return;let t=await e.json(),o=t.state;if(!t.running||!o||!o.isStreaming&&!o.isPromptRunning)return;tV.current=!!o.isStreaming,tK.current=!!o.isPromptRunning,tq.current=!0,U(!0),e5(i9(o)),F({type:"start"}),oT(r),!o.isStreaming&&o.isPromptRunning&&oL(r)}catch{}})(),s}catch(e){return console.error("Failed to resolve queued message recovery:",e),oM({type:"error",message:"Failed to resolve queued message recovery"}),tk}},[tk,oM,oT,oL,tE]),o8=(0,n.useCallback)(async()=>{let e=t_.current;if(!e)return null;try{return await i6(e,{type:"export_queue"})}catch(e){return console.error("Failed to export queue:",e),oM({type:"error",message:"Failed to export queue"}),null}},[oM]),o5=(0,n.useCallback)(async e=>{let t=t_.current;if(!t)return null;try{let o=await i6(t,{type:"import_queue",entries:e});return o&&tx(at(o)),o?.imported??0}catch(e){return console.error("Failed to import queue:",e),oM({type:"error",message:"Failed to import queue"}),null}},[oM,tx]),o3=(0,n.useCallback)(async e=>{let t=t_.current;if(!t)return null;try{let o=await i6(t,{type:"stage_recovery",entries:e});return o?.pendingRecovery&&tE(o.pendingRecovery),(o?.staged??0)>0&&tF(!0),o?.staged??0}catch(e){return console.error("Failed to stage imported queue:",e),oM({type:"error",message:"Failed to stage imported queue"}),null}},[oM,tE]),o7=(0,n.useCallback)(async(e,t,o)=>{let r=t_.current;if(!r)return!1;try{let n=await i6(r,{type:"move_queue",kind:e,fromIndex:t,toIndex:o});return n&&tx(at(n)),!0}catch(e){return console.error("Failed to move queued message:",e),oM({type:"error",message:e instanceof Error?e.message:"Failed to move queued message"}),!1}},[oM,tx]),o9=(0,n.useCallback)(async(e,t)=>{let o=t_.current;if(!o)return null;try{let r=await i6(o,{type:"recall_queue_item",kind:e,index:t});return r&&(void 0!==r.steering||void 0!==r.followUp)&&tx(at(r)),r?.entry?{text:r.entry.text,images:r.entry.images?.map(({data:e,mimeType:t})=>({data:e,mimeType:t}))}:null}catch(e){return console.error("Failed to recall queued message:",e),oM({type:"error",message:e instanceof Error?e.message:"Failed to recall queued message"}),null}},[oM,tx]),re=(0,n.useCallback)(async(e,t,o,r)=>{let n=t_.current;if(!n)return!1;try{let s=await i6(n,{type:"requeue_at",kind:e,index:t,text:o,images:r?.map(({data:e,mimeType:t})=>({type:"image",data:e,mimeType:t}))});return s&&tx(at(s)),!0}catch(e){return console.error("Failed to requeue message:",e),oM({type:"error",message:e instanceof Error?e.message:"Failed to requeue message"}),!1}},[oM,tx]),rt=(0,n.useCallback)(async(e,t)=>{let o=t_.current;if(!o)return!1;try{let r=await i6(o,{type:"remove_queue_item",kind:e,index:t});return r&&tx(at(r)),!0}catch(e){return console.error("Failed to remove queued message:",e),oM({type:"error",message:e instanceof Error?e.message:"Failed to remove queued message"}),!1}},[oM,tx]),ro=(0,n.useCallback)(async e=>{if(ol.current="auto"===e?null:e,eH(e),"auto"===e)return;let t=t_.current??await t9.current;if(t)try{await i6(t,{type:"set_thinking_level",level:e})}catch(e){console.error("Failed to set thinking level:",e)}},[]),rr=(0,n.useCallback)(async e=>{let t=(0,i8.xG)(e);ou(e);let o=t_.current??await t9.current;if(o)try{await i6(o,{type:"set_tools",toolNames:t})}catch(e){console.error("Failed to set tools:",e)}},[ou]),rn=(0,n.useRef)(0),rs=(0,n.useCallback)(async e=>{let t=t_.current??await t9.current,o=++rn.current;if(e){if(eg.current="plan"===ec?"default":ec,eh(!0),em.current=!0,eM.current={sessionKey:"",signature:""},t)try{if(await i6(t,{type:"prompt",message:"/plan"}),rn.current!==o)return}catch(e){if(rn.current!==o)return;console.error("Failed to enter plan mode:",e)}}else if(eh(!1),em.current=!1,eM.current={sessionKey:"",signature:""},t){try{if(await i6(t,{type:"prompt",message:"/plan exit"}),rn.current!==o)return}catch(e){if(rn.current!==o)return;console.error("Failed to exit plan mode:",e)}if(rn.current!==o)return;try{let e=eg.current;await i6(t,{type:"set_tools",toolNames:(0,i8.xG)(e)})}catch(e){console.error("Failed to restore tools after plan exit:",e)}}},[ec]),ri=(0,n.useCallback)(e=>{ex(e);let t=t_.current;if(!t){ek.current=e;return}ek.current=null,fetch(`/api/modes?session=${encodeURIComponent(t)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).catch(e=>{console.error("Failed to persist mode settings:",e)})},[]),ra=(0,n.useCallback)(e=>{if(ri({...eP.current,collaborationMode:tw(e)}),eC.current=tw(e),eM.current={sessionKey:"",signature:""},"goal"!==e){eI.current=null,eL.current=!1,eA(e=>"idle"===e.status?e:{...e,status:"idle",goalText:null});let e=t_.current;e&&i6(e,{type:"goal_stop"}).catch(()=>{})}},[ri]),rl=(0,n.useCallback)(async e=>{ri({...eP.current,tokenMode:tj(e)});let t=t_.current??await t9.current;if(t)try{if("economy"!==e||em.current){if("economy"!==e){let e=em.current?i8.SC:(0,i8.xG)("plan"===ec?"default":ec);await i6(t,{type:"set_tools",toolNames:e})}}else await i6(t,{type:"set_tools",toolNames:[...tC]})}catch(e){console.error("Failed to apply token mode tools:",e)}},[ri,ec]),rd=(0,n.useCallback)(async e=>{ri({...eP.current,toolApprovalMode:tS(e)});let t=t_.current??await t9.current;if(t)try{await i6(t,{type:"set_approval_mode",mode:tS(e)})}catch(e){console.error("Failed to apply approval mode:",e)}},[ri]),rc=(0,n.useCallback)(async e=>{ri({...eP.current,permissionRules:e});let t=t_.current??await t9.current;if(t)try{await i6(t,{type:"set_approval_policy",policy:e})}catch(e){console.error("Failed to apply permission rules:",e)}},[ri]),rp=(0,n.useCallback)(async(e,t,o)=>{let r=t_.current;if(r)try{await i6(r,{type:"resolve_approval",id:e,approve:t,reason:o})}catch(e){console.error("Failed to resolve approval:",e)}finally{eW(t=>t.filter(t=>t.id!==e))}},[]),ru=(0,n.useCallback)(e=>{eI.current=e},[]),rh=(0,n.useCallback)(e=>{let t=e.trim();if(!t)return;eI.current=t,eA(e=>({...e,status:"running",goalText:t,turnsUsed:0,noProgressTurns:0,tokensUsed:0,startedAt:Date.now()}));let o=t_.current;o&&i6(o,{type:"goal_start",goalText:t}).catch(()=>{})},[]),rg=(0,n.useCallback)(()=>{if("running"!==eN.current.status)return;eA(e=>({...e,status:"paused"}));let e=t_.current;e&&i6(e,{type:"goal_pause"}).catch(()=>{})},[]),rm=(0,n.useCallback)(()=>{let e=eN.current;if("paused"!==e.status&&"blocked"!==e.status)return;eA(e=>({...e,status:"running"}));let t=t_.current;t&&i6(t,{type:"goal_resume"}).catch(()=>{})},[]),rf=(0,n.useCallback)(()=>{eL.current=!1,eI.current=null,eA(e=>({...e,status:"idle",goalText:null,turnsUsed:0,noProgressTurns:0}));let e=t_.current;e&&i6(e,{type:"goal_stop"}).catch(()=>{})},[]),rx=(0,n.useCallback)(e=>{let t=e.trim();if(!t)return;eA(e=>({...e,goalText:t}));let o=t_.current;o&&i6(o,{type:"goal_edit",goalText:t}).catch(()=>{})},[]),rk=(0,n.useCallback)(()=>{let e=t7.current,t=t1.current;if(!e||!t)return;let o=t.getBoundingClientRect().top-e.getBoundingClientRect().top+e.scrollTop,r=Math.max(0,e.scrollHeight-e.clientHeight),n=Math.min(Math.max(0,o-16),r);t6.current=n>=r-150,t5.current=Date.now()+700,e.scrollTo({top:n,behavior:"smooth"})},[]),rv=(0,n.useCallback)(e=>{if(e instanceof KeyboardEvent){if(!an.has(e.key)||e.target instanceof Element&&e.target.closest("input, textarea, [contenteditable='true']"))return}else if(e instanceof PointerEvent){let t=t7.current;if(t&&e.target instanceof Element&&!t.contains(e.target))return}t8.current=Date.now()+1200},[]),ry=(0,n.useCallback)(()=>{let e=t7.current;if(e){let{scrollTop:t,clientHeight:o,scrollHeight:r}=e;t6.current=t+o>=r-150}if(Date.now()<t8.current){t4.current=!1;return}Date.now()<t5.current||(t4.current=!1)},[]);(0,n.useEffect)(()=>{if(tJ.current=!0,t){t_.current=t.id;let e=eR.current,o=ez.current;("auto"!==e||o.allow.length||o.ask.length||o.deny.length)&&(i6(t.id,{type:"set_approval_mode",mode:e}).catch(()=>{}),i6(t.id,{type:"set_approval_policy",policy:o}).catch(()=>{}));let r=e=>{!tZ.current&&(tZ.current=!0,e.isBashRunning&&(tX.current=!0,q(!0)),oy(t.id),(e.isStreaming||e.isPromptRunning)&&(tV.current=!!e.isStreaming,tK.current=!!e.isPromptRunning,tq.current=!0,U(!0),e5(i9(e)),F({type:"start"}),oT(t.id),!e.isStreaming&&e.isPromptRunning&&oL(t.id)))};(async()=>{try{let e,o=new AbortController,n=setTimeout(()=>o.abort(),2e4);try{e=await fetch(`/api/sessions/${encodeURIComponent(t.id)}/state`,{signal:o.signal})}finally{clearTimeout(n)}if(!e.ok)throw Error(`HTTP ${e.status}`);let s=await e.json();if(!tJ.current||t_.current!==t.id)return;s.running&&s.state&&r(s.state)}catch{}})(),ok(t.id,!0,!0).then(e=>{e?.running&&e.state&&r(e.state),e?.state&&(void 0!==e.state.isCompacting&&e0(e.state.isCompacting),void 0!==e.state.contextUsage&&e_(e.state.contextUsage??null),void 0!==e.state.systemPrompt&&eV(e.state.systemPrompt??null),void 0!==e.state.thinkingLevel&&eH(e.state.thinkingLevel??"auto"),void 0!==e.state.extensionStatuses&&tu(e.state.extensionStatuses??[]),void 0!==e.state.extensionWidgets&&tg(e.state.extensionWidgets??[]),void 0!==e.state.queuedMessages&&tx(at(e.state.queuedMessages)),void 0!==e.state.pendingRecovery&&tE(e.state.pendingRecovery??[])),e?.running||(async()=>{for(let e=0;e<5;e++){if(e>0&&await new Promise(e=>setTimeout(e,2e3)),!tJ.current||t_.current!==t.id||tq.current)return;try{let e=await fetch(`/api/agent/${encodeURIComponent(t.id)}`);if(!e.ok)continue;let o=await e.json();if(!tJ.current||t_.current!==t.id)return;if(o?.running&&o.state)return void r(o.state)}catch{}}})()})}return()=>{tJ.current=!1,f.current?.abort(),k.current?.abort(),oc(),tN(),oS(),oC()}},[oc]),(0,n.useEffect)(()=>{c?.(eq)},[eq,c]),(0,n.useEffect)(()=>{d&&d(g?.tree??[],j,oK)},[g?.tree,j,oK,d]),(0,n.useEffect)(()=>(window.addEventListener("keydown",rv),window.addEventListener("pointerdown",rv,{passive:!0}),()=>{window.removeEventListener("keydown",rv),window.removeEventListener("pointerdown",rv)}),[rv]),(0,n.useEffect)(()=>{let e=t7.current;if(e)return e.addEventListener("wheel",rv,{passive:!0}),e.addEventListener("touchstart",rv,{passive:!0}),e.addEventListener("scroll",ry,{passive:!0}),()=>{e.removeEventListener("wheel",rv),e.removeEventListener("touchstart",rv),e.removeEventListener("scroll",ry)}},[C.length,v,ry,rv]),(0,n.useEffect)(()=>{C.length>0&&(t2.current?(t0.current=!0,t1.current&&(t2.current=!1,rk())):v||!t0.current?(v||(t0.current=!0),oH("instant")):!tq.current&&(t4.current||t6.current)&&(oH("smooth"),rj(e=>e+1)))},[C.length,v,B,oH,rk]);let rb=(0,n.useRef)(null),[rw,rj]=(0,n.useState)(0),rS=`${t?.id??null}#${rw}`;(0,n.useEffect)(()=>{let e;if(v){rb.current=null;return}if(0===C.length||rb.current===rS)return;rb.current=rS;let t=!1,o=!1,r=-1,n=0,s=Date.now(),i=()=>{if(t||o)return;let a=t7.current;if(a){if(Date.now()<t8.current){let{scrollTop:e,clientHeight:t,scrollHeight:r}=a;if(e+t<r-150){o=!0;return}}if(oH("instant"),a.scrollHeight===r){if((n+=1)>=4||Date.now()-s>=3e4)return}else if(r=a.scrollHeight,n=0,Date.now()-s>=3e4)return;e=window.setTimeout(i,n>0?500:250)}};return e=window.setTimeout(i,250),()=>{t=!0,void 0!==e&&window.clearTimeout(e)}},[v,oH,rS]),(0,n.useEffect)(()=>{let e=new AbortController;return oY(e.signal).catch(e=>{if(e instanceof DOMException&&"AbortError"===e.name)return}),()=>e.abort()},[oY,l]),(0,n.useEffect)(()=>{if(!en)return;let e=()=>{"visible"===document.visibilityState&&oY()};return document.addEventListener("visibilitychange",e),window.addEventListener("online",e),()=>{document.removeEventListener("visibilitychange",e),window.removeEventListener("online",e)}},[en,oY]),(0,n.useEffect)(()=>{if(!e1)return;let e=setTimeout(()=>e2(null),3e3);return()=>clearTimeout(e)},[e1]),(0,n.useEffect)(()=>{if(!e4)return;let e=setTimeout(()=>e6(null),6e3);return()=>clearTimeout(e)},[e4]),(0,n.useEffect)(()=>{if(0===tr.visible.length)return;let e=tr.visible.find(e=>e.exiting);if(e){let t=setTimeout(()=>{tn({type:"remove",id:e.id})},180);return()=>clearTimeout(t)}if(!tr.visible[0])return;let t=setTimeout(()=>{tn({type:"mark_oldest_exiting"})},5e3);return()=>clearTimeout(t)},[tr.visible]),(0,n.useEffect)(()=>{ti(null)},[C.length,eU?.tokens,eU?.percent,eU?.contextWindow]);let rC=g?.tree??[];return{data:g,loading:v,error:b,activeLeafId:j,messages:C,entryIds:R,historyCursor:I,hasEarlierMessages:P,streamState:W,agentRunning:B,bashRunning:_,pendingBash:V,modelNames:G,modelList:Y,modelThinkingLevels:Z,modelThinkingLevelMaps:ee,modelScopeWarnings:eo,modelsError:en,newSessionModel:ei,toolPreset:ec,thinkingLevel:e$,retryInfo:eO,contextUsage:eU,systemPrompt:eq,forkingEntryId:eK,isCompacting:eQ,compactError:e1,compactResult:e4,currentModel:om,displayModel:of,sessionStats:ox,tokenRate:A,planMode:eu,collaborationMode:eb,tokenMode:ew,toolApprovalMode:ej,permissionRules:eS,modeSettings:ef,approvalRequests:eE,handleCollaborationModeChange:ra,handleTokenModeChange:rl,handleToolApprovalModeChange:rd,handlePermissionRulesChange:rc,resolveApproval:rp,setActiveGoalText:ru,goalState:eD,handleGoalStart:rh,handleGoalPause:rg,handleGoalResume:rm,handleGoalStop:rf,handleGoalEdit:rx,slashCommands:e9,slashCommandsLoading:tt,queuedMessages:tm,pendingRecovery:tk,recoveryIsImport:tW,notices:tr.visible,extensionDialog:ta,extensionCustomUi:td,extensionStatuses:tp,extensionWidgets:th,respondToExtensionUi:oz,sendExtensionCustomInput:oI,agentPhase:e8,isNew:u,promptAnchorActive:e3,branchTree:rC,sessionIdRef:t_,eventSourceRef:tL,messagesEndRef:t3,scrollContainerRef:t7,lastUserMsgRef:t1,pendingScrollToUserRef:t2,initialScrollDoneRef:t0,scrollUserMsgToTop:rk,handleSend:oB,executeBash:oU,handleAbort:o_,handleFork:oq,handleNavigate:oV,handleModelChange:oG,handleCompact:oJ,handleSteer:oQ,handleFollowUp:o1,handlePromptWithStreamingBehavior:o0,handleAbortCompaction:o2,handleRecallQueue:o4,resolveRecovery:o6,exportQueueData:o8,importQueueData:o5,stageQueueImport:o3,moveQueuedMessage:o7,recallQueuedMessage:o9,requeueAt:re,removeQueuedMessage:rt,handleBuiltinSlashCommand:oX,handleToolPresetChange:rr,handleThinkingLevelChange:ro,handlePlanModeChange:rs,loadTools:oy,loadSlashCommands:oj,reloadModels:oY,setActiveLeafId:S,setData:m,setMessages:T,loadContext:ov,dispatch:F,setAgentRunning:U,setForkingEntryId:eG,handleLeafChange:oK,handleAgentEventRef:tQ}}({session:e,newSessionCwd:t,onAgentEnd:W,onSessionCreated:i,onSessionForked:l,modelsRefreshKey:d,chatInputRef:c,onBranchDataChange:p,onSystemPromptChange:u,onSessionStatsPanelOpen:g}),[tc,tp]=(0,n.useState)(!1);(0,n.useEffect)(()=>{0===eg.length&&tp(!1)},[eg.length]);let{balance:tu,refresh:th,refreshSoon:tg}=function(){let[e,t]=(0,n.useState)(null),[o,r]=(0,n.useState)(!1),s=(0,n.useRef)(null),i=(0,n.useRef)(null),a=(0,n.useRef)(!0);(0,n.useEffect)(()=>(a.current=!0,()=>{a.current=!1,i.current&&clearTimeout(i.current),s.current?.abort()}),[]);let l=(0,n.useRef)(null),d=(0,n.useCallback)(async()=>{s.current?.abort();let e=new AbortController;s.current=e;try{let o=await fetch("/api/deepseek/balance",{signal:e.signal,cache:"no-store"}),n=await o.json();if(!a.current)return;if(n?.available&&null!=n.totalBalance){let e=l.current;(null===e||e.available!==n.available||e.reason!==n.reason||e.currency!==n.currency||e.totalBalance!==n.totalBalance||e.grantedBalance!==n.grantedBalance||e.toppedUpBalance!==n.toppedUpBalance)&&(l.current=n,t(n)),r(!1)}else null===l.current&&r(!0)}catch{if(!a.current)return;null===l.current&&r(!0)}},[]),c=(0,n.useCallback)(()=>{i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{i.current=null,d()},2e3)},[d]);return{balance:e,failed:o,refresh:d,refreshSoon:c}}(),tm=el?.provider==="deepseek",tf=(0,n.useRef)(null);(0,n.useEffect)(()=>{tm&&th()},[tm,th]),(0,n.useEffect)(()=>{if(tm)for(let e=H.length-1;e>=0;e--){let t=H[e];if("assistant"!==t.role||!t.usage)continue;let o=`${e}:${B[e]??""}`;o!==tf.current&&(tf.current=o,tg());break}},[H,B,tm,tg]);let tx=(0,n.useMemo)(()=>{let e=H.findLast(e=>"assistant"===e.role&&!!e.usage);if(!e?.usage)return null;let t=e.usage;return{model:e.model??"",input:t.input??0,output:t.output??0,cacheRead:t.cacheRead??0,costCNY:r4(e.model)?r6(e.model,t):0,costUSD:r4(e.model)?0:t.cost?.total??0}},[H]),[tk,tP]=(0,n.useState)(!1),[tE,tW]=(0,n.useState)(null),tF=(0,n.useRef)(!1);(0,n.useEffect)(()=>{if(!e6){tF.current=!1;return}if(_){tF.current=!0;return}tF.current&&(tF.current=!1,tW(function(e){for(let t=e.length-1;t>=0;t--){let o=e[t];if("assistant"!==o.role)continue;let r=o.content;if("string"==typeof r&&r.trim())return r;if(Array.isArray(r)){let e=r.filter(e=>"text"===e.type).map(e=>e.text??"").join("\n").trim();if(e)return e}}for(let t=e.length-1;t>=0;t--){let o=e[t];if("toolResult"!==o.role)continue;let r=o.content,n="string"==typeof r?r:Array.isArray(r)?r.map(e=>e.text??"").join("\n"):"";if(!n)continue;let s=n.match(/\*\*Proposed Plan\*\*\s*\n+([\s\S]+)/i);if(s?.[1]?.trim())return s[1].trim()}return null}(H)??null),tP(!0))},[_,e6,H]);let tD=(0,n.useCallback)(()=>{tP(!1);let e=tA.current;"plan"===e5&&e7("normal"),e8(!1).then(()=>{e&&eD(I("tasks.planReviewExecutePrompt",{plan:e}))})},[e8,eD,I,e5,e7]),tA=(0,n.useRef)(null);(0,n.useEffect)(()=>{tA.current=tE},[tE]);let tN=(0,n.useCallback)(e=>{tP(!1),eB(e)},[eB]),tL=(0,n.useCallback)(()=>{tP(!1),"plan"===e5&&e7("normal"),e8(!1)},[e8,e5,e7]);(0,n.useEffect)(()=>{ex&&E.current!==ex.id&&(E.current=ex.id,P.current&&M.current())},[ex]),(0,n.useEffect)(()=>(a=_||q?eN:null,()=>void(a=null)),[_,q,eN]);let[t$,tH]=(0,n.useState)(!1),[tO,tB]=(0,n.useState)(!1),[tU,t_]=(0,n.useState)(!1),tq=(0,n.useCallback)(()=>{let e=eM.current;if(!e)return;let t=e.scrollHeight-e.scrollTop-e.clientHeight;tH(e.scrollTop>1),tB(t>1),t_(t>240)},[eM]),tV=(0,n.useCallback)(()=>{window.requestAnimationFrame(()=>{let e=eM.current,t=eI.current;if(!e||!t)return;let o=Math.max(88,c?.current?.measureHeight?.()??0),r=()=>{if(!e||!t)return;let r=Math.max(0,t.getBoundingClientRect().top-e.getBoundingClientRect().top+e.scrollTop-96-e.clientHeight+o);e.scrollTo({top:r,behavior:"auto"})};r(),tq(),window.setTimeout(r,200)})},[eI,eM,tq,c]);(0,n.useEffect)(()=>{let e=eM.current;if(!e)return;let t=new ResizeObserver(tq);return t.observe(e),e.firstElementChild&&t.observe(e.firstElementChild),e.addEventListener("scroll",tq,{passive:!0}),tq(),()=>{e.removeEventListener("scroll",tq),t.disconnect()}},[H.length,eM,tq]);let tK=(0,n.useRef)(!1);(0,n.useEffect)(()=>{let t=eM.current;if(!t)return;let o=()=>{if(tK.current||!tl||!ta||t.scrollTop>8)return;let o=e?.id;if(!o)return;tK.current=!0;let r=t.scrollHeight-t.scrollTop;td(o,eT,ta).finally(()=>{tK.current=!1,requestAnimationFrame(()=>{let e=t.scrollHeight-r;Math.abs(t.scrollTop-e)>1&&t.scrollTo({top:e,behavior:"auto"})})})};return t.addEventListener("scroll",o,{passive:!0}),()=>t.removeEventListener("scroll",o)},[eM,ta,tl,td,e?.id,eT]);let tG=(0,n.useRef)(!1);(0,n.useEffect)(()=>{if(!tl||!ta)return;let t=eM.current,o=e?.id;if(!t||!o||tK.current||tG.current||L||t.scrollTop>8||t.scrollHeight>t.clientHeight+50)return;tG.current=!0;let r=t.scrollHeight-t.scrollTop;td(o,eT,ta).finally(()=>{tG.current=!1,requestAnimationFrame(()=>{let e=t.scrollHeight-r;Math.abs(t.scrollTop-e)>1&&t.scrollTo({top:e,behavior:"auto"})})})},[eM,ta,tl,td,e?.id,eT,L,H.length]);let tJ=(0,n.useRef)(null),tY=(0,n.useRef)([]),tX=(0,n.useMemo)(()=>({getOffsetForIndex:e=>tJ.current?.getOffsetForIndex(e)?.[0]??0,sizeFor:e=>{let t=tJ.current;if(!t)return 0;let o=t.measurementsCache[e];return o?.size??t.options.estimateSize?.(e)??0},totalHeight:()=>tJ.current?.getTotalSize()??0,refToItemIndex:e=>tY.current[e],itemCount:tY.current.length}),[]),tZ=ed?[ed.sessionId,ed.sessionFile??"",ed.sessionName??"",ed.userMessages,ed.assistantMessages,ed.toolCalls,ed.toolResults,ed.totalMessages,ed.tokens.input,ed.tokens.output,ed.tokens.cacheRead,ed.tokens.cacheWrite,ed.tokens.total,ed.cost??0,ed.totalActiveMs??0].join("|"):null,tQ=(0,n.useRef)(ed);tQ.current=ed,(0,n.useEffect)(()=>{h?.(tQ.current)},[tZ,h]),(0,n.useEffect)(()=>()=>{h?.(null)},[h]);let t0=er?`${er.percent??"null"}|${er.contextWindow}|${er.tokens??"null"}`:null,t2=(0,n.useRef)(er);t2.current=er,(0,n.useEffect)(()=>{m?.(t2.current)},[t0,m]),(0,n.useEffect)(()=>()=>{m?.(null)},[m]);let{isDragOver:t4,handleDragEnter:t6,handleDragOver:t3,handleDragLeave:t7,handleDrop:oe}=function(e){let[t,o]=(0,n.useState)(!1),r=(0,n.useRef)(0),s=(0,n.useCallback)(e=>{e.dataTransfer.files.length&&(e.preventDefault(),r.current+=1,o(!0))},[]),i=(0,n.useCallback)(e=>{e.dataTransfer.files.length&&e.preventDefault()},[]);return{isDragOver:t,handleDragEnter:s,handleDragOver:i,handleDragLeave:(0,n.useCallback)(()=>{r.current-=1,r.current<=0&&(r.current=0,o(!1))},[]),handleDrop:(0,n.useCallback)(t=>{t.preventDefault(),r.current=0,o(!1),e(Array.from(t.dataTransfer.files),t.dataTransfer)},[e])}}((0,n.useCallback)((e,t)=>{if(_){let t=e.filter(e=>e.type.startsWith("image/"));t.length&&c?.current?.addImages(t);return}c?.current?.addFiles(e,t)},[_,c])),or=H.filter(e=>"user"===e.role||"assistant"===e.role),on=(0,n.useMemo)(()=>{let e=new Set,t=[];for(let r=H.length-1;r>=0&&t.length<50;r-=1){var o;let n="user"!==(o=H[r]).role?null:("string"==typeof o.content?o.content:o.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n")).trim()||null;!n||e.has(n)||(e.add(n),t.push(n))}return t},[H]),os=(w=or.length,(j=(0,n.useRef)([])).current=Array(w).fill(null).map((e,t)=>j.current[t]??null),j),oi=eS&&0===H.length&&!U.isStreaming&&!_,oa=e?.cwd??t??void 0,ol=(0,n.useMemo)(()=>(function(e,t,o){let r=new Map;for(let t of e)"toolResult"===t.role&&r.set(t.toolCallId,t);let n=-1;for(let t=e.length-1;t>=0;t--)if("user"===e[t].role){n=t;break}let s=new Map,i=0;e.forEach((e,t)=>{("user"===e.role||"assistant"===e.role)&&s.set(t,i++)});let a=[];for(let n=0;n<e.length;){let s,i=e[n],l="custom"===i.role&&"compaction"===i.customType;if(0===n&&"user"!==i.role&&!l){let o=1;for(;o<e.length&&"user"!==e[o].role;)o+=1;let s=Array.from({length:o},(e,t)=>t).filter(t=>ot(e[t])),i=t5(e,t,s,r);if(i.length>0){a.push({kind:"turn",userIdx:-1,endIdx:o,startsCompactionTurn:!1,finalAssistantIdx:-1,visibleProcessIndices:s,processBlocks:i,finalAnswerMessage:null,writtenFiles:void 0}),n=o;continue}}if("user"!==i.role&&!l){a.push({kind:"single",idx:n}),n+=1;continue}let d=n,c=d+1;for(;c<e.length&&"user"!==e[c].role;)c+=1;let p=function(e,t,o){for(let n=o-1;n>t;n--){var r;if("assistant"===(r=e[n]).role&&t1(r).answerBlocks.some(e=>"image"===e.type||"text"===e.type&&e.text.trim().length>0))return n}for(let r=o-1;r>t;r--)if(e[r]?.role==="assistant")return r;return -1}(e,d,c);if(-1===p){let o=Array.from({length:c-d-1},(e,t)=>d+1+t).filter(t=>ot(e[t])),s=t5(e,t,o,r);a.push({kind:"turn",userIdx:d,endIdx:c,startsCompactionTurn:l,finalAssistantIdx:p,visibleProcessIndices:o,processBlocks:s,finalAnswerMessage:null,writtenFiles:void 0}),n=c;continue}let u=[];for(let e=d+1;e<p;e++)u.push(e);let h=u.filter(t=>ot(e[t])),g=e[p],m=t1(g),f=m.processBlocks.length>0?oo(g,m.processBlocks,{omitUsage:!0}):null,x=m.answerBlocks.length>0?oo(g,m.answerBlocks):null,k=t5(e,t,h,r);if(f&&(k=k.concat(t8(g,{messageIndex:p,entryId:t[p],toolResults:r}).processBlocks)),x){let t=[];for(let o=d+1;o<=p;o++){let r=e[o];if(r?.role==="assistant")for(let e of r.content??[])t.push(e)}s=function(e,t,o){let r=new Set,n=[];for(let s of e){if("toolCall"!==s.type||!function(e){let t,o;return"write"===(t=e.toLowerCase())||t.startsWith("write_")||t.endsWith(".write")||t.endsWith("_write")||"edit"===(o=e.toLowerCase())||o.startsWith("edit_")||o.endsWith(".edit")||o.endsWith("_edit")||o.includes("str_replace")||o.includes("replace_editor")}(s.toolName))continue;let e=t?.get(s.toolCallId);if(!e||e.isError)continue;let i=function(e){if(!e)return null;let t=e.file_path??e.path;return"string"==typeof t&&t.length>0?t:null}(s.input);if(!i)continue;let a=function(e,t){let o;if(!e)return null;let r=/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith("\\\\")||void 0!==t&&(/^[a-zA-Z]:[\\/]/.test(t)||t.startsWith("\\\\")),n=e=>r?e.replace(/\\/g,"/"):e,s=n(e),i=t?n(t).replace(/\/+$/,""):void 0,a=/^[a-zA-Z]:\//.test(s),l=s.startsWith("//");if(a||l)o=s;else if(s.startsWith("/")){let e=i?.match(/^([a-zA-Z]:)(?:\/|$)/)?.[1]??i?.match(/^(\/\/[^/]+\/[^/]+)(?:\/|$)/)?.[1];o=e?`${e}${s}`:s}else{if(!i)return null;o=`${i}/${s}`}return t9(o)}(i,o);a&&(r.has(a)||(r.add(a),n.push({filePath:a})))}return n}(t,r,o)}a.push({kind:"turn",userIdx:d,endIdx:c,startsCompactionTurn:l,finalAssistantIdx:p,visibleProcessIndices:h,processBlocks:k,finalAnswerMessage:x,writtenFiles:s}),n=c}return{toolResultsMap:r,lastUserIdx:n,visibleRefIndexByMessage:s,items:a}})(H,B,oa),[H,B,oa]),od=el?J[`${el.provider}:${el.modelId}`]??null:null,oc=el?Y[`${el.provider}:${el.modelId}`]??null:null,op=(0,n.useCallback)(()=>{Q()},[Q]),ou=(0,n.useCallback)(e=>{e8(e),e&&"plan"!==e5?e7("plan"):e||"plan"!==e5||e7("normal")},[e8,e7,e5]),oh=(0,n.useCallback)(e=>{e7(e),"plan"!==e||e6?"plan"!==e&&e6&&e8(!1):e8(!0)},[e7,e8,e6]),og=e?.relation?.kind==="subagent"?(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",gap:8,padding:"14px 16px",borderTop:"1px solid var(--border)",color:"var(--text-dim)",fontSize:12},children:[(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("rect",{x:"3",y:"11",width:"18",height:"10",rx:"2"}),(0,r.jsx)("circle",{cx:"12",cy:"5",r:"2"}),(0,r.jsx)("path",{d:"M12 7v4"})]}),I("subagent.readOnlyNotice")]}):(0,r.jsx)(iM,{ref:c,onSend:eD,onBash:eA,tasksBoardEnabled:y,onAbort:eN,onSteer:_?eB:void 0,onFollowUp:_?eU:void 0,onPromptWithStreamingBehavior:_?e_:void 0,isStreaming:_,model:el,modelNames:K,modelList:G,modelScopeWarnings:X,modelsError:Z,onRetryModels:op,onModelChange:eH,compactResult:ea,toolPreset:ee,onToolPresetChange:e||eS?e1:void 0,planMode:e6,onPlanModeChange:ou,collaborationMode:e5,toolApprovalMode:e3,onCollaborationModeChange:oh,goalState:tt,onGoalStart:to,onGoalPause:tr,onGoalResume:tn,onGoalStop:ts,thinkingLevel:et,onThinkingLevelChange:e||eS?e2:void 0,availableThinkingLevels:od,thinkingLevelMap:oc,retryInfo:eo,queuedMessages:eh,inputHistory:on,onRecallQueue:eV,onMoveQueue:eY,onRecallOne:eX,onRequeueAt:eZ,onRemoveQueueItem:eQ,slashCommands:ep,slashCommandsLoading:eu,onLoadSlashCommands:e4,onBuiltinCommand:e0,onAudioUnlock:R,draftKey:e?.id??(t?`new:${t}`:void 0),cwd:e?.cwd??t}),om=ey.filter(e=>"belowEditor"!==e.placement),of=ey.filter(e=>"belowEditor"===e.placement),ox=es?I("desktop.compacting"):function(e,t){if(e?.kind==="running_tools"){let o=e.tools.map(e=>e.name);return 0===o.length?t("desktop.runningTool"):t("desktop.runningTools",{tools:o.length<=3?o.join(", "):`${o.slice(0,2).join(", ")} (+${o.length-2})`})}return e?.kind==="waiting_model"?t("desktop.waitingForModel"):e?.kind==="running_command"?t("desktop.runningCommand"):null}(ej,I);return L?(0,r.jsx)("div",{className:"flex h-full items-center justify-center text-text-muted",children:I("desktop.loadingSession")}):$?(0,r.jsx)("div",{className:"flex h-full items-center justify-center text-red-400",children:$}):(0,r.jsxs)("div",{className:"relative flex h-full min-w-0 flex-col overflow-hidden",onDragEnter:t6,onDragOver:t3,onDragLeave:t7,onDrop:oe,children:[t4&&(0,r.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,r.jsx)("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",children:[0,.8,1.6].map(e=>(0,r.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,r.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,r.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,r.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,r.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,r.jsxs)("g",{stroke:"rgba(37,99,235,0.45)",strokeWidth:"1.4",strokeLinecap:"round",children:[(0,r.jsx)("line",{x1:"96",y1:"46",x2:"96",y2:"43"}),(0,r.jsx)("line",{x1:"96",y1:"70",x2:"96",y2:"73"}),(0,r.jsx)("line",{x1:"84",y1:"58",x2:"81",y2:"58"}),(0,r.jsx)("line",{x1:"108",y1:"58",x2:"111",y2:"58"}),(0,r.jsx)("line",{x1:"87.5",y1:"49.5",x2:"85.4",y2:"47.4"}),(0,r.jsx)("line",{x1:"104.5",y1:"66.5",x2:"106.6",y2:"68.6"}),(0,r.jsx)("line",{x1:"104.5",y1:"49.5",x2:"106.6",y2:"47.4"}),(0,r.jsx)("line",{x1:"87.5",y1:"66.5",x2:"85.4",y2:"68.6"})]})]})]}),ex&&(0,r.jsx)(ak,{request:ex,onRespond:eb}),ek&&(0,r.jsx)(av,{request:ek,onInput:ew}),!eS&&eg.length>0&&!tc&&(0,r.jsx)(iW,{items:eg,sessionId:e?.id,onResolve:eK,onExport:eG,onStageImport:eJ,onDismiss:()=>tp(!0),mode:em?"import":"recovery"}),e9.length>0&&(0,r.jsx)(nI,{request:e9[0]??null,queuedCount:Math.max(0,e9.length-1),busy:!1,onResolve:(e,t)=>{let o=e9[0];o&&te(o.id,e,t)}}),oi?(0,r.jsx)("div",{className:"flex flex-1 flex-col items-center justify-center overflow-y-auto",children:(0,r.jsxs)("div",{className:"w-full max-w-[820px]",children:[(0,r.jsx)("div",{style:{display:"flex",justifyContent:"center",marginBottom:28},children:(0,r.jsxs)("svg",{fill:"currentColor",fillRule:"evenodd",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",style:{width:64,height:64,color:"var(--accent)",opacity:.85},"aria-label":"Pi",children:[(0,r.jsx)("title",{children:"Pi"}),(0,r.jsx)("path",{clipRule:"evenodd",d:"M1 1h16.5v11H12v5.5H6.5V23H1V1zm5.5 5.5V12H12V6.5H6.5z"}),(0,r.jsx)("path",{d:"M17.5 12H23v11h-5.5V12z"})]})}),z&&(0,r.jsxs)("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",gap:10,marginBottom:18,marginTop:-14},children:[(0,r.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:["web ",(0,r.jsxs)("span",{style:{color:"var(--text)"},children:["v","0.17.2"]})]}),(0,r.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:["pi ",(0,r.jsxs)("span",{style:{color:"var(--text)"},children:["v","0.85.1"]})]})]}),(0,r.jsx)("div",{style:{padding:"0 34px 6px 7px",paddingRight:z?16:34},children:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12},children:[(0,r.jsx)("div",{ref:x,style:{display:"flex",alignItems:"center",minWidth:0,flex:1,minHeight:48}}),(0,r.jsxs)("div",{style:{display:z?"none":"flex",flexDirection:"column",alignItems:"flex-end",gap:2,flexShrink:0},children:[(0,r.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:["web ",(0,r.jsxs)("span",{style:{color:"var(--text)"},children:["v","0.17.2"]})]}),(0,r.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:["pi ",(0,r.jsxs)("span",{style:{color:"var(--text)"},children:["v","0.85.1"]})]})]})]})}),(0,r.jsx)("div",{style:{padding:"0 16px",paddingRight:z?16:34},children:(0,r.jsx)(ax,{notices:ef,align:"right"})}),"goal"===e5&&(0,r.jsx)(nR,{goalState:tt,onPause:tr,onResume:tn,onStop:ts,onEdit:ti}),og,(0,r.jsx)("div",{style:{padding:"0 16px 6px",paddingRight:z?16:34,marginTop:-15},children:(0,r.jsx)(iK,{onViewFullHistory:k,cwd:oa,systemPrompt:v,sessionStats:ed,contextUsage:er,hasSession:!!e,showChat:!0,showSoundLabel:!0,soundEnabled:S,onSoundToggle:C,onCompact:e?eO:void 0,onAbortCompaction:eq,isCompacting:es,compactError:ei,isDeepSeekOfficial:tm,deepseekBalance:tu,lastTurnUsage:tx})})]})}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"relative flex flex-1 overflow-hidden z-0",children:[(0,r.jsx)("div",{style:{position:"absolute",top:12,left:0,right:18*!z,zIndex:40,padding:"0 16px",pointerEvents:"none"},children:(0,r.jsx)("div",{style:{maxWidth:820,margin:"0 auto"},children:(0,r.jsx)(ax,{notices:ef,floating:!0,align:"right"})})}),(0,r.jsxs)("div",{className:"relative flex-1 min-h-0 min-w-0",children:[(0,r.jsx)("div",{ref:eM,className:"h-full min-w-0 overflow-x-hidden overflow-y-auto pt-4 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:(0,r.jsx)("div",{style:{minWidth:0,padding:"0 16px"},children:(0,r.jsxs)("div",{style:{width:"100%",minWidth:0,maxWidth:820,margin:"0 auto"},children:[(0,r.jsx)(am,{statuses:ev}),(0,r.jsx)(af,{widgets:om}),(()=>{let{toolResultsMap:t,lastUserIdx:o,visibleRefIndexByMessage:n,items:s}=ol,i=(s,i={})=>{let a=i.messageOverride??H[s];if(!a||"toolResult"===a.role)return null;let l="user"===a.role&&s>0&&"assistant"===H[s-1].role?B[s-1]:void 0,d="user"===a.role||"assistant"===a.role,c=n.get(s),p=i.keyPrefix??"message",u=!1;if("assistant"===a.role){u=!0;for(let e=s+1;e<H.length;e++){let t=H[e].role;if("user"===t)break;if("assistant"===t){u=!1;break}}u&&U.isStreaming&&s===H.length-1&&(u=!1)}void 0!==i.showTimestamp&&(u=i.showTimestamp);let h=(0,r.jsx)(ne,{message:a,toolResults:t,modelNames:K,cwd:oa,onOpenFile:f,entryId:B[s],onFork:_||eS||0===s&&"user"===a.role?void 0:eL,forking:en===B[s],onNavigate:_?void 0:e$,prevAssistantEntryId:_?void 0:l,onEditContent:F,onQuoteReply:D,onOpenSession:b,onCreateTask:N,showTimestamp:u,prevTimestamp:s>0?H[s-1].timestamp:void 0,sessionId:e?.id??ez.current??void 0,writtenFiles:i.writtenFiles},`${p}-view-${s}`);return d&&!1!==i.attachRef&&void 0!==c?(0,r.jsx)("div",{ref:e=>{os.current[c]=e,s===o&&(eP.current=e,e&&eE.current&&(eE.current=!1,eW.current=!0,eF()))},children:h},`${p}-${s}`):h},a=[],l=[],d=[],c=0,p=(e,t,o)=>{null!==e&&(a.push(e),l.push(t),d.push(o))},u=(e,t)=>B[e]||`${t}-${e}`;for(let a of s){if("single"===a.kind){if(H[a.idx]?.role==="toolResult")continue;p(i(a.idx),n.get(a.idx),u(a.idx,"single"));continue}let{userIdx:s,endIdx:l,startsCompactionTurn:d,finalAssistantIdx:h}=a;if((_||U.isStreaming)&&l===H.length&&(s===o||d)){s>=0&&p(i(s),n.get(s),u(s,"user"));let o=U.streamingMessage?.role==="assistant",a=[],d=!o&&h>=0?h:l;for(let e=s+1;e<d;e++)ot(H[e])&&a.push(e);let c=t5(H,B,a,t),g=null;if(!o&&h>=0){let e=H[h],o=t1(e,{isStreaming:!0}),r=t8(e,{messageIndex:h,entryId:B[h],toolResults:t,isStreaming:!0});c=c.concat(r.processBlocks),o.answerBlocks.length>0&&(g=oo(e,o.answerBlocks,{omitUsage:!0}))}if(o){let e=U.streamingMessage,o=t1(e,{isStreaming:!0}),r=t8(e,{messageIndex:H.length,toolResults:t,isStreaming:!0});c=c.concat(r.processBlocks),o.answerBlocks.length>0&&(g=oo(e,o.answerBlocks,{omitUsage:!0}))}if(c.length>0){let t=a.map(e=>n.get(e)).find(e=>"number"==typeof e);p((0,r.jsx)("div",{ref:void 0===t?void 0:e=>{os.current[t]=e},children:(0,r.jsx)(su,{blocks:c,isStreaming:_||U.isStreaming,cwd:oa,onOpenFile:f,sessionId:e?.id??ez.current??void 0,tokenRate:ec})},`live-process-group-${s}`),t,`live-process-${s}-${a[0]??"none"}`)}g&&p((0,r.jsx)(ne,{message:g,isStreaming:!0,modelNames:K,cwd:oa,onOpenFile:f,onQuoteReply:D,onOpenSession:b},`live-answer-${s}`),h>=0?n.get(h):void 0,h>=0?`live-answer-${u(h,"answer")}`:`live-answer-streaming-${s}`);continue}if(-1===h&&0===a.processBlocks.length){if(s>=0)for(let e=s;e<l;e++)p(i(e),n.get(e),u(e,"raw"));continue}s>=0&&p(i(s),n.get(s),u(s,"user"));let{processBlocks:g,finalAnswerMessage:m,writtenFiles:x,visibleProcessIndices:k}=a;if(g.length>0){let t=k.map(e=>n.get(e)).find(e=>"number"==typeof e)??(m?void 0:n.get(h));k[0],p((0,r.jsx)("div",{ref:void 0===t?void 0:e=>{os.current[t]=e},children:(0,r.jsx)(su,{blocks:g,isStreaming:!1,defaultExpanded:!1,onAutoExpanded:void 0,cwd:oa,onOpenFile:f,sessionId:e?.id??ez.current??void 0})},`process-group-${s}-${h}`),t,`process-${s>=0?u(s,"user"):`orphan-${c++}`}`)}if(m&&p(i(h,{messageOverride:m,writtenFiles:x}),n.get(h),u(h,"answer")),h>=0)for(let e=h+1;e<l;e++)p(i(e),n.get(e),u(e,"tail"))}let h=[],g=l.map((e,t)=>({startRef:e,itemIdx:t})).filter(e=>void 0!==e.startRef);return g.forEach((e,t)=>{let o=g[t+1]?.startRef??or.length;for(let t=e.startRef;t<o;t++)h[t]=e.itemIdx}),tY.current=h,(0,r.jsx)(iJ,{scrollElementRef:eM,items:a,itemKeys:d,virtualizerRef:tJ})})(),ox&&(es||_&&!U.streamingMessage)&&(0,r.jsx)("div",{className:"py-2 text-[13px] text-text-muted",children:(0,r.jsxs)("span",{className:"animate-[pulse_1.5s_infinite]",children:[ox,ej?.kind==="waiting_model"&&(0,r.jsx)("span",{style:{display:"inline-block",width:12,height:12,marginLeft:6,verticalAlign:"-2px",border:"1.5px solid var(--text-muted)",borderTopColor:"transparent",borderRadius:"50%",animation:"spin 0.6s linear infinite"}})]})}),V&&(0,r.jsx)(ne,{message:{role:"bashExecution",command:V.command,output:"",excludeFromContext:V.excludeFromContext},sessionId:e?.id??ez.current??void 0}),q&&!V&&(0,r.jsx)("div",{className:"py-2 text-[13px] text-text-muted",children:(0,r.jsx)("span",{className:"animate-[pulse_1.5s_infinite]",children:I("desktop.runningShellCommand")})}),(0,r.jsx)("div",{style:{height:96}}),(0,r.jsx)("div",{ref:eI}),(0,r.jsx)(nb,{open:tk,planText:tE,busy:_,onExecute:tD,onFeedback:tN,onExit:tL,onClose:()=>tP(!1)})]})})}),t$&&(0,r.jsx)("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 top-0 z-10 h-8 bg-gradient-to-b from-[var(--bg)] to-transparent"}),tO&&(0,r.jsx)("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 bottom-0 z-10 h-8 bg-gradient-to-t from-[var(--bg)] to-transparent"}),tU&&(0,r.jsxs)("button",{type:"button",onClick:()=>tV(),title:I("desktop.scrollToBottom"),"aria-label":I("desktop.scrollToBottom"),style:{position:"absolute",bottom:14,right:18,zIndex:20,display:"flex",alignItems:"center",gap:6,padding:"5px 10px",border:"1px solid var(--border)",borderRadius:999,background:"color-mix(in srgb, var(--bg-panel) 92%, transparent)",color:"var(--text-muted)",fontSize:11,fontWeight:600,cursor:"pointer",boxShadow:"0 4px 14px rgba(0,0,0,0.14)",backdropFilter:"blur(4px)",transition:"color 0.12s, border-color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:[(0,r.jsx)(rJ.Z,{size:12,weight:"bold","aria-hidden":"true"}),I("desktop.scrollToBottom")]})]}),z?null:(0,r.jsx)(iZ,{messages:H,streamingMessage:U.streamingMessage,scrollContainer:eM,messageRefs:os,virtualizer:tX})]}),(0,r.jsxs)("div",{className:"relative z-10",children:[(0,r.jsx)("div",{style:{padding:"0 16px",paddingRight:z?16:34},children:(0,r.jsx)("div",{style:{maxWidth:820,margin:"0 auto"},children:(0,r.jsx)(af,{widgets:of})})}),og,(0,r.jsx)("div",{className:`session-info-bar-wrap${z?" is-mobile":""}`,children:(0,r.jsx)("div",{className:"session-info-bar-inner",children:(0,r.jsx)(iK,{onViewFullHistory:k,cwd:oa,systemPrompt:v,sessionStats:ed,contextUsage:er,hasSession:!!e,showChat:!0,soundEnabled:S,onSoundToggle:C,onCompact:e?eO:void 0,onAbortCompaction:eq,isCompacting:es,compactError:ei,branchTree:eC,branchActiveLeafId:eT,onBranchLeafChange:eR,isDeepSeekOfficial:tm,deepseekBalance:tu,lastTurnUsage:tx})})})]})]})]})}function am({statuses:e}){return 0===e.length?null:(0,r.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginBottom:10},children:e.map(e=>(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,maxWidth:"100%",padding:"4px 8px",border:"1px solid color-mix(in srgb, var(--accent) 24%, var(--border))",borderRadius:6,background:"color-mix(in srgb, var(--accent) 7%, var(--bg))",color:"var(--text-muted)",fontSize:12},children:[(0,r.jsx)("span",{style:{color:"var(--accent)",fontFamily:"var(--font-mono)",fontSize:11},children:e.key}),(0,r.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.text})]},e.key))})}function af({widgets:e}){return 0===e.length?null:(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8,marginBottom:10},children:e.map(e=>(0,r.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-panel)",overflow:"hidden"},children:[(0,r.jsx)("div",{style:{padding:"5px 9px",borderBottom:"1px solid var(--border)",color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)"},children:e.key}),(0,r.jsx)("pre",{style:{margin:0,padding:"8px 9px",color:"var(--text-muted)",fontSize:12,lineHeight:1.5,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"var(--font-mono)"},children:e.lines.join("\n")})]},e.key))})}function ax({notices:e,floating:t=!1,align:o="left"}){return 0===e.length?null:(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",alignItems:"right"===o?"flex-end":"stretch",marginBottom:10*!t},children:e.map((o,n)=>{let s="error"===o.type?"#ef4444":"warning"===o.type?"#d97706":"success"===o.type?"#10b981":"var(--accent)";return(0,r.jsxs)("div",{className:"notice-shelf-item",style:{display:"flex",alignItems:"center",gap:10,minHeight:44,maxHeight:180,marginBottom:6*(n!==e.length-1),overflowY:"auto",overflowX:"hidden",borderRadius:14,border:"1px solid color-mix(in srgb, var(--border) 70%, transparent)",background:"var(--bg)",color:"var(--text-muted)",width:"fit-content",maxWidth:"min(100%, 620px)",boxShadow:t?"0 1px 2px rgba(15,23,42,0.05), 0 10px 28px -14px rgba(15,23,42,0.24)":"0 1px 2px rgba(15,23,42,0.04), 0 8px 24px -12px rgba(15,23,42,0.10)",fontSize:13,lineHeight:1.45,transformOrigin:"top center",animation:o.exiting?"notice-shelf-out 0.18s ease-in forwards":"notice-shelf-in 0.18s ease-out both",padding:"0 12px"},children:[(0,r.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:s,flexShrink:0}}),(0,r.jsx)("span",{style:{padding:"10px 0",minWidth:0,maxWidth:"100%",overflowWrap:"anywhere",whiteSpace:"pre-wrap"},children:o.message})]},o.id)})})}function ak({request:e,onRespond:t}){let{t:o}=(0,A.s)(),[s,i]=(0,n.useState)("editor"===e.method?e.prefill??"":"");(0,n.useEffect)(()=>{i("editor"===e.method?e.prefill??"":"")},[e]);let a=()=>{"confirm"===e.method?t(e,{confirmed:!0}):t(e,{value:s})};return(0,r.jsx)("div",{style:{position:"absolute",inset:0,zIndex:90,display:"flex",alignItems:"center",justifyContent:"center",padding:20,background:"rgba(0,0,0,0.18)"},children:(0,r.jsxs)("div",{role:"dialog","aria-modal":"true",style:{width:"min(560px, 100%)",border:"1px solid var(--border)",borderRadius:8,background:"var(--bg)",boxShadow:"0 20px 60px rgba(0,0,0,0.28)",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{padding:"12px 14px",borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)("div",{style:{color:"var(--text)",fontSize:14,fontWeight:650},children:e.title}),(0,r.jsx)("div",{style:{marginTop:3,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)"},children:o("desktop.extensionRequest")})]}),(0,r.jsxs)("div",{style:{padding:14},children:["confirm"===e.method&&(0,r.jsx)("div",{style:{color:"var(--text-muted)",fontSize:13,lineHeight:1.6,whiteSpace:"pre-wrap"},children:e.message}),"select"===e.method&&(0,r.jsx)("div",{style:{display:"grid",gap:8},children:e.options.map(o=>(0,r.jsx)("button",{onClick:()=>t(e,{value:o}),style:{width:"100%",padding:"9px 10px",borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",cursor:"pointer",textAlign:"left",fontSize:13},children:o},o))}),"input"===e.method&&(0,r.jsx)("input",{autoFocus:!0,value:s,placeholder:e.placeholder,onChange:e=>i(e.target.value),onKeyDown:o=>{"Enter"===o.key&&a(),"Escape"===o.key&&t(e,{cancelled:!0})},style:{width:"100%",padding:"9px 10px",borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",outline:"none",fontSize:13}}),"editor"===e.method&&(0,r.jsx)("textarea",{autoFocus:!0,value:s,onChange:e=>i(e.target.value),onKeyDown:o=>{"Escape"===o.key&&t(e,{cancelled:!0}),(o.metaKey||o.ctrlKey)&&"Enter"===o.key&&a()},style:{width:"100%",minHeight:220,padding:10,borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",outline:"none",resize:"vertical",fontSize:13,lineHeight:1.55,fontFamily:"var(--font-mono)"}})]}),(0,r.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,padding:"10px 14px",borderTop:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,r.jsx)("button",{onClick:()=>t(e,{cancelled:!0}),style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text-muted)",cursor:"pointer"},children:o("desktop.cancel")}),"confirm"===e.method?(0,r.jsx)("button",{onClick:a,style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--accent)",background:"var(--accent)",color:"#fff",cursor:"pointer"},children:o("desktop.confirm")}):"select"!==e.method?(0,r.jsx)("button",{onClick:a,style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--accent)",background:"var(--accent)",color:"#fff",cursor:"pointer"},children:o("desktop.submit")}):null]})]})})}function av({request:e,onInput:t}){let{t:o}=(0,A.s)(),s=(0,n.useRef)(null),i=function(e){let t=/^[┌├└╭╰][─┬┴┼]+[┐┤┘╮╯]$/,o=[];for(let r of e){let e=tJ(r).trimEnd();if(t.test(e))continue;let n=r,s=tZ(n);("│"===s||"┃"===s)&&" "===tZ(n=tX(n,0))&&(n=tX(n,0));let i=function(e){let t=tY(e);for(let e=t.length-1;e>=0;e--)if(""!==t[e].char.trim())return e;return -1}(n),a=i>=0?tY(n)[i]?.char:void 0;("│"===a||"┃"===a)&&(n=tX(n,i)),o.push(function(e){let t=e;for(;;){let e=tY(t),o=e[e.length-1];if(!o||""!==o.char.trim())return t;t=t.slice(0,o.start)+t.slice(o.end)}}(n))}for(;o.length>0&&""===tJ(o[0]).trim();)o.shift();for(;o.length>0&&""===tJ(o[o.length-1]).trim();)o.pop();return o.length?o:e}(e.lines);return(0,n.useEffect)(()=>{s.current?.focus()},[e.id]),(0,r.jsx)("div",{style:{position:"absolute",inset:0,zIndex:95,display:"flex",alignItems:"center",justifyContent:"center",padding:20,background:"rgba(0,0,0,0.18)"},children:(0,r.jsxs)("div",{ref:s,tabIndex:0,role:"dialog","aria-modal":"true",onKeyDown:o=>{let r=function(e){if(e.ctrlKey&&!e.metaKey&&!e.altKey&&1===e.key.length){let t=e.key.toLowerCase();if(t>="a"&&t<="z")return String.fromCharCode(t.charCodeAt(0)-96)}switch(e.key){case"ArrowUp":return"\x1b[A";case"ArrowDown":return"\x1b[B";case"ArrowRight":return"\x1b[C";case"ArrowLeft":return"\x1b[D";case"Enter":return"\r";case"Escape":return"\x1b";case"Backspace":return"";case"Tab":return" ";case" ":return" ";default:if(!e.ctrlKey&&!e.metaKey&&!e.altKey&&1===e.key.length)return e.key;return null}}(o);r&&(o.preventDefault(),o.stopPropagation(),t(e,r))},style:{width:"min(920px, 100%)",maxHeight:"min(760px, calc(100vh - 40px))",border:"1px solid var(--border)",borderRadius:8,background:"var(--bg)",boxShadow:"0 20px 60px rgba(0,0,0,0.28)",overflow:"hidden",outline:"none"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:"10px 12px",borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)("div",{style:{color:"var(--text)",fontSize:13,fontWeight:650},children:o("desktop.extensionPanel")}),(0,r.jsx)("button",{onClick:()=>t(e,"\x03"),style:{padding:"5px 9px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:o("desktop.close")})]}),(0,r.jsx)("pre",{style:{margin:0,padding:14,maxHeight:"calc(min(760px, 100vh - 40px) - 48px)",overflow:"auto",background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:13,lineHeight:1.45,whiteSpace:"pre"},children:(i.length?i:[""]).map((e,t,o)=>{var s;return(0,r.jsxs)(n.Fragment,{children:[(s=`line-${t}`,(function(e){let t,o=[],r={},n=0;for(tV.lastIndex=0;null!==(t=tV.exec(e));)t.index>n&&o.push({text:e.slice(n,t.index),style:r}),r=function(e,t){let o={...e};for(let e=0;e<t.length;e++){let r=t[e];if(0===r)for(let e of Object.keys(o))delete o[e];else if(1===r)o.fontWeight=700;else if(2===r)o.opacity=.65;else if(3===r)o.fontStyle="italic";else if(4===r)o.textDecoration="underline";else if(22===r)delete o.fontWeight,delete o.opacity;else if(23===r)delete o.fontStyle;else if(24===r)delete o.textDecoration;else if(39===r)delete o.color;else if(49===r)delete o.backgroundColor;else if(r>=30&&r<=37)o.color=tK[r-30];else if(r>=90&&r<=97)o.color=tG[r-90];else if(r>=40&&r<=47)o.backgroundColor=tK[r-40];else if(r>=100&&r<=107)o.backgroundColor=tG[r-100];else if((38===r||48===r)&&2===t[e+1]){let[n,s,i]=[t[e+2],t[e+3],t[e+4]];[n,s,i].every(e=>"number"==typeof e&&Number.isFinite(e))&&(38===r?o.color=`rgb(${n}, ${s}, ${i})`:o.backgroundColor=`rgb(${n}, ${s}, ${i})`),e+=4}else if((38===r||48===r)&&5===t[e+1]){let n=function(e){if(e>=0&&e<8)return tK[e];if(e>=8&&e<16)return tG[e-8];if(e>=16&&e<=231){let t=e-16,o=Math.floor(t/36),r=Math.floor(t%36/6),n=e=>0===e?0:55+40*e;return`rgb(${n(o)}, ${n(r)}, ${n(t%6)})`}if(e>=232&&e<=255){let t=8+(e-232)*10;return`rgb(${t}, ${t}, ${t})`}}(t[e+2]);n&&(38===r?o.color=n:o.backgroundColor=n),e+=2}}return o}(r,t[1]?t[1].split(";").map(e=>Number(e||"0")):[0]),n=t.index+t[0].length;return n<e.length&&o.push({text:e.slice(n),style:r}),o})(e).map((e,t)=>Object.keys(e.style).length>0?(0,r.jsx)("span",{style:e.style,children:e.text},`${s}-${t}`):e.text)),t<o.length-1?"\n":null]},t)})})]})})}var ay=o(93549);let ab={png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml",bmp:"image/bmp",ico:"image/x-icon",avif:"image/avif"},aw={mp3:"audio/mpeg",wav:"audio/wav",ogg:"audio/ogg",oga:"audio/ogg",opus:"audio/ogg",m4a:"audio/mp4",aac:"audio/aac",flac:"audio/flac",weba:"audio/webm"};function aj(e){return(e.replace(/\\/g,"/").split("/").pop()??"").toLowerCase().split(".").pop()??""}function aS(e){let t=e.nodeType===Node.ELEMENT_NODE?e:e.parentElement;return t?.closest(".file-source-line[data-line-number]")??null}function aC(e,t){if(!t||t.isCollapsed||0===t.rangeCount)return null;let o=t.getRangeAt(0);if(!e.contains(o.startContainer)||!e.contains(o.endContainer))return null;let r=Number(aS(o.startContainer)?.dataset.lineNumber),n=Number(aS(o.endContainer)?.dataset.lineNumber);return Number.isInteger(r)&&Number.isInteger(n)?r<=n?{startLine:r,endLine:n}:{startLine:n,endLine:r}:null}function aT(e,t,o,r={}){let n=ed(e),s=new URLSearchParams({type:t});for(let[e,t]of(o&&s.set("sessionId",o),Object.entries(r)))void 0!==t&&s.set(e,String(t));return`/api/files/${n}?${s.toString()}`}function aR({filePath:e,sourceSessionId:t}){let{t:o}=(0,A.s)();return(0,r.jsx)("a",{href:aT(e,"download",t),download:ec(e),title:o("desktop.downloadFile"),style:{display:"flex",alignItems:"center",justifyContent:"center",height:20,padding:"0 5px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:4,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,textDecoration:"none"},children:(0,r.jsx)(E.z,{size:11,"aria-hidden":"true"})})}let az={fontFamily:"var(--font-mono)",fontSize:13,lineHeight:1.6,tabSize:2},aI={fontFamily:"var(--font-mono)",fontSize:13,lineHeight:1.6,padding:"12px 0 12px 16px",color:"var(--text-dim)",textAlign:"right",userSelect:"none"};async function aM(e,t){let o=await fetch(`/api/files/${ed(e)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t})});if(!o.ok)throw Error((await o.json().catch(()=>({}))).error??`HTTP ${o.status}`);let r=await o.json();return"number"==typeof r.size?r.size:0}let aP={delete:"3px solid var(--git-status-deleted)",add:"3px solid var(--git-status-added)",edit:"3px solid var(--git-status-modified)"},aE="var(--git-status-deleted-bg)",aW="var(--git-status-added-bg)",aF="var(--git-status-added)";function aD(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function aA({oldContent:e,newContent:t}){let{t:o}=(0,A.s)(),n=function(e,t){let o=e.length,r=t.length,n=o+r,s=Array(2*n+1).fill(0),i=[];for(let a=0;a<=n;a++){i.push([...s]);for(let l=-a;l<=a;l+=2){let d,c=(d=l===-a||l!==a&&s[l-1+n]<s[l+1+n]?s[l+1+n]:s[l-1+n]+1)-l;for(;d<o&&c<r&&e[d]===t[c];)d++,c++;if(s[l+n]=d,d>=o&&c>=r){let s=[],l=o,d=r;for(let o=a;o>0;o--){let r,a=i[o-1],c=l-d;r=c===-o||c!==o&&a[c-1+n]<a[c+1+n]?c+1:c-1;let p=a[r+n],u=p-r;for(;l>p&&d>u;)l--,d--,s.unshift({type:"unchanged",text:e[l]});o>0&&(l>p?(l--,s.unshift({type:"removed",text:e[l]})):(d--,s.unshift({type:"added",text:t[d]})))}for(;l>0&&d>0;)l--,d--,s.unshift({type:"unchanged",text:e[l]});return s}}}return[...e.map(e=>({type:"removed",text:e})),...t.map(e=>({type:"added",text:e}))]}(e.split("\n"),t.split("\n"));if(!n.some(e=>"unchanged"!==e.type))return(0,r.jsx)("div",{style:{padding:"12px 16px",fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:o("desktop.noChanges")});let s=new Set(n.flatMap((e,t)=>"unchanged"!==e.type?[t]:[])),i=new Set;for(let e of s)for(let t=Math.max(0,e-3);t<=Math.min(n.length-1,e+3);t++)i.add(t);let a=[],l=0;for(;l<n.length;)if(i.has(l)){let e=[];for(;l<n.length&&i.has(l);)e.push(n[l]),l++;a.push({hidden:!1,lines:e})}else{let e=0;for(;l<n.length&&!i.has(l);)e++,l++;a.push({hidden:!0,count:e})}let d=[],c=1;for(let e of n)"removed"===e.type?d.push(0):d.push(c++);let p=0;return(0,r.jsx)("div",{style:{fontFamily:"var(--font-mono)",fontSize:13,lineHeight:1.6,minWidth:"max-content"},children:a.map((e,t)=>{if(e.hidden){let n=(0,r.jsx)("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:o("desktop.unchangedLines",{count:e.count})},t);return p+=e.count,n}let n=[],s=[],i=[],a=()=>{if(s.length||i.length){let e=s.length&&i.length?"edit":s.length?"delete":"add";for(let t of s)n.push({key:t.key,kind:"removed",text:t.text,lineNo:null,block:e});for(let t of i)n.push({key:t.key,kind:"added",text:t.text,lineNo:t.lineNo,block:e});s=[],i=[]}};e.lines.forEach((e,o)=>{"unchanged"===e.type?(a(),n.push({key:`${t}:${o}`,kind:"context",text:e.text,lineNo:d[p+o],block:null})):"removed"===e.type?s.push({key:`${t}:${o}`,text:e.text}):i.push({key:`${t}:${o}`,text:e.text,lineNo:d[p+o]})}),a();let l=n.map(e=>{let t="removed"===e.kind?aE:"added"===e.kind?aW:"transparent",o=e.block?aP[e.block]:"3px solid transparent",n="added"===e.kind?aF:"var(--text-dim)";return(0,r.jsxs)("div",{style:{display:"flex",background:t,borderLeft:o},children:[(0,r.jsx)("span",{style:{minWidth:44,padding:"0 8px 0 16px",textAlign:"right",color:n,userSelect:"none",fontSize:11,lineHeight:1.6,flexShrink:0},children:e.lineNo??""}),(0,r.jsx)("span",{style:{flex:1,minWidth:0,padding:"0 8px 0 0",whiteSpace:"pre",color:"var(--text)"},children:e.text||"\xa0"})]},e.key)});return p+=e.lines.length,(0,r.jsx)("div",{children:l},t)})})}function aN({patch:e}){let t=rU(e);if(!t)return null;let o=[],n=[],s=[],i=()=>{if(n.length||s.length){let e=n.length&&s.length?"edit":n.length?"delete":"add";for(let t of n)o.push({key:t.key,kind:"removed",text:t.text,lineNo:null,block:e});for(let t of s)o.push({key:t.key,kind:"added",text:t.text,lineNo:t.lineNo,block:e});n=[],s=[]}};return t.forEach((e,t)=>{e.rows.forEach((e,r)=>{if("hunk"===e.type){i(),o.push({key:`${t}:${r}:h`,kind:"hunk",text:e.text,lineNo:null,block:null});return}let{left:a,right:l}=e;if("context"===a.type&&"context"===l.type){i(),o.push({key:`${t}:${r}:c`,kind:"context",text:a.text,lineNo:l.lineNo,block:null});return}"removed"===a.type&&n.push({key:`${t}:${r}:l`,text:a.text}),"added"===l.type&&s.push({key:`${t}:${r}:r`,text:l.text,lineNo:l.lineNo})})}),i(),(0,r.jsx)("div",{style:{fontFamily:"var(--font-mono)",fontSize:12,lineHeight:1.55,minWidth:"max-content"},children:o.map(e=>{if("hunk"===e.kind)return(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{style:{height:"1.55em"}}),(0,r.jsx)("div",{style:{padding:"3px 12px",color:"var(--accent-blue)",background:"var(--bg-secondary)"},children:e.text}),(0,r.jsx)("div",{style:{height:"1.55em"}})]},e.key);let t="removed"===e.kind?aE:"added"===e.kind?aW:"transparent",o=e.block?aP[e.block]:"3px solid transparent",n="added"===e.kind?aF:"var(--text-dim)";return(0,r.jsxs)("div",{style:{display:"flex",background:t,borderLeft:o},children:[(0,r.jsx)("span",{style:{width:44,flexShrink:0,padding:"0 8px 0 16px",textAlign:"right",color:n,userSelect:"none",fontSize:11},children:e.lineNo??""}),(0,r.jsx)("span",{style:{flex:1,minWidth:0,padding:"0 8px 0 0",whiteSpace:"pre",color:"var(--text)"},children:e.text||"\xa0"})]},e.key)})})}function aL({filePath:e,cwd:t,sourceSessionId:o}){let{t:s}=(0,A.s)(),[i,a]=(0,n.useState)(0),[l,d]=(0,n.useState)(null),[c,p]=(0,n.useState)(null),[u,h]=(0,n.useState)(null),g=(0,n.useRef)(null),m=ec(e).toLowerCase().split(".").pop()??"";(0,n.useEffect)(()=>{a(0),d(null),p(null),h(null),g.current&&(g.current.close(),g.current=null);let t=new EventSource(aT(e,"watch",o));return g.current=t,t.addEventListener("change",e=>{try{let t=JSON.parse(e.data);"number"==typeof t.size&&d(t.size)}catch{}a(e=>e+1)}),()=>{t.close(),g.current=null}},[e,o]);let f=aT(e,"read",o,i?{v:i}:void 0),x=null!=l?aD(l):null;return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,r.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,r.jsx)("span",{style:{fontFamily:"var(--font-mono)"},title:e,children:ep(e,t)}),(0,r.jsx)("span",{style:{marginLeft:"auto"},children:m||s("desktop.image")}),c&&(0,r.jsxs)("span",{children:[c.w," \xd7 ",c.h]}),x&&(0,r.jsx)("span",{children:x}),(0,r.jsx)(aR,{filePath:e,sourceSessionId:o})]}),(0,r.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:u?(0,r.jsx)("div",{style:{color:"#f87171",fontSize:13},children:u}):(0,r.jsx)("img",{src:f,alt:e,onLoad:e=>{let t=e.currentTarget;p({w:t.naturalWidth,h:t.naturalHeight})},onError:()=>h(s("desktop.failedToLoadImage")),style:{maxWidth:"100%",maxHeight:"100%",objectFit:"contain",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"}})})]})}function a$({filePath:e,cwd:t,sourceSessionId:o}){let{t:s}=(0,A.s)(),[i,a]=(0,n.useState)(0),[l,d]=(0,n.useState)(null),[c,p]=(0,n.useState)(null),[u,h]=(0,n.useState)(null),g=(0,n.useRef)(null),m=ec(e).toLowerCase().split(".").pop()??"";(0,n.useEffect)(()=>{a(0),d(null),p(null),h(null),g.current&&(g.current.close(),g.current=null);let t=new EventSource(aT(e,"watch",o));return g.current=t,t.addEventListener("change",e=>{try{let t=JSON.parse(e.data);"number"==typeof t.size&&d(t.size)}catch{}p(null),h(null),a(e=>e+1)}),()=>{t.close(),g.current=null}},[e,o]);let f=aT(e,"read",o,i?{v:i}:void 0);return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,r.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,r.jsx)("span",{style:{fontFamily:"var(--font-mono)"},title:e,children:ep(e,t)}),(0,r.jsx)("span",{style:{marginLeft:"auto"},children:m||s("desktop.audio")}),null!=c&&(0,r.jsx)("span",{children:function(e){if(!Number.isFinite(e))return"";let t=Math.round(e),o=Math.floor(t/60);return`${o}:${String(t%60).padStart(2,"0")}`}(c)}),null!=l&&(0,r.jsx)("span",{children:aD(l)}),(0,r.jsx)(aR,{filePath:e,sourceSessionId:o})]}),(0,r.jsx)("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",padding:24,background:"var(--bg-panel)"},children:(0,r.jsxs)("div",{style:{width:"min(680px, 100%)"},children:[u&&(0,r.jsx)("div",{style:{color:"#f87171",fontSize:13,marginBottom:12,textAlign:"center"},children:u}),(0,r.jsx)("audio",{controls:!0,preload:"metadata",src:f,onLoadedMetadata:e=>p(e.currentTarget.duration),onError:()=>h(s("desktop.failedToLoadAudio")),style:{width:"100%"}},f)]})})]})}function aH({filePath:e,cwd:t,sourceSessionId:o}){let{t:s}=(0,A.s)(),[i,a]=(0,n.useState)(0),[l,d]=(0,n.useState)(null),[c,p]=(0,n.useState)(null),u=(0,n.useRef)(null),h=aj(e),g="pdf"===h,m=g?aT(e,"read",o,i?{v:i}:void 0):aT(e,"preview",o,i?{v:i}:void 0);return(0,n.useEffect)(()=>{a(0),d(null),p(null),u.current&&(u.current.close(),u.current=null),fetch(aT(e,"meta",o)).then(e=>e.json()).then(e=>{e.error&&p(e.error),"number"==typeof e.size&&(d(e.size),!g&&e.size>0xa00000&&p(s("desktop.docxTooLargeForPreview")))}).catch(e=>p(String(e)));let t=new EventSource(aT(e,"watch",o));return u.current=t,t.addEventListener("change",e=>{try{let t=JSON.parse(e.data);if("number"==typeof t.size&&(d(t.size),!g&&t.size>0xa00000))return void p(s("desktop.docxTooLargeForPreview"))}catch{}p(null),a(e=>e+1)}),()=>{t.close(),u.current=null}},[e,g,o,s]),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,r.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,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:e,children:ep(e,t)}),(0,r.jsx)("span",{style:{marginLeft:"auto"},children:"docx"===h?s("desktop.docxPreview"):"pdf"}),null!=l&&(0,r.jsx)("span",{children:aD(l)}),(0,r.jsx)(aR,{filePath:e,sourceSessionId:o})]}),(0,r.jsx)("div",{style:{flex:1,minHeight:0,background:"var(--bg-panel)"},children:c?(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",padding:24,color:"#f87171",fontSize:13,textAlign:"center"},children:c}):(0,r.jsx)("iframe",{src:m,sandbox:g?void 0:"allow-same-origin",title:s("desktop.previewFile",{file:ec(e)}),style:{width:"100%",height:"100%",border:"none",background:g?"var(--bg)":"#eef1f5"}},m)})]})}function aO({filePath:e,cwd:t,sourceSessionId:o,onOpenFile:n,onAtMention:s,onMentionLines:i,initialDisplayMode:a,onFileSaved:l}){let d;return null!==(ab[aj(e)]??null)?(0,r.jsx)(aL,{filePath:e,cwd:t,sourceSessionId:o}):null!==(aw[aj(e)]??null)?(0,r.jsx)(a$,{filePath:e,cwd:t,sourceSessionId:o}):null!==("pdf"===(d=aj(e))||"docx"===d?d:null)?(0,r.jsx)(aH,{filePath:e,cwd:t,sourceSessionId:o}):(0,r.jsx)(aB,{filePath:e,cwd:t,sourceSessionId:o,onOpenFile:n,onAtMention:s,onMentionLines:i,initialDisplayMode:a,onFileSaved:l})}function aB({filePath:e,cwd:t,sourceSessionId:o,onOpenFile:s,onAtMention:i,onMentionLines:a,initialDisplayMode:l,onFileSaved:d}){let c,p,{t:u}=(0,A.s)(),[g,m]=(0,n.useState)(null),[x,k]=(0,n.useState)(null),[v,y]=(0,n.useState)(null),[b,w]=(0,n.useState)(!0),[j,S]=(0,n.useState)(null),[C,T]=(0,n.useState)(!1),[R,z]=(0,n.useState)("source"),[I,M]=(0,n.useState)(!1),[P,E]=(0,n.useState)(0),[W,F]=(0,n.useState)(null),D=(0,n.useRef)(null),N=(0,n.useRef)(null),[L,$]=(0,n.useState)(!1),[H,O]=(0,n.useState)(""),[B,U]=(0,n.useState)(""),[_,q]=(0,n.useState)(!1),[V,K]=(0,n.useState)(null),[G,J]=(0,n.useState)(!1),Y=(0,n.useRef)(null),X=(0,n.useRef)(null),Z=(0,n.useRef)(0),Q=(0,n.useRef)(!1);(0,n.useEffect)(()=>{Q.current=L},[L]);let ee=L&&H!==B,et=!!(g?.content&&g.content.includes("\0")),eo=(0,n.useCallback)(async e=>{if(!t)return void y(null);try{let o=new URLSearchParams({cwd:t,path:e}),r=await fetch(`/api/git/diff?${o.toString()}`),n=await r.json();y(r.ok&&n.supported&&"string"==typeof n.patch?n:null)}catch{y(null)}},[t]),er=(0,n.useCallback)((e,t=!1)=>fetch(aT(e,"read",o)).then(e=>e.json()).then(e=>e.error?(S(e.error),null):(t?(m(t=>(t&&k(t.content),e)),E(e=>e+1)):m(e),e)).catch(e=>(S(String(e)),null)),[o]);(0,n.useEffect)(()=>{w(!0),S(null),m(null),k(null),y(null),T(!1),z("source"),M(!1),E(0),$(!1),O(""),U(""),K(null),J(!1),q(!1),D.current&&(D.current.close(),D.current=null),er(e).then(e=>{(e?.language==="markdown"||e?.language==="html")&&"diff"!==l&&T(!0)}).finally(()=>w(!1)),eo(e);let t=new EventSource(aT(e,"watch",o));return D.current=t,t.addEventListener("change",()=>{Q.current?J(!0):(er(e,!0),eo(e))}),()=>{t.close(),D.current=null}},[e,er,eo,l,o]);let en=(0,n.useCallback)(()=>{g&&!et&&(O(g.content),U(g.content),K(null),J(!1),$(!0))},[g,et]),es=(0,n.useCallback)(()=>{$(!1),O(""),U(""),K(null),J(!1)},[]),ei=(0,n.useCallback)(()=>{(!ee||window.confirm(u("files.unsavedChanges")))&&es()},[ee,es,u]),ea=(0,n.useCallback)(async()=>{if(!g||_)return;let t=++Z.current;q(!0),K(null);try{let o=await aM(e,H);if(t!==Z.current)return;m(e=>e?{...e,content:H,size:o}:e),U(H),q(!1),es(),eo(e),d?.()}catch(e){if(t!==Z.current)return;K(e instanceof Error?e.message:String(e)),q(!1)}},[g,_,H,e,es,eo,d]);(0,n.useEffect)(()=>{if(!L)return;let e=e=>{if((e.metaKey||e.ctrlKey)&&"s"===e.key.toLowerCase()){e.preventDefault(),ea();return}"Escape"===e.key&&(e.preventDefault(),ei())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[L,ea,ei]),(0,n.useEffect)(()=>{if(!ee)return;let e=e=>{e.preventDefault(),e.returnValue=""};return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[ee]);let ed=(0,n.useCallback)(()=>{let e=Y.current,t=X.current;e&&t&&(t.scrollTop=e.scrollTop)},[]),ec=(0,n.useCallback)(e=>{if("Tab"!==e.key||e.metaKey||e.ctrlKey||e.altKey)return;e.preventDefault();let t=e.currentTarget,{selectionStart:o,selectionEnd:r}=t;O(t.value.slice(0,o)+" "+t.value.slice(r)),requestAnimationFrame(()=>{let e=Y.current;if(!e)return;let t=o+2;e.selectionStart=t,e.selectionEnd=t})},[]),eu=(0,n.useMemo)(()=>ru(g?.content??""),[g?.content]),eh=v?.supported===!0&&"string"==typeof v.patch;(0,n.useEffect)(()=>{"diff"===l&&eh&&z("diff")},[eh,l]);let em=eh&&v?.status==="deleted",ef=(0,n.useCallback)(o=>{a&&o&&a(ep(e,t),o.startLine,o.endLine)},[t,e,a]);if((0,n.useEffect)(()=>{let e=()=>{let e=N.current,t="source"===R&&!C;F(a&&t&&e?aC(e,window.getSelection()):null)};if(e(),a&&"source"===R&&!C)return document.addEventListener("selectionchange",e),()=>document.removeEventListener("selectionchange",e)},[g?.content,a,C,R]),(0,n.useEffect)(()=>{if(!a||"source"!==R||C)return;let e=e=>{if(e.repeat||"i"!==e.key.toLowerCase()||!e.metaKey&&!e.ctrlKey||e.altKey||e.shiftKey)return;let t=e.target;if(t instanceof Element&&t.closest("input, textarea, [contenteditable='true']"))return;let o=N.current,r=o?aC(o,window.getSelection()):null;r&&(e.preventDefault(),ef(r))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[ef,a,C,R]),b)return(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:u("desktop.loadingFile")});if(em&&!g)return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,r.jsx)("div",{style:{padding:"5px 16px",borderBottom:"1px solid var(--border)",color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11},title:e,children:ep(e,t)}),(0,r.jsx)("div",{style:{flex:1,overflow:"auto",background:"var(--bg)"},children:(0,r.jsx)(aN,{patch:v.patch})})]});if(j)return(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#f87171",fontSize:13},children:j});if(!g)return null;let ex="html"===g.language,ek="markdown"===g.language,ev=(p=(c=el(e).replace(/\/+$/,"")).lastIndexOf("/"))<0?"":0===p?"/":2===p&&/^[a-zA-Z]:\//.test(c)?c.slice(0,3):c.slice(0,p),ey=g.content.split("\n"),eb=null!==x&&x!==g.content||eh,ew=!em&&!et&&eg();return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,r.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,r.jsx)("span",{style:{fontFamily:"var(--font-mono)"},title:e,children:ep(e,t)}),(0,r.jsx)("span",{style:{marginLeft:"auto"},children:g.language}),"source"===R&&!L&&(0,r.jsx)("span",{children:u("desktop.lines",{count:ey.length})}),(0,r.jsx)("span",{children:aD(g.size)}),eb&&!L&&(0,r.jsxs)("div",{style:{display:"flex",borderRadius:5,overflow:"hidden",border:"1px solid var(--border)"},children:[(0,r.jsx)("button",{onClick:()=>z("source"),style:{padding:"2px 8px",fontSize:11,border:"none",cursor:"pointer",background:"source"===R?"var(--bg-selected)":"var(--bg-hover)",color:"source"===R?"var(--text)":"var(--text-muted)",fontWeight:"source"===R?600:400},children:u("desktop.source")}),(0,r.jsxs)("button",{onClick:()=>z("diff"),style:{padding:"2px 8px",fontSize:11,border:"none",borderLeft:"1px solid var(--border)",cursor:"pointer",background:"diff"===R?"var(--bg-selected)":"var(--bg-hover)",color:"diff"===R?"var(--text)":"var(--text-muted)",fontWeight:"diff"===R?600:400},children:[u("desktop.diff")," ",P>0&&(0,r.jsxs)("span",{style:{color:"var(--git-status-added)",marginLeft:2},children:["+",P]})]})]}),"source"===R&&!C&&!L&&(0,r.jsx)("button",{onClick:()=>M(e=>!e),title:I?u("desktop.disableWordWrap"):u("desktop.enableWordWrap"),style:{padding:"2px 8px",fontSize:11,cursor:"pointer",background:I?"var(--bg-selected)":"var(--bg-hover)",color:I?"var(--text)":"var(--text-muted)",border:"1px solid var(--border)",borderRadius:5,fontWeight:I?600:400},children:u("desktop.wrap")}),ex&&"source"===R&&!L&&(0,r.jsxs)("div",{style:{display:"flex",borderRadius:5,overflow:"hidden",border:"1px solid var(--border)"},children:[(0,r.jsx)("button",{onClick:()=>T(!1),style:{padding:"2px 8px",fontSize:11,border:"none",cursor:"pointer",background:C?"var(--bg-hover)":"var(--bg-selected)",color:C?"var(--text-muted)":"var(--text)",fontWeight:C?400:600},children:u("desktop.code")}),(0,r.jsx)("button",{onClick:()=>T(!0),style:{padding:"2px 8px",fontSize:11,border:"none",borderLeft:"1px solid var(--border)",cursor:"pointer",background:C?"var(--bg-selected)":"var(--bg-hover)",color:C?"var(--text)":"var(--text-muted)",fontWeight:C?600:400},children:u("desktop.preview")})]}),ek&&"source"===R&&!L&&(0,r.jsxs)("div",{style:{display:"flex",borderRadius:5,overflow:"hidden",border:"1px solid var(--border)"},children:[(0,r.jsx)("button",{onClick:()=>T(!0),style:{padding:"2px 8px",fontSize:11,border:"none",cursor:"pointer",background:C?"var(--bg-selected)":"var(--bg-hover)",color:C?"var(--text)":"var(--text-muted)",fontWeight:C?600:400},children:u("desktop.preview")}),(0,r.jsx)("button",{onClick:()=>T(!1),style:{padding:"2px 8px",fontSize:11,border:"none",borderLeft:"1px solid var(--border)",cursor:"pointer",background:C?"var(--bg-hover)":"var(--bg-selected)",color:C?"var(--text-muted)":"var(--text)",fontWeight:C?400:600},children:u("desktop.raw")})]}),L?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{type:"button",onClick:()=>void ea(),disabled:_,title:u("files.saveHint"),"aria-label":u("files.save"),style:{height:20,minWidth:20,padding:"0 5px",display:"inline-flex",alignItems:"center",justifyContent:"center",border:"1px solid var(--border)",borderRadius:4,background:"var(--bg-selected)",color:"var(--text)",cursor:"pointer"},children:(0,r.jsx)(ay.g,{size:13,"aria-hidden":"true"})}),(0,r.jsx)("button",{type:"button",onClick:ei,disabled:_,title:u("files.cancelEdit"),"aria-label":u("files.cancelEdit"),style:{height:20,minWidth:20,padding:"0 5px",display:"inline-flex",alignItems:"center",justifyContent:"center",border:"1px solid var(--border)",borderRadius:4,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer"},children:(0,r.jsx)(h.X,{size:13,"aria-hidden":"true"})})]}):"source"===R&&ew?(0,r.jsx)("button",{type:"button",onClick:en,title:u("files.edit"),"aria-label":u("files.edit"),style:{height:20,minWidth:20,padding:"0 5px",display:"inline-flex",alignItems:"center",justifyContent:"center",border:"1px solid var(--border)",borderRadius:4,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer"},children:(0,r.jsx)(f.I,{size:13,"aria-hidden":"true"})}):null,(i||a)&&!L&&(0,r.jsx)("button",{type:"button",onPointerDown:e=>e.preventDefault(),onClick:()=>{W&&a?ef(W):i?.(ep(e,t),!1)},title:W?u("desktop.mentionSelectedLines",{start:W.startLine,end:W.endLine}):u("desktop.mentionFile"),"aria-label":W?u("desktop.mentionSelectedLines",{start:W.startLine,end:W.endLine}):u("desktop.mentionFile"),style:{height:20,minWidth:20,padding:"0 5px",border:"1px solid var(--border)",borderRadius:4,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer"},children:"@"}),!L&&(0,r.jsx)(aR,{filePath:e,sourceSessionId:o})]}),(0,r.jsx)("div",{ref:N,style:{flex:1,overflow:"auto",background:"var(--bg)"},children:L?(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[G&&(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"5px 12px",borderBottom:"1px solid var(--border)",background:"rgba(214,168,75,0.14)",color:"#d6a84b",fontSize:11,flexShrink:0},children:[(0,r.jsx)("span",{style:{flex:1},children:u("files.externalModified")}),(0,r.jsx)("button",{type:"button",onClick:()=>{(!ee||window.confirm(u("files.reloadOverwriteConfirm")))&&er(e).then(e=>{e&&(O(e.content),U(e.content),J(!1))})},disabled:_,style:{padding:"2px 8px",fontSize:11,border:"1px solid #d6a84b",borderRadius:4,background:"transparent",color:"#d6a84b",cursor:"pointer"},children:u("files.reload")})]}),V&&(0,r.jsx)("div",{style:{padding:"5px 12px",borderBottom:"1px solid var(--border)",background:"rgba(248,113,113,0.14)",color:"#f87171",fontSize:11,flexShrink:0},children:u("files.saveFailed",{error:V})}),(0,r.jsxs)("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[(0,r.jsx)("div",{ref:X,"aria-hidden":"true",style:{...aI,height:"100%",overflow:"hidden",whiteSpace:"pre",pointerEvents:"none"},children:H.split("\n").map((e,t)=>`${t+1}
37
37
  `).join("")}),(0,r.jsx)("textarea",{ref:Y,value:H,onChange:e=>O(e.target.value),onScroll:ed,onKeyDown:ec,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",wrap:"off",style:{flex:1,height:"100%",resize:"none",border:"none",outline:"none",background:"var(--bg)",color:"var(--text)",...az,whiteSpace:"pre",overflow:"auto",padding:0,tabSize:2}})]})]}):"diff"===R&&eb?eh?(0,r.jsx)(aN,{patch:v.patch}):(0,r.jsx)(aA,{oldContent:x,newContent:g.content}):ex&&C?(0,r.jsx)("iframe",{srcDoc:g.content,sandbox:"allow-scripts",style:{width:"100%",height:"100%",border:"none",background:"var(--bg)"},title:u("desktop.htmlPreview")}):ek&&C?(0,r.jsx)("div",{className:"markdown-body markdown-file-preview",style:{padding:"24px 32px"},children:(0,r.jsx)(on.oz,{remarkPlugins:rm,rehypePlugins:rf,components:{h1:({children:e})=>(0,r.jsx)("h1",{id:rp(e),children:e}),h2:({children:e})=>(0,r.jsx)("h2",{id:rp(e),children:e}),h3:({children:e})=>(0,r.jsx)("h3",{id:rp(e),children:e}),code({className:e,children:t,...o}){let n=e?.replace("language-","").toLowerCase()??"",s=String(t);return e?.includes("language-")||s.includes("\n")?"mermaid"===n?(0,r.jsx)(rE,{code:s.replace(/\n$/,"")}):(0,r.jsx)(rD,{code:s.replace(/\n$/,""),lang:n}):(0,r.jsx)("code",{className:"inline max-w-full whitespace-normal break-words [overflow-wrap:anywhere] align-baseline bg-(--bg-secondary) border border-(--border) px-1.5 py-0.5 text-xs font-mono text-(--accent-blue)",...o,children:t})},pre:({children:e})=>(0,r.jsx)(r.Fragment,{children:e}),a({href:e,children:o,...n}){delete n.node;let i="text-(--accent-blue) underline underline-offset-2 hover:text-(--accent-blue)/80",a=s?oe(e,ev,t??ev):null;return a&&s?(0,r.jsx)("a",{href:e,...n,className:i,onClick:e=>{if(e.defaultPrevented||0!==e.button||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;let t=e.currentTarget.getAttribute("target");t&&"_self"!==t||(e.preventDefault(),s(a))},children:o}):(0,r.jsx)("a",{href:e,...n,className:i,target:"_blank",rel:"noopener noreferrer",children:o})},table:({children:e})=>(0,r.jsx)("div",{className:"my-3 rounded-lg overflow-hidden border border-(--border)",children:(0,r.jsx)("div",{className:"overflow-x-auto",children:(0,r.jsx)("table",{className:"w-full text-sm border-collapse [&_tr:last-child>td]:border-b-0",children:e})})})},children:eu})}):(0,r.jsx)(os.A,{language:"text"===g.language?"plaintext":g.language,style:rx,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)"}},lineProps:e=>({className:"file-source-line","data-line-number":String(e)}),wrapLongLines:I,children:g.content})})]})}function aU({tabs:e,activeTabId:t,onSelectTab:o,onCloseTab:s}){let{t:i}=(0,A.s)(),[a,l]=(0,n.useState)(null);return(0,r.jsx)("div",{role:"tablist",style:{display:"flex",alignItems:"flex-end",background:"var(--bg-panel)",overflowX:"auto",flexShrink:0,height:36},children:e.map(n=>{let d=n.id===t;return(0,r.jsxs)("div",{role:"tab","aria-label":"terminal"===n.kind?i("terminal.tabLabel",{name:n.label}):n.label,"aria-selected":d,tabIndex:d||!t&&e[0].id===n.id?0:-1,onKeyDown:t=>{if(t.target===t.currentTarget){if("Enter"===t.key||" "===t.key)t.preventDefault(),o(n.id);else if(["ArrowLeft","ArrowRight","Home","End"].includes(t.key)){t.preventDefault();let r=e.findIndex(e=>e.id===n.id),s="Home"===t.key?0:"End"===t.key?e.length-1:(r+("ArrowRight"===t.key?1:-1)+e.length)%e.length;o(e[s].id),t.currentTarget.parentElement?.children[s]?.focus()}}},onClick:()=>o(n.id),onMouseDown:e=>{1===e.button&&e.preventDefault()},onAuxClick:e=>{1===e.button&&(e.preventDefault(),e.stopPropagation(),n.closing||s(n.id))},style:{display:"flex",alignItems:"center",gap:6,height:36,paddingLeft:12,paddingRight:6,borderRight:"1px solid var(--border)",background:d?"var(--bg)":"var(--bg-panel)",cursor:"pointer",fontSize:12,color:d?"var(--text)":"var(--text-muted)",whiteSpace:"nowrap",maxWidth:180,minWidth:80,flexShrink:0,userSelect:"none",transition:"background 0.1s, color 0.1s"},children:[(0,r.jsx)("span",{style:{flexShrink:0,opacity:d?1:.7,display:"flex",alignItems:"center"},children:"terminal"===n.kind?(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,r.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]}):ea(n.label,13)}),(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",flex:1,fontWeight:d?500:400},title:n.filePath,children:n.label}),(0,r.jsx)("button",{disabled:n.closing,onClick:e=>{e.stopPropagation(),s(n.id)},onMouseEnter:()=>l(n.id),onMouseLeave:()=>l(null),style:{display:"flex",alignItems:"center",justifyContent:"center",width:24,height:24,background:a===n.id?"var(--bg-hover)":"transparent",border:"none",borderRadius:4,color:a===n.id?"var(--text)":"var(--text-dim)",cursor:"pointer",padding:0,flexShrink:0,transition:"background 0.1s, color 0.1s"},title:i("desktop.closeTab"),"aria-label":i("desktop.closeTabWithLabel",{label:n.label}),children:(0,r.jsx)(h.X,{size:11,"aria-hidden":"true"})})]},n.id)})})}var a_=o(27289),aq=o(93534),aV=o(45781),aK=o(68731),aG=o(93912),aJ=o(23675),aY=o(48716),aX=o(47013),aZ=o(51265);let aQ={"restore-script":"restore","generate-cmd":"cmd",keep:"keep","keep-with-warning":"warning",manual:"manual"};function a0({cwd:e}){let{t}=(0,A.s)(),o=(0,n.useRef)(null),[s,i]=(0,n.useState)(!0),[a,l]=(0,n.useState)(!1),[d,c]=(0,n.useState)(!1),[p,u]=(0,n.useState)(null),[h,g]=(0,n.useState)(null),[m,f]=(0,n.useState)(new Set),[x,k]=(0,n.useState)(new Set),[v,y]=(0,n.useState)(!1),[b,w]=(0,n.useState)(null),[j,S]=(0,n.useState)(!1),[C,T]=(0,n.useState)(null),[R,z]=(0,n.useState)([]),[I,M]=(0,n.useState)(""),[P,E]=(0,n.useState)(null),[W,F]=(0,n.useState)(null);(0,n.useEffect)(()=>{fetch("/api/models").then(e=>e.json()).then(e=>{let t=e.models??[];z(t),t.length>0&&M(`${t[0].provider}/${t[0].id}`)}).catch(()=>{})},[]);let D=(0,n.useCallback)(async()=>{c(!0),u(null);try{let e=await fetch("/api/backup/export",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({includeSecrets:s,includeSessions:a})});if(!e.ok){let t=await e.json();u(t.error??`HTTP ${e.status}`);return}let t=await e.blob(),o=(e.headers.get("Content-Disposition")??"").match(/filename="?([^";]+)"?/),r=URL.createObjectURL(t),n=document.createElement("a");n.href=r,n.download=o?.[1]??"pi-backup.zip",document.body.appendChild(n),n.click(),n.remove(),URL.revokeObjectURL(r)}catch{u(String(t("desktop.backupExportFailed")))}finally{c(!1)}},[s,a,t]),N=(0,n.useCallback)(async e=>{if(e){w(null),T(null),g(null);try{let o=new FormData;o.append("phase","parse"),o.append("file",e);let r=await fetch("/api/backup/import",{method:"POST",body:o}),n=await r.json();if(!r.ok||n.error)return void w(n.error??`HTTP ${r.status}`);if("preview"!==n.phase||!n.preview)return void w(String(t("desktop.backupImportFailed")));g(n),f(new Set(n.preview.categories)),k(new Set),y(!1)}catch{w(String(t("desktop.backupImportFailed")))}}},[t]),L=(0,n.useCallback)(async()=>{if(h){S(!0),w(null);try{let e=new FormData;e.append("phase","restore"),e.append("token",h.token),e.append("selections",JSON.stringify({categories:[...m],skippedMcpServers:[...x],reinstallNpm:v}));let r=await fetch("/api/backup/import",{method:"POST",body:e}),n=await r.json();if(!r.ok||n.error)return void w(n.error??`HTTP ${r.status}`);if("report"!==n.phase||!n.report)return void w(String(t("desktop.backupRestoreFailed")));T(n.report),g(null),o.current&&(o.current.value="")}catch{w(String(t("desktop.backupRestoreFailed")))}finally{S(!1)}}},[h,m,x,v,t]),$=(0,n.useCallback)(async o=>{if(o.installPrompt&&e){E(o.name),F(null);try{let t=I.indexOf("/"),r=t>0?I.slice(0,t):void 0,n=t>0?I.slice(t+1):void 0,s=await fetch("/api/agent/new",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,message:o.installPrompt,provider:r,modelId:n})}),i=await s.json();if(!s.ok||i.error)return void w(i.error??`HTTP ${s.status}`);F({server:o.name,sessionId:i.sessionId})}catch{w(String(t("desktop.backupInstallSessionFailed")))}finally{E(null)}}},[e,I,t]),H=e=>"win32"===e?"Windows":"darwin"===e?"macOS":"Linux";return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",flex:1,minWidth:0,minHeight:0,overflowY:"auto"},children:[(0,r.jsx)("header",{style:{padding:"18px 22px 14px",borderBottom:"1px solid var(--border)"},children:(0,r.jsx)("h1",{style:{margin:0,fontSize:16,fontWeight:700,color:"var(--text)"},children:t("desktop.backup")})}),(0,r.jsxs)("section",{style:{padding:"18px 22px",borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)("h2",{style:{margin:0,fontSize:13,fontWeight:600,color:"var(--text)"},children:t("desktop.backupExportTitle")}),(0,r.jsx)("p",{style:{margin:"6px 0 12px",fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:t("desktop.backupExportDescription")}),(0,r.jsxs)("label",{style:{display:"flex",gap:8,alignItems:"flex-start",cursor:"pointer",marginBottom:8},children:[(0,r.jsx)("input",{type:"checkbox",checked:s,onChange:e=>i(e.target.checked),style:{marginTop:2}}),(0,r.jsxs)("span",{style:{fontSize:12,color:"var(--text)"},children:[t("desktop.backupIncludeSecrets"),(0,r.jsx)("span",{style:{display:"block",fontSize:11,color:"#ef4444"},children:t("desktop.backupSecretsWarning")})]})]}),(0,r.jsxs)("label",{style:{display:"flex",gap:8,alignItems:"flex-start",cursor:"pointer",marginBottom:14},children:[(0,r.jsx)("input",{type:"checkbox",checked:a,onChange:e=>l(e.target.checked),style:{marginTop:2}}),(0,r.jsxs)("span",{style:{fontSize:12,color:"var(--text)"},children:[t("desktop.backupIncludeSessions"),(0,r.jsx)("span",{style:{display:"block",fontSize:11,color:"var(--text-dim)"},children:t("desktop.backupSessionsHint")})]})]}),(0,r.jsxs)("button",{type:"button",onClick:D,disabled:d,style:{display:"inline-flex",alignItems:"center",gap:7,padding:"8px 14px",background:"var(--accent)",border:"none",borderRadius:6,color:"#fff",fontSize:12,fontWeight:600,cursor:d?"wait":"pointer"},children:[(0,r.jsx)(aX.f,{size:15,"aria-hidden":"true"}),d?t("desktop.backupExporting"):t("desktop.backupExportButton")]}),p&&(0,r.jsx)("p",{style:{margin:"8px 0 0",fontSize:11,color:"#ef4444"},children:p})]}),(0,r.jsxs)("section",{style:{padding:"18px 22px"},children:[(0,r.jsx)("h2",{style:{margin:0,fontSize:13,fontWeight:600,color:"var(--text)"},children:t("desktop.backupImportTitle")}),(0,r.jsx)("p",{style:{margin:"6px 0 12px",fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:t("desktop.backupImportDescription")}),(0,r.jsx)("input",{ref:o,type:"file",accept:".zip,application/zip",onChange:e=>N(e.target.files?.[0]),style:{display:"none"}}),(0,r.jsxs)("button",{type:"button",onClick:()=>o.current?.click(),style:{display:"inline-flex",alignItems:"center",gap:7,padding:"8px 14px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",fontSize:12,fontWeight:600,cursor:"pointer"},children:[(0,r.jsx)(aZ._,{size:15,"aria-hidden":"true"}),t("desktop.backupImportButton")]}),b&&(0,r.jsx)("p",{style:{margin:"0 0 10px",fontSize:11,color:"#ef4444",lineHeight:1.5},children:b}),h&&(0,r.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,padding:14,background:"var(--bg-panel)",display:"flex",flexDirection:"column",gap:12},children:[(0,r.jsxs)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.6},children:[(0,r.jsxs)("span",{style:{color:"var(--text)",fontWeight:600},children:[t("desktop.backupManifest"),":"]})," ",new Date(h.preview.manifest.createdAt).toLocaleString()," \xb7 ",H(h.preview.manifest.sourcePlatform)," →",H(navigator.platform.includes("Win")?"win32":navigator.platform.includes("Linux")?"linux":"darwin")," \xb7 pi-web ",h.preview.manifest.piWebVersion,h.preview.manifest.includeSecrets?"":` \xb7 ${t("desktop.backupNoSecrets")}`]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:6},children:t("desktop.backupCategories")}),(0,r.jsx)("div",{style:{display:"flex",gap:14,flexWrap:"wrap"},children:h.preview.categories.map(e=>(0,r.jsxs)("label",{style:{display:"flex",gap:6,alignItems:"center",cursor:"pointer",fontSize:12,color:"var(--text)"},children:[(0,r.jsx)("input",{type:"checkbox",checked:m.has(e),onChange:t=>{let o=new Set(m);t.target.checked?o.add(e):o.delete(e),f(o)}}),t(`desktop.backupCategory${e}`)]},e))})]}),h.preview.servers.length>0&&(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:6},children:t("desktop.backupMcpServers")}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:h.preview.servers.map(o=>(0,r.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8,fontSize:12},children:[(0,r.jsx)("input",{type:"checkbox",checked:!x.has(o.name),onChange:e=>{let t=new Set(x);e.target.checked?t.delete(o.name):t.add(o.name),k(t)},style:{marginTop:2}}),(0,r.jsxs)("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:2},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[(0,r.jsx)("code",{style:{fontSize:11,fontFamily:"var(--font-mono)",color:"var(--text)"},children:o.name}),(0,r.jsx)("span",{style:{fontSize:10,padding:"1px 6px",borderRadius:8,background:"manual"===o.action||"keep-with-warning"===o.action?"rgba(239,68,68,0.15)":"var(--bg-selected)",color:"manual"===o.action||"keep-with-warning"===o.action?"#ef4444":"var(--text-muted)"},children:aQ[o.action]})]}),(0,r.jsxs)("div",{style:{fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[(0,r.jsx)("code",{style:{fontFamily:"var(--font-mono)"},children:o.original.command}),o.adapted&&o.adapted.command!==o.original.command&&(0,r.jsxs)(r.Fragment,{children:[" → ",(0,r.jsx)("code",{style:{fontFamily:"var(--font-mono)",color:"var(--text)"},children:o.adapted.command})]})]}),o.reason&&(0,r.jsx)("div",{style:{fontSize:11,color:"#ef4444"},children:o.reason}),"manual"===o.action&&o.installPrompt&&e&&(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:2,flexWrap:"wrap"},children:[(0,r.jsx)("select",{value:I,onChange:e=>M(e.target.value),style:{fontSize:11,padding:"4px 6px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:4,color:"var(--text)",maxWidth:220},title:t("desktop.backupInstallModel"),children:R.map(e=>(0,r.jsxs)("option",{value:`${e.provider}/${e.id}`,children:[e.provider,"/",e.name||e.id]},`${e.provider}/${e.id}`))}),(0,r.jsx)("button",{type:"button",disabled:P===o.name,onClick:()=>$(o),style:{padding:"4px 10px",fontSize:11,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:4,color:"var(--text)",cursor:P===o.name?"wait":"pointer"},children:P===o.name?"…":t("desktop.backupInstallSession")}),W?.server===o.name&&(0,r.jsx)("a",{href:`?session=${encodeURIComponent(W.sessionId)}`,style:{fontSize:11,color:"var(--accent)"},children:t("desktop.backupOpenSession")})]})]})]},o.name))})]}),h.preview.npmPackages.length>0&&(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:6},children:t("desktop.backupNpmPackages")}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:4,marginBottom:6},children:h.preview.npmPackages.map(e=>(0,r.jsx)("code",{style:{fontSize:11,fontFamily:"var(--font-mono)",color:"var(--text)"},children:e},e))}),(0,r.jsxs)("label",{style:{display:"flex",gap:6,alignItems:"flex-start",cursor:"pointer",fontSize:12,color:"var(--text)",lineHeight:1.4},children:[(0,r.jsx)("input",{type:"checkbox",checked:v,onChange:e=>y(e.target.checked),style:{marginTop:2}}),(0,r.jsxs)("span",{children:[t("desktop.backupReinstallNpm"),(0,r.jsx)("span",{style:{display:"block",fontSize:11,color:"var(--text-dim)"},children:t("desktop.backupReinstallNpmHint")})]})]})]}),h.preview.warnings.length>0&&(0,r.jsx)("div",{style:{fontSize:11,color:"#ef4444",lineHeight:1.5},children:h.preview.warnings.map((e,t)=>(0,r.jsxs)("div",{children:["⚠ ",e]},t))}),(0,r.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,r.jsxs)("button",{type:"button",onClick:L,disabled:j||0===m.size,style:{display:"inline-flex",alignItems:"center",gap:7,padding:"8px 14px",background:"var(--accent)",border:"none",borderRadius:6,color:"#fff",fontSize:12,fontWeight:600,cursor:j?"wait":"pointer",opacity:0===m.size?.5:1},children:[(0,r.jsx)(aZ._,{size:15,"aria-hidden":"true"}),j?t("desktop.backupRestoring"):t("desktop.backupRestoreButton")]}),(0,r.jsx)("button",{type:"button",onClick:()=>{g(null),o.current&&(o.current.value="")},disabled:j,style:{padding:"8px 14px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",fontSize:12,cursor:"pointer"},children:t("desktop.cancel")})]})]}),C&&(0,r.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,padding:14,background:"var(--bg-panel)",display:"flex",flexDirection:"column",gap:10},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,fontWeight:600,color:"var(--text)"},children:[(0,r.jsx)(rQ.W,{size:16,"aria-hidden":"true"}),t("desktop.backupRestoreReport")]}),C.restored.length>0&&(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{style:{fontSize:11,fontWeight:600,color:"#4ade80",marginBottom:4},children:["✓ ",t("desktop.backupReportRestored")]}),(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-muted)",lineHeight:1.6,fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:C.restored.join("\n")})]}),C.needsRestart.length>0&&(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{style:{fontSize:11,fontWeight:600,color:"#fbbf24",marginBottom:4},children:["\uD83D\uDD04 ",t("desktop.backupReportRestart")]}),(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-muted)",lineHeight:1.6,fontFamily:"var(--font-mono)"},children:C.needsRestart.join("\n")})]}),C.manual.length>0&&(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{style:{fontSize:11,fontWeight:600,color:"#ef4444",marginBottom:4},children:[(0,r.jsx)(X.N,{size:12,style:{verticalAlign:-2},"aria-hidden":"true"})," ",t("desktop.backupReportManual")]}),C.manual.map((e,t)=>(0,r.jsxs)("div",{style:{fontSize:11,color:"var(--text-muted)",lineHeight:1.6},children:[(0,r.jsx)("strong",{style:{color:"var(--text)"},children:e.server}),": ",e.message]},t))]}),C.warnings.length>0&&(0,r.jsx)("div",{style:{fontSize:11,color:"#ef4444",lineHeight:1.6},children:C.warnings.map((e,t)=>(0,r.jsxs)("div",{children:["⚠ ",e]},t))}),C.needsRestart.length>0&&(0,r.jsx)("p",{style:{margin:0,fontSize:11,color:"#fbbf24",lineHeight:1.5},children:t("desktop.backupRestartHint")})]})]})]})}let a1={position:"relative",width:40,height:22,borderRadius:11,border:"none",cursor:"pointer",padding:0,flexShrink:0,transition:"background 0.18s ease",outline:"none"},a2={position:"absolute",top:3,width:16,height:16,borderRadius:"50%",background:"#fff",transition:"left 0.18s ease, transform 0.18s ease",boxShadow:"0 1px 3px rgba(0,0,0,0.18)"};function a4({checked:e,onChange:t,label:o,description:n}){return(0,r.jsxs)("label",{style:{display:"flex",alignItems:n?"flex-start":"center",justifyContent:"space-between",gap:12,padding:"12px 14px",borderRadius:7,cursor:"pointer",userSelect:"none",transition:"background 0.12s",margin:"0 -14px"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[(0,r.jsxs)("span",{style:{flex:1,minWidth:0},children:[(0,r.jsx)("span",{style:{display:"block",fontSize:13,fontWeight:550,color:"var(--text)",lineHeight:1.4},children:o}),n&&(0,r.jsx)("span",{style:{display:"block",fontSize:11,lineHeight:1.5,color:"var(--text-muted)",marginTop:2},children:n})]}),(0,r.jsx)("button",{type:"button",role:"switch","aria-checked":e,onClick:o=>{o.preventDefault(),t(!e)},style:{...a1,background:e?"var(--accent)":"color-mix(in srgb, var(--border) 70%, var(--bg))"},children:(0,r.jsx)("span",{style:{...a2,left:e?21:3}})})]})}function a6({title:e,description:t,children:o}){return(0,r.jsxs)("section",{style:{padding:"20px 22px",borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)("h2",{style:{margin:0,fontSize:14,fontWeight:650,color:"var(--text)"},children:e}),(0,r.jsx)("p",{style:{margin:"5px 0 14px",fontSize:12,lineHeight:1.5,color:"var(--text-muted)"},children:t}),(0,r.jsx)("div",{children:o})]})}let a8="pi-input-shortcut";function a5(){try{let e=localStorage.getItem(a8);return"ctrl-enter"===e?"ctrl-enter":"enter"}catch{return"enter"}}function a3(){let{t:e}=(0,A.s)(),[t,o]=(0,n.useState)(a5);(0,n.useEffect)(()=>{let e=()=>o(a5());return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)},[]);let s=(0,n.useCallback)(e=>{o(e);try{localStorage.setItem(a8,e),window.dispatchEvent(new StorageEvent("storage",{key:a8,newValue:e}))}catch{}},[]);return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",flex:1,minWidth:0,minHeight:0,overflowY:"auto"},children:[(0,r.jsx)("header",{style:{padding:"18px 22px 14px",borderBottom:"1px solid var(--border)"},children:(0,r.jsx)("h1",{style:{margin:0,fontSize:16,fontWeight:700,color:"var(--text)"},children:e("desktop.chat")})}),(0,r.jsx)(a6,{title:e("desktop.inputShortcut"),description:e("desktop.inputShortcutDescription"),children:(0,r.jsx)(a4,{checked:"ctrl-enter"===t,onChange:e=>s(e?"ctrl-enter":"enter"),label:e("desktop.useCtrlEnter"),description:e("desktop.useCtrlEnterDescription")})})]})}var a7=o(95650),a9=o(55803),le=o(23602),lt=o(18613),lo=o(12779);let lr={display:"flex",gap:6,flexWrap:"wrap"};function ln(e,t,o){return{display:"inline-flex",alignItems:"center",gap:7,padding:"7px 14px",border:`1px solid ${e?"var(--accent)":t?"var(--border-hover)":"var(--border)"}`,borderRadius:8,background:e?"color-mix(in srgb, var(--accent) 12%, var(--bg))":t?"var(--bg-hover)":"var(--bg-card)",color:e?"var(--accent)":t?"var(--text)":"var(--text-muted)",fontSize:13,fontWeight:e?600:400,cursor:o?"not-allowed":"pointer",opacity:o?.5:1,transition:"border-color 0.15s, background 0.15s, color 0.15s",outline:"none",whiteSpace:"nowrap"}}function ls({icon:e,label:t,actions:o}){return(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:10,width:"100%"},children:[(0,r.jsx)("span",{style:{color:"var(--text-dim)",display:"inline-flex",flexShrink:0},children:e}),(0,r.jsx)("span",{style:{fontSize:11,fontWeight:700,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.06em"},children:t}),o&&(0,r.jsx)("span",{style:{display:"inline-flex",alignItems:"center",gap:12,marginLeft:"auto"},children:o})]})}let li={display:"inline-flex",alignItems:"center",gap:6,padding:0,border:0,background:"transparent",color:"var(--accent)",fontSize:11,cursor:"pointer",whiteSpace:"nowrap"},la={onMouseEnter:e=>{e.currentTarget.style.textDecoration="underline"},onMouseLeave:e=>{e.currentTarget.style.textDecoration="none"}};function ll({title:e,description:t,children:o}){return(0,r.jsxs)("section",{style:{padding:"20px 22px",borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)("h2",{style:{margin:0,fontSize:14,fontWeight:650,color:"var(--text)"},children:e}),(0,r.jsx)("p",{style:{margin:"5px 0 16px",fontSize:12,lineHeight:1.5,color:"var(--text-muted)"},children:t}),o]})}function ld({depth:e}){let t=e/100;return(0,r.jsxs)("svg",{width:14,height:14,viewBox:"0 0 14 14",style:{flexShrink:0},children:[(0,r.jsx)("rect",{x:1.5,y:1.5,width:11,height:11,rx:2.5,style:{fill:"none",stroke:"var(--text-dim)",strokeWidth:1+2*t,opacity:.2+.8*t}}),(0,r.jsx)("rect",{x:4,y:4,width:6,height:6,rx:1,style:{fill:"var(--text-dim)",opacity:.05+.35*t}})]})}function lc({hasDark:e,hasLight:t,darkColor:o,lightColor:n,t:s}){return(0,r.jsxs)("span",{style:{display:"inline-flex",gap:3,alignItems:"center",flexShrink:0},children:[e&&(0,r.jsx)("span",{title:s("desktop.darkVariant"),style:{display:"inline-block",width:7,height:7,borderRadius:"50%",background:o??"#7c6f64"}}),t&&(0,r.jsx)("span",{title:s("desktop.lightVariant"),style:{display:"inline-block",width:7,height:7,borderRadius:"50%",background:n??"#d5c4a1",border:"1px solid rgba(0,0,0,0.1)"}})]})}function lp(){let{mode:e,resolvedMode:t,themeName:o,setMode:s,setTheme:i,previewTheme:a,clearPreview:l,isThemeCached:d,borderDepth:c,setBorderDepth:p}=o9(),{locale:u,setLocale:h,t:g}=(0,A.s)(),[m,f]=(0,n.useState)([]),[x,k]=(0,n.useState)(!0),[v,y]=(0,n.useState)(null),[b,w]=(0,n.useState)(null);(0,n.useEffect)(()=>{let e=!1;return fetch("/api/themes").then(e=>e.ok?e.json():null).then(t=>{!e&&t&&f(t.themeSets)}).catch(()=>{}).finally(()=>{e||k(!1)}),()=>{e=!0}},[]);let j=(0,n.useCallback)(e=>{y(e),i(e).finally(()=>y(null))},[i]),S=(0,n.useRef)(null),C=(0,n.useCallback)(e=>{w(e),null!==S.current&&window.clearTimeout(S.current),S.current=window.setTimeout(()=>{S.current=null,null!==e?d(e)&&a(e):l()},160)},[a,l,d]),T=(0,n.useCallback)(e=>{s(e)},[s]),R=(0,n.useCallback)(()=>{window.piDesktop?.openThemeFolder()},[]),z=(0,n.useCallback)(()=>{window.piDesktop?window.piDesktop.openThemeDocs():window.open("https://pi.dev/docs/latest/themes","_blank","noopener,noreferrer")},[]);return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",flex:1,minWidth:0,minHeight:0,overflowY:"auto"},children:[(0,r.jsx)("header",{style:{padding:"18px 22px 14px",borderBottom:"1px solid var(--border)"},children:(0,r.jsx)("h1",{style:{margin:0,fontSize:16,fontWeight:700,color:"var(--text)"},children:g("desktop.display")})}),(0,r.jsxs)(ll,{title:g("desktop.theme"),description:g("desktop.themeDescription"),children:[(0,r.jsx)(ls,{icon:(0,r.jsx)(a7.p,{size:14,weight:"fill"}),label:g("desktop.colorScheme"),actions:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("button",{type:"button",onClick:R,style:li,...la,children:[(0,r.jsx)(a9.N,{size:12,weight:"regular","aria-hidden":"true"}),g("desktop.openThemeFolder")]}),(0,r.jsxs)("button",{type:"button",onClick:z,style:li,...la,children:[(0,r.jsx)(le.B,{size:12,weight:"regular","aria-hidden":"true"}),g("desktop.learnPiThemes")]})]})}),x?(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-dim)"},children:g("desktop.loadingThemes")}):(0,r.jsxs)("div",{style:lr,children:[(0,r.jsx)("button",{type:"button",onClick:()=>j(""),disabled:null!==v,style:ln(""===o,"__default__"===b,null!==v),onMouseEnter:()=>C(""),onMouseLeave:()=>C(null),children:g("desktop.defaultTheme")}),m.map(e=>(0,r.jsxs)("button",{type:"button",onClick:()=>j(e.name),disabled:null!==v,style:ln(o===e.name,b===e.name,v===e.name),onMouseEnter:()=>C(e.name),onMouseLeave:()=>C(null),children:[e.displayName,(0,r.jsx)(lc,{hasDark:e.hasDark,hasLight:e.hasLight,darkColor:e.accent,lightColor:e.accentLight,t:g})]},e.name))]}),(0,r.jsxs)("div",{style:{marginTop:20},children:[(0,r.jsx)(ls,{icon:(0,r.jsx)(ld,{depth:c}),label:`${g("desktop.borderVisibility")} (${c})`}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10},children:[(0,r.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",flexShrink:0},children:g("desktop.borderSubtle")}),(0,r.jsx)("input",{type:"range",min:0,max:100,step:1,value:c,onChange:e=>p(Number(e.target.value)),style:{flex:1,accentColor:"var(--accent)",height:6,cursor:"pointer"}}),(0,r.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",flexShrink:0},children:g("desktop.borderBold")})]}),(0,r.jsx)("div",{style:{marginTop:10,display:"flex",gap:10},children:[0,25,50,75,100].map(e=>{let t=c===e,o=e<=50?`color-mix(in srgb, var(--border-orig) ${2*e}%, var(--bg) ${100-2*e}%)`:`color-mix(in srgb, var(--border-orig) ${100-(e-50)*2}%, var(--text) ${(e-50)*2}%)`;return(0,r.jsx)("div",{onClick:()=>p(e),style:{width:28,height:20,border:`2px solid ${t?"var(--accent)":o}`,borderRadius:5,background:"var(--bg-card)",cursor:"pointer",transition:"border-color 0.1s"}},e)})})]}),(0,r.jsxs)("div",{style:{marginTop:20},children:[(0,r.jsx)(ls,{icon:"dark"===t?(0,r.jsx)(lt.A,{size:14,weight:"fill"}):(0,r.jsx)(lo.b,{size:14,weight:"fill"}),label:g("desktop.appearanceMode")}),(0,r.jsx)("div",{style:lr,children:[{value:"light",icon:(0,r.jsx)(lo.b,{size:15,weight:"light"===e?"fill":"regular"})},{value:"dark",icon:(0,r.jsx)(lt.A,{size:15,weight:"dark"===e?"fill":"regular"})},{value:"system",icon:(0,r.jsx)(aq.V,{size:15,weight:"system"===e?"fill":"regular"})}].map(t=>{let o=e===t.value;return(0,r.jsxs)("button",{type:"button",onClick:()=>T(t.value),style:ln(o,b===`mode:${t.value}`),onMouseEnter:()=>w(`mode:${t.value}`),onMouseLeave:()=>w(null),children:[t.icon,g(`desktop.${t.value}`)]},t.value)})})]}),!x&&0===m.length&&(0,r.jsxs)("p",{style:{margin:"14px 0 0",fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:[g("desktop.noCustomThemes")," ",g("desktop.noCustomThemesHint")," ",(0,r.jsx)("code",{style:{fontSize:10,background:"var(--bg-secondary)",padding:"1px 5px",borderRadius:3,fontFamily:"var(--font-mono)"},children:"~/.pi/agent/themes/*.json"})," ",g("desktop.noCustomThemesHint2")]})]}),(0,r.jsx)(ll,{title:g("desktop.language"),description:g("desktop.languageDescription"),children:(0,r.jsx)("div",{style:lr,children:["en","zh-CN"].map(e=>(0,r.jsx)("button",{type:"button",onClick:()=>h("zh-CN"===e?"zh-CN":"en"),style:ln("zh-CN"===e?"zh-CN"===u:"zh-CN"!==u,b===`lang:${e}`),onMouseEnter:()=>w(`lang:${e}`),onMouseLeave:()=>w(null),children:"en"===e?g("desktop.english"):g("desktop.chinese")},e))})})]})}var lu=o(94638);function lh({children:e}){return(0,r.jsx)("div",{style:{borderRadius:12,border:"1px solid var(--border)",background:"color-mix(in srgb, var(--bg-panel) 55%, transparent)",overflow:"hidden"},children:e})}function lg({children:e}){return(0,r.jsx)("div",{style:{padding:"0 14px"},children:(0,r.jsx)("div",{style:{borderBottom:"1px solid var(--border)"},children:e})})}function lm({children:e}){return(0,r.jsx)("div",{style:{padding:"0 14px"},children:e})}function lf({children:e}){return(0,r.jsx)("div",{style:{display:"flex",gap:8,borderRadius:10,border:"1px solid var(--border)",background:"color-mix(in srgb, var(--bg-panel) 55%, transparent)",padding:"10px 12px",fontSize:12,lineHeight:1.5,color:"var(--text-muted)"},children:e})}let lx=[{value:"normal",labelKey:"modes.collabNormal"},{value:"plan",labelKey:"modes.collabPlan"},{value:"goal",labelKey:"modes.collabGoal"}],lk=[{value:"economy",labelKey:"modes.tokenEconomy"},{value:"full",labelKey:"modes.tokenFull"},{value:"delivery",labelKey:"modes.tokenDelivery"}],lv=[{value:"ask",labelKey:"modes.approvalAsk"},{value:"auto",labelKey:"modes.approvalAuto"},{value:"yolo",labelKey:"modes.approvalYolo"}];function ly({options:e,value:t,onChange:o,disabled:n,accentFor:s}){let{t:i}=(0,A.s)();return(0,r.jsx)("div",{role:"radiogroup",style:{display:"flex",border:"1px solid var(--border)",borderRadius:8,overflow:"hidden",height:28,flexShrink:0},children:e.map(e=>{let a=e.value===t,l=s?.(e.value);return(0,r.jsx)("button",{type:"button",role:"radio","aria-checked":a,disabled:n,onClick:()=>{e.value!==t&&o(e.value)},style:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%",padding:"0 12px",background:a?"var(--bg-selected)":"none",border:"none",color:a?l??"var(--accent)":"var(--text-muted)",cursor:n?"not-allowed":"pointer",fontSize:11.5,fontWeight:a?650:500,opacity:n?.5:1,whiteSpace:"nowrap",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{a||n||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{a||(e.currentTarget.style.background="none")},children:i(e.labelKey)},e.value)})})}function lb(){let{t:e}=(0,A.s)(),[t,o]=(0,n.useState)({tasksBoard:!0}),[s,i]=(0,n.useState)(null),[a,l]=(0,n.useState)(!1),[d,c]=(0,n.useState)(!1);(0,n.useEffect)(()=>{let e=!1;return(async()=>{try{let[t,r]=await Promise.all([fetch("/api/features"),fetch("/api/modes")]);if(!e&&t.ok){let e=await t.json();o(t=>({...t,...e}))}if(!e&&r.ok){let e=await r.json();i({collaborationMode:tw(e.collaborationMode),tokenMode:tj(e.tokenMode),toolApprovalMode:tS(e.toolApprovalMode),permissionRules:e.permissionRules??{allow:[],ask:[],deny:[]}})}e||l(!0)}catch{}})(),()=>{e=!0}},[]);let p=(0,n.useCallback)(async e=>{c(!0);try{let t=await fetch("/api/features",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({tasksBoard:e})});if(t.ok){let e=await t.json();o(t=>({...t,...e.features})),window.dispatchEvent(new CustomEvent("pi:features-changed"))}}catch{}finally{c(!1)}},[]),u=(0,n.useCallback)(async e=>{c(!0);try{let t=await fetch("/api/modes",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(t.ok){let e=await t.json();i(t=>t?{...t,collaborationMode:tw(e.modes?.collaborationMode??t.collaborationMode),tokenMode:tj(e.modes?.tokenMode??t.tokenMode),toolApprovalMode:tS(e.modes?.toolApprovalMode??t.toolApprovalMode),permissionRules:e.modes?.permissionRules??t.permissionRules}:t),window.dispatchEvent(new CustomEvent("pi:modes-changed"))}}catch{}finally{c(!1)}},[]);return(0,r.jsx)("div",{style:{flex:1,overflow:"auto",minWidth:0,padding:"20px 22px",display:"flex",flexDirection:"column",gap:16},children:(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[a?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(lh,{children:(0,r.jsx)(lm,{children:(0,r.jsx)(a4,{checked:t.tasksBoard,onChange:e=>void p(e),label:(0,r.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:6},children:[(0,r.jsx)(lu.x,{size:14,"aria-hidden":"true"}),e("desktop.featuresTasksBoard"),(0,r.jsx)("span",{style:{borderRadius:999,background:"rgba(37,99,235,0.12)",color:"var(--accent)",padding:"1px 7px",fontSize:9,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.04em"},children:"Beta"})]}),description:e("desktop.featuresTasksBoardDesc")})})}),s&&(0,r.jsxs)(lh,{children:[(0,r.jsx)(lg,{children:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:16,padding:"12px 0"},children:[(0,r.jsxs)("div",{style:{minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)"},children:e("desktop.featuresCollabDefault")}),(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:2},children:e("desktop.featuresCollabDefaultDesc")})]}),(0,r.jsx)(ly,{options:lx,value:s.collaborationMode,onChange:e=>void u({collaborationMode:e}),disabled:d})]})}),(0,r.jsx)(lg,{children:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:16,padding:"12px 0"},children:[(0,r.jsxs)("div",{style:{minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)"},children:e("desktop.featuresTokenDefault")}),(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:2},children:e("desktop.featuresTokenDefaultDesc")})]}),(0,r.jsx)(ly,{options:lk,value:s.tokenMode,onChange:e=>void u({tokenMode:e}),disabled:d})]})}),(0,r.jsx)(lm,{children:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:16,padding:"12px 0"},children:[(0,r.jsxs)("div",{style:{minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)"},children:e("desktop.featuresApprovalDefault")}),(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:2},children:e("desktop.featuresApprovalDefaultDesc")})]}),(0,r.jsx)(ly,{options:lv,value:s.toolApprovalMode,onChange:e=>void u({toolApprovalMode:e}),disabled:d,accentFor:e=>"yolo"===e?"var(--accent-red, #ef4444)":void 0})]})})]})]}):(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)"},children:e("desktop.featuresLoading")}),(0,r.jsx)(lf,{children:e("desktop.featuresDesc")}),d&&(0,r.jsx)("div",{style:{padding:"0 2px",fontSize:11,color:"var(--text-muted)"},children:e("desktop.featuresSaving")})]})})}var lw=o(76553);function lj({open:e,onClose:t,children:o}){let[s,i]=(0,n.useState)(!1),[a,l]=(0,n.useState)(!1);return((0,n.useEffect)(()=>{if(e)l(!0),requestAnimationFrame(()=>requestAnimationFrame(()=>i(!0)));else{i(!1);let e=setTimeout(()=>l(!1),250);return()=>clearTimeout(e)}},[e]),a)?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{onClick:t,style:{position:"fixed",inset:0,zIndex:1001,background:s?"rgba(0,0,0,0.35)":"rgba(0,0,0,0)",transition:"background 0.25s ease"}}),(0,r.jsxs)("div",{style:{position:"fixed",bottom:0,left:0,right:0,zIndex:1002,maxHeight:"85dvh",borderRadius:"16px 16px 0 0",background:"var(--bg)",boxShadow:"0 -4px 24px rgba(0,0,0,0.15)",transform:s?"translateY(0)":"translateY(100%)",transition:"transform 0.25s cubic-bezier(0.32, 0.72, 0, 1)",display:"flex",flexDirection:"column",overflow:"hidden"},children:[(0,r.jsx)("div",{style:{display:"flex",justifyContent:"center",padding:"10px 0 4px",flexShrink:0},children:(0,r.jsx)("div",{style:{width:36,height:4,borderRadius:2,background:"var(--border)"}})}),(0,r.jsx)("div",{style:{flex:1,overflow:"auto",minHeight:0},children:o})]})]}):null}function lS({onSessionsChanged:e}){let{t}=(0,A.s)(),o=O(),[s,i]=(0,n.useState)(null),[a,l]=(0,n.useState)([]),[p,u]=(0,n.useState)([]),[g,m]=(0,n.useState)(new Set),[f,x]=(0,n.useState)(null),[k,v]=(0,n.useState)({imported:0,skipped:0,errors:0,total:0,done:!1}),[y,b]=(0,n.useState)([]),[w,j]=(0,n.useState)(!1),[S,C]=(0,n.useState)({done:0,total:0}),T=(0,n.useRef)(new Map),R=(0,n.useRef)(!1),[z,I]=(0,n.useState)(!1),[M,P]=(0,n.useState)(null),[W,F]=(0,n.useState)(!1),D=(0,n.useCallback)(async()=>{I(!0),P(null);try{let e=await fetch("/api/import/discover"),t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);l(t.sources),t.reasonix?.available&&(u(t.reasonix.projects),i("reasonix"))}catch(e){P(e instanceof Error?e.message:String(e))}finally{I(!1)}},[]),[N,L]=(0,n.useState)(!1);(0,n.useEffect)(()=>{N||(L(!0),D())},[N,D]);let $=(0,n.useCallback)(async()=>{if(0!==g.size&&s){I(!0),P(null);try{let e=await fetch("/api/import/execute",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({source:s,projects:[...g]})}),t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);x(t.jobId)}catch(e){P(e instanceof Error?e.message:String(e))}finally{I(!1)}}},[s,g]);(0,n.useEffect)(()=>{let t;if(!f)return;let o=!0,r=async()=>{if(o)try{let n=await fetch(`/api/import/status?jobId=${encodeURIComponent(f)}`),s=await n.json();if(!o)return;v({imported:s.imported??0,skipped:s.skipped??0,errors:s.errors??0,total:s.total??0,done:s.done??!1}),s.done&&s.sessionIds&&(b(s.sessionIds),e?.()),s.done||(t=setTimeout(r,800))}catch{o&&(t=setTimeout(r,2e3))}};return r(),()=>{o=!1,clearTimeout(t)}},[f,e]);let H=(0,n.useCallback)(async()=>{if(w){for(let[e,t]of(R.current=!0,T.current))t.abort(),c(e);return}if(0===y.length)return;R.current=!1,j(!0),C({done:0,total:y.length});let t=0,o=0,r=async()=>{for(;!R.current;){let e=y[t++];if(!e)return;let r=new AbortController;T.current.set(e,r);try{await d(e,r.signal)}catch{}finally{T.current.delete(e),C({done:o+=1,total:y.length})}}};await Promise.all(Array.from({length:Math.min(2,y.length)},r)),T.current.clear(),j(!1),e?.()},[w,y,e]);if(k.done&&y.length>0)return(0,r.jsxs)("div",{style:{padding:"18px 22px",display:"flex",flexDirection:"column",gap:14},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10},children:[(0,r.jsx)(nv.r,{size:20,weight:"fill",style:{color:"#4ade80"}}),(0,r.jsx)("span",{style:{fontSize:14,fontWeight:600,color:"var(--text)"},children:t("desktop.importDone")??"导入完成"})]}),(0,r.jsxs)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.6},children:[t("desktop.importedSummary",{imported:k.imported})??`成功导入 ${k.imported} 个会话`,k.skipped>0&&(0,r.jsx)("span",{style:{marginLeft:8},children:t("desktop.importSkippedCount",{skipped:k.skipped})??`,${k.skipped} 个跳过`}),k.errors>0&&(0,r.jsx)("span",{style:{marginLeft:8,color:"#ef4444"},children:t("desktop.importErrorsCount",{errors:k.errors})??`,${k.errors} 个失败`})]}),(0,r.jsxs)("button",{type:"button",onClick:H,style:{display:"inline-flex",alignItems:"center",gap:7,padding:"8px 14px",background:"var(--accent)",border:"none",borderRadius:6,color:"#fff",fontSize:12,fontWeight:600,cursor:"pointer",alignSelf:"flex-start"},children:[w?(0,r.jsx)(K.y,{size:14,style:{animation:"spin 1s linear infinite"}}):(0,r.jsx)(lw.o,{size:15}),w?`${t("desktop.importGeneratingTitles")??"正在生成标题…"} (${S.done}/${S.total}) — ${t("desktop.stop")??"停止"}`:t("desktop.importGenerateTitles")??"为导入的会话生成标题"]}),(0,r.jsx)("button",{type:"button",onClick:()=>{x(null),v({imported:0,skipped:0,errors:0,total:0,done:!1}),b([]),j(!1),C({done:0,total:0})},style:{display:"inline-flex",alignItems:"center",gap:7,padding:"8px 14px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",fontSize:12,cursor:"pointer",alignSelf:"flex-start"},children:t("desktop.importAgain")??"再次导入"})]});let B=(0,r.jsxs)("div",{style:{padding:o?"12px 18px":"18px 22px",display:"flex",flexDirection:"column",gap:14},children:[M&&(0,r.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8,fontSize:12,color:"#ef4444",lineHeight:1.5},children:[(0,r.jsx)(X.N,{size:14,style:{flexShrink:0,marginTop:1}}),(0,r.jsx)("span",{children:M})]}),!f&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.6},children:t("desktop.importSessionsDesc")??"从其他 AI 编码工具导入历史对话记录到 pi-web。目前支持 Reasonix,更多工具陆续支持中。"}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:a.map(e=>(0,r.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:10,padding:"10px 14px",border:"1px solid var(--border)",borderRadius:8,cursor:"available"===e.status?"pointer":"default",background:s===e.key?"var(--bg-selected)":"var(--bg-panel)",opacity:"unavailable"===e.status?.5:"coming-soon"===e.status?.7:1,transition:"background 0.12s"},children:[(0,r.jsx)("input",{type:"radio",name:"import-source",value:e.key,checked:s===e.key,disabled:"available"!==e.status,onChange:()=>i(e.key)}),(0,r.jsxs)("div",{style:{flex:1},children:[(0,r.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)"},children:e.label}),"coming-soon"===e.status&&(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",marginTop:1},children:t("desktop.comingSoon")??"即将支持"})]}),"reasonix"===e.key&&p.length>0&&(0,r.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)"},children:[p.length," ",t("desktop.projects")??"个项目"," \xb7 ",p.reduce((e,t)=>e+t.sessions,0)," ",t("desktop.sessions")??"会话"]})]},e.key))}),"reasonix"===s&&p.length>0&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,r.jsx)("span",{style:{fontSize:12,fontWeight:600,color:"var(--text)"},children:t("desktop.importSelectProjects")??"选择要导入的项目"}),(0,r.jsx)("button",{type:"button",onClick:()=>m(new Set(p.map(e=>e.name))),style:lC,children:t("desktop.importSelectAll")??"全选"}),(0,r.jsx)("button",{type:"button",onClick:()=>m(new Set),style:lC,children:t("desktop.importDeselectAll")??"取消全选"})]}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:p.map(e=>(0,r.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:10,padding:"8px 12px",border:"1px solid var(--border)",borderRadius:6,cursor:"pointer",background:g.has(e.name)?"var(--bg-selected)":"transparent",transition:"background 0.12s"},children:[(0,r.jsx)("input",{type:"checkbox",checked:g.has(e.name),onChange:()=>{var t;return t=e.name,void m(e=>{let o=new Set(e);return o.has(t)?o.delete(t):o.add(t),o})}}),(0,r.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:12,fontWeight:500,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),(0,r.jsxs)("div",{style:{fontSize:11,color:"var(--text-dim)",marginTop:2},children:[e.sessions," ",t("desktop.sessions")??"会话",e.matched&&(0,r.jsxs)("span",{style:{marginLeft:8,color:"var(--accent)"},children:["→ ",t("desktop.importMerged")??"合并到现有项目",e.existingCount>0&&` (${t("desktop.importExistingCount",{count:e.existingCount})??`${e.existingCount} 个已有`})`]}),!e.matched&&(0,r.jsxs)("span",{style:{marginLeft:8,color:"var(--text-muted)"},children:["→ ",t("desktop.importNewProject")??"新建项目"]})]})]})]},e.name))}),(0,r.jsx)("button",{type:"button",onClick:$,disabled:z||0===g.size,style:{display:"inline-flex",alignItems:"center",gap:7,padding:"8px 14px",background:"var(--accent)",border:"none",borderRadius:6,color:"#fff",fontSize:12,fontWeight:600,cursor:0===g.size?"not-allowed":"pointer",alignSelf:"flex-start",opacity:0===g.size?.5:1},children:z?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(K.y,{size:14,style:{animation:"spin 1s linear infinite"}})," ",t("desktop.importing")??"导入中…"]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(E.z,{size:15})," ",t("desktop.importStart")??"开始导入"]})})]}),"reasonix"===s&&0===p.length&&!z&&(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",padding:"12px 0"},children:t("desktop.importNoData")??"未找到 Reasonix 数据。请确认 ~/.reasonix/projects/ 目录存在且包含会话文件。"})]}),f&&!k.done&&(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:12,color:"var(--text)"},children:[(0,r.jsx)(K.y,{size:14,style:{animation:"spin 1s linear infinite"}}),t("desktop.importing")??"导入中…"]}),(0,r.jsx)("div",{style:{height:6,borderRadius:3,background:"var(--bg-panel)",overflow:"hidden"},children:(0,r.jsx)("div",{style:{height:"100%",borderRadius:3,background:"var(--accent)",width:`${k.total>0?(k.imported+k.skipped+k.errors)/k.total*100:0}%`,transition:"width 0.3s ease"}})}),(0,r.jsxs)("div",{style:{fontSize:11,color:"var(--text-dim)"},children:[k.imported+k.skipped+k.errors," / ",k.total,k.skipped>0&&` \xb7 ${t("desktop.importSkippedCount",{skipped:k.skipped})??`${k.skipped} 跳过`}`]})]})]});return o?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("button",{type:"button",onClick:()=>F(!0),style:{display:"flex",alignItems:"center",gap:8,padding:"10px 14px",width:"100%",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:8,color:"var(--text)",fontSize:12,cursor:"pointer"},children:[(0,r.jsx)(E.z,{size:16}),(0,r.jsx)("span",{style:{fontWeight:500},children:t("desktop.importSessions")??"导入会话"})]}),(0,r.jsxs)(lj,{open:W,onClose:()=>F(!1),children:[(0,r.jsxs)("div",{style:{padding:"4px 18px 14px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,r.jsx)("span",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:t("desktop.importSessions")??"导入会话"}),(0,r.jsx)("button",{onClick:()=>F(!1),style:lT,children:(0,r.jsx)(h.X,{size:18})})]}),B]})]}):B}let lC={background:"none",border:"none",color:"var(--accent)",fontSize:11,cursor:"pointer",padding:"2px 4px"},lT={background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",padding:4,display:"flex"},lR="deepseek-vision",lz={padding:"7px 9px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",fontSize:12,fontFamily:"var(--font-mono)",width:"100%",boxSizing:"border-box"};function lI(){return{fontSize:12,color:"var(--text-muted)"}}let lM={padding:"7px 12px",border:"none",borderRadius:6,background:"var(--accent)",color:"#fff",cursor:"pointer",fontSize:12};function lP({sessionId:e}){let{t}=(0,A.s)(),[o,s]=(0,n.useState)(!1),[i,a]=(0,n.useState)(null),[l,d]=(0,n.useState)(!1),[c,p]=(0,n.useState)(null),[u,h]=(0,n.useState)(!1),[g,m]=(0,n.useState)({}),[f,x]=(0,n.useState)(""),[k,v]=(0,n.useState)(""),[y,b]=(0,n.useState)("eager"),[w,j]=(0,n.useState)(!1),[S,C]=(0,n.useState)(null),[T,R]=(0,n.useState)(!1),[z,I]=(0,n.useState)(!1),[M,P]=(0,n.useState)({provider:"custom",baseUrl:"",apiKey:"",model:"",maxTokens:4096,hasApiKey:!1}),[E,W]=(0,n.useState)(""),[F,D]=(0,n.useState)(""),[N,L]=(0,n.useState)(!1),[$,H]=(0,n.useState)(null),[O,B]=(0,n.useState)(!1);(0,n.useEffect)(()=>{let e=!1;return(async()=>{a(null);try{let[t,o]=await Promise.all([fetch("/api/mcp"),fetch("/api/vision-config")]),r=await t.json();if(!t.ok||r.error)throw Error(r.error??`HTTP ${t.status}`);let n=await o.json();if(!o.ok||n.error)throw Error(n.error??`HTTP ${o.status}`);if(e)return;m(r.mcpServers??{}),x(r.filePath);let i=(r.mcpServers??{})[lR];v(i?.command??""),b(i?.lifecycle==="lazy"?"lazy":"eager"),P({provider:n.provider,baseUrl:n.baseUrl,apiKey:"",model:n.model,maxTokens:n.maxTokens,hasApiKey:n.hasApiKey}),n.path&&D(n.path),s(!0)}catch(t){e||a(t instanceof Error?t.message:String(t))}})(),()=>{e=!0}},[]);let U=(0,n.useCallback)(async()=>{if(!k.trim())return void C(t("desktop.mcpVisionCommandRequired"));j(!0),C(null),R(!1),I(!1);try{let e=g[lR],t={...g,[lR]:{...e??{},command:k.trim(),args:Array.isArray(e?.args)?e.args:[],transport:"stdio",lifecycle:y}},o=await fetch("/api/mcp",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({mcpServers:t})}),r=await o.json();if(!o.ok||r.error)throw Error(r.error??`HTTP ${o.status}`);m(t),R(!0)}catch(e){C(e instanceof Error?e.message:String(e))}finally{j(!1)}},[g,k,y,t]),_=(0,n.useCallback)(async()=>{j(!0),C(null),R(!1),I(!1);try{let e={...g};delete e[lR];let t=await fetch("/api/mcp",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({mcpServers:e})}),o=await t.json();if(!t.ok||o.error)throw Error(o.error??`HTTP ${t.status}`);m(e),v(""),b("eager"),I(!0)}catch(e){C(e instanceof Error?e.message:String(e))}finally{j(!1)}},[g]),q=(0,n.useCallback)(async()=>{L(!0),H(null),B(!1);try{let e=await fetch("/api/vision-config",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({...M,...E?{apiKey:E}:{}})}),t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);P({...t,apiKey:"",hasApiKey:t.hasApiKey}),W(""),B(!0)}catch(e){H(e instanceof Error?e.message:String(e))}finally{L(!1)}},[M,E]),V=(0,n.useCallback)(async()=>{if(e){d(!0),p(null),h(!1);try{let t=await fetch("/api/mcp/restart",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:e,name:lR})}),o=await t.json();if(!t.ok||o.error)throw Error(o.error??`HTTP ${t.status}`);h(!0)}catch(e){p(e instanceof Error?e.message:String(e))}finally{d(!1)}}},[e]),K=!!g[lR];return(0,r.jsxs)(lh,{children:[(0,r.jsx)(lg,{children:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:7,padding:"12px 0"},children:[(0,r.jsx)(sR.k,{size:15,"aria-hidden":"true"}),(0,r.jsxs)("div",{style:{minWidth:0},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[(0,r.jsx)("span",{style:{fontSize:13,fontWeight:600,color:"var(--text)"},children:t("desktop.mcpVisionTitle")}),(0,r.jsx)("span",{style:{fontSize:10,padding:"1px 6px",borderRadius:3,background:K?"rgba(37,99,235,0.12)":"rgba(245,158,11,0.12)",color:K?"var(--accent)":"#d97706",textTransform:"capitalize"},children:K?t("desktop.mcpVisionRegistered"):t("desktop.mcpVisionNotRegistered")})]}),(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:2},children:t("desktop.mcpVisionDesc")})]})]})}),o?i?(0,r.jsx)(lm,{children:(0,r.jsx)("div",{style:{padding:"8px 0",fontSize:12,color:"#ef4444"},children:i})}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(lg,{children:(0,r.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",padding:"10px 0 2px"},children:t("desktop.mcpVisionRegistration")})}),(0,r.jsx)(lg,{children:(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(120px, 180px) 1fr",gap:8,alignItems:"center",padding:"6px 0"},children:[(0,r.jsxs)("span",{style:lI(),children:[t("desktop.mcpVisionCommand")," *"]}),(0,r.jsx)("input",{value:k,onChange:e=>v(e.target.value),placeholder:"/path/to/deepseek-vision-mcp",style:lz}),(0,r.jsx)("span",{style:lI(),children:t("desktop.mcpVisionLifecycle")}),(0,r.jsxs)("select",{value:y,onChange:e=>b(e.target.value),style:{...lz,fontFamily:"var(--font-mono)"},children:[(0,r.jsx)("option",{value:"eager",children:"eager"}),(0,r.jsx)("option",{value:"lazy",children:"lazy"})]}),(0,r.jsx)("span",{style:lI(),children:t("desktop.mcpVisionTransport")}),(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",fontFamily:"var(--font-mono)",padding:"7px 0"},children:t("desktop.mcpVisionTransportFixed")})]})}),(0,r.jsx)(lg,{children:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"6px 0",flexWrap:"wrap"},children:[(0,r.jsx)("button",{type:"button",onClick:()=>void U(),disabled:w,style:{...lM,cursor:w?"wait":"pointer"},children:w?t("desktop.saving"):t("desktop.mcpVisionSaveReg")}),K&&(0,r.jsx)("button",{type:"button",onClick:()=>void _(),disabled:w,title:t("desktop.mcpVisionRemove"),style:{padding:"7px 12px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"#ef4444",cursor:w?"not-allowed":"pointer",fontSize:12},children:t("desktop.mcpVisionRemove")}),T&&(0,r.jsx)("span",{style:{color:"#22c55e",fontSize:12},children:t("desktop.mcpVisionSavedReg")}),z&&(0,r.jsx)("span",{style:{color:"#22c55e",fontSize:12},children:t("desktop.mcpVisionRemoved")}),S&&(0,r.jsx)("span",{style:{color:"#ef4444",fontSize:12},children:S})]})}),(0,r.jsx)(lg,{children:(0,r.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",padding:"10px 0 2px"},children:t("desktop.mcpVisionModelConfig")})}),(0,r.jsx)(lg,{children:(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(120px, 180px) 1fr",gap:8,alignItems:"center",padding:"6px 0"},children:[(0,r.jsx)("span",{style:lI(),children:t("desktop.mcpVisionProvider")}),(0,r.jsx)("input",{value:M.provider,onChange:e=>P(t=>({...t,provider:e.target.value})),style:lz}),(0,r.jsx)("span",{style:lI(),children:t("desktop.mcpVisionBaseUrl")}),(0,r.jsx)("input",{value:M.baseUrl,onChange:e=>P(t=>({...t,baseUrl:e.target.value})),style:lz}),(0,r.jsx)("span",{style:lI(),children:t("desktop.mcpVisionApiKey")}),(0,r.jsx)("input",{type:"password",value:E,onChange:e=>W(e.target.value),placeholder:M.hasApiKey?"••••••••":"API key",style:lz}),(0,r.jsx)("span",{style:lI(),children:t("desktop.mcpVisionModel")}),(0,r.jsx)("input",{value:M.model,onChange:e=>P(t=>({...t,model:e.target.value})),style:lz}),(0,r.jsx)("span",{style:lI(),children:t("desktop.mcpVisionMaxTokens")}),(0,r.jsx)("input",{type:"number",min:1,value:M.maxTokens,onChange:e=>P(t=>({...t,maxTokens:Number(e.target.value)||1})),style:lz})]})}),(0,r.jsx)(lm,{children:(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8,padding:"6px 0"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,r.jsx)("button",{type:"button",onClick:()=>void q(),disabled:N,style:{...lM,cursor:N?"wait":"pointer"},children:N?t("desktop.saving"):t("desktop.mcpVisionSaveModel")}),(0,r.jsx)("button",{type:"button",onClick:()=>void V(),disabled:l||!e||!K,title:e?t("desktop.mcpVisionRestartTitle"):t("desktop.mcpVisionRestartNoSession"),style:{padding:"7px 12px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:!l&&e&&K?"pointer":"not-allowed",fontSize:12,opacity:!l&&e&&K?1:.5},children:l?t("desktop.mcpVisionRestarting"):t("desktop.mcpVisionRestart")}),O&&(0,r.jsx)("span",{style:{color:"#22c55e",fontSize:12},children:t("desktop.mcpVisionSavedModel")}),u&&(0,r.jsx)("span",{style:{color:"#22c55e",fontSize:12},children:t("desktop.mcpVisionRestarted")}),$&&(0,r.jsx)("span",{style:{color:"#ef4444",fontSize:12},children:$}),c&&(0,r.jsx)("span",{style:{color:"#ef4444",fontSize:12},children:c})]}),(0,r.jsxs)(lf,{children:[t("desktop.mcpVisionModelNote"),F&&(0,r.jsx)("div",{style:{marginTop:4,fontFamily:"var(--font-mono)",fontSize:10},children:F}),f&&(0,r.jsx)("div",{style:{fontFamily:"var(--font-mono)",fontSize:10},children:f})]})]})})]}):(0,r.jsx)(lm,{children:(0,r.jsx)("div",{style:{padding:"8px 0",fontSize:12,color:"var(--text-muted)"},children:t("desktop.loading")})})]})}function lE({sessionId:e,onApplied:t,onBeforeApply:o}){let{t:s}=(0,A.s)(),[i,a]=(0,n.useState)(!1),[l,d]=(0,n.useState)(!1),[c,p]=(0,n.useState)(null),u=(0,n.useCallback)(async()=>{if(e){a(!0),p(null),d(!1);try{await o?.(),await i6(e,{type:"reload"}),d(!0),await t?.()}catch(e){p(e instanceof Error?e.message:String(e))}finally{a(!1)}}},[e,t,o]),h=i||!e;return(0,r.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[(0,r.jsx)("button",{type:"button",onClick:()=>void u(),disabled:h,title:s(e?"desktop.applyNowTitle":"desktop.applyNowNoSession"),style:{padding:"7px 12px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:h?"not-allowed":"pointer",fontSize:12,opacity:h?.5:1,whiteSpace:"nowrap"},children:s(i?"desktop.applyNowApplying":"desktop.applyNow")}),l&&(0,r.jsx)("span",{style:{color:"#22c55e",fontSize:12},children:s("desktop.applyNowDone")}),c&&(0,r.jsx)("span",{style:{color:"#ef4444",fontSize:12},children:c})]})}let lW=["stdio","sse","http"],lF=["eager","lazy"],lD={name:"",command:"",args:"",transport:"stdio",lifecycle:"eager",requestTimeoutMs:"",env:""},lA={padding:"7px 9px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",fontSize:12,fontFamily:"var(--font-mono)",width:"100%",boxSizing:"border-box"};function lN(){return{fontSize:12,color:"var(--text-muted)"}}function lL(e,t){return{fontSize:10,padding:"1px 6px",borderRadius:3,background:t,color:e,flexShrink:0,textTransform:"capitalize"}}function l$({sessionId:e}){let{t}=(0,A.s)(),[o,s]=(0,n.useState)({}),[i,a]=(0,n.useState)(""),[l,d]=(0,n.useState)(!1),[c,p]=(0,n.useState)(null),[u,h]=(0,n.useState)(null),[g,m]=(0,n.useState)(lD),[x,k]=(0,n.useState)(!1),[y,b]=(0,n.useState)(null),[w,j]=(0,n.useState)(!1),S=(0,n.useCallback)(async()=>{p(null);try{let e=await fetch("/api/mcp"),t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);s(t.mcpServers??{}),a(t.filePath)}catch(e){p(e instanceof Error?e.message:String(e))}finally{d(!0)}},[]);(0,n.useEffect)(()=>{S()},[S]);let C=(0,n.useCallback)(()=>{m(lD),h({name:"",isNew:!0}),b(null),j(!1)},[]),R=(0,n.useCallback)((e,t)=>{m({name:e,command:t.command??"",args:Array.isArray(t.args)?t.args.join("\n"):"",transport:"string"==typeof t.transport?t.transport:"stdio",lifecycle:"string"==typeof t.lifecycle?t.lifecycle:"eager",requestTimeoutMs:"number"==typeof t.requestTimeoutMs?String(t.requestTimeoutMs):"",env:void 0!==t.env?JSON.stringify(t.env,null,2):""}),h({name:e,isNew:!1}),b(null),j(!1)},[]),z=(0,n.useCallback)(async()=>{if(u){k(!0),b(null),j(!1);try{let e=g.name.trim();if(u.isNew&&!e)return void b("Server name is required");if(u.isNew&&!/^[a-zA-Z0-9_-]+$/.test(e))return void b("Allowed characters: a-z, A-Z, 0-9, _ and -");if(u.isNew&&e===lR)return void b(t("desktop.mcpVisionNameReserved"));let r=function(e){if(!e.command.trim())return{error:"Command is required"};let t=e.args.split("\n").map(e=>e.trim()).filter(Boolean),o={command:e.command.trim(),args:t,transport:lW.includes(e.transport)?e.transport:"stdio",lifecycle:lF.includes(e.lifecycle)?e.lifecycle:"eager"};if(""!==e.requestTimeoutMs.trim()){let t=Number(e.requestTimeoutMs);if(!Number.isFinite(t)||t<=0)return{error:"Request timeout must be a positive number"};o.requestTimeoutMs=t}if(""!==e.env.trim())try{o.env=JSON.parse(e.env)}catch{return{error:"Environment must be valid JSON"}}return{server:o}}(g);if(r.error||!r.server)return void b(r.error??"Invalid server");let n={...o};u.isNew?n[e]=r.server:(delete n[u.name],n[g.name.trim()||u.name]=r.server);let i=await fetch("/api/mcp",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({mcpServers:n})}),a=await i.json();if(!i.ok||a.error)throw Error(a.error??`HTTP ${i.status}`);s(n),h(null),j(!0)}catch(e){b(e instanceof Error?e.message:String(e))}finally{k(!1)}}},[u,g,o,t]),I=(0,n.useCallback)(async e=>{k(!0),b(null);try{let t={...o};delete t[e];let r=await fetch("/api/mcp",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({mcpServers:t})}),n=await r.json();if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);s(t),j(!0)}catch(e){b(e instanceof Error?e.message:String(e))}finally{k(!1)}},[o]),M=(0,n.useCallback)((e,t)=>{m(o=>({...o,[e]:t}))},[]),P=Object.entries(o).filter(([e])=>e!==lR);return(0,r.jsx)("div",{style:{flex:1,overflow:"auto",minWidth:0,padding:"20px 22px",display:"flex",flexDirection:"column",gap:16},children:(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:l?c?(0,r.jsx)("div",{style:{fontSize:12,color:"#ef4444"},children:c}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12},children:[(0,r.jsxs)("div",{style:{minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)"},children:t("desktop.mcpServers")}),(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)",marginTop:2,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexShrink:0},children:[(0,r.jsx)(lE,{sessionId:e,onApplied:S}),(0,r.jsxs)("button",{type:"button",onClick:C,style:{display:"flex",alignItems:"center",gap:6,padding:"7px 12px",border:"none",borderRadius:6,background:"var(--accent)",color:"#fff",cursor:"pointer",fontSize:12,flexShrink:0},children:[(0,r.jsx)(v.c,{size:13,"aria-hidden":"true"}),t("desktop.mcpAddServer")]})]})]}),(0,r.jsx)(lf,{children:t("desktop.mcpRestartNote")}),(0,r.jsx)(lP,{sessionId:e}),0!==P.length||u?P.map(([e,o])=>(0,r.jsx)(lh,{children:(0,r.jsx)(lm,{children:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"12px 0",minWidth:0},children:[(0,r.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[(0,r.jsx)("span",{style:{fontSize:13,fontWeight:600,color:"var(--text)",fontFamily:"var(--font-mono)"},children:e}),(0,r.jsx)("span",{style:lL("var(--accent)","rgba(37,99,235,0.12)"),children:o.transport??"stdio"}),(0,r.jsx)("span",{style:lL("#d97706","rgba(245,158,11,0.12)"),children:o.lifecycle??"lazy"})]}),(0,r.jsxs)("div",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)",marginTop:4,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[o.command,Array.isArray(o.args)&&o.args.length>0?` ${o.args.map(e=>e.includes(" ")?`"${e}"`:e).join(" ")}`:""]})]}),(0,r.jsxs)("div",{style:{display:"flex",gap:6,flexShrink:0},children:[(0,r.jsxs)("button",{type:"button",onClick:()=>R(e,o),disabled:x,style:{display:"flex",alignItems:"center",gap:5,padding:"6px 10px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:x?"not-allowed":"pointer",fontSize:12,opacity:x?.5:1},children:[(0,r.jsx)(f.I,{size:12,"aria-hidden":"true"}),t("desktop.mcpEdit")]}),(0,r.jsx)("button",{type:"button",onClick:()=>void I(e),disabled:x,title:t("desktop.mcpDelete"),"aria-label":t("desktop.mcpDelete"),style:{display:"flex",alignItems:"center",padding:"6px 9px",background:"rgba(239,68,68,0.08)",border:"1px solid var(--border)",borderRadius:6,color:"#ef4444",cursor:x?"not-allowed":"pointer",fontSize:12,opacity:x?.5:1},children:(0,r.jsx)(T.l,{size:12,"aria-hidden":"true"})})]})]})})},e)):(0,r.jsx)(lh,{children:(0,r.jsx)(lm,{children:(0,r.jsx)("div",{style:{padding:"14px 0",fontSize:12,color:"var(--text-dim)"},children:o[lR]?t("desktop.mcpEmptyOther"):t("desktop.mcpEmpty")})})}),u&&(0,r.jsxs)(lh,{children:[(0,r.jsx)(lg,{children:(0,r.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)",padding:"12px 0 4px"},children:u.isNew?t("desktop.mcpNewServer"):t("desktop.mcpEditServer",{name:u.name})})}),(0,r.jsx)(lg,{children:(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(150px, 220px) 1fr",gap:"8px 12px",alignItems:"center",padding:"8px 0"},children:[(0,r.jsx)("span",{style:lN(),children:t("desktop.mcpServerName")}),(0,r.jsx)("input",{value:g.name,onChange:e=>M("name",e.target.value),disabled:!u.isNew,placeholder:"my-server",style:{...lA,opacity:u.isNew?1:.5}}),(0,r.jsxs)("span",{style:lN(),children:[t("desktop.mcpCommand")," *"]}),(0,r.jsx)("input",{value:g.command,onChange:e=>M("command",e.target.value),placeholder:"npx @modelcontextprotocol/server-foo",style:lA}),(0,r.jsx)("span",{style:lN(),children:t("desktop.mcpArgs")}),(0,r.jsx)("textarea",{value:g.args,onChange:e=>M("args",e.target.value),placeholder:"--port 3000\n--verbose",rows:3,style:{...lA,resize:"vertical",lineHeight:1.5}}),(0,r.jsx)("span",{style:lN(),children:t("desktop.mcpTransport")}),(0,r.jsx)("select",{value:g.transport,onChange:e=>M("transport",e.target.value),style:{...lA,fontFamily:"var(--font-mono)"},children:lW.map(e=>(0,r.jsx)("option",{value:e,children:e},e))}),(0,r.jsx)("span",{style:lN(),children:t("desktop.mcpLifecycle")}),(0,r.jsx)("select",{value:g.lifecycle,onChange:e=>M("lifecycle",e.target.value),style:{...lA,fontFamily:"var(--font-mono)"},children:lF.map(e=>(0,r.jsx)("option",{value:e,children:e},e))}),(0,r.jsx)("span",{style:lN(),children:t("desktop.mcpRequestTimeoutMs")}),(0,r.jsx)("input",{type:"number",min:1,value:g.requestTimeoutMs,onChange:e=>M("requestTimeoutMs",e.target.value),placeholder:"300000",style:lA}),(0,r.jsx)("span",{style:lN(),children:t("desktop.mcpEnv")}),(0,r.jsx)("textarea",{value:g.env,onChange:e=>M("env",e.target.value),placeholder:'{\n "API_KEY": "..."\n}',rows:3,style:{...lA,resize:"vertical",lineHeight:1.5}})]})}),(0,r.jsx)(lm,{children:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"10px 0"},children:[(0,r.jsx)("button",{type:"button",onClick:()=>void z(),disabled:x,style:{padding:"7px 12px",border:"none",borderRadius:6,background:"var(--accent)",color:"#fff",cursor:x?"wait":"pointer",fontSize:12},children:x?t("desktop.saving"):t("desktop.mcpSave")}),(0,r.jsx)("button",{type:"button",onClick:()=>h(null),disabled:x,style:{padding:"7px 12px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:x?"not-allowed":"pointer",fontSize:12},children:t("desktop.mcpCancel")}),y&&(0,r.jsx)("span",{style:{color:"#ef4444",fontSize:12},children:y})]})})]}),w&&!u&&(0,r.jsx)("div",{style:{fontSize:12,color:"#22c55e"},children:t("desktop.mcpSavedRestart")})]}):(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)"},children:t("desktop.loading")})})})}var lH=o(9210);function lO(){let{t:e}=(0,A.s)(),[t,o]=(0,n.useState)(null),[s,i]=(0,n.useState)([]),[a,l]=(0,n.useState)(!0),[d,c]=(0,n.useState)(!1),[p,u]=(0,n.useState)(!1),[h,g]=(0,n.useState)(null);(0,n.useEffect)(()=>{fetch("/api/settings/title-model").then(e=>e.json()).then(e=>{o(e.value),i(e.models??[])}).catch(()=>{}).finally(()=>l(!1))},[]);let m=null!==t&&!s.some(e=>e.label===t),f=(0,n.useCallback)(async t=>{c(!0),g(null),u(!1);try{let e=await fetch("/api/settings/title-model",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({value:""===t?null:t})}),r=await e.json();if(!e.ok||r.error)return void g(r.error??`HTTP ${e.status}`);o(r.value??null),u(!0),setTimeout(()=>u(!1),2e3)}catch{g(String(e("desktop.titleModelSaveError")))}finally{c(!1)}},[e]),x=[...new Set(s.map(e=>e.provider))];return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6,padding:"12px 18px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",flexShrink:0},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,r.jsx)("span",{style:{fontSize:12,fontWeight:600,color:"var(--text)",whiteSpace:"nowrap"},children:e("desktop.titleModel")}),(0,r.jsxs)("select",{value:t??"",disabled:a||d,onChange:e=>f(e.target.value),style:{flex:1,minWidth:200,maxWidth:420,padding:"6px 9px",fontSize:12,color:"var(--text)",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:5},children:[(0,r.jsx)("option",{value:"",children:e("desktop.titleModelFollowSession")}),m&&null!==t&&(0,r.jsxs)("option",{value:t,style:{color:"#ef4444"},children:[t,"(",e("desktop.titleModelInvalid"),")"]}),x.map(e=>(0,r.jsx)("optgroup",{label:e,children:s.filter(t=>t.provider===e).map(e=>(0,r.jsxs)("option",{value:e.label,children:[e.name||e.id,e.reasoning?"(reasoning)":""]},e.label))},e))]}),d&&(0,r.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:"…"}),!d&&p&&(0,r.jsx)("span",{style:{fontSize:11,color:"#4ade80"},children:e("desktop.titleModelSaved")})]}),(0,r.jsx)("p",{style:{margin:0,fontSize:11,color:"var(--text-muted)",lineHeight:1.5},children:e("desktop.titleModelDescription")}),h&&(0,r.jsx)("p",{style:{margin:0,fontSize:11,color:"#ef4444",lineHeight:1.5},children:h}),m&&null!==t&&(0,r.jsxs)("p",{style:{margin:0,fontSize:11,color:"#ef4444",lineHeight:1.5},children:[t,"(",e("desktop.titleModelInvalid"),")"]})]})}let lB=["name","reasoning","contextWindow","maxTokens","thinkingLevelMap","hidden"];function lU(e){if(""===e.trim())return;let t=Number(e);return Number.isFinite(t)&&t>0?t:void 0}function l_(e){let t=lU(e.contextWindow??""),o=lU(e.maxTokens??""),r=e.thinkingLevelMap&&Object.keys(e.thinkingLevelMap).length>0?{...e.thinkingLevelMap}:void 0;return{...e.name?.trim()?{name:e.name.trim()}:{},..."boolean"==typeof e.reasoning?{reasoning:e.reasoning}:{},...void 0!==t?{contextWindow:t}:{},...void 0!==o?{maxTokens:o}:{},...r?{thinkingLevelMap:r}:{},..."boolean"==typeof e.hidden?{hidden:e.hidden}:{}}}function lq({providerId:e,onRegisterFlush:t,onConfigChange:o}){let{t:s}=(0,A.s)(),i=O(),[a,l]=(0,n.useState)([]),[d,c]=(0,n.useState)({}),[p,u]=(0,n.useState)({}),[h,g]=(0,n.useState)(new Set),[m,f]=(0,n.useState)(!0),[x,k]=(0,n.useState)(!1),[v,y]=(0,n.useState)(null),[b,w]=(0,n.useState)(!1),[j,S]=(0,n.useState)(null),C=(0,n.useRef)(d),T=(0,n.useRef)(p),R=(0,n.useRef)(a),z=(0,n.useRef)(h),I=(0,n.useRef)(0),M=(0,n.useRef)(null);C.current=d,T.current=p,R.current=a,z.current=h,(0,n.useEffect)(()=>{let t=!1;return f(!0),y(null),(async()=>{try{let o=await fetch(`/api/models-config/builtin?provider=${encodeURIComponent(e)}`),r=await o.json();if(!o.ok||r.error)throw Error(r.error??`HTTP ${o.status}`);if(t)return;let n={};for(let e of r.models){let t=r.overrides[e.id]??{};n[e.id]={name:"string"==typeof t.name&&t.name.length>0?t.name:e.name,reasoning:"boolean"==typeof t.reasoning?t.reasoning:e.reasoning,contextWindow:"number"==typeof t.contextWindow?String(t.contextWindow):null!=e.contextWindow?String(e.contextWindow):"",maxTokens:"number"==typeof t.maxTokens?String(t.maxTokens):null!=e.maxTokens?String(e.maxTokens):"",hidden:"boolean"==typeof t.hidden&&t.hidden,thinkingLevelMap:t.thinkingLevelMap??e.thinkingLevelMap}}l(r.models),c(n),u(n),g(new Set)}catch(e){t||y(e instanceof Error?e.message:String(e))}finally{t||f(!1)}})(),()=>{t=!0}},[e]);let P=(0,n.useCallback)((e,t)=>{I.current+=1,c(o=>({...o,[e]:{...o[e]??{},...t}})),g(t=>new Set(t).add(e))},[]),E=(0,n.useCallback)(async()=>{let t=M.current;if(t)return t;let r=(async()=>{let t=new Set(z.current);if(0===t.size)return;let r=I.current,n={...C.current},s={},i={};for(let e of R.current){let t=n[e.id],o=T.current[e.id];t&&(s[e.id]=l_(t)),o&&(i[e.id]=l_(o))}let a=function(e,t,o){let r={};for(let n of e){let e=t[n];if(!e)continue;let s=o[n]??{},i={};for(let t of lB){let o=e[t],r=s[t];JSON.stringify(o)!==JSON.stringify(r)&&(i[t]=void 0===o?null:o)}Object.keys(i).length>0&&(r[n]=i)}return r}(t,s,i);if(0===Object.keys(a).length)return void g(new Set);k(!0),y(null),w(!1);try{let s=await fetch("/api/models-config/builtin",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:e,patches:a})}),i=await s.json();if(!s.ok||i.error)throw Error(i.error??`HTTP ${s.status}`);o?.(i.provider??null);let l={...T.current};for(let e of t){let t=n[e];t&&(l[e]={...t})}T.current=l,u(l),I.current===r&&g(e=>new Set([...e].filter(e=>!t.has(e)))),w(!0),setTimeout(()=>w(!1),2e3)}catch(e){throw y(e instanceof Error?e.message:String(e)),e}finally{k(!1)}})();M.current=r;try{await r}finally{M.current===r&&(M.current=null)}},[o,e]);(0,n.useEffect)(()=>{if(t)return t(e,E)??void 0},[t,e,E]);let[W,F]=(0,n.useState)({phase:"idle"}),[D,N]=(0,n.useState)([]),L=(0,n.useCallback)(async()=>{F({phase:"loading"});try{let t=await fetch("/api/models-config/discover",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerName:e,provider:{}})}),o=await t.json();if(!t.ok||o.error||!o.models)return void F({phase:"error",message:o.error??`HTTP ${t.status}`});let r=new Set(R.current.map(e=>e.id)),n=new Set(o.models.filter(e=>!r.has(e.id)).map(e=>e.id));F({phase:"success",models:o.models,newIds:n}),N(o.models.filter(e=>n.has(e.id)).map(e=>e.id))}catch(e){F({phase:"error",message:e instanceof Error?e.message:String(e)})}},[e]),$=(0,n.useCallback)(async()=>{if(W.models?.length){k(!0),y(null);try{let t=W.models.map(e=>({id:e.id,...e.name?{name:e.name}:{}})),r=await fetch("/api/models-config/builtin",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:e,models:t})}),n=await r.json();if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);o?.(n.provider??null),F({phase:"idle"}),N([]);let s=await fetch(`/api/models-config/builtin?provider=${encodeURIComponent(e)}`);if(s.ok){let e=await s.json();if(e.models){l(e.models),R.current=e.models;let t={};for(let o of e.models){let r=e.overrides?.[o.id]??{};t[o.id]={name:"string"==typeof r.name&&r.name.length>0?r.name:o.name,reasoning:"boolean"==typeof r.reasoning?r.reasoning:o.reasoning,contextWindow:"number"==typeof r.contextWindow?String(r.contextWindow):null!=o.contextWindow?String(o.contextWindow):"",maxTokens:"number"==typeof r.maxTokens?String(r.maxTokens):null!=o.maxTokens?String(o.maxTokens):"",hidden:"boolean"==typeof r.hidden&&r.hidden,thinkingLevelMap:r.thinkingLevelMap??o.thinkingLevelMap}}c(t),u(t),g(new Set)}}}catch(e){y(e instanceof Error?e.message:String(e))}finally{k(!1)}}},[W.models,o,e]);return m?(0,r.jsx)("div",{style:{borderTop:"1px solid var(--border)",marginTop:14,paddingTop:12},children:(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-dim)"},children:s("desktop.modelsLoading")})}):(0,r.jsxs)("div",{style:{borderTop:"1px solid var(--border)",marginTop:14,paddingTop:12,display:"flex",flexDirection:"column",gap:10},children:[(0,r.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)"},children:s("desktop.builtinModelsTitle")}),(0,r.jsxs)("div",{style:{borderTop:"1px solid var(--border)",paddingTop:10,display:"flex",flexDirection:"column",gap:8},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[(0,r.jsx)("button",{type:"button",onClick:()=>{L()},disabled:"loading"===W.phase,style:{padding:"5px 12px",background:(W.phase,"var(--bg-panel)"),border:"1px solid var(--border)",borderRadius:5,color:"loading"===W.phase?"var(--text-dim)":"var(--text-muted)",cursor:"loading"===W.phase?"not-allowed":"pointer",fontSize:12},children:"loading"===W.phase?s("desktop.modelsDiscoveryFetching"):s("desktop.builtinModelsFetchNew")}),"success"===W.phase&&W.models&&(0,r.jsx)("button",{type:"button",onClick:()=>{$()},disabled:x||0===D.length,style:{padding:"5px 12px",background:D.length>0&&!x?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:5,color:D.length>0&&!x?"#fff":"var(--text-dim)",cursor:D.length>0&&!x?"pointer":"not-allowed",fontSize:12,fontWeight:600},children:x?s("desktop.modelsSaving"):`${s("desktop.modelsAddModelManual")} (${D.length})`})]}),"error"===W.phase&&(0,r.jsx)("p",{style:{margin:0,fontSize:11,color:"#f87171"},children:W.message}),"success"===W.phase&&W.models&&(0,r.jsx)("div",{style:{maxHeight:200,overflowY:"auto",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)"},children:W.models.map(e=>{let t=W.newIds?.has(e.id)??!1,o=D.includes(e.id);return(0,r.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:8,minHeight:32,padding:"5px 9px",borderBottom:"1px solid var(--border)",cursor:t?"pointer":"default",opacity:t?1:.55},children:[(0,r.jsx)("input",{type:"checkbox",checked:o,disabled:!t,onChange:t=>{N(o=>t.target.checked?[...o,e.id]:o.filter(t=>t!==e.id))},style:{width:13,height:13,accentColor:"var(--accent)",flexShrink:0}}),(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text)",fontWeight:t?600:400},children:e.name||e.id}),(0,r.jsx)("code",{style:{fontSize:10,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:e.id}),t&&(0,r.jsx)("span",{style:{fontSize:10,padding:"1px 6px",borderRadius:8,background:"var(--accent)",color:"#fff",marginLeft:"auto"},children:"新"})]},e.id)})})]}),v&&(0,r.jsx)("p",{style:{margin:0,fontSize:11,color:"#f87171"},children:v}),0===a.length&&!v&&(0,r.jsx)("p",{style:{margin:0,fontSize:11,color:"var(--text-dim)"},children:s("desktop.builtinModelsEmpty")}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:a.map(e=>{let t=d[e.id]??{},o=j===e.id,n=h.has(e.id);return(0,r.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",padding:"8px 10px"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[(0,r.jsxs)("button",{type:"button",onClick:()=>S(o?null:e.id),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text)",fontSize:12,fontWeight:600,padding:0,textAlign:"left"},children:[t.name||e.name||e.id,n&&(0,r.jsx)("span",{style:{color:"var(--accent)",marginLeft:6},children:"•"})]}),(0,r.jsx)("code",{style:{fontSize:10,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:e.id}),(t.reasoning??e.reasoning)&&(0,r.jsx)("span",{style:{fontSize:10,padding:"1px 6px",borderRadius:8,background:"var(--bg-selected)",color:"var(--text-muted)"},children:"reasoning"}),(0,r.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)"},children:[s("desktop.builtinModelsContext"),": ",(0,r.jsx)("b",{children:t.contextWindow?Number(t.contextWindow).toLocaleString():"—"})," \xb7 ",s("desktop.builtinModelsMaxTokens"),": ",(0,r.jsx)("b",{children:t.maxTokens?Number(t.maxTokens).toLocaleString():"—"})]})]}),o&&(0,r.jsxs)("div",{style:{marginTop:10,display:"flex",flexDirection:"column",gap:10},children:[(0,r.jsxs)("label",{style:{display:"flex",gap:6,alignItems:"center",fontSize:12,color:"var(--text)",width:"100%"},children:[s("desktop.modelsName"),(0,r.jsx)("input",{type:"text",value:t.name??"",placeholder:e.name||e.id,onChange:t=>P(e.id,{name:t.target.value.trim()||void 0}),style:{flex:1,minWidth:0,padding:"4px 7px",fontSize:11,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:4,color:"var(--text)",fontFamily:"var(--font-mono)"}}),(0,r.jsxs)("label",{style:{display:"flex",gap:4,alignItems:"center",fontSize:11,color:t.hidden?"#f87171":"var(--text-muted)",cursor:"pointer",whiteSpace:"nowrap",marginLeft:8},children:[(0,r.jsx)("input",{type:"checkbox",checked:!0===t.hidden,onChange:t=>P(e.id,{hidden:t.target.checked})}),s("desktop.builtinModelsHide")]})]}),(0,r.jsxs)("div",{style:{display:"flex",gap:16,flexWrap:"wrap",flexDirection:i?"column":"row",alignItems:i?"flex-start":"center"},children:[(0,r.jsxs)("label",{style:{display:"flex",gap:6,alignItems:"center",fontSize:12,color:"var(--text)",cursor:"pointer"},children:[(0,r.jsx)("input",{type:"checkbox",checked:!0===t.reasoning,onChange:t=>P(e.id,{reasoning:t.target.checked})}),s("desktop.builtinModelsReasoning")]}),(0,r.jsxs)("label",{style:{display:"flex",gap:6,alignItems:"center",fontSize:12,color:"var(--text)",flex:i?1:void 0,width:i?"100%":void 0},children:[s("desktop.modelsContextWindow"),(0,r.jsx)("input",{type:"number",min:1,value:t.contextWindow??"",placeholder:null!=e.contextWindow?String(e.contextWindow):"",onChange:t=>P(e.id,{contextWindow:t.target.value}),style:{flex:1,minWidth:0,padding:"4px 7px",fontSize:11,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:4,color:"var(--text)",fontFamily:"var(--font-mono)"}})]}),(0,r.jsxs)("label",{style:{display:"flex",gap:6,alignItems:"center",fontSize:12,color:"var(--text)",flex:i?1:void 0,width:i?"100%":void 0},children:[s("desktop.modelsMaxOutputTokens"),(0,r.jsx)("input",{type:"number",min:1,value:t.maxTokens??"",placeholder:null!=e.maxTokens?String(e.maxTokens):"",onChange:t=>P(e.id,{maxTokens:t.target.value}),style:{flex:1,minWidth:0,padding:"4px 7px",fontSize:11,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:4,color:"var(--text)",fontFamily:"var(--font-mono)"}})]})]}),(0,r.jsx)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-dim)"},children:s("desktop.builtinModelsThinking")}),(0,r.jsx)(l5,{value:t.thinkingLevelMap,onChange:t=>P(e.id,{thinkingLevelMap:t})})]})]},e.id)})}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,r.jsx)("button",{type:"button",onClick:()=>{E().catch(()=>{})},disabled:x||0===h.size,style:{alignSelf:"flex-start",padding:"5px 14px",background:h.size>0&&!x?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:5,color:h.size>0&&!x?"#fff":"var(--text-dim)",cursor:h.size>0&&!x?"pointer":"not-allowed",fontSize:12,fontWeight:600},children:x?s("desktop.modelsSaving"):b?s("desktop.modelsSaved"):s("desktop.modelsSave")}),h.size>0&&(0,r.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:s("desktop.builtinModelsDirty",{count:h.size})})]})]})}let lV=["openai-completions","openai-responses","anthropic-messages","google-generative-ai","mistral-conversations"],lK="__custom__";function lG(){let{t:e}=(0,A.s)();return(0,n.useCallback)((t,o)=>e(t,o),[e])}function lJ({label:e,children:t}){return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)("label",{style:{fontSize:11,color:"var(--text-muted)",fontWeight:500},children:e}),t]})}let lY={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 lX({value:e,onChange:t,placeholder:o,mono:n,inputRef:s}){return(0,r.jsx)("input",{ref:s,value:e,onChange:e=>t(e.target.value),placeholder:o,style:{...lY,fontFamily:n?"var(--font-mono)":"inherit"}})}function lZ({value:e,onChange:t,placeholder:o,mono:s,onKeyDown:i,autoComplete:a="off",spellCheck:l=!1,style:d}){let c=lG(),[p,u]=(0,n.useState)(!1);return(0,n.useEffect)(()=>{e||u(!1)},[e]),(0,r.jsxs)("div",{style:{position:"relative",width:"100%",...d},children:[(0,r.jsx)("input",{type:p?"text":"password",value:e,onChange:e=>t(e.target.value),onKeyDown:i,placeholder:o,style:{...lY,paddingRight:34,fontFamily:s?"var(--font-mono)":"inherit"},autoComplete:a,spellCheck:l}),(0,r.jsx)("button",{type:"button",onClick:()=>u(e=>!e),"aria-label":c(p?"desktop.modelsHideApiKey":"desktop.modelsShowApiKey"),title:c(p?"desktop.modelsHideApiKey":"desktop.modelsShowApiKey"),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:p?(0,r.jsx)(lH.G,{size:15}):(0,r.jsx)(sR.b,{size:15})})]})}function lQ({value:e,onChange:t,placeholder:o}){return(0,r.jsx)("input",{type:"number",value:e,onChange:e=>t(e.target.value),placeholder:o,style:lY})}function l0({value:e,onChange:t,options:o,required:n}){let s=lG();return(0,r.jsxs)("select",{value:e,onChange:e=>t(e.target.value),style:{...lY,color:e?"var(--text)":"var(--text-dim)"},children:[!n&&(0,r.jsx)("option",{value:"",children:s("desktop.modelsInheritNone")}),o.map(e=>(0,r.jsx)("option",{value:e,children:e},e))]})}function l1({label:e,checked:t,onChange:o}){return(0,r.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:6,cursor:"pointer",fontSize:12,color:"var(--text-muted)"},children:[(0,r.jsx)("input",{type:"checkbox",checked:t,onChange:e=>o(e.target.checked),style:{width:13,height:13,accentColor:"var(--accent)",cursor:"pointer"}}),e]})}function l2({children:e}){return(0,r.jsx)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:2},children:e})}function l4({name:e,provider:t,onChange:o,onRename:s,onDelete:i,onAddModels:a,onAddModel:l}){let d=lG(),[c,p]=(0,n.useState)(e),[u,h]=(0,n.useState)({phase:"idle"}),[g,m]=(0,n.useState)(""),[f,x]=(0,n.useState)([]),k=(0,n.useRef)(0),v=(0,n.useRef)(null);(0,n.useEffect)(()=>p(e),[e]);let y=(e,r)=>o({...t,[e]:r});(0,n.useEffect)(()=>{t.api||o({...t,api:"openai-completions"})},[t.api]),(0,n.useEffect)(()=>{k.current+=1,h({phase:"idle"}),m(""),x([])},[e,t.baseUrl,t.api,t.apiKey]);let b=(0,n.useCallback)(async()=>{if("loading"===u.phase)return;let o=++k.current;h({phase:"loading"}),x([]);try{let r=await fetch("/api/models-config/discover",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerName:e,provider:{...t,models:void 0}})}),n=await r.json();if(o!==k.current)return;if(!r.ok||n.error||!n.models)return void h({phase:"error",message:n.error??`HTTP ${r.status}`});h({phase:"success",models:n.models,endpoint:n.endpoint??t.baseUrl??""})}catch(e){if(o!==k.current)return;h({phase:"error",message:e instanceof Error?e.message:String(e)})}},[u.phase,e,t]),w=new Set((t.models??[]).map(e=>e.id)),j="success"===u.phase?u.models:[],S=g.trim().toLocaleLowerCase(),C=j.filter(e=>!S||e.id.toLocaleLowerCase().includes(S)||e.name?.toLocaleLowerCase().includes(S)),T=C.slice(0,300),R=T.filter(e=>!w.has(e.id)).map(e=>e.id),z=f.filter(e=>!w.has(e)).length,I=R.length>0&&R.every(e=>f.includes(e)),M=!I&&R.some(e=>f.includes(e));return(0,n.useEffect)(()=>{v.current&&(v.current.indeterminate=M)},[M]),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,r.jsx)(l2,{children:d("desktop.modelsProvider")}),(0,r.jsx)("button",{onClick:i,style:{padding:"3px 8px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:4,color:"#ef4444",cursor:"pointer",fontSize:11},children:d("desktop.delete")})]}),(0,r.jsxs)(lJ,{label:d("desktop.modelsProviderName"),children:[(0,r.jsx)(lX,{value:c,onChange:p,placeholder:"provider-name",mono:!0}),c!==e&&c.trim()&&(0,r.jsx)("button",{onClick:()=>s(c.trim()),style:{marginTop:4,padding:"3px 10px",background:"var(--accent)",border:"none",borderRadius:4,color:"#fff",cursor:"pointer",fontSize:11,alignSelf:"flex-start"},children:d("desktop.rename")})]}),(0,r.jsx)(lJ,{label:d("desktop.modelsBaseUrl"),children:(0,r.jsx)(lX,{value:t.baseUrl??"",onChange:e=>y("baseUrl",e||void 0),placeholder:"http(s)://host:port/v1",mono:!0})}),(0,r.jsxs)(lJ,{label:d("desktop.modelsApiKey"),children:[(0,r.jsx)(lZ,{value:t.apiKey??"",onChange:e=>y("apiKey",e||void 0),placeholder:d("desktop.modelsApiKeyPlaceholder"),mono:!0}),(0,r.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:d("desktop.modelsApiKeyHelp")})]}),(0,r.jsx)(lJ,{label:d("desktop.modelsApi"),children:(0,r.jsx)(l0,{value:t.api??"openai-completions",onChange:e=>y("api",e),options:lV,required:!0})}),(0,r.jsxs)("div",{style:{borderTop:"1px solid var(--border)",paddingTop:14,display:"flex",flexDirection:"column",gap:10},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:["success"!==u.phase&&(0,r.jsx)("button",{onClick:b,disabled:"loading"===u.phase,style:{height:30,padding:"0 12px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:t.baseUrl?.trim()&&"loading"!==u.phase?"var(--text-muted)":"var(--text-dim)",cursor:t.baseUrl?.trim()&&"loading"!==u.phase?"pointer":"not-allowed",fontSize:11},children:"loading"===u.phase?d("desktop.modelsDiscoveryFetching"):d("desktop.modelsDiscoveryFetch")}),(0,r.jsx)("button",{onClick:l,title:d("desktop.modelsAddModelManual"),style:{height:30,padding:"0 12px",border:"none",borderRadius:5,background:"var(--accent)",color:"#fff",cursor:"pointer",fontSize:11,fontWeight:600},children:d("desktop.modelsAddModelManual")})]}),"error"===u.phase&&(0,r.jsx)("div",{style:{padding:"7px 9px",border:"1px solid rgba(239,68,68,0.3)",borderRadius:5,color:"#ef4444",fontSize:11,lineHeight:1.4},children:u.message}),"success"===u.phase&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("input",{value:g,onChange:e=>m(e.target.value),placeholder:d("desktop.modelsDiscoveryFilterPlaceholder",{count:u.models.length}),"aria-label":d("desktop.modelsDiscoveryFilter"),style:{...lY,width:"100%",minWidth:0}}),(0,r.jsxs)("div",{style:{maxHeight:220,overflowY:"auto",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)"},children:[(0,r.jsxs)("label",{style:{minHeight:32,padding:"5px 9px",display:"flex",alignItems:"center",gap:8,position:"sticky",top:0,zIndex:1,borderBottom:"1px solid var(--border)",background:"var(--bg)",cursor:R.length?"pointer":"default",color:"var(--text-muted)",fontSize:10,fontWeight:600},children:[(0,r.jsx)("input",{ref:v,type:"checkbox",checked:I,disabled:0===R.length,onChange:()=>{let e=new Set(R);x(t=>I?t.filter(t=>!e.has(t)):Array.from(new Set([...t,...R])))},style:{width:13,height:13,accentColor:"var(--accent)",flexShrink:0}}),d("desktop.modelsDiscoverySelectShown")]}),0===T.length?(0,r.jsx)("div",{style:{padding:12,color:"var(--text-dim)",fontSize:11},children:d("desktop.modelsDiscoveryNoMatches")}):T.map((e,t)=>{let o=w.has(e.id),n=f.includes(e.id);return(0,r.jsxs)("label",{style:{minHeight:36,padding:"6px 9px",display:"flex",alignItems:"center",gap:8,borderTop:0===t?"none":"1px solid var(--border)",cursor:o?"default":"pointer",opacity:o?.65:1},children:[(0,r.jsx)("input",{type:"checkbox",checked:n||o,disabled:o,onChange:()=>{var t;return t=e.id,void x(e=>e.includes(t)?e.filter(e=>e!==t):[...e,t])},style:{width:13,height:13,accentColor:"var(--accent)",flexShrink:0}}),(0,r.jsxs)("span",{style:{minWidth:0,flex:1},children:[(0,r.jsx)("span",{style:{display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text)",fontSize:11},children:e.name??e.id}),e.name&&(0,r.jsx)("code",{style:{display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontSize:10,fontFamily:"var(--font-mono)"},children:e.id})]}),o&&(0,r.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10},children:d("desktop.modelsDiscoveryAdded")})]},e.id)})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:10},children:[(0,r.jsx)("span",{title:u.endpoint,style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontSize:10},children:C.length>T.length?d("desktop.modelsDiscoveryShowing",{shown:T.length,total:C.length}):d("desktop.modelsDiscoveryFetched",{count:u.models.length})}),(0,r.jsx)("button",{onClick:()=>{if("success"!==u.phase)return;let e=new Set(f),t=u.models.filter(t=>e.has(t.id)&&!w.has(t.id));0!==t.length&&(a(t),x([]))},disabled:0===z,style:{height:28,padding:"0 11px",border:"none",borderRadius:5,background:z?"var(--accent)":"var(--bg-panel)",color:z?"#fff":"var(--text-dim)",cursor:z?"pointer":"not-allowed",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:z?d("desktop.modelsDiscoveryAddSelectedCount",{count:z}):d("desktop.modelsDiscoveryAddSelected")})]})]})]})]})}let l6=["off","minimal","low","medium","high","xhigh","max"],l8={off:"var(--text-dim)",minimal:"var(--text-muted)",low:"#60a5fa",medium:"#a78bfa",high:"#f472b6",xhigh:"#fb923c",max:"#ef4444"};function l5({value:e,onChange:t}){let o=lG(),n=e??{},s=(e,o)=>{let r={...n};"omit"===o?delete r[e]:r[e]=o,t(Object.keys(r).length?r:void 0)};return(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:2},children:l6.map(e=>{let t=n[e],i=e in n?null===t?"null":"string":"omit",a="string"==typeof t?t:"",l=l8[e],d={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)"},c={background:"var(--accent)",color:"#fff",fontWeight:600};return(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"5px 4px",borderRadius:6,background:"transparent",border:"1px solid transparent"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:5,width:68,flexShrink:0},children:[(0,r.jsx)("span",{style:{width:6,height:6,borderRadius:"50%",background:l,flexShrink:0,opacity:"null"===i?.3:1}}),(0,r.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,r.jsxs)("div",{style:{display:"flex",borderRadius:5,border:"1px solid var(--border)",overflow:"hidden",flexShrink:0},children:[(0,r.jsx)("button",{onClick:()=>s(e,"omit"),style:{...d,..."omit"===i?c:{}},children:o("desktop.modelsDefault")}),(0,r.jsx)("button",{onClick:()=>s(e,null),style:{...d,borderLeft:"1px solid var(--border)",..."null"===i?{background:"#ef4444",color:"#fff",fontWeight:600}:{}},children:o("desktop.modelsDisabled")})]}),(0,r.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,r.jsx)("button",{onClick:()=>s(e,a||e),style:{...d,..."string"===i?c:{},borderRight:"1px solid var(--border)",flexShrink:0},children:o("desktop.modelsCustom")}),(0,r.jsx)("input",{value:a,onChange:t=>s(e,t.target.value),onFocus:()=>{"string"!==i&&s(e,a||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 l3={thinkingFormat:"deepseek",requiresReasoningContentOnAssistantMessages:!0};function l7({providerName:e,provider:t,model:o,onChange:s,onDelete:i}){let a=lG(),[l,d]=(0,n.useState)({phase:"idle"}),[c,p]=(0,n.useState)({phase:"idle"}),u=(0,n.useRef)(0),h=(0,n.useRef)(null),g=(e,t)=>s({...o,[e]:t}),f=(()=>{if("idle"===l.phase)return null;if("testing"===l.phase)return a("desktop.modelsTestingConnection");let e=[void 0!==l.latencyMs?`${l.latencyMs}ms`:null,void 0!==l.status?`HTTP ${l.status}`:null].filter(Boolean);return"success"===l.phase?[a("desktop.modelsConnected"),...e,l.responseText||null].filter(Boolean).join(" \xb7 "):[a("desktop.modelsFailed"),...e,l.message].filter(Boolean).join(" \xb7 ")})();(0,n.useEffect)(()=>{d({phase:"idle"})},[e,t.baseUrl,t.api,t.apiKey,o.id,o.api]);let x=(0,n.useCallback)(async()=>{if(o.id.trim()&&"testing"!==l.phase){d({phase:"testing"});try{let r=await fetch("/api/models-config/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerName:e,provider:t,model:o})}),n=await r.json();if(!r.ok||!n.ok)return void d({phase:"error",message:n.error??`HTTP ${r.status}`,latencyMs:n.latencyMs,status:n.status});d({phase:"success",latencyMs:n.latencyMs,status:n.status,responseText:n.responseText})}catch(e){d({phase:"error",message:e instanceof Error?e.message:String(e)})}}},[o,t,e,l.phase]);(0,n.useEffect)(()=>{u.current+=1,p({phase:"idle"}),h.current=null},[e,t.baseUrl,o.id]);let k=(0,n.useCallback)(async()=>{let r=o.id.trim();if(!r||"loading"===c.phase)return;let n=++u.current;p({phase:"loading"});try{let i=new URLSearchParams({q:r,provider:e,limit:"50"});t.baseUrl?.trim()&&i.set("baseUrl",t.baseUrl.trim());let a=await fetch(`/api/models-config/catalog?${i}`),l=await a.json();if(n!==u.current)return;if(!a.ok||l.error||!l.recommendation)return void p({phase:"error",message:l.error??`HTTP ${a.status}`});let d=function(e,t){let o={...e},r=0;if(!e.name?.trim()&&t.name&&(o.name=t.name,r+=1),void 0===e.reasoning&&!0===t.reasoning&&(o.reasoning=!0,r+=1),!e.input?.length&&t.input?.length&&(o.input=[...t.input],r+=1),void 0===e.contextWindow&&void 0!==t.contextWindow&&(o.contextWindow=t.contextWindow,r+=1),void 0===e.maxTokens&&void 0!==t.maxTokens&&(o.maxTokens=t.maxTokens,r+=1),t.cost){let n={...e.cost??{}},s=!1;for(let e of["input","output","cacheRead","cacheWrite"])void 0===n[e]&&void 0!==t.cost[e]&&(n[e]=t.cost[e],s=!0,r+=1);s&&(o.cost=n)}return{model:o,appliedCount:r}}(o,l.recommendation.preset);d.appliedCount>0&&(h.current=o,s(d.model)),p({phase:"success",recommendation:l.recommendation,appliedCount:d.appliedCount})}catch(e){if(n!==u.current)return;p({phase:"error",message:e instanceof Error?e.message:String(e)})}},[c.phase,o,s,t.baseUrl,e]),v=(()=>{if("success"!==c.phase)return null;let{recommendation:t,appliedCount:o}=c,r=o>0?a("desktop.modelsCatalogFilled",{count:o}):a("desktop.modelsCatalogNoEmptyFields");if("unreliable"===t.price.status){let e="no-exact-match"===t.price.reason?a("desktop.modelsCatalogNoExactMatch"):a("desktop.modelsCatalogPriceUnreliable");return`${r} \xb7 ${e}`}let n="provider"===t.price.method?a("desktop.modelsCatalogPriceProvider",{provider:t.price.providerName??t.price.providerId??e}):"base-url"===t.price.method?a("desktop.modelsCatalogPriceBaseUrl",{provider:t.price.providerName??t.price.providerId??e}):a("desktop.modelsCatalogPriceConsensus",{support:t.price.support,total:t.price.total});return`${r} \xb7 ${n}`})(),y="error"===c.phase?c.message:v,b="error"===c.phase?"#ef4444":"success"===c.phase&&"unreliable"===c.recommendation.price.status?"#d97706":"var(--text-dim)";return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,r.jsx)(l2,{children:a("desktop.modelsModelSection")}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[f&&(0,r.jsx)("span",{title:f,style:{maxWidth:260,height:24,padding:"0 8px",border:`1px solid ${"error"===l.phase?"#fecaca":"success"===l.phase?"#bbf7d0":"var(--border)"}`,borderRadius:4,background:"error"===l.phase?"#fee2e2":"success"===l.phase?"#dcfce7":"#e5e7eb",color:"#111827",fontSize:11,display:"inline-flex",alignItems:"center",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",boxSizing:"border-box"},children:f}),(0,r.jsxs)("button",{onClick:x,disabled:!o.id.trim()||"testing"===l.phase,title:a("desktop.modelsTestConnection"),style:{height:24,padding:"0 8px",background:"success"===l.phase?"#16a34a":"none",border:`1px solid ${"success"===l.phase?"#16a34a":"var(--border)"}`,borderRadius:4,color:"success"===l.phase?"#fff":o.id.trim()&&"testing"!==l.phase?"var(--text-muted)":"var(--text-dim)",cursor:o.id.trim()&&"testing"!==l.phase?"pointer":"not-allowed",fontSize:11,display:"inline-flex",alignItems:"center",justifyContent:"center",boxSizing:"border-box",gap:5},children:["success"===l.phase&&(0,r.jsx)(m.S,{size:11}),"testing"===l.phase?a("desktop.modelsTesting"):"success"===l.phase?a("desktop.modelsOk"):a("desktop.modelsTest")]}),(0,r.jsx)("button",{onClick:i,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:a("desktop.modelsRemove")})]})]}),(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[(0,r.jsx)(lJ,{label:a("desktop.modelsIdRequired"),children:(0,r.jsx)(lX,{value:o.id,onChange:e=>g("id",e),placeholder:"model-id",mono:!0})}),(0,r.jsx)(lJ,{label:a("desktop.modelsName"),children:(0,r.jsx)(lX,{value:o.name??"",onChange:e=>g("name",e||void 0),placeholder:a("desktop.modelsDisplayName")})})]}),(0,r.jsxs)("div",{style:{padding:"10px 0",borderTop:"1px solid var(--border)",borderBottom:"1px solid var(--border)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[(0,r.jsx)("button",{onClick:()=>void k(),disabled:!o.id.trim()||"loading"===c.phase,style:{height:28,padding:"0 10px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:o.id.trim()&&"loading"!==c.phase?"var(--text-muted)":"var(--text-dim)",cursor:o.id.trim()&&"loading"!==c.phase?"pointer":"not-allowed",fontSize:11},children:"loading"===c.phase?a("desktop.modelsCatalogFilling"):a("desktop.modelsCatalogFill")}),(0,r.jsx)("a",{href:"https://github.com/anomalyco/models.dev",target:"_blank",rel:"noreferrer",style:{marginLeft:"auto",color:"var(--text-dim)",fontSize:10,textDecoration:"none"},children:a("desktop.modelsCatalogSource")})]}),(0,r.jsxs)("div",{"aria-live":"polite",style:{marginTop:6,height:20,display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,color:b,fontSize:10},children:[(0,r.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:y}),"success"===c.phase&&h.current&&(0,r.jsx)("button",{onClick:()=>{let e=h.current;e&&(h.current=null,s(e),p({phase:"idle"}))},style:{background:"none",border:"none",color:"var(--accent)",cursor:"pointer",fontSize:10,flexShrink:0},children:a("desktop.modelsCatalogUndo")})]})]}),(0,r.jsx)(lJ,{label:a("desktop.modelsApiOverride"),children:(0,r.jsx)(l0,{value:o.api??"",onChange:e=>g("api",e||void 0),options:lV})}),(0,r.jsxs)("div",{style:{display:"flex",gap:20,flexWrap:"wrap"},children:[(0,r.jsx)(l1,{label:a("desktop.modelsReasoningThinking"),checked:o.reasoning??!1,onChange:e=>g("reasoning",e||void 0)}),(0,r.jsx)(l1,{label:a("desktop.modelsImageInput"),checked:o.input?.includes("image")??!1,onChange:e=>g("input",e?["text","image"]:void 0)})]}),o.reasoning&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(l1,{label:a("desktop.modelsDeepSeekCompat"),checked:o.compat?.thinkingFormat==="deepseek",onChange:e=>s(function(e,t){if(t)return{...e,compat:{...e.compat??{},...l3}};if(!e.compat)return e;let o={...e.compat};return delete o.thinkingFormat,delete o.requiresReasoningContentOnAssistantMessages,{...e,compat:Object.keys(o).length?o:void 0}}(o,e))}),(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:8},children:[(0,r.jsx)(l2,{children:a("desktop.modelsThinkingLevelMap")}),o.thinkingLevelMap&&(0,r.jsx)("button",{onClick:()=>g("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:a("desktop.modelsClearAll")})]}),(0,r.jsx)(l5,{value:o.thinkingLevelMap,onChange:e=>g("thinkingLevelMap",e)})]})]}),(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[(0,r.jsx)(lJ,{label:a("desktop.modelsContextWindow"),children:(0,r.jsx)(lQ,{value:void 0!==o.contextWindow?String(o.contextWindow):"",onChange:e=>g("contextWindow",e?parseInt(e):void 0),placeholder:"128000"})}),(0,r.jsx)(lJ,{label:a("desktop.modelsMaxOutputTokens"),children:(0,r.jsx)(lQ,{value:void 0!==o.maxTokens?String(o.maxTokens):"",onChange:e=>g("maxTokens",e?parseInt(e):void 0),placeholder:"16384"})})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(l2,{children:a("desktop.modelsCostPerMillionTokens")}),(0,r.jsx)("div",{style:{marginTop:8,display:"grid",gridTemplateColumns:"1fr 1fr 1fr 1fr",gap:8},children:["input","output","cacheRead","cacheWrite"].map(e=>(0,r.jsx)(lJ,{label:e,children:(0,r.jsx)(lQ,{value:o.cost?.[e]!==void 0?String(o.cost[e]):"",onChange:t=>{let r;return r=parseFloat(t),void s({...o,cost:{...o.cost??{},[e]:isNaN(r)?void 0:r}})},placeholder:"0"})},e))})]})]})}function l9({provider:e,onRefresh:t,onRegisterBuiltinFlush:o,onBuiltinProviderChange:s}){let i=lG(),[a,l]=(0,n.useState)({phase:"idle"}),[d,c]=(0,n.useState)(""),p=(0,n.useRef)(null),u=(0,n.useRef)(null);(0,n.useEffect)(()=>{("auth"===a.phase||"prompt"===a.phase)&&setTimeout(()=>u.current?.focus(),50)},[a.phase]),(0,n.useEffect)(()=>{l({phase:"idle"}),c(""),p.current?.close(),p.current=null},[e.id]),(0,n.useEffect)(()=>()=>{p.current?.close()},[]);let h=(0,n.useCallback)(()=>{p.current?.close(),l({phase:"connecting"}),c("");let o=new EventSource(`/api/auth/login/${encodeURIComponent(e.id)}`);p.current=o,o.onmessage=e=>{let r=JSON.parse(e.data);"auth"===r.type?(l({phase:"auth",url:r.url,instructions:r.instructions??null,token:r.token}),window.open(r.url,"_blank","noopener,noreferrer")):"device_code"===r.type?(l({phase:"device_code",userCode:r.userCode,verificationUri:r.verificationUri,intervalSeconds:r.intervalSeconds??null,expiresInSeconds:r.expiresInSeconds??null}),window.open(r.verificationUri,"_blank","noopener,noreferrer")):"prompt_request"===r.type?l({phase:"prompt",message:r.message,placeholder:r.placeholder??null,token:r.token}):"select_request"===r.type?l({phase:"select",message:r.message,options:r.options??[],token:r.token}):"progress"===r.type?l({phase:"progress",message:r.message}):"success"===r.type?(o.close(),l({phase:"success"}),t()):"error"===r.type?(o.close(),l({phase:"error",message:r.message})):"cancelled"===r.type&&(o.close(),l({phase:"idle"}))},o.onerror=()=>{o.close(),l(e=>"success"===e.phase?e:{phase:"error",message:i("desktop.modelsConnectionLost")})}},[e.id,t,i]),g=(0,n.useCallback)(async()=>{try{let t=await fetch(`/api/auth/logout/${encodeURIComponent(e.id)}`,{method:"POST"});if(t.ok)l({phase:"idle"});else{let e=await t.json().catch(()=>null);l({phase:"error",message:409===t.status?i("desktop.modelsAuthenticationStateChanged"):e?.error??`HTTP ${t.status}`})}}catch(e){l({phase:"error",message:e instanceof Error?e.message:String(e)})}finally{t()}},[e.id,t,i]),m=(0,n.useCallback)(async(t,o)=>{if(o.trim()){l({phase:"progress",message:i("desktop.modelsVerifying")});try{let r=await fetch(`/api/auth/login/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:t,code:o.trim()})});if(!r.ok){let e=await r.json().catch(()=>({}));l({phase:"error",message:e.error??i("desktop.modelsServerError",{status:r.status})});return}c("")}catch(e){l({phase:"error",message:e instanceof Error?e.message:i("desktop.modelsNetworkError")})}}},[e.id,i]),f=(0,n.useCallback)(async(t,o)=>{l({phase:"progress",message:i("desktop.modelsContinuing")});try{let r=await fetch(`/api/auth/login/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:t,code:o})});if(!r.ok){let e=await r.json().catch(()=>({}));l({phase:"error",message:e.error??i("desktop.modelsServerError",{status:r.status})})}}catch(e){l({phase:"error",message:e instanceof Error?e.message:i("desktop.modelsNetworkError")})}},[e.id,i]),x="connecting"===a.phase||"progress"===a.phase||"auth"===a.phase||"device_code"===a.phase||"prompt"===a.phase||"select"===a.phase;return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,r.jsx)(l2,{children:i("desktop.modelsSubscription")}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,r.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:e.loggedIn?"#4ade80":"var(--border)",display:"inline-block"}}),(0,r.jsx)("span",{style:{fontSize:11,color:e.loggedIn?"#4ade80":"var(--text-dim)"},children:e.loggedIn?i("desktop.modelsConnected"):i("desktop.modelsNotConnected")})]})]}),(0,r.jsxs)("div",{style:{minHeight:48},children:["idle"===a.phase&&(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:e.loggedIn?i("desktop.modelsAlreadyConnected"):i("desktop.modelsConnectAccount",{provider:e.name})}),"connecting"===a.phase&&(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)"},children:i("desktop.modelsOpeningBrowser")}),"select"===a.phase&&(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:a.message}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:a.options.map(e=>(0,r.jsx)("button",{onClick:()=>f(a.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"===a.phase||"prompt"===a.phase)&&(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:"auth"===a.phase?i("desktop.modelsCompleteSignIn"):a.message}),"auth"===a.phase&&(0,r.jsxs)("p",{style:{margin:0,fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:[i("desktop.modelsBrowserDidNotOpen")," ",(0,r.jsx)("a",{href:a.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)",wordBreak:"break-all"},children:i("desktop.modelsOpenLoginPage")}),"."]}),(0,r.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,r.jsx)("input",{ref:u,value:d,onChange:e=>c(e.target.value),onKeyDown:e=>{"Enter"===e.key&&m(a.token,d)},placeholder:"auth"===a.phase?"http://localhost:1455/auth/callback?code=…":a.placeholder??i("desktop.modelsEnterValue"),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,r.jsx)("button",{onClick:()=>m(a.token,d),disabled:!d.trim(),style:{padding:"6px 12px",background:d.trim()?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:5,color:d.trim()?"#fff":"var(--text-dim)",cursor:d.trim()?"pointer":"not-allowed",fontSize:12,fontWeight:600,flexShrink:0},children:i("desktop.submit")})]})]}),"device_code"===a.phase&&(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:i("desktop.modelsOpenVerificationPage")}),(0,r.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:a.userCode}),(0,r.jsxs)("p",{style:{margin:0,fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:[(0,r.jsx)("a",{href:a.verificationUri,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)",wordBreak:"break-all"},children:a.verificationUri}),a.expiresInSeconds?` ${i("desktop.modelsExpiresInMinutes",{count:Math.ceil(a.expiresInSeconds/60)})}`:""]})]}),"progress"===a.phase&&(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)"},children:a.message}),"success"===a.phase&&(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"#4ade80"},children:i("desktop.modelsConnectedSuccessfully")}),"error"===a.phase&&(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"#f87171"},children:a.message})]}),(0,r.jsx)("div",{style:{display:"flex",gap:8},children:x?(0,r.jsx)("button",{onClick:()=>{p.current?.close(),l({phase:"idle"})},style:{padding:"5px 12px",background:"none",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:i("desktop.cancel")}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{onClick:h,style:{padding:"5px 14px",background:"var(--accent)",border:"none",borderRadius:5,color:"#fff",cursor:"pointer",fontSize:12,fontWeight:600},children:e.loggedIn?i("desktop.modelsReLogin"):i("desktop.modelsLogin")}),e.loggedIn&&(0,r.jsx)("button",{onClick:g,style:{padding:"5px 12px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:5,color:"#ef4444",cursor:"pointer",fontSize:12},children:i("desktop.modelsDisconnect")})]})}),(0,r.jsx)(lq,{providerId:e.id,onRegisterFlush:o,onConfigChange:s})]})}function de({provider:e,onRefresh:t,onRegisterBuiltinFlush:o,onBuiltinProviderChange:s}){let i=lG(),[a,l]=(0,n.useState)(""),[d,c]=(0,n.useState)(!1),[p,u]=(0,n.useState)(!1),[h,g]=(0,n.useState)(null),[f,x]=(0,n.useState)(!1);(0,n.useEffect)(()=>{l(""),g(null),x(!1)},[e.id]);let k=(0,n.useCallback)(async()=>{if(a.trim()){c(!0),g(null),x(!1);try{let o=await fetch(`/api/auth/api-key/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:a.trim()})}),r=await o.json();!o.ok||r.error?g(r.error??`HTTP ${o.status}`):(l(""),x(!0),setTimeout(()=>x(!1),2e3),t())}catch(e){g(String(e))}finally{c(!1)}}},[a,e.id,t]),v=(0,n.useCallback)(async()=>{u(!0),g(null);try{let t=await fetch(`/api/auth/api-key/${encodeURIComponent(e.id)}`,{method:"DELETE"}),o=await t.json();(!t.ok||o.error)&&g(409===t.status?i("desktop.modelsAuthenticationStateChanged"):o.error??`HTTP ${t.status}`)}catch(e){g(String(e))}finally{t(),u(!1)}},[e.id,t,i]);return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,r.jsx)(l2,{children:i("desktop.modelsApiKey")}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,r.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:e.configured?"#4ade80":"var(--border)",display:"inline-block"}}),(0,r.jsx)("span",{style:{fontSize:11,color:e.configured?"#4ade80":"var(--text-dim)"},children:e.configured?i("desktop.modelsConfigured"):i("desktop.modelsNotConfigured")})]})]}),(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:e.configured?i("desktop.modelsApiKeyStored"):i("desktop.modelsEnableModels",{provider:e.displayName,count:e.modelCount,models:1===e.modelCount?i("desktop.modelsSingular"):i("desktop.modelsPlural")})}),(0,r.jsx)(lJ,{label:i("desktop.modelsApiKey"),children:(0,r.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,r.jsx)(lZ,{value:a,onChange:l,onKeyDown:e=>{"Enter"===e.key&&a.trim()&&k()},placeholder:e.configured?i("desktop.modelsEnterNewKey"):"sk-…",style:{flex:1},autoComplete:"off",spellCheck:!1,mono:!0}),(0,r.jsxs)("button",{onClick:k,disabled:d||!a.trim()||f,style:{padding:"6px 12px",background:f?"#16a34a":a.trim()?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:5,color:a.trim()||f?"#fff":"var(--text-dim)",cursor:d||!a.trim()||f?"not-allowed":"pointer",fontSize:12,fontWeight:600,flexShrink:0,display:"flex",alignItems:"center",gap:5},children:[f&&(0,r.jsx)(m.S,{size:12}),f?i("desktop.modelsSaved"):d?i("desktop.modelsSaving"):i("desktop.modelsSave")]})]})}),h&&(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"#f87171"},children:h}),e.configured&&(0,r.jsx)("button",{onClick:v,disabled:p,style:{alignSelf:"flex-start",padding:"5px 12px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:5,color:"#ef4444",cursor:p?"not-allowed":"pointer",fontSize:12},children:p?i("desktop.modelsRemoving"):i("desktop.modelsDisconnect")}),(0,r.jsx)(lq,{providerId:e.id,onRegisterFlush:o,onConfigChange:s})]})}function dt({oauthProviders:e,apiKeyProviders:t,onSelectOAuth:o,onSelectApiKey:s,onAddCustom:i,onClose:a}){let l=lG(),[d,c]=(0,n.useState)(""),p=(0,n.useRef)(null);(0,n.useEffect)(()=>{setTimeout(()=>p.current?.focus(),30)},[]);let h=d.trim().toLowerCase(),g=e.filter(e=>!e.loggedIn&&(!h||e.name.toLowerCase().includes(h))),m=t.filter(e=>!e.configured&&(!h||e.displayName.toLowerCase().includes(h)||e.id.toLowerCase().includes(h))),f=!h||"custom".includes(h)||"openai-compatible".includes(h)||"anthropic-compatible".includes(h),x=g.length+m.length+ +!!f,k={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,r.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&&a()},children:(0,r.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,r.jsxs)("div",{style:{padding:"10px 14px",borderBottom:"1px solid var(--border)",flexShrink:0,display:"flex",alignItems:"center",gap:8},children:[(0,r.jsx)(u.$,{size:13,style:{color:"var(--text-dim)",flexShrink:0}}),(0,r.jsx)("input",{ref:p,value:d,onChange:e=>c(e.target.value),onKeyDown:e=>{"Escape"===e.key&&a()},placeholder:l("desktop.modelsSearchProviders"),style:{flex:1,background:"none",border:"none",outline:"none",color:"var(--text)",fontSize:13,boxSizing:"border-box"}})]}),(0,r.jsx)("div",{style:{flex:1,overflowY:"auto",padding:14},children:0===x?(0,r.jsx)("div",{style:{padding:"20px 0",fontSize:12,color:"var(--text-dim)",textAlign:"center"},children:l("desktop.modelsNoProvidersMatch")}):(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(min(240px, 100%), 1fr))",gap:8},children:[f&&(0,r.jsx)("div",{style:{gridColumn:"1 / -1",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:l("desktop.modelsCustom")}),f&&(0,r.jsxs)("button",{onClick:()=>{i(),a()},style:k,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,r.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l("desktop.modelsCompatibleProvider")}),(0,r.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:l("desktop.modelsCustomEndpointFormat")})]}),(0,r.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,r.jsx)(v.c,{size:13,style:{color:"var(--text-dim)"}})})]}),g.length>0&&(0,r.jsx)("div",{style:{gridColumn:"1 / -1",paddingTop:6*!!f,fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:l("desktop.modelsSubscriptions")}),g.map(e=>(0,r.jsxs)("button",{onClick:()=>{o(e.id),a()},style:k,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,r.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),(0,r.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:"OAuth"})]}),(0,r.jsx)(is,{id:e.id,size:28})]},e.id)),m.length>0&&(0,r.jsx)("div",{style:{gridColumn:"1 / -1",paddingTop:6*(g.length>0),fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:l("desktop.modelsApiKey")}),m.map(e=>(0,r.jsxs)("button",{onClick:()=>{s(e.id),a()},style:k,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,r.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.displayName}),(0,r.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:l("desktop.modelsCount",{count:e.modelCount})})]}),(0,r.jsx)(is,{id:e.id,size:28})]},e.id))]})})]})})}function dr({existingProviders:e,onCancel:t,onSubmit:o}){let s=lG(),[i,a]=(0,n.useState)(""),[l,d]=(0,n.useState)(lV[0]),[c,p]=(0,n.useState)(lV[0]),[u,h]=(0,n.useState)(""),[g,m]=(0,n.useState)(""),[f,x]=(0,n.useState)(void 0),[k,y]=(0,n.useState)(!1),[b,w]=(0,n.useState)(""),[j,S]=(0,n.useState)(""),[C,T]=(0,n.useState)(""),[R,z]=(0,n.useState)(""),I=(0,n.useRef)(null);(0,n.useEffect)(()=>{setTimeout(()=>I.current?.focus(),30)},[]);let M=!u.trim()||/^https?:\/\//i.test(u.trim());return(0,r.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&&t()},children:(0,r.jsxs)("div",{style:{width:480,maxWidth:"calc(100vw - 32px)",maxHeight:"min(82vh, 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,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,r.jsx)("span",{style:{fontSize:14,fontWeight:700,color:"var(--text)"},children:s("desktop.modelsAddCustomTitle")}),(0,r.jsx)("button",{onClick:t,"aria-label":s("desktop.modelsClose"),title:s("desktop.modelsClose"),style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),(0,r.jsxs)("div",{style:{padding:16,overflowY:"auto",display:"flex",flexDirection:"column",gap:14},children:[(0,r.jsx)(lJ,{label:s("desktop.modelsProviderNameOptional"),children:(0,r.jsx)(lX,{value:i,onChange:a,placeholder:"new-provider",mono:!0,inputRef:I})}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)(l2,{children:s("desktop.modelsCallFormat")}),(0,r.jsxs)("select",{value:c,onChange:e=>{let t=e.target.value;(p(t),t===lK)?y(!0):d(t)},style:lY,children:[lV.map(e=>(0,r.jsx)("option",{value:e,children:e},e)),(0,r.jsx)("option",{value:lK,children:s("desktop.modelsCustomCallFormat")})]}),(0,r.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)"},children:s("desktop.modelsCallFormatHelp")}),c===lK&&(0,r.jsx)("span",{style:{fontSize:10,color:"#d97706",lineHeight:1.4},children:s("desktop.modelsCustomCallFormatHelp")})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)(l2,{children:s("desktop.modelsImportProvider")}),(0,r.jsxs)("select",{value:R,onChange:t=>{var o;let r;return z(o=t.target.value),void((r=e.find(e=>e.name===o))&&(r.provider.api&&(d(r.provider.api),p(r.provider.api)),h(r.provider.baseUrl??""),m(r.provider.apiKey??""),x(r.provider.headers?{...r.provider.headers}:void 0)))},style:{...lY,color:R?"var(--text)":"var(--text-dim)"},children:[(0,r.jsx)("option",{value:"",children:s("desktop.modelsImportProviderPlaceholder")}),e.map(e=>(0,r.jsxs)("option",{value:e.name,children:[e.name,e.provider.api?` \xb7 ${e.provider.api}`:""]},e.name))]}),R&&(0,r.jsxs)("span",{style:{fontSize:10,color:"#4ade80"},children:[s("desktop.modelsImported"),": ",R]})]}),(0,r.jsxs)("div",{style:{borderTop:"1px solid var(--border)",paddingTop:12,display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)(l2,{children:s("desktop.modelsFullUrl")}),k?(0,r.jsxs)("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[(0,r.jsx)(lX,{value:u,onChange:h,placeholder:s("desktop.modelsUrlPlaceholder"),mono:!0}),(0,r.jsx)("button",{onClick:()=>{y(!1),h("")},title:s("desktop.modelsRemove"),style:{flexShrink:0,width:28,height:28,background:"none",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-dim)",cursor:"pointer",fontSize:14,lineHeight:1,display:"flex",alignItems:"center",justifyContent:"center"},children:"\xd7"})]}):(0,r.jsxs)("button",{onClick:()=>y(!0),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,padding:"7px 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:[(0,r.jsx)(v.c,{size:12}),s("desktop.modelsAddUrl")]}),u.trim()&&!M&&(0,r.jsx)("span",{style:{fontSize:10,color:"#ef4444"},children:s("desktop.modelsUrlInvalid")}),(0,r.jsxs)(lJ,{label:s("desktop.modelsApiKey"),children:[(0,r.jsx)(lZ,{value:g,onChange:m,placeholder:s("desktop.modelsApiKeyPlaceholder"),mono:!0}),(0,r.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:s("desktop.modelsApiKeyHelp")})]})]}),(0,r.jsxs)("div",{style:{borderTop:"1px solid var(--border)",paddingTop:12,display:"flex",flexDirection:"column",gap:10},children:[(0,r.jsx)(l2,{children:s("desktop.modelsCustomRequest")}),(0,r.jsxs)(lJ,{label:s("desktop.modelsRequestModelId"),children:[(0,r.jsx)(lX,{value:b,onChange:w,placeholder:"model-id",mono:!0}),(0,r.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:s("desktop.modelsRequestModelIdHelp")})]}),(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[(0,r.jsx)(lJ,{label:s("desktop.modelsRequestContextLength"),children:(0,r.jsx)(lQ,{value:j,onChange:S,placeholder:"128000"})}),(0,r.jsx)(lJ,{label:s("desktop.modelsRequestOutputLength"),children:(0,r.jsx)(lQ,{value:C,onChange:T,placeholder:"16384"})})]})]})]}),(0,r.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,padding:"10px 16px",borderTop:"1px solid var(--border)",flexShrink:0},children:[(0,r.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:s("desktop.cancel")}),(0,r.jsx)("button",{onClick:()=>{let e=b.trim()?{id:b.trim(),...parseInt(j,10)>0?{contextWindow:parseInt(j,10)}:{},...parseInt(C,10)>0?{maxTokens:parseInt(C,10)}:{}}:void 0;o({name:i.trim(),api:l,...u.trim()?{baseUrl:u.trim()}:{},...g.trim()?{apiKey:g.trim()}:{},...f?{headers:f}:{},model:e})},disabled:!M,style:{padding:"6px 16px",background:M?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:6,color:M?"#fff":"var(--text-dim)",cursor:M?"pointer":"not-allowed",fontSize:13,fontWeight:600},children:s("desktop.modelsAdd")})]})]})})}function dn({embedded:e=!1,sessionId:t,onCloseAction:o,onSavedAction:s,onRegisterFlush:i}){let a=lG(),l=O(),[d,c]=(0,n.useState)({providers:{}}),[p,u]=(0,n.useState)(!0),[h,g]=(0,n.useState)(!1),[f,x]=(0,n.useState)(null),[k,v]=(0,n.useState)(!1),[y,b]=(0,n.useState)(null),[w,j]=(0,n.useState)([]),[S,C]=(0,n.useState)([]),[T,R]=(0,n.useState)(!1),[I,M]=(0,n.useState)(!1),[P,E]=(0,n.useState)({oauth:!1,apiKey:!1}),W=(0,n.useRef)({providers:{}}),F=(0,n.useRef)(new Map),D=(0,n.useRef)(0),A=(0,n.useRef)(!1);W.current=d;let N=(0,n.useCallback)(e=>{let t=e(W.current);return W.current=t,D.current+=1,c(t),t},[]),L=(0,n.useCallback)(()=>{fetch("/api/auth/combined").then(e=>e.json()).then(e=>{j(e.oauth??[]),C(e.apiKey??[])}).catch(()=>{}).finally(()=>E({oauth:!0,apiKey:!0}))},[]),$=(0,n.useCallback)((e,t)=>(F.current.set(e,t),()=>{F.current.get(e)===t&&F.current.delete(e)}),[]),H=(0,n.useCallback)(async()=>{for(let e of[...F.current.values()])await e()},[]);(0,n.useEffect)(()=>{if(i)return i(H)??void 0},[H,i]);let B=(0,n.useCallback)((e,t)=>{N(o=>{let r={...o.providers??{}};return t?r[e]=t:delete r[e],{...o,providers:r}}),s?.()},[s,N]),U=(0,n.useCallback)(async e=>{if(!A.current){A.current=!0,x(null);try{await H(),b(e)}catch(e){x(e instanceof Error?e.message:String(e))}finally{A.current=!1}}},[H]);(0,n.useEffect)(()=>{fetch("/api/models-config").then(e=>e.json()).then(e=>{let t=e.providers?e:{...e,providers:{}};W.current=t,D.current+=1,c(t)}).catch(()=>{let e={providers:{}};W.current=e,D.current+=1,c(e)}).finally(()=>u(!1)),L()},[L]);let _=(0,n.useCallback)(async e=>{if(!A.current){A.current=!0,x(null);try{await H();let t=e.name.trim()||"new-provider",o=t,r=1;for(;W.current.providers?.[o];)o=`${t}-${r++}`;let n={api:e.api||"openai-completions",...e.baseUrl?{baseUrl:e.baseUrl}:{},...e.apiKey?{apiKey:e.apiKey}:{},...e.headers?{headers:e.headers}:{},...e.model?{models:[e.model]}:{}};N(e=>({...e,providers:{...e.providers??{},[o]:n}})),b({type:"provider",name:o}),M(!1)}catch(e){x(e instanceof Error?e.message:String(e))}finally{A.current=!1}}},[H,N]),q=(0,n.useCallback)((e,t)=>{N(o=>({...o,providers:{...o.providers??{},[e]:t}}))},[N]),V=(0,n.useCallback)((e,t)=>{N(o=>{let r=Object.entries(o.providers??{}),n=r.findIndex(([t])=>t===e);return -1===n?o:(r[n]=[t,r[n][1]],{...o,providers:Object.fromEntries(r)})}),b(o=>o?"provider"===o.type&&o.name===e?{type:"provider",name:t}:"model"===o.type&&o.providerName===e?{...o,providerName:t}:o:o)},[N]),K=(0,n.useCallback)(e=>{let t=Object.keys(N(t=>{let o={...t.providers??{}};return delete o[e],{...t,providers:o}}).providers??{});b(t.length>0?{type:"provider",name:t[0]}:null)},[N]),G=(0,n.useCallback)(async e=>{if(!A.current){A.current=!0,x(null);try{await H();let t=N(t=>{let o=t.providers?.[e]??{},r=[...o.models??[],{id:""}];return{...t,providers:{...t.providers??{},[e]:{...o,models:r}}}}),o=(t.providers?.[e]?.models?.length??1)-1;b({type:"model",providerName:e,index:o})}catch(e){x(e instanceof Error?e.message:String(e))}finally{A.current=!1}}},[H,N]),J=(0,n.useCallback)((e,t)=>{N(o=>{let r=o.providers?.[e]??{},n=[...r.models??[]],s=new Set(n.map(e=>e.id));for(let e of t)s.has(e.id)||(s.add(e.id),n.push({id:e.id,name:e.name}));return{...o,providers:{...o.providers??{},[e]:{...r,models:n}}}})},[N]),Y=(0,n.useCallback)((e,t,o)=>{N(r=>{let n=r.providers?.[e]??{},s=[...n.models??[]];return s[t]=o,{...r,providers:{...r.providers??{},[e]:{...n,models:s}}}})},[N]),X=(0,n.useCallback)(async(e,t)=>{if(!A.current){A.current=!0,x(null);try{await H(),N(o=>{let r=o.providers?.[e]??{},n=[...r.models??[]];return n.splice(t,1),{...o,providers:{...o.providers??{},[e]:{...r,models:n.length?n:void 0}}}}),b({type:"provider",name:e})}catch(e){x(e instanceof Error?e.message:String(e))}finally{A.current=!1}}},[H,N]),Z=(0,n.useCallback)(async()=>{if(!h){g(!0),x(null),v(!1);try{await H();let e=W.current,t=await fetch("/api/models-config",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),o=await t.json();if(!t.ok||o.error)throw Error(o.error??`HTTP ${t.status}`);o.config&&(W.current=o.config,D.current+=1,c(o.config)),v(!0),s?.(),setTimeout(()=>v(!1),2e3)}catch(e){x(e instanceof Error?e.message:String(e))}finally{g(!1)}}},[H,s,h]),Q=(0,n.useCallback)(async()=>{try{await H(),o?.()}catch(e){x(e instanceof Error?e.message:String(e))}},[H,o]),ee=Object.entries(d.providers??{}),et=new Set([...w.map(e=>e.id),...S.map(e=>e.id)]),eo=ee.filter(([e])=>!et.has(e)),er=w.filter(e=>e.loggedIn),en=S.filter(e=>e.configured);(0,n.useEffect)(()=>{if(y||p||!P.oauth||!P.apiKey)return;let e=er[0]?{type:"oauth",providerId:er[0].id}:en[0]?{type:"apikey",providerId:en[0].id}:eo[0]?.[0]?{type:"provider",name:eo[0][0]}:null;e&&b(e)},[en,er,eo,p,P.apiKey,P.oauth,y]);let es=(()=>{if(!y)return null;if("oauth"===y.type){let e=w.find(e=>e.id===y.providerId);return e?(0,r.jsx)(l9,{provider:e,onRefresh:L,onRegisterBuiltinFlush:$,onBuiltinProviderChange:t=>B(e.id,t)},e.id):null}if("apikey"===y.type){let e=S.find(e=>e.id===y.providerId);return e?(0,r.jsx)(de,{provider:e,onRefresh:L,onRegisterBuiltinFlush:$,onBuiltinProviderChange:t=>B(e.id,t)},e.id):null}if("provider"===y.type){let e=d.providers?.[y.name];return e?(0,r.jsx)(l4,{name:y.name,provider:e,onChange:e=>q(y.name,e),onRename:e=>V(y.name,e),onDelete:()=>K(y.name),onAddModels:e=>J(y.name,e),onAddModel:()=>{G(y.name)}},y.name):null}let e=d.providers?.[y.providerName],t=e?.models?.[y.index];return t?(0,r.jsx)(l7,{providerName:y.providerName,provider:e,model:t,onChange:e=>Y(y.providerName,y.index,e),onDelete:()=>{X(y.providerName,y.index)}},`${y.providerName}-${y.index}`):null})();return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{style:e?{display:"flex",flex:1,minWidth:0,minHeight:0,overflow:"hidden"}:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:t=>{e||t.target!==t.currentTarget||Q()},children:(0,r.jsxs)("div",{style:e?{flex:1,minWidth:0,minHeight:0,display:"flex",flexDirection:"column",overflow:"hidden"}:{width:l?"calc(100vw - 16px)":860,maxWidth:"calc(100vw - 16px)",height:l?"calc(100dvh - 16px)":"78vh",maxHeight:"calc(100dvh - 16px)",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:[!e&&(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 18px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10},children:[(0,r.jsx)("span",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:a("desktop.models")}),(0,r.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:"~/.pi/agent/models.json"})]}),(0,r.jsx)("button",{onClick:()=>{Q()},"aria-label":a("desktop.modelsClose"),title:a("desktop.modelsClose"),style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),(0,r.jsx)(lO,{}),(0,r.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:l?"column":"row",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{width:l?"100%":210,maxHeight:l?"40vh":void 0,borderRight:l?"none":"1px solid var(--border)",borderBottom:l?"1px solid var(--border)":"none",display:"flex",flexDirection:"column",flexShrink:0,background:"var(--bg-panel)"},children:[(0,r.jsxs)("div",{style:{flex:1,overflowY:"auto",padding:"8px 6px"},children:[er.map(e=>{let t=y?.type==="oauth"&&y.providerId===e.id;return(0,r.jsxs)("div",{onClick:()=>{U({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,r.jsx)(is,{id:e.id,size:16}),(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name})]},e.id)}),en.map(e=>{let t=y?.type==="apikey"&&y.providerId===e.id;return(0,r.jsxs)("div",{onClick:()=>{U({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,r.jsx)(is,{id:e.id,size:16}),(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.displayName})]},e.id)}),(er.length>0||en.length>0)&&eo.length>0&&(0,r.jsx)("div",{style:{margin:"4px 8px",borderTop:"1px solid var(--border)"}}),p?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:a("desktop.modelsLoading")}):eo.map(([e,t])=>{let o=y?.type==="provider"&&y.name===e,n=t.models??[];return(0,r.jsxs)("div",{style:{marginBottom:2},children:[(0,r.jsxs)("div",{onClick:()=>{U({type:"provider",name:e})},style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",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,r.jsx)(z.G,{size:11,style:{color:"var(--text-dim)",flexShrink:0}}),(0,r.jsx)("span",{style:{fontSize:12,fontWeight:o?600:400,color:"var(--text)",fontFamily:"var(--font-mono)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e})]}),n.map((t,o)=>{let n=y?.type==="model"&&y.providerName===e&&y.index===o;return(0,r.jsxs)("div",{onClick:()=>{U({type:"model",providerName:e,index:o})},style:{display:"flex",alignItems:"center",gap:6,padding:"5px 8px 5px 26px",borderRadius:5,cursor:"pointer",background:n?"var(--bg-selected)":"none"},onMouseEnter:e=>{n||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{n||(e.currentTarget.style.background="none")},children:[(0,r.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||a("desktop.modelsNewModel")}),t.reasoning&&(0,r.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"})]},o)}),(0,r.jsx)("div",{onClick:t=>{t.stopPropagation(),G(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,r.jsx)("span",{style:{fontSize:11},children:a("desktop.modelsAddModel")})})]},e)})]}),(0,r.jsx)("div",{style:{borderTop:"1px solid var(--border)",padding:"8px 6px"},children:(0,r.jsx)("button",{onClick:()=>R(!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:a("desktop.modelsAddProvider")})})]}),(0,r.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:p?null:es??(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:a("desktop.modelsSelectProviderOrModel")})})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:10,padding:"10px 18px",borderTop:"1px solid var(--border)",flexShrink:0},children:[f&&(0,r.jsx)("span",{style:{fontSize:12,color:"#f87171",flex:1},children:f}),!e&&(0,r.jsx)("button",{onClick:()=>{Q()},style:{padding:"6px 14px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:13},children:a("desktop.cancel")}),(0,r.jsx)(lE,{sessionId:t,onBeforeApply:Z}),(0,r.jsxs)("button",{onClick:Z,disabled:h||k,style:{position:"relative",padding:"6px 16px",minWidth:92,background:k?"#16a34a":h?"var(--bg-panel)":"var(--accent)",border:"none",borderRadius:6,color:k?"#fff":h?"var(--text-muted)":"#fff",cursor:h||k?"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:k?"saved-pop 0.45s ease":void 0},children:[k&&(0,r.jsx)(m.S,{size:14,style:{strokeDasharray:18,animation:"saved-check-draw 0.35s ease forwards",flexShrink:0}}),(0,r.jsx)("span",{children:k?a("desktop.modelsSaved"):h?a("desktop.modelsSaving"):a("desktop.modelsSave")})]})]})]})}),T&&(0,r.jsx)(dt,{oauthProviders:w,apiKeyProviders:S,onSelectOAuth:e=>{U({type:"oauth",providerId:e})},onSelectApiKey:e=>{U({type:"apikey",providerId:e})},onAddCustom:()=>{R(!1),M(!0)},onClose:()=>R(!1)}),I&&(0,r.jsx)(dr,{existingProviders:eo.map(([e,t])=>({name:e,provider:t})),onCancel:()=>M(!1),onSubmit:e=>{_(e)}})]})}function ds(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function di(e){let t=e.trim().match(/^\$?\s*pi\s+install\s+(\S+)\s*$/);return t?.[1]??e}function da(e){return`${e.scope}\0${e.source}`}function dl(e,t){if(e.disabled)return t("desktop.disabled");let o=[e.counts.extensions?t("desktop.extensionsCount",{count:e.counts.extensions}):"",e.counts.skills?t("desktop.skillsCount",{count:e.counts.skills}):"",e.counts.prompts?t("desktop.promptsCount",{count:e.counts.prompts}):"",e.counts.themes?t("desktop.themesCount",{count:e.counts.themes}):""].filter(Boolean);return o.length?o.join(" \xb7 "):t("desktop.noResources")}function dd(e,t){let o=[];return e.version&&o.push(t("desktop.installedVersion",{version:e.version})),e.configuredVersion&&o.push(t("desktop.configuredVersion",{version:e.configuredVersion})),o.length?o.join(" \xb7 "):t("desktop.unknown")}function dc(e){return"loaded"===e?"var(--accent)":"installed"===e?"#f59e0b":"disabled"===e?"var(--text-dim)":"#ef4444"}function dp({pkg:e}){let{t}=(0,A.s)(),o=[["extension",t("desktop.extensions")],["skill",t("desktop.skills")],["prompt",t("desktop.prompts")],["theme",t("desktop.themes")]].map(([t,o])=>({kind:t,label:o,resources:e.resources.filter(e=>e.kind===t)})).filter(e=>e.resources.length>0);return 0===o.length?(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)"},children:t(e.disabled?"desktop.packageDisabled":"desktop.noResolvedResources")}):(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:12},children:o.map((e,t)=>(0,r.jsxs)("div",{style:{borderTop:0===t?"none":"1px solid var(--border)",paddingTop:12*(0!==t)},children:[(0,r.jsx)("div",{style:{fontSize:10,fontWeight:700,color:"var(--text-dim)",textTransform:"uppercase",marginBottom:6},children:e.label}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:e.resources.map(e=>(0,r.jsxs)("div",{style:{minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:e.path,children:e.name}),(0,r.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:1},title:e.path,children:e.relativePath})]},`${e.kind}:${e.path}`))})]},e.kind))})}function du({scope:e}){let{t}=(0,A.s)();return(0,r.jsx)("span",{style:{fontSize:10,padding:"1px 5px",borderRadius:3,flexShrink:0,background:"project"===e?"rgba(99,102,241,0.12)":"rgba(120,120,120,0.12)",color:"project"===e?"rgba(99,102,241,0.85)":"var(--text-dim)"},children:t(`desktop.${e}`)})}function dh(e,t){return{padding:"6px 12px",background:t?"rgba(239,68,68,0.08)":"none",border:"1px solid var(--border)",borderRadius:6,color:t?"#ef4444":"var(--text-muted)",cursor:e?"not-allowed":"pointer",fontSize:12,opacity:e?.5:1}}function dg({enabled:e,loading:t,onToggle:o,label:n}){return(0,r.jsx)("button",{type:"button",onClick:o,disabled:t,title:n,"aria-label":n,"aria-pressed":e,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",opacity:t?.65:1},children:(0,r.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 dm({value:e,onChange:t}){let{t:o}=(0,A.s)();return(0,r.jsx)("div",{style:{display:"inline-flex",border:"1px solid var(--border)",borderRadius:7,overflow:"hidden",height:30},children:["global","project"].map(n=>{let s=e===n;return(0,r.jsx)("button",{onClick:()=>t(n),style:{width:76,border:"none",borderRight:"global"===n?"1px solid var(--border)":"none",background:s?"var(--bg-selected)":"none",color:s?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12},children:o(`desktop.${n}`)},n)})})}function df({cwd:e,source:t,scope:o,busy:s,actionError:i,onSourceChange:a,onScopeChange:l,onInstall:d}){let{t:c}=(0,A.s)(),p=(0,n.useRef)(null);return(0,n.useEffect)(()=>{p.current?.focus()},[]),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:18,maxWidth:660,minHeight:"100%"},children:[(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,flexWrap:"wrap"},children:[(0,r.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)"},children:c("desktop.addPluginTitle")}),(0,r.jsx)("a",{href:"https://pi.dev/packages",target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)",fontSize:12,textDecoration:"none",whiteSpace:"nowrap"},children:"pi.dev/packages ↗"})]}),(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:"project"===o?`${ds(e)}/.pi/agent/{npm,git}`:"~/.pi/agent/{npm,git}"})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:7},children:[(0,r.jsx)("label",{htmlFor:"plugin-source",style:{fontSize:12,fontWeight:600,color:"var(--text-muted)"},children:c("desktop.pluginSource")}),(0,r.jsx)("input",{id:"plugin-source",ref:p,value:t,onChange:e=>a(e.target.value),onPaste:e=>{let t=e.clipboardData.getData("text"),o=di(t);o!==t&&(e.preventDefault(),a(o))},onBlur:e=>a(di(e.currentTarget.value)),placeholder:"npm:@scope/package",style:{width:"100%",height:36,padding:"0 11px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:13,outline:"none"},onKeyDown:e=>{"Enter"===e.key&&t.trim()&&!s&&d()}})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,r.jsx)(dm,{value:o,onChange:l}),(0,r.jsx)("button",{type:"button",onClick:d,disabled:s||!t.trim(),style:{...dh(s||!t.trim()),background:"var(--accent)",color:"white",borderColor:"var(--accent)"},children:c(s?"desktop.installing":"desktop.install")})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:7},children:[(0,r.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text-muted)"},children:c("desktop.examples")}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:["npm:@scope/pi-plugin","git:https://github.com/user/repo","/absolute/path/to/plugin"].map(e=>(0,r.jsx)("button",{type:"button",onClick:()=>a(e),style:{width:"100%",minHeight:30,textAlign:"left",padding:"6px 9px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-dim)",cursor:"pointer",fontFamily:"var(--font-mono)",fontSize:11},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-panel)",e.currentTarget.style.color="var(--text-dim)"},children:e},e))})]}),i&&(0,r.jsx)("div",{style:{fontSize:12,color:"#ef4444",whiteSpace:"pre-wrap"},children:i})]})}function dx({pkg:e,cwd:t,busyKey:o,actionError:n,actionMessage:s,sessionId:i,onAction:a,onReloadSession:l}){let{t:d}=(0,A.s)(),c=da(e),p=o?.endsWith(c)??!1,u="reload"===o,h=!e.disabled;return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:20,maxWidth:680},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:12,minWidth:0,flexWrap:"wrap"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:180,flex:1},children:[(0,r.jsx)(dg,{enabled:h,loading:p||u,onToggle:()=>a(e.disabled?"enable":"disable",e),label:d(e.disabled?"desktop.enablePackage":"desktop.disablePackage")}),(0,r.jsx)(du,{scope:e.scope}),e.disabled?(0,r.jsx)("span",{style:{fontSize:10,padding:"1px 5px",borderRadius:3,background:"rgba(120,120,120,0.12)",color:"var(--text-dim)"},children:d("desktop.disabled")}):e.filtered&&(0,r.jsx)("span",{style:{fontSize:10,padding:"1px 5px",borderRadius:3,background:"rgba(245,158,11,0.12)",color:"#d97706"},children:d("desktop.filtered")}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.source})]}),(0,r.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[(0,r.jsx)("button",{onClick:()=>a("update",e),disabled:p||u,style:dh(p||u),children:d(o===`update:${c}`?"desktop.updating":"desktop.update")}),(0,r.jsx)("button",{onClick:l,disabled:!i||u||p,style:dh(!i||u||p),title:d(i?"desktop.reloadCurrentSession":"desktop.openSessionToReload"),children:d(u?"desktop.reloading":"desktop.reloadSession")}),(0,r.jsx)("button",{onClick:()=>a("remove",e),disabled:p||u,style:dh(p||u,!0),children:d(o===`remove:${c}`?"desktop.removing":"desktop.remove")})]})]}),(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(96px, 130px) minmax(0, 1fr)",gap:"9px 14px",fontSize:12,lineHeight:1.45},children:[(0,r.jsx)("div",{style:{color:"var(--text-dim)"},children:d("desktop.status")}),(0,r.jsx)("div",{style:{color:dc(e.status),textTransform:"capitalize"},children:e.status}),(0,r.jsx)("div",{style:{color:"var(--text-dim)"},children:d("desktop.version")}),(0,r.jsx)("div",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:dd(e,d)}),(0,r.jsx)("div",{style:{color:"var(--text-dim)"},children:d("desktop.package")}),(0,r.jsx)("div",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)",overflowWrap:"anywhere"},children:e.packageName??d("desktop.unknown")}),(0,r.jsx)("div",{style:{color:"var(--text-dim)"},children:d("desktop.resources")}),(0,r.jsx)("div",{style:{color:"var(--text-muted)"},children:dl(e,d)}),(0,r.jsx)("div",{style:{color:"var(--text-dim)"},children:d("desktop.installedPath")}),(0,r.jsx)("div",{style:{color:e.installedPath?"var(--text-muted)":"#ef4444",fontFamily:"var(--font-mono)",overflowWrap:"anywhere"},children:e.installedPath?ds(e.installedPath):d("desktop.notFound")}),(0,r.jsx)("div",{style:{color:"var(--text-dim)"},children:d("desktop.cwd")}),(0,r.jsx)("div",{style:{color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflowWrap:"anywhere"},children:ds(t)})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[(0,r.jsx)("div",{style:{fontSize:12,fontWeight:700,color:"var(--text)"},children:d("desktop.resolvedResources")}),(0,r.jsx)(dp,{pkg:e})]}),s&&(0,r.jsx)("div",{style:{fontSize:12,color:"#16a34a"},children:s}),n&&(0,r.jsx)("div",{style:{fontSize:12,color:"#ef4444",whiteSpace:"pre-wrap"},children:n})]})}function dk({cwd:e,sessionId:t,embedded:o=!1,onCloseAction:s,onReloadedAction:i}){let a=O(),{t:l}=(0,A.s)(),[d,c]=(0,n.useState)(null),[p,u]=(0,n.useState)(!0),[h,g]=(0,n.useState)(null),[m,f]=(0,n.useState)(null),[x,k]=(0,n.useState)(!1),[y,b]=(0,n.useState)(""),[w,j]=(0,n.useState)("global"),[S,C]=(0,n.useState)(null),[T,R]=(0,n.useState)(null),[z,I]=(0,n.useState)(null),M=(0,n.useMemo)(()=>d?.packages??[],[d?.packages]),P=M.find(e=>da(e)===m)??null,E=(0,n.useMemo)(()=>["project","global"].map(e=>({scope:e,packages:M.filter(t=>t.scope===e)})).filter(e=>e.packages.length>0),[M]),W=(0,n.useCallback)(async()=>{u(!0),g(null);try{let t=await fetch(`/api/plugins?cwd=${encodeURIComponent(e)}`),o=await t.json();if(!t.ok||o.error)throw Error(o.error??`HTTP ${t.status}`);c(o),k(e=>0===o.packages.length||e),f(e=>e&&o.packages.some(t=>da(t)===e)?e:o.packages[0]?da(o.packages[0]):null)}catch(e){g(e instanceof Error?e.message:String(e))}finally{u(!1)}},[e]);(0,n.useEffect)(()=>{W()},[W]);let F=(0,n.useCallback)(async(t,o)=>{let r=da(o);C(`${t}:${r}`),R(null),I(null);try{let r=await fetch("/api/plugins",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:t,source:o.source,scope:o.scope,cwd:e})}),n=await r.json();if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);if(c(n),"remove"===t)f(n.packages[0]?da(n.packages[0]):null),0===n.packages.length&&k(!0),I(l("desktop.packageRemoved"));else{let e={install:l("desktop.packageInstalled"),update:l("desktop.packageUpdated"),disable:l("desktop.packageDisabledMessage"),enable:l("desktop.packageEnabled")};I(e[t])}}catch(e){R(e instanceof Error?e.message:String(e))}finally{C(null)}},[e,l]),D=(0,n.useCallback)(async()=>{let t=di(y).trim();if(!t)return;let o=`${w}\0${t}`;C(`install:${o}`),R(null),I(null);try{var r;let n,s,i=await fetch("/api/plugins",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"install",source:t,scope:w,cwd:e})}),a=await i.json();if(!i.ok||a.error)throw Error(a.error??`HTTP ${i.status}`);c(a);let d=(r=a.packages,s=(n=t.trim()).startsWith("npm:")?n.slice(4):n,r.find(e=>e.scope===w&&e.source===n)??r.find(e=>e.scope===w&&e.source===`npm:${s}`)??r.find(e=>e.scope===w&&e.source.endsWith(n)));f(d?da(d):o),k(!1),b(""),I(l("desktop.packageInstalled"))}catch(e){R(e instanceof Error?e.message:String(e))}finally{C(null)}},[e,w,y,l]),N=(0,n.useCallback)(async()=>{if(t){C("reload"),R(null),I(null);try{await i6(t,{type:"reload"}),i?.(),await W(),I(l("desktop.sessionReloaded"))}catch(e){R(e instanceof Error?e.message:String(e))}finally{C(null)}}},[W,i,t,l]),L=S?.startsWith("install:")??!1;return(0,r.jsx)("div",{style:o?{display:"flex",flex:1,minWidth:0,minHeight:0,overflow:"hidden"}:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:e=>{o||e.target!==e.currentTarget||s?.()},children:(0,r.jsxs)("div",{style:o?{display:"flex",flex:1,minWidth:0,minHeight:0,flexDirection:"column",overflow:"hidden"}:{width:a?"calc(100vw - 16px)":860,maxWidth:"calc(100vw - 16px)",height:a?"calc(100dvh - 16px)":"76vh",maxHeight:"calc(100dvh - 16px)",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.18)",overflow:"hidden"},children:[!o&&(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 18px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10,minWidth:0},children:[(0,r.jsx)("span",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:l("desktop.plugins")}),(0,r.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:ds(e)})]}),(0,r.jsx)("button",{onClick:s,title:l("desktop.close"),"aria-label":l("desktop.close"),style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),(0,r.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:a?"column":"row",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{width:a?"100%":245,maxHeight:a?"40vh":void 0,borderRight:a?"none":"1px solid var(--border)",borderBottom:a?"1px solid var(--border)":"none",display:"flex",flexDirection:"column",flexShrink:0,background:"var(--bg-panel)"},children:[(0,r.jsx)("div",{style:{flex:1,overflowY:"auto",padding:"8px 6px"},children:p?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:l("desktop.loading")}):h?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"#ef4444"},children:h}):0===M.length?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"var(--text-dim)"},children:l("desktop.noPluginsConfigured")}):E.map(e=>(0,r.jsxs)("div",{style:{marginBottom:6},children:[(0,r.jsx)("div",{style:{padding:"4px 8px 3px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase"},children:l(`desktop.${e.scope}`)}),e.packages.map(e=>{let t=da(e),o=!x&&m===t;return(0,r.jsxs)("div",{onClick:()=>{f(t),k(!1),R(null),I(null)},style:{display:"flex",alignItems:"center",gap:7,padding:"8px 8px",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,r.jsx)("span",{style:{flexShrink:0,width:7,height:7,borderRadius:"50%",background:dc(e.status)}}),(0,r.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,r.jsx)("div",{style:{fontSize:12,fontWeight:o?600:400,color:"var(--text)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.source}),(0,r.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:2},children:dl(e,l)}),(e.version||e.configuredVersion)&&(0,r.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:2},children:dd(e,l)})]})]},t)})]},e.scope))}),(0,r.jsx)("div",{style:{padding:"8px 6px",borderTop:"1px solid var(--border)",flexShrink:0},children:(0,r.jsxs)("button",{type:"button",onClick:()=>{k(!0),R(null),I(null)},style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,border:"none",width:"100%",cursor:"pointer",background:x?"var(--bg-selected)":"none",color:x?"var(--accent)":"var(--text-dim)",fontSize:12},onMouseEnter:e=>{x||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{x||(e.currentTarget.style.background="none")},children:[(0,r.jsx)(v.c,{size:13}),l("desktop.addPlugin")]})})]}),(0,r.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:x?(0,r.jsx)(df,{cwd:e,source:y,scope:w,busy:L,actionError:T,onSourceChange:b,onScopeChange:j,onInstall:D}):p?null:P?(0,r.jsx)(dx,{pkg:P,cwd:e,busyKey:S,actionError:T,actionMessage:z,sessionId:t,onAction:F,onReloadSession:N},da(P)):(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:l("desktop.selectPackage")})})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:"10px 18px",borderTop:"1px solid var(--border)",flexShrink:0},children:[(0,r.jsx)("div",{style:{minWidth:0,flex:1,fontSize:11,color:"var(--text-dim)",overflow:"hidden"},children:d?.diagnostics.length?(0,r.jsx)("span",{title:d.diagnostics.map(e=>`${e.type}: ${e.source?`${e.source}: `:""}${e.message}`).join("\n"),style:{color:d.diagnostics.some(e=>"error"===e.type)?"#ef4444":"#d97706"},children:l("desktop.diagnosticsCount",{count:d.diagnostics.length,suffix:1===d.diagnostics.length?"":"s"})}):(0,r.jsx)("span",{children:d?l("desktop.pluginResourceTotals",{extensions:d.totals.extensions,skills:d.totals.skills,prompts:d.totals.prompts,themes:d.totals.themes}):""})}),(0,r.jsx)("button",{onClick:()=>void W(),disabled:p||null!==S,style:dh(p||null!==S),children:l("desktop.refresh")}),!o&&(0,r.jsx)("button",{onClick:s,style:dh(!1),children:l("desktop.close")})]})]})})}var dv=o(36282);function dy(){let{t:e}=(0,A.s)(),[t,o]=(0,n.useState)({enabled:!1,protocol:"http",host:"127.0.0.1",port:7890,username:"",password:"",noProxy:"localhost,127.0.0.1,.local",hasPassword:!1}),[s,i]=(0,n.useState)(!1),[a,l]=(0,n.useState)(!1),[d,c]=(0,n.useState)(null),[p,u]=(0,n.useState)(null),[h,g]=(0,n.useState)(null),[m,f]=(0,n.useState)(!1),[x,k]=(0,n.useState)(!1);(0,n.useEffect)(()=>{(async()=>{try{let e=await fetch("/api/proxy");if(e.ok){let t=await e.json();o(e=>({...e,...t,password:""}))}}catch{}})()},[]);let v=(0,n.useCallback)((e,t)=>{o(o=>({...o,[e]:t})),"password"===e&&k(!0),f(!0),u(null),g(null)},[]),y=(0,n.useCallback)(async()=>{i(!0),u(null),g(null);try{let r={...t};delete r.hasPassword,x||delete r.password;let n=await fetch("/api/proxy",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)}),s=await n.json();if(n.ok){u(!0),f(!1),k(!1);let e=await fetch("/api/proxy");if(e.ok){let t=await e.json();o(e=>({...e,...t,password:""}))}}else u(!1),g(s.error||e("desktop.proxySaveFailed"))}catch(t){u(!1),g(t instanceof Error?t.message:e("desktop.proxySaveFailed"))}finally{i(!1)}},[t,x,e]),b=(0,n.useCallback)(async()=>{l(!0),c(null),m&&await y();try{let t=await fetch("/api/proxy/test",{method:"POST"}),o=await t.json();o.success?c({ok:!0,message:`${e("desktop.proxyTestSuccess")} \xb7 ${o.latencyMs}ms`,latencyMs:o.latencyMs}):c({ok:!1,message:o.error||e("desktop.proxyTestFailed")})}catch(t){c({ok:!1,message:t instanceof Error?t.message:e("desktop.proxyTestFailed")})}finally{l(!1)}},[m,y,e]),w=(0,n.useCallback)(()=>{if(!t.enabled||!t.host||!t.port)return null;let e="";return t.username&&t.password?e=`${t.username}:${"•".repeat(Math.min(t.password.length,8))}@`:t.username&&(e=`${t.username}@`),`${t.protocol}://${e}${t.host}:${t.port}`},[t.enabled,t.host,t.port,t.protocol,t.username,t.password])();return(0,r.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:"column",padding:"16px 20px",overflow:"auto",gap:16},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:4},children:[(0,r.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:8,fontSize:14,fontWeight:500,color:"var(--text)",cursor:"pointer"},children:[(0,r.jsx)("input",{type:"checkbox",checked:t.enabled,onChange:e=>v("enabled",e.target.checked),style:{width:16,height:16,accentColor:"var(--accent)"}}),e("desktop.proxyEnable")]}),t.enabled&&w&&(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontFamily:"var(--font-mono)",backgroundColor:"var(--bg-hover)",padding:"2px 10px",borderRadius:4,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"60%"},title:w,children:w})]}),(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px 16px",opacity:t.enabled?1:.5,pointerEvents:t.enabled?"auto":"none"},children:[(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)("label",{style:{fontSize:12,color:"var(--text-muted)"},children:e("desktop.proxyProtocol")}),(0,r.jsxs)("select",{value:t.protocol,onChange:e=>v("protocol",e.target.value),style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:13,fontFamily:"var(--font-mono)",outline:"none"},children:[(0,r.jsx)("option",{value:"http",children:"HTTP"}),(0,r.jsx)("option",{value:"https",children:"HTTPS"}),(0,r.jsx)("option",{value:"socks5",children:"SOCKS5"})]})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)("label",{style:{fontSize:12,color:"var(--text-muted)"},children:e("desktop.proxyHost")}),(0,r.jsx)("input",{type:"text",value:t.host,onChange:e=>v("host",e.target.value),placeholder:"127.0.0.1",style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:13,fontFamily:"var(--font-mono)",outline:"none"}})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)("label",{style:{fontSize:12,color:"var(--text-muted)"},children:e("desktop.proxyPort")}),(0,r.jsx)("input",{type:"number",value:t.port,onChange:e=>v("port",parseInt(e.target.value,10)||0),placeholder:"7890",min:1,max:65535,style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:13,fontFamily:"var(--font-mono)",outline:"none"}})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)("label",{style:{fontSize:12,color:"var(--text-muted)"},children:e("desktop.proxyUsername")}),(0,r.jsx)("input",{type:"text",value:t.username,onChange:e=>v("username",e.target.value),placeholder:t.username?"":e("desktop.proxyUsername"),style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:13,fontFamily:"var(--font-mono)",outline:"none"}})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)("label",{style:{fontSize:12,color:"var(--text-muted)"},children:e("desktop.proxyPassword")}),(0,r.jsx)("input",{type:"password",value:t.password,onChange:e=>v("password",e.target.value),placeholder:t.hasPassword?"••••••••":e("desktop.proxyPassword"),style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:13,fontFamily:"var(--font-mono)",outline:"none"}})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4,gridColumn:"1 / -1"},children:[(0,r.jsx)("label",{style:{fontSize:12,color:"var(--text-muted)"},children:e("desktop.proxyNoProxy")}),(0,r.jsx)("input",{type:"text",value:t.noProxy,onChange:e=>v("noProxy",e.target.value),placeholder:"localhost,127.0.0.1,.local",style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:13,fontFamily:"var(--font-mono)",outline:"none"}})]})]}),(0,r.jsxs)("div",{style:{display:"flex",gap:10,marginTop:4},children:[(0,r.jsx)("button",{type:"button",onClick:y,disabled:s,style:{padding:"6px 18px",borderRadius:6,border:"none",background:"var(--accent)",color:"#fff",fontSize:13,fontWeight:500,cursor:s?"not-allowed":"pointer",opacity:s?.5:1,transition:"background 0.15s"},onMouseEnter:e=>{s||(e.currentTarget.style.background="var(--accent-hover)")},onMouseLeave:e=>{s||(e.currentTarget.style.background="var(--accent)")},children:s?e("desktop.proxySaving"):e("desktop.proxySave")}),(0,r.jsx)("button",{type:"button",onClick:b,disabled:a||!t.enabled,style:{padding:"6px 18px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:t.enabled?"var(--text)":"var(--text-muted)",fontSize:13,fontWeight:500,cursor:t.enabled?"pointer":"not-allowed",opacity:t.enabled?1:.5,transition:"background 0.15s"},onMouseEnter:e=>{t.enabled&&(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t.enabled&&(e.currentTarget.style.background="var(--bg)")},children:a?e("desktop.proxyTesting"):e("desktop.proxyTest")})]}),!0===p&&(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"6px 12px",borderRadius:6,backgroundColor:"rgba(34, 197, 94, 0.12)",color:"#22c55e",fontSize:13},children:[(0,r.jsx)(nv.r,{size:16,weight:"fill"}),e("desktop.proxySaved")]}),!1===p&&h&&(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"6px 12px",borderRadius:6,backgroundColor:"rgba(239, 68, 68, 0.10)",color:"#ef4444",fontSize:13},children:[(0,r.jsx)(iU.J,{size:16,weight:"fill"}),h]}),d&&(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"6px 12px",borderRadius:6,backgroundColor:d.ok?"rgba(34, 197, 94, 0.10)":"rgba(239, 68, 68, 0.10)",color:d.ok?"#22c55e":"#ef4444",fontSize:13},children:[d.ok?(0,r.jsx)(nv.r,{size:16,weight:"fill"}):(0,r.jsx)(iU.J,{size:16,weight:"fill"}),d.message,void 0!==d.latencyMs&&(0,r.jsxs)("span",{style:{color:"var(--text-muted)",fontSize:12,marginLeft:4},children:["(",d.latencyMs,"ms)"]})]}),m&&!p&&!h&&(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"4px 12px",borderRadius:6,backgroundColor:"var(--bg-hover)",color:"var(--text-muted)",fontSize:12},children:[(0,r.jsx)(dv.j,{size:12,weight:"fill"}),e("desktop.proxyUnsaved")]})]})}function db(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function dw(e){let t=e.sourceInfo?.source,o=e.sourceInfo?.scope;return"user"===o||"user"===t?"global":"project"===o||"project"===t?"project":"path"}function dj(e){return e.install?`${e.install.scope}\0${e.install.package}`:null}function dS(e,t){return e?e.slice(0,8):t}function dC({enabled:e,loading:t,onToggle:o}){let{t:n}=(0,A.s)();return(0,r.jsx)("button",{onClick:o,disabled:t,title:n(e?"desktop.visibleInModelPrompt":"desktop.hiddenFromModelPrompt"),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,r.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 dT({skill:e,cwd:t,onToggle:o,toggling:n,saveError:s,updateStatus:i,checkingUpdate:a,updating:l,updateError:d,onCheckUpdate:c,onUpdate:p}){let{t:u}=(0,A.s)(),h=dw(e),g=!e.disableModelInvocation;return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:20},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:7},children:[(0,r.jsx)("span",{style:{fontSize:10,padding:"1px 5px",borderRadius:3,flexShrink:0,background:"project"===h?"rgba(99,102,241,0.12)":"rgba(120,120,120,0.12)",color:"project"===h?"rgba(99,102,241,0.8)":"var(--text-dim)"},children:u(`desktop.${h}`)}),(0,r.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"===h&&e.startsWith(t)){let o=e.slice(t.length).replace(/^[/\\]/,"");return`./${o}`}return db(e)}(e.filePath)}),(0,r.jsx)(dC,{enabled:g,loading:n,onToggle:()=>o(e)}),s&&(0,r.jsx)("span",{style:{fontSize:12,color:"#f87171",flexShrink:0},children:s})]}),!g&&(0,r.jsx)("div",{style:{marginTop:-12,color:"var(--text-dim)",fontSize:12},children:u("desktop.hiddenButInvocable")}),e.install?.skillsShUrl&&(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:u("desktop.pluginSource")}),(0,r.jsx)("a",{href:e.install.skillsShUrl,target:"_blank",rel:"noreferrer",title:e.install.skillsShUrl,style:{display:"flex",alignItems:"center",gap:8,width:"fit-content",maxWidth:"100%",color:"var(--accent)",textDecoration:"none"},children:(0,r.jsxs)("span",{style:{fontFamily:"var(--font-mono)",fontSize:12,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[e.install.skillsShUrl.replace(/^https?:\/\//,"")," ↗"]})})]}),e.install&&(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:7},children:[(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:u("desktop.version")}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:12,color:"var(--text-muted)"},children:dS(i?.currentVersion??e.install.versionHash,u("desktop.unknown"))}),e.install.canCheckForUpdates&&(0,r.jsx)("button",{onClick:c,disabled:a||l,style:{padding:"4px 9px",border:"1px solid var(--border)",borderRadius:5,background:"none",color:"var(--text-muted)",cursor:a||l?"not-allowed":"pointer",opacity:a||l?.5:1,fontSize:11},children:u("desktop.check")}),i?.state==="update-available"&&(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:12,color:"#d97706"},children:dS(i.latestVersion,u("desktop.unknown"))}),(a||i&&"update-available"!==i.state)&&(0,r.jsx)("span",{style:{fontSize:12,color:a?"var(--accent)":i?.state==="up-to-date"?"#16a34a":i?.state==="error"?"#ef4444":"var(--text-dim)"},children:a?u("desktop.checking"):i?.state==="up-to-date"?u("desktop.upToDate"):i?.state==="unsupported"?u("desktop.automaticChecksUnavailable"):i?.message||u("desktop.checkFailed")}),i?.state==="update-available"&&(0,r.jsx)("button",{onClick:p,disabled:l||a,style:{padding:"4px 10px",border:"none",borderRadius:5,background:"var(--accent)",color:"#fff",cursor:l||a?"not-allowed":"pointer",opacity:l||a?.5:1,fontSize:11,fontWeight:600},children:u(l?"desktop.updating":"desktop.update")})]}),d&&(0,r.jsx)("span",{style:{fontSize:12,color:"#ef4444"},children:d})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:u("desktop.name")}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:14,color:"var(--text)"},children:e.name})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:u("desktop.description")}),(0,r.jsx)("span",{style:{fontSize:14,color:"var(--text-muted)",lineHeight:1.6},children:e.description})]})]})}function dR({cwd:e,installedPackages:t,projectResourcesLoaded:o,onInstalled:s}){let{t:i}=(0,A.s)(),[a,l]=(0,n.useState)(""),[d,c]=(0,n.useState)([]),[p,u]=(0,n.useState)(!1),[h,g]=(0,n.useState)(null),[m,f]=(0,n.useState)(null),[x,k]=(0,n.useState)(null),[v,y]=(0,n.useState)(new Set),[b,w]=(0,n.useState)("global"),j=(0,n.useRef)(null);(0,n.useEffect)(()=>{j.current?.focus()},[]),(0,n.useEffect)(()=>{o||w("global")},[o]);let S=(0,n.useCallback)(async e=>{if(e.trim()){u(!0),g(null),c([]);try{let t=await fetch("/api/skills/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:e.trim()})}),o=await t.json();if(o.error)return void g(o.error);c(o.results??[]),0===(o.results??[]).length&&g(i("desktop.noSkillsFound"))}catch(e){g(String(e))}finally{u(!1)}}},[i]),C=(0,n.useCallback)(async t=>{f(t),k(null);try{let o=await fetch("/api/skills/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({package:t,scope:b,cwd:e})}),r=await o.json();if(!o.ok||r.error)return void k(r.error??`HTTP ${o.status}`);y(e=>new Set(e).add(`${b}:${t}`)),s()}catch(e){k(String(e))}finally{f(null)}},[s,b,e]),T="global"===b?"~/.pi/agent/skills/":`${db(e)}/.pi/skills/`;return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,marginBottom:20},children:[(0,r.jsx)("div",{style:{fontSize:14,fontWeight:600,color:"var(--text)"},children:i("desktop.addSkillTitle")}),(0,r.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,r.jsx)("input",{ref:j,value:a,onChange:e=>l(e.target.value),onKeyDown:e=>{"Enter"===e.key&&S(a)},placeholder:i("desktop.skillSearchPlaceholder"),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,r.jsx)("button",{onClick:()=>S(a),disabled:p||!a.trim(),style:{padding:"7px 16px",fontSize:13,borderRadius:6,border:"none",background:"var(--accent)",color:"#fff",cursor:p||!a.trim()?"not-allowed":"pointer",opacity:p||!a.trim()?.5:1,flexShrink:0},children:p?i("desktop.searching"):i("desktop.search")})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10},children:[(0,r.jsx)("div",{style:{display:"flex",borderRadius:5,border:"1px solid var(--border)",overflow:"hidden",fontSize:12,flexShrink:0},children:["global","project"].map(e=>(0,r.jsx)("button",{onClick:()=>w(e),disabled:"project"===e&&!o,title:"project"!==e||o?void 0:i("desktop.projectSkillInstallUnavailable"),style:{padding:"3px 10px",border:"none",cursor:"project"!==e||o?"pointer":"not-allowed",opacity:"project"!==e||o?1:.5,background:b===e?"var(--bg-selected)":"none",color:b===e?"var(--text)":"var(--text-dim)",fontWeight:b===e?600:400,borderRight:"global"===e?"1px solid var(--border)":"none"},children:i(`desktop.${e}`)},e))}),(0,r.jsxs)("span",{style:{fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["→ ",T]})]}),h&&(0,r.jsx)("div",{style:{fontSize:12,color:"#f87171"},children:h}),x&&(0,r.jsx)("div",{style:{fontSize:12,color:"#f87171",wordBreak:"break-word"},children:x})]}),d.length>0?(0,r.jsx)("div",{style:{flex:1,overflowY:"auto"},children:d.map(e=>{let o=t[b].has(e.package)||v.has(`${b}:${e.package}`),n=m===e.package,s=e.package.indexOf("@"),a=s>-1?e.package.slice(0,s):e.package,l=s>-1?e.package.slice(s+1):null;return(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:14,padding:"12px 0",borderBottom:"1px solid var(--border)"},children:[(0,r.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)",marginBottom:3},children:l??a}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)"},children:a}),(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:e.installs}),e.url&&(0,r.jsx)("a",{href:e.url,target:"_blank",rel:"noreferrer",style:{fontSize:12,color:"var(--accent)",textDecoration:"none"},children:"skills.sh ↗"})]})]}),(0,r.jsx)("button",{onClick:()=>!o&&!n&&C(e.package),disabled:o||n||null!==m,style:{flexShrink:0,padding:"5px 14px",fontSize:12,fontWeight:500,borderRadius:5,border:"1px solid var(--border)",cursor:o||n||null!==m?"not-allowed":"pointer",background:o?"rgba(34,197,94,0.1)":"none",color:o?"#16a34a":n?"var(--accent)":"var(--text-muted)",transition:"color 0.12s"},children:o?`✓ ${i("desktop.installed")}`:n?i("desktop.installing"):i("desktop.install")})]},e.package)})}):!h&&!p&&(0,r.jsxs)("div",{style:{fontSize:13,color:"var(--text-dim)",lineHeight:1.8},children:[i("desktop.skillSearchHint").split("skills.sh")[0],(0,r.jsx)("a",{href:"https://skills.sh",target:"_blank",rel:"noreferrer",style:{color:"var(--accent)",textDecoration:"none"},children:"skills.sh"}),i("desktop.skillSearchHint").split("skills.sh")[1]]})]})}function dz({cwd:e,embedded:t=!1,sessionId:o,onCloseAction:s}){let i=O(),{t:a}=(0,A.s)(),[l,d]=(0,n.useState)([]),[c,p]=(0,n.useState)(!0),[u,h]=(0,n.useState)(null),[g,m]=(0,n.useState)(null),[f,x]=(0,n.useState)(new Set),[k,y]=(0,n.useState)(null),[b,w]=(0,n.useState)(!1),[j,S]=(0,n.useState)({}),[C,T]=(0,n.useState)(new Set),[R,z]=(0,n.useState)(!1),[I,M]=(0,n.useState)(null),[P,E]=(0,n.useState)(null),[W,F]=(0,n.useState)(!0),D=(0,n.useCallback)(async()=>{p(!0),h(null);try{let t=await fetch(`/api/skills?cwd=${encodeURIComponent(e)}`),o=await t.json();if(!t.ok||o.error)throw Error(o.error??`HTTP ${t.status}`);let r=o.skills??[];if(d(r),F(o.projectResourcesLoaded??!0),r.length>0&&!g){let e=r.find(e=>!e.disableModelInvocation)??r[0];m(e.filePath)}return r}catch(e){return h(String(e)),[]}finally{p(!1)}},[e,g]);(0,n.useEffect)(()=>{S({}),E(null),D()},[e]);let N=(0,n.useCallback)(async t=>{let o=(t?[t]:l.filter(e=>!!e.install)).map(dj).filter(e=>!!e);if(0!==o.length){E(null),T(e=>new Set([...e,...o])),t||z(!0);try{let o=await fetch("/api/skills/check",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,package:t?.install?.package,scope:t?.install?.scope})}),r=await o.json();if(!o.ok||r.error)throw Error(r.error??`HTTP ${o.status}`);S(e=>{let t={...e};for(let e of r.updates??[])t[`${e.scope}\0${e.package}`]=e;return t})}catch(e){E(e instanceof Error?e.message:String(e))}finally{T(e=>{let t=new Set(e);for(let e of o)t.delete(e);return t}),t||z(!1)}}},[e,l]),L=(0,n.useCallback)(async t=>{if(!t.install)return;let o=dj(t);M(o),E(null);try{let r=await fetch("/api/skills/update",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,package:t.install.package,scope:t.install.scope})}),n=await r.json();if(!r.ok||n.error||!n.success)throw Error(n.error??`HTTP ${r.status}`);await D();let s=n.skill?.install?.versionHash;S(e=>({...e,[o]:{package:t.install.package,scope:t.install.scope,state:"up-to-date",currentVersion:s,latestVersion:s}}))}catch(e){E(e instanceof Error?e.message:String(e))}finally{M(null)}},[e,D]),$=(0,n.useCallback)(async t=>{let o=!t.disableModelInvocation;x(e=>new Set(e).add(t.filePath)),y(null);try{let r=await fetch("/api/skills",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,filePath:t.filePath,disableModelInvocation:o})}),n=await r.json();if(!r.ok||n.error)return void y(n.error??`HTTP ${r.status}`);d(e=>e.map(e=>e.filePath===t.filePath?{...e,disableModelInvocation:o}:e))}catch(e){y(String(e))}finally{x(e=>{let o=new Set(e);return o.delete(t.filePath),o})}},[e]),H=l.find(e=>e.filePath===g)??null;return(0,r.jsx)("div",{style:t?{display:"flex",flex:1,minWidth:0,minHeight:0,overflow:"hidden"}:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:e=>{t||e.target!==e.currentTarget||s?.()},children:(0,r.jsxs)("div",{style:t?{display:"flex",flex:1,minWidth:0,minHeight:0,flexDirection:"column",overflow:"hidden"}:{width:i?"calc(100vw - 16px)":860,maxWidth:"calc(100vw - 16px)",height:i?"calc(100dvh - 16px)":"78vh",maxHeight:"calc(100dvh - 16px)",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:[!t&&(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 18px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10},children:[(0,r.jsx)("span",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:a("desktop.skills")}),(0,r.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)",maxWidth:320,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:db(e)})]}),(0,r.jsx)("button",{onClick:s,title:a("desktop.close"),"aria-label":a("desktop.close"),style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),!W&&(0,r.jsx)("div",{role:"status",style:{padding:"8px 18px",borderBottom:"1px solid var(--border)",background:"var(--bg-subtle)",color:"var(--text-muted)",fontSize:12},children:a("desktop.projectSkillsRestricted")}),(0,r.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:i?"column":"row",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{width:i?"100%":210,maxHeight:i?"40vh":void 0,borderRight:i?"none":"1px solid var(--border)",borderBottom:i?"1px solid var(--border)":"none",display:"flex",flexDirection:"column",flexShrink:0,background:"var(--bg-panel)"},children:[(0,r.jsx)("div",{style:{padding:"8px 8px 0",display:"flex",justifyContent:"flex-end"},children:(0,r.jsx)(lE,{sessionId:o,onApplied:D})}),(0,r.jsx)("div",{style:{flex:1,overflowY:"auto",padding:"8px 6px"},children:c?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:a("desktop.loading")}):u?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"#f87171"},children:u}):0===l.length?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"var(--text-dim)"},children:a("desktop.noSkillsFound")}):(()=>{let e=[];for(let{key:t,label:o,matches:r}of[{key:"project / skills.sh",label:`${a("desktop.project")} / skills.sh`,matches:e=>"project"===dw(e)&&!!e.install?.skillsShUrl},{key:"project",label:a("desktop.project"),matches:e=>"project"===dw(e)&&!e.install?.skillsShUrl},{key:"global / skills.sh",label:`${a("desktop.global")} / skills.sh`,matches:e=>"global"===dw(e)&&!!e.install?.skillsShUrl},{key:"global",label:a("desktop.global"),matches:e=>"global"===dw(e)&&!e.install?.skillsShUrl},{key:"path",label:a("desktop.path"),matches:e=>"path"===dw(e)}]){let n=l.filter(r);n.length>0&&e.push({key:t,label:o,skills:n})}return e.map(({key:e,label:t,skills:o})=>(o.filter(e=>e.disableModelInvocation),(0,r.jsxs)("div",{style:{marginBottom:6},children:[(0,r.jsx)("div",{style:{padding:"4px 8px 3px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.06em"},children:t}),[...o.filter(e=>!e.disableModelInvocation),...o.filter(e=>e.disableModelInvocation)].map(e=>{let t,o,n=!b&&g===e.filePath,s=e.disableModelInvocation;return(0,r.jsxs)("div",{onClick:()=>{m(e.filePath),w(!1)},style:{display:"flex",alignItems:"center",gap:7,padding:"8px 8px",borderRadius:5,cursor:"pointer",background:n?"var(--bg-selected)":"none"},onMouseEnter:e=>{n||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{n||(e.currentTarget.style.background="none")},children:[(0,r.jsx)("span",{style:{flexShrink:0,width:7,height:7,borderRadius:"50%",background:s?"var(--border)":"var(--accent)",boxShadow:s?"none":"0 0 4px var(--accent)",transition:"background 0.15s, box-shadow 0.15s"}}),(0,r.jsx)("span",{style:{fontSize:12,fontWeight:n?600:400,color:s?"var(--text-dim)":"var(--text)",fontFamily:"var(--font-mono)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),(o=(t=dj(e))?j[t]:void 0,o?.state!=="update-available"?null:(0,r.jsx)("span",{title:a("desktop.updateAvailable"),style:{color:"#d97706",fontSize:13,lineHeight:1,flexShrink:0},children:"↑"}))]},e.filePath)})]},e)))})()}),(0,r.jsx)("div",{style:{padding:"8px 6px",borderTop:"1px solid var(--border)",flexShrink:0},children:(0,r.jsxs)("div",{onClick:()=>w(!0),style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,cursor:"pointer",background:b?"var(--bg-selected)":"none",color:b?"var(--accent)":"var(--text-dim)",fontSize:12},onMouseEnter:e=>{b||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{b||(e.currentTarget.style.background="none")},children:[(0,r.jsx)(v.c,{size:13}),a("desktop.addSkill")]})})]}),(0,r.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:b?(0,r.jsx)(dR,{cwd:e,installedPackages:{global:new Set(l.filter(e=>e.install?.scope==="global").map(e=>e.install.package)),project:new Set(l.filter(e=>e.install?.scope==="project").map(e=>e.install.package))},projectResourcesLoaded:W,onInstalled:()=>{D()}}):c?null:H?(0,r.jsx)(dT,{skill:H,cwd:e,onToggle:$,toggling:f.has(H.filePath),saveError:k,updateStatus:dj(H)?j[dj(H)]:void 0,checkingUpdate:!!dj(H)&&C.has(dj(H)),updating:I===dj(H),updateError:P,onCheckUpdate:()=>void N(H),onUpdate:()=>void L(H)},H.filePath):(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:a("desktop.selectSkill")})})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 18px",borderTop:"1px solid var(--border)",flexShrink:0},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10},children:[l.some(e=>!!e.install)&&(0,r.jsx)("button",{onClick:()=>void N(),disabled:R||null!==I,style:{padding:"6px 12px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:R||null!==I?"not-allowed":"pointer",opacity:R||null!==I?.5:1,fontSize:12},children:R?a("desktop.checking"):a("desktop.checkUpdates")}),Object.values(j).filter(e=>"update-available"===e.state).length>0&&(0,r.jsx)("span",{style:{fontSize:12,color:"#d97706"},children:a("desktop.updatesCount").replace("{count}",String(Object.values(j).filter(e=>"update-available"===e.state).length)).replace("{suffix}",1===Object.values(j).filter(e=>"update-available"===e.state).length?"":"s")})]}),!t&&(0,r.jsx)("button",{onClick:s,style:{padding:"6px 14px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:13},children:a("desktop.close")})]})]})})}function dI(){let{t:e}=(0,A.s)(),[t,o]=(0,n.useState)([]),[s,i]=(0,n.useState)(""),[a,l]=(0,n.useState)(""),[d,c]=(0,n.useState)(""),[p,u]=(0,n.useState)(""),[h,g]=(0,n.useState)(!0),[m,f]=(0,n.useState)(null),x=(0,n.useCallback)(async()=>{g(!0),f(null);try{let e=await fetch("/api/logs?limit=500"),t=await e.json();if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);o(t.entries??[])}catch(e){f(e instanceof Error?e.message:String(e))}finally{g(!1)}},[]);(0,n.useEffect)(()=>{x()},[x]);let k=(0,n.useMemo)(()=>[...new Set(t.map(e=>e.source).filter(Boolean))].sort(),[t]),v=(0,n.useMemo)(()=>[...new Set(t.map(e=>e.statusCode).filter(e=>void 0!==e))].sort((e,t)=>e-t),[t]),y=(0,n.useMemo)(()=>{let e=p.trim().toLocaleLowerCase();return t.filter(e=>!s||e.level===s).filter(e=>!a||e.statusCode===Number(a)).filter(e=>!d||e.source===d).filter(t=>!e||[t.message,t.details,t.provider,t.model,t.source].filter(Boolean).some(t=>t.toLocaleLowerCase().includes(e))).slice(0,200)},[t,s,a,d,p]),b=async()=>{try{let e=await fetch("/api/logs",{method:"DELETE"});if(!e.ok)throw Error(`HTTP ${e.status}`);o([])}catch(e){f(e instanceof Error?e.message:String(e))}},w=async e=>{let t=[`[${e.timestamp}] ${e.level.toUpperCase()} ${e.statusCode??"—"}`,`${e.source}${e.provider?` \xb7 ${e.provider}`:""}${e.model?` \xb7 ${e.model}`:""}`,e.message,e.details].filter(Boolean).join("\n");try{await re(t),f(null)}catch(e){f(e instanceof Error?e.message:String(e))}};return(0,r.jsxs)("div",{style:{flex:1,minWidth:0,minHeight:0,overflow:"auto",padding:"18px 20px",display:"flex",flexDirection:"column",gap:12},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[(0,r.jsxs)("select",{value:s,onChange:e=>i(e.target.value),style:{padding:"7px 9px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",fontSize:12},children:[(0,r.jsx)("option",{value:"",children:e("desktop.logsAllLevels")}),["error","warning","info"].map(e=>(0,r.jsx)("option",{value:e,children:e},e))]}),(0,r.jsxs)("select",{value:a,onChange:e=>l(e.target.value),style:{padding:"7px 9px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",fontSize:12},children:[(0,r.jsx)("option",{value:"",children:e("desktop.logsAllCodes")}),v.map(e=>(0,r.jsx)("option",{value:e,children:e},e))]}),(0,r.jsxs)("select",{value:d,onChange:e=>c(e.target.value),style:{padding:"7px 9px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",fontSize:12},children:[(0,r.jsx)("option",{value:"",children:e("desktop.logsAllSources")}),k.map(e=>(0,r.jsx)("option",{value:e,children:e},e))]}),(0,r.jsx)("input",{value:p,onChange:e=>u(e.target.value),placeholder:e("desktop.logsSearch"),style:{flex:1,minWidth:180,padding:"7px 9px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",fontSize:12}}),(0,r.jsx)("button",{type:"button",onClick:()=>void x(),title:e("desktop.refresh"),"aria-label":e("desktop.refresh"),style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:30,height:30,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer"},children:(0,r.jsx)(C.S,{size:14})}),(0,r.jsx)("button",{type:"button",onClick:()=>void b(),title:e("desktop.logsClear"),"aria-label":e("desktop.logsClear"),style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:30,height:30,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"#ef4444",cursor:"pointer"},children:(0,r.jsx)(T.l,{size:14})})]}),h&&(0,r.jsx)("div",{style:{color:"var(--text-muted)",fontSize:12},children:e("desktop.loading")}),m&&(0,r.jsx)("div",{style:{color:"#ef4444",fontSize:12},children:m}),!h&&!m&&0===y.length&&(0,r.jsx)("div",{style:{color:"var(--text-muted)",fontSize:12},children:e("desktop.logsEmpty")}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:y.map(t=>(0,r.jsxs)("details",{style:{border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-panel)",padding:"8px 10px"},children:[(0,r.jsxs)("summary",{style:{cursor:"pointer",color:"error"===t.level?"#ef4444":"warning"===t.level?"#f59e0b":"var(--text)",fontSize:12},children:[(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",marginRight:8},children:t.statusCode??"—"}),(0,r.jsx)("span",{style:{marginRight:8},children:new Date(t.timestamp).toLocaleString()}),(0,r.jsx)("span",{style:{overflowWrap:"anywhere"},children:t.message.length>180?`${t.message.slice(0,180)}…`:t.message})]}),(0,r.jsxs)("div",{style:{padding:"8px 0 0 18px",color:"var(--text-muted)",fontSize:11,lineHeight:1.5,whiteSpace:"pre-wrap",overflowWrap:"anywhere"},children:[(0,r.jsxs)("div",{children:[t.source,t.provider?` \xb7 ${t.provider}`:"",t.model?` \xb7 ${t.model}`:""]}),(0,r.jsx)("div",{style:{marginTop:5,maxHeight:260,overflow:"auto"},children:t.message}),t.details&&(0,r.jsx)("div",{style:{marginTop:5,maxHeight:260,overflow:"auto"},children:t.details}),(0,r.jsx)("button",{type:"button",onClick:()=>void w(t),style:{marginTop:8,padding:"4px 7px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg)",color:"var(--text-muted)",cursor:"pointer",fontSize:11},children:e("desktop.logsCopy")})]})]},t.id))})]})}let dM={padding:"7px 9px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",fontSize:12,width:"100%"},dP={padding:"6px 12px",border:"none",borderRadius:6,background:"var(--accent)",color:"#fff",cursor:"pointer",fontSize:12};function dE(){let{t:e}=(0,A.s)(),[t,o]=(0,n.useState)([]),[s,i]=(0,n.useState)(!0),[a,l]=(0,n.useState)(null),[d,c]=(0,n.useState)(""),[p,u]=(0,n.useState)(""),[g,m]=(0,n.useState)(!1),[x,k]=(0,n.useState)(null),y=(0,n.useCallback)(async()=>{try{let e=await fetch("/api/snippets");if(!e.ok)return;let t=await e.json();o(t.snippets??[]),i(!1)}catch{i(!1)}},[]);(0,n.useEffect)(()=>{y()},[y]);let b=(0,n.useCallback)(()=>{window.dispatchEvent(new Event("pi:snippets-changed"))},[]),w=()=>{l(null),c(""),u(""),k(null)},j=(0,n.useCallback)(async()=>{let t=d.trim();if(!t)return void k(e("desktop.snippetNameRequired"));m(!0),k(null);try{if(a){let e=await fetch(`/api/snippets/${encodeURIComponent(a.id)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t,content:p})});if(!e.ok)throw Error(`HTTP ${e.status}`)}else{let e=await fetch("/api/snippets",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t,content:p})});if(!e.ok)throw Error(`HTTP ${e.status}`)}await y(),b(),w()}catch(e){k(e instanceof Error?e.message:String(e))}finally{m(!1)}},[a,d,p,y,b,e]),S=(0,n.useCallback)(async e=>{try{let t=await fetch(`/api/snippets/${encodeURIComponent(e)}`,{method:"DELETE"});if(!t.ok)throw Error(`HTTP ${t.status}`);a?.id===e&&w(),await y(),b()}catch(e){k(e instanceof Error?e.message:String(e))}},[a,y,b]);return(0,r.jsxs)(lh,{children:[(0,r.jsx)(lg,{children:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:7,padding:"12px 0"},children:[(0,r.jsx)(n7.c,{size:15,"aria-hidden":"true"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)"},children:e("desktop.snippets")}),(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:2},children:e("desktop.snippetsDesc")})]})]})}),(0,r.jsx)(lg,{children:(0,r.jsxs)("div",{style:{width:"100%"},children:[(0,r.jsxs)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginBottom:8},children:[(0,r.jsx)("button",{type:"button",onClick:w,style:dP,children:(0,r.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:5},children:[(0,r.jsx)(v.F,{size:13})," ",e("desktop.snippetNew")]})}),a&&(0,r.jsx)("button",{type:"button",onClick:w,style:{...dP,background:"var(--bg-hover)",color:"var(--text-muted)"},children:(0,r.jsx)(h.X,{size:13})})]}),(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(120px, 200px) 1fr",gap:8,alignItems:"start",marginBottom:8},children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",display:"block",marginBottom:4},children:e("desktop.snippetName")}),(0,r.jsx)("input",{value:d,onChange:e=>c(e.target.value),placeholder:"#name",style:dM})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",display:"block",marginBottom:4},children:e("desktop.snippetContent")}),(0,r.jsx)("textarea",{value:p,onChange:e=>u(e.target.value),rows:3,style:{...dM,resize:"vertical",fontFamily:"var(--font-mono)",fontSize:11}})]})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:10},children:[(0,r.jsx)("button",{type:"button",onClick:()=>void j(),disabled:g,style:{...dP,cursor:g?"wait":"pointer"},children:e("desktop.snippetSave")}),x&&(0,r.jsx)("span",{style:{color:"var(--status-error, #ef4444)",fontSize:12},children:x})]}),s?(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-dim)"},children:e("desktop.loadingThemes")}):0===t.length?(0,r.jsx)(lf,{children:e("desktop.snippetEmpty")}):(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:t.map(t=>(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"6px 10px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6},children:[(0,r.jsx)("span",{style:{color:"var(--accent)",fontFamily:"var(--font-mono)",fontSize:11},children:"#"}),(0,r.jsx)("span",{style:{fontWeight:600,fontSize:12,flexShrink:0},children:t.name}),(0,r.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-muted)",fontSize:11,fontFamily:"var(--font-mono)"},children:t.content.split("\n")[0]}),(0,r.jsx)("button",{type:"button",onClick:()=>{l(t),c(t.name),u(t.content),k(null)},title:e("desktop.snippetEdit"),style:{background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",padding:2},children:(0,r.jsx)(f.I,{size:13})}),(0,r.jsx)("button",{type:"button",onClick:()=>void S(t.id),title:e("desktop.snippetDelete"),style:{background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",padding:2},children:(0,r.jsx)(T.l,{size:13})})]},t.id))})]})}),(0,r.jsx)(lm,{children:(0,r.jsx)(lf,{children:e("desktop.snippetHint")})})]})}let dW={builtin:0,global:1,workspace:2,project:3},dF="pi-web:settings-navigation";function dD(){try{return window.localStorage}catch{return null}}function dA(e){let t=e.getItem(dF);if(!t)return{};try{let e=JSON.parse(t);if(null===e||"object"!=typeof e||Array.isArray(e))return{};return{section:"string"==typeof e.section?e.section:void 0,selections:null===e.selections||"object"!=typeof e.selections||Array.isArray(e.selections)?void 0:e.selections}}catch{return{}}}function dN(e,t){return"models"===e?e:t?JSON.stringify([e,t]):null}function dL(e,t,o=dD()){if(!o)return null;let r=dN(e,t);if(!r)return null;try{let e=dA(o).selections?.[r];return"string"==typeof e&&e.length>0?e:null}catch{return null}}function d$({embedded:e,title:t,subtitle:o,closeLabel:n="Close",onClose:s,children:i,width:a=900,height:l="78vh"}){let d=e?void 0:{"--config-panel-width":`${a}px`,"--config-panel-height":l};return(0,r.jsx)("div",{role:e?void 0:"dialog","aria-modal":e?void 0:"true","aria-label":t,className:`config-panel-root ${e?"is-embedded":"is-modal"}`,onClick:t=>{e||t.target!==t.currentTarget||s()},children:(0,r.jsxs)("div",{className:"config-panel-surface",style:d,children:[!e&&(0,r.jsxs)("div",{className:"config-panel-header",children:[(0,r.jsx)("strong",{className:"config-panel-title",children:t}),o&&(0,r.jsx)("code",{className:"config-panel-subtitle",title:o,children:o}),(0,r.jsx)("button",{type:"button",className:"config-close-button",onClick:s,title:n,"aria-label":n,children:"\xd7"})]}),i]})})}function dH({children:e}){return(0,r.jsx)("div",{className:"config-split-view",children:e})}function dO({children:e}){return(0,r.jsx)("aside",{className:"config-sidebar",children:e})}function dB({children:e}){return(0,r.jsx)("div",{className:"config-sidebar-list",children:e})}function dU({children:e}){return(0,r.jsx)("div",{className:"config-sidebar-group-label",children:e})}function d_({active:e=!1,className:t,children:o,...n}){return(0,r.jsx)("button",{type:"button",...n,"aria-current":e?"page":void 0,className:["config-sidebar-item",t].filter(Boolean).join(" "),children:o})}function dq({className:e,...t}){return(0,r.jsx)("span",{...t,className:["config-sidebar-text",e].filter(Boolean).join(" ")})}function dV({className:e,...t}){return(0,r.jsx)("div",{...t,className:["config-detail-stack",e].filter(Boolean).join(" ")})}function dK({className:e,...t}){return(0,r.jsx)("div",{...t,className:["config-detail-header",e].filter(Boolean).join(" ")})}function dG({className:e,...t}){return(0,r.jsx)("div",{...t,className:["config-detail-header-info",e].filter(Boolean).join(" ")})}function dJ({className:e,...t}){return(0,r.jsx)("div",{...t,className:["config-detail-actions",e].filter(Boolean).join(" ")})}function dY({label:e,children:t,style:o}){return(0,r.jsxs)("div",{className:"config-field",style:o,children:[(0,r.jsx)("span",{className:"config-field-label",children:e}),t]})}function dX({children:e}){return(0,r.jsx)("div",{className:"config-empty-state",children:e})}function dZ({children:e,style:t}){return(0,r.jsx)("div",{className:"config-detail",style:t,children:e})}function dQ({status:e,children:t}){return(0,r.jsxs)("footer",{className:"config-footer",children:[(0,r.jsx)("div",{className:"config-footer-status",children:e}),(0,r.jsx)("div",{className:"config-footer-actions",children:t})]})}function d0({variant:e="secondary",size:t="default",className:o,children:n,...s}){return(0,r.jsx)("button",{type:"button",...s,className:["config-button",`config-button-${e}`,`config-button-${t}`,o].filter(Boolean).join(" "),children:n})}function d1({checked:e,disabled:t=!1,loading:o=!1,label:n,onChange:s}){let i=t||o;return(0,r.jsx)("button",{type:"button",role:"switch","aria-checked":e,"aria-busy":o||void 0,"aria-label":n,title:n,disabled:i,className:`config-switch${o?" is-loading":""}`,onClick:()=>s(!e),children:(0,r.jsx)("span",{className:"config-switch-knob","aria-hidden":"true"})})}function d2({active:e=!1,children:t,className:o,...n}){return(0,r.jsx)("div",{className:"config-list-action",children:(0,r.jsxs)("button",{type:"button",...n,"aria-current":e?"page":void 0,className:["config-list-action-button",o].filter(Boolean).join(" "),children:[(0,r.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M12 5v14M5 12h14"})}),t]})})}function d4({active:e,color:t}){return(0,r.jsx)("span",{"aria-hidden":"true",className:`config-status-dot${e?" is-active":!1===e?" is-inactive":""}`,style:t?{backgroundColor:t}:void 0})}let d6=new Intl.Collator(void 0,{numeric:!0,sensitivity:"base"});function d8(e,t){return d6.compare(e.name||e.modelId,t.name||t.modelId)||d6.compare(e.provider,t.provider)||d6.compare(e.modelId,t.modelId)}function d5({options:e,value:t,onChange:o,onClear:s,emptyLabel:i,selectedLabel:a,disabled:l=!1,busy:d=!1,isAutoSelection:c=!1,ariaLabel:p,variant:u="toolbar",placement:h="up"}){let g,m,f,x,k,v,y,b,w,{t:j}=(0,A.s)(),S=O(),C=(0,n.useRef)(null),T=(0,n.useRef)(null),[R,z]=(0,n.useState)(!1),[I,M]=(0,n.useState)(null),[P,E]=(0,n.useState)(""),W=l||d,F=(0,n.useMemo)(()=>[...e].sort(d8),[e]),D=(g=P.trim().toLocaleLowerCase())?F.filter(e=>`${e.name} ${e.modelId}`.toLocaleLowerCase().includes(g)):F,N=F.length>8,L=[];for(let e of D){let t=L.find(t=>t.provider===e.provider);t?t.options.push(e):L.push({provider:e.provider,options:[e]})}let $=a??(t?F.find(e=>e.modelId===t.modelId&&e.provider===t.provider)?.name??t.modelId:i??(F.length>0?"Select model":"No models"));(0,n.useEffect)(()=>{let e=e=>{C.current&&!C.current.contains(e.target)&&T.current&&!T.current.contains(e.target)&&(z(!1),E(""))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,n.useEffect)(()=>{W&&(z(!1),E(""))},[W]);let H="field"===u?{display:"flex",alignItems:"center",gap:7,width:"100%",minWidth:0,height:34,padding:"0 9px",overflow:"hidden",border:"1px solid var(--border)",borderRadius:5,background:W?"var(--bg-panel)":"var(--bg)",color:W?"var(--text-dim)":"var(--text)",cursor:W?"default":"pointer",fontSize:12,textAlign:"left"}:{display:"flex",alignItems:"center",justifyContent:S?"flex-start":void 0,gap:6,width:S?"100%":void 0,maxWidth:S?"100%":220,height:32,padding:S?"8px 10px":"8px 12px",overflow:"hidden",border:"none",borderRadius:9,background:R?"var(--bg-hover)":"none",color:"var(--text-muted)",cursor:W?"not-allowed":"pointer",fontSize:12,opacity:W?.5:1,transition:"background 0.12s, color 0.12s"};return(0,r.jsxs)("div",{ref:C,className:`model-selector is-${u}${W?" is-disabled":""}`,style:{position:"relative",width:"field"===u||S?"100%":void 0,minWidth:0,flex:"toolbar"===u&&S?"1 1 auto":void 0},onKeyDown:e=>{"Escape"===e.key&&R&&(e.preventDefault(),e.stopPropagation(),E(""),z(!1))},children:[(0,r.jsxs)("button",{type:"button","aria-label":p,"aria-haspopup":"listbox","aria-expanded":R,"aria-busy":d||void 0,disabled:W,title:d?"Switching model":W?$:F.length>0||s?"Change model":"No available models",style:H,onClick:e=>{let t=e.currentTarget.getBoundingClientRect();M({top:t.top,right:t.right,bottom:t.bottom,left:t.left,width:t.width}),z(e=>(e&&E(""),!e))},onMouseEnter:e=>{W||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{if(W){e.currentTarget.style.background="field"===u?"var(--bg-panel)":"none",e.currentTarget.style.color="field"===u?"var(--text-dim)":"var(--text-muted)";return}e.currentTarget.style.background=R?"var(--bg-hover)":"field"===u?"var(--bg)":"none",e.currentTarget.style.color="field"===u?"var(--text)":"var(--text-muted)"},children:[d?(0,r.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",style:{animation:"spin 0.8s linear infinite",flexShrink:0},"aria-hidden":"true",children:(0,r.jsx)("path",{d:"M21 12a9 9 0 1 1-2.64-6.36"})}):(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{flexShrink:0},children:[(0,r.jsx)("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),(0,r.jsx)("rect",{x:"9",y:"9",width:"6",height:"6"}),(0,r.jsx)("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),(0,r.jsx)("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),(0,r.jsx)("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),(0,r.jsx)("line",{x1:"15",y1:"20",x2:"15",y2:"23"}),(0,r.jsx)("line",{x1:"20",y1:"9",x2:"23",y2:"9"}),(0,r.jsx)("line",{x1:"20",y1:"14",x2:"23",y2:"14"}),(0,r.jsx)("line",{x1:"1",y1:"9",x2:"4",y2:"9"}),(0,r.jsx)("line",{x1:"1",y1:"14",x2:"4",y2:"14"})]}),(0,r.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:$}),"field"===u&&(0,r.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{flexShrink:0,color:"var(--text-dim)"},children:(0,r.jsx)("polyline",{points:"6 9 12 15 18 9"})})]}),R&&I&&(m=window.visualViewport?.height??window.innerHeight,f=window.visualViewport?.width??window.innerWidth,x=I.top-8,k=m-I.bottom-8,y=Math.max(120,Math.min((v="up"===h||x>k)?x:k,.6*m)),b=v?{bottom:m-I.top+6}:{top:I.bottom+6},w=S?{left:8,right:8,maxWidth:"calc(100vw - 16px)"}:{left:I.left,width:"max-content",minWidth:I.width,maxWidth:Math.max(I.width,f-I.left-8)},(0,r.jsxs)("div",{ref:T,role:"listbox","aria-label":p,style:{position:"fixed",...b,...w,zIndex:500,display:"flex",flexDirection:"column",maxHeight:y,overflow:"hidden",border:"1px solid var(--border)",borderRadius:8,background:"var(--bg)",boxShadow:v?"0 -4px 16px rgba(0,0,0,0.10)":"0 4px 16px rgba(0,0,0,0.10)"},children:[N&&(0,r.jsx)("div",{style:{flexShrink:0,padding:"6px 8px",borderBottom:"1px solid var(--border)"},children:(0,r.jsx)("input",{value:P,onChange:e=>E(e.target.value),placeholder:j("chat.filterModels"),"aria-label":j("chat.filterModels"),autoFocus:!0,autoComplete:"off",spellCheck:!1,style:{boxSizing:"border-box",width:"100%",minWidth:220*!S,padding:"5px 8px",border:"1px solid var(--border)",borderRadius:5,outline:"none",background:"var(--bg)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:11}})}),(0,r.jsxs)("div",{style:{minHeight:0,overflowY:"auto"},children:[s&&!P.trim()&&(0,r.jsx)(d3,{active:!t,label:i??"Default",onClick:()=>{z(!1),E(""),s()}}),0===L.length?(0,r.jsx)("div",{style:{padding:"8px 12px",color:"var(--text-dim)",fontSize:12,whiteSpace:"nowrap"},children:P.trim()?j("chat.noMatchingModels"):"No available models"}):L.map((e,n)=>(0,r.jsxs)("div",{children:[L.length>1&&(0,r.jsx)("div",{style:{padding:"6px 12px 4px",borderTop:n>0||s?"1px solid var(--border)":"none",color:"var(--text-dim)",fontSize:10,fontWeight:600,letterSpacing:0,textTransform:"uppercase"},children:e.provider}),e.options.map(e=>(0,r.jsx)(d3,{active:e.modelId===t?.modelId&&e.provider===t?.provider,label:e.name,onClick:()=>{let r;return r=e.modelId===t?.modelId&&e.provider===t?.provider,void(z(!1),E(""),(!r||c)&&o(e.provider,e.modelId))}},`${e.provider}:${e.modelId}`))]},e.provider))]})]}))]})}function d3({active:e,label:t,onClick:o}){return(0,r.jsxs)("button",{type:"button",role:"option","aria-selected":e,onClick:o,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",border:"none",background:e?"var(--bg-selected)":"none",color:e?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:e?600:400,textAlign:"left",whiteSpace:"nowrap"},onMouseEnter:t=>{e||(t.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:t=>{e||(t.currentTarget.style.background="none")},children:[e?(0,r.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},"aria-hidden":"true",children:(0,r.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,r.jsx)("span",{style:{width:10,flexShrink:0}}),(0,r.jsx)("span",{title:t,style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis"},children:t})]})}let d7=["read","bash","edit","write","grep","find","ls"],d9=["","off","minimal","low","medium","high","xhigh","max"],ce={name:"custom-agent",displayName:"Custom agent",description:"",systemPrompt:"",tools:["read","bash","edit","write","grep","find","ls"],loadSkills:!1,loadExtensions:!1,inheritContext:!1,runInBackground:!1,enabled:!0},ct={width:"100%",minWidth:0,height:34,padding:"0 9px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg)",color:"var(--text)",fontSize:12,outline:"none"},co={background:"var(--bg-panel)",color:"var(--text-dim)",cursor:"default"};function cr(e){return{name:e.name,displayName:e.displayName,description:e.description,systemPrompt:e.systemPrompt,tools:[...e.tools],loadSkills:e.loadSkills,loadExtensions:e.loadExtensions,...e.model?{model:e.model}:{},...e.thinking?{thinking:e.thinking}:{},...e.maxTurns?{maxTurns:e.maxTurns}:{},inheritContext:e.inheritContext,runInBackground:e.runInBackground,enabled:e.enabled}}function cn(e){return`${e.scope}:${e.name}`}function cs(e){return"global"===e||"project"===e}function ci(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function ca({label:e,children:t}){return(0,r.jsx)(dY,{label:e,children:t})}function cl({checked:e,disabled:t,label:o,onChange:n}){return(0,r.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:7,color:t?"var(--text-dim)":"var(--text-muted)",fontSize:12,cursor:t?"default":"pointer"},children:[(0,r.jsx)("input",{type:"checkbox",checked:e,disabled:t,onChange:e=>n(e.target.checked)}),o]})}function cd({cwd:e,sessionId:t=null,onClose:o,onReloaded:s,embedded:i=!1}){let a=O(),{t:l}=(0,A.s)(),[d,c]=(0,n.useState)([]),[p,u]=(0,n.useState)([]),[h,g]=(0,n.useState)(!0),[m,f]=(0,n.useState)(null),[x,k]=(0,n.useState)(()=>dL("agents",e)),[v,y]=(0,n.useState)(ce),[b,w]=(0,n.useState)("view"),[j,S]=(0,n.useState)("global"),[C,T]=(0,n.useState)(!0),[R,z]=(0,n.useState)(!1),[I,M]=(0,n.useState)(!1),[P,E]=(0,n.useState)(!1),[W,F]=(0,n.useState)(null),[D,N]=(0,n.useState)(!1),[L,$]=(0,n.useState)(!0),[H,B]=(0,n.useState)(!1),[U,_]=(0,n.useState)(null),[q,V]=(0,n.useState)(!1),[K,G]=(0,n.useState)(!1),J=(0,n.useMemo)(()=>d.find(e=>cn(e)===x)??null,[d,x]),Y=(0,n.useMemo)(()=>p.map(e=>({provider:e.provider,modelId:e.id,name:e.name})),[p]),X=(0,n.useCallback)(async t=>{T(!0),F(null);try{let o=await fetch(`/api/subagents/profiles?cwd=${encodeURIComponent(e)}`,{cache:"no-store"}),r=await o.json();if(!o.ok||r.error)throw Error(r.error??`HTTP ${o.status}`);let n=r.profiles??[];c(n);let s=t??dL("agents",e),i=n.find(e=>cn(e)===s)??n.find(e=>"project"===e.scope)??n.find(e=>"global"===e.scope)??n[0]??null;k(i?cn(i):null),i&&(y(cr(i)),w(cs(i.scope)?"edit":"view"),cs(i.scope)&&S(i.scope))}catch(e){F(e instanceof Error?e.message:String(e))}finally{T(!1)}},[e]);(0,n.useEffect)(()=>{X()},[X]),(0,n.useEffect)(()=>{let e=new AbortController;return $(!0),_(null),(async()=>{try{let t=await fetch("/api/subagents/settings",{cache:"no-store",signal:e.signal}),o=await t.json();if(!t.ok||o.error||"boolean"!=typeof o.enabled)throw Error(o.error??`HTTP ${t.status}`);N(o.enabled)}catch(t){if(e.signal.aborted)return;_(t instanceof Error?t.message:String(t))}finally{e.signal.aborted||$(!1)}})(),()=>e.abort()},[]),(0,n.useEffect)(()=>{x&&function(e,t,o,r=dD()){if(!r||!t)return;let n=dN(e,o);if(n)try{let e=dA(r);e.selections={...e.selections,[n]:t},r.setItem(dF,JSON.stringify(e))}catch{}}("agents",x,e)},[e,x]),(0,n.useEffect)(()=>{let t=new AbortController;return g(!0),f(null),(async()=>{try{let o=await fetch(`/api/models?cwd=${encodeURIComponent(e)}`,{signal:t.signal}),r=await o.json();if(!o.ok||r.error)throw Error(r.error??`HTTP ${o.status}`);u(r.modelList??[]),f(r.modelError??null)}catch(e){if(t.signal.aborted)return;f(e instanceof Error?e.message:String(e))}finally{t.signal.aborted||g(!1)}})(),()=>t.abort()},[e]);let Z=async()=>{z(!0),F(null),M(!1);try{let t=await fetch("/api/subagents/profiles",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,scope:j,profile:v})}),o=await t.json();if(!t.ok||o.error||!o.profile)throw Error(o.error??`HTTP ${t.status}`);await X(cn(o.profile)),M(!0),setTimeout(()=>M(!1),2e3)}catch(e){F(e instanceof Error?e.message:String(e))}finally{z(!1)}},Q=async()=>{if(J&&cs(J.scope)&&window.confirm(l("agents.deleteConfirm",{name:J.displayName}))){z(!0),F(null);try{let t=await fetch("/api/subagents/profiles",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,scope:J.scope,name:J.name})}),o=await t.json();if(!t.ok||o.error)throw Error(o.error??`HTTP ${t.status}`);await X()}catch(e){F(e instanceof Error?e.message:String(e))}finally{z(!1)}}},ee="view"!==b,et="create"===b,eo=!ee||R||P,er=et?j:J?.scope,en=et?"global"===j?`~/.pi/agent/agents/${v.name||"..."}.md`:`./.pi/agents/${v.name||"..."}.md`:J?function(e,t){if(!e.filePath)return null;if(("project"===e.scope||"workspace"===e.scope)&&e.filePath.startsWith(t)){let o=e.filePath.slice(t.length).replace(/^[/\\]/,"");return`./${o}`}return ci(e.filePath)}(J,e)??l("agents.builtinPath"):"",es=et?en:J?.filePath??en,ei=!v.model||p.some(e=>`${e.provider}/${e.id}`===v.model),ea=(()=>{if(!v.model)return null;let e=v.model.indexOf("/");return e<0?{provider:"",modelId:v.model}:{provider:v.model.slice(0,e),modelId:v.model.slice(e+1)}})(),el=eo?{...ct,...co}:ct,ed=(e,t)=>{y(o=>({...o,[e]:t}))},ec=async t=>{if(et)return void ed("enabled",t);if(J&&cs(J.scope)){E(!0),F(null);try{let o=await fetch("/api/subagents/profiles",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,scope:J.scope,name:J.name,enabled:t})}),r=await o.json();if(!o.ok||r.error||!r.profile)throw Error(r.error??`HTTP ${o.status}`);let n=r.profile;c(e=>e.map(e=>cn(e)===cn(n)?n:e)),y(e=>({...e,enabled:n.enabled}))}catch(e){F(e instanceof Error?e.message:String(e))}finally{E(!1)}}},ep=async e=>{B(!0),_(null);try{let o=await fetch("/api/subagents/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:e})}),r=await o.json();if(!o.ok||r.error||"boolean"!=typeof r.enabled)throw Error(r.error??`HTTP ${o.status}`);N(r.enabled),V(!!t)}catch(e){_(e instanceof Error?e.message:String(e))}finally{B(!1)}},eu=async()=>{if(t){G(!0),_(null);try{await i6(t,{type:"reload"}),V(!1),s?.()}catch(e){_(e instanceof Error?e.message:String(e))}finally{G(!1)}}};return(0,r.jsxs)(d$,{embedded:i,title:l("common.agents"),subtitle:ci(e),closeLabel:l("agents.close"),onClose:o,children:[(0,r.jsxs)("div",{className:"agents-feature-setting",children:[(0,r.jsxs)("div",{className:"agents-feature-copy",children:[(0,r.jsx)("strong",{children:l("agents.builtInTitle")}),(0,r.jsx)("span",{children:l("agents.builtInDescription")}),q&&(0,r.jsx)("span",{role:"status",className:"agents-feature-reload-notice",children:l("agents.reloadRequired")})]}),(0,r.jsxs)("div",{className:"agents-feature-actions",children:[q&&t&&(0,r.jsx)(d0,{size:"small",onClick:()=>void eu(),disabled:K||H,children:K?l("agents.reloading"):l("agents.reloadSession")}),(0,r.jsx)(d1,{checked:D,disabled:L||K,loading:H,label:l("agents.builtInTitle"),onChange:e=>void ep(e)})]})]}),(0,r.jsxs)(dH,{children:[(0,r.jsxs)(dO,{children:[(0,r.jsx)(dB,{children:C?(0,r.jsx)("div",{style:{padding:10,color:"var(--text-dim)",fontSize:12},children:l("agents.loading")}):["project","global","workspace","builtin"].map(e=>{let t=d.filter(t=>t.scope===e);return 0===t.length?null:(0,r.jsxs)("div",{className:"config-sidebar-group",children:[(0,r.jsx)(dU,{children:l(`agents.scope.${e}`)}),t.map(e=>{let t,o,n=(t=e.name.toLowerCase(),o=dW[e.scope],d.some(e=>e.name.toLowerCase()===t&&dW[e.scope]>o));return(0,r.jsxs)(d_,{active:x===cn(e)&&!et,onClick:()=>{k(cn(e)),y(cr(e)),w(cs(e.scope)?"edit":"view"),cs(e.scope)&&S(e.scope),F(null)},children:[(0,r.jsx)(d4,{active:e.enabled}),(0,r.jsx)(dq,{className:`is-grow${e.enabled?"":" is-muted"}`,children:e.displayName}),n&&(0,r.jsx)("span",{className:"agents-overridden-label",children:l("agents.overridden")})]},cn(e))})]},e)})}),(0,r.jsx)(d2,{active:et,onClick:()=>{let e="custom-agent",t=2;for(;d.some(t=>t.name===e);)e=`custom-agent-${t++}`;k(null),y({...ce,name:e,displayName:e}),w("create"),S("global"),F(null)},children:l("agents.new")})]}),(0,r.jsx)(dZ,{children:(0,r.jsx)(dV,{className:"is-fill",children:J||et?(0,r.jsxs)(dV,{children:[(0,r.jsxs)(dK,{children:[(0,r.jsxs)(dG,{children:[er&&(0,r.jsx)("span",{className:`config-scope-tag${"project"===er?" is-project":""}`,children:l(`agents.scope.${er}`)}),(0,r.jsx)("span",{title:es,className:"config-detail-path",children:en})]}),(0,r.jsxs)(dJ,{children:[J&&("view"===b||"edit"===b)&&(0,r.jsx)(d0,{size:"small",onClick:()=>{if(!J)return;let e=function(e,t){let o=new Set(t.map(e=>e.name.toLowerCase())),r=`${e}-copy`,n=r,s=2;for(;o.has(n.toLowerCase());)n=`${r}-${s++}`;return n}(J.name,d);k(null),y({...cr(J),name:e,displayName:l("agents.copyName",{name:J.displayName})}),w("create"),S(cs(J.scope)?J.scope:"global"),F(null)},disabled:R||P,children:l("agents.duplicate")}),J&&cs(J.scope)&&"edit"===b&&(0,r.jsx)(d0,{variant:"danger",size:"small",onClick:()=>void Q(),disabled:R||P,children:l("agents.delete")}),(0,r.jsx)(d1,{checked:v.enabled,disabled:eo,label:v.enabled?l("agents.disable"):l("agents.enable"),onChange:e=>void ec(e)})]})]}),et&&(0,r.jsx)(ca,{label:l("agents.saveScope"),children:(0,r.jsx)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:3,padding:3,border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)"},children:["global","project"].map(e=>(0,r.jsx)("button",{type:"button",onClick:()=>S(e),disabled:R,style:{height:28,border:"none",borderRadius:4,background:j===e?"var(--bg-selected)":"transparent",color:j===e?"var(--text)":"var(--text-muted)",cursor:R?"default":"pointer",fontSize:11,fontWeight:j===e?600:400},children:l(`agents.scope.${e}`)},e))})}),(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:a?"1fr":"minmax(0, 1fr) minmax(0, 1fr)",gap:12},children:[(0,r.jsx)(ca,{label:l("agents.name"),children:et?(0,r.jsx)("input",{"aria-label":l("agents.name"),value:v.name,disabled:eo,onChange:e=>ed("name",e.target.value),style:ct}):(0,r.jsx)("code",{style:{minHeight:34,display:"flex",alignItems:"center",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text)",fontSize:12},children:v.name})}),(0,r.jsx)(ca,{label:l("agents.displayName"),children:(0,r.jsx)("input",{"aria-label":l("agents.displayName"),value:v.displayName,disabled:eo,onChange:e=>ed("displayName",e.target.value),style:el})})]}),(0,r.jsx)(ca,{label:l("agents.description"),children:(0,r.jsx)("input",{"aria-label":l("agents.description"),value:v.description,disabled:eo,onChange:e=>ed("description",e.target.value),style:el})}),(0,r.jsx)(ca,{label:l("agents.prompt"),children:(0,r.jsx)("textarea",{className:"agents-system-prompt","aria-label":l("agents.prompt"),value:v.systemPrompt,disabled:eo,onChange:e=>ed("systemPrompt",e.target.value),style:{...el,height:195,minHeight:195,maxHeight:"60vh",padding:9,overflow:"auto",resize:eo?"none":"vertical",lineHeight:1.5}})}),(0,r.jsx)(ca,{label:l("agents.tools"),children:(0,r.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px"},children:d7.map(e=>(0,r.jsx)(cl,{label:e,disabled:eo,checked:v.tools.includes(e),onChange:t=>ed("tools",t?[...v.tools,e]:v.tools.filter(t=>t!==e))},e))})}),(0,r.jsx)(ca,{label:l("agents.resources"),children:(0,r.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 20px"},children:[(0,r.jsx)(cl,{label:l("agents.loadSkills"),disabled:eo,checked:v.loadSkills,onChange:e=>ed("loadSkills",e)}),(0,r.jsx)(cl,{label:l("agents.loadExtensions"),disabled:eo,checked:v.loadExtensions,onChange:e=>ed("loadExtensions",e)})]})}),(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:a?"1fr":"minmax(0, 1.5fr) minmax(120px, 0.75fr) minmax(100px, 0.5fr)",gap:12},children:[(0,r.jsx)(ca,{label:l("agents.model"),children:(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)(d5,{options:Y,value:ea,onChange:(e,t)=>ed("model",`${e}/${t}`),onClear:()=>ed("model",void 0),emptyLabel:h?l("agents.modelsLoading"):l("agents.inherit"),selectedLabel:v.model&&!ei?l("agents.modelUnavailable",{model:v.model}):void 0,disabled:eo||h||0===p.length&&!v.model,ariaLabel:l("agents.model"),variant:"field",placement:"auto"}),m&&(0,r.jsx)("span",{style:{color:"#ef4444",fontSize:10},children:m})]})}),(0,r.jsx)(ca,{label:l("agents.thinking"),children:(0,r.jsx)("select",{"aria-label":l("agents.thinking"),value:v.thinking??"",disabled:eo,onChange:e=>ed("thinking",e.target.value||void 0),style:el,children:d9.map(e=>(0,r.jsx)("option",{value:e,children:e||l("agents.inherit")},e||"default"))})}),(0,r.jsx)(ca,{label:l("agents.maxTurns"),children:(0,r.jsx)("input",{"aria-label":l("agents.maxTurns"),type:"number",min:1,value:v.maxTurns??"",disabled:eo,onChange:e=>ed("maxTurns",e.target.value?Number(e.target.value):void 0),style:el})})]}),(0,r.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",gap:"10px 20px"},children:[(0,r.jsx)(cl,{label:l("agents.inheritContext"),disabled:eo,checked:v.inheritContext,onChange:e=>ed("inheritContext",e)}),(0,r.jsx)(cl,{label:l("agents.background"),disabled:eo,checked:v.runInBackground,onChange:e=>ed("runInBackground",e)})]})]}):(0,r.jsx)(dX,{children:l("agents.empty")})})})]}),(0,r.jsx)(dQ,{status:(U||W)&&(0,r.jsx)("span",{role:"alert",style:{color:"#ef4444"},children:U||W}),children:ee&&(0,r.jsxs)(d0,{variant:"primary",onClick:()=>void Z(),disabled:R||I||P||!v.name.trim(),className:I?"is-success":void 0,children:[I&&(0,r.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",className:"config-button-success-icon",children:(0,r.jsx)("polyline",{points:"20 6 9 17 4 12"})}),(0,r.jsx)("span",{children:I?l("i18n.saved"):R?l("agents.saving"):l("agents.save")})]})})]})}function cc({sessionId:e,onSessionReloaded:t}){let{t:o}=(0,A.s)(),[s,i]=(0,n.useState)(null),[a,l]=(0,n.useState)(null);(0,n.useEffect)(()=>{let e=!1;return fetch("/api/tools/settings").then(async t=>{let o=await t.json();if(!t.ok||o.error)throw Error(o.error??`HTTP ${t.status}`);e||i(o)}).catch(t=>{e||l(t instanceof Error?t.message:String(t))}),()=>{e=!0}},[]);let d=(0,n.useCallback)(async o=>{l(null);try{let r=await fetch("/api/tools/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:o})}),n=await r.json();if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);i(n),e&&(await i6(e,{type:"reload"}),t())}catch(e){l(e instanceof Error?e.message:String(e))}},[t,e]);return(0,r.jsx)("div",{style:{padding:16,overflowY:"auto",minHeight:0,flex:1},children:(0,r.jsxs)(lh,{children:[(0,r.jsx)(lg,{children:(0,r.jsx)(a4,{label:o("desktop.usePowerShell"),description:o("desktop.shellToolDescription"),checked:s?.powerShellEnabled??!1,onChange:e=>void d(e)})}),(0,r.jsx)(lm,{children:(0,r.jsx)("div",{style:{padding:"10px 0",fontSize:12,lineHeight:1.5,color:"var(--text-dim)"},children:s?.isWindows?o("desktop.shellToolWindowsOnly"):a??o("desktop.shellToolMacOnly")})})]})})}function cp(e){return null==e?"—":i$(e)}function cu({sessionId:e,cwd:t}){let{t:o}=(0,A.s)(),[s,i]=(0,n.useState)(null),[a,l]=(0,n.useState)(null),[d,c]=(0,n.useState)(!1);(0,n.useEffect)(()=>{let t=!1;return e?(fetch(`/api/agent/${encodeURIComponent(e)}`).then(e=>e.ok?e.json():null).then(e=>{t||i(e?.state?.contextUsage??null)}).catch(()=>{}),()=>{t=!0}):void i(null)},[e]);let p=(0,n.useCallback)(async()=>{c(!0);try{let e=await fetch("/api/usage");e.ok&&l(await e.json())}catch{}finally{c(!1)}},[]);(0,n.useEffect)(()=>{p()},[p]);let u=(0,n.useMemo)(()=>a?.daily.slice(-14)??[],[a]),h=(0,n.useMemo)(()=>u.reduce((e,t)=>Math.max(e,t.tokens),0),[u]);return(0,r.jsxs)("div",{style:{flex:1,overflow:"auto",minWidth:0,padding:"16px 20px",display:"flex",flexDirection:"column",gap:16},children:[(0,r.jsx)("h3",{style:{margin:0,fontSize:15,fontWeight:600,color:"var(--text)"},children:o("desktop.usage")}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[(0,r.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text-muted)"},children:o("desktop.usageSession")}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[e?(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:12,borderRadius:12,border:"1px solid var(--border)",padding:16},children:s?(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:16},children:[(0,r.jsxs)("svg",{width:72,height:72,viewBox:"0 0 72 72",style:{flexShrink:0},children:[(0,r.jsx)("circle",{cx:36,cy:36,r:30,fill:"none",stroke:"var(--border)",strokeWidth:7}),(0,r.jsx)("circle",{cx:36,cy:36,r:30,fill:"none",stroke:"var(--accent)",strokeWidth:7,strokeLinecap:"round",strokeDasharray:2*Math.PI*30,strokeDashoffset:2*Math.PI*30*(1-Math.min(1,(s.percent??0)/100)),transform:"rotate(-90 36 36)",style:{transition:"stroke-dashoffset 0.4s ease"}}),(0,r.jsx)("text",{x:36,y:41,textAnchor:"middle",fontSize:15,fontWeight:700,fill:"var(--text)",children:null!=s.percent?`${s.percent.toFixed(0)}%`:"?"})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:3},children:[(0,r.jsx)("span",{style:{fontSize:13,color:"var(--text)"},children:o("desktop.usageContext",{used:cp(s.tokens),window:cp(s.contextWindow)})}),(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)"},children:o("desktop.usageContextHint")})]})]})}):(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)"},children:o("desktop.usageNoSessionData")})}):(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)"},children:o("desktop.usageNoSession")}),t&&(0,r.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t})]})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[(0,r.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text-muted)"},children:o("desktop.usageGlobal")}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,r.jsx)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(140px, 1fr))",gap:10},children:[{label:o("desktop.usageTotal"),value:cp(a?.totalTokens),sub:a?`${a.totalSessions} ${o("desktop.usageSessions")}`:"…"},{label:o("desktop.usageMessages"),value:a?String(a.messageCount):"…",sub:o("desktop.usageMessagesHint")}].map(e=>(0,r.jsxs)("div",{style:{borderRadius:12,border:"1px solid var(--border)",padding:"12px 14px",background:"var(--bg-panel)"},children:[(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-muted)",marginBottom:4},children:e.label}),(0,r.jsx)("div",{style:{fontSize:18,fontWeight:700,color:"var(--text)"},children:e.value}),(0,r.jsx)("div",{style:{fontSize:10.5,color:"var(--text-dim)",marginTop:2},children:e.sub})]},e.label))}),(0,r.jsxs)("div",{style:{borderRadius:12,border:"1px solid var(--border)",padding:"14px 16px"},children:[(0,r.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",marginBottom:10},children:o("desktop.usageDaily")}),0===u.length?(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)"},children:o(d?"desktop.featuresLoading":"desktop.usageNoData")}):(0,r.jsx)("div",{style:{display:"flex",alignItems:"flex-end",gap:6,height:96,overflowX:"auto"},children:u.map(e=>{let t=h>0?Math.max(4,Math.round(e.tokens/h*72)):4;return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:4,flexShrink:0},children:[(0,r.jsx)("div",{style:{fontSize:9,color:"var(--text-dim)"},children:e.tokens>0?cp(e.tokens):""}),(0,r.jsx)("div",{style:{width:8,height:t,borderRadius:4,background:e.tokens>0?"var(--accent)":"var(--bg-hover)",opacity:e.tokens>0?.85:1},title:`${e.day}: ${cp(e.tokens)}`}),(0,r.jsx)("div",{style:{fontSize:9,color:"var(--text-dim)"},children:e.day.slice(5)})]},e.day)})})]}),(0,r.jsxs)("div",{style:{borderRadius:12,border:"1px solid var(--border)",overflow:"hidden"},children:[(0,r.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",padding:"10px 14px",borderBottom:"1px solid var(--border)"},children:o("desktop.usageTopSessions")}),a&&0===a.sessions.length?(0,r.jsx)("div",{style:{padding:"14px",fontSize:12,color:"var(--text-muted)"},children:o("desktop.usageNoData")}):(a?.sessions??[]).slice(0,12).map(e=>(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"8px 14px",borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)("span",{style:{flex:1,minWidth:0,fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name??e.firstMessage??e.id}),(0,r.jsx)("span",{style:{flexShrink:0,fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:cp(e.tokens)})]},e.path))]})]})]})]})}function ch(){let{t:e}=(0,A.s)(),[t,o]=(0,n.useState)(!1),[s,i]=(0,n.useState)("");(0,n.useEffect)(()=>{o(new URLSearchParams(window.location.search).has("piweb_connected")),i(window.location.host)},[]);let a=(0,n.useCallback)(()=>{window.location.href="piweb-switch://manage"},[]);return t?(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",flex:1,minWidth:0,minHeight:0,overflowY:"auto"},children:[(0,r.jsx)("header",{style:{padding:"18px 22px 14px",borderBottom:"1px solid var(--border)"},children:(0,r.jsx)("h1",{style:{margin:0,fontSize:16,fontWeight:700,color:"var(--text)"},children:e("desktop.server")})}),(0,r.jsxs)("div",{style:{padding:"18px 22px",display:"flex",flexDirection:"column",gap:14},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"12px 14px",borderRadius:10,background:"var(--bg-hover)",border:"1px solid var(--border)"},children:[(0,r.jsx)(a_.X,{size:18,color:"var(--accent)"}),(0,r.jsxs)("div",{style:{minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)"},children:e("desktop.serverCurrent")}),(0,r.jsx)("div",{style:{fontSize:14,fontWeight:600,color:"var(--text)",fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:s})]})]}),(0,r.jsxs)("button",{type:"button",onClick:a,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:8,padding:"10px 16px",borderRadius:10,background:"linear-gradient(135deg, var(--accent), var(--accent-hover, var(--accent)))",color:"#fff",fontSize:14,fontWeight:600,cursor:"pointer",border:"none"},children:[(0,r.jsx)(lw.o,{size:16}),e("desktop.serverSwitch")]}),(0,r.jsx)("p",{style:{margin:0,fontSize:12.5,lineHeight:1.7,color:"var(--text-muted)"},children:e("desktop.serverSwitchHint")})]})]}):null}let cg=[{id:"server",labelKey:"desktop.server",Icon:a_.X},{id:"display",labelKey:"desktop.display",Icon:aq.V},{id:"chat",labelKey:"desktop.chat",Icon:aV.W},{id:"models",labelKey:"desktop.models",Icon:z.f},{id:"skills",labelKey:"desktop.skills",Icon:I.B},{id:"plugins",labelKey:"desktop.plugins",Icon:M.F},{id:"proxy",labelKey:"desktop.proxy",Icon:aK.l},{id:"features",labelKey:"desktop.features",Icon:g.l},{id:"logs",labelKey:"desktop.logs",Icon:w.B},{id:"snippets",labelKey:"desktop.snippets",Icon:n7.c},{id:"usage",labelKey:"desktop.usage",Icon:aG._},{id:"mcp",labelKey:"desktop.mcp",Icon:aJ.b},{id:"subagents",labelKey:"desktop.subagents",Icon:aY.d},{id:"tools",labelKey:"desktop.tools",Icon:aJ.b},{id:"backup",labelKey:"desktop.backup",Icon:rQ.W},{id:"import",labelKey:"desktop.importSessions",Icon:E.z}];function cm({initialTab:e="models",cwd:t,sessionId:o,onCloseAction:s,onModelsSavedAction:i,onSessionReloadedAction:a,onSessionsChanged:l}){let d=O(),{t:c}=(0,A.s)(),[p,u]=(0,n.useState)("skills"===e||"plugins"===e?t?e:"display":e),[g,m]=(0,n.useState)(!1);(0,n.useEffect)(()=>{m(new URLSearchParams(window.location.search).has("piweb_connected"))},[]);let f=g?cg:cg.filter(({id:e})=>"server"!==e),[x,k]=(0,n.useState)(!1),[v,y]=(0,n.useState)(null),b=(0,n.useRef)(new Set),w=(0,n.useCallback)(e=>(b.current.add(e),()=>{b.current.delete(e)}),[]),j=(0,n.useCallback)(async()=>{if(!x){k(!0),y(null);try{let e=(await Promise.allSettled([...b.current].map(e=>e()))).find(e=>"rejected"===e.status);if(e)throw e.reason;s()}catch(e){y(e instanceof Error?e.message:String(e))}finally{k(!1)}}},[x,s]);return(0,r.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&&j()},children:(0,r.jsxs)("section",{role:"dialog","aria-modal":"true","aria-label":c("desktop.settings"),className:"settings-modal",style:{width:d?"calc(100vw - 16px)":1e3,maxWidth:"calc(100vw - 16px)",height:d?"calc(100dvh - 16px)":"80vh",maxHeight:"calc(100dvh - 16px)",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,r.jsxs)("header",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 18px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10,minWidth:0},children:[(0,r.jsx)("span",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:c("desktop.settings")}),"models"===p?(0,r.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:"~/.pi/agent/models.json"}):t&&(0,r.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t})]}),(0,r.jsx)("button",{type:"button",onClick:()=>{j()},disabled:x,title:c("desktop.closeSettings"),"aria-label":c("desktop.closeSettings"),style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",padding:4,display:"flex"},children:(0,r.jsx)(h.X,{size:18,"aria-hidden":"true"})})]}),(0,r.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:d?"column":"row",minHeight:0,overflow:"hidden",pointerEvents:x?"none":void 0},children:[(0,r.jsx)("nav",{"aria-label":c("desktop.settingsSections"),style:{display:"flex",flexDirection:d?"row":"column",gap:4,width:d?"100%":150,padding:8,flexShrink:0,minWidth:0,background:"var(--bg-panel)",borderRight:d?"none":"1px solid var(--border)",borderBottom:d?"1px solid var(--border)":"none",overflowX:d?"auto":void 0,overflowY:d?"hidden":void 0,WebkitOverflowScrolling:d?"touch":void 0},children:f.filter(({id:e})=>!(d&&"import"===e)).map(({id:e,labelKey:o,Icon:n})=>{let s=("skills"===e||"plugins"===e)&&!t,i=p===e;return(0,r.jsxs)("button",{type:"button",disabled:s,onClick:()=>u(e),"aria-current":i?"page":void 0,style:{display:"flex",alignItems:"center",gap:8,flex:d?"0 0 auto":void 0,whiteSpace:"nowrap",width:d?void 0:"100%",padding:"8px 10px",border:"none",borderRadius:6,background:i?"var(--bg-selected)":"none",color:i?"var(--text)":"var(--text-muted)",cursor:s?"not-allowed":"pointer",opacity:s?.4:1,fontSize:12,fontWeight:i?600:400,textAlign:"left",transition:"background 0.12s, color 0.12s"},title:c(o),"aria-label":c(o),onMouseEnter:e=>{i||s||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{i||(e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)")},children:[(0,r.jsx)(n,{size:16,"aria-hidden":"true"}),!d&&(0,r.jsx)("span",{children:c(o)})]},e)})}),(0,r.jsx)("div",{style:{display:"server"===p?"flex":"none",flex:1,minWidth:0,minHeight:0},children:(0,r.jsx)(ch,{})}),(0,r.jsx)("div",{style:{display:"display"===p?"flex":"none",flex:1,minWidth:0,minHeight:0},children:(0,r.jsx)(lp,{})}),(0,r.jsx)("div",{style:{display:"chat"===p?"flex":"none",flex:1,minWidth:0,minHeight:0},children:(0,r.jsx)(a3,{})}),(0,r.jsx)("div",{style:{display:"models"===p?"flex":"none",flex:1,minWidth:0,minHeight:0},children:(0,r.jsx)(dn,{embedded:!0,sessionId:o,onSavedAction:i,onRegisterFlush:w})}),t&&(0,r.jsx)("div",{style:{display:"skills"===p?"flex":"none",flex:1,minWidth:0,minHeight:0},children:(0,r.jsx)(dz,{cwd:t,embedded:!0,sessionId:o})}),t&&(0,r.jsx)("div",{style:{display:"plugins"===p?"flex":"none",flex:1,minWidth:0,minHeight:0},children:(0,r.jsx)(dk,{cwd:t,sessionId:o,embedded:!0,onReloadedAction:a})}),(0,r.jsx)("div",{style:{display:"proxy"===p?"flex":"none",flex:1,minWidth:0,minHeight:0},children:(0,r.jsx)(dy,{})}),(0,r.jsx)("div",{style:{display:"features"===p?"flex":"none",flex:1,minWidth:0,minHeight:0},children:(0,r.jsx)(lb,{})}),(0,r.jsx)("div",{style:{display:"logs"===p?"flex":"none",flex:1,minWidth:0,minHeight:0},children:(0,r.jsx)(dI,{})}),(0,r.jsx)("div",{style:{display:"snippets"===p?"flex":"none",flex:1,minWidth:0,minHeight:0},children:(0,r.jsx)(dE,{})}),(0,r.jsx)("div",{style:{display:"usage"===p?"flex":"none",flex:1,minWidth:0,minHeight:0},children:(0,r.jsx)(cu,{sessionId:o,cwd:t})}),(0,r.jsx)("div",{style:{display:"mcp"===p?"flex":"none",flex:1,minWidth:0,minHeight:0},children:(0,r.jsx)(l$,{sessionId:o})}),(0,r.jsx)("div",{style:{display:"subagents"===p?"flex":"none",flex:1,minWidth:0,minHeight:0},children:(0,r.jsx)(cd,{cwd:t??"",sessionId:o,onClose:s})}),(0,r.jsx)("div",{style:{display:"tools"===p?"flex":"none",flex:1,minWidth:0,minHeight:0},children:(0,r.jsx)(cc,{sessionId:o,onSessionReloaded:a})}),(0,r.jsx)("div",{style:{display:"backup"===p?"flex":"none",flex:1,minWidth:0,minHeight:0},children:(0,r.jsx)(a0,{cwd:t})}),(0,r.jsx)("div",{style:{display:"import"===p?"flex":"none",flex:1,minWidth:0,minHeight:0,overflowY:"auto"},children:(0,r.jsx)(lS,{onSessionsChanged:l})})]}),v&&(0,r.jsx)("div",{style:{padding:"6px 18px",borderTop:"1px solid var(--border)",color:"#f87171",fontSize:11},children:v})]})})}let cf=new Set(["awaiting_input","review","failed"]),cx=(0,n.createContext)(null);function ck(){let e=(0,n.useContext)(cx);if(!e)throw Error("useTasksView must be used within TasksViewProvider");return e}function cv({children:e}){let{t}=(0,A.s)(),o=(0,n.useRef)(t);(0,n.useEffect)(()=>{o.current=t},[t]);let[s,i]=(0,n.useState)([]),[a,l]=(0,n.useState)([]),d=(0,n.useRef)(0),c=(0,n.useCallback)(async()=>{let e=++d.current;try{let t=await (0,sS.Wt)(),o=(await Promise.all(t.map(e=>(0,sS.Vk)(e).catch(()=>[])))).flat().sort((e,t)=>t.id-e.id);if(e!==d.current)return;l(e=>cy(e,t)?e:t),i(e=>cy(e,o)?e:o)}catch{}},[]);(0,n.useEffect)(()=>{c();let e=null,t=!1,o=()=>{t||((e=new EventSource("/api/tasks/events")).onmessage=()=>{c()},e.onerror=()=>{e?.close(),e=null,c(),setTimeout(o,2e3)})};o();let r=()=>{"visible"===document.visibilityState&&c()},n=()=>void c();document.addEventListener("visibilitychange",r),window.addEventListener("online",n);let s=setInterval(()=>void c(),6e4);return()=>{t=!0,e?.close(),document.removeEventListener("visibilitychange",r),window.removeEventListener("online",n),clearInterval(s)}},[c]);let p=(0,n.useMemo)(()=>s.filter(e=>cf.has(e.status)&&null==e.archivedAt).length,[s]),u=(0,n.useRef)(null);(0,n.useEffect)(()=>{let e=u.current;if((u.current=new Map(s.map(e=>[e.id,e.status])),e&&0!==s.length)&&"Notification"in window){for(let o of s)if(e.get(o.id)!==o.status&&("review"===o.status||"failed"===o.status)&&null==o.archivedAt&&"visible"!==document.visibilityState)try{let e="review"===o.status?t("tasks.notifyReview",{title:o.title}):t("tasks.notifyFailed",{title:o.title});!function(e,t){new Promise(o=>{if(!("Notification"in window))return void o();let r=()=>{try{new Notification(e,{body:t,tag:"pi-tasks"})}catch{}o()};"granted"===Notification.permission?r():"denied"!==Notification.permission?Notification.requestPermission().then(e=>{"granted"===e?r():o()}):o()})}("Pi Web Tasks",e)}catch{}}},[s,t]);let h=(0,n.useMemo)(()=>({tasks:s,projects:a,attentionCount:p,refetch:c}),[s,a,p,c]);return(0,r.jsx)(cx.Provider,{value:h,children:e})}function cy(e,t){return JSON.stringify(e)===JSON.stringify(t)}var cb=o(4539),cw=o(12449),cj=o(2571);let cS=["todo","inProgress","attention","done"];function cC(e){return"review"===e.status&&0===e.filesChanged}function cT(){return{defaultAgentType:null,modeId:null,configValues:{},autoProcess:!0,maxConcurrent:1,mergeStrategy:"merge",deleteWorktreeDefault:!0,preflightCommand:null,initCommand:null,stagePrompts:null}}let cR=["todo","inProgress","attention","done"],cz={todo:{id:"todo",marker:"var(--text-dim)"},inProgress:{id:"inProgress",marker:"var(--accent)"},attention:{id:"attention",marker:"#f59e0b"},done:{id:"done",marker:"#10b981"}};var cI=o(54775),cM=o(98998),cP=o(36668);function cE({task:e}){let{t}=(0,A.s)(),o=t("failed"===e.status&&"interrupted"===e.failureReason?"tasks.statusInterrupted":function(e){switch(e){case"todo":return"tasks.statusTodo";case"queued":return"tasks.statusQueued";case"preparing":return"tasks.statusPreparing";case"running":return"tasks.statusRunning";case"awaiting_input":return"tasks.statusAwaitingInput";case"review":return"tasks.statusReview";case"merging":return"tasks.statusMerging";case"done":return"tasks.statusDone";case"failed":return"tasks.statusFailed";case"canceled":return"tasks.statusCanceled"}}(e.status)),n={display:"inline-flex",alignItems:"center",gap:4,borderRadius:999,padding:"2px 8px",fontSize:10,fontWeight:600,lineHeight:1.4,flexShrink:0,whiteSpace:"nowrap"};switch(e.status){case"queued":case"preparing":case"running":case"merging":return(0,r.jsxs)("span",{style:{...n,color:"var(--accent)"},children:[(0,r.jsx)(cI.N,{size:11,className:"pi-spin",style:{animation:"pi-spin 1s linear infinite"},"aria-hidden":"true"}),o]});case"awaiting_input":case"review":return(0,r.jsx)("span",{style:{...n,border:"1px solid rgba(245,158,11,0.45)",background:"rgba(245,158,11,0.08)",color:"#d97706"},children:o});case"done":return(0,r.jsxs)("span",{style:{...n,background:"rgba(16,185,129,0.12)",color:"#059669"},children:[(0,r.jsx)(m.J,{size:10,weight:"bold","aria-hidden":"true"}),o]});case"failed":return(0,r.jsx)("span",{style:{...n,background:"rgba(239,68,68,0.12)",color:"#dc2626"},children:o});default:return(0,r.jsx)("span",{style:{...n,background:"var(--bg-hover)",color:"var(--text-muted)"},children:o})}}function cW({task:e}){let t=e.preflight;if(!t||"review"!==e.status)return null;let o="passed"===t.status?{background:"rgba(16,185,129,0.12)",color:"#059669"}:"failed"===t.status?{background:"rgba(239,68,68,0.12)",color:"#dc2626"}:{background:"var(--bg-hover)",color:"var(--text-muted)"};return(0,r.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:4,borderRadius:999,padding:"1px 6px",fontSize:10,fontWeight:500,lineHeight:1.5,maxWidth:"100%",...o},title:t.command,children:["running"===t.status?(0,r.jsx)(cI.N,{size:10,style:{animation:"pi-spin 1s linear infinite"},"aria-hidden":"true"}):"passed"===t.status?(0,r.jsx)(nv.r,{size:10,"aria-hidden":"true"}):(0,r.jsx)(iU.J,{size:10,"aria-hidden":"true"}),(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.command})]})}function cF({task:e,folderName:t,now:o,onOpen:n,onStart:s,onCancel:i,onRetry:a,onRequeue:l,onViewSession:d,onMerge:c,onArchive:p,onEdit:u}){let{t:h}=(0,A.s)(),g=null!=e.archivedAt,f="running"===e.status||"awaiting_input"===e.status||"merging"===e.status,x=null!=e.filesChanged&&e.filesChanged>0?(0,r.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:3,fontFamily:"var(--font-mono)",fontSize:10},children:[(0,r.jsxs)("span",{style:{color:"#059669"},children:["+",e.additions??0]}),(0,r.jsxs)("span",{style:{color:"#dc2626"},children:["-",e.deletions??0]})]}):null,k=function(e,t){if(!e)return"";let o=new Date(e).getTime();if(Number.isNaN(o))return"";let r=Math.floor(Math.max(0,t-o)/6e4);if(r<1)return"now";if(r<60)return`${r}m`;let n=Math.floor(r/60);if(n<24)return`${n}h`;let s=Math.floor(n/24);return`${s}d`}(e.finishedAt??e.settledAt??e.startedAt??e.createdAt,o),{primary:v,more:y}=(()=>{let t=[],o=null;if(g)return{primary:o={icon:P.T,label:h("tasks.actionUnarchive"),onClick:p},more:t};switch(e.status){case"todo":o={icon:cj.j,label:h("tasks.actionStart"),onClick:s},t.push({icon:n9.S,label:h("tasks.actionEdit"),onClick:u});break;case"queued":case"preparing":case"running":case"awaiting_input":o={icon:cM.k,label:h("tasks.actionCancel"),onClick:i};break;case"review":o=cC(e)?{icon:m.J,label:h("tasks.actionComplete"),onClick:c}:{icon:cP.r,label:h("tasks.actionMerge"),onClick:c};break;case"merging":break;case"failed":o={icon:C.S,label:h("tasks.actionRetry"),onClick:a},t.push({icon:n9.S,label:h("tasks.actionEdit"),onClick:u}),t.push({icon:P.T,label:h("tasks.actionArchive"),onClick:p});break;case"done":o={icon:P.T,label:h("tasks.actionArchive"),onClick:p};break;case"canceled":o={icon:ny.f,label:h("tasks.actionRequeue"),onClick:l},t.push({icon:P.T,label:h("tasks.actionArchive"),onClick:p})}return{primary:o,more:t}})(),b=[...y];return null!=e.conversationId&&b.push({icon:nk.y,label:h("tasks.actionViewSession"),onClick:d}),(0,r.jsxs)("div",{role:"button",tabIndex:0,onClick:n,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),n())},style:{display:"flex",flexDirection:"column",cursor:"pointer",borderRadius:12,border:"1px solid color-mix(in srgb, var(--border) 85%, transparent)",background:"var(--bg-panel)",padding:12,textAlign:"left",transition:"border-color 0.12s",opacity:g?.6:1,boxShadow:"0 1px 2px rgba(0,0,0,0.04)"},className:"task-card-hover",onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="color-mix(in srgb, var(--border) 85%, transparent)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:8},children:[(0,r.jsx)("span",{style:{minWidth:0,overflowWrap:"break-word",fontSize:13,fontWeight:500,lineHeight:1.4},children:e.title}),(0,r.jsx)(cE,{task:e})]}),(0,r.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"2px 6px",marginTop:6,fontSize:11,color:"var(--text-muted)"},children:[t?(0,r.jsx)("span",{style:{maxWidth:160,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t}):null,t&&e.workBranch?(0,r.jsx)("span",{style:{opacity:.5},children:"/"}):null,e.workBranch?(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:10,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:180},children:e.workBranch}):null,(t||e.workBranch)&&(x||k)?(0,r.jsx)("span",{style:{opacity:.5},children:"\xb7"}):null,x,x&&k?(0,r.jsx)("span",{style:{opacity:.5},children:"\xb7"}):null,k?(0,r.jsx)("span",{style:{flexShrink:0},children:k}):null,(0,r.jsx)(cW,{task:e})]}),e.lastError&&("failed"===e.status||"review"===e.status)?(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,marginTop:8,borderRadius:8,background:"rgba(239,68,68,0.08)",padding:"6px 8px",fontSize:11,color:"#dc2626"},children:[(0,r.jsx)(r0.t,{size:13,style:{flexShrink:0},"aria-hidden":"true"}),(0,r.jsx)("span",{style:{minWidth:0,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.lastError}),(0,r.jsx)("button",{type:"button",style:{flexShrink:0,fontWeight:600,background:"none",border:"none",cursor:"pointer",color:"inherit",fontSize:11,textDecoration:"underline"},onClick:e=>{e.stopPropagation(),n()},children:h("tasks.errorView")})]}):null,"review"===e.status&&e.resultSummary?(0,r.jsx)("p",{style:{margin:"6px 0 0",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden",fontSize:11,lineHeight:1.5,color:"var(--text-muted)"},children:e.resultSummary}):null,f&&e.latestProgress?(0,r.jsx)("p",{style:{margin:"6px 0 0",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden",fontSize:11,lineHeight:1.5,color:"var(--text-muted)",fontStyle:"italic"},children:e.latestProgress}):null,v||b.length>0?(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,marginTop:12,paddingTop:12,borderTop:"1px solid var(--border)"},children:[v?(0,r.jsxs)("button",{type:"button",onClick:e=>{e.stopPropagation(),v.onClick()},style:{display:"inline-flex",alignItems:"center",gap:5,padding:"4px 10px",borderRadius:7,background:"var(--accent)",color:"#fff",border:"none",cursor:"pointer",fontSize:11,fontWeight:600},children:[(0,r.jsx)(v.icon,{size:12,weight:"bold","aria-hidden":"true"}),v.label]}):null,(0,r.jsx)("div",{style:{flex:1}}),b.map(e=>(0,r.jsx)("button",{type:"button",title:e.label,"aria-label":e.label,onClick:t=>{t.stopPropagation(),e.onClick()},style:{display:"flex",alignItems:"center",justifyContent:"center",width:26,height:26,padding:0,borderRadius:999,background:"none",border:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",opacity:0,transition:"opacity 0.12s, background 0.12s, color 0.12s"},className:"task-card-secondary",onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:(0,r.jsx)(e.icon,{size:13,"aria-hidden":"true"})},e.label))]}):null]})}function cD({open:e,onOpenChange:t,task:o}){let{t:s}=(0,A.s)(),{refetch:i}=ck(),[a,l]=(0,n.useState)(""),[d,c]=(0,n.useState)(!1);if((0,n.useEffect)(()=>{e&&(l(""),c(!1))},[e,o]),!e||!o)return null;let p=async()=>{if(!d){c(!0);try{await (0,sS.oQ)(o.id,o.projectRoot,"cancel",{reason:a.trim()||null}),t(!1),i()}catch(e){console.error("cancel failed",e)}finally{c(!1)}}};return(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:950,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.45)"},onMouseDown:e=>{e.target===e.currentTarget&&t(!1)},children:(0,r.jsxs)("div",{style:{width:"min(440px, calc(100vw - 48px))",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 16px 48px rgba(0,0,0,0.3)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 16px 0"},children:[(0,r.jsx)("h3",{style:{fontSize:15,fontWeight:600,margin:0},children:s("tasks.cancelTitle")}),(0,r.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":s("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex"},children:(0,r.jsx)(h.X,{size:16,"aria-hidden":"true"})})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,padding:"14px 16px 16px"},children:[(0,r.jsx)("p",{style:{margin:0,fontSize:12,lineHeight:1.5,color:"var(--text-muted)"},children:s("tasks.cancelDescription")}),(0,r.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)"},children:s("tasks.cancelReasonLabel")}),(0,r.jsx)("textarea",{value:a,onChange:e=>l(e.target.value),placeholder:s("tasks.cancelReasonPlaceholder"),rows:3,autoFocus:!0,style:{width:"100%",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"8px 10px",color:"var(--text)",fontSize:13,outline:"none",fontFamily:"inherit",resize:"vertical"}})]}),(0,r.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:4},children:[(0,r.jsx)("button",{type:"button",onClick:()=>t(!1),disabled:d,style:{padding:"8px 14px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:s("tasks.cancelKeep")}),(0,r.jsx)("button",{type:"button",onClick:()=>void p(),disabled:d,style:{padding:"8px 16px",borderRadius:8,background:"var(--accent)",color:"#fff",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:s("tasks.cancelSubmit")})]})]})]})})}function cA({open:e,onOpenChange:t,task:o}){let{t:s}=(0,A.s)(),{refetch:i}=ck(),[a,l]=(0,n.useState)(!0),[d,c]=(0,n.useState)(!1),p=o?.worktreePath!=null;if((0,n.useEffect)(()=>{if(!e||!o)return;c(!1);let t=!1;return(0,sS.CG)(o.projectRoot).then(e=>{t||l(e.deleteWorktreeDefault)}).catch(()=>{t||l(!0)}),()=>{t=!0}},[e,o]),!e||!o)return null;let u=async()=>{if(!d){c(!0);try{await (0,sS.ZX)(o.id,o.projectRoot,p&&a),t(!1),i()}catch(e){console.error("complete failed",e)}finally{c(!1)}}};return(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:950,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.45)"},onMouseDown:e=>{e.target===e.currentTarget&&t(!1)},children:(0,r.jsxs)("div",{style:{width:"min(440px, calc(100vw - 48px))",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 16px 48px rgba(0,0,0,0.3)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 16px 0"},children:[(0,r.jsx)("h3",{style:{fontSize:15,fontWeight:600,margin:0},children:s("tasks.completeTitle")}),(0,r.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":s("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex"},children:(0,r.jsx)(h.X,{size:16,"aria-hidden":"true"})})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,padding:"14px 16px 16px"},children:[(0,r.jsx)("p",{style:{margin:0,fontSize:12,lineHeight:1.5,color:"var(--text-muted)"},children:s("tasks.completeDescription")}),p?(0,r.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,cursor:"pointer"},children:[(0,r.jsx)("input",{type:"checkbox",checked:a,onChange:e=>l(e.target.checked),style:{accentColor:"var(--accent)"}}),s("tasks.completeDeleteWorktree")]}):null,(0,r.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:4},children:[(0,r.jsx)("button",{type:"button",onClick:()=>t(!1),disabled:d,style:{padding:"8px 14px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:s("i18n.cancel")}),(0,r.jsx)("button",{type:"button",onClick:()=>void u(),disabled:d,style:{padding:"8px 16px",borderRadius:8,background:"var(--accent)",color:"#fff",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:s("tasks.completeSubmit")})]})]})]})})}var cN=o(51285),cL=o(16894);function c$({open:e,onOpenChange:t,task:o,onViewSession:s,onMerge:i,onEdit:a,onCancel:l,onRetry:d,onRequeue:c,onComplete:p}){let{t:u}=(0,A.s)(),{refetch:g}=ck(),[f,x]=(0,n.useState)([]),[k,v]=(0,n.useState)([]),[b,w]=(0,n.useState)(null),[j,S]=(0,n.useState)(null),[R,z]=(0,n.useState)(!1),[I,M]=(0,n.useState)(!1),[E,W]=(0,n.useState)(""),[F,D]=(0,n.useState)(!1),[N,L]=(0,n.useState)(!1),[$,H]=(0,n.useState)(!1),O=o?.id??null,B=o?.projectRoot??null,U=(0,n.useCallback)(async()=>{if(null==O||null==B)return;let[e,t]=await Promise.all([(0,sS.HB)(B,O).catch(()=>[]),o?.worktreePath?(0,sS.JH)(B,O).then(e=>e.files).catch(()=>[]):Promise.resolve([])]);x(e),v(t)},[O,B,o?.worktreePath]);(0,n.useEffect)(()=>{if(!e||null==O)return;x([]),v([]),M(!1),W(""),U();let t=window.setInterval(()=>void U(),5e3);return()=>window.clearInterval(t)},[e,O,U]);let _=(0,n.useCallback)(async e=>{H(!0);try{await e()}catch(e){console.error("detail action failed",e)}finally{H(!1),g()}},[g]),q=(0,n.useCallback)(async e=>{if(null!=B&&null!=O){z(!0);try{let t=await (0,sS.h)(B,O,e);S(t.supported&&t.patch?t.patch:null)}catch{S(null)}finally{z(!1)}}},[B,O]),V=async()=>{null!=o&&null!=B&&(await _(()=>(0,sS.bH)(o.id,B,N)),t(!1))},K=async()=>{null!=o&&null!=B&&E.trim()&&(await _(()=>(0,sS.in)(o.id,B,E.trim())),M(!1),W(""))};if(!e||null==o||null==B)return null;let G=[];if(null==o.archivedAt)switch(o.status){case"todo":G.push({label:u("tasks.actionStart"),icon:cj.j,onClick:()=>void _(()=>(0,sS.oQ)(o.id,B,"start")),filled:!0}),G.push({label:u("tasks.actionEdit"),icon:n9.S,onClick:()=>a(o)});break;case"queued":case"preparing":case"running":case"awaiting_input":G.push({label:u("tasks.actionCancel"),icon:cM.k,onClick:()=>l(o),danger:!0});break;case"review":G.push({label:cC(o)?u("tasks.actionComplete"):u("tasks.actionMerge"),icon:cC(o)?m.J:cN.Y,onClick:()=>cC(o)?p(o):i(o),filled:!0}),G.push({label:u("tasks.actionReturn"),icon:ny.f,onClick:()=>M(!0)});break;case"failed":G.push({label:u("tasks.actionRetry"),icon:C.S,onClick:()=>d(o),filled:!0}),G.push({label:u("tasks.actionEdit"),icon:n9.S,onClick:()=>a(o)});break;case"done":G.push({label:u("tasks.actionArchive"),icon:P.T,onClick:()=>void _(()=>(0,sS.et)(o.id,B,!0))});break;case"canceled":G.push({label:u("tasks.actionRequeue"),icon:ny.f,onClick:()=>c(o),filled:!0})}else G.push({label:u("tasks.actionUnarchive"),icon:P.T,onClick:()=>void _(()=>(0,sS.et)(o.id,B,!1))});return null!=o.conversationId&&G.push({label:u("tasks.actionViewSession"),icon:nk.y,onClick:()=>s(o)}),(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:800,background:"rgba(0,0,0,0.35)"},onMouseDown:e=>{e.target===e.currentTarget&&t(!1)},children:(0,r.jsxs)("div",{style:{position:"absolute",top:0,right:0,bottom:0,width:"min(480px, 90vw)",background:"var(--bg-panel)",borderLeft:"1px solid var(--border)",display:"flex",flexDirection:"column",boxShadow:"-8px 0 32px rgba(0,0,0,0.2)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:12,padding:"16px 16px 0"},children:[(0,r.jsxs)("div",{style:{minWidth:0},children:[(0,r.jsx)("h3",{style:{margin:0,fontSize:15,fontWeight:600,lineHeight:1.4,overflowWrap:"break-word"},children:o.title}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:6},children:[(0,r.jsx)(cE,{task:o}),o.workBranch?(0,r.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:4,fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-muted)"},children:[(0,r.jsx)(y.Z,{size:12,"aria-hidden":"true"}),o.workBranch]}):null]})]}),(0,r.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":u("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex",flexShrink:0},children:(0,r.jsx)(h.X,{size:16,"aria-hidden":"true"})})]}),(0,r.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:8,padding:"14px 16px 0"},children:G.map(e=>{let t,o;return(0,r.jsxs)("button",{type:"button",onClick:e.onClick,disabled:$,style:(t=e.filled,o=e.danger,{display:"inline-flex",alignItems:"center",gap:5,padding:"7px 12px",borderRadius:8,fontSize:12,fontWeight:600,cursor:"pointer",background:t?"var(--accent)":o?"rgba(239,68,68,0.1)":"var(--bg-hover)",color:t?"#fff":o?"#dc2626":"var(--text)",border:t||o?"none":"1px solid var(--border)"}),children:[(0,r.jsx)(e.icon,{size:13,weight:"bold","aria-hidden":"true"}),e.label]},e.label)})}),I&&(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8,padding:"12px 16px 0"},children:[(0,r.jsx)("textarea",{value:E,onChange:e=>W(e.target.value),placeholder:u("tasks.returnPlaceholder"),rows:3,style:{width:"100%",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"8px 10px",color:"var(--text)",fontSize:12,resize:"vertical",fontFamily:"inherit"}}),(0,r.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:[(0,r.jsx)("button",{type:"button",onClick:()=>M(!1),style:{padding:"6px 12px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:u("i18n.cancel")}),(0,r.jsx)("button",{type:"button",onClick:()=>void K(),disabled:!E.trim(),style:{padding:"6px 14px",borderRadius:8,background:"var(--accent)",color:"#fff",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:u("tasks.returnSubmit")})]})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6,padding:"14px 16px 0",fontSize:12,color:"var(--text-muted)"},children:[(0,r.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,r.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",width:64},children:u("tasks.metaProject")}),(0,r.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)",fontSize:11},children:o.projectRoot})]}),o.createdAt?(0,r.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,r.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",width:64},children:u("tasks.metaCreated")}),(0,r.jsx)("span",{children:new Date(o.createdAt).toLocaleString()})]}):null,o.mergeCommit?(0,r.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,r.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",width:64},children:u("tasks.metaCommit")}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11},children:o.mergeCommit})]}):null]}),k.length>0&&(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4,padding:"14px 16px 0"},children:[(0,r.jsx)("span",{style:{fontSize:11,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.05em"},children:u("tasks.changedFiles")}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:2,maxHeight:140,overflowY:"auto"},children:k.map(e=>(0,r.jsxs)("button",{type:"button",onClick:()=>{var t;w(t=e.file),S(null),q(t)},style:{display:"flex",alignItems:"center",gap:8,textAlign:"left",padding:"4px 6px",borderRadius:6,background:"none",border:"none",color:"var(--text)",fontSize:12,cursor:"pointer"},children:[(0,r.jsx)(cL.o,{size:13,style:{flexShrink:0,color:"var(--text-muted)"},"aria-hidden":"true"}),(0,r.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)",fontSize:11},children:e.file}),(0,r.jsxs)("span",{style:{fontFamily:"var(--font-mono)",fontSize:10,color:"#059669",flexShrink:0},children:["+",e.additions]}),(0,r.jsxs)("span",{style:{fontFamily:"var(--font-mono)",fontSize:10,color:"#dc2626",flexShrink:0},children:["-",e.deletions]})]},e.file))})]}),null!=b&&(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6,padding:"12px 16px 0",minHeight:0,flexShrink:0},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,r.jsx)("span",{style:{fontSize:11,fontWeight:600,color:"var(--text-muted)"},children:u("tasks.diff")}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:10,color:"var(--text-muted)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:b}),(0,r.jsx)("button",{type:"button",onClick:()=>w(null),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:2,display:"flex"},children:(0,r.jsx)(h.X,{size:12,"aria-hidden":"true"})})]}),R?(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-muted)",padding:8},children:u("tasks.loading")}):j?(0,r.jsx)("pre",{style:{margin:0,maxHeight:200,overflow:"auto",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:10,fontSize:11,lineHeight:1.5,fontFamily:"var(--font-mono)",color:"var(--text-muted)",whiteSpace:"pre"},children:j.split("\n").map((e,t)=>{let o;return e.startsWith("+")&&!e.startsWith("+++")?o="#059669":e.startsWith("-")&&!e.startsWith("---")?o="#dc2626":e.startsWith("@@")&&(o="var(--accent)"),(0,r.jsx)("div",{style:{color:o},children:e||" "},t)})}):(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-muted)",padding:8},children:u("tasks.noDiff")})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4,padding:"14px 16px 0",flex:1,minHeight:0},children:[(0,r.jsx)("span",{style:{fontSize:11,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.05em"},children:u("tasks.timeline")}),(0,r.jsx)("div",{style:{flex:1,minHeight:0,overflowY:"auto",paddingBottom:8},children:0===f.length?(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",padding:8},children:u("tasks.noEvents")}):(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:2},children:[...f].reverse().map(e=>{var t;let o,n;return(0,r.jsxs)("div",{style:{display:"flex",gap:8,padding:"4px 6px",borderRadius:6,fontSize:11},children:[(0,r.jsx)("span",{style:{color:"var(--text-dim)",flexShrink:0,fontFamily:"var(--font-mono)",fontSize:10,paddingTop:1},children:new Date(e.createdAt).toLocaleTimeString()}),(0,r.jsx)("span",{style:{color:"var(--text)",flexShrink:0,fontWeight:500},children:(t=e.kind,(n=u(o=`tasks.event_${t}`))===o?t:n)}),e.payload?.feedback?(0,r.jsx)("span",{style:{color:"var(--text-muted)",fontStyle:"italic",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:String(e.payload.feedback)}):null]},e.id)})})})]}),(0,r.jsx)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:8,padding:"10px 16px",borderTop:"1px solid var(--border)",flexShrink:0},children:F?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:6,fontSize:12,cursor:"pointer"},children:[(0,r.jsx)("input",{type:"checkbox",checked:N,onChange:e=>L(e.target.checked),style:{accentColor:"var(--accent)"}}),u("tasks.deleteWorktree")]}),(0,r.jsx)("button",{type:"button",onClick:()=>D(!1),style:{padding:"6px 12px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:u("i18n.cancel")}),(0,r.jsx)("button",{type:"button",onClick:()=>void V(),disabled:$,style:{padding:"6px 14px",borderRadius:8,background:"#dc2626",color:"#fff",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:u("tasks.deleteConfirm")})]}):(0,r.jsxs)("button",{type:"button",onClick:()=>D(!0),style:{display:"inline-flex",alignItems:"center",gap:5,padding:"6px 12px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"#dc2626",fontSize:12,cursor:"pointer"},children:[(0,r.jsx)(T.l,{size:13,"aria-hidden":"true"}),u("tasks.delete")]})})]})})}var cH=o(17757);function cO({open:e,onOpenChange:t,task:o,defaultProject:s,projects:i,prefillTitle:a,prefillPrompt:l,onSubmit:d}){let{t:c}=(0,A.s)(),[p,u]=(0,n.useState)(""),[g,m]=(0,n.useState)(""),[f,x]=(0,n.useState)(""),[k,v]=(0,n.useState)([]),[y,b]=(0,n.useState)(""),[w,j]=(0,n.useState)(!1),S=(0,n.useRef)(!1);if((0,n.useEffect)(()=>{if(!e){S.current=!1;return}S.current||(S.current=!0,u(o?.projectRoot??s??i[0]??""),m(o?.title??a??""),x(o?.config?.prompt??l??""),(0,sS.VB)().then(v).catch(()=>void 0))},[e,o,s,i,a,l]),!e)return null;let C=async()=>{if(p&&g.trim()&&!w){j(!0);try{await d(p,g.trim(),{prompt:f.trim(),agentType:o?.config?.agentType??null,modelId:o?.config?.modelId??null,thinkingLevel:o?.config?.thinkingLevel??null}),t(!1)}catch(e){console.error("submit task failed",e)}finally{j(!1)}}},R=async()=>{if(y.trim()&&g.trim())try{await (0,sS.nY)({name:y.trim(),title:g.trim(),config:{prompt:f.trim()}}),b(""),(0,sS.VB)().then(v).catch(()=>void 0)}catch(e){console.error("save template failed",e)}},z=async e=>{try{await (0,sS.B_)(e),(0,sS.VB)().then(v).catch(()=>void 0)}catch(e){console.error("delete template failed",e)}},I={width:"100%",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"8px 10px",color:"var(--text)",fontSize:13,outline:"none"};return(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:900,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.45)"},onMouseDown:e=>{e.target===e.currentTarget&&t(!1)},children:(0,r.jsxs)("div",{style:{width:"min(520px, calc(100vw - 48px))",maxHeight:"80vh",overflowY:"auto",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 16px 48px rgba(0,0,0,0.3)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 16px 0"},children:[(0,r.jsx)("h3",{style:{fontSize:15,fontWeight:600,margin:0},children:o?c("tasks.editTitle"):c("tasks.newTitle")}),(0,r.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":c("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex"},children:(0,r.jsx)(h.X,{size:16,"aria-hidden":"true"})})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,padding:"14px 16px 16px"},children:[k.length>0&&(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)("span",{style:{fontSize:11,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.05em"},children:c("tasks.templates")}),(0,r.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:k.map(e=>(0,r.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:4,borderRadius:999,background:"var(--bg-hover)",padding:"3px 8px",fontSize:11},children:[(0,r.jsx)("button",{type:"button",onClick:()=>{m(e.title),x(e.config?.prompt??"")},style:{background:"none",border:"none",cursor:"pointer",color:"var(--text)",fontSize:11,padding:0},children:e.name}),(0,r.jsx)("button",{type:"button",onClick:()=>void z(e.id),"aria-label":c("tasks.deleteTemplate"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-dim)",padding:0,display:"flex"},children:(0,r.jsx)(T.l,{size:10,"aria-hidden":"true"})})]},e.id))})]}),(0,r.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)("span",{style:{fontSize:12,fontWeight:500,color:"var(--text)"},children:c("tasks.fieldProject")}),(0,r.jsx)("select",{value:p,onChange:e=>u(e.target.value),style:I,children:i.map(e=>(0,r.jsx)("option",{value:e,children:e.split("/").filter(Boolean).pop()??e},e))})]}),(0,r.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)("span",{style:{fontSize:12,fontWeight:500,color:"var(--text)"},children:c("tasks.fieldTitle")}),(0,r.jsx)("input",{value:g,onChange:e=>m(e.target.value),placeholder:c("tasks.fieldTitlePlaceholder"),style:I,autoFocus:!0})]}),(0,r.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)("span",{style:{fontSize:12,fontWeight:500,color:"var(--text)"},children:c("tasks.fieldPrompt")}),(0,r.jsx)("textarea",{value:f,onChange:e=>x(e.target.value),placeholder:c("tasks.fieldPromptPlaceholder"),rows:6,style:{...I,resize:"vertical",fontFamily:"inherit",lineHeight:1.5}})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,r.jsx)("input",{value:y,onChange:e=>b(e.target.value),placeholder:c("tasks.templateNamePlaceholder"),style:{...I,flex:1}}),(0,r.jsxs)("button",{type:"button",onClick:()=>void R(),disabled:!y.trim()||!g.trim(),style:{display:"inline-flex",alignItems:"center",gap:5,padding:"8px 12px",borderRadius:8,background:"var(--bg-hover)",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:[(0,r.jsx)(cH.D,{size:13,"aria-hidden":"true"}),c("tasks.saveAsTemplate")]})]}),(0,r.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:4},children:[(0,r.jsx)("button",{type:"button",onClick:()=>t(!1),style:{padding:"8px 14px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:c("i18n.cancel")}),(0,r.jsx)("button",{type:"button",onClick:()=>void C(),disabled:!p||!g.trim()||w,style:{padding:"8px 16px",borderRadius:8,background:"var(--accent)",color:"#fff",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:c("tasks.save")})]})]})]})})}function cB({open:e,onOpenChange:t,task:o}){let{t:s}=(0,A.s)(),{refetch:i}=ck(),[a,l]=(0,n.useState)(!0),[d,c]=(0,n.useState)(""),[p,u]=(0,n.useState)(!0),[g,m]=(0,n.useState)(!1);if((0,n.useEffect)(()=>{e&&o&&(l(!0),c(o.title),m(!1),(0,sS.CG)(o.projectRoot).then(e=>u(e.deleteWorktreeDefault)).catch(()=>u(!0)))},[e,o]),!e||!o)return null;let f=async()=>{if((a||d.trim())&&!g){m(!0);try{await (0,sS.oB)(o.id,o.projectRoot,a?null:d.trim(),p),t(!1),i()}catch(e){console.error("merge failed",e)}finally{m(!1)}}};return(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:950,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.45)"},onMouseDown:e=>{e.target===e.currentTarget&&t(!1)},children:(0,r.jsxs)("div",{style:{width:"min(440px, calc(100vw - 48px))",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 16px 48px rgba(0,0,0,0.3)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 16px 0"},children:[(0,r.jsx)("h3",{style:{fontSize:15,fontWeight:600,margin:0},children:s("tasks.mergeTitle")}),(0,r.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":s("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex"},children:(0,r.jsx)(h.X,{size:16,"aria-hidden":"true"})})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,padding:"14px 16px 16px"},children:[(0,r.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,cursor:"pointer"},children:[(0,r.jsx)("input",{type:"radio",checked:a,onChange:()=>l(!0),style:{accentColor:"var(--accent)"}}),s("tasks.mergeAutoMessage")]}),(0,r.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,cursor:"pointer"},children:[(0,r.jsx)("input",{type:"radio",checked:!a,onChange:()=>l(!1),style:{accentColor:"var(--accent)"}}),s("tasks.mergeManualMessage")]}),!a&&(0,r.jsx)("input",{value:d,onChange:e=>c(e.target.value),placeholder:s("tasks.mergeMessagePlaceholder"),style:{width:"100%",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"8px 10px",color:"var(--text)",fontSize:13,outline:"none",fontFamily:"inherit"}}),(0,r.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,cursor:"pointer"},children:[(0,r.jsx)("input",{type:"checkbox",checked:p,onChange:e=>u(e.target.checked),style:{accentColor:"var(--accent)"}}),s("tasks.mergeDeleteWorktree")]}),(0,r.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:4},children:[(0,r.jsx)("button",{type:"button",onClick:()=>t(!1),style:{padding:"8px 14px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:s("i18n.cancel")}),(0,r.jsx)("button",{type:"button",onClick:()=>void f(),disabled:!a&&!d.trim()||g,style:{padding:"8px 16px",borderRadius:8,background:"var(--accent)",color:"#fff",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:s("tasks.mergeConfirm")})]})]})]})})}function cU({open:e,onOpenChange:t,task:o,kind:s}){let{t:i}=(0,A.s)(),{refetch:a}=ck(),[l,d]=(0,n.useState)(""),[c,p]=(0,n.useState)(!1);if((0,n.useEffect)(()=>{e&&(d(""),p(!1))},[e,o]),!e||!o)return null;let u="retry"===s,g=async()=>{if(!c){p(!0);try{await (0,sS.oQ)(o.id,o.projectRoot,s,{note:l.trim()||null}),t(!1),a()}catch(e){console.error("restart failed",e)}finally{p(!1)}}};return(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:950,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.45)"},onMouseDown:e=>{e.target===e.currentTarget&&t(!1)},children:(0,r.jsxs)("div",{style:{width:"min(480px, calc(100vw - 48px))",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 16px 48px rgba(0,0,0,0.3)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 16px 0"},children:[(0,r.jsx)("h3",{style:{fontSize:15,fontWeight:600,margin:0},children:i(u?"tasks.restartTitleRetry":"tasks.restartTitleRequeue")}),(0,r.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":i("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex"},children:(0,r.jsx)(h.X,{size:16,"aria-hidden":"true"})})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,padding:"14px 16px 16px"},children:[(0,r.jsx)("p",{style:{margin:0,fontSize:12,lineHeight:1.5,color:"var(--text-muted)"},children:i("tasks.restartDescription")}),(0,r.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)"},children:i("tasks.actionAddNote")}),(0,r.jsx)("textarea",{value:l,onChange:e=>d(e.target.value),placeholder:i(u?"tasks.followUpPlaceholderRetry":"tasks.followUpPlaceholderRequeue"),rows:3,autoFocus:!0,style:{width:"100%",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"8px 10px",color:"var(--text)",fontSize:13,outline:"none",fontFamily:"inherit",resize:"vertical"}})]}),(0,r.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:4},children:[(0,r.jsx)("button",{type:"button",onClick:()=>t(!1),disabled:c,style:{padding:"8px 14px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:i("i18n.cancel")}),(0,r.jsx)("button",{type:"button",onClick:()=>void g(),disabled:c,style:{padding:"8px 16px",borderRadius:8,background:"var(--accent)",color:"#fff",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:i(u?"tasks.actionRetry":"tasks.actionRequeue")})]})]})]})})}let c_=["work","retry","return","merge"];function cq({open:e,onOpenChange:t,projectRoot:o}){let{t:s}=(0,A.s)(),{projects:i}=ck(),[a,l]=(0,n.useState)(""),[d,c]=(0,n.useState)(()=>cT()),[p,u]=(0,n.useState)(!1),[g,m]=(0,n.useState)(!1);if((0,n.useEffect)(()=>{if(!e)return;let t=o??i[0]??"";l(t),t&&(0,sS.Pf)(t).then(e=>{u(null!=e),c(e??cT())}).catch(()=>{u(!1),c(cT())})},[e,o,i]),!e)return null;let f=(e,t)=>{c(o=>({...o,[e]:t}))},x=async()=>{if(a&&!g){m(!0);try{await (0,sS.eA)(a,d),u(!0),t(!1)}catch(e){console.error("save settings failed",e)}finally{m(!1)}}},k=async()=>{if(a)try{await (0,sS.E)(a),u(!1),c(cT())}catch(e){console.error("reset settings failed",e)}},v={width:"100%",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"7px 10px",color:"var(--text)",fontSize:12,outline:"none",fontFamily:"inherit"},y={display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:"10px 0",borderBottom:"1px solid var(--border)"};return(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:960,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.45)"},onMouseDown:e=>{e.target===e.currentTarget&&t(!1)},children:(0,r.jsxs)("div",{style:{width:"min(560px, calc(100vw - 48px))",maxHeight:"82vh",overflowY:"auto",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 16px 48px rgba(0,0,0,0.3)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 16px 0"},children:[(0,r.jsx)("h3",{style:{fontSize:15,fontWeight:600,margin:0},children:s("tasks.settingsTitle")}),(0,r.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":s("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex"},children:(0,r.jsx)(h.X,{size:16,"aria-hidden":"true"})})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10,padding:"14px 16px 16px"},children:[(0,r.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)("span",{style:{fontSize:12,fontWeight:500},children:s("tasks.settingsProject")}),(0,r.jsx)("select",{value:a,onChange:e=>l(e.target.value),style:v,children:i.map(e=>(0,r.jsx)("option",{value:e,children:e.split("/").filter(Boolean).pop()??e},e))})]}),a?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{style:y,children:[(0,r.jsx)("span",{style:{fontSize:12},children:s("tasks.settingsAutoProcess")}),(0,r.jsx)("input",{type:"checkbox",checked:d.autoProcess,onChange:e=>f("autoProcess",e.target.checked),style:{accentColor:"var(--accent)"}})]}),(0,r.jsxs)("div",{style:y,children:[(0,r.jsx)("span",{style:{fontSize:12},children:s("tasks.settingsMaxConcurrent")}),(0,r.jsx)("input",{type:"number",min:0,value:d.maxConcurrent,onChange:e=>f("maxConcurrent",Math.max(0,Number(e.target.value)||0)),style:{...v,width:90}})]}),(0,r.jsxs)("div",{style:y,children:[(0,r.jsx)("span",{style:{fontSize:12},children:s("tasks.settingsMergeStrategy")}),(0,r.jsxs)("select",{value:d.mergeStrategy,onChange:e=>f("mergeStrategy",e.target.value),style:{...v,width:140},children:[(0,r.jsx)("option",{value:"merge",children:s("tasks.mergeStrategyMerge")}),(0,r.jsx)("option",{value:"squash",children:s("tasks.mergeStrategySquash")})]})]}),(0,r.jsxs)("div",{style:y,children:[(0,r.jsx)("span",{style:{fontSize:12},children:s("tasks.settingsDeleteWorktree")}),(0,r.jsx)("input",{type:"checkbox",checked:d.deleteWorktreeDefault,onChange:e=>f("deleteWorktreeDefault",e.target.checked),style:{accentColor:"var(--accent)"}})]}),(0,r.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)("span",{style:{fontSize:12},children:s("tasks.settingsPreflightCommand")}),(0,r.jsx)("input",{value:d.preflightCommand??"",onChange:e=>f("preflightCommand",e.target.value||null),placeholder:s("tasks.settingsPreflightPlaceholder"),style:{...v,fontFamily:"var(--font-mono)",fontSize:11}})]}),(0,r.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)("span",{style:{fontSize:12},children:s("tasks.settingsInitCommand")}),(0,r.jsx)("input",{value:d.initCommand??"",onChange:e=>f("initCommand",e.target.value||null),placeholder:s("tasks.settingsInitPlaceholder"),style:{...v,fontFamily:"var(--font-mono)",fontSize:11}})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6,paddingTop:4},children:[(0,r.jsx)("span",{style:{fontSize:12,fontWeight:500},children:s("tasks.settingsStagePrompts")}),c_.map(e=>(0,r.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)"},children:s(`tasks.stage.${e}`)}),(0,r.jsx)("input",{value:d.stagePrompts?.[e]??"",onChange:t=>f("stagePrompts",{...d.stagePrompts??{},[e]:t.target.value}),style:{...v,fontSize:11}})]},e))]}),p&&(0,r.jsx)("button",{type:"button",onClick:()=>void k(),style:{alignSelf:"flex-start",padding:"6px 12px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text-muted)",fontSize:12,cursor:"pointer"},children:s("tasks.settingsReset")})]}):(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",padding:8},children:s("tasks.settingsNoProject")}),(0,r.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:4},children:[(0,r.jsx)("button",{type:"button",onClick:()=>t(!1),style:{padding:"8px 14px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:s("i18n.cancel")}),(0,r.jsx)("button",{type:"button",onClick:()=>void x(),disabled:!a||g,style:{padding:"8px 16px",borderRadius:8,background:"var(--accent)",color:"#fff",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:s("tasks.save")})]})]})]})})}function cV({open:e,onOpenChange:t,task:o}){let{t:s}=(0,A.s)();return((0,n.useEffect)(()=>{if(!e)return},[e,o]),e&&o)?(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:970,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.45)"},onMouseDown:e=>{e.target===e.currentTarget&&t(!1)},children:(0,r.jsxs)("div",{style:{width:"min(520px, calc(100vw - 48px))",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 16px 48px rgba(0,0,0,0.3)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 16px 0"},children:[(0,r.jsx)("h3",{style:{fontSize:15,fontWeight:600,margin:0},children:s("tasks.sessionTitle")}),(0,r.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":s("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex"},children:(0,r.jsx)(h.X,{size:16,"aria-hidden":"true"})})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10,padding:"14px 16px 16px",fontSize:12},children:[(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:10},children:[(0,r.jsx)("span",{style:{color:"var(--text-muted)"},children:s("tasks.sessionId")}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,overflowWrap:"anywhere"},children:o.conversationId??"—"})]}),o.sessionFile?(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:10},children:[(0,r.jsx)("span",{style:{color:"var(--text-muted)"},children:s("tasks.sessionFile")}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,overflowWrap:"anywhere"},children:o.sessionFile})]}):null,(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-muted)",lineHeight:1.6},children:s("tasks.sessionHint")}),(0,r.jsx)("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:4},children:(0,r.jsx)("button",{type:"button",onClick:()=>t(!1),style:{padding:"8px 16px",borderRadius:8,background:"var(--accent)",color:"#fff",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:s("i18n.close")})})]})]})}):null}let cK="__all__",cG="pi-tasks-board-filter",cJ={showCanceled:!1,showArchived:!1},cY="pi:open-task-settings";function cX(){let{t:e}=(0,A.s)(),{attentionCount:t}=ck();return(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,height:36,flexShrink:0,padding:"0 16px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,r.jsxs)("h1",{style:{margin:0,display:"flex",alignItems:"center",gap:6,fontSize:13,fontWeight:600},children:[(0,r.jsx)(lu.x,{size:15,color:"var(--text-muted)","aria-hidden":"true"}),e("tasks.title"),(0,r.jsx)("span",{style:{borderRadius:999,background:"rgba(37,99,235,0.12)",color:"var(--accent)",padding:"1px 8px",fontSize:9,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.04em"},children:"Beta"})]}),t>0?(0,r.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:4,borderRadius:999,background:"rgba(239,68,68,0.12)",color:"#dc2626",padding:"1px 8px",fontSize:10,fontWeight:700},children:[t," ",e("tasks.attentionBadge")]}):null,(0,r.jsx)("div",{style:{flex:1}}),(0,r.jsxs)("button",{type:"button",onClick:()=>window.dispatchEvent(new Event(cY)),style:{display:"inline-flex",alignItems:"center",gap:5,height:26,padding:"0 10px",borderRadius:7,background:"none",border:"none",color:"var(--text-muted)",fontSize:12,cursor:"pointer"},title:e("tasks.settingsTitle"),children:[(0,r.jsx)(cb.O,{size:13,"aria-hidden":"true"}),e("tasks.settingsTitle")]})]})}function cZ({activeProject:e}){let{t}=(0,A.s)(),{tasks:s,projects:i,refetch:a}=ck(),[l,d]=(0,n.useState)(null),[c,u]=(0,n.useState)(()=>(function(){try{let e=window.localStorage.getItem(cG);if(e){let t=JSON.parse(e);return{showCanceled:t.showCanceled??!1,showArchived:t.showArchived??!1}}}catch{}return cJ})()),[h,g]=(0,n.useState)(!1);(0,n.useEffect)(()=>{try{window.localStorage.setItem(cG,JSON.stringify(c))}catch{}},[c]);let[m,f]=(0,n.useState)(null),[x,k]=(0,n.useState)(!1),y=(0,n.useRef)(null),b=(0,n.useRef)({x:0,y:0}),w=(0,n.useRef)(null),j=(0,n.useRef)(null),[S,C]=(0,n.useState)(null),T=(0,n.useRef)(null);T.current=S;let R=(0,n.useRef)(!1),z=(0,n.useRef)(!1),[I,M]=(0,n.useState)(()=>Date.now());(0,n.useEffect)(()=>{let e=window.setInterval(()=>M(Date.now()),6e4);return()=>window.clearInterval(e)},[]);let[P,E]=(0,n.useState)(!1),[W,F]=(0,n.useState)(null),[D,N]=(0,n.useState)(null);(0,n.useEffect)(()=>{let e=()=>{let e,t=(e=nP,nP=null,e);t&&(F(null),N(t),E(!0))};return e(),window.addEventListener(nM,e),()=>window.removeEventListener(nM,e)},[]);let[L,$]=(0,n.useState)(null),[H,O]=(0,n.useState)(null),[B,U]=(0,n.useState)(!1),[_,q]=(0,n.useState)(null),[V,K]=(0,n.useState)(!1),[G,J]=(0,n.useState)(null),[Y,X]=(0,n.useState)("retry"),[Z,Q]=(0,n.useState)(!1),[ee,et]=(0,n.useState)(null),[eo,er]=(0,n.useState)(!1),[en,es]=(0,n.useState)(!1),[ei,ea]=(0,n.useState)(null),[el,ed]=(0,n.useState)(!1);(0,n.useEffect)(()=>{let e=()=>es(!0);return window.addEventListener(cY,e),()=>window.removeEventListener(cY,e)},[]);let ec=(0,n.useMemo)(()=>null==l?s:s.filter(e=>e.projectRoot===l),[s,l]),ep=(0,n.useMemo)(()=>(function(e,t,o=!1){let r={todo:[],inProgress:[],attention:[],done:[]};for(let n of e)("canceled"!==n.status||t)&&(null==n.archivedAt||o)&&r[function(e){switch(e){case"todo":case"queued":return"todo";case"preparing":case"running":return"inProgress";case"awaiting_input":case"review":case"merging":case"failed":return"attention";case"done":case"canceled":return"done"}}(n.status)].push(n);for(let e of cS)r[e].sort((e,t)=>(t.updatedAt??"").localeCompare(e.updatedAt??""));return r})(ec,c.showCanceled,c.showArchived),[ec,c]),eu=(0,n.useMemo)(()=>{let e=ep.todo;if(null==S)return e;let t=new Map(e.map(e=>[e.id,e])),o=S.flatMap(e=>t.get(e)??[]);for(let t of e)S.includes(t.id)||o.push(t);return o},[ep.todo,S]),eh=(0,n.useMemo)(()=>s.find(e=>e.id===L)??null,[s,L]),eg=(0,n.useMemo)(()=>s.find(e=>e.id===ei)??null,[s,ei]),em=(0,n.useCallback)(async e=>{try{await e()}catch(e){console.error("task action failed",e)}finally{a()}},[a]),ef=(0,n.useCallback)(e=>{null!=e.conversationId&&(ea(e.id),ed(!0))},[ea,ed]),ex=(0,n.useCallback)(e=>{O(e),U(!0)},[O,U]),ek=(0,n.useCallback)(()=>{F(null),E(!0)},[F,E]),ev=(0,n.useCallback)((e,t)=>{let o=w.current,r=y.current;o&&r&&(o.style.transform=`translate3d(${e-r.dx}px, ${t-r.dy}px, 0)`)},[]),ey=e=>{let t=e.currentTarget.getBoundingClientRect();y.current={dx:e.clientX-t.left,dy:e.clientY-t.top,width:t.width}},eb=(0,n.useCallback)(e=>{if(f(null),k(!1),e){R.current=!1;return}requestAnimationFrame(()=>{R.current=!1})},[f,k]),ew=(0,n.useCallback)(()=>{z.current=!0,C(null),eb(!0)},[eb,C]);(0,n.useEffect)(()=>{if(!m)return;let e=()=>{document.hidden&&ew()};return window.addEventListener("blur",ew),document.addEventListener("visibilitychange",e),()=>{window.removeEventListener("blur",ew),document.removeEventListener("visibilitychange",e)}},[m,ew]),(0,n.useEffect)(()=>{m&&!eu.some(e=>e.id===m.task.id)&&ew()},[m,eu,ew]);let ej=(0,n.useCallback)((e,t,o)=>{if(z.current){eb(!0),C(null);return}let r=j.current?.getBoundingClientRect(),n=null!=r&&t>=r.left&&t<=r.right&&o>=r.top&&o<=r.bottom;if(eb(!1),n){C(null);let t=s.find(t=>t.id===e.id);t?.status==="todo"&&null!=l&&em(()=>(0,sS.oQ)(e.id,e.projectRoot,"start"));return}let i=T.current;null!=l&&null!=i&&(async()=>{try{await (0,sS.Lu)(l,i)}catch(e){console.error("reorder failed",e)}await a(),C(null)})()},[em,eb,l,a,s]),eS=(0,n.useCallback)(()=>{em(async()=>{let e=await (0,sS.a5)(l);e>0&&console.log(`started ${e} tasks`)})},[em,l]),eC=(0,n.useCallback)(()=>{let e=ep.done.filter(e=>null==e.archivedAt);0!==e.length&&em(()=>Promise.all(e.map(e=>(0,sS.et)(e.id,e.projectRoot,!0))))},[em,ep.done]),eT=+(c.showCanceled!==cJ.showCanceled)+ +(c.showArchived!==cJ.showArchived),eR=s.length>0,ez=(0,n.useMemo)(()=>{let t=new Set(i);return e&&t.add(e),[...t].sort()},[i,e]),eI=(0,n.useMemo)(()=>{let e=new Map;for(let t of ez)e.set(t,t.split("/").filter(Boolean).pop()??t);return e},[ez]);return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0},children:[eR&&(0,r.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:8,padding:"14px 16px 8px"},children:[(0,r.jsxs)("select",{value:l??cK,onChange:e=>d(e.target.value===cK?null:e.target.value),style:{height:30,borderRadius:999,padding:"0 10px",background:"var(--bg-panel)",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,fontWeight:500,cursor:"pointer",maxWidth:"14rem"},"aria-label":t("tasks.allFolders"),children:[(0,r.jsx)("option",{value:cK,children:t("tasks.allFolders")}),ez.map(e=>(0,r.jsx)("option",{value:e,children:eI.get(e)??e},e))]}),(0,r.jsxs)("div",{style:{position:"relative"},children:[(0,r.jsxs)("button",{type:"button",onClick:()=>g(e=>!e),style:{display:"inline-flex",alignItems:"center",gap:6,height:30,borderRadius:999,padding:"0 12px",background:"var(--bg-panel)",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,fontWeight:500,cursor:"pointer"},children:[(0,r.jsx)(cw.n,{size:13,"aria-hidden":"true"}),t("tasks.filter"),eT>0?(0,r.jsx)("span",{style:{borderRadius:999,background:"rgba(37,99,235,0.12)",color:"var(--accent)",padding:"1px 6px",fontSize:10,fontWeight:700},children:eT}):null]}),h&&(0,r.jsx)("div",{style:{position:"absolute",top:34,left:0,zIndex:50,width:200,borderRadius:12,padding:6,background:"var(--bg-panel)",border:"1px solid var(--border)",boxShadow:"0 8px 24px rgba(0,0,0,0.16)"},children:[["showCanceled",t("tasks.showCanceled")],["showArchived",t("tasks.showArchived")]].map(([e,t])=>(0,r.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:8,padding:"6px 8px",borderRadius:8,cursor:"pointer",fontSize:12},children:[(0,r.jsx)("input",{type:"checkbox",checked:c[e],onChange:t=>u(o=>({...o,[e]:t.target.checked})),style:{accentColor:"var(--accent)"}}),t]},e))})]}),(0,r.jsx)("div",{style:{flex:1}}),(0,r.jsxs)("button",{type:"button",onClick:eS,style:{display:"inline-flex",alignItems:"center",gap:6,height:30,borderRadius:999,padding:"0 12px",background:"none",border:"none",color:"var(--text)",fontSize:12,cursor:"pointer"},title:t("tasks.startAll"),children:[(0,r.jsx)(cj.j,{size:13,"aria-hidden":"true"}),t("tasks.startAll")]}),(0,r.jsxs)("button",{type:"button",onClick:ek,style:{display:"inline-flex",alignItems:"center",gap:6,height:30,borderRadius:999,padding:"0 14px",background:"var(--accent)",color:"#fff",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:[(0,r.jsx)(v.F,{size:13,weight:"bold","aria-hidden":"true"}),t("tasks.new")]})]}),eR?(0,r.jsx)("div",{style:{flex:1,minHeight:0,overflowX:"auto"},children:(0,r.jsx)("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:16,minWidth:"56rem",height:"100%",padding:"4px 16px 16px"},children:cR.map(e=>{let o="todo"===e?eu:ep[e],n=cz[e],s=e=>(0,r.jsx)(cF,{task:e,folderName:e.projectRoot?eI.get(e.projectRoot)??null:null,now:I,onOpen:()=>{R.current||$(e.id)},onStart:()=>void em(()=>(0,sS.oQ)(e.id,e.projectRoot,"start")),onCancel:()=>{q(e),K(!0)},onRetry:()=>{J(e),X("retry"),Q(!0)},onRequeue:()=>{J(e),X("requeue"),Q(!0)},onViewSession:()=>ef(e),onMerge:()=>{cC(e)?(et(e),er(!0)):ex(e)},onArchive:()=>void em(()=>(0,sS.et)(e.id,e.projectRoot,null==e.archivedAt)),onEdit:()=>{F(e),E(!0)}},e.id);return(0,r.jsxs)("div",{ref:"inProgress"===e?j:void 0,style:{display:"flex",flexDirection:"column",minHeight:0,gap:8},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,height:24,flexShrink:0,padding:"0 2px"},children:[(0,r.jsx)("span",{style:{width:3,height:14,borderRadius:999,background:n.marker,flexShrink:0},"aria-hidden":"true"}),(0,r.jsx)("h2",{style:{fontSize:12,fontWeight:600,color:"var(--text)"},children:t(`tasks.col${e[0].toUpperCase()}${e.slice(1)}`)}),(0,r.jsx)("span",{style:{borderRadius:999,background:"var(--bg-hover)",padding:"1px 8px",fontSize:10,fontWeight:600,color:"var(--text-muted)"},children:o.length}),(0,r.jsx)("div",{style:{flex:1}}),"done"===e&&ep.done.some(e=>null==e.archivedAt)?(0,r.jsx)("button",{type:"button",onClick:eC,style:{background:"none",border:"none",cursor:"pointer",fontSize:11,color:"var(--text-muted)",padding:"2px 6px",borderRadius:6},children:t("tasks.archiveAllDone")}):null]}),0===o.length?(0,r.jsx)("div",{style:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:4,borderRadius:12,border:"1px dashed var(--border)",padding:16,textAlign:"center",..."inProgress"===e&&m?x?{borderColor:"var(--accent)",background:"rgba(37,99,235,0.08)"}:{borderColor:"var(--accent)"}:{}},children:(0,r.jsx)("p",{style:{fontSize:12,color:"var(--text-muted)"},children:t(`tasks.emptyCol${e[0].toUpperCase()}${e.slice(1)}`)})}):(0,r.jsx)("div",{style:{flex:1,minHeight:0,overflowY:"auto",borderRadius:12,transition:"background 0.15s, box-shadow 0.15s",..."inProgress"===e&&m?x?{background:"rgba(37,99,235,0.06)",boxShadow:"inset 0 0 0 2px var(--accent)"}:{boxShadow:"inset 0 0 0 1px rgba(37,99,235,0.25)"}:{}},children:(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:16,paddingBottom:4},children:o.map(t=>"todo"===e?(0,r.jsx)("div",{draggable:!0,onDragStart:e=>{var o,r;e.dataTransfer.effectAllowed="move",o=e.clientX,r=e.clientY,R.current=!0,z.current=!1,b.current={x:o,y:r},f({task:t,width:y.current?.width??280})},onDrag:e=>{var t,o;let r,n;return b.current={x:t=e.clientX,y:o=e.clientY},ev(t,o),void((n=null!=(r=j.current?.getBoundingClientRect())&&t>=r.left&&t<=r.right&&o>=r.top&&o<=r.bottom)!==x&&k(n))},onDragEnd:e=>ej(t,e.clientX,e.clientY),onPointerDown:ey,style:{cursor:"grab",opacity:m?.task.id===t.id?.4:1},children:s(t)},t.id):(0,r.jsx)("div",{children:s(t)},t.id))})})]},e)})})}):(0,r.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:12,padding:32,textAlign:"center"},children:[(0,r.jsx)(lu.x,{size:40,color:"var(--text-dim)",opacity:.4,"aria-hidden":"true"}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)("p",{style:{fontSize:14,fontWeight:500,color:"var(--text)"},children:t("tasks.empty")}),(0,r.jsx)("p",{style:{maxWidth:320,fontSize:12,color:"var(--text-muted)",lineHeight:1.6},children:t("tasks.emptyHint")})]}),(0,r.jsxs)("button",{type:"button",onClick:ek,style:{display:"inline-flex",alignItems:"center",gap:6,padding:"7px 14px",borderRadius:8,background:"var(--accent)",color:"#fff",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:[(0,r.jsx)(v.F,{size:13,weight:"bold","aria-hidden":"true"}),t("tasks.new")]})]}),(0,r.jsx)(cO,{open:P,onOpenChange:E,task:W,defaultProject:D?.projectRoot??l??e??null,projects:ez,prefillTitle:D?D.text.slice(0,80):void 0,prefillPrompt:D?D.text:void 0,onSubmit:async(e,t,r)=>{await em(async()=>{let{createTaskApi:n}=await Promise.resolve().then(o.bind(o,23084)),{updateTaskApi:s}=await Promise.resolve().then(o.bind(o,23084));W?await s(W.id,e,{title:t,config:r}):await n({projectRoot:e,title:t,config:r})}),E(!1),N(null)}}),(0,r.jsx)(c$,{open:null!=L,onOpenChange:e=>{e||$(null)},task:eh,onViewSession:ef,onMerge:ex,onEdit:e=>{F(e),E(!0)},onCancel:e=>{q(e),K(!0)},onRetry:e=>{J(e),X("retry"),Q(!0)},onRequeue:e=>{J(e),X("requeue"),Q(!0)},onComplete:e=>{et(e),er(!0)}}),(0,r.jsx)(cB,{open:B,onOpenChange:U,task:H}),(0,r.jsx)(cD,{open:V,onOpenChange:K,task:_}),(0,r.jsx)(cU,{open:Z,onOpenChange:Q,task:G,kind:Y}),(0,r.jsx)(cA,{open:eo,onOpenChange:er,task:ee}),(0,r.jsx)(cV,{open:el&&null!=eg,onOpenChange:ed,task:eg}),(0,r.jsx)(cq,{open:en,onOpenChange:es,projectRoot:l}),m?(0,p.createPortal)((0,r.jsx)("div",{ref:w,style:{position:"fixed",left:0,top:0,zIndex:999,pointerEvents:"none",width:m.width,willChange:"transform"},"aria-hidden":"true",children:(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8,borderRadius:12,border:x?"1px solid var(--accent)":"1px solid var(--border)",background:"var(--bg-panel)",padding:12,boxShadow:"0 8px 24px rgba(0,0,0,0.2)",transform:"rotate(-1deg)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:8},children:[(0,r.jsx)("span",{style:{minWidth:0,overflowWrap:"break-word",fontSize:13,fontWeight:500},children:m.task.title}),(0,r.jsx)(cE,{task:m.task})]}),x?(0,r.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:4,fontSize:11,fontWeight:600,color:"var(--accent)"},children:[(0,r.jsx)(cj.j,{size:11,weight:"bold","aria-hidden":"true"}),t("tasks.dropToStart")]}):null]})}),document.body):null]})}var cQ=o(62235),c0=o(1022);function c1(){return!!window.__TAURI_INTERNALS__}let c2=null;function c4(){return c2||(c2=o.e(8518).then(o.bind(o,38518)).then(e=>e.getCurrentWindow())),c2}async function c6(e){let t=await c4();await e(t)}async function c8(){await c6(e=>e.minimize())}async function c5(){await c6(e=>e.toggleMaximize())}async function c3(){await c6(e=>e.startDragging())}async function c7(){await c6(e=>e.close())}async function c9(){return(await c4()).isMaximized()}function pe(){let[e,t]=(0,n.useState)(null);return(0,n.useEffect)(()=>{c1()&&t(function(){if("u"<typeof navigator)return null;let e=navigator.platform||"";return/mac/i.test(e)?"macos":/win/i.test(e)?"windows":/linux/i.test(e)?"linux":null}())},[]),{platform:e,isDesktop:null!==e,isMacOS:"macos"===e,dragRegionProps:e?{"data-tauri-drag-region":!0}:{}}}let pt="pi-web-island-pos";function po(e,t,o,r,n,s){return{x:Math.min(Math.max(0,e),Math.max(0,o-n)),y:Math.min(Math.max(0,t),Math.max(0,r-s))}}let pr={display:"flex",alignItems:"center",justifyContent:"center",width:26,height:26,padding:0,flexShrink:0,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",borderRadius:7,transition:"background 0.12s, color 0.12s"};function pn({onRefreshSession:e}={}){let{t:t}=(0,A.s)(),{isDark:o}=o9(),{isDesktop:s,isMacOS:i}=pe(),a=s&&!i,[l,d]=(0,n.useState)(!1),[c,p]=(0,n.useState)(null),[u,h]=(0,n.useState)(null),g=(0,n.useRef)(null),m=(0,n.useRef)(null);(0,n.useEffect)(()=>{a&&c4().then(()=>void 0,e=>{throw c2=null,e}).catch(e=>{console.error("[DynamicIsland] window API preload failed:",e)})},[a]);let f=(0,n.useCallback)(e=>{e().catch(e=>{console.error("[DynamicIsland] window command failed:",e),p(String(e)),window.setTimeout(()=>p(null),4e3)})},[]),x=(0,n.useCallback)(()=>{window.location.reload()},[]);(0,n.useEffect)(()=>{if(!c1()||!a)return;let e=()=>{c9().then(d)};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[a]),(0,n.useEffect)(()=>{if(a)try{let e=localStorage.getItem(pt);if(e){let t=JSON.parse(e);"number"==typeof t.x&&"number"==typeof t.y&&h(po(t.x,t.y,window.innerWidth,window.innerHeight,168,34))}}catch{}},[a]),(0,n.useEffect)(()=>{if(a&&u)try{localStorage.setItem(pt,JSON.stringify(u))}catch{}},[u,a]);let[k,v]=(0,n.useState)(0);(0,n.useEffect)(()=>{if(!a)return;let e=()=>{v(window.innerWidth),h(e=>e?po(e.x,e.y,window.innerWidth,window.innerHeight,168,34):e)};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[a]);let y=(0,n.useCallback)(e=>{if(0!==e.button||e.target.closest?.("[data-island-btn]"))return;let t=g.current;if(!t)return;let o=t.getBoundingClientRect();m.current={startX:e.clientX,startY:e.clientY,origX:o.left,origY:o.top},e.currentTarget.setPointerCapture(e.pointerId)},[]),b=(0,n.useCallback)(e=>{let t=m.current;if(!t)return;let o=e.clientX-t.startX,r=e.clientY-t.startY;h(po(t.origX+o,t.origY+r,window.innerWidth,window.innerHeight,168,34))},[]),w=(0,n.useCallback)(e=>{m.current=null;try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}},[]),j=(0,n.useCallback)(()=>c5().then(()=>{d(e=>!e)}),[]),S=(0,n.useCallback)(e=>{if(!m.current&&!e.target.closest?.("[data-island-btn]")){h(null);try{localStorage.removeItem(pt)}catch{}}},[]);if(!a)return null;let T=k||window.innerWidth,R=null!==u?u.x:Math.max(0,T-168-14);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{ref:g,role:"toolbar","aria-label":t("desktop.islandLabel"),title:t("desktop.islandResetHint"),onPointerDown:y,onPointerMove:b,onPointerUp:w,onPointerCancel:w,onDoubleClick:S,onMouseDown:e=>e.stopPropagation(),onDoubleClickCapture:e=>e.stopPropagation(),style:{position:"fixed",top:null!==u?u.y:100,left:R,zIndex:700,display:"flex",alignItems:"center",gap:1,padding:"3px 5px",borderRadius:999,background:"color-mix(in srgb, var(--bg-panel) 88%, transparent)",border:"1px solid var(--border)",boxShadow:o?"0 6px 24px rgba(0,0,0,0.45)":"0 6px 20px rgba(0,0,0,0.12)",cursor:"grab",userSelect:"none",touchAction:"none"},children:[(0,r.jsx)("span",{"data-island-grip":!0,"aria-hidden":"true",title:t("desktop.islandDrag"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:12,height:26,flexShrink:0,marginRight:2,color:"var(--text-dim)",cursor:"grab"},children:(0,r.jsxs)("svg",{width:"6",height:"14",viewBox:"0 0 6 14",fill:"currentColor","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"1.5",cy:"2",r:"1.2"}),(0,r.jsx)("circle",{cx:"4.5",cy:"2",r:"1.2"}),(0,r.jsx)("circle",{cx:"1.5",cy:"7",r:"1.2"}),(0,r.jsx)("circle",{cx:"4.5",cy:"7",r:"1.2"}),(0,r.jsx)("circle",{cx:"1.5",cy:"12",r:"1.2"}),(0,r.jsx)("circle",{cx:"4.5",cy:"12",r:"1.2"})]})}),e&&(0,r.jsx)("button",{type:"button","data-island-btn":!0,"aria-label":t("desktop.refreshSession"),title:t("desktop.refreshSession"),onClick:()=>{try{e()}catch(e){console.error("[DynamicIsland] refresh session failed:",e)}},style:pr,onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:(0,r.jsx)(c0.P,{size:13,"aria-hidden":"true"})}),(0,r.jsx)("button",{type:"button","data-island-btn":!0,"aria-label":t("desktop.reloadPage"),title:t("desktop.reloadPage"),onClick:x,style:pr,onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:(0,r.jsx)(C.S,{size:13,"aria-hidden":"true"})}),(0,r.jsx)("span",{"aria-hidden":"true",style:{width:1,height:18,flexShrink:0,background:"var(--border)",margin:"0 3px"}}),(0,r.jsx)("button",{type:"button","data-island-btn":!0,"aria-label":t("desktop.minimize"),title:t("desktop.minimize"),onClick:()=>f(c8),style:pr,onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1",children:(0,r.jsx)("line",{x1:"1",y1:"5",x2:"9",y2:"5"})})}),(0,r.jsx)("button",{type:"button","data-island-btn":!0,"aria-label":t(l?"desktop.restore":"desktop.maximize"),title:t(l?"desktop.restore":"desktop.maximize"),onClick:()=>f(j),style:pr,onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:l?(0,r.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1",children:[(0,r.jsx)("rect",{x:"2",y:"0.5",width:"7.5",height:"7.5"}),(0,r.jsx)("path",{d:"M0.5 2.5 V9.5 H7.5"})]}):(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1",children:(0,r.jsx)("rect",{x:"0.5",y:"0.5",width:"9",height:"9"})})}),(0,r.jsx)("button",{type:"button","data-island-btn":!0,"aria-label":t("desktop.close"),title:t("desktop.close"),onClick:()=>f(c7),style:pr,onMouseEnter:e=>{e.currentTarget.style.background="#e81123",e.currentTarget.style.color="#fff"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:(0,r.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1",children:[(0,r.jsx)("line",{x1:"0",y1:"0",x2:"10",y2:"10"}),(0,r.jsx)("line",{x1:"10",y1:"0",x2:"0",y2:"10"})]})})]}),c&&(0,r.jsx)("div",{role:"alert",style:{position:"fixed",top:(null!==u?u.y:100)+34+6,left:R,zIndex:700,maxWidth:280,padding:"5px 10px",borderRadius:8,background:"var(--bg-panel)",border:"1px solid var(--status-error, #f85149)",color:"var(--status-error, #f85149)",fontSize:11,lineHeight:1.5,wordBreak:"break-all",boxShadow:o?"0 6px 24px rgba(0,0,0,0.45)":"0 6px 20px rgba(0,0,0,0.12)",pointerEvents:"none"},children:c})]})}function ps(){try{return window.localStorage}catch{return null}}let pi="pi-web:desktop-server-hint-seen";function pa(e=ps()){if(e)try{e.setItem(pi,"1")}catch{}}function pl(){let{t:e}=(0,A.s)(),[t,o]=(0,n.useState)(!1);(0,n.useEffect)(()=>{let e=!1;try{e=new URLSearchParams(window.location.search).has("piweb_connected")}catch{e=!1}e&&function(e=ps()){if(!e)return!1;try{return"1"!==e.getItem(pi)}catch{return!1}}()&&o(!0)},[]);let s=(0,n.useCallback)(()=>{pa(),o(!1)},[]),i=(0,n.useCallback)(()=>{pa(),o(!1),window.location.href="piweb-switch://manage"},[]);return t?(0,r.jsxs)("div",{role:"status",style:{position:"fixed",top:56,right:16,zIndex:700,width:288,padding:"14px 16px 14px",borderRadius:12,background:"var(--bg-panel)",border:"1px solid var(--border)",boxShadow:"0 12px 36px rgba(0,0,0,0.32)",color:"var(--text)"},children:[(0,r.jsx)("span",{"aria-hidden":"true",style:{position:"absolute",top:-6,right:28,width:10,height:10,background:"var(--bg-panel)",borderTop:"1px solid var(--border)",borderLeft:"1px solid var(--border)",transform:"rotate(45deg)"}}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:10},children:[(0,r.jsx)(a_.X,{size:18,color:"var(--accent)",style:{flexShrink:0,marginTop:1}}),(0,r.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,r.jsx)("div",{style:{fontSize:13.5,fontWeight:600,lineHeight:1.45},children:e("desktop.serverHintTitle")}),(0,r.jsx)("p",{style:{margin:"6px 0 0",fontSize:12.5,lineHeight:1.65,color:"var(--text-muted)"},children:e("desktop.serverHintBody")})]}),(0,r.jsx)("button",{type:"button",onClick:s,"aria-label":e("desktop.serverHintDismiss"),title:e("desktop.serverHintDismiss"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,flexShrink:0,background:"none",border:"none",cursor:"pointer",color:"var(--text-dim)"},children:(0,r.jsx)(h.X,{size:14,"aria-hidden":"true"})})]}),(0,r.jsx)("button",{type:"button",onClick:i,style:{marginTop:12,width:"100%",display:"flex",alignItems:"center",justifyContent:"center",gap:6,padding:"8px 12px",borderRadius:9,background:"var(--accent)",border:"none",color:"#fff",fontSize:13,fontWeight:600,cursor:"pointer"},children:e("desktop.serverHintAction")})]}):null}function pd({isDark:e,toggleTheme:t,translate:o}){let[s,i]=(0,n.useState)(!1);(0,n.useEffect)(()=>{i(!0)},[]);let a=o(s?e?"desktop.switchToLight":"desktop.switchToDark":"desktop.switchToLight");return(0,r.jsx)("button",{className:"app-no-drag",suppressHydrationWarning:!0,onClick:e=>{let o=e.currentTarget.getBoundingClientRect();t({x:o.left+o.width/2,y:o.top+o.height/2})},title:a,"aria-label":a,"aria-pressed":!s||e,style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:s?e?(0,r.jsx)(lo.b,{size:16,"aria-hidden":"true"}):(0,r.jsx)(lt.A,{size:16,"aria-hidden":"true"}):(0,r.jsx)(lo.b,{size:16,"aria-hidden":"true"})})}function pc({topBarRef:e,sidebarOpen:t,onSidebarToggle:o,isDark:s,toggleTheme:i,isMobile:a,showTasks:l,tasksBoardEnabled:d,onToggleTasks:c,systemPrompt:p,activeTopPanel:u,topPanelPos:h,sessionStats:g,selectedSession:f,contextUsage:x,copiedSessionField:k,onCopySessionField:v,rightPanelOpen:y,onToggleFilePanel:b,onRefreshSession:j,onOpenSettings:S,sessionTitle:T,onWorkspaceControlsHostChange:R,onTitleRightHostChange:z,desktopChrome:I,windowDrag:M}){let P,E,W,F,D,N,L,$,H,O,B,{t:U}=(0,A.s)(),[_,q]=(0,n.useState)(!1),[V,K]=(0,n.useState)(!1);return(0,n.useEffect)(()=>{try{K(new URLSearchParams(window.location.search).has("piweb_connected"))}catch{K(!1)}},[]),(0,r.jsxs)(r.Fragment,{children:[V&&(0,r.jsx)(pl,{}),(0,r.jsxs)("div",{ref:e,className:"app-title-bar",...I?.dragRegionProps,...M,style:{display:"flex",alignItems:"center",flexShrink:0,borderBottom:"1px solid var(--border)",height:48,background:"var(--bg-panel)",position:"relative",zIndex:600,paddingLeft:76*!!I?.isMacOS},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",minWidth:0,height:"100%",flex:"0 1 auto",position:"relative",zIndex:1},children:[(0,r.jsx)("button",{className:"app-no-drag",onClick:o,title:t?U("desktop.hideSidebar"):U("desktop.showSidebar"),"aria-label":t?U("desktop.hideSidebar"):U("desktop.showSidebar"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,flexShrink:0,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)"},children:t?(0,r.jsx)(cQ.V,{size:16,"aria-hidden":"true"}):(0,r.jsx)(w.B,{size:16,"aria-hidden":"true"})}),(0,r.jsx)("div",{className:"app-no-drag",ref:R,style:{flex:"0 1 auto",minWidth:0,maxWidth:"min(60vw, 820px)",height:"100%",display:"flex",alignItems:"center",padding:"0 8px 0 0",overflow:"visible"}})]}),(0,r.jsxs)("div",{className:"app-title-drag",style:{position:"absolute",left:"var(--pi-titlebar-sidebar-offset, 0px)",right:0,top:0,bottom:0,minWidth:0,display:"flex",alignItems:"center",justifyContent:"center",padding:"0 12px",overflow:"hidden",userSelect:"none"},children:[T&&(0,r.jsx)("button",{type:"button",onClick:()=>{a&&q(!0)},title:a?T:void 0,style:{display:"block",flex:"0 1 auto",minWidth:0,maxWidth:"calc(100% - 320px)",fontSize:12,fontWeight:500,color:"var(--text-muted)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",background:"none",border:"none",cursor:"pointer",padding:"2px 6px",borderRadius:5},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:T}),(0,r.jsx)("div",{className:"app-no-drag",ref:z,style:{flexShrink:0,display:"flex",alignItems:"center",marginLeft:4}})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:3,minWidth:0,height:"100%",flexShrink:1,overflow:"hidden",marginLeft:"auto",position:"relative",zIndex:1},children:[!a&&d&&(0,r.jsx)("button",{className:"app-no-drag",onClick:c,title:l?U("desktop.hideTaskBoard"):U("desktop.showTaskBoard"),"aria-label":l?U("desktop.hideTaskBoard"):U("desktop.showTaskBoard"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:l?"var(--bg-selected)":"none",border:"none",color:l?"var(--text)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background=l?"var(--bg-selected)":"none",e.currentTarget.style.color=l?"var(--text)":"var(--text-muted)"},children:(0,r.jsx)(lu.x,{size:16,"aria-hidden":"true"})}),(0,r.jsx)("button",{className:"app-no-drag",onClick:b,title:y?U("desktop.hideFilePanel"):U("desktop.showFilePanel"),"aria-label":y?U("desktop.hideFilePanel"):U("desktop.showFilePanel"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:y?"var(--bg-selected)":"none",border:"none",color:y?"var(--text)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background=y?"var(--bg-selected)":"none",e.currentTarget.style.color=y?"var(--text)":"var(--text-muted)"},children:(0,r.jsx)(cQ.V,{size:16,"aria-hidden":"true",style:{transform:"scaleX(-1)"}})}),(0,r.jsx)(pd,{isDark:s,toggleTheme:i,translate:U}),V&&(0,r.jsx)("button",{className:"app-no-drag",type:"button",onClick:()=>{window.location.href="piweb-switch://manage"},title:U("desktop.serverSwitch"),"aria-label":U("desktop.serverSwitch"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:(0,r.jsx)(a_.X,{size:16,"aria-hidden":"true"})}),!V&&(0,r.jsx)("button",{className:"app-no-drag",type:"button",onClick:j,title:U("desktop.refreshSession"),"aria-label":U("desktop.refreshSession"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:(0,r.jsx)(C.S,{size:16,"aria-hidden":"true"})}),(0,r.jsx)("button",{className:"app-no-drag",type:"button",onClick:S,title:U("desktop.settings"),"aria-label":U("desktop.settings"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:(0,r.jsx)(cb.O,{size:16,"aria-hidden":"true"})})]})]}),(0,r.jsx)(pn,{onRefreshSession:j}),u&&h&&(0,r.jsxs)("div",{style:{position:"fixed",top:h.top,left:h.left,width:h.width,maxHeight:`calc(100dvh - ${h.top}px)`,overflowY:"auto",zIndex:500},children:["system"===u&&(0,r.jsx)("div",{style:{background:"var(--bg-panel)",borderBottom:"1px solid var(--border)"},children:p?(0,r.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:p}):""===p?(0,r.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:"System prompt is empty (tools are disabled)"}):(0,r.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:"Send a message to load the system prompt"})}),"session"===u&&(0,r.jsx)("div",{style:{background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",boxShadow:"0 10px 28px rgba(0,0,0,0.10)",padding:"12px 16px"},children:g?(P=[...g.sessionName?[{label:U("desktop.name"),value:g.sessionName,copyField:null}]:[],{label:U("desktop.sessionInfoFile"),value:g.sessionFile??U("desktop.sessionInfoInMemory"),copyField:"file"},{label:U("desktop.sessionInfoId"),value:g.sessionId,copyField:"id"}],E=[[U("desktop.sessionInfoUser"),g.userMessages.toLocaleString()],[U("desktop.sessionInfoAssistant"),g.assistantMessages.toLocaleString()],[U("desktop.sessionInfoToolCalls"),g.toolCalls.toLocaleString()],[U("desktop.sessionInfoToolResults"),g.toolResults.toLocaleString()],[U("desktop.sessionInfoTotal"),g.totalMessages.toLocaleString()]],W=[[U("desktop.sessionInfoInput"),g.tokens.input.toLocaleString()],[U("desktop.sessionInfoOutput"),g.tokens.output.toLocaleString()],...g.tokens.cacheRead>0?[[U("desktop.sessionInfoCacheRead"),g.tokens.cacheRead.toLocaleString()]]:[],...g.tokens.cacheWrite>0?[[U("desktop.sessionInfoCacheWrite"),g.tokens.cacheWrite.toLocaleString()]]:[],[U("desktop.sessionInfoTotal"),g.tokens.total.toLocaleString()]],F=x??g.contextUsage,N=[...g.cost>0?[[U("desktop.sessionInfoCost"),`$${g.cost.toFixed(4)}`]]:[],...F?.contextWindow?[[U("desktop.sessionInfoContext"),`${null!==F.percent?`${F.percent.toFixed(1)}%`:"?"} / ${(D=F.contextWindow)>=1e6?`${(D/1e6).toFixed(1)}M`:D>=1e3?`${(D/1e3).toFixed(0)}k`:String(D)}`]]:[]],L=(e,t,o="left",n=!1)=>(0,r.jsxs)("div",{style:{minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:11,fontWeight:700,color:"var(--text)",marginBottom:6},children:e}),(0,r.jsx)("div",{style:{display:"grid",gridTemplateColumns:n?"max-content max-content":"auto minmax(0, 1fr)",columnGap:n?14:12,rowGap:4,justifyContent:n?"start":void 0},children:t.map(([t,s])=>(0,r.jsxs)("div",{style:{display:"contents"},children:[(0,r.jsx)("div",{style:{color:"var(--text-dim)",whiteSpace:"nowrap"},children:t}),(0,r.jsx)("div",{style:{color:"var(--text-muted)",minWidth:0,overflowWrap:n?"normal":"anywhere",textAlign:o,whiteSpace:"right"===o?"nowrap":"normal"},children:s})]},`${e}:${t}`))})]}),$=(e,t)=>{let o=k===e;return(0,r.jsx)("button",{type:"button",title:o?U("desktop.copied"):U({file:"desktop.copyFilePath",id:"desktop.copySessionId",projectDir:"desktop.copyProjectDir",gitBranch:"desktop.copyGitBranch",gitWorktree:"desktop.copyGitWorktree"}[e]),onClick:()=>v(e,t),style:{alignSelf:"start",display:"inline-flex",alignItems:"center",justifyContent:"center",width:22,height:22,marginTop:-2,color:o?"var(--accent)":"var(--text-dim)",background:"transparent",border:"1px solid var(--border)",borderRadius:4,cursor:"pointer",flex:"0 0 auto",transition:"color 0.12s, border-color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color=o?"var(--accent)":"var(--text-dim)",e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.background="transparent"},children:o?(0,r.jsx)(m.J,{size:12,"aria-hidden":"true"}):(0,r.jsx)(or.Q,{size:12,"aria-hidden":"true"})})},H=(0,r.jsxs)("div",{style:{minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:11,fontWeight:700,color:"var(--text)",marginBottom:6},children:U("desktop.sessionInfoTitle")}),(0,r.jsx)("div",{style:{display:"grid",gridTemplateColumns:"auto minmax(0, 1fr) auto",columnGap:12,rowGap:8,alignItems:"start"},children:P.map(e=>(0,r.jsxs)("div",{style:{display:"contents"},children:[(0,r.jsx)("div",{style:{color:"var(--text-dim)",whiteSpace:"nowrap"},children:e.label}),(0,r.jsx)("div",{style:{color:"var(--text-muted)",minWidth:0,overflowWrap:"anywhere",wordBreak:"break-word",whiteSpace:"normal"},children:e.value}),(0,r.jsx)("div",{children:e.copyField?$(e.copyField,e.value):null})]},`session-info:${e.label}`))})]}),B=(O=[...f?[{label:U("desktop.projectDir"),value:f.projectRoot??f.cwd,copyField:"projectDir"}]:[],...f?.branch?[{label:U("desktop.gitBranch"),value:f.branch,copyField:"gitBranch"}]:[],...f?.isWorktree?[{label:U("desktop.gitWorktree"),value:f.cwd,copyField:"gitWorktree"}]:[]]).length>0?(0,r.jsxs)("div",{style:{minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:11,fontWeight:700,color:"var(--text)",marginBottom:6},children:U("desktop.projectSection")}),(0,r.jsx)("div",{style:{display:"grid",gridTemplateColumns:"auto minmax(0, 1fr) auto",columnGap:12,rowGap:8,alignItems:"start"},children:O.map(e=>(0,r.jsxs)("div",{style:{display:"contents"},children:[(0,r.jsx)("div",{style:{color:"var(--text-dim)",whiteSpace:"nowrap"},children:e.label}),(0,r.jsx)("div",{style:{color:"var(--text-muted)",minWidth:0,overflowWrap:"anywhere",wordBreak:"break-word",whiteSpace:"normal"},children:e.value}),(0,r.jsx)("div",{children:e.copyField?$(e.copyField,e.value):null})]},`project-info:${e.label}`))})]}):null,(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:a?"1fr":"minmax(360px, 1.7fr) minmax(140px, 0.55fr) minmax(190px, 0.75fr)",gap:a?16:24,fontSize:12,lineHeight:1.5,fontFamily:"var(--font-mono)"},children:[(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:a?16:20,minWidth:0},children:[H,B]}),L(U("desktop.sessionInfoMessages"),E),L(U("desktop.sessionInfoTokens"),[...W,...N],"right",!0)]})):(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:U("desktop.sendMessageForSessionInfo")})})]}),_&&T&&(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:3e3,display:"flex",alignItems:"flex-start",justifyContent:"center",paddingTop:48,background:"rgba(0,0,0,0.35)"},onMouseDown:e=>{e.target===e.currentTarget&&q(!1)},children:(0,r.jsx)("div",{role:"dialog","aria-label":T,style:{maxWidth:"min(560px, calc(100vw - 32px))",maxHeight:"min(60vh, 400px)",overflow:"auto",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:12,boxShadow:"0 16px 40px rgba(0,0,0,0.3)",padding:"14px 18px",fontSize:13,lineHeight:1.6,color:"var(--text)",wordBreak:"break-word",whiteSpace:"pre-wrap"},children:T})})]})}function pp({cwd:e,busy:t,error:o,onCancelAction:n,onConfirmAction:s}){let{t:i}=(0,A.s)();return(0,r.jsx)("div",{role:"presentation",style:{position:"fixed",inset:0,zIndex:1100,display:"flex",alignItems:"center",justifyContent:"center",padding:16,background:"rgba(0, 0, 0, 0.4)"},onClick:e=>{t||e.target!==e.currentTarget||n()},children:(0,r.jsxs)("section",{role:"dialog","aria-modal":"true","aria-labelledby":"project-trust-title",style:{width:440,maxWidth:"100%",border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",boxShadow:"0 12px 36px rgba(0, 0, 0, 0.24)",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{display:"flex",gap:12,padding:"18px 18px 14px"},children:[(0,r.jsx)(nz.o,{size:21,weight:"duotone",color:"var(--accent-orange)",style:{flexShrink:0,marginTop:1},"aria-hidden":"true"}),(0,r.jsxs)("div",{style:{minWidth:0},children:[(0,r.jsx)("h2",{id:"project-trust-title",style:{margin:0,fontSize:15,fontWeight:700,color:"var(--text)"},children:i("desktop.trustProjectTitle")}),(0,r.jsx)("p",{style:{margin:"7px 0 0",fontSize:12,lineHeight:1.6,color:"var(--text-muted)"},children:i("desktop.trustProjectBody")}),(0,r.jsx)("code",{style:{display:"block",marginTop:10,padding:"8px 10px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:11,overflowWrap:"anywhere"},children:e}),o&&(0,r.jsx)("div",{role:"alert",style:{marginTop:10,color:"var(--accent-red)",fontSize:12,lineHeight:1.5},children:o})]})]}),(0,r.jsxs)("footer",{style:{display:"flex",justifyContent:"flex-end",gap:8,padding:"10px 18px",borderTop:"1px solid var(--border)"},children:[(0,r.jsx)("button",{type:"button",onClick:n,disabled:t,style:{height:32,padding:"0 12px",border:"1px solid var(--border)",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:t?"not-allowed":"pointer",fontSize:12},children:i("desktop.cancel")}),(0,r.jsx)("button",{type:"button",onClick:s,disabled:t,style:{height:32,padding:"0 12px",border:"1px solid var(--accent)",borderRadius:5,background:"var(--accent)",color:"white",cursor:t?"wait":"pointer",opacity:t?.7:1,fontSize:12,fontWeight:600},children:i(t?"desktop.trustingProject":"desktop.trustProject")})]})]})})}function pu(e,t,o){let r=Number.isFinite(e)?e:t,n=Math.max(t,o);return Math.round(Math.max(t,Math.min(n,r)))}function ph(e){return pu(.42*e,360,640)}function pg(e,t){try{window.localStorage.setItem(e,String(t))}catch{}}function pm(e){let{ariaLabel:t,cssVariable:o,defaultWidth:r,getDefaultWidth:s,getMaxWidth:i,growthDirection:a,maxWidth:l,minWidth:d,storageKey:c,widthRef:p}=e,u=(0,n.useRef)(null),h=(0,n.useRef)(null),g=(0,n.useRef)(!1),[m,f]=(0,n.useState)(r),[x,k]=(0,n.useState)(!1),[v,y]=(0,n.useState)(!1);(0,n.useEffect)(()=>{y(!0)},[]);let b=(0,n.useCallback)(()=>Math.min(l,Math.max(d,i())),[i,l,d]),w=(0,n.useCallback)(e=>pu(e,d,b()),[b,d]),j=(0,n.useCallback)(e=>{p.current=e;let t=`${e}px`;u.current?.style.setProperty(o,t),u.current?.parentElement?.style.setProperty(o,t)},[o,p]),S=(0,n.useCallback)((e,t={})=>{let{forcePersist:o=!1,persist:r=!0}=t,n=w(e),s=n!==p.current;return j(n),f(n),r&&(s||o)&&pg(c,n),n},[j,w,c,p]),C=(0,n.useCallback)(e=>{document.body.style.cursor=e.previousCursor,document.body.style.userSelect=e.previousUserSelect},[]),T=(0,n.useCallback)(e=>{let t=h.current;if(t&&t.pointerId===e){h.current=null,C(t),k(!1),S(p.current,{forcePersist:!0});try{t.target.hasPointerCapture(e)&&t.target.releasePointerCapture(e)}catch{}}},[S,C,p]),R=(0,n.useCallback)(e=>{if("mouse"===e.pointerType&&0!==e.button)return;e.preventDefault(),e.stopPropagation();let t=h.current;t&&T(t.pointerId);let o=e.currentTarget;o.focus({preventScroll:!0}),o.setPointerCapture(e.pointerId),h.current={pointerId:e.pointerId,startX:e.clientX,startWidth:p.current,target:o,previousCursor:document.body.style.cursor,previousUserSelect:document.body.style.userSelect},document.body.style.cursor="col-resize",document.body.style.userSelect="none",k(!0)},[T,p]),z=(0,n.useCallback)(e=>{let t=h.current;if(!t||t.pointerId!==e.pointerId)return;if("mouse"===e.pointerType&&0===e.buttons)return void T(e.pointerId);e.preventDefault();let o="right"===a?1:-1,r=w(t.startWidth+(e.clientX-t.startX)*o);j(r),e.currentTarget.setAttribute("aria-valuenow",String(r)),e.currentTarget.setAttribute("aria-valuetext",`${r} px`)},[j,w,T,a]),I=(0,n.useCallback)(e=>{T(e.pointerId)},[T]),M=(0,n.useCallback)(e=>{T(e.pointerId)},[T]),P=(0,n.useCallback)(e=>{T(e.pointerId)},[T]),E=(0,n.useCallback)(()=>{S(s?.()??r,{forcePersist:!0})},[S,r,s]),W=(0,n.useCallback)(()=>{S(p.current)},[S,p]),F=(0,n.useCallback)(e=>{let t=e.shiftKey?32:12,o="right"===a?"ArrowRight":"ArrowLeft",r="right"===a?"ArrowLeft":"ArrowRight";e.key===o?(e.preventDefault(),S(p.current+t,{forcePersist:!0})):e.key===r?(e.preventDefault(),S(p.current-t,{forcePersist:!0})):"Home"===e.key?(e.preventDefault(),S(d,{forcePersist:!0})):"End"===e.key?(e.preventDefault(),S(b(),{forcePersist:!0})):"Enter"===e.key&&(e.preventDefault(),E())},[S,b,a,d,E,p]);return(0,n.useEffect)(()=>{if(g.current)return;g.current=!0;let e=function(e){try{let t=window.localStorage.getItem(e);if(null===t)return null;let o=Number.parseInt(t,10);return Number.isFinite(o)?o:null}catch{return null}}(c),t=S(e??s?.()??r,{persist:!1});null!==e&&e!==t&&pg(c,t)},[S,r,s,c]),(0,n.useEffect)(()=>{if(!g.current)return;S(p.current);let e=()=>{S(p.current)};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[S,p]),(0,n.useEffect)(()=>{if(!x)return;let e=()=>{let e=h.current;e&&T(e.pointerId)},t=()=>{"visible"!==document.visibilityState&&e()};return window.addEventListener("blur",e),document.addEventListener("visibilitychange",t),()=>{window.removeEventListener("blur",e),document.removeEventListener("visibilitychange",t)}},[T,x]),(0,n.useEffect)(()=>()=>{let e=h.current;e&&(h.current=null,C(e))},[C]),{isResizing:x,panelRef:u,reclampWidth:W,separatorProps:{"aria-label":t,"aria-orientation":"vertical","aria-valuemax":v?b():l,"aria-valuemin":d,"aria-valuenow":m,"aria-valuetext":`${m} px`,onDoubleClick:E,onKeyDown:F,onLostPointerCapture:P,onPointerCancel:M,onPointerDown:R,onPointerMove:z,onPointerUp:I,role:"separator",tabIndex:0},width:m}}function pf(e){return e.name||e.firstMessage||e.id.slice(0,12)}function px({status:e}){return"running"===e||"starting"===e?(0,r.jsxs)("svg",{className:"animate-spin",width:"13",height:"13",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeWidth:"2",opacity:"0.25"}),(0,r.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}):"failed"===e?(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,r.jsx)("path",{d:"m9 9 6 6M15 9l-6 6"})]}):"aborted"===e||"interrupted"===e?(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,r.jsx)("path",{d:"M9 9h6v6H9z"})]}):(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,r.jsx)("path",{d:"m8 12 3 3 5-6"})]})}function pk({session:e,main:t,selected:o,running:n,onSelect:s}){let{locale:i,t:a}=(0,A.s)(),l=e.relation?.kind==="subagent"?e.relation:null,d=n?"running":l?.status??"completed",c=t?a("agentSwitcher.main"):l?.description||pf(e),p=t?pf(e):`${l?.profile??a("agentSwitcher.subagent")} \xb7 ${function(e,t){let o=new Date(e).getTime();if(!Number.isFinite(o))return"";let r=Math.round((o-Date.now())/1e3),n=new Intl.RelativeTimeFormat(t,{numeric:"auto"});if(60>Math.abs(r))return n.format(r,"second");let s=Math.round(r/60);if(60>Math.abs(s))return n.format(s,"minute");let i=Math.round(s/60);return 24>Math.abs(i)?n.format(i,"hour"):n.format(Math.round(i/24),"day")}(e.modified,i)}`;return(0,r.jsxs)("button",{type:"button",role:"option","aria-selected":o,onClick:s,style:{width:"100%",minHeight:56,display:"grid",gridTemplateColumns:"28px minmax(0, 1fr) auto",alignItems:"center",gap:9,padding:"7px 12px",border:"none",borderBottom:"1px solid var(--border)",borderLeft:o?"2px solid var(--accent)":"2px solid transparent",background:o?"var(--bg-selected)":"transparent",color:"var(--text)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{o||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{o||(e.currentTarget.style.background="transparent")},children:[(0,r.jsx)("span",{style:{width:28,height:28,display:"grid",placeItems:"center",color:t?"var(--text-muted)":"var(--accent)"},children:t?(0,r.jsxs)("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"12",cy:"8",r:"4"}),(0,r.jsx)("path",{d:"M4 21a8 8 0 0 1 16 0"})]}):(0,r.jsxs)("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("rect",{x:"5",y:"7",width:"14",height:"11",rx:"2"}),(0,r.jsx)("path",{d:"M9 11h.01M15 11h.01M9 15h6M12 7V4M10 4h4"})]})}),(0,r.jsxs)("span",{style:{minWidth:0},children:[(0,r.jsx)("span",{style:{display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:12,fontWeight:o?600:500},title:c,children:c}),(0,r.jsx)("span",{style:{display:"block",marginTop:2,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontSize:11},title:p,children:p})]}),(0,r.jsx)("span",{style:{display:"flex",alignItems:"center",gap:6,color:t&&!n?"var(--text-dim)":"running"===d||"starting"===d?"var(--accent)":"completed"===d?"#16a34a":"failed"===d?"#dc2626":"aborted"===d?"#d97706":"var(--text-dim)",fontSize:11,whiteSpace:"nowrap"},children:t&&!n?o?a("agentSwitcher.current"):null:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(px,{status:d}),(0,r.jsx)("span",{children:a(`agentSwitcher.status.${d}`)})]})})]})}function pv({rootSession:e,subagents:t,selectedSessionId:o,runningSessionIds:s,onSelectSession:i}){let{t:a}=(0,A.s)(),[l,d]=(0,n.useState)(""),c=(0,n.useMemo)(()=>[...t].sort((e,t)=>{let o=s.has(e.id);return o!==s.has(t.id)?o?-1:1:t.modified.localeCompare(e.modified)}),[s,t]),p=l.trim().toLowerCase(),u=p?c.filter(e=>{let t=e.relation?.kind==="subagent"?e.relation:null;return[t?.description,t?.profile,e.name,e.firstMessage].some(e=>e?.toLowerCase().includes(p))}):c,h=t.filter(e=>s.has(e.id)).length;return(0,r.jsx)("div",{role:"listbox","aria-label":a("agentSwitcher.title"),style:{background:"var(--bg-panel)",borderLeft:"1px solid var(--border)",borderRight:"1px solid var(--border)",borderBottom:"1px solid var(--border)",borderRadius:"0 0 6px 6px",boxShadow:"0 10px 28px rgba(0,0,0,0.10)",overflow:"hidden"},children:(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{style:{minHeight:44,display:"flex",alignItems:"center",gap:8,padding:"7px 12px",borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)("strong",{style:{fontSize:12,fontWeight:600},children:a("agentSwitcher.title")}),(0,r.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:a("agentSwitcher.count",{count:t.length})}),h>0&&(0,r.jsx)("span",{style:{marginLeft:"auto",color:"var(--accent)",fontSize:11},children:a("agentSwitcher.runningCount",{count:h})})]}),t.length>8&&(0,r.jsx)("div",{style:{padding:8,borderBottom:"1px solid var(--border)"},children:(0,r.jsx)("input",{type:"search",value:l,onChange:e=>d(e.target.value),placeholder:a("agentSwitcher.search"),"aria-label":a("agentSwitcher.search"),style:{width:"100%",height:32,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text)",fontSize:12,outline:"none"}})}),(0,r.jsxs)("div",{style:{maxHeight:"min(58dvh, 480px)",overflowY:"auto"},children:[(0,r.jsx)(pk,{session:e,main:!0,selected:e.id===o,running:s.has(e.id),onSelect:()=>i(e)}),u.map(e=>(0,r.jsx)(pk,{session:e,selected:e.id===o,running:s.has(e.id),onSelect:()=>i(e)},e.id)),0===u.length&&(0,r.jsx)("div",{style:{padding:"22px 12px",color:"var(--text-dim)",fontSize:12,textAlign:"center"},children:a("agentSwitcher.noMatches")})]})]})})}function py(){var e;let t,o,l=(0,i.useRouter)(),d=(0,i.useSearchParams)(),c=(0,n.useMemo)(()=>{let e;return{requestedCwd:e=d.get("cwd")?.trim()||null,sessionId:e?null:d.get("session")}},[d]),{isDark:p,toggleTheme:u}=o9(),{t:h}=(0,A.s)(),g=O(),[m,f]=(0,n.useState)(null),[x,k]=(0,n.useState)(null),[v,y]=(0,n.useState)(0),[b,w]=(0,n.useState)(0),[j,S]=(0,n.useState)(0),[C,T]=(0,n.useState)(!1),[R,z]=(0,n.useState)("models"),[I,M]=(0,n.useState)(0),[P,E]=(0,n.useState)(null),[W,F]=(0,n.useState)(!1),[D,N]=(0,n.useState)(!1),[L,$]=(0,n.useState)(null),[H,B]=(0,n.useState)(!0),[U,_]=(0,n.useState)(!1);(0,n.useEffect)(()=>{g&&B(!1)},[g]),(0,n.useEffect)(()=>{_(!0)},[]);let q=(0,n.useRef)(null),V=(0,n.useRef)(null),[K,G]=(0,n.useState)(null),[J,Y]=(0,n.useState)(null),[X,Z]=(0,n.useState)(null),Q=pe(),ee=function(){let{isDesktop:e,isMacOS:t}=pe(),o=(0,n.useCallback)(e=>{var t;0===e.button&&(t=e.target).closest("[data-tauri-drag-region]")&&!t.closest('button, a, input, textarea, select, [role="button"], [contenteditable="true"], [data-no-drag]')&&(e.preventDefault(),e.stopPropagation(),2===e.detail?c5():c3())},[]);return e&&!t?{onMouseDown:o}:{}}(),[et,eo]=(0,n.useState)(null),er=(0,n.useCallback)(e=>{eo(e)},[]),[en,es]=(0,n.useState)(null),ei=(0,n.useCallback)(e=>{es(e)},[]),[ea,el]=(0,n.useState)(null),ed=(0,n.useRef)(null),ep=(0,n.useCallback)((e,t)=>{re(t).then(()=>{ed.current&&clearTimeout(ed.current),el(e),ed.current=setTimeout(()=>el(null),1400)})},[]);(0,n.useEffect)(()=>()=>{ed.current&&clearTimeout(ed.current)},[]);let[eu,eh]=(0,n.useState)(null),eg=(0,n.useCallback)(e=>{eh(e)},[]),[em,ef]=(0,n.useState)(null),[ex,ek]=(0,n.useState)(null),ev=(0,n.useCallback)(()=>{g&&B(!1),ef("session")},[g]),ey=(0,n.useCallback)(()=>{g&&ef(null),B(e=>!e)},[g]);(0,n.useEffect)(()=>{if(!em||!V.current)return;let e=()=>{let e=V.current.getBoundingClientRect();ek({top:e.bottom,left:e.left,width:e.width})};e();let t=new ResizeObserver(e);return t.observe(V.current),()=>t.disconnect()},[em]);let[eb,ew]=(0,n.useState)([]),[ej,eS]=(0,n.useState)(null),[eC,eT]=(0,n.useState)(!1),[eR,ez]=(0,n.useState)(!1),[eI,eM]=(0,n.useState)([]),[eP,eE]=(0,n.useState)(()=>new Set);(0,n.useEffect)(()=>{if(!eR)return;let e=!1,t=()=>{fetch("/api/sessions",{cache:"no-store"}).then(e=>e.json()).then(t=>{e||(eM(t.sessions??[]),eE(new Set(t.runningSessionIds??[])))}).catch(()=>{})};t();let o=setInterval(t,3e3);return()=>{e=!0,clearInterval(o)}},[eR,m?.id,v]);let eW=(0,n.useCallback)(async e=>{try{let t=await fetch(`/api/sessions/${encodeURIComponent(e)}`,{cache:"no-store"}),o=await t.json();if(!t.ok||!o.info)throw Error(o.error??`HTTP ${t.status}`);e9.current(o.info)}catch(e){console.error("[pi-web] failed to open session:",e instanceof Error?e.message:e)}},[]),eF=(0,n.useRef)(260),eD=(0,n.useRef)(ph(1366)),eA=(0,n.useCallback)(()=>ph(window.innerWidth),[]),eN=(0,n.useCallback)(()=>(function(e){let{viewportWidth:t,rightPanelOpen:o,rightPanelWidth:r}=e;if(t<=640)return 480;let n=t<960;return Math.min(480,t-(n?320:420)-(!n&&o?r:0))})({viewportWidth:window.innerWidth,rightPanelOpen:eC,rightPanelWidth:eD.current}),[eC]),eL=(0,n.useCallback)(()=>(function(e){let{viewportWidth:t,sidebarOpen:o,sidebarWidth:r}=e;return t<960?1200:Math.min(1200,t-420-(o?r:0))})({viewportWidth:window.innerWidth,sidebarOpen:H,sidebarWidth:eF.current}),[H]),e$=pm({ariaLabel:h("desktop.resizeSidebar"),cssVariable:"--sidebar-width",defaultWidth:260,getMaxWidth:eN,growthDirection:"right",maxWidth:480,minWidth:180,storageKey:"pi-sidebar-width",widthRef:eF}),eH=pm({ariaLabel:h("desktop.resizeFilePanel"),cssVariable:"--right-panel-width",defaultWidth:ph(1366),getDefaultWidth:eA,getMaxWidth:eL,growthDirection:"left",maxWidth:1200,minWidth:300,storageKey:"pi-right-panel-width",widthRef:eD}),eO=e$.reclampWidth,eB=eH.reclampWidth;(0,n.useEffect)(()=>{eC&&(eO(),eB())},[eB,eO,eC]);let eU=(0,n.useCallback)((e,t)=>{q.current?.insertText(sj(e,t))},[]),e_=(0,n.useCallback)(e=>{let t=e.map(e=>sj(e,!1)).join("");t&&q.current?.insertText(t)},[]),eq=(0,n.useCallback)((e,t,o)=>{let r,n,s,i;q.current?.insertText((r=Math.max(1,Math.min(t,o)),n=Math.max(1,Math.max(t,o)),s=e.includes(" ")?`@"${e}"`:`@${e}`,i=r===n?`:${r}`:`:${r}-${n}`,`${s}${i} `))},[]),[eV,eK]=(0,n.useState)(()=>c.sessionId),[eG,eJ]=(0,n.useState)(null),[eY,eX]=(0,n.useState)(()=>c.requestedCwd?"validating":"idle"),[eZ,eQ]=(0,n.useState)(null),[e0,e1]=(0,n.useState)(()=>!eV),e2=(0,n.useRef)(!1),e4=(0,n.useRef)(new Map),[e6,e8]=(0,n.useState)(null),e5=(0,n.useRef)("");(0,n.useEffect)(()=>{let e=`${c.requestedCwd??""}|${c.sessionId??""}`;e5.current!==e&&(e5.current=e,eK(c.sessionId),e1(!c.sessionId),c.requestedCwd||eX("idle"),eQ(null))},[c]),(0,n.useEffect)(()=>{let e=c.requestedCwd;if(!e)return;let t=new AbortController;return eX("validating"),eQ(null),fetch("/api/cwd/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e}),signal:t.signal}).then(async e=>{let t=await e.json().catch(()=>({}));if(!e.ok||!t.cwd)throw Error(t.error??`HTTP ${e.status}`);e2.current=!0,k(t.cwd),eX("ready")}).catch(e=>{t.signal.aborted||(eQ(e instanceof Error?e.message:String(e)),eX("error"))}),()=>t.abort()},[c]);let e3=(0,n.useCallback)((e,t)=>{if(!e)return;if(eJ(e),e2.current&&m&&tk(m.projectRoot??m.cwd,t??e)){if(e2.current=!1,m){let e=m.projectRoot??m.cwd;e&&e4.current.set(e,m.id)}return}e2.current=!1;let o=t??e;if(m&&tk(m.projectRoot??m.cwd,o)){(m.projectRoot??m.cwd)&&e4.current.set(o,m.id);return}if(m){let e=m.projectRoot??m.cwd;e&&e4.current.set(e,m.id)}f(null),k(t=>t&&t!==e?null:t),w(e=>e+1),eo(null),ef(null),window.history.replaceState(null,"","/");let r=e4.current.get(o);e8(r?{projectRoot:o,sessionId:r}:null)},[m]);(0,n.useEffect)(()=>{let e=eG?ec(eG)||eG:null;document.title=e?`${e} — Pi Agent Web`:"Pi Agent Web"},[eG]);let e7=(0,n.useCallback)((e,t=!1)=>{if(t||e8(null),!t&&m){let t=tk(m.projectRoot??m.cwd,e.projectRoot??e.cwd);if(m.id===e.id&&t){g&&B(!1);return}}let o=e.projectRoot??e.cwd;o&&e4.current.set(o,e.id),k(null),f(e),w(e=>e+1),eo(null),e1(!0),g&&!t&&B(!1),t&&(e2.current=!0),t||window.history.replaceState(null,"",`?session=${encodeURIComponent(e.id)}`)},[g,m]),e9=(0,n.useRef)(()=>{});(0,n.useEffect)(()=>{e9.current=e7},[e7]);let te=(0,n.useCallback)(e=>{fetch("/api/sessions").then(e=>e.ok?e.json():null).then(t=>{let o=t?.sessions.find(t=>t.id===e);o&&f(t=>!t||t.id!==e||t.projectRoot&&t.name?t:o)}).catch(()=>{})},[]);(0,n.useEffect)(()=>{if(!e6)return;let{projectRoot:e,sessionId:t}=e6;e9.current({path:"",id:t,cwd:e,created:"",modified:"",messageCount:0,firstMessage:"",projectRoot:e},!0),te(t),window.history.replaceState(null,"",`?session=${encodeURIComponent(t)}`),e8(null)},[e6,te]);let tt=(0,n.useCallback)((e,t)=>{e8(null),f(null),k(t),w(e=>e+1),eo(null),ef(null),g&&B(!1),window.history.replaceState(null,"","/")},[l,g]);!function(e){let{onNewSession:t,activeCwd:o}=e;(0,n.useEffect)(()=>{let e=e=>{if("Escape"===e.key){if(!a)return;let t=e.target?.tagName;if("TEXTAREA"===t||"INPUT"===t)return;e.preventDefault(),a();return}if("n"===e.key&&e.ctrlKey&&e.altKey){if(!o||!t)return;e.preventDefault(),t(o)}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[o,t])}({onNewSession:e=>tt(`kb-${Date.now()}`,e),activeCwd:eG});let to=(0,n.useCallback)(e=>{k(null),e8(null);let t=e.projectRoot??e.cwd;t&&e4.current.set(t,e.id),f(e),e.cwd&&eJ(e.cwd),y(e=>e+1),te(e.id),window.history.replaceState(null,"",`?session=${encodeURIComponent(e.id)}`),window.setTimeout(()=>y(e=>e+1),1200),window.setTimeout(()=>y(e=>e+1),4e3)},[l,te]),tr=(0,n.useCallback)(()=>{y(e=>e+1),S(e=>e+1)},[]),tn=(0,n.useCallback)(e=>{y(e=>e+1),w(e=>e+1),k(null),e8(null),f(t=>{let o={...t??{path:"",cwd:"",created:"",modified:"",messageCount:0,firstMessage:""},id:e},r=o.projectRoot??o.cwd;return r&&e4.current.set(r,e),o}),te(e),window.history.replaceState(null,"",`?session=${encodeURIComponent(e)}`)},[l,te]),ts=(0,n.useCallback)(()=>{e1(!0)},[]),ti=(0,n.useCallback)(e=>{if(y(e=>e+1),m?.id===e){let e=m.cwd;f(null),k(e??null),w(e=>e+1),eo(null),ef(null),window.history.replaceState(null,"","/")}},[l,m]),ta=(0,n.useCallback)((e,t,o,r)=>{let n="string"==typeof o||null===o?o:void 0,s="object"==typeof o&&null!==o?o:r,i=`file:${e}`;ew(o=>{let r=o.find(e=>e.id===i);return r?n&&r.sourceSessionId!==n||s?.initialDisplayMode&&r.initialDisplayMode!==s.initialDisplayMode?o.map(e=>e.id===i?{...e,sourceSessionId:n??e.sourceSessionId,initialDisplayMode:s?.initialDisplayMode??e.initialDisplayMode}:e):o:[...o,{id:i,label:t,filePath:e,sourceSessionId:n,initialDisplayMode:s?.initialDisplayMode}]}),eS(i),eT(!0),g&&B(!1)},[g]),tl=(0,n.useCallback)(e=>{ta(e,ec(e),m?.id??null)},[ta,m?.id]),td=(0,n.useCallback)(e=>{ew(t=>{let o=t.filter(t=>t.id!==e);return 0===o.length&&eT(!1),o}),eS(t=>{if(t!==e)return t;let o=eb.filter(t=>t.id!==e);return o.length>0?o[o.length-1].id:null})},[eb]),tc=(0,n.useCallback)(e=>{S(e=>e+1),ta(e,ec(e))},[ta]),tp=(0,n.useCallback)((e,t)=>{S(e=>e+1);let o=e.endsWith("/")?e:e+"/",r=r=>r===e||t&&r.startsWith(o);ew(e=>{let t=e.filter(e=>!r(e.filePath));return 0===t.length&&eT(!1),t}),eS(e=>{if(!e)return e;let t=eb.find(t=>t.id===e);if(!t||!r(t.filePath))return e;let o=eb.filter(e=>!r(e.filePath));return o.length>0?o[o.length-1].id:null})},[eb]),tu=m?tM(m.name||en?.sessionName)||m.firstMessage.slice(0,50)||m.id.slice(0,12):(t=eG??x)?t.replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean).pop()||t:null,th=(0,n.useCallback)(()=>{m&&window.open(`/api/sessions/${encodeURIComponent(m.id)}/export?inline=1`,"_blank","noopener,noreferrer")},[m]),tg=x??(null===m&&eG?eG:null),tm="validating"!==eY&&"error"!==eY&&(null!==m||null!==tg),tf=m?.cwd??tg,[tx,tv]=(0,n.useState)(!1),ty=(0,n.useCallback)(()=>{g||tv(e=>!e)},[g]),[tb,tw]=(0,n.useState)(!0);(0,n.useEffect)(()=>{let e=!1,t=()=>fetch("/api/features").then(e=>e.ok?e.json():null).then(t=>{!e&&t&&"boolean"==typeof t.tasksBoard&&(tw(t.tasksBoard),t.tasksBoard||tv(!1))}).catch(()=>{});t();let o=()=>t();return window.addEventListener("pi:features-changed",o),()=>{e=!0,window.removeEventListener("pi:features-changed",o)}},[]);let tj=e0&&!tm;(0,n.useEffect)(()=>{let e=()=>{g||tv(!0)};return window.addEventListener(ah,e),()=>window.removeEventListener(ah,e)},[g]),(0,n.useEffect)(()=>{if(E(null),F(!1),$(null),!tf)return;let e=new AbortController;return fetch(`/api/project-trust?cwd=${encodeURIComponent(tf)}`,{signal:e.signal}).then(async e=>{let t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);E(t)}).catch(e=>{e instanceof DOMException&&"AbortError"===e.name||console.error("Failed to load project trust:",e)}),()=>e.abort()},[tf]);let tS=(0,n.useCallback)(async()=>{if(tf&&!D){N(!0),$(null);try{let e=await fetch("/api/project-trust",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:tf})}),t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);E(t),F(!1),M(e=>e+1),w(e=>e+1)}catch(e){$(e instanceof Error?e.message:String(e))}finally{N(!1)}}},[D,tf]),tC=eb.find(e=>e.id===ej)??null,tT=eG??m?.cwd??x,tR=(0,n.useCallback)(e=>{z(e),T(!0)},[]),tz=(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(t$,{selectedSessionId:m?.id??null,onSelectSession:e7,onNewSession:tt,initialSessionId:eV,onInitialRestoreDone:ts,refreshKey:v,onSessionDeleted:ti,selectedCwd:m?.cwd??x??null,onCwdChange:e3,onOpenFile:ta,selectedSessionStats:en,onOpenSettings:e=>{tR(["models","skills","plugins","chat","features","logs"].includes(e)?e:"models")},explorerRefreshKey:j,onAtMention:eU,onAtMentions:e_,onFileCreated:tc,onFileDeleted:tp,workspaceControlsHosts:{title:K,welcome:X,titleRight:J},showWorkspaceControls:!0})});return(0,r.jsxs)(cv,{children:[(0,r.jsx)("style",{children:`
38
38
  @media (max-width: 640px) {
39
39
  .sidebar-overlay-backdrop.sidebar-mobile-pending {