@baique/pi-web-sky 0.1.59 → 0.1.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.next/BUILD_ID +1 -1
- package/.next/app-path-routes-manifest.json +8 -8
- package/.next/build-manifest.json +3 -3
- package/.next/react-loadable-manifest.json +1 -1
- package/.next/required-server-files.js +1 -1
- package/.next/required-server-files.json +1 -1
- package/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/.next/server/app/_global-error.html +1 -1
- package/.next/server/app/_global-error.rsc +1 -1
- package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/.next/server/app/_not-found.html +1 -1
- package/.next/server/app/_not-found.rsc +3 -3
- package/.next/server/app/_not-found.segments/_full.segment.rsc +3 -3
- package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +3 -3
- package/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
- package/.next/server/app/api/app-update/route.js +1 -1
- package/.next/server/app/index.html +1 -1
- package/.next/server/app/index.rsc +5 -5
- package/.next/server/app/index.segments/__PAGE__.segment.rsc +5 -5
- package/.next/server/app/index.segments/_full.segment.rsc +5 -5
- package/.next/server/app/index.segments/_tree.segment.rsc +2 -2
- package/.next/server/app/page.js +8 -8
- package/.next/server/app/page_client-reference-manifest.js +1 -1
- package/.next/server/app-paths-manifest.json +8 -8
- package/.next/server/middleware-build-manifest.js +1 -1
- package/.next/server/middleware-react-loadable-manifest.js +1 -1
- package/.next/server/pages/404.html +1 -1
- package/.next/server/pages/500.html +1 -1
- package/.next/static/chunks/{8088.39866dc5f1d15868.js → 8088.a8a689f302a4f56d.js} +1 -1
- package/.next/static/chunks/app/{layout-15b8d7ddfb49a19d.js → layout-772dd85585321723.js} +1 -1
- package/.next/static/chunks/app/page-c0fcc5519c551d52.js +256 -0
- package/.next/static/chunks/{webpack-1ce35e1249cfd931.js → webpack-4b8e9412e72f86c0.js} +1 -1
- package/.next/static/css/21bd3ff21f2866ac.css +1 -0
- package/.next/trace +7 -8
- package/.next/trace-build +1 -1
- package/lib/transcript.test.mjs +186 -0
- package/lib/transcript.ts +304 -0
- package/lib/turn-merge.ts +1 -1
- package/package.json +1 -1
- package/.next/static/chunks/app/page-06102d7540ccaf75.js +0 -256
- package/.next/static/css/c7d127e07b1a786c.css +0 -1
- /package/.next/static/{qD0gvlcxBrjwm2vdTuA1h → 8BGmvqU4qqWNmMv2mieIS}/_buildManifest.js +0 -0
- /package/.next/static/{qD0gvlcxBrjwm2vdTuA1h → 8BGmvqU4qqWNmMv2mieIS}/_ssgManifest.js +0 -0
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8974],{1518:(e,t,n)=>{"use strict";n.d(t,{d:()=>i});let r=/^<skill name="([^"\n]+)" location="([^"\n]+)">\nReferences are relative to [^\n]+\.\n\n([\s\S]*)\n<\/skill>(?:\n\n([\s\S]+))?$/;function i(e){let t=e.match(r);if(!t)return null;let[,n,,i,o]=t;return{command:o?`/skill:${n} ${o}`:`/skill:${n}`,skillBody:i,userMessage:t[4]}}},3099:(e,t,n)=>{"use strict";function r(e){let t=/(?:^|\s)@"([^"\n]*)$/.exec(e);if(t)return{start:e.length-(t[1].length+2),query:t[1],quoted:!0};let n=/(?:^|\s)@([^\s"]*)$/.exec(e);return n?{start:e.length-(n[1].length+1),query:n[1],quoted:!1}:null}function i(e){let t=0;for(let n=0;n<e.length;n++)"/"===e[n]&&t++;return t}function o(e){let t=new Set;for(let n of e){let e=n.indexOf("/");for(;-1!==e;)t.add(n.slice(0,e)),e=n.indexOf("/",e+1)}let n=[];for(let e of t)n.push({path:e,isDir:!0});for(let t of e)t&&n.push({path:t,isDir:!1});return n.sort((e,t)=>i(e.path)-i(t.path)||e.path.localeCompare(t.path)),n}function a(e,t){if(!e)return!0;let n=0;for(let r=0;r<t.length&&n<e.length;r++)t[r]===e[n]&&n++;return n===e.length}function s(e,t,n=20){let r=t.toLowerCase();if(!r)return e.slice(0,n);let o=[];for(let t of e){let e=function(e,t){let n=e.path.toLowerCase(),r=0;if(t.includes("/"))n===t?r=100:n.startsWith(t)?r=80:n.includes(t)?r=50:a(t,n)&&(r=10);else{let e=n.lastIndexOf("/"),i=-1===e?n:n.slice(e+1);i===t?r=100:i.startsWith(t)?r=80:i.includes(t)?r=50:n.includes(t)?r=30:a(t,n)&&(r=10)}return e.isDir&&r>0&&(r+=10),r}(t,r);e>0&&o.push({entry:t,score:e})}return o.sort((e,t)=>t.score-e.score||i(e.entry.path)-i(t.entry.path)||e.entry.path.localeCompare(t.entry.path)),o.slice(0,n).map(e=>e.entry)}function l(e,t,n=!1){let r=t?`${e}/`:e,i=n||r.includes(" ");if(t){let e=i?`@"${r}"`:`@${r}`;return{text:e,cursorOffset:i?e.length-1:e.length}}let o=i?`@"${r}" `:`@${r} `;return{text:o,cursorOffset:o.length}}function d(e,t){let n=t?`${e}/`:e;return n.includes(" ")?`@"${n}" `:`@${n} `}function c(e,t,n){let r=Math.max(1,Math.min(t,n)),i=Math.max(1,Math.max(t,n)),o=e.includes(" ")?`@"${e}"`:`@${e}`,a=r===i?`:${r}`:`:${r}-${i}`;return`${o}${a} `}function u(e){return e.map(e=>d(e,!1)).join("")}n.d(t,{$C:()=>d,R7:()=>s,RO:()=>r,SO:()=>u,W:()=>l,Yh:()=>o,sn:()=>c})},4325:(e,t,n)=>{"use strict";function r(e=document){return"visible"!==e.visibilityState||!e.hasFocus()}function i(e){switch(e.method){case"select":case"confirm":case"input":case"editor":return!0;case"custom":return!0!==e.closed;default:return!1}}function o(e,t){return!(!i(e)||t.has(e.id))&&(t.add(e.id),!0)}async function a(e,t={createWindowNotification:(e,t)=>new Notification(e,t),getServiceWorkerRegistration:"serviceWorker"in navigator?()=>navigator.serviceWorker.getRegistration():null}){let n={body:e.body,...e.tag?{tag:e.tag}:{}};if(t.getServiceWorkerRegistration)try{let r=await t.getServiceWorkerRegistration();if(r)return await r.showNotification(e.title,{...n,data:{url:e.sessionUrl}}),"service-worker"}catch{}try{let r=t.createWindowNotification(e.title,n);return r.onclick=()=>{r.close(),e.onClick()},"window"}catch{return null}}n.d(t,{$N:()=>o,SH:()=>r,YI:()=>i,dL:()=>a})},7834:(e,t,n)=>{"use strict";function r(e){if(navigator.clipboard?.writeText)return navigator.clipboard.writeText(e);try{let t=document.createElement("textarea");return t.value=e,t.style.position="fixed",t.style.opacity="0",document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t),Promise.resolve()}catch{return Promise.reject()}}n.d(t,{D:()=>r})},13405:(e,t,n)=>{"use strict";n.d(t,{J:()=>p});var r=n(95155),i=n(12115),o=n(47650),a=n(39247),s=n(48660),l=n(20985);function d(e,t){return t&&e.startsWith(t)?"~"+e.slice(t.length):e}function c({text:e,style:t}){return(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",display:"block",minWidth:0,lineHeight:1.35,direction:"rtl",textAlign:"left",...t},children:(0,r.jsx)("span",{style:{unicodeBidi:"plaintext"},children:e})})}let u=(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,r.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,r.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,r.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,r.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]});function p({cwd:e,onSelect:t,style:n,labelStyle:h,onOpenChange:g,showMainLabel:x=!0,compact:f=!1}){let{t:m}=(0,a.s)(),[v,b]=(0,i.useState)(null),[y,k]=(0,i.useState)(!1),[w,j]=(0,i.useState)(""),[S,C]=(0,i.useState)(!1),[T,M]=(0,i.useState)(!1),[I,L]=(0,i.useState)(""),[R,E]=(0,i.useState)(!1),[z,W]=(0,i.useState)(""),P=(0,s.u)(),[$,N]=(0,i.useState)(null),[D,B]=(0,i.useState)(!1),[A,F]=(0,i.useState)(null),H=(0,i.useRef)(null),O=(0,i.useRef)(null),U=(0,i.useRef)(null),_=(0,i.useRef)(null),[q,V]=(0,i.useState)(null);(0,i.useEffect)(()=>{fetch("/api/home").then(e=>e.json()).then(e=>{e.home&&j(e.home)}).catch(()=>{})},[]);let J=(0,i.useRef)(null);(0,i.useEffect)(()=>{if(!e||J.current===e)return;let t=!1;return k(!0),fetch(`/api/worktrees?cwd=${encodeURIComponent(e)}`).then(e=>e.json()).then(n=>{if(!t){if(k(!1),n.error||!n.projectRoot)return void b(null);b({forCwd:e,projectRoot:n.projectRoot,projectKey:n.projectKey??"",isGit:n.isGit??!1,isTopLevel:n.isTopLevel??!1,currentWorktreePath:n.currentWorktreePath??null,worktrees:n.worktrees??[]}),J.current=e}}).catch(()=>{t||k(!1)}),()=>{t=!0}},[e]);let K=v?v.worktrees.find(t=>t.path===e)??(v.forCwd===e&&v.currentWorktreePath?v.worktrees.find(e=>e.path===v.currentWorktreePath):void 0)??v.worktrees.find(e=>e.isMain):void 0,Y=(0,i.useCallback)(()=>{let e=O.current?.getBoundingClientRect();if(!e)return;let t=window.innerHeight-e.bottom<Math.min(320,e.top);V({left:e.left,top:t?e.top:e.bottom,width:e.width,up:t}),C(!0)},[]);(0,i.useEffect)(()=>{g?.(S)},[S,g]);let G=(0,i.useCallback)(e=>{C(!1),N(null),L(""),t?.(e,v?{projectRoot:v.projectRoot,projectKey:v.projectKey,worktreePaths:v.worktrees.map(e=>e.path)}:void 0)},[t,v]),X=(0,i.useCallback)(async()=>{let e=z.trim();if(e&&!D&&v){B(!0),N(null);try{let n=await fetch("/api/worktrees",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:v.projectRoot,branch:e})}),r=await n.json().catch(()=>({}));if(!n.ok||r.error||!r.path)return void N(r.error??`HTTP ${n.status}`);E(!1),W(""),b(t=>t?{...t,worktrees:[...t.worktrees,{path:r.path,branch:e,isMain:!1}]}:t),C(!1),N(null),L(""),t?.(r.path,v?{projectRoot:v.projectRoot,projectKey:v.projectKey,worktreePaths:[...v.worktrees.map(e=>e.path),r.path]}:void 0)}catch(e){N(e instanceof Error?e.message:String(e))}finally{B(!1)}}},[z,D,v,t]),Z=(0,i.useCallback)(async(e,n)=>{if(v&&!D){B(!0),N(null);try{let r=await fetch("/api/worktrees",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:v.projectRoot,path:e,force:n})}),i=await r.json().catch(()=>({}));if(!r.ok){if(i.dirty&&!n)return void F(e);N(i.error??`HTTP ${r.status}`);return}F(null),b(t=>t?{...t,worktrees:t.worktrees.filter(t=>t.path!==e)}:t),K?.path===e&&(C(!1),N(null),L(""),t?.(v.projectRoot,v?{projectRoot:v.projectRoot,projectKey:v.projectKey,worktreePaths:v.worktrees.filter(t=>t.path!==e).map(e=>e.path)}:void 0))}catch(e){N(e instanceof Error?e.message:String(e))}finally{B(!1)}}},[v,D,K?.path,t]);(0,i.useEffect)(()=>{let e=e=>{let t=e.target;H.current?.contains(t)||U.current?.contains(t)||(C(!1),E(!1),W(""),N(null),F(null),L(""))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let Q=(v?.worktrees.length??0)>=8,ee=Q&&I.trim()?(v?.worktrees??[]).filter(e=>(e.branch??d(e.path,w)).toLowerCase().includes(I.trim().toLowerCase())):v?.worktrees??[],et=K?.path??null,en=null!==v&&!(v.isGit&&v.isTopLevel),er=en?v.isGit?"当前为仓库子目录,子目录会话保持自身项目身份":"该目录不是 git 仓库,worktree 切换不可用":null;return(0,r.jsxs)("div",{ref:H,style:{position:"relative"},children:[(0,r.jsxs)("button",{ref:O,onClick:en?void 0:Y,title:en?er??void 0:K?K.path:m("sidebar.switchWorktree"),style:{display:"flex",alignItems:"center",gap:6,height:28,boxSizing:"border-box",padding:f?"0 6px":"0 10px",maxWidth:f?85:void 0,background:S?"var(--side-active)":T?"var(--side-hover)":"transparent",border:"none",borderRadius:5,cursor:en?"default":"pointer",fontSize:11,lineHeight:1.35,color:"var(--text-muted)",textAlign:"left",transition:"background 0.12s",...n},onMouseEnter:()=>M(!0),onMouseLeave:()=>M(!1),children:[u,(0,r.jsx)(c,{text:K?K.branch??d(K.path,w):y?"…":m("sidebar.worktrees"),style:{flex:1,fontFamily:"var(--font-mono)",color:"var(--text)",...h}}),x&&K?.isMain&&(0,r.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10},children:m("sidebar.main")}),!f&&!en&&(v?.worktrees.length??0)>1&&(0,r.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10},children:v.worktrees.length}),!f&&!en&&(0,r.jsx)("svg",{width:"9",height:"9",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,r.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),q&&(0,o.createPortal)((0,r.jsx)("div",{ref:U,style:{position:"fixed",left:q.left,top:q.top,width:q.width,zIndex:1e3},children:(0,r.jsxs)(l.f,{open:S,up:q.up,style:{position:"absolute",top:q.up?"auto":4,bottom:q.up?"calc(100% + 4px)":"auto",left:0,right:0,minWidth:220,background:"var(--popover-glass)",backdropFilter:"blur(var(--glass-blur-heavy)) saturate(var(--glass-saturate))",WebkitBackdropFilter:"blur(var(--glass-blur-heavy)) saturate(var(--glass-saturate))",border:"1px solid color-mix(in srgb, var(--border) 60%, transparent)",borderRadius:8,boxShadow:"0 6px 20px rgba(0,0,0,0.10)",overflow:"hidden"},children:[Q&&(0,r.jsx)("div",{style:{padding:"6px 8px",borderBottom:"1px solid var(--border)"},children:(0,r.jsx)("input",{value:I,onChange:e=>L(e.target.value),onKeyDown:e=>{"Escape"===e.key&&(L(""),C(!1))},placeholder:m("sidebar.filterWorktrees"),autoFocus:!0,style:{width:"100%",fontSize:11,fontFamily:"var(--font-mono)",padding:"5px 8px",border:"1px solid color-mix(in srgb, var(--border) 55%, transparent)",borderRadius:5,outline:"none",background:"var(--side-input)",color:"var(--text)",boxSizing:"border-box"}})}),(0,r.jsxs)("div",{style:{maxHeight:"min(40vh, 300px)",overflowY:"auto"},children:[ee.map(e=>{let t=e.path===et;return A===e.path?(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"7px 10px",borderBottom:"1px solid var(--border)",background:"rgba(239,68,68,0.06)"},children:[(0,r.jsx)("span",{style:{flex:1,fontSize:11,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:m("sidebar.forceRemoveCheckout")}),(0,r.jsx)("button",{onClick:()=>void Z(e.path,!0),disabled:D,style:{padding:"3px 9px",background:"#ef4444",border:"none",borderRadius:5,color:"#fff",fontSize:11,fontWeight:600,cursor:"pointer",flexShrink:0},children:m("sidebar.force")}),(0,r.jsx)("button",{onClick:()=>F(null),style:{padding:"3px 9px",background:"transparent",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-muted)",fontSize:11,cursor:"pointer",flexShrink:0},children:m("sidebar.cancel")})]},e.path):(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",borderBottom:"1px solid var(--border)"},children:[(0,r.jsxs)("button",{onClick:()=>G(e.path),title:e.path,onMouseEnter:e=>{e.currentTarget.style.background="var(--side-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:7,padding:"8px 10px",background:"transparent",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11,fontFamily:"var(--font-mono)"},children:[t?(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},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)(c,{text:e.branch??d(e.path,w),style:{flex:1}}),e.isMain&&(0,r.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10},children:m("sidebar.main")})]}),!e.isMain&&(0,r.jsx)("button",{onClick:()=>void Z(e.path,!1),disabled:D,title:m("sidebar.removeWorktreeTitle",{path:e.path}),style:{display:"flex",alignItems:"center",justifyContent:"center",width:34,height:28,padding:0,marginRight:4,background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",borderRadius:5,flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="#ef4444",e.currentTarget.style.background="rgba(239,68,68,0.08)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)",e.currentTarget.style.background="none"},children:(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,r.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,r.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,r.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]})})]},e.path)}),Q&&0===ee.length&&I.trim()&&(0,r.jsx)("div",{style:{padding:"8px 10px",fontSize:11,color:"var(--text-dim)"},children:m("sidebar.noMatchingWorktrees")})]}),R?(0,r.jsxs)("div",{style:{padding:"6px 8px"},children:[(0,r.jsx)("input",{ref:_,value:z,onChange:e=>{W(e.target.value),N(null)},...P.compositionProps,onKeyDown:e=>{P.isIMEBusy(e)||("Enter"===e.key&&(e.preventDefault(),X()),"Escape"===e.key&&(E(!1),W(""),N(null)))},placeholder:m("sidebar.branchName"),style:{width:"100%",fontSize:11,fontFamily:"var(--font-mono)",padding:"5px 8px",border:"1px solid var(--accent)",borderRadius:5,outline:"none",background:"var(--side-input)",color:"var(--text)",boxSizing:"border-box"}}),(0,r.jsxs)("div",{style:{display:"flex",gap:5,marginTop:5},children:[(0,r.jsx)("button",{onClick:()=>void X(),disabled:D||!z.trim(),style:{flex:1,padding:"4px 0",background:"var(--accent)",border:"none",borderRadius:5,color:"#fff",fontSize:11,fontWeight:600,cursor:D||!z.trim()?"not-allowed":"pointer",opacity:D||!z.trim()?.65:1},children:D?m("sidebar.creating"):m("sidebar.create")}),(0,r.jsx)("button",{onClick:()=>{E(!1),W(""),N(null)},style:{flex:1,padding:"4px 0",background:"transparent",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-muted)",fontSize:11,cursor:"pointer"},children:m("sidebar.cancel")})]})]}):(0,r.jsxs)("button",{onClick:e=>{e.stopPropagation(),E(!0),N(null),setTimeout(()=>_.current?.focus(),0)},title:m("sidebar.createWorktreeTitle"),style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11},children:[(0,r.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.1",strokeLinecap:"round",style:{flexShrink:0},children:[(0,r.jsx)("line",{x1:"5",y1:"1",x2:"5",y2:"9"}),(0,r.jsx)("line",{x1:"1",y1:"5",x2:"9",y2:"5"})]}),(0,r.jsx)("span",{children:m("sidebar.newWorktree")})]}),$&&(0,r.jsx)("div",{style:{padding:"5px 10px 8px",color:"#dc2626",fontSize:11,lineHeight:1.35,overflowWrap:"anywhere"},children:$})]})}),document.body)]})}},14755:(e,t,n)=>{"use strict";n.d(t,{getPresetFromTools:()=>c,sn:()=>d,xG:()=>u});let r=["none","read-only","default","full"],i=[],o=["read","grep","find","ls"],a=["read","bash","edit","write"],s=["bash","read","edit","write","grep","find","ls"],l=new Set(s);function d(e){return"string"==typeof e&&r.includes(e)}function c(e){let t=e.filter(e=>e.active);if(0===t.length)return"none";let n=t.map(e=>e.name).filter(e=>l.has(e)).sort().join(",");return n===[...o].sort().join(",")?"read-only":n===[...a].sort().join(",")?"default":n===[...s].sort().join(",")?"full":"default"}function u(e){return"none"===e?[...i]:"read-only"===e?[...o]:"full"===e?[...s]:[...a]}},19870:(e,t,n)=>{"use strict";function r(e){try{return decodeURIComponent(e)}catch{return e}}function i(e){return/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith("\\\\")?e.replace(/\\/g,"/"):e}function o(e){let t=i(e),n=/^[a-zA-Z]:\//.test(t),r=t.startsWith("//"),o=t.startsWith("/")&&!n&&!r,a=[];for(let e of t.split("/"))if(e&&"."!==e){if(".."===e){a.length>0&&".."!==a[a.length-1]?a.pop():o||n||r||a.push(e);continue}a.push(e)}let s=a.join("/");return n?s:r?`//${s}`:o?`/${s}`:s}function a(e,t,n=t){let s,l,d,c,u;if(!e)return null;let p=e.split("#",1)[0].split("?",1)[0].trim();if(!p)return null;let h=null,g=null,x=r(p),f=x.startsWith("\\\\"),m=i(x),v=m.toLowerCase();if(v.startsWith("/api/")||v.startsWith("/_next/")||!f&&m.startsWith("//")||/^[a-zA-Z][a-zA-Z0-9+.-]*:/i.test(m)&&!v.startsWith("file:")&&!/^[a-zA-Z]:\//.test(m))return null;if(v.startsWith("file:")?g=(h=function(e){try{let t=new URL(e);if("file:"!==t.protocol)return null;let n=r(t.pathname);if(t.hostname)return`//${t.hostname}${n.startsWith("/")?n:`/${n}`}`;if(/^\/[a-zA-Z]:\//.test(n))return n.slice(1);return n}catch{return null}}(m))?"absolute":null:/^[a-zA-Z]:\//.test(m)||m.startsWith("/")?(h=m,g="absolute"):t&&!(m.startsWith("#")||m.startsWith("?"))&&(m.startsWith("./")||m.startsWith("../")||m.includes("/")||/(^|\/)\.?[^/]+\.[^/.]+$/.test(m))&&(h=`${i(t).replace(/\/+$/,"")}/${m}`,g="relative"),!h)return null;let b=o(h).replace(/:\d+(?::\d+)?$/,"");return"relative"===g&&n&&(s=o(b).replace(/\/+$/,""),l=o(n).replace(/\/+$/,""),c=(d=/^[a-zA-Z]:\//.test(s)||/^[a-zA-Z]:\//.test(l))?s.toLowerCase():s,!(c===(u=d?l.toLowerCase():l)||c.startsWith(`${u}/`)))?null:b}function s(e,t){let n;if(!e)return null;let r=/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith("\\\\")||void 0!==t&&(/^[a-zA-Z]:[\\/]/.test(t)||t.startsWith("\\\\")),i=e=>r?e.replace(/\\/g,"/"):e,a=i(e),s=t?i(t).replace(/\/+$/,""):void 0,l=/^[a-zA-Z]:\//.test(a),d=a.startsWith("//");if(l||d)n=a;else if(a.startsWith("/")){let e=s?.match(/^([a-zA-Z]:)(?:\/|$)/)?.[1]??s?.match(/^(\/\/[^/]+\/[^/]+)(?:\/|$)/)?.[1];n=e?`${e}${a}`:a}else{if(!s)return null;n=`${s}/${a}`}return o(n)}n.d(t,{V:()=>a,X:()=>s})},20985:(e,t,n)=>{"use strict";n.d(t,{f:()=>o});var r=n(95155),i=n(12115);function o({open:e,children:t,style:n,up:a=!1}){let[s,l]=(0,i.useState)(e),[d,c]=(0,i.useState)(e);return((0,i.useEffect)(()=>{let t,n;return e?(l(!0),c(!1),t=window.requestAnimationFrame(()=>{t=window.requestAnimationFrame(()=>c(!0))})):(c(!1),n=setTimeout(()=>l(!1),140)),()=>{void 0!==t&&window.cancelAnimationFrame(t),n&&clearTimeout(n)}},[e]),s)?(0,r.jsx)("div",{style:{...n,opacity:+!!d,transform:d?"translateY(0) scale(1)":a?"translateY(8px) scale(0.96)":"translateY(-8px) scale(0.96)",transformOrigin:a?"bottom center":"top center",transition:"opacity 140ms ease, transform 140ms ease",pointerEvents:e?"auto":"none"},children:t}):null}},22271:(e,t,n)=>{"use strict";function r(e){let t=e.trim();if(!t.startsWith("file://"))return t;try{let e=new URL(t),n=decodeURIComponent(e.pathname);return/^\/[a-zA-Z]:[\\/]/.test(n)?n=n.slice(1):e.host&&"localhost"!==e.host&&(n=`//${e.host}${n}`),n}catch{let e=t.replace(/^file:\/\/(localhost)?/,"");try{e=decodeURIComponent(e)}catch{}return/^\/[a-zA-Z]:[\\/]/.test(e)&&(e=e.slice(1)),e}}n.d(t,{Gm:()=>o,ph:()=>a});let i=["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 o(e,t){if(!e)return[];let n=[],o=Array.from(e.files??[]);for(let e of o){let t=e.path;"string"==typeof t&&t.trim()&&n.push(t.trim())}if(n.length>0)return Array.from(new Set(n));for(let t of Array.from(e.items??[]))if("file"===t.kind){let e=t.getAsFile(),r=e?.path;"string"==typeof r&&r.trim()&&n.push(r.trim())}if(n.length>0)return Array.from(new Set(n));for(let t of i)try{let i=e.getData(t);if(i){let e=function(e){if(!e)return[];let t=e.split(/\r?\n/),n=[];for(let e of t){let t=e.trim();!(!t||t.startsWith("#"))&&"copy"!==t&&"cut"!==t&&(t.startsWith("file://")?n.push(r(t)):(t.startsWith("/")||/^[a-zA-Z]:[\\/]/.test(t))&&n.push(t))}return n}(i);e.length>0&&n.push(...e)}}catch{}if(n.length>0)return Array.from(new Set(n));try{let t=e.getData("text/plain")||e.getData("text");if(t){let e=t.split(/\r?\n/).map(e=>e.trim()).filter(Boolean),i=e.filter(e=>e.startsWith("file://"));if(i.length>0&&i.length===e.length)for(let e of i)n.push(r(e))}}catch{}if(n.length>0)return Array.from(new Set(n));if(t?.fallbackToFileName&&o.length>0)for(let e of o)e.name&&n.push(e.name);return Array.from(new Set(n))}function a(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):""}},23584:(e,t,n)=>{"use strict";n.d(t,{NN:()=>l,Oi:()=>c,Uh:()=>S,WH:()=>d,fI:()=>a,lg:()=>o,mi:()=>i});var r=n(12115);let i=820,o=820,a=2e3,s="pi-chat-content-width",l=14,d=12,c=24,u="pi-chat-content-font-size",p={width:820,fontSize:14},h=null,g=new Set;function x(e){let t=Number(e);return Number.isFinite(t)?Math.max(o,Math.min(a,Math.round(t))):i}function f(e){let t=Number(e??l);return Number.isFinite(t)?Math.max(d,Math.min(c,Math.round(t))):l}function m(e){try{return window.localStorage.getItem(e)}catch{return null}}function v({width:e,fontSize:t}){"u">typeof document&&(document.documentElement.style.setProperty("--chat-content-max-width",`${e}px`),document.documentElement.style.setProperty("--chat-content-font-size",`${t}px`))}function b(){return h||v(h={width:x(m(s)),fontSize:f(m(u))}),h}function y(e){return g.add(e),()=>{g.delete(e)}}function k(e,t){let n="width"===e?x(t):f(t);v(h={...b(),[e]:n});try{window.localStorage.setItem("width"===e?s:u,String(n))}catch{}g.forEach(e=>e())}let w=e=>k("width",e),j=e=>k("fontSize",e);function S(){return{...(0,r.useSyncExternalStore)(y,b,()=>p),setWidth:w,setFontSize:j}}},23657:(e,t,n)=>{"use strict";function r(){return"u">typeof crypto&&"function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}n.d(t,{S:()=>r})},26365:(e,t,n)=>{Promise.resolve().then(n.bind(n,97290)),Promise.resolve().then(n.bind(n,39247))},28999:(e,t,n)=>{"use strict";function r(e){return/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith("\\\\")?e.replace(/\\/g,"/"):e}function i(e){return r(e).split("/").filter(Boolean).map(encodeURIComponent).join("/")}function o(e){let t=r(e).replace(/\/+$/,"");return t.split("/").pop()??t}function a(e){let t=r(e).replace(/\/+$/,""),n=t.lastIndexOf("/");return n<0?"":0===n?"/":2===n&&/^[a-zA-Z]:\//.test(t)?t.slice(0,3):t.slice(0,n)}function s(e,t){if(!t)return e;let n=r(e),i=r(t).replace(/\/$/,"");return n.startsWith(i+"/")?n.slice(i.length+1):e}function l(e,t){return`${r(e).replace(/\/$/,"")}/${t}`}n.d(t,{A0:()=>r,HG:()=>i,WP:()=>o,e_:()=>l,gX:()=>a,qP:()=>s})},29608:(e,t,n)=>{"use strict";n.d(t,{K:()=>u});var r=n(95155),i=n(12115),o=n(47650),a=n(39247),s=n(22271);async function l(e){let t=e?`?path=${encodeURIComponent(e)}`:"",n=await fetch(`/api/cwd/browse${t}`),r=await n.json();if(!n.ok||r.error)throw Error(r.error??`HTTP ${n.status}`);return r}function d(){return(0,r.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.3","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M1.5 3h4l1.5 2h7.5v7.5h-13z"})})}function c(){return(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("rect",{x:"2",y:"3",width:"12",height:"10",rx:"1.5"}),(0,r.jsx)("path",{d:"M2 9h12"}),(0,r.jsx)("circle",{cx:"11.5",cy:"11",r:"0.6",fill:"currentColor",stroke:"none"})]})}function u({onCancel:e,onSelect:t,busy:n=!1,error:p}){let{t:h}=(0,a.s)(),[g,x]=(0,i.useState)(null),[f,m]=(0,i.useState)(""),[v,b]=(0,i.useState)(null),[y,k]=(0,i.useState)(""),[w,j]=(0,i.useState)([]),[S,C]=(0,i.useState)(null),[T,M]=(0,i.useState)(null),[I,L]=(0,i.useState)(!0),R=(0,i.useCallback)(async e=>{L(!0),M(null);try{let t=await l(e),n=t.path??e??"/";m(n),b(t.parentPath??null),k(n),j(t.directories??[]),C(t.drives??null)}catch(e){M(e instanceof Error?e.message:String(e))}finally{L(!1)}},[]);(0,i.useEffect)(()=>{x(document.body),R()},[R]);let E=y.trim()!==f,z=!!f&&!E&&!n,W=!!v||/^[a-zA-Z]:[\\/]?$/.test(f);return g?(0,o.createPortal)((0,r.jsx)("div",{className:"directory-picker-backdrop",role:"dialog","aria-modal":"true","aria-label":h("directoryPicker.selectDirectory"),onClick:t=>{t.target!==t.currentTarget||n||e()},onKeyDown:t=>{"Escape"!==t.key||n||e()},style:{position:"fixed",inset:0,zIndex:1e3,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.35)"},children:(0,r.jsxs)("div",{className:"directory-picker-panel",style:{width:520,maxWidth:"calc(100vw - 16px)",height:"min(620px, calc(100dvh - 16px))",maxHeight:"calc(100dvh - 16px)",display:"flex",flexDirection:"column",overflow:"hidden",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 8px 32px rgba(0,0,0,0.18)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0,padding:"12px 18px",borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)("div",{style:{minWidth:0,flex:1},children:(0,r.jsx)("div",{style:{color:"var(--text)",fontWeight:700,fontSize:15},children:h("directoryPicker.selectDirectory")})}),(0,r.jsx)("button",{type:"button",onClick:e,disabled:n,title:h("i18n.close"),"aria-label":h("i18n.close"),style:{padding:"2px 6px",border:0,background:"none",color:"var(--text-muted)",fontSize:20,lineHeight:1,cursor:n?"default":"pointer",opacity:n?.5:1},children:"\xd7"})]}),(0,r.jsxs)("form",{onSubmit:e=>{e.preventDefault();let t=y.trim();t&&R(t)},style:{display:"flex",alignItems:"center",gap:8,flexShrink:0,padding:"10px 14px",borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)("button",{className:"directory-picker-back",type:"button",onClick:()=>void R(v??void 0),disabled:I||!W,title:h("directoryPicker.goToParent"),"aria-label":h("directoryPicker.goToParent"),style:{width:36,height:36,padding:0,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-hover)",color:"var(--text-muted)",cursor:W?"pointer":"default",opacity:W?1:.45},children:(0,r.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"m18 15-6-6-6 6"})})}),(0,r.jsx)("label",{htmlFor:"directory-path",style:{position:"absolute",width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",border:0},children:h("directoryPicker.directoryPath")}),(0,r.jsx)("input",{className:"directory-picker-path",id:"directory-path",type:"text",value:y,placeholder:"/path/to/project or ~/project",autoFocus:!0,autoComplete:"off",spellCheck:!1,onChange:e=>{k(e.target.value),M(null)},onPaste:e=>{let t=(0,s.Gm)(e.clipboardData);t.length>0&&(e.preventDefault(),k(t[0]),M(null))},style:{minWidth:0,flex:1,height:36,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,outline:"none",background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:12}}),(0,r.jsx)("button",{className:"directory-picker-action",type:"submit",disabled:I||!y.trim(),title:h("directoryPicker.goToDirectory"),style:{minWidth:58,height:36,padding:"0 12px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-hover)",color:"var(--text-muted)",cursor:I||!y.trim()?"default":"pointer",opacity:I||!y.trim()?.6:1},children:h("directoryPicker.go")})]}),(0,r.jsxs)("div",{className:"directory-picker-list",style:{flex:1,minHeight:0,overflow:"auto",padding:"8px 10px"},children:[I?(0,r.jsx)("div",{style:{padding:8,color:"var(--text-dim)",fontSize:11},children:h("directoryPicker.loadingDirectories")}):null!==S?(0,r.jsx)(r.Fragment,{children:S.length>0?S.map(e=>(0,r.jsxs)("button",{className:"directory-picker-entry",type:"button",onClick:()=>void R(e.path),title:e.path,style:{width:"100%",minHeight:34,display:"flex",alignItems:"center",gap:7,padding:"6px 8px",border:0,borderRadius:5,background:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontFamily:"var(--font-mono)",fontSize:11},children:[(0,r.jsx)(c,{}),(0,r.jsx)("span",{children:e.name})]},e.path)):(0,r.jsx)("div",{style:{padding:8,color:"var(--text-dim)",fontSize:11},children:h("directoryPicker.noDrives")})}):w.length>0?w.map(e=>(0,r.jsxs)("button",{className:"directory-picker-entry",type:"button",onClick:()=>void R(e.path),title:e.path,style:{width:"100%",minHeight:30,display:"flex",alignItems:"center",gap:7,padding:"5px 8px",border:0,borderRadius:5,background:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontFamily:"var(--font-mono)",fontSize:11},children:[(0,r.jsx)(d,{}),(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name})]},e.path)):(0,r.jsx)("div",{style:{padding:8,color:"var(--text-dim)",fontSize:11},children:h("directoryPicker.noSubdirectories")}),(T||p)&&(0,r.jsx)("div",{style:{padding:"8px",color:"#dc2626",fontSize:11},children:T??p})]}),(0,r.jsxs)("div",{className:"directory-picker-footer",style:{display:"flex",justifyContent:"flex-end",alignItems:"center",gap:10,flexShrink:0,padding:"10px 18px",borderTop:"1px solid var(--border)"},children:[(0,r.jsx)("button",{className:"directory-picker-action",type:"button",onClick:e,disabled:n,style:{padding:"6px 14px",border:"1px solid var(--border)",borderRadius:6,background:"none",color:"var(--text-muted)",cursor:n?"default":"pointer",fontSize:13},children:h("i18n.cancel")}),(0,r.jsx)("button",{className:"directory-picker-action",type:"button",onClick:()=>t(f),disabled:!z,title:h(E?"directoryPicker.openBeforeSelecting":"directoryPicker.selectCurrentDirectory"),style:{padding:"6px 16px",border:0,borderRadius:6,background:"var(--accent)",color:"#fff",fontSize:13,fontWeight:600,opacity:z?1:.6,cursor:z?"pointer":"default"},children:h(n?"i18n.checking":"directoryPicker.selectThisFolder")})]})]})}),g):null}},30527:(e,t,n)=>{"use strict";n.d(t,{I3:()=>d,sj:()=>a});var r=n(95155);let i="/icons/catppuccin";function o({name:e,size:t=14}){let n={width:t,height:t,"--catppuccin-icon-light":`url(${i}/latte/${e}.svg)`,"--catppuccin-icon-dark":`url(${i}/mocha/${e}.svg)`};return(0,r.jsx)("span",{"aria-hidden":"true",className:"catppuccin-file-icon",style:n})}function a({size:e=14,open:t=!1}){return(0,r.jsx)(o,{name:t?"_folder_open":"_folder",size:e})}function s({size:e=14}){return(0,r.jsx)(o,{name:"_file",size:e})}let l={ts:"typescript",tsx:"typescript-react",js:"javascript",mjs:"javascript",cjs:"javascript",jsx:"javascript-react",py:"python",json:"json",jsonl:"json",css:"css",less:"css",scss:"sass",html:"html",htm:"html",md:"markdown",mdx:"markdown",yaml:"yaml",yml:"yaml",toml:"toml",sh:"bash",bash:"bash",zsh:"bash",fish:"bash",rs:"rust",go:"go",sql:"database",graphql:"graphql",gql:"graphql",tf:"terraform",hcl:"terraform",docx:"ms-word",pdf:"pdf",lock:"lock"};function d(e,t=14){let n=e.toLowerCase(),i="dockerfile"===n||n.startsWith("dockerfile.")?"docker":".env"===n||n.startsWith(".env.")?"env":[".gitignore",".gitattributes",".gitmodules"].includes(n)?"git":"package-lock.json"===n?"npm-lock":"bun.lock"===n?"bun-lock":["next.config.js","next.config.mjs","next.config.cjs","next.config.ts"].includes(n)?"next":[".eslintrc",".eslintrc.js",".eslintrc.json",".eslintrc.yml","eslint.config.mjs","eslint.config.js"].includes(n)?"eslint":["yarn.lock","pnpm-lock.yaml","cargo.lock"].includes(n)?"lock":n.endsWith(".config.ts")||n.endsWith(".config.js")||n.endsWith(".config.mjs")||n.endsWith(".config.cjs")?"config":void 0;if(i)return(0,r.jsx)(o,{name:i,size:t});let a=l[n.split(".").pop()??""];return a?(0,r.jsx)(o,{name:a,size:t}):(0,r.jsx)(s,{size:t})}},31590:(e,t,n)=>{"use strict";n.d(t,{a:()=>l});var r=n(12115);let i="(max-width: 640px)";function o(e){if(!window.matchMedia)return()=>{};let t=window.matchMedia(i);return t.addEventListener("change",e),()=>t.removeEventListener("change",e)}function a(){return!!window.matchMedia&&window.matchMedia(i).matches}function s(){return!1}function l(){return(0,r.useSyncExternalStore)(o,a,s)}},32383:(e,t,n)=>{"use strict";n.d(t,{$J:()=>o,RE:()=>i});class r extends Error{constructor(e,t,n,r){super(e),this.status=t,this.code=n,this.accepted=r,this.name="AgentCommandError"}}function i(e){return e instanceof r&&"prompt_rejected"===e.code&&!1===e.accepted}async function o(e,t){let n=await fetch(`/api/agent/${encodeURIComponent(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),i=await n.json().catch(()=>({}));if(!n.ok||i.error)throw new r(i.error??`HTTP ${n.status}`,n.status,i.code,i.accepted);return i.data}},32782:(e,t,n)=>{"use strict";n.d(t,{G:()=>i});var r=n(12115);function i(){let[e,t]=(0,r.useState)(()=>{let e=localStorage.getItem("pi-sound-enabled");return null===e||"true"===e}),n=(0,r.useRef)(e);(0,r.useEffect)(()=>{n.current=e},[e]);let i=(0,r.useRef)(null),o=(0,r.useCallback)(()=>{if(i.current&&"closed"!==i.current.state)return i.current;try{i.current=new AudioContext}catch{return null}return i.current},[]),a=(0,r.useCallback)((e=!1)=>{if(!e&&!n.current)return;let t=o();t&&"suspended"===t.state&&t.resume().catch(()=>{})},[o]);return{soundEnabled:e,onSoundToggle:(0,r.useCallback)(()=>{let e=!n.current;e&&a(!0),n.current=e,localStorage.setItem("pi-sound-enabled",String(e)),t(e)},[a]),playDoneSound:(0,r.useCallback)(()=>{if(!n.current)return;let e=o();if(!e)return;let t=()=>{try{let t;t=e.currentTime,[523.25,659.25].forEach((n,r)=>{let i=e.createOscillator(),o=e.createGain();i.connect(o),o.connect(e.destination),i.type="sine",i.frequency.value=n;let a=t+.18*r;o.gain.setValueAtTime(0,a),o.gain.linearRampToValueAtTime(.18,a+.02),o.gain.exponentialRampToValueAtTime(.001,a+.45),i.start(a),i.stop(a+.45)})}catch{}};"suspended"===e.state?e.resume().then(t).catch(()=>{}):t()},[o]),unlockAudio:a,soundEnabledRef:n}}},34229:(e,t,n)=>{"use strict";n.d(t,{E:()=>a,I:()=>o});var r=n(12115);let i=(0,r.createContext)("default"),o=i.Provider;function a(){return(0,r.useContext)(i)}},36268:(e,t,n)=>{"use strict";n.d(t,{HH:()=>s,Y0:()=>r,aO:()=>a});let r="todo",i=["pending","in_progress","completed"];function o(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function a(e){if(!o(e)||!Array.isArray(e.todos))return null;let t=[];for(let r of e.todos){var n;o(r)&&"number"==typeof r.id&&Number.isFinite(r.id)&&"string"==typeof r.content&&0!==r.content.length&&"string"==typeof(n=r.status)&&i.includes(n)&&t.push({id:r.id,content:r.content,status:r.status})}let r=t.reduce((e,t)=>Math.max(e,t.id),0);return{todos:t,nextId:"number"==typeof e.nextId&&e.nextId>r?e.nextId:r+1}}function s(e){let t=e.filter(e=>"completed"===e.status).length;return`${t}/${e.length}`}},39247:(e,t,n)=>{"use strict";n.d(t,{I18nProvider:()=>c,s:()=>u});var r=n(95155),i=n(12115);let o=new Map;function a(e){if(!e.id.trim())throw Error("Locale id must not be empty");if(o.has(e.id))throw Error(`Locale already registered: ${e.id}`);o.set(e.id,e)}function s(){return[...o.keys()]}a({id:"en",label:"English",messages:{"common.ok":"OK","common.language":"Language","common.models":"Models","common.skills":"Skills","common.plugins":"Plugins","common.settings":"Settings","common.agents":"Agents","appUpdate.releaseNotes":"Pi Web v{version} is available. View release notes","sidebar.hide":"Hide sidebar","sidebar.show":"Show sidebar","theme.light":"Light mode (click for dark)","theme.dark":"Dark mode (click for system)","theme.auto":"System theme (click for light)","history.full":"History","history.unsaved":"History is available after the session is saved","history.label":"History","nav.stats":"Stats","title.generating":"Generating...","title.updated":"Title updated","title.failed":"Generation failed","title.generate":"Generate title","title.unsaved":"Title generation is available after the session is saved","title.noMessages":"Send a message before naming this session","title.generateSession":"Generate a session title","system.prompt":"System prompt","system.empty":"System prompt is empty (tools are disabled)","system.load":"System prompt has not loaded yet","system.loading":"Loading system prompt…","system.label":"System","session.info":"Session info","session.task":"Task","session.name":"Name","session.file":"Session File","session.inMemory":"In-memory","session.id":"ID","session.user":"User","session.assistant":"Assistant","session.toolCalls":"Tool Calls","session.toolResults":"Tool Results","session.total":"Total","session.input":"Input","session.output":"Output","session.cacheRead":"Cache Read","session.cacheWrite":"Cache Write","session.cost":"Cost","session.context":"Context","session.cacheHitRate":"Avg cache hit rate","session.copy":"Copy {value}","session.copied":"Copied","session.title":"Session info","session.load":"Send a message or run /session to load session info","session.infoSection":"Session Info","session.projectSection":"Project Info","session.messages":"Messages","session.tokens":"Tokens","session.totalActive":"Active Time","session.copyFile":"Copy file path","session.copyId":"Copy session ID","session.projectDir":"Project Dir","session.gitBranch":"Git Branch","session.gitWorktree":"Worktree","session.copyProjectDir":"Copy project directory","session.copyGitBranch":"Copy git branch","session.copyGitWorktree":"Copy worktree path","workspace.opening":"Opening workspace...","workspace.unable":"Unable to open workspace","workspace.selectSession":"Select a session from the sidebar","workspace.getStarted":"Get Started","workspace.selectProject":"Select a project directory from the sidebar","workspace.addModels":"Add models via the Models button at the bottom","workspace.stepProject":"Select a project directory from the sidebar","workspace.stepModels":"Add models via the Models button at the bottom","files.hidePanel":"Hide file panel","files.showPanel":"Show file panel","files.noneOpen":"No file open","layout.resizeSidebar":"Resize sidebar","layout.resizeFilePanel":"Resize file panel","layout.resizeHint":"Drag to resize. Double-click or press Enter to reset.","sidebar.new":"New","sidebar.newSessionTitle":"New session in {path}","sidebar.refresh":"Refresh","sidebar.selectProject":"Select project…","sidebar.filterProjects":"Filter projects…","sidebar.noMatchingProjects":"No matching projects","sidebar.useDefaultDirectory":"Use default directory","sidebar.customPath":"Custom path…","directoryPicker.selectDirectory":"Select directory","directoryPicker.goToParent":"Go to parent directory","directoryPicker.directoryPath":"Directory path","directoryPicker.goToDirectory":"Go to directory","directoryPicker.go":"Go","directoryPicker.loadingDirectories":"Loading directories…","directoryPicker.noSubdirectories":"No subdirectories","directoryPicker.openBeforeSelecting":"Open this path before selecting it","directoryPicker.selectCurrentDirectory":"Select current directory","directoryPicker.selectThisFolder":"Select this folder","directoryPicker.noDrives":"No drives found","sidebar.checking":"Checking…","sidebar.open":"Open","sidebar.cancel":"Cancel","sidebar.worktrees":"Worktrees...","sidebar.filterWorktrees":"Filter worktrees…","sidebar.noMatchingWorktrees":"No matching worktrees","sidebar.switchWorktree":"Switch worktree","sidebar.switchWorktreeTitle":"Switch worktree: {path}","sidebar.main":"main","sidebar.forceRemoveCheckout":"Uncommitted changes. Force remove checkout?","sidebar.force":"Force","sidebar.createWorktreeTitle":"Create a worktree checkout for a branch","sidebar.newWorktree":"New worktree…","sidebar.branchName":"branch name","sidebar.creating":"Creating…","sidebar.create":"Create","sidebar.uploadFilesTitle":"Upload files to project root","sidebar.uploadFiles":"Upload files","sidebar.refreshExplorer":"Refresh explorer","sidebar.changedFiles":"{count} changed files","sidebar.loading":"Loading...","sidebar.noSessions":"No sessions found","sidebar.agentRunning":"Agent running…","sidebar.newActivity":"New activity","sidebar.newSessionActivity":"New session activity","sidebar.deleteSession":"Delete {title}? This cannot be undone.","sidebar.rename":"Rename","sidebar.pin":"Pin to top","sidebar.unpin":"Unpin","sidebar.pinTask":"Pin task","sidebar.unpinTask":"Unpin task","sidebar.pinned":"Pinned","sidebar.taskRunning":"{count} session(s) running","sidebar.moreActions":"More actions","sidebar.delete":"Delete","sidebar.expandForks":"Expand forks","sidebar.collapseForks":"Collapse forks","sidebar.taskOpenBoard":"Open board","sidebar.messagesCount":"{count} msgs","sidebar.views":"Views","sidebar.sessionTab":"Sessions","sidebar.boardsTab":"Boards","sidebar.filesTab":"Files","sidebar.tasks":"Tasks","sidebar.tempSessions":"Chat","sidebar.timeToday":"Today","sidebar.timeYesterday":"Yesterday","sidebar.timeThisWeek":"This week","sidebar.timeThisMonth":"Last 30 days","sidebar.timeOlder":"Older","sidebar.newTask":"New task…","sidebar.taskName":"Task name","sidebar.newTaskSession":"New task session","sidebar.loadMoreSessions":"Load more ({count})","sidebar.resizeTasks":"Drag to resize the tasks area","sidebar.deleteTask":"Delete task","sidebar.deleteTaskConfirm":'Delete task "{name}" and its {count} sessions? This cannot be undone.',"boards.system":"System","boards.title":"Boards","boards.dragToAdd":"Drag sessions from the sidebar to add","boards.dropToAdd":"Drop to add to board","boards.loadingSession":"Loading session…","boards.sessionMissing":"Session no longer exists","boards.collapse":"Collapse","boards.workbenchLimit":"Only one workbench can be expanded at a time","boards.create":"Create","boards.running":"Running","boards.runningDesc":"Auto-collects all running sessions across projects","boards.project":"Project","boards.empty":"No boards yet — create one","boards.new":"New board…","boards.rename":"Rename","boards.delete":"Delete","boards.deleting":"Deleting…","boards.deleteConfirmTitle":"Delete board?","boards.deleteConfirm":"This deletes the board and its nodes/edges. Sessions themselves are not touched.","boards.cancel":"Cancel","boards.namePlaceholder":"Board name","boards.loadingCanvas":"Loading canvas…","boards.runningEmpty":"No sessions running right now — running sessions appear here automatically.","boards.emptyCanvas":"Empty board — add sessions from the sidebar ({count} nodes)","boards.back":"Back","boards.switchBoard":"Switch board","boards.addSession":"Add session","boards.connect":"Connect","boards.connectDesc":"Connect two cards with a line (click source, then target)","boards.autoLayout":"Auto layout","boards.autoLayoutDesc":"Auto layout is not available yet","boards.cleanup":"Clean up stale","boards.clearDesc":"Clear the canvas (delete all cards/notes/edges)","boards.clearConfirm":"Clear the entire canvas? This cannot be undone.","boards.clearTaskBoardDesc":"Clear the canvas (non-session elements only; session cards stay)","boards.clearTaskConfirm":"Clear the canvas? Notes/edges/text will be removed; session cards stay (session data untouched).","boards.conflictReload":"Canvas was modified by another window/device — loaded the latest version (your unsaved changes were dropped)","boards.reloadCanvas":"Reload canvas (refresh everything from the server)","boards.scrimTitle":"Adjust canvas frost","boards.scrimAlpha":"Opacity","boards.scrimBlur":"Frost strength","boards.noSessions":"No sessions","boards.newSession":"New session","boards.draftPlaceholder":"New session — type a message to start…","boards.searchPlaceholder":"Search cards, notes, or chat messages…","boards.searchNoResults":"No matching items","boards.searchSession":"Session","boards.searchNote":"Note","boards.searchGroupNodes":"Node hits","boards.searchGroupBody":"Chat hits","boards.searchBodyTag":"Chat","search.placeholder":"Search sessions…","search.indexing":"Indexing…","search.noResults":"No matching results","search.empty":"Type a keyword to search session titles or messages","search.title":"Title","search.taskCards":"Task Cards","search.sessions":"Sessions","sidebar.worktreePath":"Worktree: {path}","sidebar.removeWorktreeTitle":"Remove worktree checkout {path}; the branch is kept","files.modified":"Modified","files.added":"Added","files.deleted":"Deleted","files.renamed":"Renamed","files.untracked":"Untracked","files.conflict":"Conflict","files.newlyUploaded":"Newly uploaded","files.containsChangedFiles":"Contains changed files","files.insertPath":"Insert path into chat","files.mention":"mention","files.download":"Download file","files.dismissError":"Dismiss error","files.addUploadedFile":"Add uploaded file to chat","files.addAllUploadedFiles":"Add all uploaded files to chat","files.dismissUploadResults":"Dismiss upload results","files.loading":"Loading files...","files.searchPlaceholder":"Search files…","files.noFiles":"No files found","files.explorer":"Explorer","files.changedCount":"{count} files","files.changeStats":"{count} changed files, {additions} lines added, {deletions} lines deleted","files.conflictSummary":"{count} file{countSuffix} already exist: {files}","files.cannotReplace":"Cannot replace: {files}","files.replace":"Replace","files.skipExisting":"Skip existing","files.cancel":"Cancel","files.checking":"Checking files","files.uploading":"Uploading, {progress}%","chat.loadingSession":"Loading session...","chat.runningTool":"Running tool...","chat.generatingToolInput":"Generating parameters...","chat.runningNamedTool":"Running {name}...","chat.runningTools":"Running {names}...","chat.runningToolsMore":"Running {names} (+{count})...","chat.waitingModel":"Waiting for model...","chat.runningCommand":"Running command...","chat.commandBusy":"Running {name}…","chat.thinking":"Thinking...","chat.processDetails":"Process details","chat.message":"message","chat.messages":"messages","chat.toolCall":"tool call","chat.toolCalls":"tool calls","chat.collapseProcess":"Collapse process details","chat.expandProcess":"Expand process details","chat.filesWritten":"Files changed","chat.openWrittenFile":"Open {name}","chat.loadEarlier":"Scroll up to load earlier messages","chat.extensionRequest":"extension request","chat.cancel":"Cancel","chat.confirm":"Confirm","chat.submit":"Submit","chat.extensionInput":"Extension terminal input","chat.extensionPanel":"Extension panel","chat.extensionWidgets":"Extension widgets","chat.extensionWidgetAbove":"Above editor widget","chat.extensionWidgetBelow":"Below editor widget","chat.extensionWidgetLine":"{count} line","chat.extensionWidgetLines":"{count} lines","chat.close":"Close","chat.extensionInspect":"inspect","chat.extensionNoDetail":"No details available (try refreshing and retrying)","chat.queued":"Queued \xb7 {count}","chat.recall":"Recall to input","chat.recallTitle":"Remove all queued messages and put them back into the input box for editing","chat.retrying":"Retrying ({attempt}/{max})…","chat.loadingCommands":"Loading commands...","chat.slashCommands":"Slash commands \xb7 {label}","chat.tabEnter":"Tab / Enter","chat.noCommands":"No extension, prompt, or skill commands found","chat.match":"1 match","chat.matches":"{count} matches","chat.command":"1 command","chat.commands":"{count} commands","chat.loadingFiles":"Loading files...","chat.files":"Files \xb7 {label}{hint}","chat.searching":"Searching…","chat.noMatchingFiles":"No matching files","chat.searchingAll":" \xb7 searching all files…","chat.indexTruncated":" \xb7 index truncated","chat.steerPlaceholder":"Steer now / queue follow-up...","chat.agentPlaceholder":"Agent is running…","chat.messagePlaceholder":"Message… Type / for commands, @ for files","chat.taskPlaceholder":"[{task}] - Message… Type / for commands, @ for files","chat.steer":"Steer","chat.followUp":"Follow-up","chat.send":"Send","chat.askSelection":"Ask about selected text","chat.askInCurrent":"Ask here","chat.askInNewChat":"Ask in new chat","chat.newQuoteChat":"New chat about selected text","chat.quoteIntro":"About this passage:","chat.quoteQuestion":"My question:","chat.quoteForkFailed":"Failed to create quoted chat","chat.quoteSelectionToggle":"Show an ask menu after selecting text","chat.sendQuestion":"Send question","chat.imageNotSupportedTitle":"The selected model does not support images","chat.imageNotSupportedBody":"Model {model} accepts text input only; attached images will not be sent. Switch to a vision-capable model or remove the attachments.","chat.attachImage":"Attach image","chat.previewImage":"Preview image","chat.filterModels":"Filter models…","chat.noMatchingModels":"No matching models","chat.showModelId":"Show IDs","chat.moreControls":"More controls","chat.collapseControls":"Collapse controls","chat.shell":"Shell","chat.outputLocal":"output stays local","chat.outputModel":"output sent to model","chat.noTools":"No tools","chat.readOnlyTools":"{count} read-only built-in tools","chat.builtInTools":"{count} built-in tools","chat.allBuiltInTools":"All built-in tools","chat.changeReasoning":"Change reasoning level: {level}","chat.changeReasoningLabel":"Change reasoning level","chat.changeToolPreset":"Change tool preset","chat.stopCompaction":"Stop compaction","chat.compactContext":"Compact context","chat.compacting":"Compacting…","chat.compact":"Compact","chat.scrollToLatest":"Back to latest","bg.title":"Wallpaper","bg.choose":"Choose image…","bg.replace":"Replace image…","bg.remove":"Remove wallpaper","bg.hint":"Images are stored locally in your browser — never uploaded. Large images are auto-compressed to your screen size.","bg.repeat":"Tile horizontally","bg.fill":"Edge colour fill","bg.adjust":"Adjust horizontal position…","bg.adjustHint":"Drag left / right to reposition","bg.adjustDone":"Done","bg.reset":"Reset position","bg.bubbleOpacity":"Bubble opacity","bg.bubbleBlur":"Frost blur","bg.bubbleReset":"Reset bubbles","chat.stopAgent":"Stop agent","chat.stop":"Stop","chat.disableSound":"Disable completion sound","chat.enableSound":"Enable completion sound","chat.thinkingUseDefault":"Use pi default","chat.thinkingOff":"Reasoning off","chat.thinkingMinimal":"Minimal reasoning","chat.thinkingLow":"Low reasoning","chat.thinkingMedium":"Medium reasoning","chat.thinkingHigh":"High reasoning","chat.thinkingXhigh":"Extra-high reasoning","chat.thinkingMax":"Max reasoning","chat.builtIn":"Built-in","chat.extensions":"Extensions","chat.prompts":"Prompts","chat.skills":"Skills","chat.dormant":"dormant","chat.commandCompact":"Compress context, optionally with instructions","chat.commandReload":"Reload extensions, skills, prompts, and tools","chat.commandName":"Set the session display name","chat.commandSession":"Show session message, token, and cost stats","chat.commandCopy":"Copy the last assistant message","chat.compacted":"Compacted","chat.tokensSaved":"{saved} saved","settings.chatContentWidth":"Chat content width","settings.chatContentWidthDescription":"Set the maximum width of message content and the input box.","settings.chatContentFontSize":"Chat font size","settings.preferences":"Preferences","settings.title":"Settings","settings.general":"General","settings.appearance":"Appearance","settings.chat":"Chat","settings.quoteSelection":"Ask about selected text","settings.resetChatContentWidth":"Reset chat width","settings.resetChatContentFontSize":"Reset chat font size","settings.projectRequired":"Project required","settings.themeLight":"Light","settings.themeDark":"Dark","tools.title":"Tools enabled in the current session","tools.details":"Tool definition details","tools.load":"Tool definitions have not loaded yet","tools.loading":"Loading tool definitions…","tools.noTools":"No active tools","tools.description":"Description","tools.parameters":"Parameters","tools.parameterCount":"{count} parameters","tools.noParameters":"No parameters","tools.required":"Required","tools.optional":"Optional","tools.allowedValues":"Allowed","tools.defaultValue":"Default","tools.guidelines":"Prompt guidelines","tools.label":"Tools","agents.close":"Close","agents.builtInTitle":"Enable Pi Web built-in sub-agents","agents.builtInDescription":"Provides Pi Web's integrated Agent tools and disables a conflicting pi-subagents extension.","agents.reloadRequired":"Reload the current session to apply this change.","agents.reloadSession":"Reload session","agents.maxConcurrent":"Concurrent sub-agents","agents.maxConcurrentDescription":"Maximum prompts running at once per parent session.","agents.reloading":"Reloading...","agents.loading":"Loading sub-agents...","agents.new":"New sub-agent","agents.empty":"Select or create a sub-agent profile","agents.saveScope":"Save to","agents.name":"Sub-agent ID","agents.displayName":"Display name","agents.description":"Description","agents.prompt":"System instructions","agents.tools":"Tools","agents.resources":"Resources","agents.loadSkills":"Load skills","agents.loadExtensions":"Load extensions","agents.model":"Model override","agents.modelsLoading":"Loading models...","agents.modelUnavailable":"{model} (unavailable)","agents.thinking":"Thinking","agents.maxTurns":"Max turns","agents.inherit":"Parent default","agents.enable":"Enable sub-agent","agents.disable":"Disable sub-agent","agents.builtinPath":"Built-in profile","agents.inheritContext":"Inherit parent context","agents.background":"Run in background by default","agents.duplicate":"Duplicate","agents.copyName":"{name} copy","agents.delete":"Delete","agents.deleteConfirm":"Delete {name}?","agents.save":"Save","agents.saving":"Saving...","agents.scope.builtin":"built-in","agents.scope.global":"global","agents.scope.workspace":"workspace","agents.scope.project":"project","agents.overridden":"Overridden","i18n.close":"Close","i18n.copy":"Copy","i18n.pin":"Pin","i18n.pinTitle":"Pin this message (creates a draggable/resizable float)","i18n.copied":"Copied","i18n.cancel":"Cancel","i18n.save":"Save","i18n.saving":"Saving…","i18n.saved":"Saved","i18n.remove":"Remove","i18n.removing":"Removing…","i18n.delete":"Delete","i18n.loading":"Loading...","i18n.search":"Search","i18n.refresh":"Refresh","i18n.update":"Update","i18n.updating":"Updating...","i18n.check":"Check","i18n.checking":"Checking...","i18n.install":"Install","i18n.installing":"Installing...","i18n.noResults":"No results","i18n.searchProviders":"Search providers…","i18n.noProviders":"No providers match","i18n.newModel":"new model","i18n.addProvider":"Add provider","i18n.selectProviderModel":"Select a provider or model","i18n.visibleInPrompt":"Visible in model prompt — click to disable","i18n.hiddenFromPrompt":"Hidden from model prompt — click to enable","i18n.dormant":"Dormant","i18n.hiddenButInvocable":"Hidden from model, still manually invocable","i18n.skillSearchPlaceholder":"e.g. react, testing, deploy","i18n.searching":"Searching…","i18n.noSkills":"No skills found","i18n.checkUpdates":"Check updates","i18n.updates":"updates","i18n.noResolvedResources":"No resolved resources","i18n.enablePackage":"Enable package","i18n.disablePackage":"Disable package","i18n.filtered":"filtered","i18n.openSessionToReload":"Open a session to reload","i18n.notFound":"Not found","i18n.noPlugins":"No plugins configured","trust.resourcesNotLoaded":"Restricted mode","trust.trustProject":"Trust project","trust.trusting":"Trusting...","trust.cancel":"Cancel","trust.dialogTitle":"Trust this project?","trust.dialogBody":"Project resources can run local code. Trust only projects whose contents you know.","trust.skillsNotLoaded":"Project skills are not loaded because this project is not trusted.","trust.pluginsNotLoaded":"Project plugins are not loaded because this project is not trusted.","trust.projectScopeUnavailable":"Project installs are unavailable while project resources are not loaded.","i18n.creatingSession":"Creating new session…","i18n.creating":"Creating…","i18n.subscription":"Subscription","i18n.subscriptions":"Subscriptions","i18n.customEndpoint":"Custom endpoint format","i18n.noChanges":"No changes","i18n.branches":"Branches","i18n.noActiveSession":"No active session","i18n.noBranches":"This session has no branches","i18n.source":"Source","i18n.preview":"Preview","i18n.diff":"Diff","i18n.downloadFile":"Download file","i18n.liveSync":"Live sync active","i18n.notWatching":"Not watching","i18n.fileViewMode":"File view mode","i18n.compareHead":"Compare working tree with HEAD","i18n.mentionSelectedLines":"Mention selected lines","i18n.disableWrap":"Disable word wrap","i18n.enableWrap":"Enable word wrap","i18n.htmlPreview":"HTML preview","i18n.previewFile":"Preview {file}","i18n.invalidMermaid":"Invalid Mermaid diagram","i18n.renderingMermaid":"Rendering Mermaid diagram","i18n.previewAfterStreaming":"Preview available after streaming","i18n.showMermaidSource":"Show Mermaid source","i18n.previewMermaid":"Preview Mermaid diagram","i18n.openMermaidViewer":"Open diagram viewer","i18n.mermaidViewer":"Mermaid diagram viewer","i18n.mermaidDiagram":"Mermaid diagram","i18n.zoomOut":"Zoom out","i18n.zoomIn":"Zoom in","i18n.fitToWidth":"Fit to width","models.discoveryFetching":"Importing models…","models.discoveryFetch":"Import models…","models.discoveryFilterPlaceholder":"Filter {count} models…","models.discoveryFilter":"Filter upstream models","models.discoverySelectShown":"Select shown","models.discoveryNoMatches":"No matching models.","models.discoveryAdded":"added","models.discoveryShowing":"Showing first {shown} of {total}","models.discoveryFetched":"{count} models fetched","models.discoveryAddSelected":"Add selected","models.discoveryAddSelectedCount":"Add selected ({count})","models.catalogSource":"source: models.dev ↗","models.catalogFilling":"Filling details…","models.catalogFill":"Fill model details","models.catalogFilled":"{count} fields filled","models.catalogNoEmptyFields":"No empty fields to fill","models.catalogNoExactMatch":"No exact models.dev match","models.catalogPriceProvider":"Price matched Provider {provider}","models.catalogPriceBaseUrl":"Price matched Base URL to {provider}","models.catalogPriceConsensus":"Price agreed by {support}/{total} records","models.catalogPriceUnreliable":"No reliable price found","models.catalogUndo":"Undo","models.capabilities":"Capabilities","models.reasoning":"Reasoning / thinking","models.imageInput":"Image input","models.modelSpecs":"Model specifications","models.contextWindow":"Context window (tokens)","models.maxOutputTokens":"Max output tokens","models.costPerMillion":"Cost per million tokens","models.costInput":"Input","models.costOutput":"Output","models.costCacheRead":"Cache read","models.costCacheWrite":"Cache write","models.notProvided":"Not provided","models.editCosts":"Edit prices","models.finishEditingCosts":"Done","models.costAllRequired":"Enter a valid non-negative price; blank fields are saved as 0.","models.advancedSettings":"Advanced settings","models.providerDefaults":"Using provider defaults","models.headersSummary":"Headers: {count}","models.compatSummary":"Compatibility: {count}","models.thinkingSummary":"Thinking levels: {count}","models.apiOverride":"API override","models.headers":"Headers","models.headersHelp":"Added to this model's requests and overrides provider headers.","models.compatibility":"Compatibility","models.deepSeekThinkingCompat":"DeepSeek thinking compatibility","models.developerRole":"Use the developer role for the system prompt","models.thinkingLevelMap":"Thinking level map","models.clearAll":"Clear all","i18n.testingModel":"Testing model connection...","i18n.connected":"Connected","i18n.failed":"Failed","i18n.test":"Test","i18n.testConnection":"Test model connection","i18n.provider":"Provider","i18n.model":"Model","i18n.providerName":"Provider name","i18n.rename":"Rename","i18n.default":"Default","i18n.disabled":"Disabled","i18n.noResources":"No resources","i18n.unknown":"Unknown","i18n.installedVersion":"installed {version}","i18n.configuredVersion":"configured {version}","i18n.extensions":"Extensions","i18n.prompts":"Prompts","i18n.themes":"Themes","i18n.resourceCount":"{count} {label}","i18n.extensionShort":"ext","i18n.skillShort":"skills","i18n.promptShort":"prompts","i18n.themeShort":"themes","i18n.custom":"Custom","i18n.clearAll":"clear all","i18n.connectedSuccessfully":"Connected successfully.","i18n.notConnected":"not connected","i18n.configured":"configured","i18n.notConfigured":"not configured","i18n.openingBrowser":"Opening browser…","i18n.submit":"Submit","i18n.login":"Login","i18n.relogin":"Re-login","i18n.disconnect":"Disconnect","i18n.networkError":"Network error","i18n.continuing":"Continuing…","i18n.skills":"Skills","i18n.plugins":"Plugins","i18n.addSkill":"Add skill","i18n.addPlugin":"Add plugin","i18n.selectSkill":"Select a skill","i18n.selectPackage":"Select a package","i18n.updateAvailable":"Update available","i18n.upToDate":"Up to date","i18n.automaticChecksUnavailable":"Automatic checks unavailable","i18n.checkFailed":"Check failed","i18n.installed":"Installed","i18n.status":"Status","i18n.version":"Version","i18n.package":"Package","i18n.resources":"Resources","i18n.installedPath":"Installed path","i18n.cwd":"CWD","i18n.resolvedResources":"Resolved Resources","i18n.reloadSession":"Reload session","i18n.reloading":"Reloading...","i18n.packageRemoved":"Package removed.","i18n.packageInstalled":"Package installed.","i18n.packageUpdated":"Package updated.","i18n.packageDisabled":"Package disabled.","i18n.packageEnabled":"Package enabled.","i18n.sessionReloaded":"Session reloaded.","i18n.thinking":"Thinking","i18n.largeMessageReveal":"Message content is very large ({size}). Click to view as plain text — markdown rendering is disabled to keep the page responsive.","i18n.loadingThinking":"Loading thinking...","i18n.copyMessage":"Copy message","i18n.editFromHere":"Edit from here","i18n.editFromHereTitle":"Edit from here — branches within this session","i18n.newSession":"New session","i18n.newSessionTitle":"New session — creates an independent copy from here","i18n.estimatedTokens":"Estimated token count while streaming","i18n.noOutput":"(no output)","i18n.noSummary":"(no summary)","i18n.conversationCompacted":"Conversation compacted","i18n.compactionDescription":"The conversation history before this point was compacted into the following summary:","i18n.fileContext":"File context: {details}","i18n.readFiles":"Read files","i18n.modifiedFiles":"Modified files","i18n.hiddenExtensionMessage":"hidden extension message","i18n.noMessage":"(no message)","i18n.showExtensionMessage":"Show extension message","i18n.collapse":"Collapse","i18n.expand":"Expand","i18n.hideDetails":"Hide details","i18n.showDetails":"Show details","i18n.thinkingUnavailable":"Thinking content unavailable","i18n.before":"Before","i18n.after":"After","i18n.sessionComplete":"Session complete","i18n.taskFinished":"Task finished.","i18n.attentionNeeded":"Pi needs your attention","i18n.extensionInputNeeded":"An extension is waiting for your input.","todo.title":"Tasks","todo.completed":"completed","todo.empty":"No active tasks. Ask the agent to add some!","notice.title":"Notifications","notice.empty":"No notifications","notice.expand":"Expand details","notice.collapse":"Collapse","notice.remove":"Remove notification","notice.clearAll":"Clear all","terminal.title":"Terminal","terminal.new":"New terminal","terminal.all":"All terminals","terminal.exited":"exited","terminal.cleanupDisconnected":"Remove disconnected terminals","terminal.empty":"No terminal sessions","terminal.createFirst":"Create a terminal session","terminal.close":"Kill process and close","terminal.resize":"Drag to resize terminal","terminal.drag":"Drag to move terminal","mcp.sectionTitle":"MCP servers","mcp.addButton":"Add MCP","mcp.emptyList":'No MCP servers yet. Click "Add MCP" below to create one.',"mcp.emptyDetail":'Select an MCP server on the left, or click "Add MCP".',"mcp.itemEnabled":"enabled","mcp.itemDisabled":"disabled","mcp.addTitle":"Add MCP server","mcp.editTitle":"Edit MCP: {name}","mcp.modeBasic":"Basic","mcp.modeJson":"JSON advanced","mcp.nameLabel":"Name","mcp.namePlaceholder":"e.g. github","mcp.specLabel":"Command or URL (http/https is treated as a URL)","mcp.specPlaceholder":"npx -y @modelcontextprotocol/server-github or https://example.com/mcp","mcp.argsLabel":"Extra args (optional, space separated)","mcp.jsonLabel":"Server definition (JSON) - all fields supported: command/url/socket, args, env, lifecycle, directTools, timeout","mcp.loadingDef":"Loading config...","mcp.jsonEmpty":"JSON cannot be empty","mcp.jsonParseError":"JSON parse failed: {message}","mcp.jsonNotObject":'JSON must be an object, e.g. {"command":"npx","args":["-y","..."]}',"mcp.jsonNeedsEntry":"JSON must contain command, url or socket","mcp.save":"Save","mcp.saveEdit":"Save changes","mcp.saving":"Saving...","mcp.cancel":"Cancel","mcp.enable":"Enable","mcp.disable":"Disable","mcp.disabledBadge":"Disabled","mcp.test":"Test connection","mcp.testing":"Testing...","mcp.edit":"Edit","mcp.delete":"Delete","mcp.moveToGlobal":"Move to global","mcp.moveToProject":"Move to project","mcp.kindCommand":"Command","mcp.kindUrl":"URL","mcp.kindSocket":"Socket","mcp.fieldType":"Type","mcp.fieldArgs":"Args","mcp.fieldEnv":"Env vars","mcp.fieldOptions":"Options","mcp.fieldSource":"Source","mcp.fieldCwd":"CWD","mcp.msgEnabled":"Enabled {name} (run /reload to apply)","mcp.msgDisabled":"Disabled {name} (run /reload to apply)","mcp.msgDeleted":"Deleted {name}","mcp.msgMoved":"Moved {name} to {scope} (run /reload to apply)","mcp.msgUpdated":"Updated {name} (run /reload to apply)","mcp.msgAdded":"Added {name} (run /reload to apply)","mcp.msgTestResult":"Test {name}: {result}","mcp.msgTestError":"Test {name}: {error}","common.close":"Close"}}),a({id:"zh-CN",label:"简体中文",messages:{"common.ok":"确定","common.close":"关闭","common.language":"语言","common.models":"模型","common.skills":"技能","common.plugins":"插件","common.settings":"设置","common.agents":"代理","appUpdate.releaseNotes":"Pi Web v{version} 可用,查看更新说明","sidebar.hide":"隐藏侧边栏","sidebar.show":"显示侧边栏","theme.light":"浅色模式(点击切换到深色)","theme.dark":"深色模式(点击切换到跟随系统)","theme.auto":"跟随系统(点击切换到浅色)","history.full":"历史","history.unsaved":"会话保存后才能查看历史","history.label":"历史","nav.stats":"统计","title.generating":"正在生成...","title.updated":"标题已更新","title.failed":"生成失败","title.generate":"生成标题","title.unsaved":"会话保存后才能生成标题","title.noMessages":"请先发送消息,再为会话命名","title.generateSession":"生成会话标题","system.prompt":"系统提示词","system.empty":"系统提示词为空(工具已禁用)","system.load":"系统提示词尚未加载","system.loading":"正在加载系统提示词…","system.label":"系统","session.info":"会话信息","session.task":"任务","session.name":"名称","session.file":"会话文件","session.inMemory":"内存中","session.id":"ID","session.user":"用户","session.assistant":"助手","session.toolCalls":"工具调用","session.toolResults":"工具结果","session.total":"总计","session.input":"输入","session.output":"输出","session.cacheRead":"缓存读取","session.cacheWrite":"缓存写入","session.cost":"费用","session.context":"上下文","session.cacheHitRate":"平均缓存命中率","session.copy":"复制{value}","session.copied":"已复制","session.title":"会话信息","session.load":"发送消息或运行 /session 以加载会话信息","session.infoSection":"会话信息","session.projectSection":"项目信息","session.messages":"消息","session.tokens":"Token","session.totalActive":"活跃时长","session.copyFile":"复制文件路径","session.copyId":"复制会话 ID","session.projectDir":"项目目录","session.gitBranch":"Git 分支","session.gitWorktree":"Worktree","session.copyProjectDir":"复制项目目录","session.copyGitBranch":"复制 Git 分支","session.copyGitWorktree":"复制 worktree 路径","workspace.opening":"正在打开工作区...","workspace.unable":"无法打开工作区","workspace.selectSession":"从侧边栏选择一个会话","workspace.getStarted":"开始使用","workspace.selectProject":"从侧边栏选择项目目录","workspace.addModels":"点击底部的“模型”按钮添加模型","workspace.stepProject":"从侧边栏选择项目目录","workspace.stepModels":"点击底部的“模型”按钮添加模型","files.hidePanel":"隐藏文件面板","files.showPanel":"显示文件面板","files.noneOpen":"没有打开的文件","layout.resizeSidebar":"调整侧边栏宽度","layout.resizeFilePanel":"调整文件面板宽度","layout.resizeHint":"拖动调整宽度。双击或按 Enter 恢复默认值。","sidebar.new":"新建","sidebar.newSessionTitle":"在 {path} 中新建会话","sidebar.refresh":"刷新","sidebar.selectProject":"选择项目…","sidebar.filterProjects":"筛选项目…","sidebar.noMatchingProjects":"没有匹配的项目","sidebar.useDefaultDirectory":"使用默认目录","sidebar.customPath":"自定义路径…","directoryPicker.selectDirectory":"选择目录","directoryPicker.goToParent":"转到上级目录","directoryPicker.directoryPath":"目录路径","directoryPicker.goToDirectory":"转到目录","directoryPicker.go":"转到","directoryPicker.loadingDirectories":"正在加载目录…","directoryPicker.noSubdirectories":"没有子目录","directoryPicker.openBeforeSelecting":"选择前请先打开此路径","directoryPicker.selectCurrentDirectory":"选择当前目录","directoryPicker.selectThisFolder":"选择此文件夹","directoryPicker.noDrives":"未找到盘符","sidebar.checking":"检查中…","sidebar.open":"打开","sidebar.cancel":"取消","sidebar.worktrees":"Worktrees...","sidebar.filterWorktrees":"筛选 worktree…","sidebar.noMatchingWorktrees":"没有匹配的 worktree","sidebar.switchWorktree":"切换 worktree","sidebar.switchWorktreeTitle":"切换 worktree:{path}","sidebar.main":"主分支","sidebar.forceRemoveCheckout":"存在未提交的更改。强制移除 checkout?","sidebar.force":"强制移除","sidebar.createWorktreeTitle":"为分支创建 worktree checkout","sidebar.newWorktree":"新建 worktree…","sidebar.branchName":"分支名称","sidebar.creating":"创建中…","sidebar.create":"创建","sidebar.uploadFilesTitle":"将文件上传到项目根目录","sidebar.uploadFiles":"上传文件","sidebar.refreshExplorer":"刷新文件浏览器","sidebar.changedFiles":"{count} 个变更文件","sidebar.loading":"加载中...","sidebar.noSessions":"未找到会话","sidebar.agentRunning":"Agent 运行中…","sidebar.newActivity":"有新活动","sidebar.newSessionActivity":"会话有新活动","sidebar.deleteSession":"删除 {title}?此操作不可恢复","sidebar.rename":"重命名","sidebar.pin":"置顶","sidebar.unpin":"取消置顶","sidebar.pinTask":"置顶任务","sidebar.unpinTask":"取消置顶任务","sidebar.pinned":"已置顶","sidebar.taskRunning":"{count} 个会话运行中","sidebar.moreActions":"更多操作","sidebar.delete":"删除","sidebar.expandForks":"展开分叉","sidebar.collapseForks":"折叠分叉","sidebar.taskOpenBoard":"打开看板","sidebar.messagesCount":"{count} 条消息","sidebar.views":"视图","sidebar.sessionTab":"会话","sidebar.boardsTab":"看板","sidebar.filesTab":"文件","sidebar.tasks":"任务","sidebar.tempSessions":"聊天","sidebar.timeToday":"今天","sidebar.timeYesterday":"昨天","sidebar.timeThisWeek":"本周","sidebar.timeThisMonth":"近一月","sidebar.timeOlder":"更久之前","sidebar.newTask":"新建任务…","sidebar.taskName":"任务名称","sidebar.newTaskSession":"新建任务会话","sidebar.loadMoreSessions":"加载更多({count})","sidebar.resizeTasks":"拖拽调整任务区高度","sidebar.deleteTask":"删除任务","sidebar.deleteTaskConfirm":"删除任务「{name}」及其下 {count} 个会话?此操作不可恢复","boards.system":"系统","boards.title":"看板","boards.dragToAdd":"从侧栏拖入会话以添加","boards.dropToAdd":"松手添加到看板","boards.loadingSession":"正在加载会话…","boards.sessionMissing":"会话已不存在","boards.collapse":"收合","boards.workbenchLimit":"同时只支持展开一个工作台","boards.create":"创建","boards.running":"运行中","boards.runningDesc":"跨项目自动聚合所有运行中的会话","boards.project":"项目","boards.empty":"还没有看板 — 新建一个吧","boards.new":"新建看板…","boards.rename":"改名","boards.delete":"删除","boards.deleting":"删除中…","boards.deleteConfirmTitle":"删除看板?","boards.deleteConfirm":"将删除看板及其节点/连线,会话本身不受影响。","boards.cancel":"取消","boards.namePlaceholder":"看板名称","boards.loadingCanvas":"正在加载画布…","boards.runningEmpty":"当前没有运行中的会话 — 运行中的会话会自动出现在这里","boards.emptyCanvas":"空看板 — 从侧栏添加会话({count} 个节点)","boards.back":"返回","boards.switchBoard":"切换看板","boards.addSession":"添加会话","boards.connect":"连线","boards.connectDesc":"连接两张卡片(先点起点,再点终点)","boards.autoLayout":"自动布局","boards.autoLayoutDesc":"自动布局暂未开放","boards.cleanup":"清理失效","boards.clearDesc":"清空画布(删除所有卡片/便笺/连线)","boards.clearConfirm":"确定清空整张画布?此操作不可撤销。","boards.clearTaskBoardDesc":"清空画布(仅清连线/便笺/文本,会话卡片保留)","boards.clearTaskConfirm":"确定清空画布?连线/便笺/文本将被删除,会话卡片会保留(会话数据不受影响)。","boards.conflictReload":"画布已被其他窗口/设备修改,已自动加载最新版本(未保存的改动已丢弃)","boards.reloadCanvas":"重新加载画布(从服务器刷新所有内容)","boards.scrimTitle":"调节画布磨砂","boards.scrimAlpha":"透明度","boards.scrimBlur":"磨砂强度","boards.noSessions":"没有会话","boards.newSession":"新建会话","boards.draftPlaceholder":"新建会话 — 输入消息开始聊天…","boards.searchPlaceholder":"搜索卡片标题、便笺或聊天正文…","boards.searchNoResults":"没有匹配的节点","boards.searchSession":"会话","boards.searchNote":"便笺","boards.searchGroupNodes":"节点命中","boards.searchGroupBody":"正文命中","boards.searchBodyTag":"正文","search.placeholder":"搜索会话…","search.indexing":"正在建立索引…","search.noResults":"没有匹配的结果","search.empty":"输入关键词搜索会话标题或对话内容","search.title":"标题","search.taskCards":"任务卡","search.sessions":"会话","sidebar.worktreePath":"Worktree:{path}","sidebar.removeWorktreeTitle":"移除 worktree checkout {path};保留分支","files.modified":"已修改","files.added":"已添加","files.deleted":"已删除","files.renamed":"已重命名","files.untracked":"未跟踪","files.conflict":"冲突","files.newlyUploaded":"刚上传","files.containsChangedFiles":"包含已更改文件","files.insertPath":"将路径插入聊天","files.mention":"提及","files.download":"下载文件","files.dismissError":"关闭错误","files.addUploadedFile":"将上传的文件添加到聊天","files.addAllUploadedFiles":"将所有上传的文件添加到聊天","files.dismissUploadResults":"关闭上传结果","files.loading":"正在加载文件...","files.searchPlaceholder":"搜索文件…","files.noFiles":"未找到文件","files.explorer":"文件浏览器","files.changedCount":"{count} 个文件","files.changeStats":"{count} 个变更文件,新增 {additions} 行,删除 {deletions} 行","files.conflictSummary":"已有 {count} 个文件:{files}","files.cannotReplace":"无法替换:{files}","files.replace":"替换","files.skipExisting":"跳过已有文件","files.cancel":"取消","files.checking":"正在检查文件","files.uploading":"正在上传,{progress}%","chat.loadingSession":"正在加载会话...","chat.runningTool":"正在运行工具...","chat.generatingToolInput":"正在生成参数...","chat.runningNamedTool":"正在运行 {name}...","chat.runningTools":"正在运行 {names}...","chat.runningToolsMore":"正在运行 {names}(另有 {count} 个)...","chat.waitingModel":"正在等待模型...","chat.runningCommand":"正在运行命令...","chat.commandBusy":"正在执行 {name}…","chat.thinking":"正在思考...","chat.processDetails":"处理详情","chat.message":"条消息","chat.messages":"条消息","chat.toolCall":"次工具调用","chat.toolCalls":"次工具调用","chat.collapseProcess":"收起处理详情","chat.expandProcess":"展开处理详情","chat.filesWritten":"改动的文件","chat.openWrittenFile":"打开 {name}","chat.loadEarlier":"向上滚动以加载更早的消息","chat.extensionRequest":"扩展请求","chat.cancel":"取消","chat.confirm":"确认","chat.submit":"提交","chat.extensionInput":"扩展终端输入","chat.extensionPanel":"扩展面板","chat.extensionWidgets":"扩展组件","chat.extensionWidgetAbove":"输入框上方组件","chat.extensionWidgetBelow":"输入框下方组件","chat.extensionWidgetLine":"{count} 行","chat.extensionWidgetLines":"{count} 行","chat.close":"关闭","chat.extensionInspect":"详情","chat.extensionNoDetail":"暂无详细过程(可尝试刷新后重试)","chat.queued":"已排队 \xb7 {count}","chat.recall":"移回输入框","chat.recallTitle":"移除所有排队消息并将其放回输入框编辑","chat.retrying":"正在重试({attempt}/{max})…","chat.loadingCommands":"正在加载命令...","chat.slashCommands":"斜杠命令 \xb7 {label}","chat.tabEnter":"Tab / Enter","chat.noCommands":"未找到扩展、提示词或技能命令","chat.match":"1 个匹配项","chat.matches":"{count} 个匹配项","chat.command":"1 个命令","chat.commands":"{count} 个命令","chat.loadingFiles":"正在加载文件...","chat.files":"文件 \xb7 {label}{hint}","chat.searching":"搜索中…","chat.noMatchingFiles":"未找到匹配的文件","chat.searchingAll":" \xb7 正在搜索所有文件…","chat.indexTruncated":" \xb7 索引不完整","chat.steerPlaceholder":"立即引导 / 排队后续消息...","chat.agentPlaceholder":"Agent 运行中…","chat.messagePlaceholder":"消息…输入 / 使用命令,输入 @ 查找文件","chat.taskPlaceholder":"[{task}] - 消息…输入 / 使用命令,输入 @ 查找文件","chat.steer":"引导","chat.followUp":"后续消息","chat.send":"发送","chat.askSelection":"询问选中的文字","chat.askInCurrent":"在当前对话询问","chat.askInNewChat":"在新对话询问","chat.newQuoteChat":"关于选中文字的新对话","chat.quoteIntro":"关于这段内容:","chat.quoteQuestion":"我的问题是:","chat.quoteForkFailed":"无法创建引用对话","chat.quoteSelectionToggle":"选中文字后显示询问菜单","chat.sendQuestion":"发送问题","chat.imageNotSupportedTitle":"当前模型不支持图片","chat.imageNotSupportedBody":"模型 {model} 的输入只支持文本,图片不会被发送。请更换支持图片的模型或移除附件。","chat.attachImage":"附加图片","chat.previewImage":"预览图片","chat.filterModels":"筛选模型…","chat.noMatchingModels":"没有匹配的模型","chat.showModelId":"显示 ID","chat.moreControls":"更多控件","chat.collapseControls":"收起控件","chat.shell":"Shell","chat.outputLocal":"输出保留在本地","chat.outputModel":"输出发送给模型","chat.noTools":"不使用工具","chat.readOnlyTools":"{count} 个只读内置工具","chat.builtInTools":"{count} 个内置工具","chat.allBuiltInTools":"全部内置工具","chat.changeReasoning":"更改推理级别:{level}","chat.changeReasoningLabel":"更改推理级别","chat.changeToolPreset":"更改工具预设","chat.stopCompaction":"停止压缩","chat.compactContext":"压缩上下文","chat.compacting":"正在压缩…","chat.compact":"压缩","chat.scrollToLatest":"回到底部","bg.title":"背景图","bg.choose":"选择图片…","bg.replace":"更换图片…","bg.remove":"移除背景图","bg.hint":"图片保存在浏览器本地,不上传。大图会按屏幕尺寸自动压缩。","bg.repeat":"平铺(横向重复)","bg.fill":"边缘色彩填充","bg.adjust":"调整横向位置…","bg.adjustHint":"左右拖拽调整壁纸位置","bg.adjustDone":"移动完成","bg.reset":"重置位置","bg.bubbleOpacity":"气泡透明度","bg.bubbleBlur":"磨砂强度","bg.bubbleReset":"重置气泡","chat.stopAgent":"停止 Agent","chat.stop":"停止","chat.disableSound":"关闭完成提示音","chat.enableSound":"开启完成提示音","chat.thinkingUseDefault":"使用 pi 默认设置","chat.thinkingOff":"关闭推理","chat.thinkingMinimal":"最低限度推理","chat.thinkingLow":"低强度推理","chat.thinkingMedium":"中等强度推理","chat.thinkingHigh":"高强度推理","chat.thinkingXhigh":"超高强度推理","chat.thinkingMax":"最高强度推理","chat.builtIn":"内置","chat.extensions":"扩展","chat.prompts":"提示词","chat.skills":"技能","chat.dormant":"休眠","chat.commandCompact":"压缩上下文,可选附加说明","chat.commandReload":"重新加载扩展、技能、提示词和工具","chat.commandName":"设置会话显示名称","chat.commandSession":"显示会话消息、Token 和费用统计","chat.commandCopy":"复制最后一条助手消息","chat.compacted":"已压缩","chat.tokensSaved":"节省 {saved}","settings.chatContentWidth":"聊天内容宽度","settings.chatContentWidthDescription":"设置消息内容和输入框的最大宽度。","settings.chatContentFontSize":"聊天字体大小","settings.preferences":"偏好","settings.title":"设置","settings.general":"通用","settings.appearance":"外观","settings.chat":"聊天","settings.quoteSelection":"选中文字后询问","settings.resetChatContentWidth":"重置聊天宽度","settings.resetChatContentFontSize":"重置聊天字号","settings.projectRequired":"需要项目","settings.themeLight":"浅色","settings.themeDark":"深色","tools.title":"当前会话启用的工具","tools.details":"工具定义详情","tools.load":"工具定义尚未加载","tools.loading":"正在加载工具定义…","tools.noTools":"没有启用的工具","tools.description":"描述","tools.parameters":"参数","tools.parameterCount":"{count} 个参数","tools.noParameters":"无参数","tools.required":"必填","tools.optional":"可选","tools.allowedValues":"可选值","tools.defaultValue":"默认值","tools.guidelines":"提示词规则","tools.label":"工具","agents.close":"关闭","agents.builtInTitle":"启用 Pi Web 内置子代理","agents.builtInDescription":"提供 Pi Web 集成的 Agent 工具,并停用发生冲突的 pi-subagents 扩展。","agents.reloadRequired":"重新加载当前会话后生效。","agents.reloadSession":"重新加载会话","agents.maxConcurrent":"并发子代理数","agents.maxConcurrentDescription":"每个父会话同时运行的最大任务数。","agents.reloading":"正在重新加载...","agents.loading":"正在加载子代理...","agents.new":"新建子代理","agents.empty":"选择或创建一个子代理配置","agents.saveScope":"保存到","agents.name":"子代理 ID","agents.displayName":"显示名称","agents.description":"描述","agents.prompt":"系统指令","agents.tools":"工具","agents.resources":"资源","agents.loadSkills":"加载技能","agents.loadExtensions":"加载扩展","agents.model":"指定模型","agents.modelsLoading":"正在加载模型...","agents.modelUnavailable":"{model}(不可用)","agents.thinking":"思考级别","agents.maxTurns":"最大轮次","agents.inherit":"跟随父会话","agents.enable":"启用子代理","agents.disable":"停用子代理","agents.builtinPath":"内置配置","agents.inheritContext":"继承父会话上下文","agents.background":"默认在后台运行","agents.duplicate":"创建副本","agents.copyName":"{name} 副本","agents.delete":"删除","agents.deleteConfirm":"删除 {name}?","agents.save":"保存","agents.saving":"正在保存...","agents.scope.builtin":"内置","agents.scope.global":"全局","agents.scope.workspace":"工作区","agents.scope.project":"项目","agents.overridden":"被覆盖","i18n.close":"关闭","i18n.copy":"复制","i18n.pin":"钉","i18n.pinTitle":"钉住此消息(生成可拖拽/缩放的浮窗)","i18n.copied":"已复制","i18n.cancel":"取消","i18n.save":"保存","i18n.saving":"保存中…","i18n.saved":"已保存","i18n.remove":"移除","i18n.removing":"移除中…","i18n.delete":"删除","i18n.loading":"加载中...","i18n.search":"搜索","i18n.refresh":"刷新","i18n.update":"更新","i18n.updating":"更新中...","i18n.check":"检查","i18n.checking":"检查中...","i18n.install":"安装","i18n.installing":"安装中...","i18n.noResults":"没有结果","i18n.searchProviders":"搜索 Provider…","i18n.noProviders":"没有匹配的 Provider","i18n.newModel":"新模型","i18n.addProvider":"添加 Provider","i18n.selectProviderModel":"选择 Provider 或模型","i18n.visibleInPrompt":"在模型提示词中可见,点击以禁用","i18n.hiddenFromPrompt":"在模型提示词中隐藏,点击以启用","i18n.dormant":"休眠","i18n.hiddenButInvocable":"对模型隐藏,仍可手动调用","i18n.skillSearchPlaceholder":"例如 react、testing、deploy","i18n.searching":"搜索中…","i18n.noSkills":"未找到技能","i18n.checkUpdates":"检查更新","i18n.updates":"项更新","i18n.noResolvedResources":"没有已解析资源","i18n.enablePackage":"启用包","i18n.disablePackage":"禁用包","i18n.filtered":"已筛选","i18n.openSessionToReload":"打开会话后才能重新加载","i18n.notFound":"未找到","i18n.noPlugins":"未配置插件","trust.resourcesNotLoaded":"受限模式","trust.trustProject":"信任项目","trust.trusting":"正在信任...","trust.cancel":"取消","trust.dialogTitle":"信任此项目?","trust.dialogBody":"项目资源可以运行本地代码。请仅信任你了解其内容的项目。","trust.skillsNotLoaded":"此项目尚未受信任,项目技能未加载。","trust.pluginsNotLoaded":"此项目尚未受信任,项目插件未加载。","trust.projectScopeUnavailable":"项目资源未加载时,无法安装到项目范围。","i18n.creatingSession":"正在创建新会话…","i18n.creating":"创建中…","i18n.subscription":"订阅","i18n.subscriptions":"订阅服务","i18n.customEndpoint":"自定义端点格式","i18n.noChanges":"没有更改","i18n.branches":"分支","i18n.noActiveSession":"没有活动会话","i18n.noBranches":"此会话没有分支","i18n.source":"源代码","i18n.preview":"预览","i18n.diff":"Diff","i18n.downloadFile":"下载文件","i18n.liveSync":"实时同步已启用","i18n.notWatching":"未监视","i18n.fileViewMode":"文件视图模式","i18n.compareHead":"比较工作区与 HEAD","i18n.mentionSelectedLines":"提及所选行","i18n.disableWrap":"禁用自动换行","i18n.enableWrap":"启用自动换行","i18n.htmlPreview":"HTML 预览","i18n.previewFile":"预览 {file}","i18n.invalidMermaid":"Mermaid 图表无效","i18n.renderingMermaid":"正在渲染 Mermaid 图表","i18n.previewAfterStreaming":"流式输出完成后可预览","i18n.showMermaidSource":"显示 Mermaid 源码","i18n.previewMermaid":"预览 Mermaid 图表","i18n.openMermaidViewer":"打开图表查看器","i18n.mermaidViewer":"Mermaid 图表查看器","i18n.mermaidDiagram":"Mermaid 图表","i18n.zoomOut":"缩小","i18n.zoomIn":"放大","i18n.fitToWidth":"适应宽度","models.discoveryFetching":"正在导入模型…","models.discoveryFetch":"导入模型…","models.discoveryFilterPlaceholder":"筛选 {count} 个模型…","models.discoveryFilter":"筛选上游模型","models.discoverySelectShown":"选择当前结果","models.discoveryNoMatches":"没有匹配的模型。","models.discoveryAdded":"已添加","models.discoveryShowing":"显示前 {shown} 个,共 {total} 个","models.discoveryFetched":"已获取 {count} 个模型","models.discoveryAddSelected":"添加所选模型","models.discoveryAddSelectedCount":"添加所选模型({count})","models.catalogSource":"来源:models.dev ↗","models.catalogFilling":"正在填入模型信息…","models.catalogFill":"填入模型信息","models.catalogFilled":"已填入 {count} 个字段","models.catalogNoEmptyFields":"没有需要填入的空字段","models.catalogNoExactMatch":"models.dev 中没有精确匹配","models.catalogPriceProvider":"价格已匹配 Provider {provider}","models.catalogPriceBaseUrl":"价格已按 Base URL 匹配 {provider}","models.catalogPriceConsensus":"价格得到 {support}/{total} 条记录支持","models.catalogPriceUnreliable":"未找到可靠价格","models.catalogUndo":"撤销","models.capabilities":"能力","models.reasoning":"推理 / 思考","models.imageInput":"图片输入","models.modelSpecs":"模型规格","models.contextWindow":"上下文窗口(tokens)","models.maxOutputTokens":"最大输出 tokens","models.costPerMillion":"每百万 tokens 价格","models.costInput":"输入","models.costOutput":"输出","models.costCacheRead":"缓存读取","models.costCacheWrite":"缓存写入","models.notProvided":"未提供","models.editCosts":"编辑价格","models.finishEditingCosts":"完成","models.costAllRequired":"请输入有效的非负价格;留空项将按 0 保存。","models.advancedSettings":"高级设置","models.providerDefaults":"沿用 Provider 默认设置","models.headersSummary":"Headers:{count}","models.compatSummary":"兼容性:{count}","models.thinkingSummary":"思考等级:{count}","models.apiOverride":"API 覆盖","models.headers":"Headers","models.headersHelp":"仅添加到该模型的请求中,并覆盖 Provider 的同名 Header。","models.compatibility":"兼容性","models.deepSeekThinkingCompat":"DeepSeek 思考兼容","models.developerRole":"使用 developer role 传递系统提示词","models.thinkingLevelMap":"思考等级映射","models.clearAll":"全部清除","i18n.testingModel":"正在测试模型连接...","i18n.connected":"已连接","i18n.failed":"失败","i18n.test":"测试","i18n.testConnection":"测试模型连接","i18n.provider":"Provider","i18n.model":"模型","i18n.providerName":"Provider 名称","i18n.rename":"重命名","i18n.default":"默认","i18n.disabled":"已禁用","i18n.noResources":"没有资源","i18n.unknown":"未知","i18n.installedVersion":"已安装 {version}","i18n.configuredVersion":"已配置 {version}","i18n.extensions":"扩展","i18n.prompts":"提示词","i18n.themes":"主题","i18n.resourceCount":"{count}{label}","i18n.extensionShort":"扩展","i18n.skillShort":"技能","i18n.promptShort":"提示词","i18n.themeShort":"主题","i18n.custom":"自定义","i18n.clearAll":"清除全部","i18n.connectedSuccessfully":"连接成功。","i18n.notConnected":"未连接","i18n.configured":"已配置","i18n.notConfigured":"未配置","i18n.openingBrowser":"正在打开浏览器…","i18n.submit":"提交","i18n.login":"登录","i18n.relogin":"重新登录","i18n.disconnect":"断开连接","i18n.networkError":"网络错误","i18n.continuing":"继续中…","i18n.skills":"技能","i18n.plugins":"插件","i18n.addSkill":"添加技能","i18n.addPlugin":"添加插件","i18n.selectSkill":"选择技能","i18n.selectPackage":"选择包","i18n.updateAvailable":"有可用更新","i18n.upToDate":"已是最新","i18n.automaticChecksUnavailable":"自动检查不可用","i18n.checkFailed":"检查失败","i18n.installed":"已安装","i18n.status":"状态","i18n.version":"版本","i18n.package":"包","i18n.resources":"资源","i18n.installedPath":"安装路径","i18n.cwd":"CWD","i18n.resolvedResources":"已解析资源","i18n.reloadSession":"重新加载会话","i18n.reloading":"重新加载中...","i18n.packageRemoved":"包已移除。","i18n.packageInstalled":"包已安装。","i18n.packageUpdated":"包已更新。","i18n.packageDisabled":"包已禁用。","i18n.packageEnabled":"包已启用。","i18n.sessionReloaded":"会话已重新加载。","i18n.thinking":"思考","i18n.largeMessageReveal":"消息内容过大({size})。点击以纯文本查看 — 已禁用 markdown 渲染以避免页面卡顿。","i18n.loadingThinking":"正在加载思考内容...","i18n.copyMessage":"复制消息","i18n.editFromHere":"从此处编辑","i18n.editFromHereTitle":"从此处编辑,此会话内创建分支","i18n.newSession":"新会话","i18n.newSessionTitle":"新会话,从此处创建独立副本","i18n.estimatedTokens":"流式输出期间的估算 Token 数","i18n.noOutput":"(无输出)","i18n.noSummary":"(无摘要)","i18n.conversationCompacted":"会话已压缩","i18n.compactionDescription":"此处之前的会话历史已压缩为以下摘要:","i18n.fileContext":"文件上下文:{details}","i18n.readFiles":"读取的文件","i18n.modifiedFiles":"修改的文件","i18n.hiddenExtensionMessage":"隐藏的扩展消息","i18n.noMessage":"(无消息)","i18n.showExtensionMessage":"显示扩展消息","i18n.collapse":"收起","i18n.expand":"展开","i18n.hideDetails":"隐藏详情","i18n.showDetails":"显示详情","i18n.thinkingUnavailable":"思考内容不可用","i18n.before":"之前","i18n.after":"之后","i18n.sessionComplete":"任务完成","i18n.taskFinished":"任务已完成。","i18n.attentionNeeded":"Pi 需要你的操作","i18n.extensionInputNeeded":"扩展正在等待你的输入。","todo.title":"任务","todo.completed":"已完成","todo.empty":"暂无任务,可以让 agent 添加。","notice.title":"通知","notice.empty":"暂无通知","notice.expand":"展开详情","notice.collapse":"收起","notice.remove":"移除通知","notice.clearAll":"全部清理","terminal.title":"终端","terminal.new":"新建终端","terminal.all":"全部终端","terminal.exited":"已退出","terminal.cleanupDisconnected":"清理失联终端","terminal.empty":"暂无终端会话","terminal.createFirst":"新建终端会话","terminal.close":"结束进程并关闭","terminal.resize":"拖拽调整终端大小","terminal.drag":"拖拽移动终端位置","mcp.sectionTitle":"MCP 服务器","mcp.addButton":"添加MCP","mcp.emptyList":'暂无 MCP 服务器,点击下方"添加MCP"创建',"mcp.emptyDetail":'选择左侧一个 MCP 服务器,或点击"添加MCP"',"mcp.itemEnabled":"已启用","mcp.itemDisabled":"已禁用","mcp.addTitle":"添加 MCP 服务器","mcp.editTitle":"编辑 MCP:{name}","mcp.modeBasic":"基础配置","mcp.modeJson":"JSON 高级","mcp.nameLabel":"名称","mcp.namePlaceholder":"如 github","mcp.specLabel":"命令 或 URL(http/https 开头识别为 URL)","mcp.specPlaceholder":"npx -y @modelcontextprotocol/server-github 或 https://example.com/mcp","mcp.argsLabel":"附加参数(可选,空格分隔)","mcp.jsonLabel":"服务器定义(JSON)—— 支持 command/url/socket、args、env、lifecycle、directTools、timeout 等全部字段","mcp.loadingDef":"加载配置中...","mcp.jsonEmpty":"JSON 不能为空","mcp.jsonParseError":"JSON 解析失败:{message}","mcp.jsonNotObject":'JSON 必须是对象,如 {"command":"npx","args":["-y","..."]}',"mcp.jsonNeedsEntry":"JSON 需要包含 command、url 或 socket 之一","mcp.save":"保存","mcp.saveEdit":"保存修改","mcp.saving":"保存中...","mcp.cancel":"取消","mcp.enable":"启用","mcp.disable":"禁用","mcp.disabledBadge":"已禁用","mcp.test":"测试连接","mcp.testing":"测试中...","mcp.edit":"编辑","mcp.delete":"删除","mcp.moveToGlobal":"移动至global","mcp.moveToProject":"移动至project","mcp.kindCommand":"命令","mcp.kindUrl":"URL","mcp.kindSocket":"Socket","mcp.fieldType":"类型","mcp.fieldArgs":"参数","mcp.fieldEnv":"环境变量","mcp.fieldOptions":"选项","mcp.fieldSource":"来源","mcp.fieldCwd":"CWD","mcp.msgEnabled":"已启用 {name}(执行 /reload 生效)","mcp.msgDisabled":"已禁用 {name}(执行 /reload 生效)","mcp.msgDeleted":"已删除 {name}","mcp.msgMoved":"已移动 {name} → {scope}(执行 /reload 生效)","mcp.msgUpdated":"已更新 {name}(执行 /reload 生效)","mcp.msgAdded":"已添加 {name}(执行 /reload 生效)","mcp.msgTestResult":"测试 {name}:{result}","mcp.msgTestError":"测试 {name}:{error}"}});let l="pi-locale",d=(0,i.createContext)(null);function c({children:e}){let[t,n]=(0,i.useState)("en"),[a,u]=(0,i.useState)(!1),p=(0,i.useMemo)(()=>s().map(e=>o.get(e)).filter(e=>!!e),[]),h=(0,i.useMemo)(()=>Object.fromEntries(s().flatMap(e=>{let t=o.get(e);return t?[[e,t.messages]]:[]})),[]);(0,i.useEffect)(()=>{let e=function(){try{let e=window.localStorage.getItem(l);if("en"===e||"zh-CN"===e)return e}catch{}for(let e of window.navigator.languages.length?window.navigator.languages:[window.navigator.language]){let t=e.toLowerCase();if("en"===t||t.startsWith("en-"))break;if("zh"===t||t.startsWith("zh-"))return"zh-CN"}return"en"}();n(e),document.documentElement.lang=e,u(!0)},[]);let g=(0,i.useCallback)(e=>{if(o.get(e)){n(e),document.documentElement.lang=e;try{window.localStorage.setItem(l,e)}catch{}}},[]),x=(0,i.useCallback)((e,n)=>(function(e,t,n,r={}){let i=n[e]?.[t]??n.en?.[t];return void 0===i?t:function(e,t={}){return e.replace(/\{([\w.-]+)\}/g,(e,n)=>{let r=t[n];return void 0===r?e:String(r)})}(i,r)})(t,e,h,n),[t,h]),f=(0,i.useMemo)(()=>({locale:a?t:"en",setLocale:g,t:x,supportedLocales:p}),[a,t,g,x,p]);return(0,r.jsx)(d.Provider,{value:f,children:e})}function u(){let e=(0,i.useContext)(d);if(!e)throw Error("useI18n must be used inside I18nProvider");return e}},40233:(e,t,n)=>{"use strict";n.d(t,{N:()=>h,t:()=>u});var r=n(95155),i=n(12115),o=n(65063),a=n(7644),s=n(96793),l=n(39247),d=n(7834),c=n(23657);function u({code:e,isStreaming:t,defaultPreview:o=!1}){let{isDark:a}=(0,s.D)(),{t:d}=(0,l.s)(),[g,x]=(0,i.useState)(o),[f,m]=(0,i.useState)(null),[v,b]=(0,i.useState)(!1),y=`${a?"dark":"light"}
|
|
2
|
-
${e}`,k=g&&!t;(0,i.useEffect)(()=>{if(!k)return;let t=!1;return m({key:y,status:"loading"}),(async()=>{let{default:r}=await Promise.all([n.e(988),n.e(9425),n.e(3546),n.e(3308)]).then(n.bind(n,43328));if(r.initialize({startOnLoad:!1,securityLevel:"strict",suppressErrorRendering:!0,theme:a?"dark":"default"}),!await r.parse(e,{suppressErrors:!0}))throw Error("Invalid Mermaid diagram");let i=`mermaid-${(0,c.S)()}`,o=await r.render(i,e);t||m({key:y,status:"ready",svg:o.svg})})().catch(()=>{t||m({key:y,status:"error"})}),()=>{t=!0}},[e,y,a,k]);let w=(0,i.useMemo)(()=>(0,r.jsx)("button",{type:"button",onClick:()=>x(e=>!e),disabled:t,title:t?d("i18n.previewAfterStreaming"):k?d("i18n.showMermaidSource"):d("i18n.previewMermaid"),className:["markdown-code-action",k?"is-active":""].filter(Boolean).join(" "),children:k?d("i18n.source"):d("i18n.preview")}),[t,k,d]);if(!k)return(0,r.jsx)(h,{code:e,lang:"mermaid",headerAction:w,isStreaming:t});let j=f?.key===y&&"error"===f.status?(0,r.jsx)("div",{className:"mermaid-block mermaid-block-error",children:d("i18n.invalidMermaid")}):f?.key!==y||"ready"!==f.status?(0,r.jsx)("div",{className:"mermaid-block mermaid-block-loading","aria-label":d("i18n.renderingMermaid")}):(0,r.jsxs)(r.Fragment,{children:[!v&&(0,r.jsx)("button",{type:"button",className:"mermaid-block mermaid-preview-button",title:d("i18n.openMermaidViewer"),"aria-label":d("i18n.openMermaidViewer"),onClick:()=>b(!0),dangerouslySetInnerHTML:{__html:f.svg}}),v&&(0,r.jsx)(p,{svg:f.svg,onClose:()=>b(!1)})]});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"}),w]}),j]})}function p({svg:e,onClose:t}){let{t:n}=(0,l.s)(),o=(0,i.useRef)(null),[a,s]=(0,i.useState)(1);return(0,i.useEffect)(()=>{let e=o.current;if(!e)return;let t=document.body.style.overflow;return document.body.style.overflow="hidden",e.showModal(),()=>{document.body.style.overflow=t,e.open&&e.close()}},[]),(0,r.jsx)("dialog",{ref:o,className:"mermaid-zoom-dialog","aria-label":n("i18n.mermaidViewer"),onCancel:e=>{e.preventDefault(),t()},onKeyDown:e=>{"Escape"===e.key&&(e.preventDefault(),t())},children:(0,r.jsxs)("div",{className:"mermaid-zoom-layout",children:[(0,r.jsxs)("div",{className:"mermaid-zoom-toolbar",children:[(0,r.jsx)("span",{className:"mermaid-zoom-title",children:n("i18n.mermaidDiagram")}),(0,r.jsxs)("div",{className:"mermaid-zoom-actions",children:[(0,r.jsxs)("div",{className:"mermaid-zoom-stepper",children:[(0,r.jsx)("button",{type:"button",onClick:()=>s(e=>Math.max(.5,e-.25)),disabled:a<=.5,title:n("i18n.zoomOut"),"aria-label":n("i18n.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)("span",{className:"mermaid-zoom-value",children:[Math.round(100*a),"%"]}),(0,r.jsx)("button",{type:"button",onClick:()=>s(e=>Math.min(3,e+.25)),disabled:a>=3,title:n("i18n.zoomIn"),"aria-label":n("i18n.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:()=>s(1),title:n("i18n.fitToWidth"),"aria-label":n("i18n.fitToWidth"),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:t,title:n("i18n.close"),"aria-label":n("i18n.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",{className:"mermaid-zoom-viewport",onClick:e=>{e.target===e.currentTarget&&t()},children:(0,r.jsx)("div",{className:"mermaid-zoom-canvas",style:{width:`${100*a}%`},dangerouslySetInnerHTML:{__html:e}})})]})})}let h=(0,i.memo)(function({code:e,lang:t,headerAction:n,isStreaming:c}){let{isDark:u}=(0,s.D)(),{t:p}=(0,l.s)(),[h,g]=(0,i.useState)(!1);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:t||"text"}),(0,r.jsxs)("div",{className:"markdown-code-actions",children:[n,(0,r.jsx)("button",{onClick:()=>{(0,d.D)(e).then(()=>{g(!0),setTimeout(()=>g(!1),1500)})},className:"markdown-code-action",children:p(h?"i18n.copied":"i18n.copy")})]})]}),c?(0,r.jsx)("pre",{style:{margin:0,padding:"11px 13px",fontSize:"calc(12.5px + var(--chat-font-size-offset, 0px))",lineHeight:1.62,overflowX:"auto",background:"var(--bubble-code-bg)"},children:(0,r.jsx)("code",{style:{fontFamily:"var(--font-mono)"},children:e})}):(0,r.jsx)(o.A,{language:t||"text",style:u?a.xJ:a.vs,showLineNumbers:!0,lineNumberStyle:{color:"var(--text-dim)",fontStyle:"normal"},customStyle:{margin:0,padding:"11px 13px",fontSize:"calc(12.5px + var(--chat-font-size-offset, 0px))",lineHeight:1.62,borderRadius:0,background:"var(--bubble-code-bg)"},codeTagProps:{style:{fontFamily:"var(--font-mono)"}},children:e})]})})},42910:(e,t,n)=>{"use strict";let r;n.d(t,{ar:()=>f,gx:()=>u,mf:()=>v,qE:()=>b});var i=n(12115),o=n(34229);let a=null,s=null,l=null,d=null,c=0;function u(e){if(!a||!s)return;let t=++c;r&&window.clearTimeout(r),r=window.setTimeout(async()=>{let n=s,[r,i]=await Promise.all([m(a,Math.round(.75*e),n,.25),m(a,Math.round((e+n.scrimBlur)*.75),n,.25)]);if(t!==c){r&&URL.revokeObjectURL(r),i&&URL.revokeObjectURL(i);return}let o=document.documentElement.style;r&&(l&&l!==r&&URL.revokeObjectURL(l),l=r,o.setProperty("--glass-bg-image",`url("${r}")`)),i&&(d&&d!==i&&URL.revokeObjectURL(d),d=i,o.setProperty("--glass-bg-image-card",`url("${i}")`))},120)}function p(){c++,r&&window.clearTimeout(r),r=void 0,l&&URL.revokeObjectURL(l),l=null,d&&URL.revokeObjectURL(d),d=null}let h=!1,g=new Set;function x(e){for(let t of(h=e,g))t(e)}function f(){let[e,t]=(0,i.useState)(h),n=(0,o.E)();return(0,i.useEffect)(()=>(g.add(t),()=>{g.delete(t)}),[]),"board"!==n&&e}async function m(e,t,n,r=.5){let i=(window.devicePixelRatio||1)*r,o=window.innerWidth,a=window.innerHeight,s=Math.max(1,Math.ceil(t)),l=await new Promise(t=>{let n=new Image;n.onload=()=>t(n.naturalWidth?n:null),n.onerror=()=>t(null),n.src=e});if(!l)return null;let d=Math.max(o/l.naturalWidth,a/l.naturalHeight),c=l.naturalWidth*d,u=l.naturalHeight*d,p=o+2*s,h=a+2*s,g=document.createElement("canvas");g.width=Math.round(p*i),g.height=Math.round(h*i);let x=g.getContext("2d");if(!x)return null;x.scale(i,i);let f=(p-c)/2+n.offsetX,v=(h-u)/2;for(let e=Math.floor(-v/u)-1;v+e*u<h+1;e++)for(let t=Math.floor(-f/c)-1;f+t*c<p+1;t++)x.drawImage(l,f+t*c,v+e*u,c,u);let b=document.createElement("canvas");b.width=Math.round(o*i),b.height=Math.round(a*i);let y=b.getContext("2d");if(!y)return null;t>0&&(y.filter=`blur(${t}px)`),y.drawImage(g,s*i,s*i,o*i,a*i,0,0,b.width,b.height);let k=await new Promise(e=>b.toBlob(e,"image/png"));return k?URL.createObjectURL(k):null}function v(e,t,n,r=0){(0,i.useEffect)(()=>{let r=document.documentElement;if(a=e,s=n,!e||!t){p(),r.style.removeProperty("--glass-bg-image"),r.style.removeProperty("--glass-bg-image-heavy"),r.style.removeProperty("--glass-bg-image-scrim"),r.style.removeProperty("--glass-bg-image-card"),x(!1);return}let i=!1,o=null,l=async()=>{let t=Math.round(.75*n.bubbleBlur),a=await m(e,t,n);if(i){a&&URL.revokeObjectURL(a);return}o&&o!==a&&URL.revokeObjectURL(o),o=a,a?r.style.setProperty("--glass-bg-image",`url("${a}")`):r.style.removeProperty("--glass-bg-image"),x(!!a)},d=window.setTimeout(l,120);return()=>{i=!0,d&&window.clearTimeout(d),p()}},[e,t,n.offsetX,n.repeat,n.fill,n.bubbleBlur,r]),(0,i.useEffect)(()=>{let r=document.documentElement;if(!e||!t)return void r.style.removeProperty("--glass-bg-image-heavy");let i=!1,o=null,a=async()=>{let t=Math.round(9),a=await m(e,t,n);if(i){a&&URL.revokeObjectURL(a);return}o&&o!==a&&URL.revokeObjectURL(o),o=a,a?r.style.setProperty("--glass-bg-image-heavy",`url("${a}")`):r.style.removeProperty("--glass-bg-image-heavy")},s=window.setTimeout(a,120);return()=>{i=!0,s&&window.clearTimeout(s)}},[e,t,n.offsetX,n.repeat,n.fill,r]),(0,i.useEffect)(()=>{let r=document.documentElement;if(!e||!t){r.style.removeProperty("--glass-bg-image-scrim"),r.style.removeProperty("--glass-bg-image-card");return}let i=!1,o=null,a=null,s=async()=>{let t=Math.round(.75*n.scrimBlur),s=Math.round((n.bubbleBlur+n.scrimBlur)*.75);if(n.scrimBlur<=0){let t=await m(e,s,n);if(i){t&&URL.revokeObjectURL(t);return}a&&a!==t&&URL.revokeObjectURL(a),a=t,t?r.style.setProperty("--glass-bg-image-card",`url("${t}")`):r.style.removeProperty("--glass-bg-image-card");return}let[l,d]=await Promise.all([m(e,t,n),m(e,s,n)]);if(i){l&&URL.revokeObjectURL(l),d&&URL.revokeObjectURL(d);return}o&&o!==l&&URL.revokeObjectURL(o),a&&a!==d&&URL.revokeObjectURL(a),o=l,a=d,l?r.style.setProperty("--glass-bg-image-scrim",`url("${l}")`):r.style.removeProperty("--glass-bg-image-scrim"),d?r.style.setProperty("--glass-bg-image-card",`url("${d}")`):r.style.removeProperty("--glass-bg-image-card"),l&&d&&document.documentElement.style.setProperty("--board-scrim-filter","none")};n.scrimBlur<=0&&r.style.removeProperty("--glass-bg-image-scrim");let l=window.setTimeout(s,120);return()=>{i=!0,l&&window.clearTimeout(l)}},[e,t,n.offsetX,n.repeat,n.fill,n.bubbleBlur,n.scrimBlur,r])}function b(e){let[t,n]=(0,i.useState)(0);return(0,i.useEffect)(()=>{let t;if(!e)return;let r=()=>{t&&window.clearTimeout(t),t=window.setTimeout(()=>n(e=>e+1),250)};return window.addEventListener("resize",r),()=>{window.removeEventListener("resize",r),t&&window.clearTimeout(t)}},[e]),t}},44051:(e,t,n)=>{"use strict";n.d(t,{Dq:()=>h,I9:()=>g,R9:()=>p,i5:()=>u,y_:()=>c});var r=n(12115);let i=[],o=new Set;function a(){for(let e of o)e()}function s(e){return o.add(e),()=>{o.delete(e)}}function l(){return i}let d=0;function c(e,t,n){let r=window.innerWidth,o=window.innerHeight,s=Math.min(340,Math.max(240,r-40)),l=d%8*22;d+=1;let c={id:`pin-${Date.now()}-${Math.random().toString(36).slice(2,7)}`,content:e,x:Math.min(Math.max(0,t+l),Math.max(0,r-s-4)),y:Math.min(Math.max(0,n+14+l),Math.max(0,o-48)),w:s};i=[...i,c],a()}function u(e){i=i.filter(t=>t.id!==e),a()}function p(e,t){i=i.map(n=>n.id===e?{...n,...t}:n),a()}function h(e){if(i.length<=1)return;let t=i.findIndex(t=>t.id===e);if(-1===t||t===i.length-1)return;let n=[...i],[r]=n.splice(t,1);n.push(r),i=n,a()}function g(){return(0,r.useSyncExternalStore)(s,l,l)}},48660:(e,t,n)=>{"use strict";n.d(t,{u:()=>o});var r=n(12115);function i(e,t=Date.now()){e.composing=!1,e.endedAt=t}function o(){let e=(0,r.useRef)({composing:!1,endedAt:0}),t=(0,r.useRef)(null),n=(0,r.useCallback)(n=>{t.current=n?.target??null,e.current.composing=!0},[]),o=(0,r.useCallback)(()=>{t.current=null,i(e.current)},[]),a=(0,r.useCallback)(t=>(function(e,t,n=Date.now()){return!!e.composing||t?.isComposing===!0||t?.keyCode===229||n-e.endedAt<100})(e.current,t?.nativeEvent),[]);return(0,r.useEffect)(()=>{let n=n=>{t.current&&n.target===t.current&&(t.current=null,i(e.current))};return document.addEventListener("blur",n,!0),()=>document.removeEventListener("blur",n,!0)},[]),{compositionProps:{onCompositionStart:n,onCompositionEnd:o},isIMEBusy:a}}},59185:(e,t,n)=>{"use strict";n.d(t,{t:()=>a});var r=n(95155),i=n(36268),o=n(39247);function a({todos:e}){let{t}=(0,o.s)();return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"9px 12px",borderBottom:"1px solid color-mix(in srgb, var(--border) 70%, transparent)",fontSize:12,fontWeight:650,color:"var(--text)"},children:[t("todo.title"),(0,r.jsxs)("span",{style:{marginLeft:"auto",fontSize:11,color:"var(--text-meta)",fontWeight:500},children:[(0,i.HH)(e)," ",t("todo.completed")]})]}),0===e.length?(0,r.jsx)("div",{style:{padding:"12px 14px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:t("todo.empty")}):(0,r.jsx)("div",{style:{maxHeight:330,overflowY:"auto"},children:e.map(e=>{let t="completed"===e.status;return(0,r.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8,padding:"7px 12px",borderBottom:"1px solid color-mix(in srgb, var(--border) 45%, transparent)"},children:[(0,r.jsx)("span",{"aria-hidden":"true",style:{flexShrink:0,marginTop:2,width:13,height:13,borderRadius:4,display:"flex",alignItems:"center",justifyContent:"center",fontSize:10,fontWeight:800,lineHeight:1,color:t?"#fff":"transparent",background:t?"#16a34a":"color-mix(in srgb, var(--border) 70%, transparent)",border:t?"none":"1px solid color-mix(in srgb, var(--border) 80%, transparent)"},children:"✓"}),(0,r.jsx)("span",{style:{flex:1,minWidth:0,fontSize:12,lineHeight:1.4,color:t?"var(--text-meta)":"var(--text)",textDecoration:t?"line-through":"none",wordBreak:"break-word"},children:e.content}),"in_progress"===e.status&&(0,r.jsx)("span",{"aria-hidden":"true",style:{flexShrink:0,marginTop:5,width:7,height:7,borderRadius:"50%",background:"var(--accent)"}})]},e.id??e.content)})})]})}},59767:e=>{e.exports={panel:"DraftStash_panel__oKqVT","draft-stash-in":"DraftStash_draft-stash-in__ri0Cg",toggle:"DraftStash_toggle__Bnscj",toggleOpen:"DraftStash_toggleOpen__8e8PR",toggleLabel:"DraftStash_toggleLabel__uY4AC",toggleArrow:"DraftStash_toggleArrow__Ggwg9",expandArea:"DraftStash_expandArea__FsTfq",activeBar:"DraftStash_activeBar__b6iYc",activeDot:"DraftStash_activeDot__lnx2D",activeLabel:"DraftStash_activeLabel__QKNcj",cancelBtn:"DraftStash_cancelBtn__WGbk5",list:"DraftStash_list__J4Tfv",row:"DraftStash_row__AxlvA",rowActions:"DraftStash_rowActions__SI2BG",btn:"DraftStash_btn__iCSwh",content:"DraftStash_content__OS0mw",time:"DraftStash_time__TpC8e",btnDanger:"DraftStash_btnDanger__RuifZ"}},66249:(e,t,n)=>{"use strict";function r(e,t){let n=(e,n)=>{let r=t?.has(e.session.id)??!1;return r!==(t?.has(n.session.id)??!1)?r?-1:1:e.session.modified<n.session.modified?1:e.session.modified>n.session.modified?-1:0};return[...e.filter(e=>e.session.pinned).sort(n),...e.filter(e=>!e.session.pinned).sort(n)]}function i(e){return!e.renaming&&!e.confirmDelete}n.d(t,{Fm:()=>a,GO:()=>s,IS:()=>l,il:()=>o,nJ:()=>r,y_:()=>i});let o="text/session-depth";function a(e){let t=Number.parseInt(e,10);return Number.isFinite(t)&&t>0?t:0}function s(e){return 0===e}function l(e,t,n,r){let i=null;return e.map((o,a)=>{let s=!!o.session.pinned,l=a>0&&!!e[a-1]?.session.pinned;!s&&(0===a||l)&&(i=null);let d=s||t.has(o.session.id)?null:r(o.session.modified,n),c=d&&d!==i?d:null;return d&&(i=d),{node:o,header:c,pinDivider:l&&!s}})}},68925:(e,t,n)=>{"use strict";n.d(t,{Ep:()=>u,LA:()=>v,LO:()=>m,iA:()=>f,u_:()=>x});var r=n(88374),i=n(5924),o=n(94764),a=n(63835),s=n(54152),l=n(84678),d=n(98164);let c={...o.j,attributes:{...o.j.attributes,code:[["className",/^language-./,"math-inline","math-display"]]},strip:[...o.j.strip||[],"iframe","object","style","form"]};function u(e){let t=e.includes("\r\n")?"\r\n":"\n",n=e.split(/\r?\n/),r=[],i=null,o=0,a=null,s=new Map;for(let e=0;e<n.length;e++){var l;let t=n[e];if(a){r.push(t),RegExp(`</${a}\\s*>`,"i").test(t)&&(a=null);continue}let d=t.match(/^ {0,3}(`{3,}|~{3,})/);if(d){let e=d[1][0],n=d[1].length;i?e===i.marker&&n>=i.size&&(i=null):i={marker:e,size:n},o=0,r.push(t);continue}if(i){r.push(t);continue}let c=t.match(/<(code|pre|script|style)\b/i);if(c){let e=c[1].toLowerCase(),n=t.slice((c.index??0)+c[0].length);RegExp(`</${e}\\s*>`,"i").test(n)||(a=e),o=0,r.push(t);continue}if(/^(?: {4}|\t)/.test(t)||""===t.trim()){o=0,r.push(t);continue}if(o||t.includes("`")){o=function(e,t){let n=t;for(let t=0;t<e.length;){if("`"!==e[t]){t++;continue}let r=t+1;for(;"`"===e[r];)r++;let i=r-t;0===n?n=i:i===n&&(n=0),t=r}return n}(t,o),r.push(t);continue}let u=t.match(/^([ ]{0,3})\\\[[ \t]*(.+?)[ \t]*\\\][ \t]*$/);if(u){let e=u[2].trim();if(e){r.push(`${u[1]}$$`,`${u[1]}${e}`,`${u[1]}$$`);continue}}let g=t.match(/^([ ]{0,3})\\\[[ \t]*$/);if(g){let t=function(e,t){for(let n=t;n<e.length;n++){let t=e[n];if(/^ {0,3}\\\][ \t]*$/.test(t))return n;if(/^ {0,3}(`{3,}|~{3,})/.test(t)||/^ {0,3}\\\[[ \t]*$/.test(t)||/<(code|pre|script|style)\b/i.test(t))break}return -1}(n,e+1);if(-1!==t){r.push(`${g[1]}$$`,...n.slice(e+1,t).map(e=>h(e,g[1])),`${g[1]}$$`),e=t;continue}}let x=t.match(/^([ \t]{0,3})\$\$(.+)\$\$[ \t]*$/);if(x){let e=x[2].trim();if(e){r.push(`${x[1]}$$`,`${x[1]}${e}`,`${x[1]}$$`);continue}}let f=t.match(/^([ \t]{0,3})\$\$(.+)$/);if(f){let t=f[1],i=f[2].trimEnd();if(i&&!i.includes("$$")){let o=p(n,e+1,t,s);if(o){r.push(`${t}$$`,`${t}${i}`);for(let i=e+1;i<o.index;i++)r.push(h(n[i],t));o.content&&r.push(`${t}${o.content}`),r.push(`${t}$$`),e=o.index;continue}}}let m=t.match(/^([ \t]{0,3})\$\$\s*$/);if(m){let t=m[1],i=p(n,e+1,t,s);if(i&&(i.glued||""!==t)){r.push(`${t}$$`);for(let o=e+1;o<i.index;o++)r.push(h(n[o],t));i.content&&r.push(`${t}${i.content}`),r.push(`${t}$$`),e=i.index;continue}}r.push((l=t,/^\s{0,3}\[[^\]]+\]:/.test(l)||/]\s*\(/.test(l)||/<(?:!--|\/?[A-Za-z][^>]*>)/.test(l)||/\b(?:https?|file|mailto):/i.test(l)||/\b[A-Za-z]:\\/.test(l)?l:l.replace(/(?<!\\)\\\(([^`\r\n$]+?)(?<!\\)\\\)/g,(e,t)=>t.trim()?`$${t}$`:e)))}return r.join(t)}function p(e,t,n,r){let i=r.get(n);if(void 0!==i&&t<i)return null;for(let i=t;i<e.length;i++){var o,a,s,l;let t=e[i];if(o=t,""===(a=n)?/^ {0,3}\$\$\s*$/.test(o):o.startsWith(a)&&/^\$\$\s*$/.test(o.slice(a.length)))return{index:i,content:"",glued:!1};if(s=t,/^ {0,3}(`{3,}|~{3,})/.test(s)||/^[ \t]*(?:[-+*]|\d{1,9}[.)])(?:[ \t]+|$)/.test(s)||/^ {0,3}#{1,6}(?:[ \t]+|$)/.test(s)||/^ {0,3}>/.test(s)||/<(code|pre|script|style)\b/i.test(s)||(l=t,/^ {0,3}\$\$(?:\S|[ \t]+\S)/.test(l)))return r.set(n,i),null;let d=function(e,t){if(!e.startsWith(t))return null;let n=e.slice(t.length).match(/^(.+?)\$\$\s*$/);if(!n)return null;let r=n[1].trimEnd();return r&&!r.includes("$$")?r:null}(t,n);if(null!==d)return{index:i,content:d,glued:!0}}return r.set(n,e.length),null}function h(e,t){if(!t||!e||e.startsWith(" "))return e;let n=e.match(/^ */)?.[0].length??0;return n>=t.length?e:`${t.slice(n)}${e}`}let g={singleTilde:!1},x=[[s.A,["yaml"]],[l.A,g],d.A],f=[[s.A,["yaml"]],[l.A,g],d.A],m=[i.A,[a.A,c],[r.A,{throwOnError:!1,strict:!1}]],v=[i.A,[a.A,c],[r.A,{throwOnError:!1,strict:!1}]]},82490:(e,t,n)=>{"use strict";function r(e){let t,n=[],r=null,o=0,a=0,s=0,l=0,d=[],c=[],u=()=>({lineNo:null,text:"",type:"empty"}),p=()=>{if(!r){d=[],c=[];return}let e=Math.max(d.length,c.length);for(let t=0;t<e;t++){let e=d[t]?{lineNo:d[t].lineNo,text:d[t].text,type:"removed"}:u(),n=c[t]?{lineNo:c[t].lineNo,text:c[t].text,type:"added"}:u();r.rows.push({type:"line",left:e,right:n})}d=[],c=[]};for(let u of e.split(/\r?\n/)){if(!(s>0||l>0)){if(u.startsWith("--- ")){p(),t=i(u.slice(4));continue}if(u.startsWith("+++ ")){p(),r={oldPath:t,newPath:i(u.slice(4)),rows:[]},n.push(r);continue}}let e=u.match(/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);if(e){r||(r={rows:[]},n.push(r)),p(),o=Number(e[1]),a=Number(e[3]),s=void 0===e[2]?1:Number(e[2]),l=void 0===e[4]?1:Number(e[4]),r.rows.push({type:"hunk",text:u});continue}if(!r)continue;if(u.startsWith("\\ ")){p(),r.rows.push({type:"hunk",text:u});continue}let h=u[0],g=u.slice(1);" "===h?(p(),r.rows.push({type:"line",left:{lineNo:o++,text:g,type:"context"},right:{lineNo:a++,text:g,type:"context"}}),s>0&&s--,l>0&&l--):"-"===h?(d.push({lineNo:o++,text:g}),s>0&&s--):"+"===h?(c.push({lineNo:a++,text:g}),l>0&&l--):""!==u&&(p(),r.rows.push({type:"hunk",text:u}))}p();let h=n.filter(e=>e.rows.some(e=>"line"===e.type));return h.length>0?h:null}function i(e){return e.split(" ")[0].trim()}n.d(t,{y:()=>r})},83588:(e,t,n)=>{"use strict";n.d(t,{G:()=>o,n:()=>a});var r=n(12115);let i=null;function o(e){i=e}function a(e){let{onNewSession:t,activeCwd:n}=e;(0,r.useEffect)(()=>{let e=e=>{if("Escape"===e.key){if(!i)return;let t=e.target?.tagName;if("TEXTAREA"===t||"INPUT"===t)return;e.preventDefault(),i();return}if("n"===e.key&&e.ctrlKey&&e.altKey){if(!n||!t)return;e.preventDefault(),t(n)}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[n,t])}},84876:(e,t,n)=>{"use strict";n.d(t,{N:()=>i});var r=n(95155);function i({label:e}){return(0,r.jsx)("div",{style:{height:"100%",width:"100%",display:"flex",alignItems:"center",justifyContent:"center",background:"var(--board-loading-bg)",color:"var(--board-loading-text)",fontSize:13},children:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,r.jsx)("span",{"aria-hidden":!0,style:{width:14,height:14,borderRadius:"50%",border:"2px solid color-mix(in srgb, var(--board-loading-text) 20%, transparent)",borderTopColor:"var(--board-loading-text)",animation:"spin 0.8s linear infinite"}}),e]})})}},88576:e=>{e.exports={preview:"ChatMinimap_preview__laAya",turn:"ChatMinimap_turn__fZuce",number:"ChatMinimap_number__3C_cY",content:"ChatMinimap_content__C7_ju",user:"ChatMinimap_user__WHJHv",userText:"ChatMinimap_userText__Nj9jo",assistant:"ChatMinimap_assistant__s6JLb",assistantJump:"ChatMinimap_assistantJump__3CM2M",outline:"ChatMinimap_outline__aleIF",heading:"ChatMinimap_heading__djZbv",paragraph:"ChatMinimap_paragraph__EqWlO"}},92726:(e,t,n)=>{"use strict";n.d(t,{l:()=>nt});var r=n(95155),i=n(47650),o=n(83588),a=n(12115);let s=/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~]|\][^\x07]*(?:\x07|\x1B\\))/g,l=/^\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~]|\][^\x07]*(?:\x07|\x1B\\))/,d=/\x1B\[([0-9;]*)m/g,c=/\x1B_pi:c\x07/g,u=["#1f2937","#dc2626","#16a34a","#d97706","#2563eb","#9333ea","#0891b2","#6b7280"],p=["#9ca3af","#ef4444","#22c55e","#f59e0b","#3b82f6","#a855f7","#06b6d4","#e5e7eb"];function h(e){return e.replace(c,"").replace(s,"")}function g(e){let t=[],n=0;for(;n<e.length;){if(27===e.charCodeAt(n)){let t=e.slice(n).match(l);if(t){n+=t[0].length;continue}}let r=e.codePointAt(n);if(void 0===r)break;let i=String.fromCodePoint(r);t.push({start:n,end:n+i.length,char:i}),n+=i.length}return t}function x(e,t){let n=g(e)[t];return n?e.slice(0,n.start)+e.slice(n.end):e}function f(e){return g(e)[0]?.char}function m(e){let t,n=[],r={},i=0;for(d.lastIndex=0;null!==(t=d.exec(e));)t.index>i&&n.push({text:e.slice(i,t.index),style:r}),r=function(e,t){let n={...e};for(let e=0;e<t.length;e++){let r=t[e];if(0===r)for(let e of Object.keys(n))delete n[e];else if(1===r)n.fontWeight=700;else if(2===r)n.opacity=.65;else if(3===r)n.fontStyle="italic";else if(4===r)n.textDecoration="underline";else if(22===r)delete n.fontWeight,delete n.opacity;else if(23===r)delete n.fontStyle;else if(24===r)delete n.textDecoration;else if(39===r)delete n.color;else if(49===r)delete n.backgroundColor;else if(r>=30&&r<=37)n.color=u[r-30];else if(r>=90&&r<=97)n.color=p[r-90];else if(r>=40&&r<=47)n.backgroundColor=u[r-40];else if(r>=100&&r<=107)n.backgroundColor=p[r-100];else if((38===r||48===r)&&2===t[e+1]){let[i,o,a]=[t[e+2],t[e+3],t[e+4]];[i,o,a].every(e=>"number"==typeof e&&Number.isFinite(e))&&(38===r?n.color=`rgb(${i}, ${o}, ${a})`:n.backgroundColor=`rgb(${i}, ${o}, ${a})`),e+=4}else if((38===r||48===r)&&5===t[e+1]){let i=function(e){if(e>=0&&e<8)return u[e];if(e>=8&&e<16)return p[e-8];if(e>=16&&e<=231){let t=e-16,n=Math.floor(t/36),r=Math.floor(t%36/6),i=e=>0===e?0:55+40*e;return`rgb(${i(n)}, ${i(r)}, ${i(t%6)})`}if(e>=232&&e<=255){let t=8+(e-232)*10;return`rgb(${t}, ${t}, ${t})`}}(t[e+2]);i&&(38===r?n.color=i:n.backgroundColor=i),e+=2}}return n}(r,t[1]?t[1].split(";").map(e=>Number(e||"0")):[0]),i=t.index+t[0].length;return i<e.length&&n.push({text:e.slice(i),style:r}),n}let v={ArrowUp:"\x1b[A",ArrowDown:"\x1b[B",ArrowRight:"\x1b[C",ArrowLeft:"\x1b[D",Home:"\x1b[H",End:"\x1b[F",Insert:"\x1b[2~",Delete:"\x1b[3~",PageUp:"\x1b[5~",PageDown:"\x1b[6~",Escape:"\x1b",Backspace:""},b={ArrowLeft:"\x1bb",ArrowRight:"\x1bf",ArrowUp:"\x1bp",ArrowDown:"\x1bn"};var y=n(22271);function k(e,t={}){return"thinking"===e.type&&!e.deferred&&!t.isStreaming&&""===e.thinking.trim()}function w(e,t={}){return(e.content??[]).filter(e=>!k(e,t))}function j(e,t={}){return t.isStreaming||"error"!==e.stopReason?null:e.errorMessage?.trim()||"Unknown provider error"}function S(e,t={}){let n=w(e,t),r=n.findLastIndex(e=>"text"!==e.type&&"image"!==e.type);return -1===r?{answerBlocks:n,processBlocks:[]}:{answerBlocks:n.slice(r+1),processBlocks:n.slice(0,r+1)}}function C(e){return e.filter(e=>"toolCall"===e.type).length}var T=n(19870);function M(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 I(e,t,n){let r=e.trim().split("\n").map(e=>`> ${e}`).join("\n");return`${t}
|
|
3
|
-
|
|
4
|
-
${r}
|
|
5
|
-
|
|
6
|
-
${n}`}var L=n(32316),R=n(28999),E=n(68925),z=n(40233);let W=(0,a.memo)(function({children:e,className:t,isStreaming:n,cwd:i,onOpenFile:o}){let s=(0,a.useMemo)(()=>(0,E.Ep)(e),[e]),l=(0,a.useMemo)(()=>({code({className:e,children:t,...i}){let o=e?.replace("language-","").toLowerCase()??"",a=String(t);return e?.includes("language-")||a.includes("\n")?"mermaid"===o?(0,r.jsx)(z.t,{code:a.replace(/\n$/,""),isStreaming:n}):(0,r.jsx)(z.N,{code:a.replace(/\n$/,""),lang:o,isStreaming:n}):(0,r.jsx)("code",{className:"markdown-inline-code",...i,children:t})},pre:({children:e})=>(0,r.jsx)(r.Fragment,{children:e}),a({href:e,children:t,...n}){delete n.node;let a=o?(0,T.V)(e,i):null;return a&&o?(0,r.jsx)("a",{href:e,...n,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:t}):(0,r.jsx)("a",{href:e,...n,target:"_blank",rel:"noopener noreferrer",children:t})},img({src:e,alt:t,...n}){delete n.node;let o="string"==typeof e?(0,T.V)(e,i):null,a=o?`/api/files/${(0,R.HG)(o)}?type=read`:e;return(0,r.jsx)("img",{src:a,alt:t??"",loading:"lazy",...n})},table:({children:e})=>(0,r.jsx)("div",{className:"markdown-table-wrap",children:(0,r.jsx)("table",{children:e})})}),[i,n,o]),d=(0,a.useMemo)(()=>(0,r.jsx)(L.oz,{remarkPlugins:E.u_,rehypePlugins:E.LO,components:l,children:s}),[s,l]);return(0,r.jsx)("div",{className:["markdown-body",t].filter(Boolean).join(" "),children:d})});var P=n(39247);function $({src:e,alt:t="",children:n,className:i,style:o}){let{t:s}=(0,P.s)(),[l,d]=(0,a.useState)(!1),c=(0,a.useRef)(null),u=(0,a.useRef)(null),p=(0,a.useRef)(null);(0,a.useEffect)(()=>{if(!l)return;let e=u.current;if(!e)return;let t=c.current,n=document.body.style.overflow;return document.body.style.overflow="hidden",e.showModal(),p.current?.focus({preventScroll:!0}),()=>{document.body.style.overflow=n,e.open&&e.close(),t?.isConnected&&t.focus({preventScroll:!0})}},[l]);let h=()=>{u.current?.open&&u.current.close(),d(!1)};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{ref:c,type:"button",className:i,style:{display:"block",padding:0,border:"none",background:"none",color:"inherit",cursor:"zoom-in",...o},onClick:()=>d(!0),"aria-label":s("chat.previewImage"),"aria-haspopup":"dialog","aria-expanded":l,title:s("chat.previewImage"),children:n}),l&&(0,r.jsxs)("dialog",{ref:u,className:"image-preview-dialog","aria-label":s("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:p,type:"button",className:"image-preview-close",onClick:h,"aria-label":s("chat.close"),title:s("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"})})})]})]})}var N=n(7834),D=n(96793),B=n(42910),A=n(31590);let F=/<(read-files|modified-files)>\s*([\s\S]*?)\s*<\/\1>/g,H=/(?:\r?\n){2,}((?:[ \t]*<(?:read-files|modified-files)>[ \t]*\r?\n[\s\S]*?\r?\n[ \t]*<\/(?:read-files|modified-files)>[ \t]*(?:\r?\n)?)+)\s*$/;var O=n(82490),U=n(30527);function _({files:e,onOpenFile:t}){let{t:n}=(0,P.s)();return 0===e.length?null:(0,r.jsx)("div",{"aria-label":n("chat.filesWritten"),style:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:6,marginTop:6},children:e.map(({filePath:e})=>{let i=(0,R.WP)(e);return(0,r.jsxs)("button",{type:"button",title:e,"aria-label":n("chat.openWrittenFile",{name:i}),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,U.I3)(i,12),(0,r.jsx)("span",{children:i})]},e)})})}var q=n(45399),V=n(1518);function J(e){let t=e.content,n=[];if("string"==typeof t)n.push(t);else if(Array.isArray(t))for(let e of t)e&&"object"==typeof e&&"text"===e.type&&"string"==typeof e.text&&n.push(e.text);return n.join("\n\n").trim()}function K(e,t){return t?{backgroundImage:`linear-gradient(${e}, ${e}), var(--glass-bg-image, none)`,backgroundAttachment:"fixed",backgroundSize:"100% 100%, 100% 100%",backgroundPosition:"0 0, 0 0",backgroundRepeat:"no-repeat, no-repeat",backgroundColor:e,backdropFilter:"none",WebkitBackdropFilter:"none"}:{background:e}}let Y=/[\u3000-\u30ff\u3400-\u9fff\uf900-\ufaff\u{20000}-\u{2fa1f}\uac00-\ud7af]/u;function G(e){let t=0,n=0;for(let r of e)Y.test(r)?t++:n++;return t+n/4}let X=new Map;function Z({children:e,className:t,...n}){let{t:i}=(0,P.s)(),[o,s]=(0,a.useState)(!1);if(e.length<=1e5)return(0,r.jsx)(W,{className:t,...n,children:e});if(!o){var l;return(0,r.jsxs)("button",{onClick:()=>s(!0),style:{display:"block",width:"100%",margin:"4px 0",padding:"7px 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left"},children:["⚠ ",i("i18n.largeMessageReveal",{size:(l=e.length)>=1e6?`${(l/1e6).toFixed(1)} MB`:l>=1e3?`${Math.round(l/1e3)} KB`:`${l} B`})]})}return(0,r.jsx)("div",{className:t,style:{maxHeight:420,overflow:"auto",fontSize:"calc(12px + var(--chat-font-size-offset, 0px))",lineHeight:1.5},children:(0,r.jsx)("pre",{style:{margin:0,padding:"8px 10px",whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"var(--font-mono)",color:"var(--text-muted)"},children:e})})}function Q(e){if(!e)return null;let t=new Date(e),n=new Date,r=t.getFullYear()===n.getFullYear()&&t.getMonth()===n.getMonth()&&t.getDate()===n.getDate(),i=t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});if(r)return i;let o=t.toLocaleDateString([],{month:"short",day:"numeric",year:t.getFullYear()!==n.getFullYear()?"numeric":void 0});return`${o} ${i}`}let ee=(0,a.memo)(function({message:e,isStreaming:t,toolResults:n,modelNames:i,cwd:o,onOpenFile:a,entryId:s,onFork:l,forking:d,onNavigate:c,parentEntryId:u,isLeafEntry:p,onEditContent:h,showTimestamp:g,prevTimestamp:x,sessionId:f,writtenFiles:m,onPin:v,bare:b}){return"user"===e.role?(0,r.jsx)(et,{message:e,cwd:o,onOpenFile:a,entryId:s,onFork:l,forking:d,onNavigate:c,parentEntryId:u,isLeafEntry:p,onEditContent:h,onPin:v,bare:b}):"assistant"===e.role?(0,r.jsx)(en,{message:e,isStreaming:t,toolResults:n,modelNames:i,cwd:o,onOpenFile:a,showTimestamp:g,prevTimestamp:x,sessionId:f,entryId:s,writtenFiles:m,onPin:v,bare:b}):"toolResult"===e.role?null:"custom"===e.role?"compaction"===e.customType?(0,r.jsx)(eh,{message:e}):(0,r.jsx)(ef,{message:e,cwd:o,onOpenFile:a}):"bashExecution"===e.role?(0,r.jsx)(eb,{message:e,sessionId:f}):null},(e,t)=>e.message===t.message&&e.isStreaming===t.isStreaming&&function(e,t,n){if(t===n||"assistant"!==e.role)return!0;for(let r of e.content??[])if("toolCall"===r.type&&t?.get(r.toolCallId)!==n?.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.entryId===t.entryId&&e.onFork===t.onFork&&e.forking===t.forking&&e.onNavigate===t.onNavigate&&e.parentEntryId===t.parentEntryId&&e.isLeafEntry===t.isLeafEntry&&e.onEditContent===t.onEditContent&&e.showTimestamp===t.showTimestamp&&e.prevTimestamp===t.prevTimestamp&&e.sessionId===t.sessionId&&e.onPin===t.onPin&&e.bare===t.bare);function et({message:e,cwd:t,onOpenFile:n,entryId:i,onFork:o,forking:s,onNavigate:l,parentEntryId:d,isLeafEntry:c,onEditContent:u,onPin:p,bare:h}){let{t:g}=(0,P.s)(),x=(0,B.ar)(),[f,m]=(0,a.useState)(!1),[v,b]=(0,a.useState)(!1),[y,k]=(0,a.useState)(!1),w="string"==typeof e.content?e.content:e.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n"),j="string"==typeof e.content?[]:e.content.filter(e=>"image"===e.type),S=(0,V.d)(w),C=S?.command,T=C?.search(/\s/)??-1,M=C?-1===T?C:C.slice(0,T):"",I=C&&-1!==T?C.slice(T+1):"",L=S?.skillBody,R=Q(e.timestamp),E=!!i&&!!o,z=C??w,D=C?function(e,t){if("string"==typeof e.content)return{...e,content:t};let n=[],r=!1;for(let i of e.content){if("text"!==i.type){n.push(i);continue}r||(n.push({...i,text:t}),r=!0)}return r||n.unshift({type:"text",text:t}),{...e,content:n}}(e,C):e,A=j.length>0&&(0,r.jsx)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginBottom:8*!!w},children:j.map((e,t)=>{let n=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)($,{src:n,children:(0,r.jsx)("img",{src:n,alt:"",style:{maxWidth:240,maxHeight:240,borderRadius:6,objectFit:"contain",display:"block",border:"1px solid rgba(59,130,246,0.15)"}})},t)})}),F=!!i&&!!l;return(0,r.jsxs)("div",{style:{marginBottom:20,display:h?"block":"flex",flexDirection:h?void 0:"column",alignItems:h?void 0:"flex-end"},onMouseEnter:()=>m(!0),onMouseLeave:()=>m(!1),children:[(0,r.jsx)("div",{style:{display:h?"block":"flex",alignItems:h?void 0:"flex-end",gap:h?void 0:6,maxWidth:h?void 0:"85%"},children:(0,r.jsx)("div",{style:{flex:h?void 0:1,minWidth:0,...K("var(--user-bg-glass)",x),border:h?"none":"1px solid var(--user-border-glass)",borderRadius:12,padding:"8px 12px",fontSize:"calc(14px + var(--chat-font-size-offset, 0px))",lineHeight:1.6,color:"var(--text)",wordBreak:"break-word",maxHeight:h?void 0:300,overflowY:h?void 0:"auto"},children:C?(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6,minWidth:0},children:[A,(0,r.jsxs)("button",{onClick:()=>k(e=>!e),title:g(y?"i18n.collapse":"i18n.expand"),"aria-expanded":y,style:{display:"flex",alignItems:"center",gap:6,padding:0,background:"none",border:"none",cursor:"pointer",color:"var(--accent)",fontFamily:"var(--font-mono)",fontSize:"calc(13px + var(--chat-font-size-offset, 0px))",textAlign:"left",width:"fit-content"},children:[(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:M}),(0,r.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,opacity:.75,transform:y?"rotate(180deg)":"none",transition:"transform 0.15s"},"aria-hidden":"true",children:(0,r.jsx)("polyline",{points:"6 9 12 15 18 9"})})]}),y&&L&&(0,r.jsx)("div",{style:{margin:"2px 0",borderLeft:"2px solid var(--bubble-hairline)",paddingLeft:10,fontSize:12},children:(0,r.jsx)(W,{className:"markdown-skill-body",cwd:t,onOpenFile:n,children:L})}),I&&(0,r.jsx)("span",{style:{color:"var(--text)",fontSize:"calc(14px + var(--chat-font-size-offset, 0px))",lineHeight:1.6,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:I})]}):(0,r.jsxs)(r.Fragment,{children:[A,w&&(0,r.jsx)(Z,{className:"markdown-user-message",cwd:t,onOpenFile:n,children:w})]})})}),!h&&(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:6,marginTop:3,mixBlendMode:"exclusion"},children:[(0,r.jsxs)("div",{style:{display:"flex",gap:3,opacity:+!!f,pointerEvents:f?"auto":"none",transition:"opacity 0.12s"},children:[p&&(0,r.jsxs)("button",{onClick:t=>p(J(e),t.clientX,t.clientY),title:g("i18n.pinTitle"),style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",height:22,background:"none",border:"none",borderRadius:5,color:"#ffffff",cursor:"pointer",fontSize:11,fontWeight:400,whiteSpace:"nowrap",transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.fontWeight="600",e.currentTarget.style.textDecoration="underline"},onMouseLeave:e=>{e.currentTarget.style.fontWeight="400",e.currentTarget.style.textDecoration="none"},children:[(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("path",{d:"M12 17v5"}),(0,r.jsx)("path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0-2-2 3 3 0 0 0-3 3V9a4 4 0 0 1-1 2.65"})]}),g("i18n.pin")]}),(0,r.jsxs)("button",{onClick:()=>{(0,N.D)(z).then(()=>{b(!0),setTimeout(()=>b(!1),1500)})},title:g("i18n.copyMessage"),style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",height:22,background:"none",border:"none",borderRadius:5,color:v?"var(--accent)":"#ffffff",cursor:"pointer",fontSize:11,fontWeight:400,whiteSpace:"nowrap",transition:"color 0.12s"},onMouseEnter:e=>{v||(e.currentTarget.style.fontWeight="600",e.currentTarget.style.textDecoration="underline")},onMouseLeave:e=>{v||(e.currentTarget.style.fontWeight="400",e.currentTarget.style.textDecoration="none")},children:[v?(0,r.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,r.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),g(v?"i18n.copied":"i18n.copy")]})]}),(E||F)&&(0,r.jsxs)("div",{style:{display:"flex",gap:3,opacity:f||s?1:0,pointerEvents:f||s?"auto":"none",transition:"opacity 0.12s"},children:[F&&(0,r.jsxs)("button",{onClick:()=>{d?l(d):c||l(i,null),u?.(D)},title:g("i18n.editFromHereTitle"),style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",height:22,background:"none",border:"none",borderRadius:5,color:"#ffffff",cursor:"pointer",fontSize:11,fontWeight:400,whiteSpace:"nowrap",transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.fontWeight="600",e.currentTarget.style.textDecoration="underline"},onMouseLeave:e=>{e.currentTarget.style.fontWeight="400",e.currentTarget.style.textDecoration="none"},children:[(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("polyline",{points:"15 10 20 15 15 20"}),(0,r.jsx)("path",{d:"M4 4v7a4 4 0 0 0 4 4h12"})]}),g("i18n.editFromHere")]}),E&&(0,r.jsxs)("button",{onClick:()=>{o(i)},disabled:s,title:g(s?"i18n.creatingSession":"i18n.newSessionTitle"),style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",height:22,background:"none",border:"none",borderRadius:5,color:s?"var(--accent)":"#ffffff",cursor:s?"not-allowed":"pointer",fontSize:11,fontWeight:400,whiteSpace:"nowrap",transition:"color 0.12s"},onMouseEnter:e=>{s||(e.currentTarget.style.fontWeight="600",e.currentTarget.style.textDecoration="underline")},onMouseLeave:e=>{s||(e.currentTarget.style.fontWeight="400",e.currentTarget.style.textDecoration="none")},children:[(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,r.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,r.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,r.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),g(s?"i18n.creating":"i18n.newSession")]})]}),R&&(0,r.jsx)("span",{style:{fontSize:10,color:"#ffffff"},children:R})]})]})}function en({message:e,isStreaming:t,toolResults:n,modelNames:i,cwd:o,onOpenFile:s,showTimestamp:l,prevTimestamp:d,sessionId:c,entryId:u,writtenFiles:p,onPin:h,bare:g}){var x;let f,m,v=(0,A.a)(),{t:b}=(0,P.s)(),y=(0,B.ar)(),w=l?Q(e.timestamp):null,S=(0,a.useMemo)(()=>(e.content??[]).map((e,t)=>({block:e,originalIndex:t})).filter(({block:e})=>!k(e,{isStreaming:t})),[e.content,t]),C=(0,a.useMemo)(()=>S.map(({block:e})=>e),[S]),T=j(e,{isStreaming:t}),[M,I]=(0,a.useState)(!1),[L,R]=(0,a.useState)(!1),E=(0,a.useRef)(null),[z,W]=(0,a.useState)(null),$=(0,a.useRef)(S);$.current=S;let D=(0,a.useRef)(null),F=(0,a.useRef)(null);(0,a.useLayoutEffect)(()=>{if(!t)return;let e=D.current,n=F.current;if(!e||!n)return;let r=()=>{let t=n.offsetHeight,r=Number.parseFloat(e.style.height);Number.isFinite(r)&&.5>Math.abs(r-t)||(e.style.height=`${t}px`)};r();let i=new ResizeObserver(r);return i.observe(n),()=>{i.disconnect(),e.style.height=""}},[t]);let H=(0,a.useRef)(new Map),O=(0,a.useMemo)(()=>{if(!t)return H.current=new Map,0;let e=new Map,n=0;for(let{block:t,originalIndex:r}of S){let i="text"===t.type?t.text:"thinking"===t.type?t.thinking:"toolCall"===t.type?t.rawInput??JSON.stringify(t.input??{})??"":null;if(null===i)continue;let o=function(e,t){var n,r;if(!e||!t.startsWith(e.text))return G(t);let i=e.tokens,o=e.text.length;return o>0&&o<t.length&&(n=e.text.charCodeAt(o-1))>=55296&&n<=56319&&(r=t.charCodeAt(o))>=56320&&r<=57343&&(i-=1/4,o--),i+G(t.slice(o))}(H.current.get(r),i);e.set(r,{text:i,tokens:o}),n+=o}return H.current=e,n},[S,t]),U=(0,a.useRef)(O);U.current=O;let q=(0,a.useRef)(new Map),[V,Y]=(0,a.useState)(new Map),X=(0,a.useMemo)(()=>{if(!e.timestamp||!d)return;let t=Math.round((e.timestamp-d)/1e3);return t>0?t:void 0},[e.timestamp,d]),Z=(0,a.useMemo)(()=>{let t=new Map;if(!n||!e.timestamp)return t;for(let[r,i]of n)if(i.timestamp&&e.timestamp){let n=Math.round((i.timestamp-e.timestamp)/1e3);n>0&&t.set(r,n)}return t},[n,e.timestamp]),ee=C.filter(e=>"text"===e.type).map(e=>e.text).join("\n");if((0,a.useEffect)(()=>{if(!t){let e=new Date().getTime();Y(t=>{let n=new Map(t);for(let[t,r]of q.current)n.has(t)||n.set(t,Math.round((e-r)/1e3));return n}),E.current=null,W(null);return}let e=setInterval(()=>{let e=$.current,t=Date.now();e.forEach(({originalIndex:e})=>{q.current.has(e)||q.current.set(e,t)}),Y(n=>{let r=!1,i=new Map(n);for(let n=0;n<e.length-1;n++){let o=e[n].originalIndex,a=e[n+1].originalIndex;if(!i.has(o)&&q.current.has(o)){let e=q.current.get(o),n=q.current.get(a)??t;i.set(o,Math.round((n-e)/1e3)),r=!0}}return r?i:n});let n=U.current;if(0===n)return;null===E.current&&(E.current=t);let r=(t-E.current)/1e3;r>.5&&W(n/r)},300);return()=>clearInterval(e)},[t]),0===C.length&&!t&&!T)return null;return(0,r.jsxs)("div",{"data-message-role":"assistant","data-entry-id":u,style:{marginBottom:20},onMouseEnter:()=>I(!0),onMouseLeave:()=>I(!1),children:[(0,r.jsx)("div",{ref:D,style:{borderRadius:"var(--bubble-radius)",...K("var(--assistant-card-glass)",y),border:g?"none":"1px solid var(--bubble-border)",boxShadow:"0 1px 2px rgba(15,23,42,0.04), 0 4px 16px -8px rgba(15,23,42,0.10)",overflow:t?"hidden":void 0,transition:t?"height 120ms cubic-bezier(0.4, 0, 0.2, 1)":void 0},children:(0,r.jsxs)("div",{ref:F,style:{display:"flex",flexDirection:"column",gap:"var(--bubble-gap)",padding:"var(--bubble-pad-y) var(--bubble-pad-x) var(--bubble-pad-end)"},children:[S.map(({block:e,originalIndex:i})=>(0,r.jsx)(er,{block:e,toolResults:n,isStreaming:t,streamingDuration:V.get(i)??("thinking"===e.type?X:void 0),toolCallDurations:Z,cwd:o,onOpenFile:s,sessionId:c,entryId:u,blockIndex:i},`${u??"stream"}-${i}`)),T&&(0,r.jsxs)("div",{role:"alert",style:{display:"flex",alignItems:"center",gap:6,padding:"2px 0",fontFamily:"var(--font-mono)",fontSize:"calc(12px + var(--chat-font-size-offset, 0px))",lineHeight:1.5,whiteSpace:"pre-wrap",overflowWrap:"anywhere"},children:[(0,r.jsx)("span",{style:{width:7,height:7,borderRadius:999,flexShrink:0,background:"#f87171",boxShadow:"0 0 0 3px rgba(248,113,113,0.15)"},"aria-hidden":"true"}),(0,r.jsxs)("span",{children:["Error: ",T]})]}),p&&p.length>0&&(0,r.jsx)(_,{files:p,onOpenFile:s})]})}),!g&&(e.provider||t||e.usage||w||ee||h)&&(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:8,paddingLeft:4,fontSize:11,color:"#ffffff",mixBlendMode:"exclusion"},children:[e.provider&&!v&&(0,r.jsx)("span",{style:{whiteSpace:"nowrap"},children:i?.[`${e.provider}:${e.model}`]??i?.[e.model]??e.model}),t&&((m=Math.round(O))<=0?null:(0,r.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},title:b("i18n.estimatedTokens"),children:[(0,r.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("line",{x1:"5",y1:"1.5",x2:"5",y2:"8.5"}),(0,r.jsx)("polyline",{points:"2 6 5 8.5 8 6"})]}),m,null!==z&&(0,r.jsxs)("span",{children:[z.toFixed(1)," t/s"]})]})),!t&&e.usage&&(0,r.jsx)("span",{children:(x=e.usage,f=[],x.input&&f.push(`${x.input.toLocaleString()} in`),x.output&&f.push(`${x.output.toLocaleString()} out`),x.cacheRead&&f.push(`${x.cacheRead.toLocaleString()} cache R`),x.cacheWrite&&f.push(`${x.cacheWrite.toLocaleString()} cache W`),x.cost?.total&&f.push(`$${x.cost.total.toFixed(4)}`),f.join(" \xb7 "))}),ee&&(0,r.jsxs)("button",{onClick:()=>{(0,N.D)(ee).then(()=>{R(!0),setTimeout(()=>R(!1),1500)})},title:b("i18n.copyMessage"),style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",height:22,background:"none",border:"none",borderRadius:5,color:L?"var(--accent)":"#ffffff",cursor:"pointer",fontSize:11,fontWeight:400,whiteSpace:"nowrap",opacity:+!!M,pointerEvents:M?"auto":"none",transition:"opacity 0.12s, color 0.12s"},onMouseEnter:e=>{L||(e.currentTarget.style.fontWeight="600",e.currentTarget.style.textDecoration="underline")},onMouseLeave:e=>{L||(e.currentTarget.style.fontWeight="400",e.currentTarget.style.textDecoration="none")},children:[L?(0,r.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,r.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),b(L?"i18n.copied":"i18n.copy")]}),h&&(0,r.jsxs)("button",{onClick:t=>h(J(e),t.clientX,t.clientY),title:b("i18n.pinTitle"),style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",height:22,background:"none",border:"none",borderRadius:5,color:"#ffffff",cursor:"pointer",fontSize:11,fontWeight:400,whiteSpace:"nowrap",opacity:+!!M,pointerEvents:M?"auto":"none",transition:"opacity 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.fontWeight="600",e.currentTarget.style.textDecoration="underline"},onMouseLeave:e=>{e.currentTarget.style.fontWeight="400",e.currentTarget.style.textDecoration="none"},children:[(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("path",{d:"M12 17v5"}),(0,r.jsx)("path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0-2-2 3 3 0 0 0-3 3V9a4 4 0 0 1-1 2.65"})]}),b("i18n.pin")]}),w&&(0,r.jsx)("span",{style:{marginLeft:"auto",fontSize:10},children:w})]})]})}function er({block:e,toolResults:t,isStreaming:n,streamingDuration:i,toolCallDurations:o,cwd:a,onOpenFile:s,sessionId:l,entryId:d,blockIndex:c}){if("text"===e.type)return(0,r.jsx)(ei,{block:e,isStreaming:n,cwd:a,onOpenFile:s});if("thinking"===e.type)return(0,r.jsx)(eo,{block:e,duration:i,isStreaming:n,sessionId:l,entryId:d,blockIndex:c});if("toolCall"===e.type){let n=t?.get(e.toolCallId),i=o?.get(e.toolCallId);return(0,r.jsx)(ea,{block:e,result:n,duration:i})}return null}function ei({block:e,isStreaming:t,cwd:n,onOpenFile:i}){return(0,r.jsx)(Z,{isStreaming:t,cwd:n,onOpenFile:i,children:e.text})}function eo({block:e,duration:t,isStreaming:n,sessionId:i,entryId:o,blockIndex:s}){let{t:l}=(0,P.s)(),{isDark:d}=(0,D.D)(),[c,u]=(0,a.useState)(!1),[p,h]=(0,a.useState)(!1),[g,x]=(0,a.useState)(null),[f,m]=(0,a.useState)(!1),[v,b]=(0,a.useState)(null),y=async()=>{let t=!c;if(u(t),t&&e.deferred&&null===g){if(!i||!o)return void b(l("i18n.thinkingUnavailable"));m(!0),b(null);try{x(await function(e,t,n){let r=`${e}:${t}:${n}`,i=X.get(r);if(i)return X.delete(r),X.set(r,i),i;let o=fetch(`/api/sessions/${encodeURIComponent(e)}/entries/${encodeURIComponent(t)}/thinking?blockIndex=${n}`).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 X.delete(r),e});if(X.set(r,o),X.size>100){let e=X.keys().next().value;e&&X.delete(e)}return o}(i,o,s))}catch(e){b(e instanceof Error?e.message:String(e))}finally{m(!1)}}};return(0,r.jsxs)("div",{onMouseEnter:()=>h(!0),onMouseLeave:()=>h(!1),style:{fontSize:"calc(13px + var(--chat-font-size-offset, 0px))"},children:[(0,r.jsxs)("button",{onClick:()=>void y(),style:{display:"flex",alignItems:"center",gap:6,width:"100%",padding:"2px 8px 2px 4px",borderRadius:6,background:p?"var(--bubble-tool-bg-fold)":"transparent",border:"none",color:p?"var(--text-meta)":"var(--text-muted)",cursor:"pointer",fontSize:"calc(13px + var(--chat-font-size-offset, 0px))",textAlign:"left",transition:"color 0.12s, background 0.12s"},children:[n?(0,r.jsx)("span",{style:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,flexShrink:0},children:(0,r.jsx)(q.KV,{state:"breathing",size:20,theme:d?"dark":"light",style:d?void 0:{filter:"brightness(0.57) contrast(1.15)"}})}):(0,r.jsx)("span",{style:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,flexShrink:0},"aria-hidden":"true",children:(0,r.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",style:{display:"block"},children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,r.jsx)("circle",{cx:"19",cy:"5",r:"2"}),(0,r.jsx)("circle",{cx:"5",cy:"19",r:"2"}),(0,r.jsx)("path",{d:"M10.4 21.9a10 10 0 0 0 9.941-15.416"}),(0,r.jsx)("path",{d:"M13.5 2.1a10 10 0 0 0-9.841 15.416"})]})}),(0,r.jsx)("span",{children:l("i18n.thinking")}),void 0!==t&&(0,r.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)",fontVariantNumeric:"tabular-nums"},children:[t,"s"]}),(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:c?"rotate(180deg)":"none",transition:"transform 0.15s"},"aria-hidden":"true",children:(0,r.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),c&&(0,r.jsx)("div",{style:{margin:"2px 0 4px 30px",borderLeft:"2px solid var(--bubble-hairline)",paddingLeft:10,color:v?"#f87171":"var(--text-muted)",fontSize:12,lineHeight:1.3,whiteSpace:"pre-wrap"},children:f?(0,r.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:8},children:[(0,r.jsx)(q.KV,{state:"searching",size:20,theme:d?"dark":"light",style:d?void 0:{filter:"brightness(0.57) contrast(1.15)"}}),l("i18n.loadingThinking")]}):v??(e.deferred?g:e.thinking)})]})}function ea({block:e,result:t,duration:n}){var i;let{t:o}=(0,P.s)(),[s,l]=(0,a.useState)(!1),[d,c]=(0,a.useState)(!1),u=(i=e).rawInput??JSON.stringify(i.input,null,2),p=void 0!==e.rawInput,h=M(e.toolName),g=t&&!t.isError?function(e){var t;let n=e.details;if(!("object"==typeof(t=n)&&null!==t&&!Array.isArray(t)))return null;let r="string"==typeof n.patch?n.patch:null;if(r)return{text:r};let i="string"==typeof n.diff?n.diff:null;return i?{text:i}:null}(t):null,x=t?t.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n"):null,f=null!==x&&("(no output)"===x.trim()||""===x.trim()),m=t?.isError??!1;return(0,r.jsxs)("div",{onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),style:{borderRadius:s?"var(--bubble-inner-radius)":5,overflow:"hidden",fontSize:"calc(12px + var(--chat-font-size-offset, 0px))",border:s?"1px solid var(--bubble-border)":"1px solid transparent",background:s?d?"var(--bubble-tool-bg-hover)":"var(--bubble-tool-bg)":d?"var(--bubble-tool-bg-fold)":"transparent",backdropFilter:s?"blur(var(--glass-blur-bubble)) saturate(var(--glass-saturate))":"none",WebkitBackdropFilter:s?"blur(var(--glass-blur-bubble)) saturate(var(--glass-saturate))":"none",transition:"background 0.12s"},children:[(0,r.jsxs)("button",{onClick:()=>l(e=>!e),style:{display:"flex",alignItems:"center",gap:6,width:"100%",padding:"6px 10px",background:"none",border:"none",color:"var(--text-meta)",cursor:"pointer",fontSize:12,textAlign:"left",minWidth:0},children:[(0,r.jsx)("span",{style:{width:7,height:7,borderRadius:999,flexShrink:0,background:m?"#f87171":"#22c55e",boxShadow:m?"0 0 0 3px rgba(248,113,113,0.15)":"0 0 0 3px rgba(34,197,94,0.15)"},"aria-hidden":"true"}),(0,r.jsx)("span",{style:{color:"var(--text-meta)",fontFamily:"var(--font-mono)",fontWeight:600,fontSize:11,flexShrink:0},children:e.toolName}),(0,r.jsx)("span",{style:{color:"var(--text-meta)",fontFamily:"var(--font-mono)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,minWidth:0},children:p?o("chat.generatingToolInput"):function(e){let t=e.input;if(!t||"object"!=typeof t)return"";let n=Object.keys(t);return 0===n.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[n[0]]).slice(0,120)}(e)}),void 0!==n&&(0,r.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)",flexShrink:0,fontVariantNumeric:"tabular-nums"},children:[n,"s"]}),(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:s?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,r.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),s&&(p||!h)&&(0,r.jsx)("div",{style:{borderTop:"1px solid var(--bubble-hairline)"},children:(0,r.jsx)("pre",{style:{margin:0,padding:"8px 10px",color:"var(--text)",fontSize:"calc(12px + var(--chat-font-size-offset, 0px))",lineHeight:1.5,overflow:"auto",background:"transparent",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:u})}),s&&t&&(g?(0,r.jsx)(es,{diff:g}):(0,r.jsx)(ep,{text:x??"",isEmpty:f,isError:m})),s&&t&&(0,r.jsx)(ev,{content:t.content})]})}function es({diff:e}){return(0,r.jsx)("div",{style:{borderTop:"1px solid var(--bubble-hairline)"},children:(0,r.jsx)(el,{text:e.text})})}function el({text:e}){let{t}=(0,P.s)(),n=(0,a.useMemo)(()=>(0,O.y)(e),[e]);if(!n)return(0,r.jsx)(eu,{text:e});let i=n.length>1;return(0,r.jsx)("div",{style:{maxHeight:560,overflowY:"auto",overflowX:"hidden"},children:n.map((e,n)=>(0,r.jsxs)("div",{style:{minWidth:0,borderTop:0===n?"none":"1px solid var(--border)",fontFamily:"var(--font-mono)",fontSize:"calc(12px + var(--chat-font-size-offset, 0px))",lineHeight:1.55},children:[i&&(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(0, 1fr)",position:"sticky",top:0,zIndex:1,background:"var(--bg-subtle)",borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)(ed,{title:e.oldPath||t("i18n.before"),side:"left"}),(0,r.jsx)(ed,{title:e.newPath||t("i18n.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)(ec,{cell:e.left,side:"left"}),(0,r.jsx)(ec,{cell:e.right,side:"right"})]},t))})]},n))})}function ed({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 ec({cell:e,side:t}){let n="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",i="added"===e.type?"+":"removed"===e.type?"-":" ",o="added"===e.type?"#22c55e":"removed"===e.type?"#f87171":"var(--text-dim)";return(0,r.jsxs)("div",{style:{display:"flex",minWidth:0,background:n,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-subtle)",borderRight:"1px solid var(--border)",flexShrink:0},children:e.lineNo??""}),(0,r.jsx)("span",{style:{width:18,padding:"0 5px",color:o,userSelect:"none",fontWeight:"context"===e.type||"empty"===e.type?400:700,flexShrink:0},children:i}),(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 eu({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 n=e.startsWith("@@")?"hunk":e.startsWith("+")&&!e.startsWith("+++")?"added":e.startsWith("-")&&!e.startsWith("---")?"removed":"context";return(0,r.jsxs)("div",{style:{display:"flex",background:"added"===n?"rgba(34,197,94,0.12)":"removed"===n?"rgba(248,113,113,0.13)":"hunk"===n?"rgba(96,165,250,0.12)":"transparent",borderLeft:"added"===n?"3px solid #22c55e":"removed"===n?"3px solid #f87171":"hunk"===n?"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-subtle)",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"===n?"#22c55e":"removed"===n?"#f87171":"hunk"===n?"var(--accent)":"var(--text)"},children:e||"\xa0"})]},t)})})}function ep({text:e,isEmpty:t,isError:n}){let{t:i}=(0,P.s)();return(0,r.jsx)("div",{style:{borderTop:"1px solid var(--bubble-hairline)"},children:(0,r.jsx)("pre",{style:{margin:0,padding:"8px 10px",color:n?"#f87171":t?"var(--text-dim)":"var(--text-muted)",fontSize:12,lineHeight:1.5,overflow:"auto",maxHeight:400,background:"transparent",whiteSpace:"pre-wrap",wordBreak:"break-all",fontStyle:t?"italic":"normal",opacity:t?.6:1},children:t?i("i18n.noOutput"):e})})}function eh({message:e}){let{t}=(0,P.s)(),n=(0,B.ar)(),i=em(e.content),o=(0,a.useMemo)(()=>{let e,t,n,r,o;return e=[],t=[],n=i.match(H),r=n?.[1]??"",o=n?.index===void 0?i:i.slice(0,n.index),r.replace(F,(n,r,i)=>{let o=i.split(/\r?\n/).map(e=>e.trim()).filter(Boolean);return"read-files"===r?e.push(...o):t.push(...o),""}),{body:o.trim(),readFiles:e,modifiedFiles:t}},[i]),s=Q(e.timestamp);return(0,r.jsx)("div",{style:{marginBottom:20},children:(0,r.jsxs)("div",{style:{borderRadius:12,overflow:"hidden",...K("var(--assistant-card-glass)",n),border:"1px solid var(--bubble-border)",boxShadow:"0 1px 2px rgba(15,23,42,0.04), 0 4px 16px -8px rgba(15,23,42,0.10)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"7px 10px",borderBottom:"1px solid var(--bubble-hairline)",color:"var(--text-muted)"},children:[(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,fontWeight:650},children:"compaction"}),s&&(0,r.jsx)("span",{style:{marginLeft:"auto",color:"var(--text-dim)",fontSize:10},children:s})]}),(0,r.jsxs)("div",{style:{padding:"11px 13px 12px"},children:[(0,r.jsx)("div",{style:{color:"var(--text)",fontSize:"calc(15px + var(--chat-font-size-offset, 0px))",fontWeight:700,lineHeight:1.35},children:t("i18n.conversationCompacted")}),(0,r.jsx)("div",{style:{marginTop:3,marginBottom:10,color:"var(--text)",fontSize:"calc(14px + var(--chat-font-size-offset, 0px))",lineHeight:1.5},children:t("i18n.compactionDescription")}),o.body?(0,r.jsx)(W,{className:"markdown-compaction-message",children:o.body}):(0,r.jsx)("span",{style:{color:"var(--text-dim)",fontSize:12},children:t("i18n.noSummary")}),(0,r.jsx)(eg,{readFiles:o.readFiles,modifiedFiles:o.modifiedFiles})]})]})})}function eg({readFiles:e,modifiedFiles:t}){let{t:n}=(0,P.s)();if(0===e.length+t.length)return null;let i=[];return e.length>0&&i.push(`${e.length} read`),t.length>0&&i.push(`${t.length} modified`),(0,r.jsxs)("details",{className:"compaction-file-details",children:[(0,r.jsx)("summary",{children:n("i18n.fileContext",{details:i.join(", ")})}),t.length>0&&(0,r.jsx)(ex,{title:n("i18n.modifiedFiles"),files:t}),e.length>0&&(0,r.jsx)(ex,{title:n("i18n.readFiles"),files:e})]})}function ex({title:e,files:t}){return(0,r.jsxs)("div",{className:"compaction-file-section",children:[(0,r.jsx)("div",{className:"compaction-file-title",children:e}),(0,r.jsx)("ul",{className:"compaction-file-list",children:t.map(e=>(0,r.jsx)("li",{children:e},e))})]})}function ef({message:e,cwd:t,onOpenFile:n}){var i;let o,{t:s}=(0,P.s)(),l=(0,B.ar)(),d=!1===e.display,[c,u]=(0,a.useState)(!d),[p,h]=(0,a.useState)(!1),[g,x]=(0,a.useState)(!1),f=em(e.content),m="string"==typeof(i=e.content)?[]:i.filter(e=>"image"===e.type),v=void 0!==e.details,b=v?function(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}(e.details):"",y=e.customType||"extension",k=Q(e.timestamp);return(0,r.jsx)("div",{style:{marginBottom:20},children:(0,r.jsxs)("div",{style:{borderRadius:12,overflow:"hidden",background:d?"color-mix(in srgb, var(--assistant-card-glass) 62%, transparent)":"var(--assistant-card-glass)",...K(d?"color-mix(in srgb, var(--assistant-card-glass) 62%, transparent)":"var(--assistant-card-glass)",l),border:"1px solid var(--bubble-border)",boxShadow:"0 1px 2px rgba(15,23,42,0.04), 0 4px 16px -8px rgba(15,23,42,0.10)",opacity:d&&!c?.82:1},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"7px 10px",borderBottom:"1px solid var(--bubble-hairline)",color:"var(--text-muted)",fontSize:11},children:[(0,r.jsx)("span",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)",fontSize:11,fontWeight:650},children:y}),d&&(0,r.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:s("i18n.hiddenExtensionMessage")}),k&&(0,r.jsx)("span",{style:{marginLeft:"auto",color:"var(--text-dim)",fontSize:10},children:k})]}),c?(0,r.jsxs)("div",{style:{padding:"6px 9px"},children:[m.length>0&&(0,r.jsx)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginBottom:8*!!f},children:m.map((e,t)=>{var n;let i=(n=e).source?"base64"===n.source.type?`data:${n.source.media_type};base64,${n.source.data}`:n.source.url??"":n.data?`data:${n.mimeType};base64,${n.data}`:"";return i?(0,r.jsx)($,{src:i,children:(0,r.jsx)("img",{src:i,alt:"",style:{maxWidth:240,maxHeight:240,borderRadius:6,objectFit:"contain",display:"block",border:"1px solid var(--border)"}})},t):null})}),f?(0,r.jsx)(W,{className:"markdown-custom-message",cwd:t,onOpenFile:n,children:f}):(0,r.jsx)("span",{style:{color:"var(--text-dim)",fontSize:12},children:s("i18n.noMessage")})]}):(0,r.jsx)("button",{onClick:()=>u(!0),style:{display:"block",width:"100%",padding:"8px 10px",border:"none",background:"transparent",color:"var(--text-dim)",cursor:"pointer",fontSize:12,textAlign:"left"},children:f?(o=f.replace(/\s+/g," ").trim())?o.length>140?`${o.slice(0,140)}...`:o:"Show extension message":s("i18n.showExtensionMessage")}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"4px 9px",borderTop:"1px solid var(--bubble-hairline)",background:"color-mix(in srgb, var(--tool-bg-glass) 66%, transparent)"},children:[f||b?(0,r.jsx)("button",{onClick:()=>{(0,N.D)(f||b).then(()=>{x(!0),setTimeout(()=>x(!1),1500)})},style:{padding:"3px 7px",border:"none",background:"none",color:g?"var(--accent)":"var(--text-muted)",cursor:"pointer",fontSize:11},children:s(g?"i18n.copied":"i18n.copy")}):null,(v||d)&&(0,r.jsx)("button",{onClick:()=>{d?u(e=>!e):h(e=>!e)},style:{marginLeft:"auto",padding:"3px 7px",border:"none",background:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:11},children:s(d?c?"i18n.collapse":"i18n.expand":p?"i18n.hideDetails":"i18n.showDetails")})]}),v&&(d&&c||!d&&p)&&(0,r.jsx)("pre",{style:{margin:0,padding:"9px 10px",borderTop:"1px solid var(--bubble-hairline)",background:"color-mix(in srgb, var(--assistant-card-glass) 55%, transparent)",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:b})]})})}function em(e){return"string"==typeof e?e:e.filter(e=>"text"===e.type).map(e=>e.text).join("\n")}function ev({content:e}){let t=(e??[]).filter(e=>"object"==typeof e&&null!==e&&"image"===e.type);return 0===t.length?null:(0,r.jsx)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",padding:"8px 10px",borderTop:"1px solid var(--bubble-hairline)"},children:t.map((e,t)=>{let n=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 n?(0,r.jsx)($,{src:n,children:(0,r.jsx)("img",{src:n,alt:"",style:{maxWidth:220,maxHeight:220,borderRadius:6,objectFit:"contain",display:"block",border:"1px solid var(--border)"}})},t):null})})}function eb({message:e,sessionId:t}){let n=(0,B.ar)(),[i,o]=(0,a.useState)(null),[s,l]=(0,a.useState)(!1),[d,c]=(0,a.useState)(null),u=!e.output&&void 0===e.exitCode&&!e.cancelled,p=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=e.truncated&&h&&null===i,x=i??e.output;async function f(){if(h){l(!0),c(null);try{let e=await fetch(h),t=await e.json();t.success?o(t.data?.output??""):c(t.error??"failed")}catch(e){c(String(e))}finally{l(!1)}}}let m=e.excludeFromContext?"bash (local)":"bash",v={type:"toolCall",toolCallId:`bash-${e.timestamp??""}`,toolName:m,input:{command:e.command}},b=u?void 0:{role:"toolResult",toolCallId:v.toolCallId,toolName:m,content:x?[{type:"text",text:x}]:[],isError:p,timestamp:e.timestamp};return(0,r.jsxs)("div",{style:{margin:"6px 0",padding:"4px",borderRadius:"var(--bubble-radius)",...K("var(--assistant-card-glass)",n),border:"1px solid var(--bubble-border)",boxShadow:"0 1px 2px rgba(15,23,42,0.04), 0 4px 16px -8px rgba(15,23,42,0.10)"},children:[(0,r.jsx)(ea,{block:v,result:b}),e.truncated&&h&&(0,r.jsxs)("div",{style:{padding:"4px 10px",fontSize:11,marginTop:-1},children:[g&&(0,r.jsx)("button",{onClick:f,disabled:s,style:{background:"none",border:"none",color:"var(--accent)",cursor:s?"default":"pointer",fontSize:11,padding:0,textDecoration:"underline"},children:s?"loading…":"view full output"}),(0,r.jsx)("a",{href:`${h}&download=1`,style:{marginLeft:10*!!g,color:"var(--accent)",fontSize:11,textDecoration:"underline"},children:"download full output"}),d&&(0,r.jsxs)("span",{style:{marginLeft:6,color:"var(--text-dim)",fontSize:11},children:["(",d,")"]})]})]})}var ey=n(44051);function ek(e){if(!e||"object"!=typeof e||"string"!=typeof e.data||"string"!=typeof e.mimeType||!e.mimeType.startsWith("image/"))return!1;let t=function(e){if(!e||e.length%4!=0)return null;let t=e.endsWith("==")?2:+!!e.endsWith("="),n=e.length-t;for(let t=0;t<n;t+=1){var r;if(!((r=e.charCodeAt(t))>=65&&r<=90||r>=97&&r<=122||r>=48&&r<=57||43===r||47===r))return null}for(let t=n;t<e.length;t+=1)if("="!==e[t])return null;return e.length/4*3-t}(e.data);return null!==t&&t<=0xa00000}let ew=new Map;function ej(e){return{value:e.value,images:e.images.map(e=>({...e}))}}function eS(e){return!e.value&&0===e.images.length}function eC(e){let t=ew.get(e);return t?ej(t):null}function eT(e,t){eS(t)?ew.delete(e):ew.set(e,ej(t))}function eM(e){ew.delete(e)}function eI(e,t){return e.trim()?t.trim()?`${e}
|
|
7
|
-
|
|
8
|
-
${t}`:e:t}function eL(e,t,n,r){let i=[...t??[],...r].filter(ek).slice(0,10).map(({data:e,mimeType:t})=>({data:e,mimeType:t}));return{value:eI(e,n),images:i}}function eR(e,t,n){if(e===t)return n?ej(n):eC(t);let r=eC(e),i=n&&!eS(n)?ej(n):r??(n?ej(n):null),o=eC(t);if(eM(e),!i)return o;let a=o?eL(o.value,o.images,i.value,i.images):i;return eT(t,a),ej(a)}var eE=n(3099),ez=n(23657);let eW="pi-web.drafts.v1";function eP(){return"u">typeof localStorage?localStorage:null}function e$(e){return"object"==typeof e&&null!==e&&"string"==typeof e.id&&"string"==typeof e.content&&"number"==typeof e.updatedAt}function eN(){let e=eP();if(!e)return[];try{let t=e.getItem(eW);if(!t)return[];let n=JSON.parse(t);if(!Array.isArray(n))return[];return n.filter(e$).sort((e,t)=>t.updatedAt-e.updatedAt)}catch{return[]}}function eD(e){let t=eP();if(t)try{t.setItem(eW,JSON.stringify(e))}catch{}}function eB(e,t=Date.now()){let n={id:(0,ez.S)(),content:e,updatedAt:t};return eD([n,...eN()]),n}function eA(e,t,n=Date.now()){let r=eN(),i=r.findIndex(t=>t.id===e);if(i<0)return null;let o={...r[i],content:t,updatedAt:n};return r.splice(i,1),r.unshift(o),eD(r),o}function eF(e){eD(eN().filter(t=>t.id!==e))}function eH(e){return e<10?`0${e}`:String(e)}var eO=n(59767),eU=n.n(eO);function e_(e,t){let n=Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype,"value")?.set;n&&n.call(e,t),e.dispatchEvent(new Event("input",{bubbles:!0}))}function eq(e,t){return null!==e&&t.some(t=>t.id===e)}function eV({items:e,expanded:t,activeItem:n,onToggle:i,onPick:o,onDelete:a,onCancelActive:s,panelRef:l}){return 0===e.length?null:(0,r.jsxs)("div",{ref:l,className:eU().panel,role:"region","aria-label":"TODO 暂存区",children:[(0,r.jsxs)("button",{type:"button",className:`${eU().toggle}${t?` ${eU().toggleOpen}`:""}`,onClick:i,"aria-expanded":t,"aria-label":t?"收起 TODO 列表":"展开 TODO 列表",children:[(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{display:"block",flexShrink:0},children:[(0,r.jsx)("rect",{x:"2",y:"2",width:"12",height:"12",rx:"3"}),(0,r.jsx)("path",{d:"M5.5 8.2l1.8 1.8 3.4-3.6"})]}),(0,r.jsxs)("span",{className:eU().toggleLabel,children:["TODO ",e.length]}),(0,r.jsx)("span",{className:eU().toggleArrow,"aria-hidden":"true",children:t?"▴":"▾"})]}),t&&(0,r.jsxs)("div",{className:eU().expandArea,children:[n&&(0,r.jsxs)("div",{className:eU().activeBar,children:[(0,r.jsx)("span",{className:eU().activeDot}),(0,r.jsx)("span",{className:eU().activeLabel,children:"正在编辑 TODO"}),(0,r.jsx)("button",{type:"button",className:eU().cancelBtn,onClick:s,title:"取消关联(内容保留在输入框)","aria-label":"取消 TODO 关联",children:"✕"})]}),(0,r.jsx)("div",{className:eU().list,children:e.map(e=>(0,r.jsxs)("div",{className:eU().row,children:[(0,r.jsx)("span",{className:eU().content,title:e.content,children:e.content}),(0,r.jsx)("span",{className:eU().time,children:function(e,t=Date.now()){let n=t-e;if(n<6e4)return"刚刚";if(n<36e5)return`${Math.floor(n/6e4)}分钟前`;let r=new Date(e),i=new Date(t),o=new Date(i.getFullYear(),i.getMonth(),i.getDate()).getTime();return e>=o?`${eH(r.getHours())}:${eH(r.getMinutes())}`:e>=o-864e5?"昨天":r.getFullYear()===i.getFullYear()?`${r.getMonth()+1}月${r.getDate()}日`:`${r.getFullYear()}年${r.getMonth()+1}月${r.getDate()}日`}(e.updatedAt)}),(0,r.jsxs)("span",{className:eU().rowActions,children:[(0,r.jsx)("button",{type:"button",className:eU().btn,onClick:()=>o(e.id),title:"回填到输入框","aria-label":"回填到输入框",children:(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("path",{d:"M9 5 H1"}),(0,r.jsx)("polyline",{points:"4 1.5 1 5 4 8.5"})]})}),(0,r.jsx)("button",{type:"button",className:`${eU().btn} ${eU().btnDanger}`,onClick:()=>a(e.id),title:"删除 TODO","aria-label":"删除 TODO",children:(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,r.jsx)("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"}),(0,r.jsx)("line",{x1:"10",y1:"11",x2:"10",y2:"17"}),(0,r.jsx)("line",{x1:"14",y1:"11",x2:"14",y2:"17"})]})})]})]},e.id))})]})]})}function eJ(){let[e,t]=(0,a.useState)([]),[n,i]=(0,a.useState)(null),[o,s]=(0,a.useState)(!1),l=(0,a.useRef)(null);(0,a.useEffect)(()=>{if(!o)return;let e=e=>{l.current&&!l.current.contains(e.target)&&s(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[o]);let d=(0,a.useRef)(e),c=(0,a.useRef)(n);(0,a.useEffect)(()=>{d.current=e},[e]),(0,a.useEffect)(()=>{c.current=n},[n]),(0,a.useEffect)(()=>{t(eN())},[]);let u=(0,a.useCallback)(()=>t(eN()),[]);(0,a.useEffect)(()=>{let e=e=>{let t=e.target;t instanceof HTMLTextAreaElement&&!t.value.trim()&&c.current&&i(null)};return document.addEventListener("input",e,!0),()=>document.removeEventListener("input",e,!0)},[]),(0,a.useEffect)(()=>{let e=e=>{if(e.isComposing||!(e.ctrlKey||e.metaKey)||e.altKey||e.shiftKey)return;let t=document.activeElement instanceof HTMLTextAreaElement?document.activeElement:null;if(t){if("s"===e.key.toLowerCase()){if(e.preventDefault(),!t.value.trim())return;let n=c.current;eq(n,d.current)?eA(n,t.value):eB(t.value),i(null),u(),e_(t,"");return}if("Delete"===e.key){e.preventDefault();let n=c.current;eq(n,d.current)&&(eF(n),i(null),u()),e_(t,"");return}"Enter"===e.key&&!e.shiftKey&&c.current&&setTimeout(()=>{t.value.trim()||i(null)},0)}};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[u]);let p=(0,a.useCallback)(e=>{let t=d.current.find(t=>t.id===e);if(!t)return;let n=document.activeElement instanceof HTMLTextAreaElement?document.activeElement:document.querySelector("textarea");if(n){if(n.value.trim()){let e=c.current;eq(e,d.current)?eA(e,n.value):eB(n.value)}i(e),u(),e_(n,t.content),n.focus()}},[u]),h=(0,a.useCallback)(e=>{eF(e),c.current===e&&i(null),u()},[u]);if(0===e.length)return null;let g=null!==n?e.find(e=>e.id===n)??null:null;return(0,r.jsx)(eV,{items:e,expanded:o,activeItem:g,onToggle:()=>s(e=>!e),onPick:p,onDelete:h,onCancelActive:()=>i(null),panelRef:l})}var eK=n(23584);let eY={error:"#ef4444",warning:"#d97706",success:"#10b981",info:"var(--accent)"};function eG({quota:e}){if("balance"===e.kind)return(0,r.jsx)("span",{style:{whiteSpace:"nowrap",flexShrink:0},children:e.text});if(0===e.items.length)return null;let t=e.items.map(e=>e.detail??`${e.label} ${Math.round(100*e.pct)}%`).join("\n");return(0,r.jsx)("span",{title:t,style:{display:"inline-flex",alignItems:"center",gap:8,flexShrink:0},children:e.items.map(e=>{var t;return(0,r.jsxs)("span",{style:{whiteSpace:"nowrap",display:"inline-flex",alignItems:"center",gap:3},children:[(0,r.jsx)("span",{"aria-hidden":!0,style:{flexShrink:0,width:5,height:5,borderRadius:"50%",background:(t=e.pct)>.8?eY.error:t>.5?eY.warning:eY.success}}),e.label," ",e.text]},e.label)})})}function eX({state:e,isDark:t}){return(0,r.jsx)(q.KV,{state:e,size:20,theme:t?"dark":"light",style:t?void 0:{filter:"brightness(0.57) contrast(1.15)"}})}function eZ({notice:e,onDismissError:t,isDark:n,silent:i,style:o}){if(i||!e)return null;if("idle"===e.level)return e.quota?(0,r.jsx)("span",{style:{color:"var(--text-muted)",...o},children:(0,r.jsx)(eG,{quota:e.quota})}):null;let a="error"===e.level;return(0,r.jsxs)("span",{role:"status","aria-live":"polite",style:{display:"inline-flex",alignItems:"center",gap:6,minWidth:0,overflow:"hidden",color:"var(--text)",fontSize:12,fontFamily:"var(--font-mono)",...o},children:[a?(0,r.jsx)(eX,{state:"breathing",isDark:n}):(0,r.jsx)("span",{"aria-hidden":"true",style:{flexShrink:0,width:5,height:5,borderRadius:"50%",background:eY[e.kind]??eY.info}}),(0,r.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.text}),a&&(0,r.jsx)("button",{onClick:t,title:"关闭","aria-label":"关闭错误提示",style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:18,height:18,padding:0,background:"none",border:"none",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",fontSize:11,lineHeight:1},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:"✕"})]})}function eQ({phase:e,modelSlot:t,right:n,quota:i,isDark:o}){let a=null;return e?a=(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(eX,{state:e.orb,isDark:o}),(0,r.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:12,fontFamily:"var(--font-mono)",lineHeight:"20px",color:"var(--text-muted)"},children:e.text})]}):t&&(a=t),(0,r.jsxs)("div",{role:"status","aria-live":"polite",style:{display:"flex",alignItems:"center",gap:8,height:26,minHeight:26,padding:"0 6px",minWidth:0},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1,minWidth:0,height:20},children:[a,i&&!e&&(0,r.jsx)("span",{style:{flexShrink:0,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:12,fontFamily:"var(--font-mono)",lineHeight:"20px",color:"var(--text-dim)"},children:(0,r.jsx)(eG,{quota:i})})]}),null!=n&&(0,r.jsx)("div",{style:{display:"flex",alignItems:"center",gap:6,flexShrink:0,minHeight:20},children:n})]})}let e0="pi-model-id-display";function e1(){try{return window.localStorage}catch{return null}}let e2=["off","read-only","default","full"],e4={off:"none","read-only":"read-only",default:"default",full:"full"},e8=new Intl.Collator(void 0,{numeric:!0,sensitivity:"base"});function e5(e,t){return e8.compare(e.name||e.modelId,t.name||t.modelId)||e8.compare(e.provider,t.provider)||e8.compare(e.modelId,t.modelId)}let e6=["auto","off","minimal","low","medium","high","xhigh","max"],e3={auto:"chat.thinkingUseDefault",off:"chat.thinkingOff",minimal:"chat.thinkingMinimal",low:"chat.thinkingLow",medium:"chat.thinkingMedium",high:"chat.thinkingHigh",xhigh:"chat.thinkingXhigh",max:"chat.thinkingMax"};function e7(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${Math.round(e/1e3)}k`:e.toLocaleString()}let e9=[{name:"compact",description:"chat.commandCompact",source:"builtin"},{name:"reload",description:"chat.commandReload",source:"builtin"},{name:"name",description:"chat.commandName",source:"builtin"},{name:"session",description:"chat.commandSession",source:"builtin",availableWhileStreaming:!0},{name:"copy",description:"chat.commandCopy",source:"builtin",availableWhileStreaming:!0}];function te(e){let t=e.trim().match(/^\/([^\s]+)(?:\s|$)/);if(t)return e9.find(e=>e.name===t[1])}function tt(e){return te(e)?.availableWhileStreaming===!0}let tn=["builtin","extension","prompt","skill"],tr={builtin:"chat.builtIn",extension:"chat.extensions",prompt:"chat.prompts",skill:"chat.skills"},ti={builtin:0,extension:1,prompt:2,skill:3};function to(e,t,n){let r=e.name.toLowerCase(),i=ta(e,n).toLowerCase();return r===t?0:r.startsWith(t)?1:r.includes(t)?2:i.includes(t)?3:4}function ta(e,t){return"builtin"===e.source?t(e.description):e.description??""}function ts(e,t){return"skill"===e.source&&!!e.name.startsWith("skill:")&&!0===t[e.name.slice(6)]}async function tl(e){let t=await createImageBitmap(e).catch(()=>null);if(!t)return{data:btoa(String.fromCharCode(...new Uint8Array(await e.arrayBuffer()))),mimeType:e.type};let n=Math.max(t.width,t.height),r=n>1024?1024/n:1,i=Math.max(1,Math.round(t.width*r)),o=Math.max(1,Math.round(t.height*r)),a=document.createElement("canvas");a.width=i,a.height=o;let s=a.getContext("2d");return s?(s.drawImage(t,0,0,i,o),t.close(),{data:a.toDataURL("image/jpeg",.85).split(",")[1]??"",mimeType:"image/jpeg"}):(t.close(),{data:btoa(String.fromCharCode(...new Uint8Array(await e.arrayBuffer()))),mimeType:e.type})}function td(e){return{data:e.data,mimeType:e.mimeType}}function tc(e){return{...e,previewUrl:`data:${e.mimeType};base64,${e.data}`}}function tu(e){return(e??[]).filter(ek).slice(0,10).map(tc)}function tp(e){e.previewUrl.startsWith("blob:")&&URL.revokeObjectURL(e.previewUrl)}function th({kind:e,text:t}){return(0,r.jsxs)("div",{title:t,style:{display:"flex",alignItems:"center",gap:6,padding:"1px 8px",fontSize:12,color:"var(--text-muted)",minWidth:0},children:[(0,r.jsx)("span",{style:{flexShrink:0,fontSize:10,fontFamily:"var(--font-mono)",padding:"0 5px",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:e}),(0,r.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t})]})}function tg({tone:e,title:t,body:n}){let[i,o]=(0,a.useState)(!1);if((0,a.useEffect)(()=>{o(!1)},[t,n]),i)return null;let s="error"===e?"#ef4444":"#f59e0b";return(0,r.jsxs)("div",{role:"alert",style:{position:"relative",marginBottom:8,padding:"8px 30px 8px 12px",borderRadius:10,border:`1px solid color-mix(in srgb, ${s} 45%, transparent)`,background:"color-mix(in srgb, var(--glass-bg-strong) 60%, transparent)",backdropFilter:"blur(var(--glass-blur-popover)) saturate(var(--glass-saturate))",WebkitBackdropFilter:"blur(var(--glass-blur-popover)) saturate(var(--glass-saturate))",color:"var(--text)",fontSize:12,lineHeight:1.5,boxShadow:"0 2px 12px -4px rgba(15,23,42,0.16)",animation:"notice-shelf-in 0.18s ease-out both"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[(0,r.jsx)("span",{style:{flexShrink:0,width:6,height:6,borderRadius:"50%",marginTop:6,background:s}}),(0,r.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,r.jsx)("div",{style:{fontWeight:600},children:t}),(0,r.jsx)("div",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",overflowWrap:"anywhere"},children:n})]})]}),(0,r.jsx)("button",{type:"button","aria-label":"Dismiss",onClick:()=>o(!0),style:{position:"absolute",top:6,right:6,display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,border:"none",background:"transparent",color:"var(--text-dim)",cursor:"pointer",borderRadius:5},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)"},children:(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:(0,r.jsx)("path",{d:"M1 1l8 8M9 1l-8 8"})})})]})}function tx({error:e}){return e?(0,r.jsx)(tg,{tone:"error",title:"Model error",body:e}):null}function tf({warnings:e}){return e&&0!==e.length?(0,r.jsx)(tg,{tone:"warning",title:e.length>1?"Model scope warnings":"Model scope warning",body:e.join("\n")}):null}let tm=(0,a.forwardRef)(function({onSend:e,onAbort:t,onSteer:n,onFollowUp:i,isStreaming:o,model:s,isAutoModelSelection:l,modelNames:d,modelList:c,modelError:u,modelScopeWarnings:p,onModelChange:h,modelSwitching:g,modelsLoading:x,onCompact:f,onAbortCompaction:m,isCompacting:v,compactError:b,toolPreset:k,onToolPresetChange:w,commandBusy:j=!1,thinkingLevel:S,onThinkingLevelChange:C,availableThinkingLevels:T,thinkingLevelMap:M,queuedMessages:I,inputHistory:L=[],onRecallQueue:R,phase:E=null,quota:z=null,slashCommands:W,slashCommandsLoading:$,onLoadSlashCommands:N,onBuiltinCommand:B,soundEnabled:F,onSoundToggle:H,onAudioUnlock:O,onPromptWithStreamingBehavior:_,draftKey:q,cwd:V,taskName:J,atBottom:K=!0,onScrollToBottom:Y},G){let X,Z,Q,ee,et,en,er,ei,eo,ea,es,el,{t:ed}=(0,P.s)(),ec=(0,A.a)(),{isDark:eu}=(0,D.D)(),{fontSize:ep}=(0,eK.Uh)(),[eh,eg]=(0,a.useState)(!1),[ex,ef]=(0,a.useState)(()=>q?eC(q)?.value??"":""),[em,ev]=(0,a.useState)(!1);(0,a.useEffect)(()=>{ev(!1)},[b]);let[eb,ey]=(0,a.useState)(!1),[ew,ej]=(0,a.useState)(null),[eS,ez]=(0,a.useState)(""),[eW,eP]=(0,a.useState)(()=>(function(e=e1()){if(!e)return!1;try{return"1"===e.getItem(e0)}catch{return!1}})()),[e$,eN]=(0,a.useState)(!1),[eD,eB]=(0,a.useState)(!1),[eA,eF]=(0,a.useState)(!1),[eH,eO]=(0,a.useState)(()=>q?tu(eC(q)?.images):[]),[eU,e_]=(0,a.useState)(!1),eq=ex.trimStart(),eV=0===eH.length&&eq.startsWith("!"),eY=eV&&eq.startsWith("!!"),[eG,eX]=(0,a.useState)(!1),[eZ,e7]=(0,a.useState)(0),[tc,tm]=(0,a.useState)(null),[tv,tb]=(0,a.useState)(null),[ty,tk]=(0,a.useState)(!1),[tw,tj]=(0,a.useState)(0),[tS,tC]=(0,a.useState)(!1),[tT,tM]=(0,a.useState)(0),[tI,tL]=(0,a.useState)(null),[tR,tE]=(0,a.useState)(!1),[tz,tW]=(0,a.useState)(null),[tP,t$]=(0,a.useState)(null),tN=V&&tP?.cwd===V?tP.values:{},tD=(0,a.useRef)(null),tB=(0,a.useRef)(null),tA=(0,a.useRef)(null),tF=(0,a.useRef)(null),tH=(0,a.useRef)(null),tO=(0,a.useRef)(null),tU=(0,a.useRef)(null),t_=(0,a.useRef)(null),tq=(0,a.useRef)(null),tV=(0,a.useRef)(null),tJ=(0,a.useRef)(null),tK=(0,a.useRef)(!1),tY=(0,a.useRef)(0),tG=(0,a.useRef)(!1),tX=(0,a.useRef)(null),tZ=(0,a.useRef)([]),tQ=(0,a.useRef)([]),t0=(0,a.useRef)([]),t1=(0,a.useRef)(null),t2=(0,a.useRef)(null),t4=(0,a.useRef)(q),t8=(0,a.useRef)(ex),t5=(0,a.useRef)(eH),t6=(0,a.useRef)(0);t8.current=ex,t5.current=eH;let t3=eH.length>0&&!l&&!function(e,t){if(!e)return!0;let n=t?.find(t=>t.provider===e.provider&&t.id===e.modelId);return!n||!n.input||n.input.includes("image")}(s,c);(0,a.useImperativeHandle)(G,()=>({insertIfEmpty(e){let t=tD.current;(t?t.value:ex).trim()||(t8.current=e,ef(e),tb(null),requestAnimationFrame(()=>{t&&(t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)}))},replaceMessage(e){var t,n;let r=tD.current,i=r?r.value:ex,o="string"==typeof e.content?e.content:e.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n"),a=tu("string"==typeof e.content?[]:e.content.flatMap(e=>{if("image"!==e.type)return[];let t=e.source?.type==="base64"?e.source.data:e.data,n=e.source?.type==="base64"?e.source.media_type:e.mimeType;if("string"!=typeof t||"string"!=typeof n)return[];let r={data:t,mimeType:n};return ek(r)?[r]:[]}));if(t=t5.current.length,n=t6.current,i.trim()||0!==t||0!==n){let e=[o,i].filter(e=>e.trim()).join("\n\n");t8.current=e,ef(e),tb(null),tC(!1),a.length>0&&eO(e=>{let t=Math.max(0,10-a.length),n=e.slice(0,t);e.slice(t).forEach(tp);let r=[...a,...n];return t5.current=r,r})}else t8.current=o,t5.current=a,ef(o),tb(null),tC(!1),eO(e=>(e.forEach(tp),a));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=tD.current,n=[e,t?t.value:ex].filter(e=>e.trim()).join("\n\n");t8.current=n,ef(n),tb(null),requestAnimationFrame(()=>{t&&(t.focus(),t.setSelectionRange(n.length,n.length),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)})},rekeyDraft(e,t){if(e===t)return;if(t4.current!==e)return void eR(e,t);let n={value:t8.current,images:t5.current.map(td)},r=eR(e,t,n)??{value:"",images:[]},i=r.value===n.value&&r.images.length===n.images.length&&r.images.every((e,t)=>e.data===n.images[t]?.data&&e.mimeType===n.images[t]?.mimeType);if(t4.current=t,i)return;let o=tu(r.images);t8.current=r.value,t5.current=o,ef(r.value),eO(e=>(e.forEach(tp),o)),tb(null),tC(!1)},restoreSubmission(e,t,n){if(!e.trim()&&!t?.length)return;let r=t4.current,i=n??r,o=i===r,a=!o&&i?eC(i):null,s=eL(e,t,o?t8.current:a?.value??"",o?t5.current.map(td):a?.images??[]);if(i&&eT(i,s),!o)return;let l=t?.length?[...tu(t).slice(0,Math.max(0,10-t5.current.length)),...t5.current].slice(0,10):t5.current;t8.current=s.value,t5.current=l,ef(t=>{let n=eI(e,t);return t8.current=n,n}),tb(null),tC(!1),t?.length&&eO(e=>{let n=Math.max(0,10-e.length),r=tu(t).slice(0,n),i=r.length>0?[...r,...e]:e;return t5.current=i,i}),requestAnimationFrame(()=>{let e=tD.current;e&&(e.focus(),e.setSelectionRange(e.value.length,e.value.length),e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)})},insertText(e){let t=tD.current;if(!t)return void ef(t=>t+(t?" ":"")+e);let n=t.selectionStart??t.value.length,r=t.selectionEnd??t.value.length,i=t.value.slice(0,n),o=t.value.slice(r),a=i.length>0&&!i.endsWith(" ")?" ":"",s=i+a+e+o;t8.current=s,ef(s),tb(null),requestAnimationFrame(()=>{if(!t)return;let r=n+a.length+e.length;t.setSelectionRange(r,r),t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`})},addImages(e){t7(e)}}));let t7=(0,a.useCallback)(async e=>{let t=Math.max(0,10-t5.current.length-t6.current),n=e.filter(e=>e.type.startsWith("image/")&&e.size<=0xa00000).slice(0,t);if(n.length){t6.current+=n.length;try{let e=await Promise.all(n.map(async e=>{let t=await tl(e);return{data:t.data,mimeType:t.mimeType,previewUrl:URL.createObjectURL(e)}}));eO(t=>{let n=e.slice(0,Math.max(0,10-t.length));e.slice(n.length).forEach(tp);let r=[...t,...n];return t5.current=r,r})}finally{t6.current-=n.length}}},[]),t9=(0,a.useCallback)(e=>{eO(t=>{let n=[...t],[r]=n.splice(e,1);return r&&tp(r),t5.current=n,n})},[]),ne=(0,a.useCallback)(()=>{t5.current=[],eO(e=>(e.forEach(tp),[]))},[]),nt=(0,a.useCallback)(()=>{t8.current="",ef(""),tb(null),tC(!1),q&&eM(q),t4.current&&t4.current!==q&&eM(t4.current),ne(),tD.current&&(tD.current.style.height="auto")},[ne,q]);(0,a.useEffect)(()=>{q&&t4.current===q&&eT(q,{value:ex,images:eH.map(td)})},[eH,q,ex]),(0,a.useEffect)(()=>{let e=t4.current;if(e===q)return;e&&eT(e,{value:t8.current,images:t5.current.map(td)});let t=q?eC(q):null;t4.current=q;let n=t?.value??"",r=tu(t?.images);t8.current=n,t5.current=r,ef(n),tb(null),tC(!1),eO(e=>(e.forEach(tp),r))},[q]),(0,a.useEffect)(()=>{let e=tD.current;e&&(e.style.height="auto",ex&&(e.style.height=`${Math.min(e.scrollHeight,200)}px`))},[ex,ep]),(0,a.useEffect)(()=>()=>{t5.current.forEach(tp)},[]);let nn=(0,a.useCallback)(async e=>{if(eH.length||!e.startsWith("/")||!B||!te(e))return!1;nt();let t=await B(e);return t.handled&&t.error&&""===t8.current.trim()&&(t8.current=e,ef(e)),t.handled},[eH.length,nt,B]),nr=(0,a.useCallback)(async()=>{let t=ex.trim();!t&&!eH.length||j||(O?.(),(!o||tt(t))&&await nn(t)||o||(nt(),e(t,eH.length?eH:void 0)))},[ex,eH,o,j,nn,e,nt,O]),ni=ex.startsWith("/")&&!/\s/.test(ex.slice(1))?ex.slice(1).toLowerCase():null,no=null===ni?[]:[...o?e9.filter(e=>e.availableWhileStreaming):e9,...W??[]].filter(e=>{let t=e.name.toLowerCase(),n=ta(e,ed).toLowerCase();return t.includes(ni)||n.includes(ni)}).sort((e,t)=>{let n=to(e,ni,ed)-to(t,ni,ed);return 0!==n?n:ti[e.source]-ti[t.source]||e8.compare(e.name,t.name)}),{commands:na,groups:ns}=(X=0,{commands:(Z=tn.map(e=>{let t=no.filter(t=>t.source===e),n="skill"===e?[...t.filter(e=>!ts(e,tN)),...t.filter(e=>ts(e,tN))]:t;return{source:e,items:n.map(e=>({command:e,index:X++}))}}).filter(e=>e.items.length>0)).flatMap(e=>e.items.map(({command:e})=>e)),groups:Z}),nl=1===no.length?ed(ni?"chat.match":"chat.command"):ed(ni?"chat.matches":"chat.commands",{count:no.length}),nd=!!ex.trim(),nc=(0,a.useCallback)((e,t)=>{if(!V)return void tb(null);let n=t??e.length;tb((0,eE.RO)(e.slice(0,n)))},[V]),nu=tv?.query??null,np=a.useMemo(()=>null!==nu&&tI&&tI.cwd===V?(0,eE.R7)(tI.entries,nu):[],[nu,tI,V]),nh=!!(nu&&tI?.truncated&&tI.cwd===V);(0,a.useEffect)(()=>{if(!nh||!V||!nu)return;let e=setTimeout(()=>{fetch(`/api/file-index?cwd=${encodeURIComponent(V)}&q=${encodeURIComponent(nu)}`).then(e=>{if(!e.ok)throw Error(`file search failed: ${e.status}`);return e.json()}).then(e=>tW({cwd:V,query:nu,matches:e.matches??[]})).catch(()=>{})},150);return()=>clearTimeout(e)},[nh,nu,V]);let ng=nh&&null!==tz&&tz.cwd===V&&tz.query===nu,nx=ng?tz.matches:np,nf=null===tv?null:`${tv.start}:${+!!tv.quoted}:${tv.query}`;(0,a.useEffect)(()=>{if(null===nf){tk(!1),tj(0);return}tk(!0),tj(0)},[nf]);let nm=null!==tv;(0,a.useEffect)(()=>{if(!nm||!V)return;let e=t1.current;e&&e.cwd===V&&Date.now()-e.fetchedAt<1e4||t2.current===V||(t2.current=V,tE(!0),fetch(`/api/file-index?cwd=${encodeURIComponent(V)}`).then(e=>{if(!e.ok)throw Error(`file index failed: ${e.status}`);return e.json()}).then(e=>{tL({cwd:V,entries:(0,eE.Yh)(e.files??[]),truncated:!!e.truncated}),t1.current={cwd:V,fetchedAt:Date.now()}}).catch(()=>{t1.current=null}).finally(()=>{t2.current=null,tE(!1)}))},[nm,V]);let nv=(0,a.useCallback)(e=>{if(!tv)return;let t=tD.current,n=t?.selectionStart??ex.length,r=ex.slice(0,tv.start),i=ex.slice(n);tv.quoted&&i.startsWith('"')&&(i=i.slice(1));let o=(0,eE.W)(e.path,e.isDir,tv.quoted),a=r+o.text+i,s=r.length+o.cursorOffset;ef(a),tb((0,eE.RO)(a.slice(0,s))),requestAnimationFrame(()=>{let e=tD.current;e&&(e.focus(),e.setSelectionRange(s,s),e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)})},[tv,ex]);(0,a.useEffect)(()=>{tw>=nx.length&&tj(Math.max(0,nx.length-1))},[nx.length,tw]),(0,a.useEffect)(()=>{tQ.current.length=nx.length},[nx.length]),(0,a.useEffect)(()=>{ty&&tQ.current[tw]?.scrollIntoView({block:"nearest",inline:"nearest"})},[tw,ty]),(0,a.useEffect)(()=>{tT>=L.length&&tM(Math.max(0,L.length-1))},[L.length,tT]),(0,a.useEffect)(()=>{t0.current.length=L.length},[L.length]),(0,a.useEffect)(()=>{tS&&t0.current[tT]?.scrollIntoView({block:"nearest",inline:"nearest"})},[tT,tS]);let nb=(0,a.useCallback)(e=>{ef(e),tC(!1),tM(0),tb(null),requestAnimationFrame(()=>{let t=tD.current;t&&(t.focus(),t.setSelectionRange(e.length,e.length),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)})},[]),ny=(0,a.useCallback)(e=>{let t=`/${e.name} `;ef(t),eX(!1),e7(0),requestAnimationFrame(()=>{let e=tD.current;e&&(e.focus(),e.setSelectionRange(t.length,t.length),e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)})},[]),nk=(0,a.useCallback)(e=>{let t=ex.trim();if(t||eH.length){if(O?.(),!eH.length&&B&&tt(t))return void nn(t);if(t.startsWith("/")&&_){nt(),_(t,"steer"===e?"steer":"followUp",eH.length?eH:void 0);return}nt(),"steer"===e&&n?n(t,eH.length?eH:void 0):"followup"===e&&i&&i(t,eH.length?eH:void 0)}},[ex,eH,B,_,n,i,nt,O,nn]),nw=()=>o?(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:ec?6:8,minWidth:0,flexShrink:0},children:[(0,r.jsxs)("button",{onClick:t,title:ed("chat.stopAgent"),"aria-label":ed("chat.stopAgent"),onMouseEnter:e=>{e.currentTarget.style.color="#dc2626"},onMouseLeave:e=>{e.currentTarget.style.color="#ef4444"},style:{display:"flex",alignItems:"center",gap:5,flexShrink:0,whiteSpace:"nowrap",padding:0,background:"transparent",border:"none",color:"#ef4444",cursor:"pointer",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",transition:"color 0.12s"},children:[(0,r.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 12 12",fill:"none","aria-hidden":"true",style:{flexShrink:0},children:(0,r.jsx)("rect",{x:"1.5",y:"1.5",width:"9",height:"9",rx:"2",fill:"currentColor"})}),ed("chat.stop")]}),nd&&n&&(0,r.jsxs)("button",{onClick:()=>nk("steer"),title:"Interrupt the current run and inject this message now",onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)"},style:{display:"flex",alignItems:"center",gap:5,flexShrink:0,whiteSpace:"nowrap",padding:0,background:"transparent",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",transition:"color 0.12s"},children:[(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("path",{d:"M7 3 L11 7 L7 11"}),(0,r.jsx)("line",{x1:"3",y1:"7",x2:"11",y2:"7"})]}),ed("chat.steer")]}),nd&&i&&(0,r.jsxs)("button",{onClick:()=>nk("followup"),title:`Queue this message after the agent finishes (${ec?"Ctrl/Cmd+":""}Alt/Option+Enter)`,"aria-keyshortcuts":ec?"Control+Alt+Enter Meta+Alt+Enter":"Alt+Enter",onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)"},style:{display:"flex",alignItems:"center",gap:5,flexShrink:0,whiteSpace:"nowrap",padding:0,background:"transparent",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",transition:"color 0.12s"},children:[(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("line",{x1:"7",y1:"3",x2:"7",y2:"8"}),(0,r.jsx)("polyline",{points:"4.5 5.5 7 3 9.5 5.5"}),(0,r.jsx)("line",{x1:"4",y1:"11",x2:"10",y2:"11"})]}),ed("chat.followUp")]})]}):(0,r.jsxs)("button",{onClick:nr,disabled:!ex.trim()&&!eH.length||j,style:{flexShrink:0,whiteSpace:"nowrap",display:"flex",alignItems:"center",gap:6,padding:0,background:"transparent",border:"none",color:(ex.trim()||eH.length)&&!j?"var(--text-muted)":"var(--text-dim)",cursor:(ex.trim()||eH.length)&&!j?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",transition:"color 0.12s",marginLeft:6},onMouseEnter:e=>{e.currentTarget.disabled||(e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.disabled||(e.currentTarget.style.color="var(--text-muted)")},children:[(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("line",{x1:"2",y1:"7",x2:"11",y2:"7"}),(0,r.jsx)("polyline",{points:"7.5 3 12 7 7.5 11"})]}),ed("chat.send")]}),nj=(0,a.useCallback)(e=>{let t=na.length-1;if(t<0)return 0;if("left"===e)return Math.max(0,eZ-1);if("right"===e)return Math.min(t,eZ+1);let n=tZ.current[eZ];if(!n)return"down"===e?Math.min(t,eZ+1):Math.max(0,eZ-1);let r=n.getBoundingClientRect(),i=r.left+r.width/2,o=r.top+r.height/2,a=-1,s=1/0;for(let n=0;n<=t;n+=1){if(n===eZ)continue;let t=tZ.current[n];if(!t)continue;let r=t.getBoundingClientRect(),l=r.top+r.height/2-o;if("down"===e?l<=4:l>=-4)continue;let d=1e3*Math.abs(l)+Math.abs(r.left+r.width/2-i);d<s&&(a=n,s=d)}return a>=0?a:"down"===e?Math.min(t,eZ+1):Math.max(0,eZ-1)},[na.length,eZ]),nS=(0,a.useCallback)(e=>{let r=e.nativeEvent,a="Enter"===e.key&&!e.shiftKey&&(!ec||e.ctrlKey||e.metaKey),s=Date.now()-tY.current<100,l=tK.current||r.isComposing||229===r.keyCode;if(a&&(l||s)){s&&e.preventDefault();return}if(tS&&!l){if("ArrowDown"===e.key){e.preventDefault(),tM(e=>Math.min(Math.max(0,L.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(),tC(!1);return}if(("Tab"===e.key||a)&&L[tT]){e.preventDefault(),nb(L[tT]);return}}if(eG&&null!==ni){if("ArrowDown"===e.key){e.preventDefault(),e7(nj("down"));return}if("ArrowUp"===e.key){e.preventDefault(),e7(nj("up"));return}if("ArrowRight"===e.key){e.preventDefault(),e7(nj("right"));return}if("ArrowLeft"===e.key){e.preventDefault(),e7(nj("left"));return}if("Escape"===e.key){e.preventDefault(),eX(!1);return}let t=na[eZ];if("Tab"===e.key&&t){e.preventDefault(),ny(t);return}if(a&&t){var d;(e.preventDefault(),o&&("builtin"!==t.source||!0!==t.availableWhileStreaming)||(d=t.name,ex.trim()!==`/${d}`))?ny(t):(eX(!1),nr());return}}if(ty&&null!==tv&&!l){if("ArrowDown"===e.key){e.preventDefault(),tj(e=>Math.min(Math.max(0,nx.length-1),e+1));return}if("ArrowUp"===e.key){e.preventDefault(),tj(e=>Math.max(0,e-1));return}if("Escape"===e.key){e.preventDefault(),tk(!1);return}if(("Tab"===e.key||a)&&nx[tw]){e.preventDefault(),nv(nx[tw]);return}}if("ArrowUp"===e.key&&!l&&!o&&L.length>0&&0===ex.trim().length){e.preventDefault(),eX(!1),tk(!1),tM(L.length-1),tC(!0);return}if("Escape"===e.key&&!l&&o&&t){e.preventDefault(),t();return}a&&(e.preventDefault(),o&&(n||i)?nk(e.altKey&&i||!n?"followup":"steer"):nr())},[ec,o,n,i,t,eG,ni,na,eZ,ny,nk,nr,nj,ty,tv,nx,tw,nv,tS,L,tT,nb,ex]),nC=(0,a.useCallback)(()=>{let e=tD.current;e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[]),nT=(0,a.useCallback)(e=>{let t=Array.from(e.clipboardData?.items??[]).filter(e=>e.type.startsWith("image/"));if(t.length>0){e.preventDefault(),t7(t.map(e=>e.getAsFile()).filter(e=>null!==e));return}let n=(0,y.Gm)(e.clipboardData,{fallbackToFileName:!0});if(n.length>0){e.preventDefault();let t=(0,y.ph)(n),r=tD.current,i=r?.selectionStart??ex.length,o=r?.selectionEnd??ex.length;ef(ex.slice(0,i)+t+ex.slice(o)),requestAnimationFrame(()=>{if(r){let e=i+t.length;r.selectionStart=e,r.selectionEnd=e,nC()}})}},[t7,ex,nC]);(0,a.useEffect)(()=>{if(null===ni){eX(!1),e7(0),tG.current=!1;return}eX(!0),e7(0),!tG.current&&N&&(tG.current=!0,Promise.resolve(N()).catch(()=>{tG.current=!1}))},[ni,N]),(0,a.useEffect)(()=>{if(!eG||!V)return;let e=!1;return t$({cwd:V,values:{}}),fetch(`/api/skills?cwd=${encodeURIComponent(V)}`).then(e=>{if(!e.ok)throw Error(`skills fetch failed: ${e.status}`);return e.json()}).then(t=>{if(e)return;let n={};for(let e of t.skills??[])n[e.name]=e.disableModelInvocation;t$({cwd:V,values:n})}).catch(()=>{e||t$({cwd:V,values:{}})}),()=>{e=!0}},[eG,V]),(0,a.useEffect)(()=>{eZ>=na.length&&e7(Math.max(0,na.length-1))},[na.length,eZ]),(0,a.useEffect)(()=>{tZ.current.length=na.length},[na.length]),(0,a.useEffect)(()=>{eG&&tZ.current[eZ]?.scrollIntoView({block:"nearest",inline:"nearest"})},[eZ,eG]),(0,a.useLayoutEffect)(()=>{if(!eG||null===ni)return void tm(null);let e=tX.current;if(!e)return;let t=null,n=()=>{t=null;let n=function(e,t,n=8){return Math.max(0,Math.floor(e-t-n))}(e.getBoundingClientRect().bottom,function(e){let t=window.visualViewport?.offsetTop??0;for(let n=e.parentElement;n;n=n.parentElement){let e=window.getComputedStyle(n).overflowY;("auto"===e||"scroll"===e||"hidden"===e||"clip"===e)&&(t=Math.max(t,n.getBoundingClientRect().top+n.clientTop))}return t}(e));tm(e=>e===n?e:n)},r=()=>{null!==t&&cancelAnimationFrame(t),t=requestAnimationFrame(n)};n();let i="u">typeof ResizeObserver&&e.parentElement?new ResizeObserver(r):null;e.parentElement&&i?.observe(e.parentElement);let o=window.visualViewport;return o?.addEventListener("resize",r),o?.addEventListener("scroll",r),window.addEventListener("resize",r),window.addEventListener("scroll",r,!0),()=>{i?.disconnect(),o?.removeEventListener("resize",r),o?.removeEventListener("scroll",r),window.removeEventListener("resize",r),window.removeEventListener("scroll",r,!0),null!==t&&cancelAnimationFrame(t)}},[eG,ni]);let nM=c&&c.length>0?c.map(e=>({provider:e.provider,modelId:e.id,name:e.name})).sort(e5):Object.entries(d??{}).map(([e,t])=>({provider:s?.provider??"unknown",modelId:e,name:t})).sort(e5),nI=(Q=eS.trim().toLocaleLowerCase())?nM.filter(e=>`${e.name} ${e.modelId}`.toLocaleLowerCase().includes(Q)):nM,nL=nM.length>8,nR=[];for(let e of nI){let t=nR.find(t=>t.provider===e.provider);t?t.options.push(e):nR.push({provider:e.provider,options:[e]})}let nE=s?nM.find(e=>e.modelId===s.modelId&&e.provider===s.provider)?.name??s.modelId:null,nz=s?nR.findIndex(e=>e.options.some(e=>e.modelId===s.modelId&&e.provider===s.provider)):-1,nW=eW?s?.modelId??null:nE,nP=x??!1,n$=nM.length>0||nW,nN=(I?.steering.length??0)+(I?.followUp.length??0);(0,a.useEffect)(()=>{if(!eb)return;let e=tF.current;if(!e)return;let t=e.querySelector("[aria-current]");t&&t.scrollIntoView({block:"nearest",inline:"nearest"})},[eb]);let nD=(n$||nP||u)&&h?(0,r.jsxs)("div",{ref:tB,style:{position:"relative",minWidth:0},children:[(0,r.jsx)("button",{onClick:n$&&!g?e=>{let t=e.currentTarget.getBoundingClientRect();ej({top:t.top,left:t.left,width:t.width}),ey(e=>(e&&ez(""),!e))}:void 0,disabled:o||g||nP,"aria-busy":g||void 0,style:{display:"flex",alignItems:"center",gap:6,padding:0,height:20,maxWidth:"100%",minWidth:0,overflow:"hidden",background:"none",border:"none",color:"var(--text-muted)",cursor:o||g?"not-allowed":"pointer",fontSize:12,fontFamily:"var(--font-mono)",lineHeight:"20px",opacity:o?.5:1,transition:"color 0.12s"},onMouseEnter:e=>{o||g||(e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)"},title:g?"Switching model":n$?"Change model":"正在载入模型",children:nP||g?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round","aria-hidden":"true",style:{flexShrink:0,animation:"spin 0.9s linear infinite"},children:(0,r.jsx)("path",{d:"M21 12a9 9 0 1 1-5.7-8.4"})}),(0,r.jsx)("span",{style:{display:"flex",alignItems:"baseline",minWidth:0,overflow:"hidden",whiteSpace:"nowrap"},children:(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:g?"切换模型中":"正在载入模型……"})})]}):(0,r.jsxs)("span",{style:{display:"flex",alignItems:"baseline",minWidth:0,overflow:"hidden",whiteSpace:"nowrap"},children:[(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:nW??(nM.length>0?"Select model":"No models")}),s?.provider&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{"aria-hidden":"true",style:{flexShrink:0,margin:"0 4px",color:"var(--text-dim)"},children:"\xb7"}),(0,r.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:11},children:s.provider})]})]})}),eb&&ew&&(ee=window.visualViewport?.height??window.innerHeight,en=Math.max(Math.min(120,et=Math.max(0,ew.top-8)),Math.min(Math.min(.5*ee,440),et)),er=ec?{left:0,right:0,width:"100%"}:{left:0,width:"max-content",minWidth:ew.width},(0,r.jsxs)("div",{ref:tA,style:{position:"absolute",bottom:"calc(100% + 12px)",...er,zIndex:500,background:"var(--popover-glass)",backdropFilter:"blur(var(--glass-blur-heavy)) saturate(var(--glass-saturate))",WebkitBackdropFilter:"blur(var(--glass-blur-heavy)) saturate(var(--glass-saturate))",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",overflow:"hidden",maxHeight:en,display:"flex",flexDirection:"column"},children:[nL&&(0,r.jsx)("div",{style:{padding:"6px 8px",borderBottom:"1px solid var(--border)",flexShrink:0},children:(0,r.jsx)("input",{value:eS,onChange:e=>ez(e.target.value),onKeyDown:e=>{"Escape"===e.key&&(ez(""),ey(!1))},placeholder:ed("chat.filterModels"),"aria-label":ed("chat.filterModels"),autoFocus:!0,autoComplete:"off",spellCheck:!1,style:{width:"100%",minWidth:220*!ec,fontSize:11,fontFamily:"var(--font-mono)",padding:"5px 8px",border:"1px solid var(--border)",borderRadius:5,outline:"none",background:"var(--bg)",color:"var(--text)",boxSizing:"border-box"}})}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:"6px 10px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,r.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",whiteSpace:"nowrap"},children:ed("chat.showModelId")}),(0,r.jsx)("button",{role:"switch","aria-checked":eW,"aria-label":ed("chat.showModelId"),onClick:()=>{eP(e=>{let t=!e;return!function(e,t=e1()){if(t)try{t.setItem(e0,e?"1":"0")}catch{}}(t),t})},style:{flexShrink:0,width:26,height:15,borderRadius:999,padding:0,border:"none",cursor:"pointer",background:eW?"var(--accent)":"color-mix(in srgb, var(--text) 22%, transparent)",position:"relative",transition:"background 0.15s"},children:(0,r.jsx)("span",{style:{position:"absolute",top:2,left:eW?13:2,width:11,height:11,borderRadius:999,background:"var(--popover-glass)",border:"1px solid var(--border)",transition:"left 0.15s"}})})]}),(0,r.jsx)("div",{style:{minHeight:0,overflowY:"auto"},children:0===nR.length?(0,r.jsx)("div",{style:{padding:"8px 12px",color:"var(--text-dim)",fontSize:12,whiteSpace:"nowrap"},children:eS.trim()?ed("chat.noMatchingModels"):"No available models"}):nR.map((e,t)=>(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column"},children:[nR.length>1&&(0,r.jsx)("div",{style:{padding:"6px 12px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:t>0?"1px solid var(--border)":"none",flexShrink:0},children:e.provider}),(0,r.jsx)("div",{ref:t===nz?tF:void 0,style:{overflowY:"auto",maxHeight:170,flexShrink:0},children:e.options.map(e=>{let t=e.modelId===s?.modelId&&e.provider===s?.provider;return(0,r.jsxs)("button",{onClick:()=>{ey(!1),ez(""),(!t||l)&&h(e.provider,e.modelId)},"aria-current":t?"true":void 0,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:t?"color-mix(in srgb, var(--accent) 14%, transparent)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left",fontWeight:t?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{t||(e.currentTarget.style.background="color-mix(in srgb, var(--text) 8%, transparent)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(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},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}}),eW?e.modelId:e.name]},`${e.provider}:${e.modelId}`)})})]},e.provider))})]}))]}):null,nB="auto"!==(ei=S??"auto")&&M?M[ei]??ei:ei,nA=Object.entries(e4).find(([,e])=>e===(k??"default"))?.[0]??"default";return(0,a.useEffect)(()=>{let e=e=>{tB.current&&!tB.current.contains(e.target)&&tA.current&&!tA.current.contains(e.target)&&(ey(!1),ez("")),tH.current&&!tH.current.contains(e.target)&&tU.current&&!tU.current.contains(e.target)&&eN(!1),tO.current&&!tO.current.contains(e.target)&&t_.current&&!t_.current.contains(e.target)&&eB(!1),tq.current&&!tq.current.contains(e.target)&&eF(!1),!tV.current||tV.current.contains(e.target)||tD.current?.contains(e.target)||tC(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,a.useEffect)(()=>{ec||eF(!1)},[ec]),(0,r.jsxs)("div",{style:{flexShrink:0,background:"transparent",padding:"0 16px 8px",paddingRight:ec?16:52},children:[(0,r.jsx)("input",{ref:tJ,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:e=>{t7(Array.from(e.target.files??[])),e.target.value=""}}),(0,r.jsxs)("div",{style:{maxWidth:"var(--chat-content-max-width, 820px)",margin:"0 auto"},children:[(0,r.jsx)(tx,{error:u}),(0,r.jsx)(tf,{warnings:p}),t3&&(eo=c?.find(e=>e.provider===s?.provider&&e.id===s?.modelId),(0,r.jsx)(tg,{tone:"warning",title:ed("chat.imageNotSupportedTitle"),body:ed("chat.imageNotSupportedBody",{model:eo?.name||s?.modelId||""})})),b&&!em&&(0,r.jsxs)("div",{role:"alert",style:{position:"relative",marginBottom:8,padding:"8px 30px 8px 12px",borderRadius:10,border:"1px solid color-mix(in srgb, #ef4444 45%, transparent)",background:"color-mix(in srgb, var(--glass-bg-strong) 60%, transparent)",backdropFilter:"blur(var(--glass-blur-popover)) saturate(var(--glass-saturate))",WebkitBackdropFilter:"blur(var(--glass-blur-popover)) saturate(var(--glass-saturate))",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:12,lineHeight:1.5,boxShadow:"0 2px 12px -4px rgba(15,23,42,0.16)",animation:"notice-shelf-in 0.18s ease-out both"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[(0,r.jsx)("span",{style:{flexShrink:0,width:6,height:6,borderRadius:"50%",marginTop:5,background:"#ef4444"}}),(0,r.jsx)("div",{style:{minWidth:0,flex:1,whiteSpace:"pre-wrap",wordBreak:"break-word",overflowWrap:"anywhere"},children:b})]}),(0,r.jsx)("button",{type:"button","aria-label":"Dismiss",onClick:()=>ev(!0),style:{position:"absolute",top:6,right:6,display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,border:"none",background:"transparent",color:"var(--text-dim)",cursor:"pointer",borderRadius:5},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)"},children:(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:(0,r.jsx)("path",{d:"M1 1l8 8M9 1l-8 8"})})})]}),(0,r.jsxs)("div",{className:"glass-canvas",style:{position:"relative",borderRadius:ec?14:16,backgroundColor:"var(--frame-glass)",border:`1px solid ${eV?"color-mix(in srgb, var(--accent) 45%, transparent)":o&&(n||i)?"rgba(234,179,8,0.4)":"color-mix(in srgb, var(--border) 90%, transparent)"}`,padding:"4px 8px 8px",boxShadow:eU?"0 0 14px 1px color-mix(in srgb, var(--border) 50%, transparent), 0 1px 2px rgba(15,23,42,0.05), 0 8px 24px -8px rgba(15,23,42,0.24)":"0 1px 2px rgba(15,23,42,0.05), 0 2px 5px rgba(15,23,42,0.04), 0 8px 24px -12px rgba(15,23,42,0.16)",transition:"border-color 0.15s, box-shadow 0.15s"},children:[(0,r.jsx)(eQ,{phase:E,modelSlot:nD,quota:z,isDark:eu,right:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(eJ,{}),!K&&Y&&(0,r.jsx)("button",{type:"button",onClick:()=>Y(),title:ed("chat.scrollToLatest"),"aria-label":ed("chat.scrollToLatest"),style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,marginLeft:2,background:"none",border:"none",borderRadius:6,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:(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:"7 13 12 18 17 13"}),(0,r.jsx)("polyline",{points:"7 6 12 11 17 6"})]})})]})}),nN>0&&(0,r.jsxs)("div",{style:{margin:"0 4px 2px",borderRadius:"var(--bubble-inner-radius)",background:"var(--bubble-tool-bg)",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"3px 8px"},children:[(0,r.jsxs)("button",{onClick:()=>eg(e=>!e),"aria-expanded":eh,onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)"},style:{display:"flex",alignItems:"center",gap:5,flex:1,minWidth:0,fontSize:11,fontFamily:"var(--font-mono)",color:"var(--text-muted)",background:"none",border:"none",cursor:"pointer",padding:0,textAlign:"left",transition:"color 0.12s"},children:[(0,r.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:ed("chat.queued",{count:nN})}),(0,r.jsx)("span",{"aria-hidden":"true",style:{flexShrink:0,fontSize:9,color:"var(--text-dim)"},children:eh?"▴":"▾"})]}),R&&(0,r.jsxs)("button",{onClick:R,title:ed("chat.recallTitle"),style:{display:"flex",alignItems:"center",gap:5,padding:0,fontSize:12,color:"var(--text)",background:"transparent",border:"none",cursor:"pointer",transition:"color 0.12s",whiteSpace:"nowrap"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text)"},children:[(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("polyline",{points:"9 14 4 9 9 4"}),(0,r.jsx)("path",{d:"M20 20v-7a4 4 0 0 0-4-4H4"})]}),ed("chat.recall")]})]}),eh&&(0,r.jsxs)(r.Fragment,{children:[I?.steering.map((e,t)=>(0,r.jsx)(th,{kind:"steer",text:e},`steer-${t}`)),I?.followUp.map((e,t)=>(0,r.jsx)(th,{kind:"follow-up",text:e},`followup-${t}`))]})]}),eH.length>0&&(0,r.jsx)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",padding:"4px 4px 0"},children:eH.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:8,border:"1px solid var(--border)",display:"block"}}),(0,r.jsx)("button",{onClick:()=>t9(t),style:{position:"absolute",top:-4,right:-4,width:16,height:16,borderRadius:"50%",background:"var(--bg-panel)",border:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,color:"var(--text-muted)"},children:(0,r.jsxs)("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,r.jsx)("line",{x1:"1",y1:"1",x2:"7",y2:"7"}),(0,r.jsx)("line",{x1:"7",y1:"1",x2:"1",y2:"7"})]})})]},t))}),(0,r.jsxs)("div",{style:{position:"relative",minWidth:0},children:[tS&&L.length>0&&(0,r.jsxs)("div",{ref:tV,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(44vh, 360px)"},children:[(0,r.jsx)("div",{title:"Input history",style:{height:30,padding:"0 10px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",color:"var(--text-dim)"},children:(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M3 12a9 9 0 1 0 3-6.7"}),(0,r.jsx)("path",{d:"M3 4v5h5"}),(0,r.jsx)("path",{d:"M12 7v5l3 2"})]})}),(0,r.jsx)("div",{style:{maxHeight:"calc(min(44vh, 360px) - 31px)",overflowY:"auto",padding:4},children:L.map((e,t)=>{let n=t===tT;return(0,r.jsxs)("button",{ref:e=>{t0.current[t]=e},type:"button",onMouseDown:t=>{t.preventDefault(),nb(e)},onMouseEnter:()=>tM(t),style:{width:"100%",display:"flex",alignItems:"flex-start",gap:8,padding:"7px 8px",border:"none",borderRadius:6,background:n?"var(--bg-selected)":"none",color:"var(--text)",cursor:"pointer",textAlign:"left",fontSize:12.5,lineHeight:1.45},children:[(0,r.jsx)("span",{style:{flexShrink:0,fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)",paddingTop:1},children:t+1}),(0,r.jsx)("span",{style:{minWidth:0,display:"-webkit-box",WebkitBoxOrient:"vertical",WebkitLineClamp:2,overflow:"hidden",overflowWrap:"anywhere"},children:e})]},`${t}:${e}`)})})]}),eG&&null!==ni&&(0,r.jsxs)("div",{ref:tX,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",boxSizing:"border-box",display:"flex",flexDirection:"column",maxHeight:null===tc?"min(72.8vh, 598px)":`min(72.8vh, 598px, ${tc}px)`},children:[(0,r.jsxs)("div",{style:{padding:"8px 10px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,fontSize:11,color:"var(--text-dim)",flexShrink:0},children:[(0,r.jsx)("span",{children:$?ed("chat.loadingCommands"):ed("chat.slashCommands",{label:nl})}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)"},children:ed("chat.tabEnter")})]}),(0,r.jsx)("div",{style:{flex:"1 1 auto",minHeight:0,overflowY:"auto",padding:10},children:$||0!==no.length?ns.map(e=>(0,r.jsxs)("section",{style:{marginBottom:12},children:[(0,r.jsxs)("div",{style:{position:"sticky",top:-10,zIndex:1,display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,padding:"4px 0 6px",background:"var(--bg)",color:"var(--text-dim)",fontSize:10,fontWeight:600,textTransform:"uppercase"},children:[(0,r.jsx)("span",{children:ed(tr[e.source])}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontWeight:500},children:e.items.length})]}),(0,r.jsx)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:8},children:e.items.map(({command:e,index:t})=>{let n=t===eZ,i=ts(e,tN);return(0,r.jsxs)("button",{ref:e=>{tZ.current[t]=e},type:"button",onMouseDown:t=>{t.preventDefault(),ny(e)},onMouseEnter:()=>e7(t),style:{width:"100%",minWidth:0,minHeight:58,display:"flex",flexDirection:"column",gap:4,justifyContent:"center",padding:"9px 10px",border:`1px solid ${n?"var(--accent)":"var(--border)"}`,borderRadius:7,background:n?"var(--bg-selected)":"var(--bg-panel)",color:"var(--text)",cursor:"pointer",textAlign:"left",boxShadow:n?"0 0 0 1px color-mix(in srgb, var(--accent) 28%, transparent)":"none"},children:[(0,r.jsxs)("span",{style:{fontSize:13,fontFamily:"var(--font-mono)",overflowWrap:"anywhere",wordBreak:"break-word",color:i?"var(--text-dim)":void 0},children:["/",e.name,i&&(0,r.jsx)("span",{style:{marginLeft:6,padding:"0 4px",border:"1px solid var(--border)",borderRadius:3,fontSize:9,color:"var(--text-dim)",whiteSpace:"nowrap"},children:ed("chat.dormant")})]}),e.description&&(0,r.jsx)("span",{style:{display:"-webkit-box",WebkitBoxOrient:"vertical",WebkitLineClamp:2,overflow:"hidden",fontSize:11,lineHeight:1.35,color:"var(--text-dim)"},children:ta(e,ed)})]},`${e.source}:${e.name}`)})})]},e.source)):(0,r.jsx)("div",{style:{padding:"2px 2px 4px",fontSize:12,color:"var(--text-dim)"},children:ed("chat.noCommands")})})]}),ty&&null!==tv&&(ea=tR&&(!tI||tI.cwd!==V),es=1===nx.length?ed("chat.match"):ed("chat.matches",{count:nx.length}),el=tI?.truncated&&!ng?tv.query?ed("chat.searchingAll"):ed("chat.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(48vh, 400px)"},children:[(0,r.jsxs)("div",{style:{padding:"8px 10px",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:ea?ed("chat.loadingFiles"):ed("chat.files",{label:es,hint:el})}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)"},children:ed("chat.tabEnter")})]}),(0,r.jsx)("div",{style:{maxHeight:"calc(min(48vh, 400px) - 34px)",overflowY:"auto",padding:4},children:ea||0!==nx.length?nx.map((e,t)=>{let n=t===tw,i=e.path.split("/").pop()??e.path,o=e.path.slice(0,e.path.length-i.length);return(0,r.jsxs)("button",{ref:e=>{tQ.current[t]=e},type:"button",onMouseDown:t=>{t.preventDefault(),nv(e)},onMouseEnter:()=>tj(t),style:{width:"100%",display:"flex",alignItems:"center",gap:8,padding:"6px 8px",border:"none",borderRadius:6,background:n?"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)(U.sj,{size:14}):(0,U.I3)(i,14)}),(0,r.jsxs)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[o&&(0,r.jsx)("span",{style:{color:"var(--text-dim)"},children:o}),i,e.isDir&&(0,r.jsx)("span",{style:{color:"var(--text-dim)"},children:"/"})]})]},`${e.isDir?"d":"f"}:${e.path}`)}):(0,r.jsx)("div",{style:{padding:"6px 8px",fontSize:12,color:"var(--text-dim)"},children:nh&&!ng?ed("chat.searching"):ed("chat.noMatchingFiles")})})]})),(0,r.jsx)("div",{style:{minWidth:0,position:"relative",display:"flex",gap:8,alignItems:"center",padding:"8px 4px"},children:(0,r.jsx)("textarea",{ref:tD,className:"chat-input-textarea",value:ex,onChange:e=>{t8.current=e.target.value,ef(e.target.value),tC(!1),nc(e.target.value,e.target.selectionStart)},onSelect:e=>{let t=e.currentTarget;nc(t.value,t.selectionStart)},onKeyDown:nS,onCompositionStart:()=>{tK.current=!0},onCompositionEnd:e=>{tK.current=!1,tY.current=Date.now();let t=e.currentTarget;nc(t.value,t.selectionStart)},onInput:nC,onFocus:()=>e_(!0),onBlur:()=>e_(!1),onPaste:nT,placeholder:o&&(n||i)?ed("chat.steerPlaceholder"):o?ed("chat.agentPlaceholder"):J?ed("chat.taskPlaceholder",{task:J}):ed("chat.messagePlaceholder"),rows:1,style:{flex:1,minWidth:0,width:"100%",background:"none",border:"none",outline:"none",resize:"none",color:"var(--text)",fontSize:"var(--chat-content-font-size, 14px)",lineHeight:1.6,fontFamily:"inherit",minHeight:24,maxHeight:200,overflow:"auto"}})})]}),eV&&(0,r.jsxs)("div",{className:"text-xs",style:{color:eY?"var(--text-muted)":"var(--accent)",padding:"2px 8px 4px"},children:[ed("chat.shell")," \xb7 ",eY?ed("chat.outputLocal"):ed("chat.outputModel")]}),(0,r.jsxs)("div",{style:{display:ec?"grid":"flex",gridTemplateColumns:ec?"minmax(0, 1fr) auto":void 0,alignItems:"center",gap:6,padding:"6px 14px 4px",marginTop:4,borderRadius:10,background:"color-mix(in srgb, var(--bg-panel) 45%, transparent)"},children:[(0,r.jsxs)("div",{style:{flex:"1 1 auto",minWidth:0,display:"flex",alignItems:"center",gap:8},children:[(0,r.jsx)("button",{onClick:()=>tJ.current?.click(),title:ed("chat.attachImage"),style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"none",border:"none",borderRadius:9,color:eH.length?"var(--accent)":"var(--text-muted)",cursor:"pointer",opacity:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=eH.length?"var(--accent)":"var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=eH.length?"var(--accent)":"var(--text-muted)"},children:(0,r.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),(0,r.jsx)("circle",{cx:"8.5",cy:"8.5",r:"1.5"}),(0,r.jsx)("polyline",{points:"21 15 16 10 5 21"})]})}),ec&&void 0!==H&&(0,r.jsx)("button",{onClick:H,title:F?ed("chat.disableSound"):ed("chat.enableSound"),"aria-label":F?ed("chat.disableSound"):ed("chat.enableSound"),style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"none",border:"none",borderRadius:9,color:F?"var(--text-muted)":"var(--text-dim)",cursor:"pointer",opacity:F?1:.55,transition:"background 0.12s, color 0.12s, opacity 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)",e.currentTarget.style.opacity="1"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=F?"var(--text-muted)":"var(--text-dim)",e.currentTarget.style.opacity=F?"1":"0.55"},children:F?(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,r.jsx)("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"}),(0,r.jsx)("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"})]}):(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,r.jsx)("line",{x1:"23",y1:"9",x2:"17",y2:"15"}),(0,r.jsx)("line",{x1:"17",y1:"9",x2:"23",y2:"15"})]})}),!ec&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{"aria-hidden":"true",style:{flexShrink:0,width:1,height:18,margin:"0 6px",background:"color-mix(in srgb, var(--border) 70%, transparent)"}}),!o&&C&&(0,r.jsxs)("div",{ref:tO,style:{position:"relative"},children:[(0,r.jsxs)("button",{onClick:()=>!o&&eB(e=>!e),disabled:o,title:ed("chat.changeReasoning",{level:nB}),"aria-label":ed("chat.changeReasoningLabel"),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,padding:ec?"0 6px":"8px 12px",width:ec?"auto":void 0,height:32,background:eD?"var(--bg-hover)":"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:o?"not-allowed":"pointer",fontSize:12,opacity:o?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{o||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=eD?"var(--bg-hover)":"none",e.currentTarget.style.color="var(--text-muted)"},children:[(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("path",{d:"M9.5 2A5.5 5.5 0 0 0 4 7.5c0 1.7.78 3.21 2 4.21V14a1 1 0 0 0 1 1h5a1 1 0 0 0 1-1v-2.29c1.22-1 2-2.51 2-4.21A5.5 5.5 0 0 0 9.5 2z"}),(0,r.jsx)("line",{x1:"7",y1:"18",x2:"12",y2:"18"}),(0,r.jsx)("line",{x1:"8",y1:"21",x2:"11",y2:"21"})]}),(!ec||eA)&&(0,r.jsx)("span",{style:{whiteSpace:"nowrap"},children:nB})]}),eD&&(0,r.jsx)("div",{style:{position:"absolute",bottom:"calc(100% + 12px)",...ec?{left:0}:{right:0},zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",overflow:"hidden",minWidth:180},children:e6.filter(e=>!T||"auto"===e||T.includes(e)).map(e=>{let t=(S??"auto")===e,n=ed(e3[e]),i="auto"!==e&&M?M[e]:void 0,o=null!=i&&i!==e?i:e,a=null!=i&&i!==e;return(0,r.jsxs)("button",{onClick:()=>{eB(!1),t||C(e)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:t?"color-mix(in srgb, var(--accent) 14%, transparent)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left",fontWeight:t?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{t||(e.currentTarget.style.background="color-mix(in srgb, var(--text) 8%, transparent)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(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},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.jsxs)("span",{style:{flex:1},children:[o,a&&(0,r.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",fontFamily:"var(--font-mono)",marginLeft:5},children:["(",e,")"]})]}),(0,r.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:n})]},e)})})]}),!o&&w&&(0,r.jsxs)("div",{ref:tH,style:{position:"relative"},children:[(0,r.jsxs)("button",{onClick:()=>!o&&eN(e=>!e),disabled:o,title:ed("chat.changeToolPreset")+`: ${nA}`,"aria-label":ed("chat.changeToolPreset"),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,padding:ec?"0 6px":"8px 12px",width:ec?"auto":void 0,height:32,background:e$?"var(--bg-hover)":"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:o?"not-allowed":"pointer",fontSize:12,opacity:o?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{o||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=e$?"var(--bg-hover)":"none",e.currentTarget.style.color="var(--text-muted)"},children:[(0,r.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,r.jsx)("path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"})}),(!ec||eA)&&(0,r.jsx)("span",{style:{whiteSpace:"nowrap"},children:nA})]}),e$&&(0,r.jsx)("div",{style:{position:"absolute",bottom:"calc(100% + 12px)",right:ec?void 0:0,left:ec?0:void 0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",overflow:"hidden",minWidth:120},children:e2.map(e=>{let t,n=e4[e],i=(k??"default")===n;return t="off"===e?ed("chat.noTools"):"read-only"===e?ed("chat.readOnlyTools",{count:4}):"default"===e?ed("chat.builtInTools",{count:4}):ed("chat.allBuiltInTools"),(0,r.jsxs)("button",{onClick:()=>{eN(!1),i||w(n)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:i?"color-mix(in srgb, var(--accent) 14%, transparent)":"none",border:"none",color:i?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left",fontWeight:i?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{i||(e.currentTarget.style.background="color-mix(in srgb, var(--text) 8%, transparent)")},onMouseLeave:e=>{i||(e.currentTarget.style.background="none")},children:[i?(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},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",{style:{flex:1},children:e}),(0,r.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:t})]},e)})})]}),!o&&f&&(0,r.jsx)("div",{children:(0,r.jsxs)("button",{onClick:f,disabled:v,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,padding:ec?"0 6px":"8px 12px",width:ec?"auto":void 0,height:32,background:"none",border:"none",borderRadius:9,color:v?"var(--text-dim)":"var(--text-muted)",cursor:v?"not-allowed":"pointer",fontSize:12,opacity:v?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{v||(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)"},title:ed("chat.compactContext"),"aria-label":ed("chat.compactContext"),children:[(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("polyline",{points:"4 14 10 14 10 20"}),(0,r.jsx)("polyline",{points:"20 10 14 10 14 4"}),(0,r.jsx)("line",{x1:"10",y1:"14",x2:"3",y2:"21"}),(0,r.jsx)("line",{x1:"21",y1:"3",x2:"14",y2:"10"})]}),(!ec||eA)&&(0,r.jsx)("span",{style:{whiteSpace:"nowrap"},children:ed("chat.compact")})]})})]})]}),!ec&&(0,r.jsx)("div",{style:{flex:1}}),(0,r.jsxs)("div",{ref:tq,style:{flex:"0 0 auto",display:"flex",alignItems:"center",justifyContent:"flex-end",position:"relative",marginLeft:ec?0:"auto"},children:[ec&&(0,r.jsx)("button",{type:"button",title:ed("chat.moreControls"),"aria-label":ed("chat.moreControls"),"aria-expanded":eA,onClick:()=>{ey(!1),ez(""),eF(e=>!e)},style:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%",height:32,padding:"8px 10px",background:eA?"var(--bg-selected)":"none",border:"none",borderRadius:9,color:eA?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:500,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=eA?"var(--bg-selected)":"none",e.currentTarget.style.color=eA?"var(--text)":"var(--text-muted)"},children:ed("chat.moreControls")}),ec&&nw(),(0,r.jsxs)("div",{style:{display:ec&&eA?"flex":"none",flexDirection:"column",alignItems:"stretch",gap:ec?1:2,...ec?{position:"absolute",right:0,bottom:"100%",marginBottom:4,zIndex:60,padding:4,width:"max-content",minWidth:132,maxWidth:"calc(100vw - 32px)",flexWrap:"nowrap",justifyContent:"flex-start",border:"1px solid color-mix(in srgb, var(--border) 72%, transparent)",borderRadius:10,background:"color-mix(in srgb, var(--glass-bg-strong) 60%, transparent)",boxShadow:"0 8px 24px rgba(0,0,0,0.14)",backdropFilter:"blur(var(--glass-blur-popover)) saturate(var(--glass-saturate))"}:null},children:[!o&&C&&(0,r.jsxs)("div",{ref:t_,style:{position:"relative"},children:[(0,r.jsxs)("button",{onClick:()=>!o&&eB(e=>!e),disabled:o,title:ed("chat.changeReasoning",{level:nB}),"aria-label":ed("chat.changeReasoningLabel"),style:{display:"flex",alignItems:"center",justifyContent:"flex-start",gap:8,padding:ec?"0 12px":"8px 12px",width:ec?"100%":void 0,height:32,textAlign:"left",background:eD?"var(--bg-hover)":"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:o?"not-allowed":"pointer",fontSize:12,opacity:o?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{o||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=eD?"var(--bg-hover)":"none",e.currentTarget.style.color="var(--text-muted)"},children:[(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("path",{d:"M9.5 2A5.5 5.5 0 0 0 4 7.5c0 1.7.78 3.21 2 4.21V14a1 1 0 0 0 1 1h5a1 1 0 0 0 1-1v-2.29c1.22-1 2-2.51 2-4.21A5.5 5.5 0 0 0 9.5 2z"}),(0,r.jsx)("line",{x1:"7",y1:"18",x2:"12",y2:"18"}),(0,r.jsx)("line",{x1:"8",y1:"21",x2:"11",y2:"21"})]}),(!ec||eA)&&(0,r.jsx)("span",{style:{whiteSpace:"nowrap"},children:nB})]}),eD&&(0,r.jsx)("div",{style:{position:"absolute",bottom:"calc(100% + 12px)",...ec?{left:0}:{right:0},zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",overflow:"hidden",minWidth:180},children:e6.filter(e=>!T||"auto"===e||T.includes(e)).map(e=>{let t=(S??"auto")===e,n=ed(e3[e]),i="auto"!==e&&M?M[e]:void 0,o=null!=i&&i!==e?i:e,a=null!=i&&i!==e;return(0,r.jsxs)("button",{onClick:()=>{eB(!1),t||C(e)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:t?"color-mix(in srgb, var(--accent) 14%, transparent)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left",fontWeight:t?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{t||(e.currentTarget.style.background="color-mix(in srgb, var(--text) 8%, transparent)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(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},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.jsxs)("span",{style:{flex:1},children:[o,a&&(0,r.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",fontFamily:"var(--font-mono)",marginLeft:5},children:["(",e,")"]})]}),(0,r.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:n})]},e)})})]}),!o&&w&&(0,r.jsxs)("div",{ref:tU,style:{position:"relative"},children:[(0,r.jsxs)("button",{onClick:()=>!o&&eN(e=>!e),disabled:o,title:ed("chat.changeToolPreset")+`: ${nA}`,"aria-label":ed("chat.changeToolPreset"),style:{display:"flex",alignItems:"center",justifyContent:"flex-start",gap:8,padding:ec?"0 12px":"8px 12px",width:ec?"100%":void 0,height:32,textAlign:"left",background:e$?"var(--bg-hover)":"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:o?"not-allowed":"pointer",fontSize:12,opacity:o?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{o||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=e$?"var(--bg-hover)":"none",e.currentTarget.style.color="var(--text-muted)"},children:[(0,r.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,r.jsx)("path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"})}),(!ec||eA)&&(0,r.jsx)("span",{style:{whiteSpace:"nowrap"},children:nA})]}),e$&&(0,r.jsx)("div",{style:{position:"absolute",bottom:"calc(100% + 12px)",right:ec?void 0:0,left:ec?0:void 0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",overflow:"hidden",minWidth:120},children:e2.map(e=>{let t,n=e4[e],i=(k??"default")===n;return t="off"===e?ed("chat.noTools"):"read-only"===e?ed("chat.readOnlyTools",{count:4}):"default"===e?ed("chat.builtInTools",{count:4}):ed("chat.allBuiltInTools"),(0,r.jsxs)("button",{onClick:()=>{eN(!1),i||w(n)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:i?"color-mix(in srgb, var(--accent) 14%, transparent)":"none",border:"none",color:i?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left",fontWeight:i?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{i||(e.currentTarget.style.background="color-mix(in srgb, var(--text) 8%, transparent)")},onMouseLeave:e=>{i||(e.currentTarget.style.background="none")},children:[i?(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},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",{style:{flex:1},children:e}),(0,r.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:t})]},e)})})]}),!o&&f&&(0,r.jsx)("div",{children:(0,r.jsxs)("button",{onClick:f,disabled:v,style:{display:"flex",alignItems:"center",justifyContent:"flex-start",gap:8,padding:ec?"0 12px":"8px 12px",width:ec?"100%":void 0,height:32,textAlign:"left",background:"none",border:"none",borderRadius:9,color:v?"var(--text-dim)":"var(--text-muted)",cursor:v?"not-allowed":"pointer",fontSize:12,opacity:v?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{v||(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)"},title:ed("chat.compactContext"),"aria-label":ed("chat.compactContext"),children:[(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("polyline",{points:"4 14 10 14 10 20"}),(0,r.jsx)("polyline",{points:"20 10 14 10 14 4"}),(0,r.jsx)("line",{x1:"10",y1:"14",x2:"3",y2:"21"}),(0,r.jsx)("line",{x1:"21",y1:"3",x2:"14",y2:"10"})]}),(!ec||eA)&&(0,r.jsx)("span",{style:{whiteSpace:"nowrap"},children:ed("chat.compact")})]})}),!K&&Y&&(0,r.jsx)("button",{type:"button",onClick:()=>Y(),title:ed("chat.scrollToLatest"),"aria-label":ed("chat.scrollToLatest"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,flexShrink:0,background:"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:"pointer",transition:"background 0.12s, color 0.12s, opacity 0.12s",animation:"back-to-latest-in 0.18s ease-out both"},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.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)("polyline",{points:"7 13 12 18 17 13"}),(0,r.jsx)("polyline",{points:"7 6 12 11 17 6"})]})})]}),!ec&&void 0!==H&&(0,r.jsx)("button",{onClick:H,title:F?ed("chat.disableSound"):ed("chat.enableSound"),"aria-label":F?ed("chat.disableSound"):ed("chat.enableSound"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,flexShrink:0,background:"none",border:"none",borderRadius:9,color:F?"var(--text-muted)":"var(--text-dim)",cursor:"pointer",opacity:F?1:.55,transition:"background 0.12s, color 0.12s, opacity 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)",e.currentTarget.style.opacity="1"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=F?"var(--text-muted)":"var(--text-dim)",e.currentTarget.style.opacity=F?"1":"0.55"},children:F?(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,r.jsx)("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"}),(0,r.jsx)("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"})]}):(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,r.jsx)("line",{x1:"23",y1:"9",x2:"17",y2:"15"}),(0,r.jsx)("line",{x1:"17",y1:"9",x2:"23",y2:"15"})]})}),!ec&&nw()]})]})]})]})]})});var tv=n(88374),tb=n(88576),ty=n.n(tb);function tk({level:e,children:t,headingIndex:n,onClick:i}){return(0,r.jsx)("button",{type:"button",className:ty().heading,"data-level":e,"data-preview-heading-index":n??void 0,disabled:null===n||!i,onClick:e=>{e.stopPropagation(),null!==n&&i?.(n)},children:t})}let tw=[...E.iA??[],function(){return e=>{if(!Array.isArray(e.children))return;let t=e.children.filter(e=>"heading"===e.type&&"number"==typeof e.depth&&e.depth<=3);if(t.length>0){t.forEach((e,t)=>{e.data={...e.data,hProperties:{...e.data?.hProperties,"data-preview-heading-index":t}}}),e.children=t;return}let n=e.children.find(e=>"paragraph"===e.type);e.children=n?[n]:[]}}],tj=[[tv.A,{throwOnError:!1,strict:!1}]];function tS(e){let t=e?.properties,n=t?.dataPreviewHeadingIndex??t?.["data-preview-heading-index"];return"number"==typeof n?n:"string"==typeof n&&/^\d+$/.test(n)?Number(n):null}let tC=(0,a.memo)(function({markdown:e,onHeadingClick:t,onAnswerClick:n}){let i=(0,a.useMemo)(()=>(0,E.Ep)(e),[e]);return e?(0,r.jsx)("div",{className:ty().outline,children:(0,r.jsx)(L.oz,{remarkPlugins:tw,rehypePlugins:tj,components:{h1:({children:e,node:n})=>(0,r.jsx)(tk,{level:1,headingIndex:tS(n),onClick:t,children:e}),h2:({children:e,node:n})=>(0,r.jsx)(tk,{level:2,headingIndex:tS(n),onClick:t,children:e}),h3:({children:e,node:n})=>(0,r.jsx)(tk,{level:3,headingIndex:tS(n),onClick:t,children:e}),h4:()=>null,h5:()=>null,h6:()=>null,p:({children:e})=>(0,r.jsx)("button",{type:"button",className:ty().paragraph,onClick:n,children:e}),blockquote:()=>null,ul:()=>null,ol:()=>null,pre:()=>null,table:()=>null,hr:()=>null,a:({children:e})=>(0,r.jsx)(r.Fragment,{children:e}),code:({children:e})=>(0,r.jsx)(r.Fragment,{children:e})},children:i})}):null});function tT({messages:e,entryIds:t,turnIndex:n,streamingMessage:i,scrollContainer:o,messageRefs:s,onRevealHistory:l}){let[d,c]=(0,a.useState)(!1),[u,p]=(0,a.useState)([]),[h,g]=(0,a.useState)(null),[x,f]=(0,a.useState)(48),[m,v]=(0,a.useState)(!1),[b,y]=(0,a.useState)(null),k=(0,a.useRef)(!1),w=(0,a.useRef)(null),j=(0,a.useRef)([]),C=(0,a.useRef)({nodes:[],gap:50,fillsHeight:!1}),T=(0,a.useRef)(null),M=(0,a.useRef)(new Map),I=(0,a.useRef)(null),L=(0,a.useRef)(null),R=(0,a.useRef)(null),E=(0,a.useMemo)(()=>i?[...e,i]:e,[e,i]),z=(0,a.useRef)(E);z.current=E;let W=(0,a.useRef)(n);W.current=n;let P=(0,a.useRef)(t);P.current=t;let $=(0,a.useMemo)(()=>(function(e,t){if(0===e.length)return{nodes:[],gap:50,fillsHeight:!1};let n=Math.max(1,t),r=Math.max(0,n-44);if(1===e.length)return{nodes:[{...e[0],topRatio:22/n}],gap:50,fillsHeight:!1};let i=r/(e.length-1),o=Math.min(50,i);return{nodes:e.map((e,t)=>({...e,topRatio:(22+t*o)/n})),gap:o,fillsHeight:i<=50}})(u,x),[u,x]),{nodes:N,gap:D}=$;C.current=$;let B=(0,a.useCallback)(e=>{L.current={index:e,until:Date.now()+1600},g(e)},[]),A=(0,a.useCallback)((e,t)=>{let n=L.current;if(n&&Date.now()<n.until)return void g(n.index);L.current=null;let r=t.filter(e=>null!==e.targetTurn.scrollTop);if(0===r.length)return void g(null);let i=e.scrollTop+.3*e.clientHeight;g(r.reduce((e,t)=>Math.abs((t.targetTurn.scrollTop??0)-i)<Math.abs((e.targetTurn.scrollTop??0)-i)?t:e,r[0]).index)},[]),F=(0,a.useCallback)(()=>{let e=o.current;if(!e)return;let t=e.scrollHeight-e.clientHeight,n=j.current;c(t>20),A(e,n)},[o,A]),H=(0,a.useRef)(null),O=(0,a.useCallback)(()=>{H.current||(H.current=setTimeout(()=>{H.current=null;let e=o.current,t=w.current;if(!e||!t)return;let n=s.current,r=e.getBoundingClientRect(),i=function(e,t){let n=[],r=null,i=0;for(let o=0;o<e.length;o++){let a=e[o];if("user"!==a.role&&"assistant"!==a.role)continue;let s=t[o]??"";if("user"===a.role)r={entryId:s,msgIdx:o,refIdx:i,userMessage:a,userText:"string"==typeof a.content?a.content.trim():a.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n").trim()||"[attachment]",assistantList:[]},n.push(r);else if(r){let e=function(e){if("assistant"!==e.role)return"";let{answerBlocks:t}=S(e);return t.filter(e=>"text"===e.type).map(e=>e.text).join("\n\n").trim()}(a);e&&r.assistantList.push({markdown:e,msgIdx:o,refIdx:i})}i+=1}return n}(z.current,P.current),a=(function(e,t){let n=new Map;for(let e of t)n.set(e.entryId,e);let r=[],i=new Set;for(let t of e){let e=n.get(t.entryId);e?(i.add(t.entryId),r.push({entryId:t.entryId,refIdx:e.refIdx,userMessage:e.userMessage,userText:e.userText,assistantList:e.assistantList,assistantPreviewText:t.assistantPreview,loaded:!0})):r.push({entryId:t.entryId,refIdx:-1,userMessage:null,userText:t.userText,assistantList:[],assistantPreviewText:t.assistantPreview,loaded:!1})}for(let e of t)i.has(e.entryId)||r.push({entryId:e.entryId,refIdx:e.refIdx,userMessage:e.userMessage,userText:e.userText,assistantList:e.assistantList,assistantPreviewText:"",loaded:!0});return r})(W.current,i).map(t=>{if(!t.loaded)return{entryId:t.entryId,userMessage:null,userText:t.userText,assistantPreviews:[],assistantPreviewText:t.assistantPreviewText,scrollTop:null,loaded:!1};let i=n?.[t.refIdx],o=t.assistantList.map(e=>({markdown:e.markdown,element:n?.[e.refIdx]??null}));return{entryId:t.entryId,userMessage:t.userMessage,userText:t.userText,assistantPreviews:o,assistantPreviewText:t.assistantPreviewText,scrollTop:i?i.getBoundingClientRect().top-r.top+e.scrollTop:null,loaded:!0}}),l=a.map((e,t)=>({topRatio:0,targetTurn:e,index:t})),d=l.length,u=Math.max(48,e.clientHeight-14-8);f(d<=1?48:Math.min(u,44+(d-1)*50)),j.current=l,p(l),c(a.length>0&&e.scrollHeight-e.clientHeight>20),A(e,l);let h=R.current,g=h?l[h.nodeIndex]:null;if(h&&g){let t=void 0===h.assistantIndex?null:g.targetTurn.assistantPreviews[h.assistantIndex],n=g.targetTurn.scrollTop;if("assistant"===h.target){let i=t?.element?.getBoundingClientRect();n=i?i.top-r.top+e.scrollTop:null}else if("heading"===h.target){let i=void 0===h.headingIndex?null:t?.element?.querySelectorAll("h1, h2, h3").item(h.headingIndex),o=i?.getBoundingClientRect();n=o?o.top-r.top+e.scrollTop:null}if(null===n)return;R.current=null,B(g.index);let i=.3*e.clientHeight;e.scrollTo({top:Math.max(0,n-i),behavior:"smooth"})}},150))},[B,s,o,A]);(0,a.useEffect)(()=>{let e=o.current;if(e)return e.addEventListener("scroll",F,{passive:!0}),()=>e.removeEventListener("scroll",F)},[o,F]),(0,a.useEffect)(()=>{let e=o.current;if(!e)return;let t=()=>{O(),F()},n=new ResizeObserver(t);return n.observe(e),e.firstElementChild&&n.observe(e.firstElementChild),t(),()=>{n.disconnect(),H.current&&(clearTimeout(H.current),H.current=null)}},[O,o,F]),(0,a.useEffect)(()=>{let e=setTimeout(()=>{O(),F()},50);return()=>clearTimeout(e)},[e.length,O,F]),(0,a.useEffect)(()=>{O(),F()},[n,O,F]);let U=(0,a.useCallback)((e,t)=>{let n=o.current;if(!n)return;if(B(e.index),null===e.targetTurn.scrollTop){R.current={nodeIndex:e.index,target:"user"},l(e.targetTurn.entryId);return}let r=Math.max(0,e.targetTurn.scrollTop-.3*n.clientHeight);n.scrollTo({top:r,behavior:t})},[B,l,o]),_=(0,a.useCallback)((e,t)=>{let n=o.current;if(!n)return;let r=e.targetTurn.assistantPreviews[t]?.element;if(!r){R.current={nodeIndex:e.index,target:"assistant",assistantIndex:t},l(e.targetTurn.entryId);return}let i=n.getBoundingClientRect(),a=r.getBoundingClientRect().top-i.top+n.scrollTop-.3*n.clientHeight;B(e.index),n.scrollTo({top:Math.max(0,a),behavior:"smooth"})},[B,l,o]),q=(0,a.useCallback)(e=>{let{nodes:t,gap:n,fillsHeight:r}=C.current,i=w.current?.clientHeight??0;if(0===t.length||i<=0)return null;let o=Math.max(0,Math.min(i,e*i)),a=t[0].topRatio*i,s=n>0?Math.round((o-a)/n):0,l=Math.max(0,Math.min(t.length-1,s)),d=t[l];if(!r&&Math.abs(o-d.topRatio*i)>Math.max(10,n/2))return null;return d},[]),V=(0,a.useCallback)((e,t,n)=>{let r=o.current;if(!r)return;let i=e.targetTurn.assistantPreviews[t]?.element;if(!i){R.current={nodeIndex:e.index,target:"heading",assistantIndex:t,headingIndex:n},l(e.targetTurn.entryId);return}let a=i.querySelectorAll("h1, h2, h3").item(n);if(!a)return;let s=r.getBoundingClientRect(),d=a.getBoundingClientRect().top-s.top+r.scrollTop-.3*r.clientHeight;B(e.index),r.scrollTo({top:Math.max(0,d),behavior:"smooth"})},[B,l,o]),J=(0,a.useCallback)(()=>{I.current&&(clearTimeout(I.current),I.current=null)},[]),K=(0,a.useCallback)(()=>{J(),v(!0)},[J]),Y=(0,a.useCallback)(()=>{J(),I.current=setTimeout(()=>{I.current=null,v(!1),y(null)},250)},[J]);(0,a.useEffect)(()=>()=>J(),[J]);let G=(0,a.useCallback)(e=>{if(!d)return;k.current=!0,K();let t=e.currentTarget.getBoundingClientRect();y(Math.max(0,Math.min(1,(e.clientY-t.top)/t.height)));let n=(e,n)=>{let r=q(Math.max(0,Math.min(1,(e-t.top)/t.height)));r&&U(r,n)};n(e.clientY,"smooth");let r=e=>{k.current&&n(e.clientY,"auto")},i=()=>{k.current=!1,window.removeEventListener("mousemove",r),window.removeEventListener("mouseup",i)};window.addEventListener("mousemove",r),window.addEventListener("mouseup",i)},[q,U,K,d]),X=null===b?null:q(b),Z=X?.index??null;(0,a.useEffect)(()=>{if(!m||null===Z)return;let e=T.current,t=M.current.get(Z);if(!e||!t)return;let n=t.offsetTop-(e.clientHeight-t.offsetHeight)/2;e.scrollTop=Math.max(0,n)},[u,m,Z]);let Q=Math.max(1,(N.length>0?N[N.length-1].topRatio*x:22)-22);return(0,r.jsxs)("div",{ref:w,onMouseDown:G,onMouseEnter:K,onMouseLeave:Y,onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();y((e.clientY-t.top)/t.height)},style:{width:26,height:x,flexShrink:0,position:"relative",marginTop:14,cursor:"pointer",userSelect:"none",border:d?"1px solid color-mix(in srgb, var(--border) 60%, transparent)":"none",background:d?"var(--panel-glass-minimap)":"transparent",backdropFilter:d?"blur(var(--glass-blur-panel)) saturate(var(--glass-saturate))":"none",WebkitBackdropFilter:d?"blur(var(--glass-blur-panel)) saturate(var(--glass-saturate))":"none",transform:"translateZ(0)",borderRadius:12,boxShadow:d?"0 1px 2px rgba(15,23,42,0.04), 0 4px 16px -8px rgba(15,23,42,0.10)":"none",overflow:"visible"},children:[d&&(0,r.jsx)("div",{style:{position:"absolute",left:"50%",top:22,height:Q,width:1,background:"var(--timeline-rail)",transform:"translateX(-50%)",zIndex:0}}),d&&N.map(e=>{let t=m&&X?.index===e.index,n=h===e.index,i=Math.max(5,Math.min(9,.75*D));return(0,r.jsx)("div",{"data-minimap-node-index":e.index,"data-minimap-node-active":n?"":void 0,style:{position:"absolute",top:`${100*e.topRatio}%`,transform:"translateY(-50%)",left:0,right:0,height:Math.max(1,D),display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"none",zIndex:2},children:(0,r.jsx)("div",{style:{width:i,height:i,borderRadius:"50%",background:n?"var(--timeline-dot-active-bg)":"var(--timeline-dot-bg)",border:`1.5px solid ${n?"var(--timeline-dot-active-border)":"var(--timeline-dot-border)"}`,boxShadow:n?"var(--timeline-dot-active-glow)":"none",transition:"transform 0.12s ease-out, background 0.12s ease-out, box-shadow 0.12s ease-out",transform:t?"scale(1.3)":"scale(1)"}})},e.index)}),d&&m&&u.length>0&&(0,r.jsx)("div",{ref:T,className:ty().preview,"data-minimap-preview-box":"",onMouseEnter:K,onMouseDown:e=>e.stopPropagation(),onMouseMove:e=>e.stopPropagation(),children:u.map(e=>{let t=Z===e.index;return(0,r.jsxs)("div",{ref:t=>{t?M.current.set(e.index,t):M.current.delete(e.index)},className:ty().turn,"data-minimap-preview-index":e.index,"data-located":t?"true":void 0,children:[(0,r.jsx)("span",{className:ty().number,"aria-hidden":"true",children:String(e.index+1).padStart(2,"0")}),(0,r.jsxs)("div",{className:ty().content,children:[(0,r.jsx)("button",{type:"button",className:ty().user,"data-minimap-preview-user":e.index,onClick:()=>{U(e,"smooth")},children:(0,r.jsx)("span",{className:ty().userText,children:e.targetTurn.userText})}),e.targetTurn.loaded?e.targetTurn.assistantPreviews.map((t,n)=>(0,r.jsxs)("div",{className:ty().assistant,children:[(0,r.jsx)("button",{type:"button",className:ty().assistantJump,"data-minimap-preview-assistant":`${e.index}-${n}`,onClick:()=>_(e,n),"aria-label":"Locate assistant message",title:"Locate assistant message",children:"A"}),(0,r.jsx)(tC,{markdown:t.markdown,onAnswerClick:()=>_(e,n),onHeadingClick:t=>V(e,n,t)})]},n)):e.targetTurn.assistantPreviewText?(0,r.jsx)("div",{className:ty().assistant,children:(0,r.jsx)("button",{type:"button",className:ty().paragraph,"data-minimap-preview-assistant-text":e.index,onClick:()=>U(e,"smooth"),children:e.targetTurn.assistantPreviewText})}):null]})]},e.index)})})]})}function tM({widgets:e}){let t,n,i,{t:o}=(0,P.s)(),s=(0,a.useId)(),l=(0,a.useRef)(null),d=(0,a.useRef)(new Map),[c,u]=(0,a.useState)(()=>e.find(e=>{let t=e.lines.length;return t>1&&t<=3})?.key??null),[p,h]=(0,a.useState)(()=>new Set),g=(0,a.useRef)(null),x=(0,a.useRef)(null);if((0,a.useEffect)(()=>{var t;let n=new Map(e.map(e=>[e.key,[...e.lines]])),r=(t=l.current,t?Array.from(n,([e,n])=>{let r=t.get(e);return r&&r.length===n.length?n.some((e,t)=>e!==r[t])?e:null:r?e:null}).filter(e=>null!==e):[]);for(let[e,t]of(l.current=n,d.current))n.has(e)||(clearTimeout(t),d.current.delete(e));for(let e of(h(e=>{let t=new Set(Array.from(e).filter(e=>n.has(e)));for(let e of r)t.add(e);return t.size===e.size&&Array.from(t).every(t=>e.has(t))?e:t}),r)){let t=d.current.get(e);t&&clearTimeout(t),d.current.set(e,setTimeout(()=>{d.current.delete(e),h(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},1100))}},[e]),(0,a.useEffect)(()=>()=>{for(let e of d.current.values())clearTimeout(e);d.current.clear()},[]),(0,a.useEffect)(()=>{if(!c)return;let e=e=>{let t=e.target;x.current?.contains(t)||g.current?.contains(t)||u(null)};return document.addEventListener("pointerdown",e,!0),()=>document.removeEventListener("pointerdown",e,!0)},[c]),0===e.length)return null;let f=e.find(e=>e.key===c&&e.lines.length>1);return(0,r.jsxs)(r.Fragment,{children:[f&&(0,r.jsx)("div",{ref:x,className:"extension-widget-panels",children:(t=e.indexOf(f),n=`${s}-trigger-${t}`,i=`${s}-panel-${t}`,(0,r.jsxs)("section",{id:i,className:"extension-widget-panel","aria-labelledby":n,children:[(0,r.jsx)("div",{className:"extension-widget-panel-heading",children:f.key}),(0,r.jsx)("pre",{className:"extension-widget-content",children:f.lines.join("\n")})]},f.key))}),(0,r.jsx)("div",{ref:g,className:"extension-widget-triggers","aria-label":o("chat.extensionWidgets"),children:e.map((e,t)=>{let n=e.lines.length>1,i=n&&e.key===f?.key,a=p.has(e.key),l=o(1===e.lines.length?"chat.extensionWidgetLine":"chat.extensionWidgetLines",{count:e.lines.length}),d=o("belowEditor"===e.placement?"chat.extensionWidgetBelow":"chat.extensionWidgetAbove"),c=`${s}-trigger-${t}`,h=`${s}-panel-${t}`,g=(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"extension-widget-update-pulse","aria-hidden":"true"}),(0,r.jsx)("span",{className:"extension-widget-placement","aria-hidden":"true",children:(0,r.jsx)("svg",{className:"extension-widget-placement-icon",viewBox:"0 0 8 6",width:"8",height:"6","data-direction":"belowEditor"===e.placement?"down":"up",focusable:"false",children:(0,r.jsx)("path",{d:"belowEditor"===e.placement?"M0 0h8L4 6z":"M4 0l4 6H0z"})})}),(0,r.jsx)("span",{className:"extension-widget-key",children:e.key})]});return n?(0,r.jsx)("button",{id:c,type:"button",className:`extension-widget-trigger${i?" is-expanded":""}${a?" is-updating":""}`,"aria-controls":h,"aria-expanded":i,"aria-label":`${d}: ${e.key}, ${l}`,title:`${e.key} - ${d} - ${i?o("i18n.collapse"):o("i18n.expand")}`,onClick:()=>{u(t=>{var n;return t===(n=e.key)?null:n})},children:g},e.key):(0,r.jsx)("div",{className:`extension-widget-trigger${a?" is-updating":""}`,"aria-label":`${d}: ${e.key}, ${l}`,title:`${e.key} - ${d}`,children:g},e.key)})})]})}function tI({statuses:e,widgets:t=[],tools:n,notice:i,sessionId:o}){if(0===e.length&&0===t.length&&!n&&!i)return null;let a=[...e].sort((e,t)=>e.key.localeCompare(t.key)).map(({text:e})=>e.replace(/[\r\n\t]/g," ").replace(/ +/g," ").trim()).join(" "),s=h(a);return(0,r.jsxs)("div",{className:`extension-status-shelf${t.length>0?" has-widgets":""}${e.length>0?" has-status":""}`,children:[(0,r.jsxs)("div",{className:"extension-status-left",children:[t.length>0&&(0,r.jsx)(tM,{widgets:t}),e.length>0&&(0,r.jsx)("div",{role:"status",className:"extension-status-line","aria-label":s,title:s,children:(0,r.jsx)("span",{className:"extension-status-text",children:m(a).map((e,t)=>(0,r.jsx)("span",{style:e.style,children:e.text},t))})})]}),(0,r.jsxs)("div",{className:`extension-status-right${n?" has-tools":""}`,children:[i,n]})]})}var tL=n(48660);function tR(e){let t=e.find(e=>"error"===e.type&&!e.exiting);return t?.id??null}let tE=new Set(["opencode-go","deepseek","commandcode"]);function tz(e,t=Date.now()){let n=Date.parse(e);if(!Number.isFinite(n))return"";let r=Math.round((n-t)/1e3);if(r<=0)return"";let i=Math.floor(r/86400),o=Math.floor((r%=86400)/3600),a=Math.floor((r%=3600)/60);return i>0?`${i}d${o}h`:o>0?`${o}h${a}m`:`${Math.max(a,1)}m`}function tW({broadcast:e,history:t,onDismissError:n,onRemoveNotice:o,onClearNotices:s,onFreezeChange:l,isDark:d}){let c,u,p,{t:h}=(0,P.s)(),[g,x]=(0,a.useState)(!1),f=(0,a.useRef)(null),m=(0,a.useRef)(null),v=(0,a.useRef)(null);(0,a.useEffect)(()=>{l(g)},[g,l]);let[b,y]=(0,a.useState)(0),k=(0,a.useRef)(null),w=e?.level!=="idle"&&e?`${e.level}:${e.text}`:null;(0,a.useEffect)(()=>{if(null===k.current){k.current=w;return}w&&w!==k.current&&y(e=>e+1),k.current=w},[w]),(0,a.useEffect)(()=>{if(t.length<=1)return;let e=f.current;e&&(e.scrollTop=e.scrollHeight)},[t.length]),(0,a.useEffect)(()=>{if(!g)return;let e=e=>{let t=e.target;m.current?.contains(t)||v.current?.contains(t)||x(!1)};return document.addEventListener("pointerdown",e,!0),()=>document.removeEventListener("pointerdown",e,!0)},[g]),(0,a.useEffect)(()=>{0===t.length&&g&&x(!1)},[t.length,g]);let j=null!==e&&"idle"!==e.level,S=t.length,C={display:"inline-flex",alignItems:"center",justifyContent:"center",minWidth:16,height:16,padding:"0 4px",borderRadius:999,background:"var(--accent)",color:"#fff",fontSize:10,fontWeight:700,lineHeight:1,flexShrink:0},T=j?(0,r.jsxs)("span",{ref:v,onClick:e=>{e.target.closest("button")||x(e=>!e)},title:g?h("notice.collapse"):h("notice.expand"),style:{display:"inline-flex",alignItems:"center",gap:6,cursor:"pointer",minWidth:0,maxWidth:"min(46vw, 480px)"},children:[(0,r.jsx)(eZ,{notice:e,onDismissError:n,isDark:d,style:{animation:"notice-flash 0.9s ease 2"}}),S>0&&(0,r.jsx)("span",{"aria-label":h("notice.title"),style:C,children:S>99?"99+":S})]},b):S>0?(0,r.jsx)("span",{ref:v,onClick:()=>x(!0),role:"button",tabIndex:0,title:h("notice.title"),"aria-label":h("notice.title"),onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),x(!0))},style:{...C,cursor:"pointer"},children:S>99?"99+":S}):null,M=g&&t.length>0?(0,i.createPortal)((0,r.jsxs)("div",{ref:m,className:"notice-drawer",role:"region","aria-label":h("notice.title"),style:(c=v.current?.getBoundingClientRect(),u=window.innerWidth,p=window.innerHeight,{position:"fixed",right:c?Math.max(8,u-c.right):12,bottom:c?Math.max(8,p-c.top+8):40,zIndex:1030,width:"min(46vw, 480px)",maxWidth:"calc(100vw - 24px)",maxHeight:"60vh",display:"flex",flexDirection:"column",background:"var(--panel-glass)",backdropFilter:"blur(var(--glass-blur-panel)) saturate(var(--glass-saturate))",WebkitBackdropFilter:"blur(var(--glass-blur-panel)) saturate(var(--glass-saturate))",border:"1px solid var(--border)",borderRadius:"10px 10px 0 0",borderBottom:"none",boxShadow:"0 -8px 30px rgba(0,0,0,0.35)",overflow:"hidden",animation:"notice-drawer-in 0.15s ease-out both",transformOrigin:"bottom right"}),children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"8px 12px",flexShrink:0,background:"color-mix(in srgb, var(--bg-hover) 60%, transparent)",borderBottom:"1px solid var(--border)",fontSize:12,fontWeight:600,color:"var(--text)",userSelect:"none"},children:[h("notice.title"),(0,r.jsx)("span",{style:{color:"var(--text-muted)",fontWeight:500},children:t.length}),(0,r.jsx)("span",{style:{flex:1}}),t.length>0&&(0,r.jsx)("button",{type:"button",onClick:s,title:h("notice.clearAll"),"aria-label":h("notice.clearAll"),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,padding:"3px 8px",background:"none",border:"1px solid color-mix(in srgb, var(--border) 60%, transparent)",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",fontSize:11,lineHeight:1},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:h("notice.clearAll")}),(0,r.jsx)("button",{type:"button",onClick:()=>x(!1),title:h("i18n.close"),"aria-label":h("i18n.close"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,background:"none",border:"none",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",fontSize:11,lineHeight:1},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)("div",{ref:f,style:{flex:1,minHeight:0,overflowY:"auto",padding:"6px 8px",display:"flex",flexDirection:"column",gap:6},children:0===t.length?(0,r.jsx)("div",{style:{padding:"10px 6px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:h("notice.empty")}):t.map(e=>{let t=eY[e.type]??eY.info;return(0,r.jsxs)("div",{className:"notice-drawer-item",style:{display:"flex",alignItems:"flex-start",gap:8,padding:"8px 10px",borderRadius:8,border:`1px solid color-mix(in srgb, ${t} 35%, transparent)`,background:"color-mix(in srgb, var(--glass-bg-strong) 60%, transparent)",color:"var(--text)",fontSize:12.5,lineHeight:1.55,animation:"notice-drawer-in 0.2s ease-out both"},children:[(0,r.jsx)("span",{"aria-hidden":"true",style:{flexShrink:0,width:6,height:6,borderRadius:"50%",background:t,marginTop:5}}),(0,r.jsx)("span",{style:{flex:1,minWidth:0,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:e.message}),(0,r.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation(),o(e.id)},title:h("notice.remove"),"aria-label":h("notice.remove"),style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:18,height:18,padding:0,background:"none",border:"none",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",fontSize:11,lineHeight:1},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:"✕"})]},e.id)})})]}),document.body):null;return(0,r.jsxs)(r.Fragment,{children:[T,M]})}var tP=n(13405),t$=n(4325);function tN(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function tD(e,t={}){if("assistant"!==e.role)return e;let n=e.content;if(!Array.isArray(n))return e;let r=n.map(e=>(function(e,t={}){if(!tN(e)||"toolCall"!==e.type)return null;let n={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=tN(e.customInput)?e.customInput:null,n=t&&"string"==typeof t.property?t.property:null,r=tN(e.arguments)?e.arguments:null;return n&&r&&"string"==typeof r[n]?r[n]:void 0}(e):void 0;return void 0===r?n:{...n,rawInput:r}})(e,t)??e);return{...e,content:r}}var tB=n(32383),tA=n(14755);let tF="pi-tool-preset";function tH(){try{return window.localStorage}catch{return null}}function tO(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 tU(e){let t,n=e.content;return"string"==typeof n?JSON.stringify({text:n,images:[]}):Array.isArray(n)?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:n.map(tO).filter(Boolean)}):JSON.stringify({text:"",images:[]})}class t_ extends Error{constructor(e,t){super(t??("ready_timeout"===e?"Timed out starting the agent session. Please try again.":"Failed to connect to the agent event stream. Please try again.")),this.status=e,this.name="AgentEventConnectionError"}}class tq{constructor(e){this.options=e,this.current=null,this.retry=null,this.retryGeneration=0}close(){this.stopRetrying(),this.current&&this.discard(this.current,new t_("closed"))}maintain(e){if(!this.options.shouldMaintain(e))return;let t=this.retryGeneration;this.ensureConnected(e).catch(n=>{t===this.retryGeneration&&(n instanceof t_?"startup_error"===n.status?this.stopRetrying():this.scheduleRetry(e):this.options.onUnexpectedError?.(n))})}async ensureConnected(e){for(;;){let t=this.current;if(t&&t.sessionId===e){if(t.attempt.ready&&1===t.source.readyState)return}else t=this.open(e);if(await t.attempt.promise,this.current!==t){if(this.current?.sessionId===e)continue;throw new t_("closed")}if(1===t.source.readyState)return;this.discard(t,new t_("closed"))}}open(e){let t,n,r;this.current&&this.discard(this.current,new t_("closed"));try{t=this.options.createSource(e)}catch(e){throw new t_("closed",e instanceof Error?e.message:String(e))}let i=!1,o=new Promise((e,t)=>{n=e,r=t}),a=setTimeout(()=>{this.fail(l,new t_("ready_timeout"))},this.options.readinessTimeoutMs),s={promise:o,ready:!1,succeed(){i||(i=!0,clearTimeout(a),n())},fail(e){i||(i=!0,clearTimeout(a),r(e))}},l={sessionId:e,source:t,attempt:s};return this.current=l,t.onmessage=e=>{let t;if(this.current===l){try{t=JSON.parse(e.data)}catch{return}if("connected"===t.type)s.ready=!0,s.succeed(),this.stopRetrying();else if("startup_error"===t.type){let e="string"==typeof t.errorMessage?t.errorMessage:void 0;this.fail(l,new t_("startup_error",e));return}this.options.onEvent(t)}},t.onerror=()=>{this.fail(l,new t_("closed"))},l}fail(e,t){this.current===e&&(this.discard(e,t),"startup_error"===t.status?this.stopRetrying():this.scheduleRetry(e.sessionId))}discard(e,t){e.attempt.fail(t),e.source.close(),this.current===e&&(this.current=null)}scheduleRetry(e){if(!this.options.shouldMaintain(e)||this.retry?.sessionId===e)return;this.clearRetry();let t=setTimeout(()=>{this.retry?.timer===t&&(this.retry=null,this.maintain(e))},this.options.reconnectDelayMs);this.retry={sessionId:e,timer:t}}stopRetrying(){this.retryGeneration+=1,this.clearRetry()}clearRetry(){this.retry&&clearTimeout(this.retry.timer),this.retry=null}}function tV(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}var tJ=n(36268);function tK(e,t){return Math.max(0,e-t)}function tY(e,t,n,r=8){return e+t>=n-r}let tG={isStreaming:!1,streamingMessage:null};function tX(e,t,n){let r=e.streamingMessage;if(!r||!Number.isInteger(t)||t<0)return e;let i=[...r.content],o=n(i[t]);return o?(i[t]=o,{isStreaming:!0,streamingMessage:{...r,content:i}}):e}function tZ(e,t){switch(t.type){case"start":return e.streamingMessage?{...e,isStreaming:!0}:{isStreaming:!0,streamingMessage:null};case"snapshot":{let n=tD(t.message,{includeStreamingRawInput:!0});return"assistant"===n.role?{isStreaming:!0,streamingMessage:n}:e}case"delta":var n=t.event;switch(n.type){case"text_start":return tX(e,n.contentIndex,e=>e?.type==="text"?e:{type:"text",text:""});case"text_delta":return tX(e,n.contentIndex,e=>e?.type==="text"?{...e,text:e.text+n.delta}:null);case"text_end":return tX(e,n.contentIndex,e=>({...e?.type==="text"?e:{},type:"text",text:n.content}));case"thinking_start":return tX(e,n.contentIndex,e=>e?.type==="thinking"?e:{type:"thinking",thinking:""});case"thinking_delta":return tX(e,n.contentIndex,e=>e?.type==="thinking"?{...e,thinking:e.thinking+n.delta}:null);case"thinking_end":return tX(e,n.contentIndex,e=>({...e?.type==="thinking"?e:{},type:"thinking",thinking:n.content}));case"toolcall_start":return tX(e,n.contentIndex,e=>e?.type==="toolCall"?{...e,toolCallId:n.id??e.toolCallId,toolName:n.toolName??e.toolName,rawInput:e.rawInput??""}:"string"!=typeof n.toolName?null:{type:"toolCall",toolCallId:n.id??"",toolName:n.toolName,input:{},rawInput:""});case"toolcall_delta":return tX(e,n.contentIndex,e=>e?.type==="toolCall"?{...e,toolCallId:n.id||e.toolCallId,toolName:n.toolName||e.toolName,rawInput:(e.rawInput??"")+n.delta}:null);case"toolcall_end":return tX(e,n.contentIndex,()=>({type:"toolCall",toolCallId:n.toolCall.id,toolName:n.toolCall.name,input:n.toolCall.arguments}));default:return e}case"end":return tG;default:return e}}function tQ(e){return{steering:e?.steering??[],followUp:e?.followUp??[]}}let t0="pi-notice-history-v1";function t1(e){return new Promise(t=>setTimeout(t,e))}function t2(e){let t=e.findIndex(e=>!e.exiting);return -1===t?e:e.map((e,n)=>n===t?{...e,exiting:!0}:e)}function t4(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:t2(e.visible),pending:[...e.pending,t.notice]};return{...e,visible:[...e.visible,t.notice]};case"mark_oldest_exiting":return{...e,visible:t2(e.visible)};case"remove":return function(e,t){let n=e,r=t;for(;r.length>0&&n.length<5;){let[e,...t]=r;n=[...n,e],r=t}return r.length>0&&!n.some(e=>e.exiting)&&(n=t2(n)),{visible:n,pending:r}}(e.visible.filter(e=>e.id!==t.id),e.pending);default:return e}}function t8(e,t){switch(t.type){case"add":{let n=e.findIndex(e=>e.id===t.notice.id);if(-1===n)return[...e,t.notice].slice(-50);let r=[...e];return r[n]=t.notice,r}case"remove":return e.filter(e=>e.id!==t.id);case"clear":return t.sessionId?e.filter(e=>e.sessionId!==t.sessionId):[];case"prune":{let t=Date.now()-6e5;return e.filter(e=>!e.ts||e.ts>=t)}default:return e}}function t5(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 t6={padding:"6px 12px",border:"none",borderRadius:6,background:"transparent",color:"var(--text)",cursor:"pointer",fontSize:12,fontWeight:500,textAlign:"left",whiteSpace:"nowrap"};function t3({label:e}){let[t,n]=(0,a.useState)(null);if((0,a.useEffect)(()=>{let e=new AbortController;return fetch("/api/app-update",{signal:e.signal}).then(async e=>e.ok?e.json():null).then(e=>{e?.updateAvailable&&e.latestVersion&&e.releaseUrl&&n(e)}).catch(()=>{}),()=>e.abort()},[]),!t)return null;let i=e(t.latestVersion);return(0,r.jsxs)("a",{href:t.releaseUrl,target:"_blank",rel:"noopener noreferrer",title:i,"aria-label":i,onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},style:{display:"inline-flex",alignItems:"center",alignSelf:"center",gap:3,minHeight:32,minWidth:0,padding:"0 4px",background:"transparent",borderRadius:5,color:"var(--accent)",fontSize:12,fontWeight:600,lineHeight:1.2,textDecoration:"none",transition:"background 0.12s",whiteSpace:"nowrap"},children:[(0,r.jsxs)("span",{style:{overflow:"hidden",textOverflow:"ellipsis"},children:["v",t.latestVersion]}),(0,r.jsxs)("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},children:[(0,r.jsx)("path",{d:"M7 17 17 7"}),(0,r.jsx)("path",{d:"M7 7h10v10"})]})]})}function t7(e){return"user"===e.role||"custom"===e.role&&"compaction"===e.customType}function t9(e,t,n={}){let r={...e,content:t};return n.omitUsage&&(r.usage=void 0),r}function ne({messageCount:e,toolCallCount:t,defaultExpanded:n=!1,children:i,t:o}){let[s,l]=(0,a.useState)(n),d=[o("chat.processDetails"),`${e} ${o(1===e?"chat.message":"chat.messages")}`];return t>0&&d.push(`${t} ${o(1===t?"chat.toolCall":"chat.toolCalls")}`),(0,r.jsxs)("div",{style:{marginBottom:14},children:[(0,r.jsxs)("button",{type:"button","aria-expanded":s,onClick:()=>l(e=>!e),style:{display:"flex",alignItems:"center",gap:8,width:"auto",minHeight:24,padding:"2px 0",border:"none",background:"transparent",color:"#ffffff",mixBlendMode:"exclusion",cursor:"pointer",fontSize:12,textAlign:"left"},title:o(s?"chat.collapseProcess":"chat.expandProcess"),children:[(0,r.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:s?"rotate(90deg)":"none",transition:"transform 0.15s"},children:(0,r.jsx)("polyline",{points:"4 2.5 7.5 6 4 9.5"})}),(0,r.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d.join(" \xb7 ")})]}),s&&(0,r.jsx)("div",{style:{marginTop:8},children:i})]})}function nt({session:e,sessionRunning:t,newSessionCwd:s,newSessionId:l,newSessionDraftKey:d,newSessionTaskId:c,pendingNewSessionTaskRef:u,onAgentEnd:p,onAttentionNeeded:h,onSessionCreated:g,onSessionForked:x,onEnvWorktreeChange:f,modelsRefreshKey:m,chatInputRef:v,onBranchDataChange:b,onSystemPromptChange:y,onSystemPromptLoaderChange:k,onSessionStatsChange:L,onSessionStatsPanelOpen:R,onTodosChange:E,onContextUsageChange:z,onOpenFile:W,soundEnabled:$=!0,onSoundToggle:N,playDoneSound:B=()=>{},unlockAudio:F,terminalOpen:H=!1,onToggleTerminal:O,inWorkbench:U=!1,onAskInNewChat:_,quoteSelectionEnabled:q=!1,initialPrompt:V,onInitialPromptConsumed:J}){var K;let Y,{t:G}=(0,P.s)(),X=(0,A.a)(),{isDark:Z}=(0,D.D)(),Q=(0,a.useRef)(B);Q.current=B;let et=(0,a.useRef)($);et.current=$;let en=(0,a.useRef)(null),er=(0,a.useCallback)(()=>{et.current&&Q.current(),p?.()},[p]),ei=(0,a.useCallback)(e=>{v?.current?.replaceMessage(e)},[v]),{loading:eo,error:ea,messages:es,entryIds:el,parentIds:ed,streamState:ec,agentRunning:eu,bashRunning:ep,pendingBash:eh,modelNames:eg,modelList:ex,modelError:ef,modelScopeWarnings:em,modelThinkingLevels:ev,modelThinkingLevelMaps:eb,toolPreset:ek,thinkingLevel:ew,retryInfo:ej,contextUsage:eS,forkingEntryId:eM,commandBusy:eI,isCompacting:eR,compactError:eE,compactResult:eW,displayModel:eP,modelSwitching:e$,sessionStats:eN,todos:eD,slashCommands:eB,slashCommandsLoading:eA,queuedMessages:eF,notices:eH,noticeHistory:eO,extensionDialog:eU,extensionCustomUi:e_,extensionStatuses:eq,extensionWidgets:eV,respondToExtensionUi:eJ,sendExtensionCustomInput:eK,removeNotice:eX,clearNotices:eZ,setNoticeHistoryFrozen:eQ,isAutoModelSelection:e0,agentPhase:e1,isNew:e2,sessionIdRef:e4,messagesEndRef:e8,scrollContainerRef:e5,lastUserMsgRef:e6,isNearBottomRef:e3,handleSend:e9,handleAbort:te,handleFork:tt,handleNavigate:tn,handleModelChange:tr,handleCompact:ti,handleSteer:to,handleFollowUp:ta,handlePromptWithStreamingBehavior:ts,handleAbortCompaction:tl,handleRecallQueue:td,handleBuiltinSlashCommand:tc,handleToolPresetChange:tu,handleThinkingLevelChange:tp,loadSlashCommands:th,scrollToBottom:tg,loadContext:tx,activeLeafId:tf,hasOlderChat:tv}=function(e){let{session:t,sessionRunning:r,newSessionCwd:i,newSessionDraftKey:o,newSessionId:s,onAgentEnd:l,onAttentionNeeded:d,onSessionCreated:c,onSessionForked:u,modelsRefreshKey:p,onBranchDataChange:h,onSystemPromptChange:g,onSystemPromptLoaderChange:x,onSessionStatsPanelOpen:f}=e,m=null===t&&null!==i,[v,b]=(0,a.useState)(null),[y,k]=(0,a.useState)(!m),[w,j]=(0,a.useState)(null),[S,C]=(0,a.useState)(null),[T,M]=(0,a.useState)(!1),[I,L]=(0,a.useState)([]),[R,E]=(0,a.useState)([]),[z,W]=(0,a.useState)([]),[P,$]=(0,a.useState)([]),[N,D]=(0,a.useReducer)(tZ,tG),[B,A]=(0,a.useState)(!1),[F,H]=(0,a.useState)(!1),[O,U]=(0,a.useState)(null),[_,q]=(0,a.useState)({}),[V,J]=(0,a.useState)([]),[K,Y]=(0,a.useState)(null),[G,X]=(0,a.useState)([]),[Z,Q]=(0,a.useState)({}),[ee,et]=(0,a.useState)({}),[en,er]=(0,a.useState)(null),[ei,eo]=(0,a.useState)(null),[ea,es]=(0,a.useState)("default"),[el,ed]=(0,a.useState)("auto"),[ec,eu]=(0,a.useState)(null),[ep,eh]=(0,a.useState)(null),[eg,ex]=(0,a.useState)(null),[ef,em]=(0,a.useState)(null),[ev,eb]=(0,a.useState)(null),[ey,ek]=(0,a.useState)(null),[ew,ej]=(0,a.useState)(!1),[eS,eM]=(0,a.useState)(!1),[eI,eR]=(0,a.useState)(null),[eE,eW]=(0,a.useState)(null),[eP,e$]=(0,a.useState)(null),[eN,eD]=(0,a.useState)(null),[eB,eA]=(0,a.useState)([]),[eF,eH]=(0,a.useState)(!1),[eO,eU]=(0,a.useReducer)(t4,{visible:[],pending:[]}),[e_,eq]=(0,a.useReducer)(t8,void 0,()=>(function(){try{let e=window.localStorage.getItem(t0);if(!e)return[];let t=JSON.parse(e);if(!t||!Array.isArray(t.notices))return[];let n=Date.now()-6e5;return t.notices.filter(e=>e&&"string"==typeof e.message&&(t.savedAt??0)>=n).slice(-50)}catch{return[]}})()),[eV,eJ]=(0,a.useState)(null),[eK,eY]=(0,a.useState)(null),[eG,eX]=(0,a.useState)(null),[eZ,eQ]=(0,a.useState)([]),[e0,e1]=(0,a.useState)([]),[e2,e4]=(0,a.useState)({steering:[],followUp:[]}),e8=(0,a.useRef)(null),e5=(0,a.useRef)(null),e6=(0,a.useRef)(null),e3=(0,a.useRef)(0),e7=(0,a.useRef)(!1),e9=(0,a.useRef)(t?.id??null),te=(0,a.useRef)(t?.id??null),tt=(0,a.useRef)(!!r),tn=(0,a.useRef)(!1),tr=(0,a.useRef)(!1),ti=(0,a.useRef)(!1),to=(0,a.useRef)(-1),ta=(0,a.useRef)(!1),ts=(0,a.useRef)(0),tl=(0,a.useRef)(null),td=(0,a.useRef)(!1),tc=(0,a.useRef)(null),tu=(0,a.useRef)(!1),tp=(0,a.useRef)(!0),th=(0,a.useRef)(0),tg=(0,a.useRef)([]),tx=(0,a.useRef)(void 0),tf=(0,a.useRef)(null),tm=(0,a.useRef)(null),tv=(0,a.useRef)(null),tb=(0,a.useRef)(!1),ty=(0,a.useRef)(null),tk=(0,a.useRef)(null),tw=(0,a.useRef)(0),tj=(0,a.useRef)(null),tS=(0,a.useRef)(!1),tC=(0,a.useRef)(!0);te.current=t?.id??null,tt.current=!!r,e5.current||(e5.current=new tq({createSource:e=>new EventSource(`/api/agent/${encodeURIComponent(e)}/events`),onEvent:e=>tl.current?.(e),shouldMaintain:e=>tC.current&&e9.current===e&&(tn.current||e7.current||te.current===e&&tt.current),readinessTimeoutMs:6e4,reconnectDelayMs:1e3,onUnexpectedError:e=>{console.error("Failed to maintain the agent event stream:",e)}}));let tT=e.setToolPreset??es;(0,a.useLayoutEffect)(()=>{m&&!e9.current&&tT(function(e=tH()){if(!e)return"default";try{let t=e.getItem(tF);return(0,tA.sn)(t)?t:"default"}catch{return"default"}}())},[m,tT]);let tM=(0,a.useCallback)((e="smooth")=>{let t=tm.current;tf.current?.scrollIntoView({behavior:e}),t&&(th.current=t.scrollTop)},[]);(0,a.useEffect)(()=>{tg.current=R},[R]);let tI=ev??v?.context.model??ey??null,tL=m?en??ei:tI,tR=t?.id??o??void 0,tE=(0,a.useRef)(void 0);tE.current=tR;let tz=(0,a.useCallback)((t,n)=>{let r=n?.map(({data:e,mimeType:t})=>({data:e,mimeType:t})),i=tE.current;if(!tC.current&&!tb.current&&i===o)return;let a=e.chatInputRef?.current;if(a)a.restoreSubmission(t,r,i);else{let e,n;i&&(n=eL(t,r,(e=eC(i)??{value:"",images:[]}).value,e.images),eT(i,n))}},[o,e.chatInputRef]),tW=(0,a.useMemo)(()=>{if(eV)return{...eV,totalActiveMs:v?.totalActiveMs};let e={input:0,output:0,cacheRead:0,cacheWrite:0,total:0},n=0,r=0,i=0,o=0,a=0;for(let t of I){if("user"===t.role&&(r+=1),"toolResult"===t.role&&(o+=1),"assistant"!==t.role)continue;i+=1;let s=t.usage;a+=t.content.filter(e=>"toolCall"===e.type).length,s&&(e.input+=s.input??0,e.output+=s.output??0,e.cacheRead+=s.cacheRead??0,e.cacheWrite+=s.cacheWrite??0,n+=s.cost?.total??0)}return(e.total=e.input+e.output+e.cacheRead+e.cacheWrite,0===e.total&&0===I.length)?null:{sessionFile:v?.filePath||void 0,sessionId:e9.current??t?.id??"",sessionName:t?.name,userMessages:r,assistantMessages:i,toolCalls:a,toolResults:o,totalMessages:I.length,tokens:e,cost:n,totalActiveMs:v?.totalActiveMs,...ep?{contextUsage:ep}:{}}},[I,eV,ep,v?.filePath,v?.totalActiveMs,t?.id,t?.name]),tP=(0,a.useCallback)(async(e,t=!1,n=!1)=>{let r=!1;try{t&&k(!0);let i=new URLSearchParams({deferThinking:"1"}),o=await fetch(`/api/sessions/${encodeURIComponent(e)}?${i}`);if(404===o.status)return t&&(b(null),C(null),L([]),$([]),j(null)),null;if(!o.ok)throw Error(`HTTP ${o.status}`);let a=await o.json();if(e9.current!==e)return null;let s=a.context.messages;b(a),C(a.leafId);let l=a.context.entryIds??[],d=tg.current,c=-1;if(l.length>0&&d.length>0){let e=d.lastIndexOf(l[0]);if(e>=0){let t=Math.min(l.length,d.length-e),n=t>0;for(let r=0;r<t;r++)if(d[e+r]!==l[r]){n=!1;break}n&&(c=e)}}if(c>=0?(L(e=>e.length>c?[...e.slice(0,c),...s]:s),E(e=>{let t=[...e.slice(0,c),...l];return tg.current=t,t}),W(e=>{let t=a.context.parentIds??l.map(()=>null);return[...e.slice(0,c),...t]})):(tg.current=l,L(s),E(l),W(a.context.parentIds??l.map(()=>null))),$(a.context.todos??[]),M(a.hasMore??!1),eb(e=>tS.current?e:null),j(null),a.context.thinkingLevel&&"off"!==a.context.thinkingLevel&&ed(a.context.thinkingLevel),r=!0,t&&k(!1),!n)return null;try{let t=await fetch(`/api/sessions/${encodeURIComponent(e)}/state`);if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();if(e9.current!==e)return null;let r=n.state;return r?(void 0!==r.contextUsage&&eh(r.contextUsage??null),void 0!==r.systemPrompt&&ex(r.systemPrompt??null),void 0!==r.thinkingLevel&&ed(r.thinkingLevel??"auto"),void 0!==r.extensionStatuses&&eQ(r.extensionStatuses??[]),void 0!==r.extensionWidgets&&e1(r.extensionWidgets??[]),void 0!==r.queuedMessages&&e4(tQ(r.queuedMessages))):n.running||e4({steering:[],followUp:[]}),n}catch(e){return console.error("Failed to load agent state:",e),null}}catch(e){return j(String(e)),null}finally{t&&!r&&k(!1)}},[]),tN=(0,a.useCallback)(async(e,t,n,r)=>{try{let i=new URLSearchParams({deferThinking:"1"});null===t?i.set("leafId","null"):t&&i.set("leafId",t),n&&i.set("before",n),r&&r>0&&i.set("tail",String(r));let o=`/api/sessions/${encodeURIComponent(e)}/context?${i}`,a=await fetch(o);if(!a.ok)throw Error(`HTTP ${a.status}`);let s=await a.json();M(s.hasMore??!1);let l=e=>e??s.context.entryIds.map(()=>null);return n?(L(e=>[...s.context.messages,...e]),E(e=>{let t=[...s.context.entryIds,...e];return tg.current=t,t}),W(e=>[...l(s.context.parentIds),...e])):(L(s.context.messages),E(()=>{let e=s.context.entryIds??[];return tg.current=e,e}),W(l(s.context.parentIds)),$(s.context.todos??[])),{entryIds:s.context.entryIds,hasMore:s.hasMore??!1}}catch(e){return console.error("Failed to load context:",e),null}},[]),tO=(0,a.useCallback)(async e=>{try{let t=await (0,tB.$J)(e,{type:"get_tools"});if(t){let{getPresetFromTools:e}=await Promise.resolve().then(n.bind(n,14755));tT(e(t))}}catch(e){console.error("Failed to load tools:",e)}},[tT]),t_=(0,a.useCallback)((e=0,t="(no messages)")=>{let n=e9.current;if(!m||!i||!n||tb.current)return;tb.current=!0;let r=s??n;c?.({id:n,path:"",cwd:i,name:void 0,created:new Date().toISOString(),modified:new Date().toISOString(),messageCount:e,firstMessage:t,transient:!0},r)},[m,i,s,c]),tK=(0,a.useCallback)(async()=>{if(e9.current||!m||!i)return e9.current;if(tv.current)return tv.current;let t=s??(0,ez.S)();e9.current=t;let n=(async()=>{let n=ty.current,r=tk.current;n&&ek(n);let o=(0,tA.xG)(ea),a=e.pendingNewSessionTaskRef?.current,s=a?.taskId&&a.draftId===t?a.taskId:void 0,l=await fetch("/api/agent/new",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:i,type:"ensure_session",id:t,toolNames:o,...s?{taskId:s}:{},...n?{provider:n.provider,modelId:n.modelId}:{},...r?{thinkingLevel:r}:{}})});if(!l.ok)throw Error(`HTTP ${l.status}`);let d=await l.json(),c=d.sessionId;return e9.current=c,d.model&&ty.current===n&&(ek(d.model),n||eo(d.model)),d.thinkingLevel&&tk.current===r&&ed(d.thinkingLevel),c})();tv.current=n;try{return await n}catch(e){throw e9.current===t&&(e9.current=null),e}finally{tv.current=null}},[m,i,s,ea,e.pendingNewSessionTaskRef]),tX=(0,a.useCallback)(async()=>{let e=e9.current??await tK();if(!e)return;let t=await (0,tB.$J)(e,{type:"get_state"});tC.current&&e9.current===e&&ex(t.systemPrompt??"")},[tK]),t2=(0,a.useCallback)(async()=>{let e=e9.current??await tK();if(!e)return eA([]),[];eH(!0);try{let t=await (0,tB.$J)(e,{type:"get_commands"}),n=t?.commands??[];return eA(n),n}catch(e){return console.error("Failed to load slash commands:",e),eA([]),[]}finally{eH(!1)}},[tK]),t6=(0,a.useCallback)(()=>{e3.current+=1,e7.current=!1,e6.current&&(clearTimeout(e6.current),e6.current=null)},[]),t3=(0,a.useCallback)(()=>{e5.current?.close()},[]),t7=(0,a.useCallback)(e=>e5.current.ensureConnected(e),[]),t9=(0,a.useCallback)(e=>{e5.current.maintain(e)},[]);(0,a.useEffect)(()=>{if(t?.id&&r)return t9(t.id),()=>{e9.current!==t.id||tn.current||e7.current||te.current===t.id&&tt.current||e5.current?.close()}},[t9,t?.id,r]);let ne=(0,a.useCallback)(async(e,t)=>{let n=e9.current;if(eY(t=>t?.id===e.id?null:t),n)try{await (0,tB.$J)(n,{type:"extension_ui_response",id:e.id,...t})}catch(e){console.error("Failed to send extension UI response:",e)}},[]),nt=(0,a.useCallback)(async(e,t)=>{let n=e9.current;if(n)try{await (0,tB.$J)(n,{type:"extension_ui_input",id:e.id,data:t})}catch(e){console.error("Failed to send extension custom UI input:",e)}},[]),nn=(0,a.useCallback)(e=>{let t=e.message.trim();if(!t)return;let n={id:e.id??(0,ez.S)(),message:t,type:e.type??"info",ts:Date.now(),sessionId:e9.current??void 0};eU({type:"add",notice:n}),eq({type:"add",notice:n})},[]),nr=(0,a.useCallback)(e=>{eq({type:"remove",id:e})},[]),ni=(0,a.useCallback)(()=>{eq({type:"clear",sessionId:e9.current??void 0})},[]),no=(0,a.useCallback)(t=>{switch((0,t$.YI)(t)&&d?.(t),t.method){case"select":case"confirm":case"input":case"editor":eY(t);break;case"notify":nn({id:t.id,message:t.message,type:t.notifyType??"info"});break;case"setStatus":eQ(e=>{let n=e.filter(e=>e.key!==t.statusKey);return void 0!==t.statusText?[...n,{key:t.statusKey,text:t.statusText}]:n});break;case"setWidget":e1(e=>{let n=e.filter(e=>e.key!==t.widgetKey);return t.widgetLines?[...n,{key:t.widgetKey,lines:t.widgetLines,placement:t.widgetPlacement??"aboveEditor"}]:n});break;case"setTitle":t.title&&(document.title=t.title);break;case"set_editor_text":e.chatInputRef?.current?.insertText(t.text);break;case"custom":eX(e=>t.closed?e?.id===t.id?null:e:t)}},[nn,d,e.chatInputRef]),na=(0,a.useCallback)(()=>{let e=tn.current;return tn.current=!1,A(!1),eD(null),eu(null),D({type:"end"}),e},[]),ns=(0,a.useCallback)(e=>to.current!==e&&(to.current=e,l?.(),!0),[l]),nl=(0,a.useCallback)(e=>{t6(),e7.current=!0;let t=e3.current,n=async()=>{if(t===e3.current&&e9.current===e&&e7.current)try{let r=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(!r.ok)throw Error(`HTTP ${r.status}`);let i=await r.json();if(t!==e3.current||e9.current!==e||!e7.current)return;let o=i.state;if(i.running&&o&&(o.isStreaming||o.isPromptRunning)){e7.current=!1,e6.current=null,tr.current=!!o?.isStreaming,ti.current=!!o?.isPromptRunning,tn.current=!0,A(!0),eD(o?.isStreaming?{kind:"waiting_model"}:{kind:"running_command"});return}if(i.running&&o?.isCompacting){eM(!0),e6.current=setTimeout(()=>void n(),600);return}e7.current=!1,e6.current=null,t3()}catch{if(t!==e3.current||e9.current!==e||!e7.current)return;e6.current=setTimeout(()=>void n(),600)}};e6.current=setTimeout(()=>void n(),3e4)},[t6,t3]),nd=(0,a.useCallback)(async(e=e9.current,t=tw.current)=>{if(tw.current===t)try{e&&await tP(e)}finally{if(tw.current!==t)return;let n=ti.current,r=tr.current;ti.current=!1,tr.current=!1,tj.current=null;let i=na();n?ns(t):r&&i&&l?.(),e&&nl(e)}},[tP,ns,l,nl,na]),nc=(0,a.useCallback)(async(e,t)=>{await t1(800);let n=Date.now();for(;tn.current&&Date.now()-n<2e4;){if(void 0!==t&&tw.current!==t)return;try{let n=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(n.ok){let r=await n.json(),i=r.state;if(!r.running||!i||!i.isStreaming&&!i.isPromptRunning)return void await nd(e,t)}}catch{}await t1(600)}},[nd]),nu=(0,a.useCallback)(async e=>{let t=ts.current+1;for(ts.current=t;ta.current&&ts.current===t&&e9.current===e;){await t1(1e3);try{let n=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(!n.ok)continue;let r=await n.json();if(r.state?.isBashRunning)continue;if(await tP(e),ts.current!==t||e9.current!==e)return;ta.current=!1,H(!1),U(null);return}catch{}}},[tP]),np=(0,a.useCallback)(async e=>{if(!tn.current||e9.current!==e)return;let t=tw.current;try{let n=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(!n.ok)return;let r=await n.json();if(e9.current!==e||tw.current!==t)return;let i=r.state;if(eM(i?.isCompacting??!1),e4(tQ(i?.queuedMessages)),r.running&&i&&(i.isStreaming||i.isPromptRunning||i.isCompacting)){tr.current=!!i.isStreaming,ti.current=!!i.isPromptRunning;return}if(!tn.current)return;i&&(void 0!==i.contextUsage&&eh(i.contextUsage??null),void 0!==i.systemPrompt&&ex(i.systemPrompt??null),void 0!==i.extensionStatuses&&eQ(i.extensionStatuses??[]),void 0!==i.extensionWidgets&&e1(i.extensionWidgets??[])),await nd(e,t)}catch{}},[nd]);(0,a.useEffect)(()=>{if(!B)return;let e=()=>{let e=e9.current;e&&np(e)},t=()=>{"visible"===document.visibilityState&&e()},n=setInterval(e,15e3);return document.addEventListener("visibilitychange",t),window.addEventListener("online",e),()=>{clearInterval(n),document.removeEventListener("visibilitychange",t),window.removeEventListener("online",e)}},[B,np]),(0,a.useEffect)(()=>{tn.current=B},[B]),tl.current=(0,a.useCallback)(e=>{switch(e.type){case"connected":D({type:"end"}),!0===e.isStreaming&&(t6(),tr.current=!0,tn.current=!0,A(!0),eD({kind:"waiting_model"}));break;case"agent_start":t6(),tr.current=!0,tn.current=!0,A(!0),eD({kind:"waiting_model"}),D({type:"start"});break;case"agent_end":if(!tn.current)break;eD(null),eu(null),D({type:"end"}),e9.current&&(tP(e9.current),fetch(`/api/agent/${encodeURIComponent(e9.current)}`).then(e=>e.json()).then(e=>{e.state?.contextUsage!==void 0&&eh(e.state.contextUsage??null),e.state?.systemPrompt!==void 0&&ex(e.state.systemPrompt??null),e.state?.extensionStatuses!==void 0&&eQ(e.state.extensionStatuses??[]),e.state?.extensionWidgets!==void 0&&e1(e.state.extensionWidgets??[]),e4(tQ(e.state?.queuedMessages))}).catch(()=>{}));break;case"agent_settled":{let e=tr.current;if(tr.current=!1,!e||ti.current)break;let t=e9.current,n=na();eM(!1),t&&(tP(t),nl(t)),n&&l?.();break}case"prompt_done":{let e=tw.current,t=ti.current;ti.current=!1,tj.current=null;let n=ns(e);if(!t&&!n)break;let r=e9.current;r&&tP(r),!tr.current&&(na(),r&&nl(r))}break;case"prompt_error":nn({type:"error",message:e.errorMessage??"Command failed"});break;case"extension_error":nn({type:"error",message:e.error??"Extension command failed"});break;case"message_start":case"message_update":if(!tn.current)break;if("message_start"===e.type){let t=e.message;if(t?.role==="user")break;t?.role==="assistant"?(D({type:"snapshot",message:t}),t.content.length>0&&eD(null)):t&&eD(null)}else{let t=e.assistantMessageEvent;t&&(D({type:"delta",event:t}),"toolcall_start"!==t.type&&"toolcall_delta"!==t.type&&eD(null))}break;case"message_end":{if(!tn.current)break;let t=e.message;if(t&&"user"===t.role){let e=tD(t),n=tU(e),r=tj.current;tj.current=null,L(t=>{let i=t[t.length-1];return r&&i?.role==="user"&&tU(i)===r?r===n?t:[...t.slice(0,-1),e]:[...t,e]})}else t&&L(e=>[...e,tD(t)]);D({type:"end"}),eD({kind:"waiting_model"});break}case"tool_execution_start":{let t=e.toolCallId,n=e.toolName;eD(e=>{let r=e?.kind==="running_tools"?[...e.tools]:[];return r.some(e=>e.id===t)||r.push({id:t,name:n}),{kind:"running_tools",tools:r}});break}case"tool_execution_update":{let t=e.toolCallId,n=e.toolName,r=function(e){if(!tV(e))return null;let t=e.content;if(!Array.isArray(t))return null;let n=t.filter(e=>tV(e)&&"text"===e.type&&"string"==typeof e.text).map(e=>e.text).join("\n").split(/\r?\n/),r="";for(let e=n.length-1;e>=0&&!(r=n[e].trim());e-=1);if(!r)return null;let i=r.replace(/\s+/g," ");return i.length<=500?i:`...${i.slice(-497)}`}(e.partialResult);eD(e=>{let i=e?.kind==="running_tools"?[...e.tools]:[],o=i.find(e=>e.id===t),a={id:t,name:n||o?.name||"tool",progress:r??o?.progress};return{kind:"running_tools",tools:[...i.filter(e=>e.id!==t),a]}});break}case"tool_execution_end":{let t=e.toolCallId;if(e.toolName===tJ.Y0&&!0!==e.isError){let t=(0,tJ.aO)(e.result?.details);t&&$(t.todos)}eD(e=>{if(e?.kind!=="running_tools")return e;let n=e.tools.filter(e=>e.id!==t);return 0===n.length?{kind:"waiting_model"}:{kind:"running_tools",tools:n}});break}case"queue_update":e4({steering:[...e.steering??[]],followUp:[...e.followUp??[]]});break;case"auto_retry_start":eu({attempt:e.attempt,maxAttempts:e.maxAttempts,errorMessage:e.errorMessage});break;case"auto_retry_end":eu(null);break;case"auto_compaction_start":case"compaction_start":eM(!0),eW(null),e$(null);break;case"auto_compaction_end":case"compaction_end":eM(!1),e.errorMessage?(eW(e.errorMessage),e$(null)):!e.aborted&&(e$(t5(e.result,e.reason??"auto")),e9.current&&tP(e9.current));break;case"extension_ui_request":no(e)}},[nn,t6,no,tP,ns,l,nl,na]);let nh=(0,a.useCallback)(async(e,n)=>{let r=e.trim();if(!r&&!n?.length)return;if(tn.current||ta.current||e8.current)return void tz(e,n);let o=!n?.length&&r.startsWith("/");if(!n?.length&&r.startsWith("!")){let t=r.startsWith("!!"),i=(t?r.slice(2):r.slice(1)).trim();return i?void await tx.current?.(i,t):void tz(e,n)}let a=tw.current+1;t6(),ti.current=!0;let s=n?.map(e=>({type:"image",source:{type:"base64",media_type:e.mimeType,data:e.data}})),l={role:"user",content:s?.length?[...e.trim()?[{type:"text",text:e}]:[],...s]:e,timestamp:Date.now()};L(e=>[...e,l]),tj.current=tU(l),tw.current=a,tn.current=!0,A(!0),eD(o?{kind:"running_command"}:{kind:"waiting_model"}),D({type:"start"}),tu.current=!0;let d=n?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType})),c=null,u=!1;try{if(m&&i){let t=e9.current??await tv.current,n=t??await tK();if(!n)throw Error("Unable to create a session for the prompt");c=n,en&&(ek(en),t&&await (0,tB.$J)(n,{type:"set_model",provider:en.provider,modelId:en.modelId})),await t7(n),u=!0,t_(1,e),await (0,tB.$J)(n,{type:"prompt",message:e,...d?.length?{images:d}:{}})}else if(t)c=t.id,await t7(t.id),u=!0,await (0,tB.$J)(t.id,{type:"prompt",message:e,...d?.length?{images:d}:{}});else throw Error("No active session for the prompt");o&&c&&nc(c,a)}catch(t){if(console.error("Failed to send message:",t),!(!u||(0,tB.RE)(t))&&c)return void nc(c,a);if(ti.current=!1,L(e=>{let t=e.lastIndexOf(l);return -1===t?e:[...e.slice(0,t),...e.slice(t+1)]}),nn({type:"error",message:t instanceof Error?t.message:String(t)}),tz(e,n),tj.current=null,c)return void np(c);tn.current=!1,t3(),A(!1),eD(null),D({type:"end"})}},[m,i,en,t,tK,t7,t_,nc,nn,t6,t3,np,tz]);tx.current=(0,a.useCallback)(async(e,n)=>{if(tn.current||ta.current||e8.current)return;let r=`${n?"!!":"!"}${e}`;ta.current=!0,U({command:e,excludeFromContext:n}),H(!0);try{let i=e9.current??t?.id??await tK();if(!i)throw Error("Unable to create a session for the shell command");t_(1,r),await (0,tB.$J)(i,{type:"bash",command:e,excludeFromContext:n}),await tP(i)}catch(e){console.error("Failed to execute shell command:",e),nn({type:"error",message:e instanceof Error?e.message:String(e)}),tz(r,void 0)}finally{ta.current=!1,U(null),H(!1)}},[nn,tK,tP,t_,tz,t]);let ng=(0,a.useCallback)(async()=>{let t=e9.current;if(!t)return;if(ta.current){try{await (0,tB.$J)(t,{type:"abort_bash"})}catch(e){console.error("Failed to abort bash:",e)}return}let n=[];try{let e=await (0,tB.$J)(t,{type:"clear_queue"});e4({steering:[],followUp:[]}),n=[...e?.steering??[],...e?.followUp??[]]}catch(e){console.error("Failed to recall queued messages on abort:",e)}n.length>0&&e.chatInputRef?.current?.prependText(n.join("\n\n"));try{await (0,tB.$J)(t,{type:"abort"})}catch(e){console.error("Failed to abort:",e)}},[e.chatInputRef]),nx=(0,a.useCallback)(async e=>{if(ta.current||e8.current)return;let t=e9.current;if(t){em(e);try{let{cancelled:n,newSessionId:r}=await (0,tB.$J)(t,{type:"fork",entryId:e})??{};!n&&r&&u?.(r)}catch(e){console.error("Fork failed:",e)}finally{em(null)}}},[u]),nf=(0,a.useCallback)(async(e,t)=>{if(ta.current||e8.current)return;let n=e9.current;if(!n)return;let r=void 0===t?e:t;try{await (0,tB.$J)(n,{type:"navigate_tree",targetId:e})}catch(e){console.error("Navigate failed:",e)}C(r),await tN(n,r)},[tN]),nm=(0,a.useCallback)(async e=>{if(ta.current||e8.current)return;C(e);let t=e9.current;t&&(await tN(t,e),e&&(0,tB.$J)(t,{type:"navigate_tree",targetId:e}).catch(()=>{}))},[tN]),nv=(0,a.useCallback)(async(e,t)=>{if(m){let n={provider:e,modelId:t};ty.current=n,er(n),ek(n);let r=e9.current??await tv.current;if(!r)return;try{await (0,tB.$J)(r,{type:"set_model",provider:e,modelId:t})}catch(e){console.error("Failed to set model:",e)}return}let n=e9.current;if(n&&!tS.current){tS.current=!0,eb({provider:e,modelId:t}),ej(!0);try{await (0,tB.$J)(n,{type:"set_model",provider:e,modelId:t}),tS.current=!1,await tP(n)}catch(e){console.error("Failed to set model:",e),tS.current=!1,eb(ev),nn({type:"error",message:`Failed to switch model: ${e instanceof Error?e.message:String(e)}`}),await tP(n)}finally{tS.current=!1,ej(!1)}}},[nn,ev,m,tP,er]),nb=(0,a.useCallback)(async(e,t)=>{if(e8.current)return!1;e8.current={name:e},eR({name:e});try{return await t(),!0}finally{e8.current=null,eR(null)}},[]),ny=(0,a.useCallback)(async()=>{let e=e9.current;e&&!eS&&await nb("compact",async()=>{eM(!0),eW(null),e$(null);try{let t=await (0,tB.$J)(e,{type:"compact"});e$(t5(t,"manual")),await tP(e,!0)}catch(e){eW(e instanceof Error?e.message:String(e)),e$(null)}finally{eM(!1)}})},[eS,tP,nb]),nk=(0,a.useCallback)(async e=>{let n=i??t?.cwd??"",r=n?`/api/models?cwd=${encodeURIComponent(n)}`:"/api/models",o=await fetch(r,e?{signal:e}:void 0);if(!o.ok)throw Error(`HTTP ${o.status}`);let a=await o.json();q(a.models),Y(a.modelError??null),X(a.modelScopeWarnings??[]),Q(a.thinkingLevels??{}),et(a.thinkingLevelMaps??{});let s=a.modelList??[];if(J(s),m&&!e9.current){let e=a.defaultModel?s.find(e=>e.id===a.defaultModel?.modelId&&e.provider===a.defaultModel?.provider):void 0;eo(e?{provider:e.provider,modelId:e.id}:null);let t=e&&a.thinkingLevelPins?.[`${e.provider}/${e.id}`];null===tk.current&&ed(t??"auto")}},[m,i,t?.cwd]),nw=(0,a.useCallback)(async e=>{if(!e.startsWith("/"))return{handled:!1};let t=e.match(/^\/([^\s]+)(?:\s+([\s\S]*))?$/);if(!t)return{handled:!1};let[,n,r=""]=t,i=r.trim(),o=e9.current??await tK(),a=e=>(e.handled&&(e.error?nn({type:"error",message:e.error}):"openSessionStats"!==e.action&&nn({type:"success",message:e.message??"Command completed"})),e);if(e8.current)return a({handled:!0,error:"Another command is still running"});try{switch(n){case"compact":if(!o)return a({handled:!0,error:"No active session to compact"});if(eS)return a({handled:!0,error:"Compaction already in progress"});if(!await nb("compact",async()=>{eM(!0),eW(null),e$(null);let e=await (0,tB.$J)(o,{type:"compact",...i?{customInstructions:i}:{}});e$(t5(e,"manual")),await tP(o,!0)&&t_()}))return a({handled:!0,error:"Another command is still running"});return a({handled:!0,message:"Compacted context"});case"reload":if(!o)return a({handled:!0,error:"No active session to reload"});if(!await nb("reload",async()=>{await (0,tB.$J)(o,{type:"reload"}),await Promise.all([tP(o,!1,!0),tO(o),t2(),nk()])}))return a({handled:!0,error:"Another command is still running"});return a({handled:!0,message:"Reloaded session resources"});case"name":if(!o)return a({handled:!0,error:"No active session to name"});if(!i)return a({handled:!0,error:"Usage: /name <name>"});return await (0,tB.$J)(o,{type:"set_session_name",name:i}),await tP(o)&&t_(),a({handled:!0,message:`Session renamed to ${i}`});case"session":{if(!o)return a({handled:!0,error:"No active session"});let e=await (0,tB.$J)(o,{type:"get_session_stats"});return e&&eJ(e),f?.(),a({handled:!0,action:"openSessionStats"})}case"copy":{if(!o)return a({handled:!0,error:"No active session"});let e=await (0,tB.$J)(o,{type:"get_last_assistant_text"}),t=e?.text??"";if(!t)return a({handled:!0,error:"No assistant message to copy"});return await navigator.clipboard.writeText(t),a({handled:!0,message:"Copied last assistant message"})}default:return{handled:!1}}}catch(e){return a({handled:!0,error:e instanceof Error?e.message:String(e)})}finally{"compact"===n&&eM(!1)}},[nn,tK,eS,nk,tP,t2,tO,t_,f,nb]),nj=(0,a.useCallback)(async(e,t,n)=>{let r=e9.current;if(!r){tz(e,n),nn({type:"error",message:"No active session for the queued message"});return}let i=n?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType}));try{await (0,tB.$J)(r,{type:"prompt",message:e,streamingBehavior:t,...i?.length?{images:i}:{}})}catch(t){console.error("Failed to submit streaming prompt:",t),(0,tB.RE)(t)&&tz(e,n),nn({type:"error",message:t instanceof Error?t.message:String(t)})}},[nn,tz]),nS=(0,a.useCallback)(async(e,t)=>{await nj(e,"steer",t)},[nj]),nC=(0,a.useCallback)(async(e,t,n)=>{await nj(e,t,n)},[nj]),nT=(0,a.useCallback)(async(e,t)=>{await nj(e,"followUp",t)},[nj]),nM=(0,a.useCallback)(async()=>{let e=e9.current;if(e)try{await (0,tB.$J)(e,{type:"abort_compaction"})}catch(e){console.error("Failed to abort compaction:",e)}},[]),nI=(0,a.useCallback)(async()=>{let t=e9.current;if(t)try{let n=await (0,tB.$J)(t,{type:"clear_queue"});e4({steering:[],followUp:[]});let r=[...n?.steering??[],...n?.followUp??[]];r.length>0&&e.chatInputRef?.current?.prependText(r.join("\n\n"))}catch(e){console.error("Failed to recall queued messages:",e),nn({type:"error",message:"Failed to recall queued messages"})}},[e.chatInputRef,nn]),nL=(0,a.useCallback)(async e=>{if(ed(e),m&&!e9.current&&(tk.current="auto"===e?null:e),"auto"===e)return;let t=e9.current??await tv.current;if(t)try{await (0,tB.$J)(t,{type:"set_thinking_level",level:e})}catch(e){console.error("Failed to set thinking level:",e)}},[m]),nR=(0,a.useCallback)(async e=>{let t=(0,tA.xG)(e);!function(e,t=tH()){if(t)try{t.setItem(tF,e)}catch{}}(e),tT(e);let n=e9.current??await tv.current;if(n)try{await (0,tB.$J)(n,{type:"set_tools",toolNames:t})}catch(e){console.error("Failed to set tools:",e)}},[tT]),nE=(0,a.useCallback)(()=>{let e=tm.current,t=tc.current;if(!e||!t)return;let n=Math.min(Math.max(0,t.getBoundingClientRect().top-e.getBoundingClientRect().top+e.scrollTop-16),Math.max(0,e.scrollHeight-e.clientHeight));tp.current=!0,th.current=n,e.scrollTo({top:n,behavior:"auto"})},[]),nz=(0,a.useCallback)(()=>{let e=tm.current;if(e){let{scrollTop:t,clientHeight:n,scrollHeight:r}=e,i=tn.current,o=tp.current,a=function(e,t,n,r,i,o=96){return!!tY(n,r,i)||!(n<t)&&(!!(!e&&n>t&&tY(n,r,i,o))||e)}(o,th.current,t,n,r,i?96:8);tp.current=a,th.current=t,!o&&a&&i&&tM("auto")}},[tM]);(0,a.useEffect)(()=>(tC.current=!0,t&&(e9.current=t.id,tP(t.id,!0,!0).then(e=>{e?.running&&(tO(t.id),(e.state?.isStreaming||e.state?.isPromptRunning)&&(tr.current=!!e.state.isStreaming,ti.current=!!e.state.isPromptRunning,tn.current=!0,A(!0),eD(e.state.isStreaming?{kind:"waiting_model"}:{kind:"running_command"}),D({type:"start"}),t9(t.id),!e.state.isStreaming&&e.state.isPromptRunning&&nc(t.id)),e.state?.isBashRunning&&(ta.current=!0,H(!0),nu(t.id))),e?.state&&(void 0!==e.state.isCompacting&&eM(e.state.isCompacting),void 0!==e.state.contextUsage&&eh(e.state.contextUsage??null),void 0!==e.state.systemPrompt&&ex(e.state.systemPrompt??null),void 0!==e.state.thinkingLevel&&ed(e.state.thinkingLevel??"auto"),void 0!==e.state.extensionStatuses&&eQ(e.state.extensionStatuses??[]),void 0!==e.state.extensionWidgets&&e1(e.state.extensionWidgets??[]),void 0!==e.state.queuedMessages&&e4(tQ(e.state.queuedMessages)))})),()=>{tC.current=!1,ts.current+=1,t6(),t3()}),[]),(0,a.useEffect)(()=>{g?.(eg)},[eg,g]),(0,a.useEffect)(()=>(x?.(tX),()=>x?.(null)),[tX,x]),(0,a.useEffect)(()=>{h&&h(v?.tree??[],S,nm)},[v?.tree,S,nm,h]),(0,a.useEffect)(()=>{let e=tm.current;if(e)return th.current=e.scrollTop,e.addEventListener("scroll",nz,{passive:!0}),()=>{e.removeEventListener("scroll",nz)}},[I.length,y,nz]),(0,a.useLayoutEffect)(()=>{I.length>0&&(tu.current?(tu.current=!1,td.current=!0,nE()):td.current?!tn.current&&tp.current&&tM("auto"):(td.current=!0,tM("instant")))},[I.length,B,tM,nE]),(0,a.useEffect)(()=>{let e=new AbortController;return nk(e.signal).catch(e=>{if(e instanceof DOMException&&"AbortError"===e.name)return}),()=>e.abort()},[nk,p]),(0,a.useEffect)(()=>{if(!eP)return;let e=setTimeout(()=>e$(null),6e3);return()=>clearTimeout(e)},[eP]),(0,a.useEffect)(()=>{if(0===eO.visible.length)return;let e=eO.visible.find(e=>e.exiting);if(e){let t=setTimeout(()=>{eU({type:"remove",id:e.id})},180);return()=>clearTimeout(t)}if(!eO.visible[0])return;let t=setTimeout(()=>{eU({type:"mark_oldest_exiting"})},5e3);return()=>clearTimeout(t)},[eO.visible]),(0,a.useEffect)(()=>{try{window.localStorage.setItem(t0,JSON.stringify({savedAt:Date.now(),notices:e_.slice(-50)}))}catch{}},[e_]);let nW=(0,a.useRef)(!1);return(0,a.useEffect)(()=>{let e=setInterval(()=>{nW.current||eq({type:"prune"})},3e4);return()=>clearInterval(e)},[]),(0,a.useEffect)(()=>{eJ(null)},[I.length,ep?.tokens,ep?.percent,ep?.contextWindow]),{data:v,loading:y,error:w,activeLeafId:S,messages:I,entryIds:R,parentIds:z,todos:P,streamState:N,agentRunning:B,modelNames:_,modelList:V,modelError:K,modelScopeWarnings:G,modelThinkingLevels:Z,modelThinkingLevelMaps:ee,newSessionModel:en,toolPreset:ea,thinkingLevel:el,retryInfo:ec,contextUsage:ep,systemPrompt:eg,forkingEntryId:ef,isCompacting:eS,compactError:eE,compactResult:eP,currentModel:tI,displayModel:tL,modelSwitching:ew,sessionStats:tW,slashCommands:eB,slashCommandsLoading:eF,queuedMessages:e2,notices:eO.visible,noticeHistory:e_,extensionDialog:eK,extensionCustomUi:eG,extensionStatuses:eZ,extensionWidgets:e0,respondToExtensionUi:ne,sendExtensionCustomInput:nt,isAutoModelSelection:m&&null===en,agentPhase:eN,isNew:m,commandBusy:eI,sessionIdRef:e9,messagesEndRef:tf,scrollContainerRef:tm,lastUserMsgRef:tc,pendingScrollToUserRef:tu,initialScrollDoneRef:td,isNearBottomRef:tp,handleSend:nh,handleAbort:ng,handleFork:nx,handleNavigate:nf,handleModelChange:nv,handleCompact:ny,handleSteer:nS,handleFollowUp:nT,handlePromptWithStreamingBehavior:nC,handleAbortCompaction:nM,handleRecallQueue:nI,handleBuiltinSlashCommand:nw,handleToolPresetChange:nR,handleThinkingLevelChange:nL,loadTools:tO,loadSlashCommands:t2,setActiveLeafId:C,setData:b,setMessages:L,loadContext:tN,removeNotice:nr,clearNotices:ni,setNoticeHistoryFrozen:e=>{nW.current=e},scrollToBottom:tM,scrollUserMsgToTop:nE,hasOlderChat:T,dispatch:D,setAgentRunning:A,setForkingEntryId:em,bashRunning:F,pendingBash:O,handleAgentEventRef:tl}}({session:e,sessionRunning:t,newSessionCwd:s,newSessionId:l,newSessionDraftKey:d,pendingNewSessionTaskRef:u,onAgentEnd:er,onAttentionNeeded:h,onSessionCreated:g,onSessionForked:x,modelsRefreshKey:m,chatInputRef:v,onBranchDataChange:b,onSystemPromptChange:y,onSystemPromptLoaderChange:k,onSessionStatsPanelOpen:R}),[tb,ty]=(0,a.useState)(null),[tk,tw]=(0,a.useState)(!1),[tj,tS]=(0,a.useState)(!1),[tC,tM]=(0,a.useState)(null),tL=(0,a.useRef)(null),tN=(0,a.useRef)(null),tO=(0,a.useCallback)(()=>{ty(null),tw(!1),tM(null)},[]);(0,a.useEffect)(()=>{q||tO()},[q,tO]);let t_=(0,a.useCallback)(()=>{if(!q||tk)return;let e=window.getSelection(),t=e?.rangeCount?e.getRangeAt(0):null,n=n0.current;if(!e||e.isCollapsed||!t||!n||!n.contains(t.commonAncestorContainer))return void ty(null);let r=e.toString().trim();if(!r)return void ty(null);let i=t.getBoundingClientRect(),o=[t.commonAncestorContainer.nodeType===Node.ELEMENT_NODE?t.commonAncestorContainer:t.commonAncestorContainer.parentElement,t.startContainer.nodeType===Node.ELEMENT_NODE?t.startContainer:t.startContainer.parentElement,t.endContainer.nodeType===Node.ELEMENT_NODE?t.endContainer:t.endContainer.parentElement].map(e=>e?.closest('[data-message-role="assistant"]')?.dataset.entryId).find(e=>!!e);ty({text:r,top:Math.min(window.innerHeight-44,i.bottom+8),left:Math.max(64,Math.min(window.innerWidth-64,i.left+i.width/2)),sourceEntryId:o})},[q,tk]),tX=(0,a.useCallback)(()=>{tb&&(v?.current?.insertText(I(tb.text,G("chat.quoteIntro"),G("chat.quoteQuestion"))),window.getSelection()?.removeAllRanges(),tO())},[v,tb,tO,G]),t2=(0,a.useCallback)(async()=>{let t=e4.current??e?.id;if(tj||!tb?.sourceEntryId||!t||!_)return;let n=tN.current?.value?.trim()||I(tb.text,G("chat.quoteIntro"),G("chat.quoteQuestion"));tS(!0),tM(null),F?.();try{await _(n,t,tb.sourceEntryId),tO()}catch(e){tM(e instanceof Error?e.message:String(e))}finally{tS(!1)}},[_,tb,tj,e?.id,e4,tO,F,G]),no=(0,a.useCallback)(()=>{tb&&(tw(!0),requestAnimationFrame(()=>{let e=tN.current;e&&(e.value=I(tb.text,G("chat.quoteIntro"),G("chat.quoteQuestion")),e.focus(),e.setSelectionRange(e.value.length,e.value.length))}))},[tb,G]);(0,a.useEffect)(()=>{if(!tb)return;let e=e=>{tk||tL.current?.contains(e.target)||tO()},t=e=>{"Escape"===e.key&&!e.isComposing&&(e.preventDefault(),e.stopPropagation(),tj||tO())};return document.addEventListener("pointerdown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("pointerdown",e),document.removeEventListener("keydown",t)}},[tb,tk,tj,tO]);let na=(0,a.useRef)(!1);(0,a.useEffect)(()=>{if(!eo&&!ea){if(!V){na.current=!1;return}na.current||(na.current=!0,J?.(),e9(V))}},[V,eo,ea,e9,J]);let[ns,nl]=(0,a.useState)(null);(0,a.useEffect)(()=>{if(!e2||!c)return void nl(null);let e=!1;return fetch(`/api/tasks/${encodeURIComponent(c)}`,{cache:"no-store"}).then(e=>e.ok?e.json():null).then(t=>{!e&&t?.task?.name&&nl(t.task.name)}).catch(()=>{}),()=>{e=!0}},[e2,c]);let nd=eW?Math.max(0,eW.tokensBefore-eW.estimatedTokensAfter):0,nc=eW?`${eW.reason&&"manual"!==eW.reason?`${eW.reason[0].toUpperCase()}${eW.reason.slice(1)} `:G("chat.compacted")} ${e7(eW.tokensBefore)} -> ${e7(eW.estimatedTokensAfter)} tokens (${G("chat.tokensSaved",{saved:e7(nd)})})`:null,nu=(0,a.useMemo)(()=>{if(eI&&"compact"!==eI.name)return{text:G("chat.commandBusy",{name:`/${eI.name}`}),orb:"working"};if(!e1)return null;let e=function(e,t){if(e?.kind==="running_tools"){let n=e.tools[e.tools.length-1];if(n?.progress)return`${t("chat.runningNamedTool",{name:n.name})} ${n.progress}`;let r=e.tools.map(e=>e.name);return 0===r.length?t("chat.runningTool"):1===r.length?t("chat.runningNamedTool",{name:r[0]}):r.length<=3?t("chat.runningTools",{names:r.join(", ")}):t("chat.runningToolsMore",{names:r.slice(0,2).join(", "),count:r.length-2})}return e?.kind==="waiting_model"?t("chat.waitingModel"):e?.kind==="running_command"?t("chat.runningCommand"):null}(e1,G);return e?{text:e,orb:e1?.kind==="waiting_model"?"breathing":"working"}:null},[e1,eI,G]),np=(0,a.useMemo)(()=>ej?`${G("chat.retrying",{attempt:ej.attempt,max:ej.maxAttempts})}${ej.errorMessage?` — ${ej.errorMessage}`:""}`:null,[ej,G]),nh=(0,a.useMemo)(()=>{let e=eH??[];return nc?[...e,{id:"compact-result",message:nc,type:"info"}]:e},[eH,nc]),ng=function(e){let t=!!(e&&tE.has(e)),[n,r]=(0,a.useState)(null),[i,o]=(0,a.useState)(null),s=(0,a.useRef)(e);return s.current=e,(0,a.useEffect)(()=>{if(!t||!e){r(null),o(null);return}let n=!0,i=async()=>{try{let t=await fetch(`/api/quota?provider=${encodeURIComponent(e)}`),i=await t.json();if(!n||s.current!==e)return;if(i.ok&&i.quota)r(function(e,t=Date.now()){var n;if("usage"===e.kind){let n=e.windows.map(e=>{let n,r=(n=Date.parse(e.resetsAt),Number.isFinite(n)?new Date(n).toLocaleString():"—"),i=tz(e.resetsAt,t);return{label:e.label,pct:Math.max(0,Math.min(1,e.percent/100)),text:`${e.percent}%`,detail:[`${e.label}窗 ${e.percent}%`,i&&`剩 ${i}`,`重置 ${r}`].filter(Boolean).join(",")}});return 0===n.length?null:{kind:"usage",items:n}}let r=e.isPeak?"峰":"谷(半价)",i=tz(e.nextSwitchAt,t),o=(()=>{let t=Date.parse(e.nextSwitchAt);if(!Number.isFinite(t))return"";let n=new Date(t);return`${String(n.getHours()).padStart(2,"0")}:${String(n.getMinutes()).padStart(2,"0")}`})(),a=[o&&`${o}${e.isPeak?"转谷":"转峰"}`,i&&`(${i})`].filter(Boolean).join(" ");return{kind:"balance",text:[`${"CNY"===(n=e.currency)?"\xa5":"USD"===n?"$":n?`${n} `:""}${e.totalBalance}`,r,a].filter(Boolean).join(" \xb7 ")}}(i.quota)),o(null);else{let e=401===i.status||403===i.status?"auth":"no credential for provider"===i.error?"no-credential":"transient";("auth"===e||"no-credential"===e)&&r(null),o(e)}}catch{if(!n||s.current!==e)return;o("transient")}},a=null,l=async()=>{await i(),n&&(a=setTimeout(l,6e4))};return l(),()=>{n=!1,a&&clearTimeout(a)}},[e,t]),{quota:n,error:i}}(eP?.provider??null),{phase:nx,notice:nf,dismissError:nm}=function(e){let t,{notices:n,phase:r,retryText:i,quota:o=null}=e,[s,l]=(0,a.useState)([]),d=tR(n),c=(0,a.useRef)(null);(0,a.useEffect)(()=>{d&&d!==c.current&&(c.current=d,l(e=>e.includes(d)?e:[...e.slice(-9),d])),d||(c.current=null)},[d]);let u=(0,a.useCallback)(()=>{l(e=>{let t=tR(n);return t&&!e.includes(t)?[...e,t]:e})},[n]),p=d&&!s.includes(d)?d:null,h=p?n.find(e=>e.id===p):null;if(h)t={level:"error",text:h.message};else{let e=function(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if("error"!==n.type&&!n.exiting)return n}return null}(n);t=e?{level:"notice",text:e.message,kind:e.type}:{level:"idle",quota:o}}return{phase:i?{text:i,orb:"working"}:r,notice:t,dismissError:u}}({notices:nh,phase:nu,retryText:np,quota:ng.quota}),nv=e?.id??e4.current??null,nb=(0,a.useMemo)(()=>nv?eO.filter(e=>!e.sessionId||e.sessionId===nv):eO,[eO,nv]),ny=eu||ep;(0,a.useEffect)(()=>{eU&&en.current!==eU.id&&(en.current=eU.id,Q.current())},[eU]),(0,a.useEffect)(()=>{U||(0,o.G)(ny?te:null)},[ny,te,U]);let[nk,nw]=(0,a.useState)(50),nj=(0,a.useRef)(null),nS=(0,a.useRef)(null),nC=(0,a.useRef)(!1),[nT,nM]=(0,a.useState)(!0),nI=(0,a.useRef)(null),nL=(0,a.useCallback)(e=>{nI.current&&clearTimeout(nI.current),nI.current=setTimeout(()=>{nM(e),nI.current=null},150)},[]),nR=(0,a.useCallback)((e,t,n)=>{(0,ey.y_)(e,t,n)},[]);(0,a.useEffect)(()=>{let t=nj.current,n=e5.current;if(!t||!n)return;let r=new IntersectionObserver(t=>{if(!t[0]?.isIntersecting||nC.current)return;let r=el[0];if(!r)return;let i=e?.id??e4.current;i&&(nC.current=!0,nS.current=n.scrollHeight-n.scrollTop,tx(i,tf,r).finally(()=>{nC.current=!1,requestAnimationFrame(()=>{if(null==nS.current)return;let e=e5.current;e&&(e.scrollTop=tK(e.scrollHeight,nS.current),nS.current=null)})}))},{root:n,threshold:0});return r.observe(t),()=>r.disconnect()},[el,e,tf,tx,e4,e5]),(0,a.useEffect)(()=>{nw(e=>Math.max(e,es.length))},[es.length]),(0,a.useLayoutEffect)(()=>{if(null==nS.current)return;let e=e5.current;e&&(e.scrollTop=tK(e.scrollHeight,nS.current),nS.current=null)},[es.length,el,e5]);let nE=eN?[eN.sessionId,eN.sessionFile??"",eN.sessionName??"",eN.userMessages,eN.assistantMessages,eN.toolCalls,eN.toolResults,eN.totalMessages,eN.tokens.input,eN.tokens.output,eN.tokens.cacheRead,eN.tokens.cacheWrite,eN.tokens.total,eN.cost??0,eN.totalActiveMs??0].join("|"):null,nz=(0,a.useRef)(eN);nz.current=eN,(0,a.useEffect)(()=>{L?.(nz.current)},[nE,L]),(0,a.useEffect)(()=>()=>{L?.(null)},[L]);let nW=(0,a.useRef)(eD);nW.current=eD;let nP=eD.map(e=>`${e.id??e.content}:${e.status??""}`).join("\0");(0,a.useEffect)(()=>{E?.(nW.current)},[nP,E]),(0,a.useEffect)(()=>()=>{E?.([])},[E]);let n$=eS?`${eS.percent??"null"}|${eS.contextWindow}|${eS.tokens??"null"}`:null,nN=(0,a.useRef)(eS);nN.current=eS,(0,a.useEffect)(()=>{z?.(nN.current)},[n$,z]),(0,a.useEffect)(()=>()=>{z?.(null)},[z]);let{isDragOver:nD,handleDragEnter:nB,handleDragOver:nA,handleDragLeave:nF,handleDrop:nH}=function(e){let[t,n]=(0,a.useState)(!1),r=(0,a.useRef)(0),i=(0,a.useCallback)(e=>{Array.from(e.dataTransfer.items).some(e=>e.type.startsWith("image/"))&&(e.preventDefault(),r.current+=1,n(!0))},[]),o=(0,a.useCallback)(e=>{Array.from(e.dataTransfer.items).some(e=>e.type.startsWith("image/"))&&e.preventDefault()},[]);return{isDragOver:t,handleDragEnter:i,handleDragOver:o,handleDragLeave:(0,a.useCallback)(()=>{r.current-=1,r.current<=0&&(r.current=0,n(!1))},[]),handleDrop:(0,a.useCallback)(t=>{t.preventDefault(),r.current=0,n(!1),e(Array.from(t.dataTransfer.files))},[e])}}((0,a.useCallback)(e=>{v?.current?.addImages(e)},[v])),nO=es.filter(e=>"user"===e.role||"assistant"===e.role),nU=(0,a.useMemo)(()=>{let e=new Map;for(let t of es)"toolResult"===t.role&&e.set(t.toolCallId,t);return e},[es]),n_=(0,a.useMemo)(()=>{let e=new Set,t=[];for(let n=es.length-1;n>=0;n-=1){let r=function(e){if("user"!==e.role)return null;if("string"==typeof e.content){let t=e.content.trim();return t.length>0?t:null}let t=e.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n").trim();return t.length>0?t:null}(es[n]);if(!(!r||e.has(r))&&(e.add(r),t.push(r),t.length>=50))break}return t.reverse()},[es]),nq=(K=nO.length,(Y=(0,a.useRef)([])).current=Array(K).fill(null).map((e,t)=>Y.current[t]??null),Y),[nV,nJ]=(0,a.useState)([]);(0,a.useEffect)(()=>{let t=e?.id??e4.current;if(!t||X)return;let n=!1,r=new URLSearchParams;return tf&&r.set("leafId",tf),fetch(`/api/sessions/${encodeURIComponent(t)}/minimap?${r}`).then(e=>e.ok?e.json():null).then(e=>{!n&&e&&nJ(e.turns)}).catch(()=>{}),()=>{n=!0}},[e?.id,e4,tf,X]);let nK=(0,a.useRef)(el);nK.current=el;let nY=(0,a.useRef)(tv);nY.current=tv;let nG=(0,a.useCallback)(async t=>{let n=e?.id??e4.current;if(n&&t){for(let e=0;e<20&&nC.current;e++)await new Promise(e=>setTimeout(e,100));if(!nC.current){nC.current=!0;try{let e=[...nK.current],r=nY.current,i=0;for(;!e.includes(t)&&r&&i<30;){i+=1;let t=e[0];if(!t)break;let o=await tx(n,tf,t,1e3);if(!o||0===o.entryIds.length)break;e=[...o.entryIds,...e],r=o.hasMore}nw(t=>Math.max(t,e.length))}finally{nC.current=!1}}}},[e?.id,tf,tx,e4]),nX=e2&&0===es.length&&!ec.isStreaming&&!ny,nZ=!!ec.streamingMessage?.content.length,nQ=e?.cwd??s??void 0,n0=(0,a.useRef)(null);(0,a.useLayoutEffect)(()=>{if(!eu||!e3.current)return;let e=e5.current;e&&(e.scrollTop=e.scrollHeight)},[ec.streamingMessage,eu,e3,e5]);let n1=eP?ev[`${eP.provider}:${eP.modelId}`]??null:null,n2=eP?eb[`${eP.provider}:${eP.modelId}`]??null:null,n4=(0,r.jsxs)("button",{type:"button",id:"terminal-bottombar-btn",onClick:O,title:G("terminal.title"),"aria-label":G("terminal.title"),"aria-expanded":H,className:`terminal-bar-toggle${H?" is-open":""}`,children:[(0,r.jsxs)("svg",{width:"12",height:"12",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"})]}),(0,r.jsx)("span",{children:G("terminal.title")})]}),n8=(0,r.jsx)(tm,{ref:v,onSend:e9,onAbort:te,onSteer:eu?to:void 0,onFollowUp:eu?ta:void 0,onPromptWithStreamingBehavior:eu?ts:void 0,isStreaming:ny,model:eP,isAutoModelSelection:e0,modelNames:eg,modelList:ex,modelError:ef,modelScopeWarnings:em,onModelChange:tr,modelSwitching:e$,modelsLoading:0===ex.length&&(!eg||0===Object.keys(eg).length)&&!ef,onCompact:e||e2?ti:void 0,onAbortCompaction:tl,isCompacting:eR,commandBusy:!!eI,compactError:eE,compactResult:eW,toolPreset:ek,onToolPresetChange:e||e2?tu:void 0,thinkingLevel:ew,onThinkingLevelChange:e||e2?tp:void 0,availableThinkingLevels:n1,thinkingLevelMap:n2,retryInfo:ej,queuedMessages:eF,inputHistory:n_,onRecallQueue:td,slashCommands:eB,slashCommandsLoading:eA,onLoadSlashCommands:th,onBuiltinCommand:tc,soundEnabled:$,onSoundToggle:N,onAudioUnlock:F,draftKey:e?.id??d??void 0,cwd:e?.cwd??s,taskName:ns,atBottom:nT,onScrollToBottom:tg,phase:X?null:nx});return eo?(0,r.jsx)("div",{className:"flex h-full items-center justify-center text-text-muted",children:G("chat.loadingSession")}):ea?(0,r.jsx)("div",{className:"flex h-full items-center justify-center text-red-400",children:ea}):(0,r.jsxs)("div",{className:`chat-content relative flex h-full min-w-0 flex-col ${U?"overflow-visible":"overflow-hidden"}`,style:{paddingBottom:"env(safe-area-inset-bottom)"},onDragEnter:nB,onDragOver:nA,onDragLeave:nF,onDrop:nH,children:[nD&&(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"})]})]})]}),eU&&(0,r.jsx)(nr,{request:eU,onRespond:eJ}),e_&&(0,r.jsx)(ni,{request:e_,onInput:eK}),X&&(0,r.jsx)("div",{style:{position:"fixed",left:"50%",top:60,transform:"translateX(-50%)",zIndex:250,display:"flex",flexDirection:"column",alignItems:"center",maxWidth:"calc(100vw - 32px)",overflowY:"auto",pointerEvents:"none"},children:(0,r.jsx)(nn,{notices:eH,floating:!0})}),nX?(0,r.jsx)("div",{className:`flex flex-1 flex-col items-center justify-center px-4 py-8 ${U?"overflow-visible":"overflow-y-auto"}`,children:(0,r.jsxs)("div",{className:"w-full",style:{maxWidth:"var(--chat-content-max-width, 820px)"},children:[(0,r.jsxs)("div",{className:"mb-3",style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,marginLeft:16,marginRight:X?16:52,fontFamily:"var(--font-mono)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:X?7:10,minWidth:0,flex:1,lineHeight:1.4,overflow:"hidden"},children:[(0,r.jsx)("span",{style:{fontSize:34,fontWeight:700,letterSpacing:0,color:"#ffffff",mixBlendMode:"exclusion",flexShrink:0,whiteSpace:"nowrap"},children:"π"}),(0,r.jsx)("span",{style:{fontSize:28,color:"#ffffff",fontWeight:700,letterSpacing:0,mixBlendMode:"exclusion",flexShrink:0,whiteSpace:"nowrap"},children:"Pi Web"}),(0,r.jsx)(t3,{label:e=>G("appUpdate.releaseNotes",{version:e})})]}),nQ&&f?(0,r.jsx)(tP.J,{cwd:nQ,onSelect:f,style:{background:"color-mix(in srgb, var(--frame-glass) 80%, transparent)",border:"1px solid color-mix(in srgb, var(--border) 70%, transparent)",borderRadius:8,height:30,flexShrink:0}}):null]}),n8]})}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"relative flex min-w-0 flex-1 overflow-hidden",children:[(0,r.jsx)("div",{ref:e5,className:"min-w-0 flex-1 overflow-x-hidden overflow-y-auto pt-4 pb-[4px] mb-[4px] [scrollbar-width:none]",onScroll:e=>{let t=e.currentTarget;nL(tY(t.scrollTop,t.clientHeight,t.scrollHeight))},children:(0,r.jsx)("div",{style:{minWidth:0,padding:X?"0 16px":"0 26px 0 16px"},children:(0,r.jsxs)("div",{ref:n0,onPointerUp:t_,style:{width:"100%",minWidth:0,maxWidth:"var(--chat-content-max-width, 820px)",margin:"0 auto"},children:[(()=>{var t;let n,i,o=-1;for(let e=es.length-1;e>=0;e--)if("user"===es[e].role){o=e;break}let a=-1;for(let e=es.length-1;e>=0;e--)if(t7(es[e])){a=e;break}let s=new Map,l=0;es.forEach((e,t)=>{("user"===e.role||"assistant"===e.role)&&s.set(t,l++)});let d=(t,n={})=>{let i=n.messageOverride??es[t],a="user"===i.role?ed[t]??null:void 0,l=null!=tf&&tf===el[t],d="user"===i.role||"assistant"===i.role,c=s.get(t),u=n.keyPrefix??"message",p=el[t]??`${u}-${t}`,h=!1;if("assistant"===i.role){h=!0;for(let e=t+1;e<es.length;e++){let t=es[e].role;if("user"===t)break;if("assistant"===t){h=!1;break}}h&&ec.isStreaming&&t===es.length-1&&(h=!1)}void 0!==n.showTimestamp&&(h=n.showTimestamp);let g=(0,r.jsx)(ee,{message:i,toolResults:nU,modelNames:eg,cwd:nQ,onOpenFile:W,entryId:el[t],onFork:ny||e2?void 0:tt,forking:eM===el[t],onNavigate:ny?void 0:tn,parentEntryId:ny?void 0:a,isLeafEntry:l,onEditContent:ei,onPin:nR,showTimestamp:h,prevTimestamp:t>0?es[t-1].timestamp:void 0,sessionId:e?.id??e4.current??void 0,writtenFiles:n.writtenFiles},`${u}-view-${p}`);return d&&!1!==n.attachRef&&void 0!==c?(0,r.jsx)("div",{ref:e=>{nq.current[c]=e,t===o&&(e6.current=e)},children:g},p):g},c=[];for(let e=0;e<es.length;){if(!t7(es[e])){c.push(d(e)),e+=1;continue}let t=e,n=t+1;for(;n<es.length&&!t7(es[n]);)n+=1;let i=function(e,t,n){for(let i=n-1;i>t;i--){var r;if("assistant"===(r=e[i]).role&&S(r).answerBlocks.some(e=>"image"===e.type||"text"===e.type&&e.text.trim().length>0))return i}for(let r=n-1;r>t;r--)if(e[r]?.role==="assistant")return r;return -1}(es,t,n);if(-1===i||(ny||ec.isStreaming)&&n===es.length&&t===a){for(let e=t;e<n;e++)c.push(d(e));e=n;continue}c.push(d(t));let o=[];for(let e=t+1;e<i;e++)o.push(e);let l=o.filter(e=>{var t;return"assistant"===(t=es[e]).role?w(t).length>0:"custom"===t.role}),u=es[i],p=S(u),h=p.processBlocks.length>0?t9(u,p.processBlocks,{omitUsage:!0}):null,g=p.answerBlocks.length>0||j(u)?t9(u,p.answerBlocks):null,x=l.length+ +!!h;if(x>0){let e=l.map(e=>s.get(e)).find(e=>"number"==typeof e)??(g?void 0:s.get(i)),n=(0,r.jsxs)(ne,{messageCount:x,defaultExpanded:!g,t:G,toolCallCount:function(e,t){let n=0;for(let r of t){let t=e[r];t?.role==="assistant"&&(n+=C(w(t)))}return n}(es,l)+C(p.processBlocks),children:[l.map(e=>d(e,{attachRef:!1,keyPrefix:"process"})),h&&d(i,{attachRef:!1,keyPrefix:"process-final",messageOverride:h,showTimestamp:!1})]});c.push((0,r.jsx)("div",{ref:void 0===e?void 0:t=>{nq.current[e]=t},children:n},`process-group-${el[t]??t}-${el[i]??i}`))}if(g){let e=[];for(let n=t+1;n<=i;n++){let t=es[n];if(t?.role==="assistant")for(let n of t.content??[])e.push(n)}let n=function(e,t,n){let r=new Set,i=[];for(let o of e){if("toolCall"!==o.type||!function(e){let t;return"write"===(t=e.toLowerCase())||t.startsWith("write_")||t.endsWith(".write")||t.endsWith("_write")||M(e)}(o.toolName))continue;let e=t?.get(o.toolCallId);if(!e||e.isError)continue;let a=function(e){if(!e)return null;let t=e.file_path??e.path;return"string"==typeof t&&t.length>0?t:null}(o.input);if(!a)continue;let s=(0,T.X)(a,n);s&&(r.has(s)||(r.add(s),i.push({filePath:s})))}return i}(e,nU,nQ);c.push(d(i,{messageOverride:g,writtenFiles:n}))}for(let e=i+1;e<n;e++)c.push(d(e));e=n}let{startIndex:u}=(n=Math.min(Math.max(nk,0),Math.max(t=c.length,0)),{startIndex:i=Math.max(0,t-n),hasMore:i>0}),p=u>0||tv;return(0,r.jsxs)(r.Fragment,{children:[p&&(0,r.jsx)("div",{ref:nj,className:"py-3 text-center text-xs text-text-muted",children:G("chat.loadEarlier")}),c.slice(u)]})})(),ec.isStreaming&&nZ&&ec.streamingMessage&&(0,r.jsx)(ee,{message:ec.streamingMessage,isStreaming:!0,modelNames:eg,cwd:nQ,onOpenFile:W}),eh&&(0,r.jsx)(ee,{message:{role:"bashExecution",command:eh.command,output:"",excludeFromContext:eh.excludeFromContext},sessionId:e?.id??e4.current??void 0}),(0,r.jsx)("div",{ref:e8})]})})}),eR&&(0,r.jsxs)("div",{className:"compaction-status",role:"status",style:{position:"absolute",top:14,left:"50%",transform:"translateX(-50%)",zIndex:60,width:220,maxWidth:"calc(100vw - 48px)",display:"flex",alignItems:"center",gap:8,padding:"6px 14px",borderRadius:999,border:"1px solid color-mix(in srgb, var(--accent) 34%, transparent)",background:"color-mix(in srgb, var(--glass-bg-strong) 72%, transparent)",backdropFilter:"blur(var(--glass-blur-popover)) saturate(var(--glass-saturate))",WebkitBackdropFilter:"blur(var(--glass-blur-popover)) saturate(var(--glass-saturate))",color:"var(--text)",fontSize:12,lineHeight:1.4,boxShadow:"0 2px 12px -4px rgba(15,23,42,0.16)",animation:"compaction-breathe 1.8s ease-in-out infinite"},children:[(0,r.jsx)("span",{className:"compaction-status-dot",style:{flexShrink:0,width:7,height:7,borderRadius:"50%",background:"var(--accent)",animation:"compaction-dot-breathe 1.4s ease-in-out infinite"}}),(0,r.jsx)("span",{style:{flex:1,minWidth:0,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:G("chat.compacting")}),(0,r.jsx)("button",{type:"button",onClick:tl,style:{flexShrink:0,background:"transparent",border:"none",borderRadius:6,padding:"1px 6px",color:"var(--accent)",fontSize:11,cursor:"pointer",transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:G("chat.stopCompaction")})]}),X?null:(0,r.jsx)(tT,{messages:es,entryIds:el,turnIndex:nV,streamingMessage:ec.streamingMessage,scrollContainer:e5,messageRefs:nq,onRevealHistory:nG})]}),q&&tb&&(0,i.createPortal)((0,r.jsx)("div",{ref:tL,role:tk?"dialog":"toolbar","aria-label":G(tk?"chat.newQuoteChat":"chat.askSelection"),style:{position:"fixed",top:tb.top,left:tb.left,transform:tk?"none":"translateX(-50%)",zIndex:130,display:"flex",flexDirection:"column",alignItems:"stretch",gap:2,width:tk?"min(420px, calc(100vw - 16px))":void 0,maxWidth:"calc(100vw - 16px)",maxHeight:"calc(var(--app-viewport-height, 100dvh) - 16px)",overflowY:"auto",padding:tk?12:3,border:"1px solid var(--border)",borderRadius:6,background:tk?"var(--bg)":"var(--bg-panel)",boxShadow:"0 8px 24px rgba(0,0,0,0.16)"},children:tk?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%",marginBottom:8},children:[(0,r.jsx)("span",{style:{fontSize:12,fontWeight:650,color:"var(--text)"},children:G("chat.newQuoteChat")}),(0,r.jsx)("button",{type:"button",onClick:tO,disabled:tj,style:{padding:"3px 8px",border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"✕"})]}),(0,r.jsx)("textarea",{ref:tN,"aria-label":G("chat.quoteQuestion"),style:{width:"100%",minHeight:96,resize:"vertical",border:"1px solid var(--border)",borderRadius:8,padding:"8px 10px",fontSize:13,lineHeight:1.5,fontFamily:"inherit",background:"var(--bg-panel)",color:"var(--text)",boxSizing:"border-box"}}),tC&&(0,r.jsx)("div",{style:{color:"var(--danger, #dc2626)",fontSize:12,marginTop:6},children:tC}),(0,r.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:6,marginTop:8},children:[(0,r.jsx)("button",{type:"button",onClick:tO,disabled:tj,style:{padding:"6px 12px",border:"1px solid var(--border)",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:G("chat.cancel")}),(0,r.jsx)("button",{type:"button",onClick:()=>void t2(),disabled:tj,style:{padding:"6px 12px",border:"none",borderRadius:6,background:"var(--accent)",color:"#fff",cursor:"pointer",fontSize:12,fontWeight:650},children:tj?"…":G("chat.sendQuestion")})]})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{type:"button",role:"menuitem",onPointerDown:e=>e.preventDefault(),onClick:()=>{nR(tb.text,tb.left,tb.top),tO()},style:t6,children:G("i18n.pin")}),(0,r.jsx)("button",{type:"button",role:"menuitem",onPointerDown:e=>e.preventDefault(),onClick:tX,style:t6,children:G("chat.askInCurrent")}),_&&tb.sourceEntryId&&(0,r.jsx)("button",{type:"button",role:"menuitem",onPointerDown:e=>e.preventDefault(),onClick:no,style:t6,children:G("chat.askInNewChat")})]})}),document.body),(0,r.jsxs)("div",{className:"relative",children:[n8,(0,r.jsx)("div",{className:"bottom-band",children:(0,r.jsx)(tI,{statuses:eq,widgets:eV,sessionId:e?.id??e4.current??void 0,tools:X?void 0:n4,notice:X?null:(0,r.jsxs)("div",{style:{flex:"0 1 auto",minWidth:0,overflow:"hidden",display:"flex",alignItems:"center",gap:8,padding:"0 10px"},children:[(0,r.jsx)(tW,{broadcast:nf,history:nb,onDismissError:nm,onRemoveNotice:eX,onClearNotices:eZ,onFreezeChange:eQ,isDark:Z}),ng.quota&&(0,r.jsx)(eG,{quota:ng.quota}),"auth"===ng.error&&(0,r.jsxs)("span",{title:"额度凭据已被上游拒绝(401/403),请重新登录该提供商",style:{display:"inline-flex",alignItems:"center",gap:5,color:eY.error,fontSize:12,fontFamily:"var(--font-mono)",whiteSpace:"nowrap"},children:[(0,r.jsx)("span",{"aria-hidden":!0,style:{width:5,height:5,borderRadius:"50%",background:eY.error,flexShrink:0}}),"⚠ 额度凭据失效,请重新登录"]}),"no-credential"===ng.error&&(0,r.jsxs)("span",{title:"该提供商未配置凭据",style:{display:"inline-flex",alignItems:"center",gap:5,color:eY.warning,fontSize:12,fontFamily:"var(--font-mono)",whiteSpace:"nowrap"},children:[(0,r.jsx)("span",{"aria-hidden":!0,style:{width:5,height:5,borderRadius:"50%",background:eY.warning,flexShrink:0}}),"未登录,额度不可用"]}),"transient"===ng.error&&null==ng.quota&&(0,r.jsxs)("span",{title:"额度查询失败,稍后自动重试",style:{display:"inline-flex",alignItems:"center",gap:5,color:"var(--text-dim)",fontSize:12,fontFamily:"var(--font-mono)",whiteSpace:"nowrap"},children:[(0,r.jsx)("span",{"aria-hidden":!0,style:{width:5,height:5,borderRadius:"50%",background:"var(--text-dim)",flexShrink:0}}),"额度查询失败"]})]})})})]})]})]})}function nn({notices:e,floating:t}){return 0===e.length?null:(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",alignItems:t?"center":"flex-end",gap:6,padding:t?"0 16px":0},children:e.map(e=>{let n="error"===e.type?"#ef4444":"warning"===e.type?"#d97706":"success"===e.type?"#10b981":"var(--accent)";return(0,r.jsxs)("div",{className:"notice-shelf-item",style:{display:"flex",alignItems:"center",gap:8,overflow:"hidden",borderRadius:8,border:"1px solid color-mix(in srgb, var(--border) 45%, transparent)",background:"color-mix(in srgb, var(--glass-bg-strong) 60%, transparent)",backdropFilter:"blur(var(--glass-blur-popover)) saturate(var(--glass-saturate))",WebkitBackdropFilter:"blur(var(--glass-blur-popover)) saturate(var(--glass-saturate))",color:"var(--text)",width:300,boxShadow:"0 2px 12px -4px rgba(15,23,42,0.16)",fontSize:12.5,lineHeight:1.55,transformOrigin:t?"top center":"bottom right",animation:e.exiting?"notice-shelf-out 0.18s ease-in forwards":"notice-shelf-in 0.18s ease-out both",padding:"8px 12px",pointerEvents:"auto"},children:[(0,r.jsx)("span",{style:{flexShrink:0,width:5,height:5,borderRadius:"50%",background:n}}),(0,r.jsx)("span",{className:"notice-shelf-text",style:{minWidth:0,flex:1,wordBreak:"break-word",display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical",overflow:"hidden"},children:e.message})]},e.id)})})}function nr({request:e,onRespond:t}){let{t:n}=(0,P.s)(),i=(0,tL.u)(),[o,s]=(0,a.useState)("editor"===e.method?e.prefill??"":"");(0,a.useEffect)(()=>{s("editor"===e.method?e.prefill??"":"")},[e]);let l=()=>{"confirm"===e.method?t(e,{confirmed:!0}):t(e,{value:o})};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%)",maxHeight:"100%",display:"flex",flexDirection:"column",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:{flexShrink:0,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:n("chat.extensionRequest")})]}),(0,r.jsxs)("div",{style:{padding:14,flex:1,minHeight:0,overflowY:"auto"},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(n=>(0,r.jsx)("button",{onClick:()=>t(e,{value:n}),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:n},n))}),"input"===e.method&&(0,r.jsx)("input",{autoFocus:!0,value:o,placeholder:e.placeholder,onChange:e=>s(e.target.value),...i.compositionProps,onKeyDown:n=>{i.isIMEBusy(n)||("Enter"===n.key&&l(),"Escape"===n.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:o,onChange:e=>s(e.target.value),...i.compositionProps,onKeyDown:n=>{!i.isIMEBusy(n)&&("Escape"===n.key&&t(e,{cancelled:!0}),(n.metaKey||n.ctrlKey)&&"Enter"===n.key&&l())},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:{flexShrink:0,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:n("chat.cancel")}),"confirm"===e.method?(0,r.jsx)("button",{onClick:l,style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--accent)",background:"var(--accent)",color:"#fff",cursor:"pointer"},children:n("chat.confirm")}):"select"!==e.method?(0,r.jsx)("button",{onClick:l,style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--accent)",background:"var(--accent)",color:"#fff",cursor:"pointer"},children:n("chat.submit")}):null]})]})})}function ni({request:e,onInput:t}){let{t:n}=(0,P.s)(),i=(0,a.useRef)(null),o=(0,a.useRef)(!1),s=function(e){let t=/^[┌├└╭╰][─┬┴┼]+[┐┤┘╮╯]$/,n=[];for(let r of e){let e=r.replace(c,""),i=h(e).trimEnd();if(t.test(i))continue;let o=e,a=f(o);("│"===a||"┃"===a)&&" "===f(o=x(o,0))&&(o=x(o,0));let s=function(e){let t=g(e);for(let e=t.length-1;e>=0;e--)if(""!==t[e].char.trim())return e;return -1}(o),l=s>=0?g(o)[s]?.char:void 0;("│"===l||"┃"===l)&&(o=x(o,s)),n.push(function(e){let t=e;for(;;){let e=g(t),n=e[e.length-1];if(!n||""!==n.char.trim())return t;t=t.slice(0,n.start)+t.slice(n.end)}}(o))}for(;n.length>0&&""===h(n[0]).trim();)n.shift();for(;n.length>0&&""===h(n[n.length-1]).trim();)n.pop();return n.length?n:e}(e.lines);return(0,a.useEffect)(()=>{i.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",{role:"dialog","aria-modal":"true",onClick:e=>{e.target.closest("button")||i.current?.focus()},style:{position:"relative",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.jsx)("textarea",{ref:i,"aria-label":n("chat.extensionInput"),autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",spellCheck:!1,onKeyDown:n=>{if(o.current||n.nativeEvent.isComposing)return;let r=function(e){if(e.metaKey||e.ctrlKey&&!e.altKey&&"v"===e.key.toLowerCase())return null;if(e.ctrlKey&&!e.altKey){let t=function(e){if(1!==e.length)return null;let t=e.toUpperCase().charCodeAt(0);return t>=64&&t<=95?String.fromCharCode(31&t):"?"===e?"":null}(e.key);if(t)return t}if(e.altKey&&!e.ctrlKey){if("Backspace"===e.key)return"\x1b\x7f";let t=b[e.key];if(t)return t;if(1===e.key.length)return`\x1b${e.key}`}return"Enter"===e.key?e.shiftKey?"\n":"\r":"Tab"===e.key?e.shiftKey?"\x1b[Z":" ":v[e.key]??null}(n);r&&(n.preventDefault(),n.stopPropagation(),t(e,r))},onInput:n=>{if(o.current||n.nativeEvent.isComposing)return;let r=n.currentTarget.value;n.currentTarget.value="",r&&t(e,r)},onCompositionStart:()=>{o.current=!0},onCompositionEnd:n=>{o.current=!1;let r=n.currentTarget;queueMicrotask(()=>{let n=r.value;r.value="",n&&t(e,n)})},onPaste:n=>{n.preventDefault();let r=(0,y.Gm)(n.clipboardData),i=r.length>0?(0,y.ph)(r):n.clipboardData.getData("text");i&&t(e,`\x1b[200~${i}\x1b[201~`)},style:{position:"absolute",width:1,height:1,padding:0,border:0,opacity:0,pointerEvents:"none"}}),(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:n("chat.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:n("chat.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:(s.length?s:[""]).map((e,t,n)=>{var i;return(0,r.jsxs)(a.Fragment,{children:[(i=`line-${t}`,m(e).map((e,t)=>Object.keys(e.style).length>0?(0,r.jsx)("span",{style:e.style,children:e.text},`${i}-${t}`):e.text)),t<n.length-1?"\n":null]},t)})})]})})}},96793:(e,t,n)=>{"use strict";n.d(t,{D:()=>b});var r=n(12115);let i="pi-theme",o=["light","dark"],a={preference:"auto",theme:"light"},s=new Set,l=null,d=!1;function c(){return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function u(e){return"auto"===e?c():e}function p(e){"u">typeof document&&document.documentElement.classList.toggle("dark","dark"===e)}function h(){if(l)return l;let e=function(){try{let e=localStorage.getItem(i);if("light"===e||"dark"===e)return e;if("auto"===e)return c()}catch{}return"light"}(),t=u(e);return p(t),l={preference:e,theme:t}}function g(e,t,n){if(p(t),n)try{localStorage.setItem(i,e)}catch{}l={preference:e,theme:t},s.forEach(e=>e())}function x(){let e=h();if("auto"!==e.preference)return;let t=c();t!==e.theme&&g("auto",t,!1)}function f(e){return s.add(e),h(),d||!window.matchMedia||(window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",x),window.addEventListener("focus",x),document.addEventListener("visibilitychange",()=>{"visible"===document.visibilityState&&x()}),d=!0),x(),()=>{s.delete(e)}}function m(){return h()}function v(){return a}function b(){let e=(0,r.useSyncExternalStore)(f,m,v),t=(0,r.useCallback)(e=>{var t;let n,r=(t=h().preference,n=o.indexOf(t),o[(n+1)%o.length]),i=u(r),a=()=>{g(r,i,!0)},s=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;if("function"!=typeof document.startViewTransition||s)return void a();let l=e?.x??window.innerWidth/2,d=e?.y??window.innerHeight/2,c=Math.hypot(Math.max(l,window.innerWidth-l),Math.max(d,window.innerHeight-d));document.startViewTransition(a).ready.then(()=>{document.documentElement.animate({clipPath:[`circle(0px at ${l}px ${d}px)`,`circle(${c}px at ${l}px ${d}px)`]},{duration:450,easing:"cubic-bezier(0.22, 0.61, 0.36, 1)",pseudoElement:"::view-transition-new(root)"})}).catch(()=>{})},[]),n=(0,r.useCallback)(e=>{let t=u(e);g(e,t,!0)},[]);return{theme:e.theme,preference:e.preference,toggleTheme:t,setPreference:n,isDark:"dark"===e.theme}}},97290:(e,t,n)=>{"use strict";n.d(t,{AppShell:()=>rM});var r=n(95155),i=n(12115),o=n(47650),a=n(73321),s=n(37206),l=n(83588),d=n(42910),c=n(13405),u=n(23657),p=n(1518);let h="pi-web:last-open-by-workspace";function g(){try{return window.localStorage}catch{return null}}function x(e){let t=e.getItem(h);if(!t)return{};try{let e=JSON.parse(t);return null===e||"object"!=typeof e||Array.isArray(e)?{}:e}catch{return{}}}function f(e,t=g()){if(t)try{let n=x(t);if(!(e in n))return;delete n[e],0===Object.keys(n).length?t.removeItem(h):t.setItem(h,JSON.stringify(n))}catch{}}function m(e){return e.projectKey??e.projectRoot??e.cwd}function v(e){let t=new Map;for(let n of e){let e=n.projectRoot??n.cwd;if(!e)continue;let r=m(n),i=t.get(r);(!i||n.modified>i.modified)&&t.set(r,{root:e,modified:n.modified})}return[...t.entries()].sort((e,t)=>t[1].modified.localeCompare(e[1].modified)).map(([e,{root:t}])=>({key:e,root:t}))}function b(e){let t=new Date(e);return t.setHours(0,0,0,0),t.getTime()}function y(e,t){let n=new Date(e);return n.setDate(n.getDate()+t),n.getTime()}function k(e,t=Date.now()){let n,r="number"==typeof e?e:Date.parse(e);return Number.isFinite(r)?r>=b(t)?"today":r>=y(b(t),-1)?"yesterday":r>=(n=new Date(t).getDay(),y(b(t),-((n+6)%7)))?"thisWeek":r>=y(b(t),-29)?"thisMonth":"older":"older"}var w=n(39247),j=n(48660),S=n(20985);function C(e,t,n=4){let r=e.parentElement,i=null;for(;r;){let e=getComputedStyle(r);if("auto"===e.overflowY||"scroll"===e.overflowY||"overlay"===e.overflowY){i=r;break}r=r.parentElement}let o=e.getBoundingClientRect(),a=i?i.getBoundingClientRect():{top:0,bottom:window.innerHeight},s=a.bottom-o.bottom,l=o.top-a.top;return s<t+n&&l>=t+n}var T=n(29608),M=n(30527),I=n(28999);async function L(e){let t=(0,I.HG)(e),n=await fetch(`/api/files/${t}?type=list`);if(!n.ok){let e=`Failed to load files (HTTP ${n.status})`;try{let t=await n.json();t.error&&(e=t.error)}catch{}throw Error(e)}return((await n.json()).entries??[]).map(t=>({name:t.name,fullPath:(0,I.e_)(e,t.name),isDir:t.isDir,size:t.size,children:t.isDir?[]:void 0,loaded:!t.isDir}))}async function R(e,t){let n=new URLSearchParams({type:"search",q:t}),r=await fetch(`/api/files/${(0,I.HG)(e)}?${n.toString()}`);if(!r.ok)throw Error(`Search failed (HTTP ${r.status})`);return r.json()}async function E(e){let t=new URLSearchParams({cwd:e}),n=await fetch(`/api/git/status?${t.toString()}`);if(!n.ok)throw Error(`Failed to load Git status (HTTP ${n.status})`);return n.json()}let z={modified:"files.modified",added:"files.added",deleted:"files.deleted",renamed:"files.renamed",untracked:"files.untracked",conflict:"files.conflict"},W={modified:"#d6a84b",added:"#4ade80",deleted:"#f87171",renamed:"#60a5fa",untracked:"#4ade80",conflict:"#f87171"};function P({status:e,t}){return(0,r.jsx)("span",{title:t(z[e.status]),"aria-label":t(z[e.status]),style:{width:14,height:14,flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",color:W[e.status],fontFamily:"var(--font-mono)",fontSize:11,fontWeight:600},children:e.code})}function $({size:e=11}){return(0,r.jsxs)("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"4"}),(0,r.jsx)("path",{d:"M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8"})]})}function N({onClick:e,title:t}){return(0,r.jsx)("button",{type:"button",onClick:e,title:t,"aria-label":t,style:{width:24,height:24,padding:0,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,border:"none",borderRadius:4,background:"none",color:"var(--text-dim)",cursor:"pointer"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="var(--side-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)",e.currentTarget.style.background="none"},children:(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round","aria-hidden":"true",children:[(0,r.jsx)("path",{d:"m6 6 12 12"}),(0,r.jsx)("path",{d:"m18 6-12 12"})]})})}function D({node:e,depth:t,cwd:n,onOpenFile:o,onAtMention:a,expandedPaths:s,onToggleExpanded:l,refreshToken:d,highlightedPaths:c,gitStatusByPath:u,changedDirectoryPaths:p,t:h}){let g=s.has(e.fullPath),x=c.has(e.fullPath),f=(0,I.A0)(e.fullPath),m=u.get(f),v=e.isDir&&(void 0!==m||p.has(f)),[b,y]=(0,i.useState)(e.children??[]),[k,w]=(0,i.useState)(e.loaded??!1),[j,S]=(0,i.useState)(!1),[C,T]=(0,i.useState)(!1),R=(0,i.useCallback)(async(t=!1)=>{if(!k||t){S(!0);try{let t=await L(e.fullPath);y(t),w(!0)}catch{}finally{S(!1)}}},[k,e.fullPath]);(0,i.useEffect)(()=>{g&&k&&R(!0)},[d]);let E=(0,i.useCallback)(()=>{if(e.isDir){let t=!g;l(e.fullPath,t),t&&!k&&R()}else o(e.fullPath,e.name)},[e.isDir,e.fullPath,e.name,k,g,R,o,l]);return(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{onClick:E,onMouseEnter:()=>T(!0),onMouseLeave:()=>T(!1),style:{position:"relative",display:"flex",alignItems:"center",gap:4,paddingLeft:8+14*t,paddingRight:8,height:24,cursor:"pointer",background:C?"var(--side-hover)":"transparent",borderRadius:4,userSelect:"none"},children:[e.isDir&&(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:g?"rotate(90deg)":"none",transition:"transform 0.1s"},children:(0,r.jsx)("polyline",{points:"3 2 7 5 3 8"})}),!e.isDir&&(0,r.jsx)("span",{style:{width:10,flexShrink:0}}),(0,r.jsx)("span",{style:{flexShrink:0,display:"flex",alignItems:"center"},children:e.isDir?(0,r.jsx)(M.sj,{size:14,open:g}):(0,M.I3)(e.name,14)}),(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},title:e.fullPath,children:e.name}),x&&(0,r.jsx)("span",{title:h("files.newlyUploaded"),"aria-label":h("files.newlyUploaded"),style:{width:14,height:14,flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center"},children:(0,r.jsx)("span",{style:{width:6,height:6,borderRadius:"50%",background:"#3b82f6"}})}),!C&&!e.isDir&&m&&(0,r.jsx)(P,{status:m,t:h}),!C&&v&&(0,r.jsx)("span",{title:h("files.containsChangedFiles"),"aria-label":h("files.containsChangedFiles"),style:{width:14,height:14,flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center"},children:(0,r.jsx)("span",{style:{width:6,height:6,borderRadius:"50%",background:"#d6a84b"}})}),j&&(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",children:(0,r.jsx)("path",{d:"M12 2v4M12 18v4M4.93 4.93l2.83 2.83M16.24 16.24l2.83 2.83M2 12h4M18 12h4"})}),a&&C&&(0,r.jsxs)("button",{onClick:t=>{t.stopPropagation(),a((0,I.qP)(e.fullPath,n),e.isDir)},title:h("files.insertPath"),style:{position:"absolute",right:e.isDir?4:28,top:"50%",transform:"translateY(-50%)",display:"flex",alignItems:"center",justifyContent:"center",gap:4,padding:"0 8px",height:20,background:"var(--side-input)",border:"1px solid color-mix(in srgb, var(--border) 55%, transparent)",borderRadius:4,color:"var(--accent)",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:[(0,r.jsx)($,{}),h("files.mention")]}),C&&!e.isDir&&(0,r.jsx)("a",{href:`/api/files/${(0,I.HG)(e.fullPath)}?type=download`,download:!0,onClick:e=>e.stopPropagation(),title:h("files.download"),style:{position:"absolute",right:4,top:"50%",transform:"translateY(-50%)",display:"flex",alignItems:"center",justifyContent:"center",gap:4,padding:"0 5px",height:20,background:"var(--side-input)",border:"1px solid color-mix(in srgb, var(--border) 55%, transparent)",borderRadius:4,color:"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap",textDecoration:"none"},children:(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,r.jsx)("polyline",{points:"7 10 12 15 17 10"}),(0,r.jsx)("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})})]}),e.isDir&&g&&(0,r.jsxs)("div",{children:[b.map(e=>(0,r.jsx)(D,{node:e,depth:t+1,cwd:n,onOpenFile:o,onAtMention:a,expandedPaths:s,onToggleExpanded:l,refreshToken:d,highlightedPaths:c,gitStatusByPath:u,changedDirectoryPaths:p,t:h},e.fullPath)),0===b.length&&k&&(0,r.jsx)("div",{style:{paddingLeft:8+(t+1)*14,fontSize:11,color:"var(--text-dim)",height:22,display:"flex",alignItems:"center"},children:"empty"})]})]})}function B({status:e,cwd:t,onOpenFile:n,t:o}){let[a,s]=(0,i.useState)(!1),l=(0,I.WP)(e.filePath),d=(0,I.qP)(e.filePath,t);return(0,r.jsxs)("div",{onClick:()=>n(e.filePath,l,{modeHint:"diff"}),onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),title:e.filePath,style:{display:"flex",alignItems:"center",gap:6,paddingLeft:10,paddingRight:8,height:24,cursor:"pointer",background:a?"var(--side-hover)":"transparent",borderRadius:4,userSelect:"none"},children:[(0,r.jsx)(P,{status:e,t:o}),(0,r.jsx)("span",{style:{flexShrink:0,display:"flex",alignItems:"center",opacity:.85},children:(0,M.I3)(l,13)}),(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:d})]})}function A({match:e,cwd:t,onOpenFile:n}){let[o,a]=(0,i.useState)(!1),s=(0,I.WP)(e.path);return(0,r.jsxs)("div",{onClick:()=>n((0,I.e_)(t,e.path),s),onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),title:e.path,style:{display:"flex",alignItems:"center",gap:6,paddingLeft:10,paddingRight:8,height:24,cursor:"pointer",background:o?"var(--side-hover)":"transparent",borderRadius:4,userSelect:"none"},children:[(0,r.jsx)("span",{style:{flexShrink:0,display:"flex",alignItems:"center"},children:e.isDir?(0,r.jsx)(M.sj,{size:13}):(0,M.I3)(s,13)}),(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:e.path})]})}let F=(0,i.forwardRef)(function({cwd:e,onOpenFile:t,refreshKey:n,onAtMention:o,onAtMentions:a,onUploadBusyChange:s,changesCollapsed:l,onChangesCountChange:d,toolbar:c},u){let{t:p}=(0,w.s)(),[h,g]=(0,i.useState)([]),[x,f]=(0,i.useState)(!0),[m,v]=(0,i.useState)(null),[b,y]=(0,i.useState)(new Set),[k,j]=(0,i.useState)(0),[S,C]=(0,i.useState)(new Set),[T,M]=(0,i.useState)([]),[z,P]=(0,i.useState)({additions:0,deletions:0}),[F,H]=(0,i.useState)("idle"),[O,U]=(0,i.useState)(0),[_,q]=(0,i.useState)(null),[V,J]=(0,i.useState)(null),[K,Y]=(0,i.useState)(null),[G,X]=(0,i.useState)(""),[Z,Q]=(0,i.useState)(null),ee=(0,i.useRef)(null),et=(0,i.useRef)(null),en=`${n??0}:${k}`,er="idle"!==F,ei=(0,i.useMemo)(()=>new Map(T.map(e=>[(0,I.A0)(e.filePath),e])),[T]),eo=(0,i.useMemo)(()=>{let t=new Set,n=(0,I.A0)(e).replace(/\/$/,"");for(let e of T){let r=(0,I.gX)((0,I.A0)(e.filePath));for(;(r===n||r.startsWith(`${n}/`))&&(t.add(r),r!==n);){let e=(0,I.gX)(r);if(e===r)break;r=e}}return t},[e,T]),ea=(0,i.useCallback)((e,t)=>{y(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r})},[]),es=(0,i.useCallback)(t=>{let n=t.uploaded??[];J({uploaded:n,skipped:t.skipped??[],errors:t.errors??[]}),n.length>0&&(C(new Set(n.map(t=>(0,I.e_)(e,t)))),j(e=>e+1))},[e]),el=(0,i.useCallback)(async(t,n)=>{Y(null),q(null),U(0),H("uploading");try{let{status:r,data:i}=await new Promise((r,i)=>{let o=new FormData;t.forEach(e=>o.append("files",e,e.name));let a=new XMLHttpRequest;a.open("POST",`/api/files/${(0,I.HG)(e)}?type=upload&conflict=${n}`),a.upload.onprogress=e=>{e.lengthComputable&&e.total>0&&U(Math.round(e.loaded/e.total*100))},a.onerror=()=>i(Error("Network error while uploading files")),a.onabort=()=>i(Error("Upload cancelled")),a.onload=()=>{let e={};try{e=JSON.parse(a.responseText)}catch{a.responseText&&(e.error=a.responseText)}r({status:a.status,data:e})},a.send(o)});if(409===r&&i.conflicts?.length)return void Y({files:t,conflicts:i.conflicts,nonReplaceable:i.nonReplaceable??[]});if(r<200||r>=300)throw Error(i.error??`Upload failed (HTTP ${r})`);U(100),es(i)}catch(e){q(e instanceof Error?e.message:String(e))}finally{H("idle")}},[es,e]),ed=(0,i.useCallback)(async t=>{if(0!==t.length&&!er){J(null),C(new Set),Y(null),q(null),U(0),H("checking");try{let n=await fetch(`/api/files/${(0,I.HG)(e)}?type=upload-check`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({fileNames:t.map(e=>e.name)})}),r=await n.json().catch(()=>({}));if(!n.ok)throw Error(r.error??`Upload check failed (HTTP ${n.status})`);if(r.conflicts?.length)return void Y({files:t,conflicts:r.conflicts,nonReplaceable:r.nonReplaceable??[]});await el(t,"error")}catch(e){q(e instanceof Error?e.message:String(e))}finally{H("idle")}}},[e,el,er]),ec=(0,i.useCallback)(e=>{let t=Array.from(e.target.files??[]);e.target.value="",ed(t)},[ed]);(0,i.useImperativeHandle)(u,()=>({openUploadPicker(){er||et.current?.click()}}),[er]),(0,i.useEffect)(()=>{s?.(er)},[s,er]),(0,i.useEffect)(()=>()=>s?.(!1),[s]),(0,i.useEffect)(()=>{let t=ee.current!==e;ee.current=e,t&&(y(new Set),C(new Set),J(null),Y(null),q(null),X(""),Q(null)),f(t),v(null);let n=!1;return L(e).then(e=>{n||g(e)}).catch(e=>{n||v(e instanceof Error?e.message:String(e))}).finally(()=>{n||f(!1)}),()=>{n=!0}},[e,n,k]),(0,i.useEffect)(()=>{let t=!1;return E(e).then(e=>{t||(M(e.isGitRepository?e.files:[]),P(e.isGitRepository?{additions:e.additions,deletions:e.deletions}:{additions:0,deletions:0}))}).catch(()=>{t||(M([]),P({additions:0,deletions:0}))}),()=>{t=!0}},[e,n,k]),(0,i.useEffect)(()=>{let t=G.trim();if(!t)return void Q(null);let n=!1,r=setTimeout(()=>{R(e,t).then(e=>{n||Q(e.matches)}).catch(()=>{n||Q([])})},200);return()=>{n=!0,clearTimeout(r)}},[e,G]),(0,i.useEffect)(()=>{d?.(T.length)},[T,d]);let eu=er||null!==K||null!==_||null!==V,ep=!l&&T.length>0,eh=(0,i.useCallback)(()=>{V&&0!==V.uploaded.length&&a?.(V.uploaded.map(t=>(0,I.qP)((0,I.e_)(e,t),e)))},[e,a,V]);return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",flex:1,minHeight:0},children:[(0,r.jsx)("input",{ref:et,type:"file",multiple:!0,hidden:!0,onChange:ec}),(0,r.jsxs)("div",{style:{flexShrink:0,padding:"4px 8px 2px"},children:[(0,r.jsx)("input",{type:"text",value:G,onChange:e=>X(e.target.value),onKeyDown:e=>{"Escape"===e.key&&X("")},placeholder:p("files.searchPlaceholder"),"aria-label":p("files.searchPlaceholder"),style:{width:"100%",fontSize:11,fontFamily:"var(--font-mono)",padding:"5px 8px",border:"1px solid color-mix(in srgb, var(--border) 55%, transparent)",borderRadius:5,outline:"none",background:"var(--side-input)",color:"var(--text)",boxSizing:"border-box"}}),c&&(0,r.jsx)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:2,padding:"4px 0 0"},children:c})]}),(0,r.jsxs)("div",{style:{flex:1,minHeight:0,overflowY:"auto",overflowX:"hidden"},children:[eu&&(0,r.jsxs)("div",{style:{padding:"6px 8px",borderBottom:"1px solid var(--border)"},children:[er&&(0,r.jsxs)("div",{role:"status","aria-live":"polite","aria-label":"checking"===F?p("files.checking"):p("files.uploading",{progress:O}),children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,minHeight:14,color:"var(--text-muted)"},children:["checking"===F?(0,r.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",style:{animation:"spin 0.8s linear infinite"},"aria-hidden":"true",children:(0,r.jsx)("path",{d:"M21 12a9 9 0 1 1-5.7-8.4"})}):(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)("path",{d:"M12 16V4"}),(0,r.jsx)("path",{d:"m7 9 5-5 5 5"}),(0,r.jsx)("path",{d:"M5 20h14"})]}),"uploading"===F&&(0,r.jsxs)("span",{style:{fontSize:10},children:[O,"%"]})]}),"uploading"===F&&(0,r.jsx)("div",{style:{height:3,marginTop:4,overflow:"hidden",borderRadius:2,background:"var(--border)"},children:(0,r.jsx)("div",{style:{width:`${O}%`,height:"100%",background:"var(--text-muted)",transition:"width 120ms ease"}})})]}),K&&(0,r.jsxs)("div",{role:"alert",style:{padding:7,border:"1px solid color-mix(in srgb, #f59e0b 55%, var(--border))",borderRadius:4,background:"color-mix(in srgb, #f59e0b 9%, var(--bg-panel))"},children:[(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text)",lineHeight:1.35,overflowWrap:"anywhere"},children:p("files.conflictSummary",{count:K.conflicts.length,countSuffix:1===K.conflicts.length?"":"s",files:K.conflicts.join(", ")})}),K.nonReplaceable.length>0&&(0,r.jsx)("div",{style:{marginTop:3,fontSize:10,color:"#f59e0b",lineHeight:1.35,overflowWrap:"anywhere"},children:p("files.cannotReplace",{files:K.nonReplaceable.join(", ")})}),(0,r.jsxs)("div",{style:{display:"flex",gap:5,marginTop:7},children:[(0,r.jsx)("button",{type:"button",onClick:()=>void el(K.files,"overwrite"),style:{height:22,padding:"0 7px",border:"1px solid #ef4444",borderRadius:4,background:"transparent",color:"#ef4444",cursor:"pointer",fontSize:10},children:p("files.replace")}),(0,r.jsx)("button",{type:"button",onClick:()=>void el(K.files,"skip"),style:{height:22,padding:"0 7px",border:"1px solid color-mix(in srgb, var(--border) 55%, transparent)",borderRadius:4,background:"var(--bg-panel)",color:"var(--text)",cursor:"pointer",fontSize:10},children:p("files.skipExisting")}),(0,r.jsx)("button",{type:"button",onClick:()=>Y(null),style:{height:22,padding:"0 7px",border:"none",borderRadius:4,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:10},children:p("files.cancel")})]})]}),_&&(0,r.jsxs)("div",{role:"alert",style:{display:"flex",alignItems:"flex-start",gap:6,fontSize:11,lineHeight:1.35,color:"#f87171"},children:[(0,r.jsx)("span",{style:{minWidth:0,flex:1,overflowWrap:"anywhere"},children:_}),(0,r.jsx)(N,{onClick:()=>q(null),title:p("files.dismissError")})]}),V&&(0,r.jsxs)("div",{"aria-live":"polite",children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minHeight:22,fontSize:11},children:[(0,r.jsxs)("div",{style:{minWidth:0,flex:1,display:"flex",alignItems:"center",gap:8},children:[V.uploaded.length>0&&(0,r.jsxs)("span",{title:`${V.uploaded.length} uploaded`,"aria-label":`${V.uploaded.length} uploaded`,style:{display:"flex",alignItems:"center",gap:3,color:"#22c55e"},children:[(0,r.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"m5 12 4 4L19 6"})}),(0,r.jsx)("span",{children:V.uploaded.length})]}),V.skipped.length>0&&(0,r.jsxs)("span",{title:`${V.skipped.length} skipped`,"aria-label":`${V.skipped.length} skipped`,style:{display:"flex",alignItems:"center",gap:3,color:"var(--text-dim)"},children:[(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:"M8 12h8"})]}),(0,r.jsx)("span",{children:V.skipped.length})]}),V.errors.length>0&&(0,r.jsxs)("span",{title:`${V.errors.length} failed`,"aria-label":`${V.errors.length} failed`,style:{display:"flex",alignItems:"center",gap:3,color:"#f87171"},children:[(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)("path",{d:"M12 3 2.5 20h19L12 3Z"}),(0,r.jsx)("path",{d:"M12 9v4"}),(0,r.jsx)("path",{d:"M12 17h.01"})]}),(0,r.jsx)("span",{children:V.errors.length})]})]}),V.uploaded.length>0&&a&&(0,r.jsxs)("button",{type:"button",onClick:eh,title:1===V.uploaded.length?p("files.addUploadedFile"):p("files.addAllUploadedFiles"),"aria-label":1===V.uploaded.length?p("files.addUploadedFile"):p("files.addAllUploadedFiles"),style:{height:22,padding:"0 7px",display:"flex",alignItems:"center",justifyContent:"center",gap:4,flexShrink:0,border:"1px solid color-mix(in srgb, var(--border) 55%, transparent)",borderRadius:4,background:"var(--bg-panel)",color:"var(--accent)",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:[(0,r.jsx)($,{}),p("files.mention")]}),(0,r.jsx)(N,{onClick:()=>J(null),title:p("files.dismissUploadResults")})]}),V.errors.map(e=>(0,r.jsxs)("div",{title:e.error,style:{display:"flex",alignItems:"center",gap:4,marginTop:3,minWidth:0,fontSize:10,color:"#f87171"},children:[(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},"aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,r.jsx)("path",{d:"M12 8v5"}),(0,r.jsx)("path",{d:"M12 17h.01"})]}),(0,r.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name})]},e.name))]})]}),ep&&(0,r.jsxs)("div",{style:{padding:"0 4px 2px"},children:[(0,r.jsxs)("div",{"aria-label":p("files.changeStats",{count:T.length,additions:z.additions,deletions:z.deletions}),style:{display:"flex",alignItems:"center",gap:6,height:24,padding:"0 10px",fontSize:12},children:[(0,r.jsx)("span",{style:{color:"var(--text-dim)"},children:p("files.changedCount",{count:T.length})}),(0,r.jsxs)("span",{style:{color:W.added,fontFamily:"var(--font-mono)"},children:["+",z.additions]}),(0,r.jsxs)("span",{style:{color:W.deleted,fontFamily:"var(--font-mono)"},children:["-",z.deletions]})]}),T.map(n=>(0,r.jsx)(B,{status:n,cwd:e,onOpenFile:t,t:p},n.filePath))]}),(!ep||null!==Z)&&(0,r.jsxs)("div",{style:{padding:"2px 4px"},children:[null!==Z?Z.length>0?Z.map(n=>(0,r.jsx)(A,{match:n,cwd:e,onOpenFile:t},n.path)):(0,r.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:p("files.noFiles")}):x?(0,r.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:"Loading files..."}):m?(0,r.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"#f87171"},children:m}):h.map(n=>(0,r.jsx)(D,{node:n,depth:0,cwd:e,onOpenFile:t,onAtMention:o,expandedPaths:b,onToggleExpanded:ea,refreshToken:en,highlightedPaths:S,gitStatusByPath:ei,changedDirectoryPaths:eo,t:p},n.fullPath)),!x&&!m&&0===h.length&&(0,r.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:p("files.noFiles")})]})]})]})});function H({active:e,onChange:t,runningCount:n=0}){let{t:o}=(0,w.s)(),[a,s]=(0,i.useState)(null),l=[{key:"sessions",label:n>0?`${o("sidebar.sessionTab")}(${n})`:o("sidebar.sessionTab"),icon:(0,r.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})},{key:"files",label:o("sidebar.filesTab"),icon:(0,r.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"})})}];return(0,r.jsx)("div",{role:"tablist","aria-label":o("sidebar.views"),style:{display:"flex",flex:"0 0 auto",minWidth:0,borderBottom:"1px solid color-mix(in srgb, var(--border) 55%, transparent)"},children:l.map(({key:n,label:i,icon:o})=>{let l=e===n,d=!l&&a===n;return(0,r.jsxs)("button",{role:"tab","aria-selected":l,onClick:()=>t(n),onMouseEnter:()=>s(n),onMouseLeave:()=>s(null),style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",gap:6,height:32,padding:0,border:"none",borderBottom:l?"2px solid var(--accent)":"2px solid transparent",marginBottom:-1,background:d?"var(--side-hover)":"transparent",cursor:"pointer",fontSize:11,fontWeight:l?600:400,color:l?"var(--accent)":d?"var(--text)":"var(--text-muted)",transition:"color 0.12s, background 0.12s"},children:[o,i]},n)})})}var O=n(66249);async function U(e){try{let t=(await e.text()).trim();if(t)return t}catch{}return`${e.status} ${e.statusText}`.trim()}function _({activeBoardId:e,collapsed:t,onToggleCollapsed:n,onOpenBoard:o,onExitBoard:a,refreshKey:s}){let{t:l}=(0,w.s)(),d=(0,j.u)(),[c,u]=(0,i.useState)([]),[,p]=(0,i.useState)(!0),[h,g]=(0,i.useState)(!1),[x,f]=(0,i.useState)(""),[m,v]=(0,i.useState)(null),[b,y]=(0,i.useState)(""),[k,S]=(0,i.useState)(null),[C,T]=(0,i.useState)(!1),[M,I]=(0,i.useState)(null),[L,R]=(0,i.useState)(null),E=(0,i.useRef)(null),z=(0,i.useRef)(null),W=(0,i.useCallback)(async()=>{try{let e=await fetch("/api/boards",{cache:"no-store"});if(!e.ok)return null;let t=await e.json();return u(t.boards),t.boards}catch{return null}finally{p(!1)}},[]);(0,i.useEffect)(()=>{W()},[W,s]),(0,i.useEffect)(()=>{h&&E.current?.focus()},[h]),(0,i.useEffect)(()=>{m&&z.current?.focus()},[m]);let P=async()=>{let e=x.trim();if(e&&!C){T(!0);try{let t=await fetch("/api/boards",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e})});if(t.ok){let e=await t.json();f(""),g(!1),await W(),o(e.board.id)}}finally{T(!1)}}},$=async e=>{if(C)return;let t=b.trim();if(!t)return void v(null);T(!0);try{(await fetch(`/api/boards/${encodeURIComponent(e)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t})})).ok&&(v(null),await W())}finally{T(!1)}},N=async t=>{if(!C){T(!0);try{if((await fetch(`/api/boards/${encodeURIComponent(t)}`,{method:"DELETE"})).ok){S(null);let n=await W();if(e===t){let e=(n??[]).find(e=>!e.isSystem&&null==e.taskId&&e.id!==t);e?o(e.id):a?.()}}}finally{T(!1)}}},D=(0,i.useCallback)(e=>t=>{t.target.closest("button, input, textarea")?t.preventDefault():(t.dataTransfer.setData("application/x-board-id",e),t.dataTransfer.effectAllowed="move",I({id:e}),R(null))},[]),B=(0,i.useCallback)(e=>t=>{if(!t.dataTransfer.types.includes("application/x-board-id")||!M||M.id===e)return;let n=t.currentTarget.getBoundingClientRect(),r=t.clientY<n.top+n.height/2;t.preventDefault(),t.dataTransfer.dropEffect="move",R({targetId:e,before:r})},[M]),A=(0,i.useCallback)(e=>t=>{t.preventDefault();let n=t.dataTransfer.getData("application/x-board-id")||M?.id;if(!n||!L||L.targetId!==e){I(null),R(null);return}let r=c.filter(e=>!e.isSystem&&null==e.taskId).map(e=>e.id),i=r.indexOf(n),o=r.indexOf(e);if(I(null),R(null),-1===i||-1===o)return;let a=[...r];a.splice(i,1);let s=a.indexOf(e)+ +!L.before;a.splice(s,0,n),fetch("/api/boards/reorder",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({orderedIds:a})}).then(e=>{if(e.ok)return W()}).catch(()=>{})},[c,L,M,W]),F=c.filter(e=>!e.isSystem&&null==e.taskId);return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",flexShrink:0},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4,padding:"5px 6px 3px 10px"},children:[(0,r.jsxs)("button",{type:"button",onClick:n,"aria-expanded":!t,style:{display:"flex",alignItems:"center",gap:6,flex:1,minWidth:0,background:"none",border:"none",padding:0,textAlign:"left",cursor:"pointer",color:"var(--text-dim)"},children:[(0,r.jsx)("span",{style:{fontSize:11,fontWeight:600,letterSpacing:"0.02em"},children:l("boards.title")}),(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:t?"rotate(-90deg)":"none",transition:"transform 0.15s"},"aria-hidden":"true",children:(0,r.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),(0,r.jsx)("button",{type:"button",onClick:()=>g(e=>!e),title:l("boards.new"),"aria-label":l("boards.new"),style:{width:24,height:24,padding:0,display:"flex",alignItems:"center",justifyContent:"center",background:"none",border:"none",borderRadius:5,color:"var(--text-dim)",cursor:"pointer"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="var(--side-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)",e.currentTarget.style.background="transparent"},children:(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round","aria-hidden":"true",children:[(0,r.jsx)("line",{x1:"6",y1:"1",x2:"6",y2:"11"}),(0,r.jsx)("line",{x1:"1",y1:"6",x2:"11",y2:"6"})]})})]}),!t&&(0,r.jsxs)("div",{style:{paddingBottom:4},children:[h&&(0,r.jsxs)("div",{onClick:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),style:{display:"flex",alignItems:"center",gap:4,margin:"0 4px 4px",padding:"0 8px 0 5px",height:32,boxSizing:"border-box",background:"var(--side-input)",border:"1px solid color-mix(in srgb, var(--border) 55%, transparent)",borderRadius:6},children:[(0,r.jsx)("span",{"aria-hidden":!0,style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,color:"var(--text-dim)",cursor:"default",pointerEvents:"none"},children:(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)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,r.jsx)("path",{d:"M3 9h18"}),(0,r.jsx)("path",{d:"M9 21V9"})]})}),(0,r.jsx)("input",{ref:E,value:x,onChange:e=>f(e.target.value),...d.compositionProps,onKeyDown:e=>{d.isIMEBusy(e)||("Enter"===e.key&&P(),"Escape"===e.key&&(g(!1),f("")))},onBlur:()=>{x.trim()&&P(),g(!1),f("")},placeholder:l("boards.namePlaceholder"),style:{flex:1,minWidth:0,height:"100%",padding:0,border:"none",outline:"none",background:"transparent",color:"var(--text)",fontSize:12}}),(0,r.jsx)("button",{type:"button",title:l("boards.create"),"aria-label":l("boards.create"),disabled:!x.trim(),onMouseDown:e=>e.preventDefault(),onClick:()=>void P(),style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,background:"transparent",border:"none",borderRadius:5,color:x.trim()?"var(--accent)":"var(--text-dim)",cursor:x.trim()?"pointer":"default"},children:(0,r.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("polyline",{points:"20 6 9 17 4 12"})})}),(0,r.jsx)("button",{type:"button",title:l("boards.cancel"),"aria-label":l("boards.cancel"),onMouseDown:e=>e.preventDefault(),onClick:()=>{g(!1),f("")},style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,background:"transparent",border:"none",borderRadius:5,color:"var(--text-dim)",cursor:"pointer"},children:(0,r.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round","aria-hidden":"true",children:[(0,r.jsx)("line",{x1:"5",y1:"5",x2:"19",y2:"19"}),(0,r.jsx)("line",{x1:"19",y1:"5",x2:"5",y2:"19"})]})})]}),0===F.length&&(0,r.jsx)("div",{style:{padding:"6px 10px",color:"var(--text-muted)",fontSize:11.5,fontStyle:"italic"},children:l("boards.empty")}),F.map(t=>(0,r.jsx)(q,{board:t,isActive:e===t.id,isDragging:M?.id===t.id,dropBefore:L?.targetId===t.id&&L.before,dropAfter:L?.targetId===t.id&&!L.before,renaming:m===t.id,renameValue:b,renameInputRef:z,onRenameValueChange:y,onStartRename:()=>{v(t.id),y(t.name)},onCommitRename:()=>void $(t.id),onCancelRename:()=>v(null),onDelete:()=>S(t.id),onDragStart:D(t.id),onDragEnd:()=>{I(null),R(null)},onDragOver:B(t.id),onDrop:A(t.id),onOpenBoard:()=>o(t.id)},t.id))]}),k&&(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1200,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.35)"},onClick:()=>S(null),children:(0,r.jsxs)("div",{className:"glass-panel",onClick:e=>e.stopPropagation(),style:{width:300,padding:16,borderRadius:12,border:"1px solid color-mix(in srgb, var(--border) 60%, transparent)",boxShadow:"0 8px 30px rgba(0,0,0,0.3)",color:"var(--text)",fontSize:13,lineHeight:1.6},children:[(0,r.jsx)("div",{style:{fontWeight:600,marginBottom:8},children:l("boards.deleteConfirmTitle")}),(0,r.jsx)("div",{style:{color:"var(--text-muted)",marginBottom:14},children:l("boards.deleteConfirm")}),(0,r.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:[(0,r.jsx)("button",{type:"button",onClick:()=>S(null),style:{padding:"5px 12px",border:"1px solid var(--border)",borderRadius:6,background:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:l("boards.cancel")}),(0,r.jsxs)("button",{type:"button",onClick:()=>void N(k),disabled:C,style:{display:"flex",alignItems:"center",gap:6,padding:"5px 12px",border:"none",borderRadius:6,background:"#dc2626",color:"#fff",cursor:C?"default":"pointer",fontSize:12,opacity:C?.7:1},children:[C&&(0,r.jsx)("span",{"aria-hidden":!0,style:{width:10,height:10,borderRadius:"50%",border:"2px solid rgba(255,255,255,0.35)",borderTopColor:"#fff",animation:"spin 0.8s linear infinite"}}),l(C?"boards.deleting":"boards.delete")]})]})]})})]})}function q({board:e,isActive:t,isDragging:n,dropBefore:o,dropAfter:a,renaming:s,renameValue:l,renameInputRef:d,onRenameValueChange:c,onStartRename:u,onCommitRename:p,onCancelRename:h,onDelete:g,onDragStart:x,onDragEnd:f,onDragOver:m,onDrop:v,onOpenBoard:b}){let{t:y}=(0,w.s)(),k=(0,j.u)(),[S,C]=(0,i.useState)(!1),[T,M]=(0,i.useState)(!1),[I,L]=(0,i.useState)(!1),R=T||I,E=(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)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,r.jsx)("path",{d:"M3 9h18"}),(0,r.jsx)("path",{d:"M9 21V9"})]}),z={flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:"transparent",border:"1px solid transparent",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",transition:"background 0.12s, color 0.12s"};return(0,r.jsx)("div",{onDragOver:e=>{e.dataTransfer.types.includes("text/session-id")&&(e.preventDefault(),e.dataTransfer.dropEffect="move",M(!0),1)||m(e)},onDragLeave:()=>M(!1),onDrop:t=>{(t=>{if(!t.dataTransfer.types.includes("text/session-id"))return!1;t.preventDefault(),t.stopPropagation(),M(!1);let n=t.dataTransfer.getData("text/session-id");if(!n||e.taskId&&!(0,O.GO)((0,O.Fm)(t.dataTransfer.getData(O.il))))return!0;let r=t.dataTransfer.getData("text/session-title")||void 0;return fetch(`/api/boards/${encodeURIComponent(e.id)}/add-session`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:n,title:r})}).then(async e=>{if(!e.ok)throw Error(`HTTP ${e.status} ${await U(e)}`);L(!0),setTimeout(()=>L(!1),700)}).catch(t=>{console.warn(`[board] 拖入看板 ${e.id} 落卡失败 (${n}):`,t?.message??t)}),!0})(t)||v(t)},style:{margin:"0 4px 2px",borderRadius:6,borderTop:o?"2px solid var(--accent)":"none",borderBottom:a?"2px solid var(--accent)":"none",opacity:n?.4:1},children:(0,r.jsx)("div",{draggable:!s,onDragStart:x,onDragEnd:f,onClick:b,"data-board-row":e.id,title:e.name,onMouseEnter:()=>C(!0),onMouseLeave:()=>C(!1),style:{display:"flex",alignItems:"center",gap:4,minHeight:38,padding:"0 8px 0 5px",borderRadius:6,background:R?"color-mix(in srgb, var(--accent) 8%, transparent)":t?"var(--side-active)":S?"var(--side-hover)":"transparent",boxShadow:R?"inset 2px 0 0 var(--accent)":"none",cursor:s?"default":"pointer",transition:"background 0.12s, box-shadow 0.12s"},children:s?(0,r.jsxs)("span",{onMouseDown:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),style:{display:"flex",alignItems:"center",gap:4,flex:1,minWidth:0,minHeight:38,boxSizing:"border-box"},children:[(0,r.jsx)("span",{"aria-hidden":!0,style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,color:"var(--text-dim)",cursor:"default",pointerEvents:"none"},children:E}),(0,r.jsx)("input",{ref:d,value:l,onChange:e=>c(e.target.value),...k.compositionProps,onKeyDown:e=>{k.isIMEBusy(e)||("Enter"===e.key&&p(),"Escape"===e.key&&h())},onBlur:p,autoFocus:!0,placeholder:y("boards.namePlaceholder"),style:{flex:1,minWidth:0,fontSize:12,border:"none",outline:"none",background:"transparent",color:"var(--text)",boxSizing:"border-box",height:"100%",padding:0}})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{"aria-hidden":!0,style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,color:"var(--text-dim)",cursor:"default",pointerEvents:"none"},children:E}),(0,r.jsx)("span",{style:{flex:1,minWidth:0,fontSize:12,fontWeight:500,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),S&&(0,r.jsxs)("span",{style:{position:"relative",display:"flex",gap:3,flexShrink:0,alignItems:"center"},children:[(0,r.jsx)("button",{type:"button",title:y("boards.rename"),"aria-label":y("boards.rename"),onClick:e=>{e.stopPropagation(),u()},style:z,onMouseEnter:e=>{e.currentTarget.style.background="var(--side-active)",e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:(0,r.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"})})}),(0,r.jsx)("button",{type:"button",title:y("boards.delete"),"aria-label":y("boards.delete"),onClick:e=>{e.stopPropagation(),g()},style:z,onMouseEnter:e=>{e.currentTarget.style.background="var(--side-active)",e.currentTarget.style.color="#ef4444"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:(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",children:[(0,r.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,r.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,r.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,r.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]})})]})]})})})}let V="text/session-id",J=(0,r.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,r.jsx)("path",{d:"M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"})}),K=(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,r.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,r.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,r.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]}),Y=(0,r.jsx)("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:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})}),G=(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)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,r.jsx)("path",{d:"M3 9h18"}),(0,r.jsx)("path",{d:"M9 21V9"})]}),X=(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:"M12 17v5"}),(0,r.jsx)("path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V6h1a2 2 0 0 0 0-4H8a2 2 0 0 0 0 4h1z"})]}),Z="application/x-task-id";function Q({task:e,content:t,sessionCount:n,pinnedCount:o,sessionTotal:a,hasMore:s,remainingCount:l,onLoadMore:d,loadingMore:c,runningCount:u,activeSessionId:p,isActive:h,onDropAssign:g,onRename:x,onDelete:f,onNewSession:m,onTogglePin:v,onOpenBoard:b,onDragStartTask:y,onDragOverTask:k,onDropTask:T,onDragEndTask:I,isDragging:L,dropBefore:R,dropAfter:E}){let{t:z}=(0,w.s)(),W=(0,j.u)(),[P,$]=(0,i.useState)(!0),N=null!=p&&e.sessionIds.includes(p);(0,i.useEffect)(()=>{N&&$(!1)},[N]);let[D,B]=(0,i.useState)(!1),[A,F]=(0,i.useState)(!1),[H,U]=(0,i.useState)(!1),[_,q]=(0,i.useState)(""),[ee,et]=(0,i.useState)(!1),[en,er]=(0,i.useState)(!1),[ei,eo]=(0,i.useState)(!1),[ea,es]=(0,i.useState)(!1),el=(0,i.useRef)(null),ed=(0,i.useRef)(null),ec=(0,i.useRef)(null);(0,i.useEffect)(()=>{if(!ei&&!ee)return;let e=e=>{let t=e.target;ed.current?.contains(t)||ec.current?.contains(t)||(eo(!1),et(!1))},t=e=>{"Escape"===e.key&&(eo(!1),et(!1))};return document.addEventListener("pointerdown",e,!0),document.addEventListener("keydown",t),()=>{document.removeEventListener("pointerdown",e,!0),document.removeEventListener("keydown",t)}},[ei,ee]);let eu=(0,i.useCallback)(e=>{if(e.stopPropagation(),ei)return void eo(!1);let t=e.currentTarget.getBoundingClientRect(),n=e.currentTarget.parentElement,r=null;for(;n;){let e=getComputedStyle(n);if("auto"===e.overflowY||"scroll"===e.overflowY||"overlay"===e.overflowY){r=n;break}n=n.parentElement}let i=r?r.getBoundingClientRect():{top:0,bottom:window.innerHeight},o=i.bottom-t.bottom,a=t.top-i.top;es(!(o>=114)&&(a>=114||a>o)),eo(!0)},[ei]);(0,i.useEffect)(()=>{if(H){let e=requestAnimationFrame(()=>el.current?.select());return()=>cancelAnimationFrame(e)}},[H]);let ep=(0,i.useCallback)(()=>{let t=_.trim();t&&x(e.id,t),U(!1)},[_,x,e.id]),eh=(0,i.useCallback)(t=>{if(t.dataTransfer.types.includes(Z)){let n=t.currentTarget.getBoundingClientRect(),r=t.clientY<n.top+n.height/2,i=k(e.id,r);B(!1),i&&(t.preventDefault(),t.dataTransfer.dropEffect="move");return}t.dataTransfer.types.includes(V)&&(t.preventDefault(),t.dataTransfer.dropEffect="move",B(!0))},[k,e.id]),eg=(0,i.useCallback)(t=>{t.preventDefault(),B(!1);let n=t.dataTransfer.getData(V);if(n){let r=(0,O.Fm)(t.dataTransfer.getData(O.il));(0,O.GO)(r)&&g(e.id,n);return}t.dataTransfer.types.includes(Z)&&T(e.id)},[g,e.id,T]),ex=(0,i.useCallback)(t=>{t.target.closest("button, input, textarea, a, [role=menuitem]")?t.preventDefault():(t.dataTransfer.setData(Z,e.id),t.dataTransfer.effectAllowed="move",y(e))},[e,y]),ef={flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"transparent",border:"1px solid transparent",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",transition:"background 0.12s, color 0.12s"};return(0,r.jsxs)("div",{onDragOver:eh,onDragLeave:()=>B(!1),onDrop:eg,style:{position:"relative",margin:"0 4px 2px",borderRadius:6,background:D?"color-mix(in srgb, var(--accent) 8%, transparent)":"transparent",border:"none",boxShadow:D?"inset 2px 0 0 var(--accent)":"none",borderTop:R?"2px solid var(--accent)":"none",borderBottom:E?"2px solid var(--accent)":"none",opacity:L?.4:1,transition:"background 0.12s, box-shadow 0.12s"},children:[(0,r.jsx)("div",{draggable:!0,onDragStart:ex,onDragEnd:I,onClick:()=>{e.sessionIds.length>0&&$(e=>!e)},onMouseEnter:()=>F(!0),onMouseLeave:()=>F(!1),style:{display:"flex",alignItems:"center",gap:4,minHeight:38,padding:"0 8px 0 5px",borderRadius:6,background:h?"var(--side-active)":A?"var(--side-hover)":"transparent",cursor:"pointer",transition:"background 0.12s"},children:H?(0,r.jsxs)("span",{onClick:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),style:{display:"flex",alignItems:"center",gap:4,flex:1,minWidth:0,minHeight:38,boxSizing:"border-box"},children:[(0,r.jsx)("span",{"aria-hidden":!0,style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,color:"var(--text-dim)",cursor:"default",pointerEvents:"none"},children:(0,r.jsx)(M.sj,{size:13,open:!P})}),(0,r.jsx)("input",{ref:el,value:_,onChange:e=>q(e.target.value),...W.compositionProps,onKeyDown:e=>{W.isIMEBusy(e)||("Enter"===e.key&&ep(),"Escape"===e.key&&U(!1))},onBlur:ep,autoFocus:!0,style:{flex:1,minWidth:0,fontSize:12,border:"none",outline:"none",background:"transparent",color:"var(--text)",boxSizing:"border-box",height:"100%",padding:0}})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{"aria-hidden":"true",style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,color:"var(--text-dim)",cursor:"default",pointerEvents:"none"},children:(0,r.jsx)(M.sj,{size:13,open:!P})}),null!=u&&u>0&&(0,r.jsx)("span",{title:z("sidebar.taskRunning",{count:u}),style:{flexShrink:0,minWidth:14,height:14,padding:"0 4px",borderRadius:999,background:"color-mix(in srgb, var(--accent) 18%, transparent)",border:"1px solid color-mix(in srgb, var(--accent) 55%, transparent)",color:"var(--accent)",fontSize:9,fontWeight:700,lineHeight:"12px",textAlign:"center",boxSizing:"border-box"},children:u}),(0,r.jsx)("span",{title:`${e.name} \xb7 ${function(e){if(!e)return"";let t=Math.floor((Date.now()-e)/6e4);if(t<1)return"now";if(t<60)return`${t}m`;let n=Math.floor(t/60);if(n<24)return`${n}h`;let r=Math.floor(n/24);return r<7?`${r}d`:new Date(e).toLocaleDateString()}(e.created)}`,style:{flex:1,minWidth:0,fontSize:12,fontWeight:500,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),e.pinned&&!H&&!ee&&(0,r.jsx)("span",{title:z("sidebar.pinned"),style:{display:"inline-flex",flexShrink:0,color:"var(--accent)"},children:(0,r.jsxs)("svg",{width:"11",height:"11",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:"M12 17v5"}),(0,r.jsx)("path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V6h1a2 2 0 0 0 0-4H8a2 2 0 0 0 0 4h1z"})]})}),(A||ei||ee)&&!H&&(0,r.jsxs)("span",{ref:ed,style:{position:"relative",display:"flex",gap:3,flexShrink:0,alignItems:"center"},children:[(0,r.jsx)("button",{type:"button",title:z("sidebar.taskOpenBoard"),onClick:t=>{t.stopPropagation(),b(e.id)},style:{...ef,width:28,height:28,color:h?"var(--accent)":void 0},onMouseEnter:e=>{e.currentTarget.style.background="var(--side-active)",e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color=h?"var(--accent)":"var(--text-muted)"},children:G}),(0,r.jsx)("button",{type:"button",title:z("sidebar.newTaskSession"),onClick:t=>{t.stopPropagation(),m(e.id)},style:{...ef,width:28,height:28},onMouseEnter:e=>{e.currentTarget.style.background="var(--side-active)",e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:Y}),(0,r.jsx)("button",{type:"button",title:z("sidebar.rename"),onClick:t=>{t.stopPropagation(),q(e.name),U(!0),eo(!1)},style:{...ef,width:28,height:28},onMouseEnter:e=>{e.currentTarget.style.background="var(--side-active)",e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:J}),(0,r.jsx)("button",{type:"button",title:z("sidebar.moreActions"),"aria-expanded":ei,"aria-haspopup":"menu",onClick:eu,style:{...ef,width:28,height:28,background:ei?"var(--side-active)":"transparent",color:ei?"var(--accent)":"var(--text-muted)"},onMouseEnter:e=>{ei||(e.currentTarget.style.background="var(--side-active)",e.currentTarget.style.color="var(--accent)")},onMouseLeave:e=>{ei||(e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)")},children:(0,r.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"12",cy:"5",r:"1.4",fill:"currentColor"}),(0,r.jsx)("circle",{cx:"12",cy:"12",r:"1.4",fill:"currentColor"}),(0,r.jsx)("circle",{cx:"12",cy:"19",r:"1.4",fill:"currentColor"})]})}),(0,r.jsx)(S.f,{open:ei,up:ea,style:{position:"absolute",top:ea?"auto":"calc(100% + 4px)",bottom:ea?"calc(100% + 4px)":"auto",right:0,zIndex:120,minWidth:148,background:"var(--popover-glass)",backdropFilter:"blur(var(--glass-blur-heavy)) saturate(var(--glass-saturate))",WebkitBackdropFilter:"blur(var(--glass-blur-heavy)) saturate(var(--glass-saturate))",border:"1px solid color-mix(in srgb, var(--border) 60%, transparent)",borderRadius:9,boxShadow:"0 8px 24px rgba(0,0,0,0.12)",padding:4},children:(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:1},role:"menu",children:[(0,r.jsxs)("button",{role:"menuitem",onClick:t=>{t.stopPropagation(),eo(!1),v(e.id)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 10px",border:"none",borderRadius:6,background:"transparent",color:e.pinned?"var(--accent)":"var(--text)",cursor:"pointer",fontSize:12,textAlign:"left",transition:"background 0.1s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--side-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[(0,r.jsx)("span",{style:{flexShrink:0,display:"inline-flex"},children:X}),z(e.pinned?"sidebar.unpinTask":"sidebar.pinTask")]}),(0,r.jsxs)("button",{role:"menuitem",onClick:t=>{t.stopPropagation(),eo(!1),q(e.name),U(!0)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 10px",border:"none",borderRadius:6,background:"transparent",color:"var(--text)",cursor:"pointer",fontSize:12,textAlign:"left",transition:"background 0.1s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--side-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[(0,r.jsx)("span",{style:{flexShrink:0,display:"inline-flex"},children:J}),z("sidebar.rename")]}),(0,r.jsxs)("button",{role:"menuitem",onClick:e=>{e.stopPropagation(),eo(!1),er(!!ed.current&&C(ed.current,96)),et(!0)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 10px",border:"none",borderRadius:6,background:"transparent",color:"#ef4444",cursor:"pointer",fontSize:12,textAlign:"left",transition:"background 0.1s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.10)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[(0,r.jsx)("span",{style:{flexShrink:0,display:"inline-flex"},children:K}),z("sidebar.deleteTask")]})]})}),ee&&(0,r.jsxs)("div",{ref:ec,role:"alertdialog",style:{position:"absolute",...en?{bottom:"calc(100% + 4px)"}:{top:"calc(100% + 4px)"},right:0,zIndex:121,width:236,boxSizing:"border-box",padding:10,display:"flex",flexDirection:"column",gap:8,background:"var(--popover-glass)",backdropFilter:"blur(var(--glass-blur-heavy)) saturate(var(--glass-saturate))",WebkitBackdropFilter:"blur(var(--glass-blur-heavy)) saturate(var(--glass-saturate))",border:"1px solid color-mix(in srgb, var(--border) 60%, transparent)",borderRadius:9,boxShadow:"0 8px 24px rgba(0,0,0,0.12)"},children:[(0,r.jsx)("div",{style:{fontSize:12,lineHeight:1.5,color:"var(--text)"},children:z("sidebar.deleteTaskConfirm",{name:e.name,count:a})}),(0,r.jsxs)("div",{style:{display:"flex",gap:6,justifyContent:"flex-end"},children:[(0,r.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation(),f(e.id),et(!1)},style:{height:24,padding:"0 10px",background:"color-mix(in srgb, #ef4444 12%, transparent)",border:"none",borderRadius:5,color:"#ef4444",fontSize:11,fontWeight:600,cursor:"pointer"},children:z("sidebar.delete")}),(0,r.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),et(!1)},style:{height:24,padding:"0 10px",background:"var(--side-input)",border:"1px solid color-mix(in srgb, var(--border) 55%, transparent)",borderRadius:5,color:"var(--text-muted)",fontSize:11,cursor:"pointer"},children:z("sidebar.cancel")})]})]})]})]})}),!P&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{style:{paddingBottom:3},children:t()}),s&&(0,r.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),d()},disabled:c,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,width:"100%",boxSizing:"border-box",margin:"2px 0",padding:0,background:"transparent",border:"none",color:"var(--text-dim)",fontSize:11,cursor:c?"default":"pointer",transition:"color 0.12s",opacity:c?.7:1},onMouseEnter:e=>{c||(e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)"},children:c?(0,r.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round","aria-hidden":"true",style:{flexShrink:0,animation:"spin 0.9s linear infinite"},children:(0,r.jsx)("path",{d:"M21 12a9 9 0 1 1-5.7-8.4"})}):z("sidebar.loadMoreSessions",{count:l})})]})]})}function ee({groups:e,selectedSessionId:t,activeBoardId:n,runningSessionIds:o,newTaskOpen:a,onNewTaskOpenChange:s,onNewTask:l,onRenameTask:d,onDeleteTask:c,onNewSessionFromTask:u,onToggleTaskPin:p,onOpenTaskBoard:h,onDropSessionToTask:g,onReorderTasks:x}){let{t:f}=(0,w.s)(),m=(0,j.u)(),[v,b]=(0,i.useState)(""),[y,k]=(0,i.useState)(!1),[S,C]=(0,i.useState)(!1),T=(0,i.useRef)(null),[I,L]=(0,i.useState)(null),[R,E]=(0,i.useState)(null),[z,W]=(0,i.useState)(null);(0,i.useEffect)(()=>{a&&T.current?.focus()},[a]);let P=(0,i.useCallback)(()=>{let e=v.trim();e&&(l(e),b(""),s(!1))},[v,l,s]),$=(0,i.useCallback)(e=>{E({id:e.id,pinned:!!e.pinned}),W(null)},[]),N=(0,i.useCallback)(()=>{E(null),W(null)},[]),D=(0,i.useCallback)((t,n)=>{if(!R||R.id===t)return!1;let r=e.find(e=>e.task.id===t);return!!r&&!!r.task.pinned===R.pinned&&(W({targetId:t,before:n}),!0)},[R,e]),B=(0,i.useCallback)(t=>{if(!R||!z||z.targetId!==t)return void N();let n=e.map(e=>e.task.id),r=n.indexOf(R.id),i=n.indexOf(t);if(-1===r||-1===i)return void N();let o=[...n];o.splice(r,1);let a=o.indexOf(t)+ +!z.before;o.splice(a,0,R.id),N(),x(o)},[R,e,N,x,z]);return(0,r.jsxs)("div",{style:{paddingBottom:4},children:[a&&(0,r.jsxs)("div",{onClick:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),style:{display:"flex",alignItems:"center",gap:4,margin:"0 4px 4px",padding:"0 8px 0 5px",height:32,boxSizing:"border-box",background:"var(--side-input)",border:"1px solid color-mix(in srgb, var(--border) 55%, transparent)",borderRadius:6},children:[(0,r.jsx)("span",{"aria-hidden":!0,style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,color:"var(--text-dim)",cursor:"default",pointerEvents:"none"},children:(0,r.jsx)(M.sj,{size:13,open:!1})}),(0,r.jsx)("input",{ref:T,value:v,onChange:e=>b(e.target.value),...m.compositionProps,onKeyDown:e=>{m.isIMEBusy(e)||("Enter"===e.key&&P(),"Escape"===e.key&&(s(!1),b("")))},onBlur:()=>{let e=v.trim();e&&(l(e),b("")),s(!1)},placeholder:f("sidebar.taskName"),style:{flex:1,minWidth:0,height:"100%",padding:0,border:"none",outline:"none",background:"transparent",color:"var(--text)",fontSize:12}}),(0,r.jsx)("button",{type:"button",title:f("sidebar.create"),"aria-label":f("sidebar.create"),disabled:!v.trim(),onMouseDown:e=>e.preventDefault(),onClick:P,onMouseEnter:()=>k(!0),onMouseLeave:()=>k(!1),style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,background:y&&v.trim()?"var(--side-hover)":"transparent",border:"none",borderRadius:5,color:v.trim()?"var(--accent)":"var(--text-dim)",cursor:v.trim()?"pointer":"default",transition:"background 0.12s"},children:(0,r.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("polyline",{points:"20 6 9 17 4 12"})})}),(0,r.jsx)("button",{type:"button",title:f("sidebar.cancel"),"aria-label":f("sidebar.cancel"),onMouseDown:e=>e.preventDefault(),onClick:()=>{s(!1),b("")},onMouseEnter:()=>C(!0),onMouseLeave:()=>C(!1),style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,background:S?"var(--side-hover)":"transparent",border:"none",borderRadius:5,color:S?"var(--text-muted)":"var(--text-dim)",cursor:"pointer",transition:"background 0.12s, color 0.12s"},children:(0,r.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round","aria-hidden":"true",children:[(0,r.jsx)("line",{x1:"5",y1:"5",x2:"19",y2:"19"}),(0,r.jsx)("line",{x1:"19",y1:"5",x2:"5",y2:"19"})]})})]}),e.map(({task:a,content:s,sessionCount:l,pinnedCount:x,sessionTotal:f,hasMore:m,remainingCount:v,onLoadMore:b},y)=>{let k=y>0?e[y-1].task:null,w=k?.pinned&&!a.pinned,j=o?a.sessionIds.filter(e=>o.has(e)).length:0,S=async()=>{L(a.id);try{await b()}finally{L(null)}};return(0,r.jsxs)(i.Fragment,{children:[w&&(0,r.jsx)("div",{style:{height:1,margin:"3px 6px",background:"color-mix(in srgb, var(--border) 55%, transparent)"}}),(0,r.jsx)(Q,{task:a,content:s,sessionCount:l,pinnedCount:x,sessionTotal:f,hasMore:m,remainingCount:v,onLoadMore:S,loadingMore:I===a.id,runningCount:j,activeSessionId:t,isActive:n===a.id,onDropAssign:g,onRename:(e,t)=>void d(e,t),onDelete:e=>void c(e),onNewSession:(e,t)=>u(e,t),onTogglePin:p,onOpenBoard:h,onDragStartTask:$,onDragOverTask:D,onDropTask:B,onDragEndTask:N,isDragging:R?.id===a.id,dropBefore:z?.targetId===a.id&&z.before,dropAfter:z?.targetId===a.id&&!z.before})]},a.id)})]})}function et({onClick:e,title:t,disabled:n,skipHover:i,color:o,background:a="none",marginRight:s,ariaPressed:l,children:d}){return(0,r.jsx)("button",{onClick:e,disabled:n,title:t,"aria-label":t,"aria-pressed":l,style:{position:"relative",display:"flex",alignItems:"center",justifyContent:"center",width:26,height:26,padding:0,marginRight:s,background:a,border:"none",color:o,cursor:n?"default":"pointer",borderRadius:5,flexShrink:0,opacity:n?.6:1,transition:"color 0.3s, background 0.3s"},onMouseEnter:e=>{n||i||(e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="var(--side-hover)")},onMouseLeave:e=>{n||i||(e.currentTarget.style.color=o,e.currentTarget.style.background=a)},children:d})}let en="pi-web:unread-session-ids";function er(e,t){return t&&e.startsWith(t)?"~"+e.slice(t.length):e}function ei({text:e,style:t}){return(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",display:"block",minWidth:0,lineHeight:1.35,direction:"rtl",textAlign:"left",...t},children:(0,r.jsx)("span",{style:{unicodeBidi:"plaintext"},children:e})})}function eo(e){let t=new Map;for(let n of e)t.set(n.id,{session:n,children:[]});let n=new Map;for(let t of e)t.parentSessionId&&n.set(t.id,t.parentSessionId);let r=[];for(let e of t.values()){let i=function(e){let r=n.get(e),i=new Set;for(;r&&!i.has(r);){if(i.add(r),t.has(r))return r;r=n.get(r)}return null}(e.session.id);i?t.get(i).children.push(e):r.push(e)}let i=e=>{e.sort((e,t)=>t.session.modified.localeCompare(e.session.modified)),e.forEach(e=>i(e.children))};return i(r),r}let ea="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";function es(e,t){let n=new Map(e.map(e=>[e.id,e]));return t.map(e=>{let t=n.get(e.id);if(!t)return e;let r=new Set(e.sessionIds),i=new Map((t.sessions??[]).map(e=>[e.id,e.parentSessionId])),o=new Set((e.sessions??[]).map(e=>e.id)),a=(t.sessions??[]).filter(e=>!o.has(e.id)&&(e=>{if(r.has(e.id))return!0;let t=e.parentSessionId,n=new Set;for(;t&&!n.has(t);){if(n.add(t),r.has(t))return!0;t=i.get(t)??void 0}return!1})(e));return{...e,sessions:[...e.sessions??[],...a],pinnedSessionIds:e.pinnedSessionIds??t.pinnedSessionIds,rootTotal:e.rootTotal??t.rootTotal,sessionTotal:e.sessionTotal??t.sessionTotal}})}function el(){let[e,t]=(0,i.useState)(!1),[n,o]=(0,i.useState)(!1),a=(0,i.useRef)(null),s=function(e,t){let[n,r]=(0,i.useState)(e),o=(0,i.useRef)(null),a=(0,i.useRef)(0);return(0,i.useEffect)(()=>{if(!t)return void r(e);a.current=0;let n=4*e.length,i=()=>{a.current+=1;let t=Math.floor(a.current/n*e.length);r(e.split("").map((e,n)=>" "===e?" ":n<t?e:ea[Math.floor(Math.random()*ea.length)]).join("")),a.current<n?o.current=requestAnimationFrame(i):r(e)};return o.current=requestAnimationFrame(i),()=>{o.current&&cancelAnimationFrame(o.current)}},[e,t]),n}(e?"0.1.59p0.86.0":"Pi Web",n),l=(0,i.useCallback)(e=>{t(e),o(!0),setTimeout(()=>o(!1),(e?6:8)*4*(1e3/60)+100)},[]),d=(0,i.useCallback)(()=>{a.current&&clearTimeout(a.current);let t=!e;l(t),t&&(a.current=setTimeout(()=>l(!1),3e3))},[e,l]);return(0,i.useEffect)(()=>()=>{a.current&&clearTimeout(a.current)},[]),(0,r.jsx)("button",{onClick:d,style:{background:"none",border:"none",padding:0,cursor:"default",fontWeight:700,fontSize:15,letterSpacing:"-0.01em",color:e?"var(--accent)":"var(--text)",fontFamily:"var(--font-mono)",minWidth:"6ch"},children:s})}function ed({selectedSessionId:e,onSelectSession:t,onNewSession:n,initialSessionId:o,skipInitialProjectSelection:a,onInitialRestoreDone:s,refreshKey:l,onSessionDeleted:d,selectedCwd:p,onCwdChange:h,onOpenFile:g,explorerRefreshKey:x,onExplorerRefresh:f,onRefresh:b,onSessionsLoaded:y,onAtMention:j,onAtMentions:C,onBackgroundTaskDone:M,onRunningSessionIdsChange:I,onNewSessionFromTask:L,onOpenBoard:R,onOpenTaskBoard:E,onExitBoard:z,activeBoardId:W,activeWorktreeProject:P}){let{t:$}=(0,w.s)(),[N,D]=(0,i.useState)([]),[B,A]=(0,i.useState)([]),[q,V]=(0,i.useState)(!1),J=(0,i.useRef)(null),[K,Y]=(0,i.useState)(!0),[G,X]=(0,i.useState)(null),[Z,Q]=(0,i.useState)(null),[ea,ec]=(0,i.useState)(""),[eh,eg]=(0,i.useState)(!1),[ex,ew]=(0,i.useState)(!1),[ej,eS]=(0,i.useState)(""),[eC,eT]=(0,i.useState)(!1),[eM,eI]=(0,i.useState)(""),[eL,eR]=(0,i.useState)(null),[eE,ez]=(0,i.useState)(!1),[eW,eP]=(0,i.useState)(null),[e$,eN]=(0,i.useState)(null),eD=P??e$,eB=(0,i.useRef)(null),[eA,eF]=(0,i.useState)("sessions"),[eH,eO]=(0,i.useState)(!1),[eU,e_]=(0,i.useState)(!1),[eq,eV]=(0,i.useState)(!1),[eJ,eK]=(0,i.useState)(!1),[eY,eG]=(0,i.useState)([]),[eX,eZ]=(0,i.useState)(!1),[eQ,e0]=(0,i.useState)(0),[e1,e2]=(0,i.useState)(!1),[e4,e8]=(0,i.useState)(0),[e5,e6]=(0,i.useState)(!0),[e3,e7]=(0,i.useState)(!1),[e9,te]=(0,i.useState)(!1),[tt,tn]=(0,i.useState)(()=>new Set),[tr,ti]=(0,i.useState)(()=>new Set),to=(0,i.useRef)(new Set);(0,i.useEffect)(()=>{eF(function(){try{return"files"===window.localStorage.getItem(ef)?"files":"sessions"}catch{return"sessions"}}()),eO(ey(em)),e_(ey(ev)),eV(ey(eb)),ti(function(){try{let e=window.localStorage.getItem(en);if(!e)return new Set;let t=JSON.parse(e);if(Array.isArray(t))return new Set(t.filter(e=>"string"==typeof e));return new Set}catch{return new Set}}())},[]);let ta=(0,i.useRef)(!1),ts=(0,i.useRef)(null),tl=(0,i.useRef)(null),td=(0,i.useRef)(null),tc=(0,i.useRef)(null),tu=(0,i.useCallback)(async()=>{let e=J.current;if(!e)return;let t=tc.current;if(t&&t.key===e)return t.promise;let n=(async()=>{V(!0);try{let t=await fetch(`/api/sessions?project=${encodeURIComponent(e)}`,{cache:"no-store"});if(!t.ok)return;let n=await t.json();J.current===e&&(A(n.sessions??[]),ta.current||tn(new Set(n.runningSessionIds??[])))}catch{}finally{V(!1)}})();tc.current={key:e,promise:n};try{await n}finally{tc.current?.key===e&&(tc.current=null)}},[]),tp=(0,i.useCallback)(async(e=!1)=>{try{e&&Y(!0),await tu();let t=await fetch("/api/sessions",{cache:"no-store"});if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();D(n.sessions),y?.(n.sessions),ta.current||tn(new Set(n.runningSessionIds??[]));let r=new Set(n.sessions.map(e=>e.id));ti(e=>{if(0===e.size)return e;let t=new Set([...e].filter(e=>r.has(e)));return t.size===e.size?e:t}),X(null),e||(e7(!0),ts.current&&clearTimeout(ts.current),ts.current=setTimeout(()=>e7(!1),2e3))}catch(e){X(String(e))}finally{e&&Y(!1)}},[y,tu]);(0,i.useEffect)(()=>{try{0===tr.size?window.localStorage.removeItem(en):window.localStorage.setItem(en,JSON.stringify([...tr]))}catch{}},[tr]),(0,i.useEffect)(()=>{let e=!1,t=null,n=null,r=()=>{t&&clearTimeout(t),t=null},i=async()=>{if(e||"visible"!==document.visibilityState)return;let o=new AbortController;n?.abort(),n=o;try{let t=await fetch("/api/agent/running",{cache:"no-store",signal:o.signal});if(!t.ok)return;let r=await t.json();if(e||n!==o)return;ta.current=!0,tn(e=>{let t=new Set(r.runningSessionIds??[]);return e.size===t.size&&[...e].every(e=>t.has(e))?e:t})}catch{}finally{n===o&&(n=null),r(),e||"visible"!==document.visibilityState||(t=setTimeout(()=>void i(),2500))}},o=()=>{"visible"===document.visibilityState?i():(r(),n?.abort(),n=null)};return i(),document.addEventListener("visibilitychange",o),()=>{e=!0,r(),n?.abort(),document.removeEventListener("visibilitychange",o)}},[]),(0,i.useEffect)(()=>{I?.(tt)},[I,tt]),(0,i.useEffect)(()=>{let t=to.current,n=[...t].filter(t=>!tt.has(t)&&t!==e),r=[...tt].filter(e=>!t.has(e));(n.length>0||r.length>0)&&ti(e=>{let t=new Set(e);return tt.forEach(e=>t.delete(e)),n.forEach(e=>t.add(e)),t});let i=r.some(e=>!N.some(t=>t.id===e));(n.length>0||i)&&tp(!1),n.length>0&&M?.(n),to.current=tt},[tt,e,N,tp,M]),(0,i.useEffect)(()=>{e&&ti(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[e]),(0,i.useEffect)(()=>{void 0!==x&&e0(e=>e+1)},[x]),(0,i.useEffect)(()=>{fetch("/api/home").then(e=>e.json()).then(e=>{e.home&&ec(e.home)}).catch(()=>{})},[]);let th=(0,i.useRef)(!1),tg=(0,i.useCallback)((e,t)=>({root:e,key:t}),[]),tx=(0,i.useCallback)(e=>{if(!e)return null;if(eW?.cwd===e)return tg(eW.root,eW.key);if(eD&&(e===eD.projectRoot||eD.worktreePaths.includes(e)))return tg(eD.projectRoot,eD.projectKey);let t=N.find(t=>t.cwd===e||(t.projectRoot??t.cwd)===e);return t?tg(t.projectRoot??t.cwd,m(t)):tg(e,e)},[eW,eD,N,tg]),tf=(0,i.useRef)(null);(0,i.useEffect)(()=>{let e=tx(Z),t=tf.current;(t?.cwd!==Z||t.key!==(e?.key??null))&&(tf.current={cwd:Z,key:e?.key??null},h?.(Z,e?.root??null,e?.key??null))},[Z,h,tx]);let tm=(0,i.useRef)(null);(0,i.useEffect)(()=>{p&&p!==tm.current&&(tm.current=p,Q(p))},[p]),(0,i.useEffect)(()=>{if(0!==N.length&&!a&&null===Z){if(o&&!th.current){th.current=!0;let e=N.find(e=>e.id===o);if(e){Q(e.cwd),t(e,!0);return}s?.()}let e=v(N);e.length>0&&Q(e[0].root)}},[N,Z,o,a,t,s]);let tv=(0,i.useCallback)(async e=>{let t=(e??eM).trim();if(t&&!eE){ez(!0),eR(null);try{let e=await fetch("/api/cwd/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t})}),n=await e.json().catch(()=>({}));if(!e.ok||n.error||!n.cwd||!n.projectRoot||!n.projectKey)return void eR(n.error??`HTTP ${e.status}`);eP({cwd:n.cwd,root:n.projectRoot,key:n.projectKey}),Q(n.cwd),eT(!1),eI(""),eg(!1)}catch(e){eR(e instanceof Error?e.message:String(e))}finally{ez(!1)}}},[eM,eE]),tb=(0,i.useCallback)(()=>{eT(!0),eR(null),eg(!1)},[]),ty=(0,i.useCallback)(async()=>{try{let e=await fetch("/api/default-cwd",{method:"POST"}),t=await e.json();t.cwd&&(Q(t.cwd),eT(!1),eI(""),eR(null),eg(!1))}catch{}},[]);(0,i.useEffect)(()=>{let e=e=>{eB.current&&!eB.current.contains(e.target)&&(eg(!1),eS(""))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let tk=(0,i.useCallback)(e=>{e.cwd&&Q(e.cwd),t(e)},[t]),tw=(0,i.useCallback)(()=>{if(!Z)return;let e=(0,u.S)();n?.(e,Z)},[Z,n]),tj=v(N),tS=tj.length>8,tC=ej.trim()?tj.filter(e=>e.root.toLowerCase().includes(ej.trim().toLowerCase())):tj,tT=tx(Z);J.current=tT?.key??null;let tM=(0,i.useRef)(null);(0,i.useEffect)(()=>{let e=tT?.key??null;tM.current===e||(tM.current=e,e&&tu())},[tT?.key,tu]);let tI=(0,i.useMemo)(()=>(function(e,t,n){let r=new Map;for(let i of e){let e=m(i);if(!e)continue;let o=r.get(e);o||(o={running:0,unread:0},r.set(e,o)),t.has(i.id)&&o.running++,n.has(i.id)&&o.unread++}return r})(N,tt,tr),[N,tt,tr]),tL=(0,i.useMemo)(()=>[...tI.entries()].some(([e,{running:t,unread:n}])=>e!==tT?.key&&(t>0||n>0)),[tI,tT]),tR=(0,i.useRef)(0),tE=(0,i.useCallback)(()=>{let e=tT?.key,t=++tR.current;e?fetch(`/api/tasks?projectKey=${encodeURIComponent(e)}`,{cache:"no-store"}).then(e=>e.ok?e.json():null).then(e=>{t===tR.current&&eG(t=>es(t,Array.isArray(e?.tasks)?e.tasks:[]))}).catch(()=>{}):eG([])},[tT?.key]);(0,i.useEffect)(()=>{tE()},[tE]);let tz=(0,i.useRef)(!1),tW=(0,i.useRef)(null),tP=(0,i.useRef)(!1);(0,i.useEffect)(()=>{let e=!tz.current;if(tz.current=!0,e)return void tp(!0);if(tP.current){tP.current=!1,tp(!1),tE();return}return tW.current&&clearTimeout(tW.current),tW.current=setTimeout(()=>{tW.current=null,tp(!1),tE()},300),()=>{tW.current&&clearTimeout(tW.current)}},[tp,tE,l]);let t$=(0,i.useCallback)(async()=>{let e=tT?.key;if(!e)return;let t=await fetch(`/api/tasks?projectKey=${encodeURIComponent(e)}`,{cache:"no-store"}),n=await t.json().catch(()=>({}));eG(e=>es(e,Array.isArray(n.tasks)?n.tasks:[]))},[tT?.key]),tN=(0,i.useCallback)(async(e,t)=>{try{let n=await fetch(`/api/tasks/${encodeURIComponent(e)}?offset=${t}`,{cache:"no-store"});if(!n.ok)return;let r=(await n.json()).task;if(!r)return;eG(t=>t.map(t=>{if(t.id!==e)return t;let n=t.sessions??[],i=new Set(n.map(e=>e.id)),o=(r.sessions??[]).filter(e=>!i.has(e.id));return{...t,sessions:[...n,...o],sessionIds:[...t.sessionIds,...o.map(e=>e.id)],rootTotal:r.rootTotal??t.rootTotal,sessionTotal:r.sessionTotal??t.sessionTotal}}))}catch{}},[]),tD=(0,i.useCallback)((e,t)=>{D(n=>n.map(n=>n.id===e?{...n,pinned:!!t||void 0}:n));let n=n=>n.id===e?{...n,pinned:!!t||void 0}:n;A(e=>e.map(n)),eG(n=>n.map(n=>{if(!n.sessionIds.includes(e))return n;let r=new Set(n.pinnedSessionIds??[]);t?r.add(e):r.delete(e);let i=new Set(n.sessionIds.filter(e=>r.has(e))),o=n.sessionIds.filter(e=>!r.has(e));return{...n,pinnedSessionIds:[...r],sessionIds:[...i,...o],sessions:(n.sessions??[]).map(n=>n.id===e?{...n,pinned:!!t||void 0}:n)}})),fetch(`/api/sessions/${encodeURIComponent(e)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({pinned:t})}).catch(()=>{}).then(()=>{t$(),tu()})},[t$,tu]),tB=(0,i.useCallback)(e=>{let t=eY.find(t=>t.id===e);if(!t)return;let n=!t.pinned;eG(t=>{let r=t.map(t=>t.id===e?{...t,pinned:n}:t);return[...r.filter(e=>e.pinned),...r.filter(e=>!e.pinned)]}),fetch(`/api/tasks/${encodeURIComponent(e)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({pinned:n})}).catch(()=>{}).then(()=>t$())},[eY,t$]),tA=(0,i.useCallback)(e=>{let t=tT?.key;if(!t)return;let n=new Map(eY.map(e=>[e.id,e])),r=[],i=[];for(let t of e){let e=n.get(t);e&&(e.pinned?r:i).push(t)}eG(t=>{let n=new Map(e.map((e,t)=>[e,t]));return[...t].sort((e,t)=>{let r=n.get(e.id)??Number.MAX_SAFE_INTEGER,i=n.get(t.id)??Number.MAX_SAFE_INTEGER;return e.pinned!==t.pinned?e.pinned?-1:1:r-i})}),r.length>0&&fetch("/api/tasks/reorder",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({projectKey:t,orderedIds:r})}).catch(()=>{}),i.length>0&&fetch("/api/tasks/reorder",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({projectKey:t,orderedIds:i})}).catch(()=>{})},[eY,tT?.key]),tF=(0,i.useCallback)((e,t)=>{let n=n=>n.id===e?{...n,name:t}:n;D(e=>e.map(n)),A(e=>e.map(n)),eG(e=>e.map(e=>({...e,sessions:(e.sessions??[]).map(n)})))},[]);(0,i.useEffect)(()=>{let e=e=>{let t=e.detail;t?.sessionId&&t?.name&&tF(t.sessionId,t.name)};return window.addEventListener("pi-web:board-session-renamed",e),()=>window.removeEventListener("pi-web:board-session-renamed",e)},[tF]),(0,i.useEffect)(()=>{let e=e=>{let t=e.detail;t?.sessionId&&d?.(t.sessionId)};return window.addEventListener("pi-web:board-session-deleted",e),()=>window.removeEventListener("pi-web:board-session-deleted",e)},[d]);let tH=(0,i.useCallback)(async e=>{let t=tT?.key;t&&(await fetch("/api/tasks",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({projectKey:t,name:e})}),await t$())},[tT?.key,t$]),tO=(0,i.useCallback)(async(e,t)=>{await fetch(`/api/tasks/${encodeURIComponent(e)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t})}),await t$()},[t$]),tU=(0,i.useCallback)(async e=>{let t=await fetch(`/api/tasks/${encodeURIComponent(e)}`,{method:"DELETE"});for(let e of(await t.json().catch(()=>({}))).deletedSessionIds??[])d?.(e);await t$()},[t$,d]),t_=(0,i.useCallback)(async(e,t)=>{let n=eY.find(t=>t.id===e);if(!n||n.sessionIds.includes(t))return;let r=await fetch(`/api/tasks/${encodeURIComponent(e)}/assign-session`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:t})});r.ok||console.warn(`[sidebar] 会话归属失败 HTTP ${r.status} task=${e} session=${t}:`,await U(r)),await t$(),tu()},[eY,t$,tu]),tq=(0,i.useCallback)(async e=>{let t=eY.find(t=>t.sessionIds.includes(e));t&&(await fetch(`/api/tasks/${encodeURIComponent(t.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionIds:t.sessionIds.filter(t=>t!==e)})}),await t$(),tu())},[eY,t$,tu]),tV=e=>e.reduce((e,t)=>e+1+tV(t.children),0),tJ=(0,i.useMemo)(()=>eY.map(e=>{let t=(0,O.nJ)(eo(e.sessions??[])),n=e.sessionTotal??tV(t);return{task:e,nodes:t,sessionTotal:n}}),[eY]),tK=(0,i.useMemo)(()=>(0,O.nJ)(eo(B),tt),[B,tt]),tY=(0,i.useMemo)(()=>(0,O.IS)(tK,tt,Date.now(),k),[tK,tt]);return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[eC&&(0,r.jsx)(T.K,{busy:eE,error:eL,onCancel:()=>{eT(!1),eR(null)},onSelect:e=>void tv(e)}),(0,r.jsxs)("div",{style:{padding:"12px 10px 10px",flexShrink:0},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:10},children:[(0,r.jsx)(el,{}),(0,r.jsxs)("div",{style:{display:"flex",gap:2,alignItems:"center"},children:[(0,r.jsxs)("button",{onClick:tw,disabled:!Z,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,background:"transparent",border:"none",color:Z?"var(--text-muted)":"var(--text-dim)",cursor:Z?"pointer":"not-allowed",padding:"3px 6px",borderRadius:4,fontSize:12,fontWeight:500,letterSpacing:"-0.01em",flexShrink:0,textDecoration:"none",transition:"color 0.12s"},title:Z?$("sidebar.newSessionTitle",{path:Z}):$("sidebar.selectProject"),onMouseEnter:e=>{Z&&(e.currentTarget.style.color="var(--accent)",e.currentTarget.style.textDecoration="underline")},onMouseLeave:e=>{e.currentTarget.style.color=Z?"var(--text-muted)":"var(--text-dim)",e.currentTarget.style.textDecoration="none"},children:[(0,r.jsx)("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:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})}),$("sidebar.tempSessions")]}),(0,r.jsxs)("button",{onClick:()=>{b?(tP.current=!0,b()):(tp(!1),tE())},style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,background:e3?"rgba(74,222,128,0.12)":"transparent",border:"none",color:e3?"#4ade80":"var(--text-muted)",cursor:"pointer",padding:"3px 6px",borderRadius:4,fontSize:12,fontWeight:500,letterSpacing:"-0.01em",flexShrink:0,textDecoration:"none",transition:"color 0.3s, background 0.3s"},onMouseEnter:e=>{e3||(e.currentTarget.style.color="var(--accent)",e.currentTarget.style.textDecoration="underline")},onMouseLeave:e=>{e3||(e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.textDecoration="none")},title:$("sidebar.refresh"),children:[e3?(0,r.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"#4ade80",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,r.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),(0,r.jsx)("path",{d:"M3 3v5h5"})]}),$("sidebar.refresh")]})]})]}),(0,r.jsxs)("div",{ref:eB,style:{position:"relative",display:"flex",alignItems:"center",borderRadius:7,background:eh?"var(--side-active)":ex?"var(--side-hover)":Z?"color-mix(in srgb, var(--glass-bg-strong) 55%, transparent)":"color-mix(in srgb, var(--accent) 8%, transparent)",border:Z?"1px solid color-mix(in srgb, var(--border) 55%, transparent)":"1px solid color-mix(in srgb, var(--accent) 40%, transparent)",boxShadow:"inset 0 1px 0 color-mix(in srgb, var(--text) 4%, transparent)",transition:"border-color 0.15s, background 0.15s"},onMouseEnter:()=>ew(!0),onMouseLeave:()=>ew(!1),children:[(0,r.jsxs)("button",{onClick:()=>eg(e=>!e),title:tT?.root??Z??"",style:{flex:1,minWidth:0,display:"flex",alignItems:"center",padding:"6px 10px",background:"transparent",border:"none",borderRadius:0,cursor:"pointer",fontSize:12,color:"var(--text)",textAlign:"left",transition:"background 0.15s"},children:[Z?(0,r.jsx)(ei,{text:er(tT?.root??Z,ea),style:{flex:1,fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text)"}}):(0,r.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)"},children:o&&!th.current?"":$("sidebar.selectProject")}),tL&&(0,r.jsx)("span",{title:$("sidebar.newActivity"),"aria-label":$("sidebar.newActivity"),style:{width:8,height:8,borderRadius:"50%",flexShrink:0,marginLeft:6,background:"var(--accent)"}})]}),Z&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{"aria-hidden":!0,style:{flexShrink:0,width:1,alignSelf:"stretch",margin:"5px 0",background:"color-mix(in srgb, var(--border) 55%, transparent)"}}),(0,r.jsx)(c.J,{cwd:Z,onSelect:(e,t)=>{t&&eN(t),Q(e),eg(!1)},onOpenChange:e=>{e&&eg(!1)},showMainLabel:!1,compact:!0,style:{height:"auto",background:"transparent",flexShrink:0,borderRadius:0,maxWidth:85}})]}),(0,r.jsxs)(S.f,{open:eh,style:{position:"absolute",top:"calc(100% + 4px)",left:0,right:0,zIndex:100,background:"var(--popover-glass)",backdropFilter:"blur(var(--glass-blur-heavy)) saturate(var(--glass-saturate))",WebkitBackdropFilter:"blur(var(--glass-blur-heavy)) saturate(var(--glass-saturate))",border:"1px solid color-mix(in srgb, var(--border) 60%, transparent)",borderRadius:8,boxShadow:"0 6px 20px rgba(0,0,0,0.10)",overflow:"hidden"},children:[tS&&(0,r.jsx)("div",{style:{padding:"6px 8px",borderBottom:"1px solid var(--border)"},children:(0,r.jsx)("input",{value:ej,onChange:e=>eS(e.target.value),onKeyDown:e=>{"Escape"===e.key&&(eS(""),eg(!1))},placeholder:$("sidebar.filterProjects"),autoFocus:!0,style:{width:"100%",fontSize:11,fontFamily:"var(--font-mono)",padding:"5px 8px",border:"1px solid color-mix(in srgb, var(--border) 55%, transparent)",borderRadius:5,outline:"none",background:"var(--side-input)",color:"var(--text)",boxSizing:"border-box"}})}),(0,r.jsxs)("div",{style:{maxHeight:"min(50vh, 380px)",overflowY:"auto"},children:[tC.map(e=>{var t,n;return(0,r.jsxs)("button",{onClick:()=>{Q(e.root),eS(""),eT(!1),eI(""),eR(null),eg(!1)},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"transparent",border:"none",borderBottom:"1px solid var(--border)",color:e.key===tT?.key?"var(--text)":"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:e.root,onMouseEnter:e=>{e.currentTarget.style.background="var(--side-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[e.key===tT?.key&&(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},children:(0,r.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}),e.key!==tT?.key&&(0,r.jsx)("span",{style:{width:10,flexShrink:0}}),(0,r.jsx)(ei,{text:er(e.root,ea),style:{flex:1}}),(t=tI.get(e.key),n=$,t&&(0!==t.running||0!==t.unread)?(0,r.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:5,flexShrink:0,marginLeft:6},children:[t.running>0&&(0,r.jsxs)("span",{title:n("sidebar.agentRunning"),"aria-label":`${n("sidebar.agentRunning")} (${t.running})`,style:{display:"inline-flex",alignItems:"center",gap:3,color:"var(--accent)",fontSize:10,fontFamily:"var(--font-mono)"},children:[(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",style:{display:"block"},children:(0,r.jsxs)("g",{children:[(0,r.jsx)("path",{d:"M21 12a9 9 0 1 1-3.8-7.4",stroke:"currentColor",strokeWidth:"2.8",strokeLinecap:"round"}),(0,r.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.9s",repeatCount:"indefinite"})]})}),t.running]}),t.unread>0&&(0,r.jsxs)("span",{title:n("sidebar.newSessionActivity"),"aria-label":`${n("sidebar.newSessionActivity")} (${t.unread})`,style:{display:"inline-flex",alignItems:"center",gap:3,color:"#0891b2",fontSize:10,fontFamily:"var(--font-mono)"},children:[(0,r.jsx)("span",{style:{width:6,height:6,borderRadius:"50%",background:"currentColor",display:"inline-block"}}),t.unread]})]}):null)]},e.key)}),0===tC.length&&ej.trim()&&(0,r.jsx)("div",{style:{padding:"8px 10px",fontSize:11,color:"var(--text-dim)"},children:$("sidebar.noMatchingProjects")})]}),!eC&&(0,r.jsxs)("button",{onClick:e=>{e.stopPropagation(),ty()},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",borderTop:tC.length>0?"1px solid var(--border)":"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11},children:[(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.1",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,r.jsx)("path",{d:"M1 3A1 1 0 0 1 2 2H4L5 3.5H8.5a.5.5 0 0 1 .5.5v4a.5.5 0 0 1-.5.5h-7A.5.5 0 0 1 1 8V3Z"})}),(0,r.jsx)("span",{children:$("sidebar.useDefaultDirectory")})]}),(0,r.jsxs)("button",{onClick:e=>{e.stopPropagation(),tb()},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11},children:[(0,r.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.1",strokeLinecap:"round",style:{flexShrink:0},children:[(0,r.jsx)("line",{x1:"5",y1:"1",x2:"5",y2:"9"}),(0,r.jsx)("line",{x1:"1",y1:"5",x2:"9",y2:"5"})]}),(0,r.jsx)("span",{children:$("sidebar.customPath")})]})]})]})]}),(0,r.jsx)(H,{active:eA,runningCount:tt.size,onChange:e=>{eF(e),function(e){try{window.localStorage.setItem(ef,e)}catch{}}(e)}}),(0,r.jsx)("div",{style:{flex:1,minHeight:0,display:"sessions"===eA?"flex":"none",flexDirection:"column",overflowY:"auto",overflowX:"hidden"},children:K?(0,r.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:$("sidebar.loading")}):G?(0,r.jsx)("div",{style:{padding:"12px 14px",color:"#f87171",fontSize:12},children:G}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(_,{activeBoardId:W??null,collapsed:eH,refreshKey:l,onToggleCollapsed:()=>{let e=!eH;eO(e),ek(em,e)},onOpenBoard:e=>R?.(e),onExitBoard:z}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",minHeight:0,flex:"0 0 auto"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4,padding:"5px 6px 3px 10px"},children:[(0,r.jsxs)("button",{type:"button",onClick:()=>{let e=!eU;e_(e),ek(ev,e)},"aria-expanded":!eU,style:{display:"flex",alignItems:"center",gap:6,flex:1,minWidth:0,background:"none",border:"none",padding:0,textAlign:"left",cursor:"pointer",color:"var(--text-dim)"},children:[(0,r.jsx)("span",{style:{fontSize:11,fontWeight:600,letterSpacing:"0.02em"},children:$("sidebar.tasks")}),(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:eU?"rotate(-90deg)":"none",transition:"transform 0.15s"},"aria-hidden":"true",children:(0,r.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),(0,r.jsx)("button",{type:"button",onClick:()=>eK(e=>!e),title:$("sidebar.newTask"),"aria-label":$("sidebar.newTask"),style:{width:24,height:24,padding:0,display:"flex",alignItems:"center",justifyContent:"center",background:"none",border:"none",borderRadius:5,color:"var(--text-dim)",cursor:"pointer"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="var(--side-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)",e.currentTarget.style.background="transparent"},children:(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round","aria-hidden":"true",children:[(0,r.jsx)("line",{x1:"6",y1:"1",x2:"6",y2:"11"}),(0,r.jsx)("line",{x1:"1",y1:"6",x2:"11",y2:"6"})]})})]}),!eU&&(0,r.jsx)("div",{style:{overflowX:"hidden"},children:(0,r.jsx)(ee,{groups:tJ.map(({task:t,nodes:n,sessionTotal:i})=>{let o=n.filter(e=>e.session.pinned).length,a=n.length,s=t.rootTotal??a;return{task:t,sessionCount:a,pinnedCount:o,sessionTotal:i,hasMore:s>a,remainingCount:Math.max(0,s-a),onLoadMore:()=>tN(t.id,a-o),content:()=>{let i=new Set(t.pinnedSessionIds??[]),o=[];return n.forEach((t,a)=>{let s=i.has(t.session.id);if(a>0){let e=n[a-1];e&&i.has(e.session.id)&&!s&&o.push((0,r.jsx)("div",{style:{margin:"2px 6px 4px",height:1,background:"color-mix(in srgb, var(--border) 45%, transparent)"}},`pin-line-${a}`))}o.push((0,r.jsx)(ep,{node:t,selectedSessionId:e,runningSessionIds:tt,unreadSessionIds:tr,onSelectSession:tk,onRenamed:(e,t)=>tF(e,t),onSessionDeleted:e=>{d?.(e)},onTogglePin:tD,depth:0},t.session.id))}),(0,r.jsx)("div",{style:{paddingLeft:14,paddingBottom:2},children:o})}}}),selectedSessionId:e,activeBoardId:W,runningSessionIds:tt,newTaskOpen:eJ,onNewTaskOpenChange:eK,onNewTask:e=>void tH(e),onRenameTask:(e,t)=>void tO(e,t),onDeleteTask:e=>void tU(e),onNewSessionFromTask:e=>L?.(e,tT?.key??void 0),onToggleTaskPin:tB,onOpenTaskBoard:e=>E?.(e),onDropSessionToTask:(e,t)=>void t_(e,t),onReorderTasks:tA})})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",minHeight:0,flex:eq?"0 0 auto":"1 0 auto"},children:[(0,r.jsx)("div",{style:{display:"flex",alignItems:"center",padding:"5px 10px 3px"},children:(0,r.jsxs)("button",{type:"button",onClick:()=>{let e=!eq;eV(e),ek(eb,e)},"aria-expanded":!eq,style:{display:"flex",alignItems:"center",gap:6,flex:1,minWidth:0,background:"none",border:"none",padding:0,textAlign:"left",cursor:"pointer",color:"var(--text-dim)"},children:[(0,r.jsx)("span",{style:{fontSize:11,fontWeight:600,letterSpacing:"0.02em"},children:$("sidebar.tempSessions")}),(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:eq?"rotate(-90deg)":"none",transition:"transform 0.15s"},"aria-hidden":"true",children:(0,r.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]})}),!eq&&(0,r.jsxs)("div",{onDragOver:e=>{e.dataTransfer.types.includes("text/session-id")&&(e.preventDefault(),e.dataTransfer.dropEffect="move",eZ(!0))},onDragLeave:()=>eZ(!1),onDrop:e=>{e.preventDefault(),eZ(!1);let t=e.dataTransfer.getData("text/session-id"),n=(0,O.Fm)(e.dataTransfer.getData(O.il));t&&(0,O.GO)(n)&&tq(t)},style:{flex:1,minHeight:0,overflowY:"auto",overflowX:"hidden",background:eX?"color-mix(in srgb, var(--accent) 8%, transparent)":"transparent"},children:[tY.map(({node:t,header:n,pinDivider:i})=>(0,r.jsxs)("div",{children:[i&&(0,r.jsx)("div",{style:{margin:"2px 6px 4px",height:1,background:"color-mix(in srgb, var(--border) 45%, transparent)"}}),n&&(0,r.jsx)(eu,{group:n}),(0,r.jsx)(ep,{node:t,selectedSessionId:e,runningSessionIds:tt,unreadSessionIds:tr,onSelectSession:tk,onRenamed:(e,t)=>tF(e,t),onSessionDeleted:e=>{d?.(e)},onTogglePin:tD,depth:0})]},t.session.id)),0===tK.length&&0===tJ.length&&(0,r.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:$("sidebar.noSessions")}),tK.length>0&&(0,r.jsx)(r.Fragment,{children:q&&(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,padding:"6px 0",color:"var(--text-dim)",fontSize:11},children:[(0,r.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round","aria-hidden":"true",style:{flexShrink:0,animation:"spin 0.9s linear infinite"},children:(0,r.jsx)("path",{d:"M21 12a9 9 0 1 1-5.7-8.4"})}),(0,r.jsx)("span",{children:$("sidebar.loading")})]})})]})]})]})}),(0,r.jsx)("div",{style:{flex:1,display:"files"===eA?"flex":"none",flexDirection:"column",minHeight:0,overflow:"hidden"},children:(p||Z)&&(0,r.jsx)("div",{style:{borderTop:"1px solid var(--border)",display:"flex",flexDirection:"column",flex:"1 1 0",minHeight:0,overflow:"hidden"},children:(0,r.jsx)("div",{style:{flex:1,minHeight:0,display:"flex",flexDirection:"column",overflow:"hidden"},children:(0,r.jsx)(F,{ref:td,cwd:Z??p,onOpenFile:g??(()=>{}),refreshKey:eQ,onAtMention:j,onAtMentions:C,onUploadBusyChange:e2,changesCollapsed:e5,onChangesCountChange:e8,toolbar:(0,r.jsxs)(r.Fragment,{children:[e4>0&&(0,r.jsx)(et,{onClick:()=>e6(e=>!e),title:$("sidebar.changedFiles",{count:e4}),ariaPressed:!e5,color:e5?"var(--text-dim)":"var(--accent)",background:e5?"none":"var(--side-active)",children:(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:"3"}),(0,r.jsx)("path",{d:"M3 12h6"}),(0,r.jsx)("path",{d:"M15 12h6"})]})}),(0,r.jsx)(et,{onClick:()=>td.current?.openUploadPicker(),disabled:e1,title:$("sidebar.uploadFilesTitle"),color:"var(--text-dim)",children:(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)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,r.jsx)("path",{d:"m17 8-5-5-5 5"}),(0,r.jsx)("path",{d:"M12 3v12"})]})}),(0,r.jsx)(et,{onClick:()=>{f?f():e0(e=>e+1),te(!0),tl.current&&clearTimeout(tl.current),tl.current=setTimeout(()=>te(!1),2e3)},title:$("sidebar.refreshExplorer"),skipHover:e9,color:e9?"#4ade80":"var(--text-dim)",background:e9?"rgba(74,222,128,0.18)":"none",marginRight:0,children:e9?(0,r.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"#4ade80",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,r.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),(0,r.jsx)("path",{d:"M3 3v5h5"})]})})]})})})})})]})}let ec={today:"sidebar.timeToday",yesterday:"sidebar.timeYesterday",thisWeek:"sidebar.timeThisWeek",thisMonth:"sidebar.timeThisMonth",older:"sidebar.timeOlder"};function eu({group:e}){let{t}=(0,w.s)();return(0,r.jsx)("div",{style:{margin:0,padding:"7px 12px 2px",fontSize:10,fontWeight:600,letterSpacing:"0.06em",color:"var(--text-dim)",userSelect:"none"},children:t(ec[e])})}function ep({node:e,selectedSessionId:t,runningSessionIds:n,unreadSessionIds:o,onSelectSession:a,onRenamed:s,onSessionDeleted:l,onTogglePin:d,depth:c}){let[u,p]=(0,i.useState)(!1),h=e.children.length>0;return(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{style:{position:"relative"},children:[c>0&&(0,r.jsx)("div",{style:{position:"absolute",left:12*c+6,top:0,bottom:0,width:1,background:"var(--border)",pointerEvents:"none"}}),(0,r.jsx)(ex,{session:e.session,isSelected:e.session.id===t,isRunning:n.has(e.session.id),isUnread:o.has(e.session.id),onClick:()=>a(e.session),onRenamed:s,onDeleted:e=>l?.(e),onTogglePin:d,depth:c,hasChildren:h,collapsed:u,onToggleCollapse:()=>p(e=>!e)})]}),h&&!u&&(0,r.jsx)("div",{children:e.children.map(e=>(0,r.jsx)(ep,{node:e,selectedSessionId:t,runningSessionIds:n,unreadSessionIds:o,onSelectSession:a,onRenamed:s,onSessionDeleted:l,onTogglePin:d,depth:c+1},e.session.id))})]})}function eh(){let{t:e}=(0,w.s)();return(0,r.jsx)("span",{title:e("sidebar.agentRunning"),"aria-label":e("sidebar.agentRunning"),style:{width:14,height:14,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,color:"var(--accent)"},children:(0,r.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",style:{display:"block"},children:(0,r.jsxs)("g",{children:[(0,r.jsx)("path",{d:"M21 12a9 9 0 1 1-3.8-7.4",stroke:"currentColor",strokeWidth:"2.8",strokeLinecap:"round"}),(0,r.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.9s",repeatCount:"indefinite"})]})})})}function eg(){let{t:e}=(0,w.s)();return(0,r.jsx)("span",{title:e("sidebar.newActivity"),"aria-label":e("sidebar.newSessionActivity"),style:{width:14,height:14,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,color:"#0891b2"},children:(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",style:{display:"block"},children:[(0,r.jsx)("circle",{cx:"7",cy:"7",r:"2.5",fill:"currentColor"}),(0,r.jsxs)("circle",{cx:"7",cy:"7",r:"3",stroke:"currentColor",strokeWidth:"1.4",opacity:"0.32",children:[(0,r.jsx)("animate",{attributeName:"r",values:"3;6;3",dur:"1.6s",repeatCount:"indefinite"}),(0,r.jsx)("animate",{attributeName:"opacity",values:"0.32;0;0.32",dur:"1.6s",repeatCount:"indefinite"})]})]})})}function ex({session:e,isSelected:t,isRunning:n,isUnread:o,onClick:a,onRenamed:s,onDeleted:l,onTogglePin:d,depth:c=0,hasChildren:u=!1,collapsed:h=!1,onToggleCollapse:g}){let{t:x}=(0,w.s)(),f=(0,j.u)(),[m,v]=(0,i.useState)(!1),[b,y]=(0,i.useState)(!1),[k,T]=(0,i.useState)(""),[M,I]=(0,i.useState)(!1),[L,R]=(0,i.useState)(!1),[E,z]=(0,i.useState)(!1),[W,P]=(0,i.useState)(!1),[$,N]=(0,i.useState)(!1),D=(0,i.useRef)(null),B=(0,i.useRef)(null);(0,i.useEffect)(()=>{if(!W&&!M)return;let e=e=>{B.current&&!B.current.contains(e.target)&&(P(!1),I(!1))},t=e=>{"Escape"===e.key&&(P(!1),I(!1))};return document.addEventListener("pointerdown",e,!0),document.addEventListener("keydown",t),()=>{document.removeEventListener("pointerdown",e,!0),document.removeEventListener("keydown",t)}},[W,M]);let A=(0,i.useCallback)(e=>{if(e.stopPropagation(),W)return void P(!1);let t=e.currentTarget.getBoundingClientRect(),n=e.currentTarget.parentElement,r=null;for(;n;){let e=getComputedStyle(n);if("auto"===e.overflowY||"scroll"===e.overflowY||"overlay"===e.overflowY){r=n;break}n=n.parentElement}let i=r?r.getBoundingClientRect():{top:0,bottom:window.innerHeight},o=i.bottom-t.bottom,a=t.top-i.top;N(!(o>=114)&&(a>=114||a>o)),P(!0)},[W]);(0,i.useEffect)(()=>{if(b){let e=requestAnimationFrame(()=>D.current?.select());return()=>cancelAnimationFrame(e)}},[b]);let F=(0,p.d)(e.firstMessage),H=F?.command??e.firstMessage,U=e.name||H.slice(0,50)||e.id.slice(0,12),_=(0,i.useCallback)(t=>{t.stopPropagation(),e.transient||(P(!1),T(e.name||H.slice(0,50)||e.id.slice(0,12)),y(!0))},[e.name,e.transient,H,e.id]),q=(0,i.useCallback)(async()=>{let t=k.trim();if(y(!1),k!==U&&t!==(e.name??""))try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t})}),s?.(e.id,t)}catch{}},[k,e.id,e.name,s,U]),V=(0,i.useCallback)(async()=>{if(!e.transient){I(!1),z(!0);try{let t=await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"DELETE"});if(!t.ok)throw Error(`HTTP ${t.status}`);l?.(e.id)}catch{z(!1)}}},[e.id,e.transient,l]),J=(0,i.useCallback)(e=>{e.stopPropagation(),P(!1),R(!!B.current&&C(B.current,96)),I(!0)},[]),K=(0,i.useCallback)(e=>{e.stopPropagation(),V()},[V]),Y=(0,i.useCallback)(e=>{e.stopPropagation(),I(!1)},[]),G=(0,i.useCallback)(t=>{(function(e,t=window){let n=new CustomEvent("pi-web:session-row-contextmenu",{cancelable:!0,detail:e});return!t.dispatchEvent(n)})({id:e.id,path:e.path,cwd:e.cwd,name:e.name,clientX:t.clientX,clientY:t.clientY,refresh:()=>{s?.(e.id,e.name??"")}})&&(t.preventDefault(),t.stopPropagation())},[s,e.cwd,e.id,e.name,e.path]);return(0,r.jsx)("div",{onClick:M||b?void 0:a,onContextMenu:M||b?void 0:G,onMouseEnter:()=>v(!0),onMouseLeave:()=>{v(!1)},draggable:(0,O.y_)({renaming:b,confirmDelete:M}),onDragStart:t=>{P(!1),t.dataTransfer.setData("text/session-id",e.id),t.dataTransfer.setData("text/session-title",U),t.dataTransfer.setData(O.il,String(c)),t.dataTransfer.effectAllowed="move"},style:{height:36,display:"flex",alignItems:"center",paddingLeft:c>0?12*c+14:14,paddingRight:8,margin:"0 6px 1px",borderRadius:6,cursor:M||b?"default":"pointer",background:M?"color-mix(in srgb, #ef4444 7%, transparent)":t?"color-mix(in srgb, var(--accent) 8%, transparent)":m?"var(--side-hover)":"transparent",borderLeft:"2px solid transparent",transition:"background 0.1s",opacity:E?.5:1,gap:6},children:b?(0,r.jsx)("input",{ref:D,value:k,onChange:e=>T(e.target.value),onBlur:q,...f.compositionProps,onKeyDown:e=>{f.isIMEBusy(e)||("Enter"===e.key&&q(),"Escape"===e.key&&y(!1))},autoFocus:!0,style:{flex:1,fontSize:12,border:"none",outline:"none",background:"transparent",color:"var(--text)",boxSizing:"border-box",height:"100%",padding:0}}):(0,r.jsxs)(r.Fragment,{children:[c>0&&(0,r.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,r.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,r.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,r.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,r.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),(0,r.jsxs)("div",{style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:6},children:[e.pinned&&(0,r.jsx)("span",{title:x("sidebar.pinned"),style:{display:"inline-flex",flexShrink:0,color:"var(--accent)"},children:(0,r.jsxs)("svg",{width:"11",height:"11",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:"M12 17v5"}),(0,r.jsx)("path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V6h1a2 2 0 0 0 0-4H8a2 2 0 0 0 0 4h1z"})]})}),n?(0,r.jsx)(eh,{}):o?(0,r.jsx)(eg,{}):null,e.isWorktree&&e.branch&&(0,r.jsxs)("span",{title:`Worktree: ${e.cwd}`,style:{display:"flex",alignItems:"center",gap:3,color:"var(--accent)",minWidth:0,overflow:"hidden",flexShrink:0},children:[(0,r.jsxs)("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,r.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,r.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,r.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,r.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.branch})]}),(0,r.jsx)("span",{title:U,style:{flex:1,minWidth:0,fontSize:12,fontWeight:t?500:400,lineHeight:1.4,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:U})]}),m&&u&&!e.transient&&(0,r.jsx)("button",{onClick:e=>{e.stopPropagation(),g?.()},title:h?"Expand forks":"Collapse forks",style:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,flexShrink:0,background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",transform:h?"rotate(-90deg)":"none",transition:"transform 0.15s"},children:(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,r.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})}),(m||W||M)&&!e.transient&&(0,r.jsxs)("div",{ref:B,style:{position:"relative",display:"flex",gap:4,flexShrink:0,alignItems:"center"},children:[(0,r.jsx)("button",{onClick:_,title:x("sidebar.rename"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:"transparent",border:"1px solid transparent",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--side-active)",e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:(0,r.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,r.jsx)("path",{d:"M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"})})}),(0,r.jsx)("button",{onClick:A,"aria-expanded":W,"aria-haspopup":"menu",title:x("sidebar.moreActions"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:W?"var(--side-active)":"transparent",border:"1px solid transparent",borderRadius:7,color:W?"var(--accent)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{W||(e.currentTarget.style.background="var(--side-active)",e.currentTarget.style.color="var(--accent)")},onMouseLeave:e=>{W||(e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)")},children:(0,r.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"12",cy:"5",r:"1.4",fill:"currentColor"}),(0,r.jsx)("circle",{cx:"12",cy:"12",r:"1.4",fill:"currentColor"}),(0,r.jsx)("circle",{cx:"12",cy:"19",r:"1.4",fill:"currentColor"})]})}),(0,r.jsx)(S.f,{open:W,up:$,style:{position:"absolute",top:$?"auto":"calc(100% + 4px)",bottom:$?"calc(100% + 4px)":"auto",right:0,zIndex:120,minWidth:148,background:"var(--popover-glass)",backdropFilter:"blur(var(--glass-blur-heavy)) saturate(var(--glass-saturate))",WebkitBackdropFilter:"blur(var(--glass-blur-heavy)) saturate(var(--glass-saturate))",border:"1px solid color-mix(in srgb, var(--border) 60%, transparent)",borderRadius:9,boxShadow:"0 8px 24px rgba(0,0,0,0.12)",padding:4},children:(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:1},role:"menu",children:[(0,r.jsxs)("button",{role:"menuitem",onClick:t=>{t.stopPropagation(),P(!1),d?.(e.id,!e.pinned)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 10px",border:"none",borderRadius:6,background:"transparent",color:e.pinned?"var(--accent)":"var(--text)",cursor:"pointer",fontSize:12,textAlign:"left",transition:"background 0.1s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--side-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,r.jsx)("path",{d:"M12 17v5"}),(0,r.jsx)("path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V6h1a2 2 0 0 0 0-4H8a2 2 0 0 0 0 4h1z"})]}),x(e.pinned?"sidebar.unpin":"sidebar.pin")]}),(0,r.jsxs)("button",{role:"menuitem",onClick:e=>{e.stopPropagation(),P(!1),_(e)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 10px",border:"none",borderRadius:6,background:"transparent",color:"var(--text)",cursor:"pointer",fontSize:12,textAlign:"left",transition:"background 0.1s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--side-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[(0,r.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,r.jsx)("path",{d:"M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"})}),x("sidebar.rename")]}),(0,r.jsxs)("button",{role:"menuitem",onClick:e=>{e.stopPropagation(),P(!1),J(e)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 10px",border:"none",borderRadius:6,background:"transparent",color:"#ef4444",cursor:"pointer",fontSize:12,textAlign:"left",transition:"background 0.1s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.10)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,r.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,r.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,r.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,r.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]}),x("sidebar.delete")]})]})}),M&&(0,r.jsxs)("div",{role:"alertdialog",style:{position:"absolute",...L?{bottom:"calc(100% + 4px)"}:{top:"calc(100% + 4px)"},right:0,zIndex:121,width:224,boxSizing:"border-box",padding:10,display:"flex",flexDirection:"column",gap:8,background:"var(--popover-glass)",backdropFilter:"blur(var(--glass-blur-heavy)) saturate(var(--glass-saturate))",WebkitBackdropFilter:"blur(var(--glass-blur-heavy)) saturate(var(--glass-saturate))",border:"1px solid color-mix(in srgb, var(--border) 60%, transparent)",borderRadius:9,boxShadow:"0 8px 24px rgba(0,0,0,0.12)"},children:[(0,r.jsx)("div",{style:{fontSize:12,lineHeight:1.5,color:"var(--text)"},children:x("sidebar.deleteSession",{title:U.slice(0,30)+(U.length>30?"…":"")})}),(0,r.jsxs)("div",{style:{display:"flex",gap:6,justifyContent:"flex-end"},children:[(0,r.jsx)("button",{onClick:K,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,height:26,padding:"0 10px",background:"color-mix(in srgb, #ef4444 12%, transparent)",border:"none",borderRadius:5,color:"#ef4444",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:x("sidebar.delete")}),(0,r.jsx)("button",{onClick:Y,style:{display:"flex",alignItems:"center",justifyContent:"center",height:26,padding:"0 10px",background:"var(--side-input)",border:"1px solid color-mix(in srgb, var(--border) 55%, transparent)",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:500,whiteSpace:"nowrap"},children:x("sidebar.cancel")})]})]})]})]})})}let ef="pi-sidebar-tab",em="pi-sidebar-boards-collapsed",ev="pi-sidebar-tasks-collapsed",eb="pi-sidebar-chat-collapsed";function ey(e){try{return"1"===window.localStorage.getItem(e)}catch{return!1}}function ek(e,t){try{t?window.localStorage.setItem(e,"1"):window.localStorage.removeItem(e)}catch{}}var ew=n(92726),ej=n(32316);function eS({item:e,zIndex:t,active:n,onClose:o,onActivate:a,onMove:s}){let l=(0,i.useRef)(null),d=(0,i.useRef)(null),[c,u]=(0,i.useState)(!1);(0,i.useEffect)(()=>{let t=l.current;if(!t)return;let n=n=>{if(n.target.closest("[data-pin-content]"))return;n.preventDefault();let r=Math.exp(-(.0015*(1===n.deltaMode?16*n.deltaY:2===n.deltaMode?100*n.deltaY:n.deltaY))),i=window.innerWidth,o=window.innerHeight,a=e.h??t.offsetHeight,l=Math.min(Math.max(180,e.w*r),.92*i),d=Math.min(Math.max(80,a*r),.9*o);if(l===e.w&&d===a)return;let c=(n.clientX-e.x)/e.w,u=(n.clientY-e.y)/a,p=Math.min(Math.max(0,Math.round(n.clientX-c*l)),Math.max(0,i-l)),h=Math.min(Math.max(0,Math.round(n.clientY-u*d)),Math.max(0,o-d));s(e.id,{w:Math.round(l),h:Math.round(d),x:p,y:h})};return t.addEventListener("wheel",n,{passive:!1}),()=>t.removeEventListener("wheel",n)},[e.w,e.x,e.y,e.h,e.id,s]),(0,i.useEffect)(()=>()=>{document.body.style.cursor="",document.body.style.userSelect=""},[]);let p=(t,n)=>{if("mouse"===n.pointerType&&0!==n.button)return;n.preventDefault(),n.stopPropagation(),a(e.id);let r=l.current;r&&(r.setPointerCapture(n.pointerId),d.current={mode:t,pointerId:n.pointerId,startX:n.clientX,startY:n.clientY,origX:e.x,origY:e.y,origW:e.w,origH:e.h??r.offsetHeight},document.body.style.cursor="move"===t?"grabbing":"nwse-resize",document.body.style.userSelect="none")},h=t=>{let n=d.current;if(!n||n.pointerId!==t)return;d.current=null,document.body.style.cursor="",document.body.style.userSelect="";let r=l.current;if(!r)return;let i=Number.parseFloat(r.style.left),o=Number.parseFloat(r.style.top);"move"!==n.mode||Number.isNaN(i)||Number.isNaN(o)||s(e.id,{x:i,y:o})},g=t=>{let n=d.current,r=l.current;if(!n||!r||n.pointerId!==t.pointerId)return;if("mouse"===t.pointerType&&0===t.buttons)return void h(t.pointerId);t.preventDefault();let i=window.innerWidth,o=window.innerHeight;if("move"===n.mode){let a=Math.max(0,i-e.w),s=Math.max(0,o-r.offsetHeight),l=Math.min(a,Math.max(0,n.origX+t.clientX-n.startX)),d=Math.min(s,Math.max(0,n.origY+t.clientY-n.startY));r.style.left=`${l}px`,r.style.top=`${d}px`}else{let r=Math.max(180,i-n.origX),a=Math.max(80,o-n.origY),l=Math.min(r,Math.max(180,n.origW+t.clientX-n.startX)),d=Math.min(a,Math.max(80,n.origH+t.clientY-n.startY));s(e.id,{w:Math.round(l),h:Math.round(d)})}},x=e=>{h(e.pointerId);try{l.current?.releasePointerCapture(e.pointerId)}catch{}};return(0,r.jsxs)("div",{ref:l,"data-pin-bubble":!0,tabIndex:0,onPointerDown:t=>{if("mouse"===t.pointerType&&0!==t.button)return;let n=t.target,r=l.current?.querySelector("[data-pin-content]"),i=r?.querySelector(".markdown-body");n.closest(".markdown-body")&&n!==r&&n!==i?a(e.id):p("move",t)},onPointerMove:g,onPointerUp:x,onMouseEnter:()=>u(!0),onMouseLeave:()=>u(!1),style:{position:"fixed",left:e.x,top:e.y,width:e.w,height:e.h??"auto",zIndex:t,display:"flex",flexDirection:"column",background:"var(--assistant-card-glass)",backdropFilter:"blur(var(--glass-blur-bubble)) saturate(var(--glass-saturate))",WebkitBackdropFilter:"blur(var(--glass-blur-bubble)) saturate(var(--glass-saturate))",border:"1px solid var(--bubble-border)",borderRadius:"var(--bubble-radius)",boxShadow:n?"0 0 0 1px color-mix(in srgb, var(--accent) 35%, transparent), 0 0 18px 2px color-mix(in srgb, var(--accent) 22%, transparent), 0 8px 30px rgba(0,0,0,0.35)":"0 0 0 1px color-mix(in srgb, var(--border) 30%, transparent), 0 0 14px 1px color-mix(in srgb, var(--text-muted) 14%, transparent), 0 8px 30px rgba(0,0,0,0.3)",color:"var(--text)",fontSize:13,lineHeight:1.5,overflow:"hidden",colorScheme:"dark",padding:14,cursor:"grab",touchAction:"none"},children:[(0,r.jsx)("div",{"data-pin-content":!0,style:{flex:1,minHeight:0,overflowY:e.h?"auto":"visible",userSelect:"text",cursor:"text",wordBreak:"break-word"},children:e.content.trim()?(0,r.jsx)("div",{className:"markdown-body",children:(0,r.jsx)(ej.oz,{children:e.content})}):(0,r.jsx)("div",{style:{color:"var(--text-muted)",fontSize:12},children:"(空内容)"})}),(0,r.jsx)("button",{"data-pin-close":!0,onPointerDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),o(e.id)},title:"关闭",style:{position:"absolute",top:4,right:4,width:22,height:22,display:"flex",alignItems:"center",justifyContent:"center",padding:0,border:"none",borderRadius:6,background:"color-mix(in srgb, var(--bg-panel) 70%, transparent)",color:"var(--text-muted)",cursor:"pointer",opacity:+!!c,transition:"opacity 0.12s",boxShadow:"0 1px 3px rgba(0,0,0,0.2)"},children:(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[(0,r.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,r.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}),(0,r.jsx)("div",{"data-pin-resize":!0,onPointerDown:e=>p("resize",e),onPointerMove:g,onPointerUp:x,style:{position:"absolute",right:0,bottom:0,width:20,height:20,cursor:"nwse-resize",touchAction:"none"},"aria-label":"调整大小",children:(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-muted)",strokeWidth:"2",strokeLinecap:"round",style:{position:"absolute",right:3,bottom:3,pointerEvents:"none",opacity:.8},children:[(0,r.jsx)("path",{d:"M14 20 20 14"}),(0,r.jsx)("path",{d:"M14 14 20 20"}),(0,r.jsx)("path",{d:"M8 20 20 8"})]})})]})}var eC=n(44051),eT=n(84876),eM=n(50640),eI=n(65063),eL=n(7644),eR=n(96793);let eE={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"},ez={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"},eW={mp4:"video/mp4",m4v:"video/mp4",webm:"video/webm",mov:"video/quicktime",ogv:"video/ogg"};function eP(e){return(e.replace(/\\/g,"/").split("/").pop()??"").toLowerCase().split(".").pop()??""}var e$=n(19870),eN=n(73620);let eD=/^(?:\uFEFF)?---[ \t]*(?:\r\n|\n|\r)/;function eB(e){return function e(t,n){if(null==t)return"";if("string"==typeof t)return t;if("number"==typeof t||"boolean"==typeof t)return String(t);if(Array.isArray(t)){if(n.has(t))return"[Circular]";n.add(t);try{return t.map(t=>e(t,n)).filter(Boolean).join(", ")}finally{n.delete(t)}}if("object"==typeof t)try{return JSON.stringify(t)??Object.prototype.toString.call(t)}catch{return Object.prototype.toString.call(t)}return String(t)}(e,new WeakSet)}var eA=n(68925),eF=n(40233);let eH=["tags","categories","keywords","tag","category"];function eO({data:e}){var t;if(!e)return null;let n=Object.entries(e);if(0===n.length)return null;let i="string"==typeof(t=e.title)?t.trim()||null:"number"==typeof t||"boolean"==typeof t?String(t):null,o=eH.find(t=>Array.isArray(e[t])),a=o?e[o].map(eB).filter(Boolean):[],s=n.filter(([e])=>e!==o&&("title"!==e||!i));return(0,r.jsxs)("div",{className:"markdown-frontmatter",children:[i&&(0,r.jsx)("div",{className:"markdown-frontmatter-title",children:i}),a.length>0&&(0,r.jsx)("div",{className:"markdown-frontmatter-tags",children:a.map((e,t)=>(0,r.jsx)("span",{className:"markdown-frontmatter-tag",children:e},`${e}-${t}`))}),s.length>0&&(0,r.jsx)("dl",{className:"markdown-frontmatter-rows",children:s.map(([e,t])=>(0,r.jsxs)("div",{className:"markdown-frontmatter-row",children:[(0,r.jsx)("dt",{children:e}),(0,r.jsx)("dd",{children:function(e){let t=eB(e);return t?"string"==typeof e&&/^(https?:\/\/|mailto:)/i.test(e)?(0,r.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:t}):t:null}(t)})]},e))})]})}var eU=n(82490);let e_={source:"Source",preview:"Preview",diff:"Diff"},eq={fontFamily:"var(--font-mono)",fontSize:13,lineHeight:1.6},eV={width:48,minWidth:48,padding:"0 10px",textAlign:"right",color:"var(--text-dim)",background:"var(--file-panel-gutter)",borderRight:"1px solid var(--border)",fontFamily:"var(--font-mono)",fontSize:11,fontStyle:"normal",fontVariantNumeric:"tabular-nums",lineHeight:"20.8px",userSelect:"none",flexShrink:0,verticalAlign:"top"};function eJ(){return(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"4"}),(0,r.jsx)("path",{d:"M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8"})]})}function eK(e){let t=e.nodeType===Node.ELEMENT_NODE?e:e.parentElement;return t?.closest(".file-source-line[data-line-number]")??null}function eY(e,t){if(!t||t.isCollapsed||0===t.rangeCount)return null;let n=t.getRangeAt(0);if(!e.contains(n.startContainer)||!e.contains(n.endContainer))return null;let r=eK(n.startContainer),i=eK(n.endContainer);if(!r||!i||!e.contains(r)||!e.contains(i))return null;let o=Number(r.dataset.lineNumber),a=Number(i.dataset.lineNumber);if(!Number.isInteger(o)||!Number.isInteger(a))return null;if(o<a){let e=r.querySelector(".file-source-line-content");if(e?.contains(n.startContainer)){let t=document.createRange();if(t.selectNodeContents(e),t.setStart(n.startContainer,n.startOffset),0===t.toString().length){let e=r.nextElementSibling;e instanceof HTMLElement&&e.matches(".file-source-line[data-line-number]")&&(o=Number((r=e).dataset.lineNumber))}}let t=i.querySelector(".file-source-line-content");if(t?.contains(n.endContainer)){let e=document.createRange();if(e.selectNodeContents(t),e.setEnd(n.endContainer,n.endOffset),0===e.toString().length){let e=i.previousElementSibling;e instanceof HTMLElement&&e.matches(".file-source-line[data-line-number]")&&(a=Number((i=e).dataset.lineNumber))}}}return o>a?null:{startLine:o,endLine:a}}function eG({rows:e,stylesheet:t,useInlineStyles:n,wrapLines:i}){return e.map((e,o)=>{let a=e.children??[],s=a[0]?.properties?.className,l=Array.isArray(s)&&s.includes("react-syntax-highlighter-line-number"),d=l?a[0]:null,c=l?a.slice(1):a;return(0,r.jsxs)("span",{className:"file-source-line","data-line-number":o+1,style:{display:"flex",minWidth:"100%"},children:[d&&(0,eM.Ay)({node:d,stylesheet:t,useInlineStyles:n,key:`source-line-number-${o}`}),(0,r.jsx)("span",{className:"file-source-line-content",style:{flex:"1 1 auto",minWidth:0,overflowWrap:i?"anywhere":"normal",whiteSpace:i?"pre-wrap":"pre"},children:c.map((e,r)=>(0,eM.Ay)({node:e,stylesheet:t,useInlineStyles:n,key:`source-token-${o}-${r}`}))})]},`source-line-${o}`)})}function eX(e,t,n,r={}){let i=(0,I.HG)(e),o=new URLSearchParams({type:t});for(let[e,t]of(n&&o.set("sessionId",n),Object.entries(r)))void 0!==t&&o.set(e,String(t));return`/api/files/${i}?${o.toString()}`}function eZ({filePath:e,sourceSessionId:t}){let{t:n}=(0,w.s)();return(0,r.jsx)("a",{href:eX(e,"download",t),download:(0,I.WP)(e),title:n("i18n.downloadFile"),"aria-label":n("i18n.downloadFile"),className:"file-viewer-icon-button",children:(0,r.jsxs)("svg",{width:"14",height:"14",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:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,r.jsx)("polyline",{points:"7 10 12 15 17 10"}),(0,r.jsx)("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})})}function eQ(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function e0({patch:e}){let t,{t:n}=(0,w.s)(),i=(t=(0,eU.y)(e))?t.flatMap(e=>e.rows.flatMap(e=>{if("hunk"===e.type)return[];if("context"===e.left.type&&"context"===e.right.type)return[{type:"unchanged",text:e.right.text,oldLineNo:e.left.lineNo,newLineNo:e.right.lineNo}];let t=[];return"removed"===e.left.type&&t.push({type:"removed",text:e.left.text,oldLineNo:e.left.lineNo,newLineNo:null}),"added"===e.right.type&&t.push({type:"added",text:e.right.text,oldLineNo:null,newLineNo:e.right.lineNo}),t})):[];if(!i.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:n("i18n.noChanges")});let o=new Set(i.flatMap((e,t)=>"unchanged"!==e.type?[t]:[])),a=new Set;for(let e of o)for(let t=Math.max(0,e-3);t<=Math.min(i.length-1,e+3);t++)a.add(t);let s=[],l=0;for(;l<i.length;)if(a.has(l)){let e=[];for(;l<i.length&&a.has(l);)e.push(i[l]),l++;s.push({hidden:!1,lines:e})}else{let e=0;for(;l<i.length&&!a.has(l);)e++,l++;s.push({hidden:!0,count:e})}return(0,r.jsx)("div",{className:"file-diff-view",style:{width:"max-content",minWidth:"100%",...eq},children:s.map((e,t)=>{if(e.hidden)return(0,r.jsxs)("div",{style:{padding:"2px 16px",color:"var(--text-dim)",background:"var(--file-panel-gutter)",fontSize:11,borderTop:"1px solid var(--border)",borderBottom:"1px solid var(--border)"},children:["... ",e.count," unchanged lines ..."]},t);let n=e.lines.map((e,t)=>{let n="added"===e.type?"rgba(0,200,80,0.12)":"removed"===e.type?"rgba(240,60,60,0.14)":"transparent",i="added"===e.type?"+":"removed"===e.type?"-":" ",o="added"===e.type?"#4ade80":"removed"===e.type?"#f87171":"var(--text-dim)";return(0,r.jsxs)("div",{className:"file-diff-line",style:{display:"flex",minWidth:"100%",background:n,borderLeft:"added"===e.type?"3px solid #4ade80":"removed"===e.type?"3px solid #f87171":"3px solid transparent"},children:[(0,r.jsx)("span",{style:eV,children:"removed"===e.type?e.oldLineNo:e.newLineNo}),(0,r.jsx)("span",{style:{minWidth:16,padding:"0 6px",color:o,userSelect:"none",flexShrink:0,fontWeight:600},children:i}),(0,r.jsx)("span",{className:"file-diff-line-content",style:{flexShrink:0,padding:"0 8px 0 0",whiteSpace:"pre",color:"var(--text)"},children:e.text||"\xa0"})]},t)});return(0,r.jsx)("div",{children:n},t)})})}function e1({filePath:e,cwd:t,sourceSessionId:n,watchEnabled:o=!0}){let{t:a}=(0,w.s)(),[s,l]=(0,i.useState)(!1),[d,c]=(0,i.useState)(0),[u,p]=(0,i.useState)(null),[h,g]=(0,i.useState)(null),[x,f]=(0,i.useState)(null),m=(0,i.useRef)(null),v=(0,i.useRef)(0),b=(0,I.WP)(e).toLowerCase().split(".").pop()??"";(0,i.useEffect)(()=>{c(0),p(null),g(null),f(null),l(!1)},[e,n]),(0,i.useEffect)(()=>{if(l(!1),m.current&&(m.current.close(),m.current=null),!o)return;let t=!0,r=new EventSource(eX(e,"watch",n));m.current=r,r.addEventListener("connected",()=>{let r;l(!0),r=++v.current,fetch(eX(e,"meta",n)).then(e=>e.json()).then(e=>{if(t&&r===v.current){if(e.error)return void f(e.error);"number"==typeof e.size&&p(e.size),g(null),f(null),c(e=>e+1)}}).catch(e=>{t&&r===v.current&&f(String(e))})}),r.addEventListener("change",e=>{v.current+=1;try{let t=JSON.parse(e.data);"number"==typeof t.size&&p(t.size)}catch{}g(null),f(null),c(e=>e+1)});let i=()=>{l(!1)};return r.addEventListener("error",i),r.onerror=i,()=>{t=!1,r.close(),m.current===r&&(m.current=null)}},[e,n,o]);let y=eX(e,"read",n,d?{v:d}:void 0),k=null!=u?eQ(u):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(--file-panel-chrome)",flexShrink:0},children:[(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)"},title:e,children:(0,I.qP)(e,t)}),(0,r.jsx)("span",{style:{marginLeft:"auto"},children:b||"image"}),h&&(0,r.jsxs)("span",{children:[h.w," \xd7 ",h.h]}),k&&(0,r.jsx)("span",{children:k}),(0,r.jsxs)("span",{title:a(s?"i18n.liveSync":"i18n.notWatching"),style:{display:"flex",alignItems:"center",gap:4,color:s?"#4ade80":"var(--text-dim)"},children:[(0,r.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:s?"#4ade80":"var(--border)",display:"inline-block",boxShadow:s?"0 0 4px #4ade80":"none"}}),s?"live":"static"]}),(0,r.jsx)(eZ,{filePath:e,sourceSessionId:n})]}),(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:x?(0,r.jsx)("div",{style:{color:"#f87171",fontSize:13},children:x}):(0,r.jsx)("img",{src:y,alt:e,onLoad:e=>{let t=e.currentTarget;g({w:t.naturalWidth,h:t.naturalHeight})},onError:()=>f("Failed to load image"),style:{maxWidth:"100%",maxHeight:"100%",objectFit:"contain",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"}})})]})}function e2(e){if(!Number.isFinite(e))return"";let t=Math.round(e),n=Math.floor(t/60);return`${n}:${String(t%60).padStart(2,"0")}`}function e4({filePath:e,cwd:t,sourceSessionId:n,watchEnabled:o=!0}){let{t:a}=(0,w.s)(),[s,l]=(0,i.useState)(!1),[d,c]=(0,i.useState)(0),[u,p]=(0,i.useState)(null),[h,g]=(0,i.useState)(null),[x,f]=(0,i.useState)(null),m=(0,i.useRef)(null),v=(0,i.useRef)(0),b=(0,I.WP)(e).toLowerCase().split(".").pop()??"";(0,i.useEffect)(()=>{c(0),p(null),g(null),f(null),l(!1)},[e,n]),(0,i.useEffect)(()=>{if(l(!1),m.current&&(m.current.close(),m.current=null),!o)return;let t=!0,r=new EventSource(eX(e,"watch",n));m.current=r,r.addEventListener("connected",()=>{let r;l(!0),r=++v.current,fetch(eX(e,"meta",n)).then(e=>e.json()).then(e=>{if(t&&r===v.current){if(e.error)return void f(e.error);"number"==typeof e.size&&p(e.size),g(null),f(null),c(e=>e+1)}}).catch(e=>{t&&r===v.current&&f(String(e))})}),r.addEventListener("change",e=>{v.current+=1;try{let t=JSON.parse(e.data);"number"==typeof t.size&&p(t.size)}catch{}g(null),f(null),c(e=>e+1)});let i=()=>{l(!1)};return r.addEventListener("error",i),r.onerror=i,()=>{t=!1,r.close(),m.current===r&&(m.current=null)}},[e,n,o]);let y=eX(e,"read",n,d?{v:d}: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(--file-panel-chrome)",flexShrink:0},children:[(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)"},title:e,children:(0,I.qP)(e,t)}),(0,r.jsx)("span",{style:{marginLeft:"auto"},children:b||"audio"}),null!=h&&(0,r.jsx)("span",{children:e2(h)}),null!=u&&(0,r.jsx)("span",{children:eQ(u)}),(0,r.jsxs)("span",{title:a(s?"i18n.liveSync":"i18n.notWatching"),style:{display:"flex",alignItems:"center",gap:4,color:s?"#4ade80":"var(--text-dim)"},children:[(0,r.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:s?"#4ade80":"var(--border)",display:"inline-block",boxShadow:s?"0 0 4px #4ade80":"none"}}),s?"live":"static"]}),(0,r.jsx)(eZ,{filePath:e,sourceSessionId:n})]}),(0,r.jsx)("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",padding:24,background:"transparent"},children:(0,r.jsxs)("div",{style:{width:"min(680px, 100%)"},children:[x&&(0,r.jsx)("div",{style:{color:"#f87171",fontSize:13,marginBottom:12,textAlign:"center"},children:x}),(0,r.jsx)("audio",{controls:!0,preload:"metadata",src:y,onLoadedMetadata:e=>g(e.currentTarget.duration),onError:()=>f("Failed to load audio"),style:{width:"100%"}},y)]})})]})}function e8({filePath:e,cwd:t,sourceSessionId:n,watchEnabled:o=!0}){let{t:a}=(0,w.s)(),[s,l]=(0,i.useState)(!1),[d,c]=(0,i.useState)(0),[u,p]=(0,i.useState)(null),[h,g]=(0,i.useState)(null),[x,f]=(0,i.useState)(null),m=(0,i.useRef)(null),v=(0,i.useRef)(0),b=(0,I.WP)(e).toLowerCase().split(".").pop()??"";(0,i.useEffect)(()=>{c(0),p(null),g(null),f(null),l(!1)},[e,n]),(0,i.useEffect)(()=>{if(l(!1),m.current&&(m.current.close(),m.current=null),!o)return;let t=!0,r=new EventSource(eX(e,"watch",n));m.current=r,r.addEventListener("connected",()=>{let r;l(!0),r=++v.current,fetch(eX(e,"meta",n)).then(e=>e.json()).then(e=>{if(t&&r===v.current){if(e.error)return void f(e.error);"number"==typeof e.size&&p(e.size),g(null),f(null),c(e=>e+1)}}).catch(e=>{t&&r===v.current&&f(String(e))})}),r.addEventListener("change",e=>{v.current+=1;try{let t=JSON.parse(e.data);"number"==typeof t.size&&p(t.size)}catch{}g(null),f(null),c(e=>e+1)});let i=()=>{l(!1)};return r.addEventListener("error",i),r.onerror=i,()=>{t=!1,r.close(),m.current===r&&(m.current=null)}},[e,n,o]);let y=eX(e,"read",n,d?{v:d}: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:(0,I.qP)(e,t)}),(0,r.jsx)("span",{style:{marginLeft:"auto"},children:b||"video"}),null!=h&&(0,r.jsx)("span",{children:e2(h)}),null!=u&&(0,r.jsx)("span",{children:eQ(u)}),(0,r.jsxs)("span",{title:a(s?"i18n.liveSync":"i18n.notWatching"),style:{display:"flex",alignItems:"center",gap:4,color:s?"#4ade80":"var(--text-dim)"},children:[(0,r.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:s?"#4ade80":"var(--border)",display:"inline-block",boxShadow:s?"0 0 4px #4ade80":"none"}}),s?"live":"static"]}),(0,r.jsx)(eZ,{filePath:e,sourceSessionId:n})]}),(0,r.jsx)("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",padding:24,background:"var(--bg-panel)",minHeight:0},children:(0,r.jsxs)("div",{style:{width:"min(960px, 100%)",height:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:0},children:[x&&(0,r.jsx)("div",{style:{color:"#f87171",fontSize:13,marginBottom:12,textAlign:"center"},children:x}),(0,r.jsx)("video",{controls:!0,preload:"metadata",src:y,onLoadedMetadata:e=>g(e.currentTarget.duration),onError:()=>f("Failed to load video"),style:{maxWidth:"100%",maxHeight:"100%"}},y)]})})]})}function e5({filePath:e,cwd:t,sourceSessionId:n,watchEnabled:o=!0}){let{t:a}=(0,w.s)(),[s,l]=(0,i.useState)(!1),[d,c]=(0,i.useState)(0),[u,p]=(0,i.useState)(null),[h,g]=(0,i.useState)(null),x=(0,i.useRef)(null),f=(0,i.useRef)(0),m=eP(e),v="pdf"===m,b=v?eX(e,"read",n,d?{v:d}:void 0):eX(e,"preview",n,d?{v:d}:void 0);return(0,i.useEffect)(()=>{c(0),p(null),g(null),l(!1);let t=!0,r=++f.current;return fetch(eX(e,"meta",n)).then(e=>e.json()).then(e=>{t&&r===f.current&&(e.error&&g(e.error),"number"==typeof e.size&&(p(e.size),!v&&e.size>0xa00000&&g("DOCX too large for preview (>10MB)")))}).catch(e=>{t&&r===f.current&&g(String(e))}),()=>{t=!1}},[e,v,n]),(0,i.useEffect)(()=>{if(l(!1),x.current&&(x.current.close(),x.current=null),!o)return;let t=!0,r=new EventSource(eX(e,"watch",n));x.current=r,r.addEventListener("connected",()=>{let r;l(!0),r=++f.current,fetch(eX(e,"meta",n)).then(e=>e.json()).then(e=>{if(t&&r===f.current){if(e.error)return void g(e.error);if("number"==typeof e.size&&(p(e.size),!v&&e.size>0xa00000))return void g("DOCX too large for preview (>10MB)");g(null),c(e=>e+1)}}).catch(e=>{t&&r===f.current&&g(String(e))})}),r.addEventListener("change",e=>{f.current+=1;try{let t=JSON.parse(e.data);if("number"==typeof t.size&&(p(t.size),!v&&t.size>0xa00000))return void g("DOCX too large for preview (>10MB)")}catch{}g(null),c(e=>e+1)});let i=()=>{l(!1)};return r.addEventListener("error",i),r.onerror=i,()=>{t=!1,r.close(),x.current===r&&(x.current=null)}},[e,v,n,o]),(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(--file-panel-chrome)",flexShrink:0},children:[(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:e,children:(0,I.qP)(e,t)}),(0,r.jsx)("span",{style:{marginLeft:"auto"},children:"docx"===m?"docx preview":"pdf"}),null!=u&&(0,r.jsx)("span",{children:eQ(u)}),(0,r.jsx)(eZ,{filePath:e,sourceSessionId:n}),(0,r.jsxs)("span",{title:a(s?"i18n.liveSync":"i18n.notWatching"),style:{display:"flex",alignItems:"center",gap:4,color:s?"#4ade80":"var(--text-dim)",flexShrink:0},children:[(0,r.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:s?"#4ade80":"var(--border)",display:"inline-block",boxShadow:s?"0 0 4px #4ade80":"none"}}),s?"live":"static"]})]}),(0,r.jsx)("div",{style:{flex:1,minHeight:0,background:"transparent"},children:h?(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",padding:24,color:"#f87171",fontSize:13,textAlign:"center"},children:h}):(0,r.jsx)("iframe",{src:b,sandbox:v?void 0:"allow-same-origin",title:a("i18n.previewFile",{file:(0,I.WP)(e)}),style:{width:"100%",height:"100%",border:"none",background:v?"var(--bg)":"#eef1f5"}},b)})]})}function e6({filePath:e,cwd:t,sourceSessionId:n,onOpenFile:i,onMentionLines:o,onAtMention:a,gitRefreshKey:s,initialDisplayMode:l,initialState:d,onStateChange:c,watchEnabled:u=!0}){let p;return null!==(eE[eP(e)]??null)?(0,r.jsx)(e1,{filePath:e,cwd:t,sourceSessionId:n,watchEnabled:u}):null!==(ez[eP(e)]??null)?(0,r.jsx)(e4,{filePath:e,cwd:t,sourceSessionId:n,watchEnabled:u}):null!==(eW[eP(e)]??null)?(0,r.jsx)(e8,{filePath:e,cwd:t,sourceSessionId:n,watchEnabled:u}):null!==("pdf"===(p=eP(e))||"docx"===p?p:null)?(0,r.jsx)(e5,{filePath:e,cwd:t,sourceSessionId:n,watchEnabled:u}):(0,r.jsx)(e3,{filePath:e,cwd:t,sourceSessionId:n,onOpenFile:i,onMentionLines:o,onAtMention:a,gitRefreshKey:s,initialDisplayMode:l,initialState:d,onStateChange:c,watchEnabled:u})}function e3({filePath:e,cwd:t,sourceSessionId:n,onOpenFile:o,onMentionLines:a,onAtMention:s,gitRefreshKey:l,initialDisplayMode:d,initialState:c,onStateChange:u,watchEnabled:p=!0}){let{isDark:h}=(0,eR.D)(),{t:g}=(0,w.s)(),[x,f]=(0,i.useState)(null),[m,v]=(0,i.useState)(null),[b,y]=(0,i.useState)(!1),[k,j]=(0,i.useState)(!1),[S,C]=(0,i.useState)(!0),[T,M]=(0,i.useState)(null),L=c?.displayMode??d??"source",R=c?.wrapLines??!1,E=c?.scrollTop??0,z=c?.scrollLeft??0,[W,P]=(0,i.useState)(L),[$,N]=(0,i.useState)(R),[D,B]=(0,i.useState)(!1),A=(0,i.useRef)(null),F=(0,i.useRef)(0),H=(0,i.useRef)(0),O=(0,i.useRef)(null),U=(0,i.useRef)(!1),_=(0,i.useRef)(void 0===c&&void 0===d),q=(0,i.useRef)(!0),V=(0,i.useRef)({displayMode:L,wrapLines:R,scrollTop:E,scrollLeft:z}),J=(0,i.useRef)(u),[K,Y]=(0,i.useState)(null);J.current=u;let G=(0,i.useCallback)(e=>{V.current.displayMode=e,P(e)},[]),X=(0,i.useCallback)(()=>{N(e=>{let t=!e;return V.current.wrapLines=t,t})},[]);(0,i.useEffect)(()=>(V.current={displayMode:L,wrapLines:R,scrollTop:E,scrollLeft:z},q.current=!0,U.current=!1,P(L),N(R),()=>{J.current?.({...V.current})}),[e,n,L,R,E,z]);let Z=(0,i.useCallback)(e=>{let t=++F.current;return fetch(eX(e,"read",n)).then(e=>e.json()).then(e=>t!==F.current?null:e.error?(M(e.error),null):(M(null),f(e),e)).catch(e=>(t!==F.current||M(String(e)),null))},[n]),Q=(0,i.useCallback)(async e=>{let n=++H.current;if(y(!0),!t){v(null),y(!1),j(!0);return}try{let r=new URLSearchParams({cwd:t,path:e}),i=await fetch(`/api/git/diff?${r.toString()}`),o=await i.json();if(n!==H.current)return;v(i.ok&&o.supported&&"string"==typeof o.patch?o:null)}catch{n===H.current&&v(null)}finally{n===H.current&&(y(!1),j(!0))}},[t]);(0,i.useEffect)(()=>{let t=!0;return C(!0),M(null),f(null),v(null),j(!1),B(!1),Z(e).finally(()=>{t&&C(!1)}),()=>{t=!1}},[e,Z,n]),(0,i.useEffect)(()=>{if(B(!1),A.current&&(A.current.close(),A.current=null),!p)return;let t=()=>{Z(e),Q(e)},r=new EventSource(eX(e,"watch",n));A.current=r,r.addEventListener("connected",()=>{B(!0),t()}),r.addEventListener("change",t);let i=()=>{B(!1)};return r.addEventListener("error",i),r.onerror=i,()=>{r.close(),A.current===r&&(A.current=null)}},[e,Z,Q,n,p]),(0,i.useEffect)(()=>{Q(e)},[Q,e,l]),(0,i.useEffect)(()=>{_.current&&(x?.language==="markdown"||x?.language==="html")&&(_.current=!1,G("preview"))},[x?.language,G]);let ee=m?.supported===!0&&"string"==typeof m.patch,et=ee&&"deleted"===m.status;(0,i.useEffect)(()=>{k&&!ee&&"diff"===W&&G("source")},[W,k,ee,G]),(0,i.useEffect)(()=>{"diff"===L&&ee&&!U.current&&(U.current=!0,G("diff"))},[L,ee,G]);let en=(0,i.useMemo)(()=>x?.language==="markdown"?(0,eA.Ep)(x.content):"",[x]),er=(0,i.useMemo)(()=>x?.language==="markdown"?function(e){let t=function(e){let t=eD.exec(e);if(!t)return null;let n=/^---[ \t]*(?:(?:\r\n|\n|\r)|$)/gm;n.lastIndex=t[0].length;let r=n.exec(e);return r?{yaml:e.slice(t[0].length,r.index).replace(/(?:\r\n|\n|\r)$/,""),rest:e.slice(r.index+r[0].length)}:null}(e);if(!t)return{data:null,rest:e};try{let e=(0,eN.Hh)(t.yaml);if(e&&"object"==typeof e&&!Array.isArray(e))return{data:e,rest:t.rest}}catch{}return{data:null,rest:t.rest}}(x.content):null,[x]);(0,i.useEffect)(()=>{let e=()=>{let e=O.current;Y(a&&"source"===W&&e?eY(e,window.getSelection()):null)};if(e(),a&&"source"===W)return document.addEventListener("selectionchange",e),()=>document.removeEventListener("selectionchange",e)},[x?.content,W,a]);let ei=(0,i.useCallback)(n=>{a&&n&&a((0,I.qP)(e,t),n.startLine,n.endLine)},[t,e,a]);if((0,i.useEffect)(()=>{if(!a||"source"!==W)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 n=O.current,r=n?eY(n,window.getSelection()):null;r&&(e.preventDefault(),ei(r))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[W,ei,a]),(0,i.useEffect)(()=>{if(!q.current||S||T&&!et||"diff"===L&&!k||"diff"===L&&ee&&"diff"!==W)return;let e=O.current;e&&(e.scrollTop=V.current.scrollTop,e.scrollLeft=V.current.scrollLeft,q.current=!1)},[x?.content,W,T,k,ee,et,S,L]),S||"diff"===L&&b&&!x)return(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:g("i18n.loading")});if(T&&!et)return(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#f87171",fontSize:13},children:T});if(!x&&!et)return null;let eo=x?.language??"text",ea=x?.content??"",es="html"===eo,el="markdown"===eo,ed=(0,I.gX)(e),ec=ea.split("\n"),eu=et?"diff":W,ep=et?["diff"]:["source",...es||el?["preview"]:[],...ee?["diff"]:[]],eh=et?g("files.deleted"):`${eo} \xb7 ${ec.length} lines \xb7 ${eQ(x.size)}`;return(0,r.jsxs)("div",{className:"file-viewer-shell",style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,r.jsxs)("div",{className:"file-viewer-toolbar",style:{display:"flex",alignItems:"center",gap:8,padding:"5px 12px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",background:"var(--file-panel-chrome)",flexShrink:0},children:[(0,r.jsx)("span",{className:"file-viewer-path",style:{fontFamily:"var(--font-mono)"},title:e,children:(0,I.qP)(e,t)}),(0,r.jsx)("span",{className:"file-viewer-meta",title:eh,children:eh}),!et&&(0,r.jsx)("span",{title:D?g("i18n.liveSync"):g("i18n.notWatching"),"aria-label":D?g("i18n.liveSync"):g("i18n.notWatching"),className:"file-viewer-live-indicator",style:{background:D?"#4ade80":"var(--border)",boxShadow:D?"0 0 4px #4ade80":"none"}}),(0,r.jsxs)("div",{className:"file-viewer-controls",children:[ep.length>1&&(0,r.jsx)("div",{className:"file-viewer-mode-switch","aria-label":g("i18n.fileViewMode"),children:ep.map(e=>{let t=eu===e;return(0,r.jsx)("button",{type:"button",onClick:()=>G(e),title:"diff"===e?g("i18n.compareHead"):void 0,"aria-pressed":t,className:"file-viewer-mode-button",style:{background:t?"var(--side-active)":"transparent",color:t?"var(--text)":"var(--text-muted)"},children:e_[e]},e)})}),(0,r.jsxs)("div",{className:"file-viewer-actions",children:[(s||a)&&(0,r.jsx)("button",{type:"button",onPointerDown:e=>e.preventDefault(),onClick:()=>{K&&a?ei(K):s?.((0,I.qP)(e,t),!1)},title:K&&a?`${g("i18n.mentionSelectedLines")} (L${K.startLine}${K.startLine!==K.endLine?`-L${K.endLine}`:""})`:g("files.insertPath"),"aria-label":g("files.mention"),disabled:!s&&!a,className:"file-viewer-icon-button",children:(0,r.jsx)(eJ,{})}),"source"===eu&&(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("button",{type:"button",onClick:X,title:$?g("i18n.disableWrap"):g("i18n.enableWrap"),"aria-label":$?g("i18n.disableWrap"):g("i18n.enableWrap"),"aria-pressed":$,className:"file-viewer-icon-button",style:{background:$?"var(--side-active)":"transparent",color:$?"var(--text)":"var(--text-muted)"},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:"M3 6h18"}),(0,r.jsx)("path",{d:"M3 12h15a3 3 0 1 1 0 6h-4"}),(0,r.jsx)("path",{d:"m16 16-2 2 2 2"}),(0,r.jsx)("path",{d:"M3 18h7"})]})})})]}),!et&&(0,r.jsx)(eZ,{filePath:e,sourceSessionId:n})]})]}),(0,r.jsx)("div",{ref:O,className:"file-viewer-content",onScroll:e=>{V.current.scrollTop=e.currentTarget.scrollTop,V.current.scrollLeft=e.currentTarget.scrollLeft},style:{flex:1,overflow:"auto",background:"transparent"},children:"diff"===eu&&ee?(0,r.jsx)(e0,{patch:m.patch}):es&&"preview"===eu?(0,r.jsx)("iframe",{srcDoc:ea,sandbox:"allow-scripts",style:{width:"100%",height:"100%",border:"none",background:"var(--bg)"},title:g("i18n.htmlPreview")}):el&&"preview"===eu?(0,r.jsxs)("div",{className:"markdown-body markdown-file-preview",style:{padding:"24px 32px"},children:[er?.data&&(0,r.jsx)(eO,{data:er.data}),(0,r.jsx)(ej.oz,{remarkPlugins:eA.iA,rehypePlugins:eA.LA,components:{code({className:e,children:t,...n}){let i=e?.replace("language-","").toLowerCase()??"",o=String(t);return e?.includes("language-")||o.includes("\n")?"mermaid"===i?(0,r.jsx)(eF.t,{code:o.replace(/\n$/,""),defaultPreview:!0}):(0,r.jsx)(eF.N,{code:o.replace(/\n$/,""),lang:i}):(0,r.jsx)("code",{className:e,...n,children:t})},pre:({children:e})=>(0,r.jsx)(r.Fragment,{children:e}),a({href:e,children:n,...i}){delete i.node;let a=o?(0,e$.V)(e,ed,t??ed):null;return a&&o?(0,r.jsx)("a",{href:e,...i,onClick:e=>{e.defaultPrevented||0!==e.button||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||(e.preventDefault(),o(a))},children:n}):(0,r.jsx)("a",{href:e,...i,children:n})},img({src:e,alt:i,...o}){delete o.node;let a="string"==typeof e?(0,e$.V)(e,ed,t??ed):null,s=a?eX(a,"read",n):e;return(0,r.jsx)("img",{src:s,alt:i??"",loading:"lazy",...o})}},children:en})]}):(0,r.jsx)(eI.A,{className:$?"file-source-view is-wrapped":"file-source-view",language:"text"===eo?"plaintext":eo,style:h?eL.xJ:eL.vs,showLineNumbers:!0,lineNumberStyle:{...eV},customStyle:{margin:0,padding:0,border:0,background:"transparent",...eq,width:$?"100%":"max-content",minWidth:"100%",minHeight:"100%",overflow:"visible"},codeTagProps:{style:{fontFamily:"var(--font-mono)",overflowWrap:$?"anywhere":"normal"}},renderer:e=>(0,r.jsx)(eG,{...e,wrapLines:$}),wrapLongLines:$,children:ea})})]})}function e7({tabs:e,activeTabId:t,onSelectTab:n,onCloseTab:o}){let{t:a}=(0,w.s)(),[s,l]=(0,i.useState)(null);return(0,r.jsx)("div",{style:{display:"flex",alignItems:"flex-end",background:"transparent",overflowX:"auto",flexShrink:0,height:36},children:e.map(e=>{let i=e.id===t;return(0,r.jsxs)("div",{onClick:()=>n(e.id),onMouseDown:e=>{1===e.button&&e.preventDefault()},onAuxClick:t=>{1===t.button&&(t.preventDefault(),t.stopPropagation(),o(e.id))},style:{display:"flex",alignItems:"center",gap:6,height:36,paddingLeft:12,paddingRight:6,borderRight:"1px solid var(--border)",background:i?"var(--file-panel-paper)":"transparent",cursor:"pointer",fontSize:12,color:i?"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:i?1:.7,display:"flex",alignItems:"center"},children:(0,M.I3)(e.label,13)}),(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",flex:1,fontWeight:i?500:400},title:e.filePath,children:e.label}),(0,r.jsx)("button",{onClick:t=>{t.stopPropagation(),o(e.id)},onMouseEnter:()=>l(e.id),onMouseLeave:()=>l(null),style:{display:"flex",alignItems:"center",justifyContent:"center",width:24,height:24,background:s===e.id?"var(--side-hover)":"transparent",border:"none",borderRadius:4,color:s===e.id?"var(--text)":"var(--text-dim)",cursor:"pointer",padding:0,flexShrink:0,transition:"background 0.1s, color 0.1s"},title:a("i18n.close"),"aria-label":`${a("i18n.close")} ${e.label}`,children:(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round","aria-hidden":"true",children:[(0,r.jsx)("line",{x1:"2",y1:"2",x2:"8",y2:"8"}),(0,r.jsx)("line",{x1:"8",y1:"2",x2:"2",y2:"8"})]})})]},e.id)})})}let e9={flex:"0 0 20%",minWidth:168},te={flex:"1 1 auto",minWidth:0};function tt(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function tn({scope:e}){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-meta)"},children:e})}function tr(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 ti({enabled:e,loading:t,onToggle:n,label:i}){return(0,r.jsx)("button",{type:"button",onClick:n,disabled:t,title:i,"aria-label":i,"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 to({value:e,projectResourcesLoaded:t,onChange:n}){let{t:i}=(0,w.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(o=>{let a=e===o,s="project"===o&&!t;return(0,r.jsx)("button",{onClick:()=>{s||n(o)},disabled:s,title:s?i("trust.projectScopeUnavailable"):void 0,style:{width:76,border:"none",cursor:s?"not-allowed":"pointer",opacity:s?.4:1,fontSize:11,background:a?"var(--bg-selected)":"none",color:a?"var(--text)":"var(--text-muted)"},children:o},o)})})}function ta({server:e,cwd:t,busy:n,actionError:i,actionMessage:o,onToggle:a,onRemove:s,onMove:l,onTest:d,onEdit:c}){let{t:u}=(0,w.s)(),p=!e.disabled,h="project"===e.scope?"global":"project",g="url"===e.kind?e.url:"socket"===e.kind?e.socket:e.command,x={color:"var(--text-meta)"},f={color:"var(--text-muted)",fontFamily:"var(--font-mono)",overflowWrap:"anywhere"};return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:20},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)(ti,{enabled:p,loading:n,onToggle:a,label:u(p?"mcp.disable":"mcp.enable")}),(0,r.jsx)(tn,{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-meta)"},children:u("mcp.disabledBadge")}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name})]}),(0,r.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[(0,r.jsx)("button",{onClick:d,disabled:n,style:tr(n),children:u(n?"mcp.testing":"mcp.test")}),(0,r.jsx)("button",{onClick:c,disabled:n,style:tr(n),children:u("mcp.edit")}),(0,r.jsx)("button",{onClick:l,disabled:n,style:tr(n),children:u("project"===h?"mcp.moveToProject":"mcp.moveToGlobal")}),(0,r.jsx)("button",{onClick:s,disabled:n,style:tr(n,!0),children:u("mcp.delete")})]})]}),(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:x,children:u("mcp.fieldType")}),(0,r.jsx)("div",{style:f,children:e.kind}),(0,r.jsx)("div",{style:x,children:u("url"===e.kind?"mcp.kindUrl":"socket"===e.kind?"mcp.kindSocket":"mcp.kindCommand")}),(0,r.jsx)("div",{style:f,children:g??"—"}),"command"===e.kind&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{style:x,children:u("mcp.fieldArgs")}),(0,r.jsx)("div",{style:f,children:e.args.length?e.args.join(" "):"—"})]}),(0,r.jsx)("div",{style:x,children:u("mcp.fieldEnv")}),(0,r.jsx)("div",{style:f,children:e.envKeys.length?e.envKeys.join(", "):"—"}),(0,r.jsx)("div",{style:x,children:u("mcp.fieldOptions")}),(0,r.jsx)("div",{style:f,children:Object.keys(e.options).length?JSON.stringify(e.options):"—"}),(0,r.jsx)("div",{style:x,children:u("mcp.fieldSource")}),(0,r.jsx)("div",{style:{color:"var(--text-meta)",fontFamily:"var(--font-mono)",overflowWrap:"anywhere"},children:tt(e.source)}),(0,r.jsx)("div",{style:x,children:u("mcp.fieldCwd")}),(0,r.jsx)("div",{style:{color:"var(--text-meta)",fontFamily:"var(--font-mono)",overflowWrap:"anywhere"},children:tt(t)})]}),o&&(0,r.jsx)("div",{style:{fontSize:12,color:"#16a34a",whiteSpace:"pre-wrap"},children:o}),i&&(0,r.jsx)("div",{style:{fontSize:12,color:"#ef4444",whiteSpace:"pre-wrap"},children:i})]})}function ts({cwd:e,scope:t,projectResourcesLoaded:n,busy:o,actionError:a,initial:s,onScopeChange:l,onSave:d,onFetchDef:c,onCancel:u}){let{t:p}=(0,w.s)(),h=!!s,[g,x]=(0,i.useState)(h&&s?s.name:""),[f,m]=(0,i.useState)(()=>s?"command"===s.kind?[s.command,...s.args].join(" "):s.url??s.socket??"":""),[v,b]=(0,i.useState)(""),[y,k]=(0,i.useState)("basic"),[j,S]=(0,i.useState)(null),[C,T]=(0,i.useState)(null),[M,I]=(0,i.useState)(!1),L={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"},R={fontSize:12,fontWeight:600,color:"var(--text-muted)"},E=/^https?:\/\//.test(f.trim()),z=()=>{let e=f.trim();if(/^https?:\/\//.test(e))return{url:e};let t=e.split(/\s+/),n=t[0]??"",r=v.trim()?v.trim().split(/\s+/):[];return{command:n,args:[...t.slice(1),...r]}},W=async()=>{if(T(null),null!==j)return void k("json");if(h&&s){k("json"),I(!0);try{let e=await c(s.name,s.scope);S(JSON.stringify(e??z(),null,2))}finally{I(!1)}}else S(JSON.stringify(z(),null,2)),k("json")},P=g.trim()&&("json"===y?(j??"").trim().length>0:f.trim().length>0);return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:18,minHeight:"100%"},children:[(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,r.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)"},children:h?p("mcp.editTitle",{name:s?.name??""}):p("mcp.addTitle")}),(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-meta)",fontFamily:"var(--font-mono)"},children:"project"===t?`${tt(e)}/.pi/mcp.json`:"~/.pi/agent/mcp.json"})]}),(0,r.jsx)("div",{style:{display:"flex",gap:8},children:["basic","json"].map(e=>(0,r.jsx)("button",{type:"button",onClick:()=>"json"===e?void W():k("basic"),style:{padding:"6px 14px",borderRadius:6,border:"1px solid var(--border)",cursor:"pointer",fontSize:12,background:y===e?"var(--accent)":"none",color:y===e?"white":"var(--text-muted)"},children:"basic"===e?p("mcp.modeBasic"):p("mcp.modeJson")},e))}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:7},children:[(0,r.jsx)("label",{style:R,children:p("mcp.nameLabel")}),(0,r.jsx)("input",{value:g,onChange:e=>x(e.target.value),placeholder:p("mcp.namePlaceholder"),style:L})]}),"json"===y?(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:7},children:[(0,r.jsx)("label",{style:R,children:p("mcp.jsonLabel")}),M?(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)"},children:p("mcp.loadingDef")}):(0,r.jsx)("textarea",{value:j??"",onChange:e=>S(e.target.value),spellCheck:!1,placeholder:'{\n "command": "npx",\n "args": ["-y", "@modelcontextprotocol/server-github"],\n "env": {}\n}',style:{width:"100%",minHeight:200,padding:"9px 11px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:12,lineHeight:1.5,outline:"none",resize:"vertical",whiteSpace:"pre",overflow:"auto"}})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:7},children:[(0,r.jsx)("label",{style:R,children:p("mcp.specLabel")}),(0,r.jsx)("input",{value:f,onChange:e=>m(e.target.value),placeholder:p("mcp.specPlaceholder"),style:L})]}),!E&&(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:7},children:[(0,r.jsx)("label",{style:R,children:p("mcp.argsLabel")}),(0,r.jsx)("input",{value:v,onChange:e=>b(e.target.value),style:L})]})]}),C&&(0,r.jsx)("div",{style:{fontSize:12,color:"#ef4444",whiteSpace:"pre-wrap"},children:C}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,r.jsx)(to,{value:t,projectResourcesLoaded:n,onChange:l}),(0,r.jsx)("button",{type:"button",onClick:()=>{if(T(null),"json"===y){let e,t=j??"";if(!t.trim())return void T(p("mcp.jsonEmpty"));try{e=JSON.parse(t)}catch(e){T(p("mcp.jsonParseError",{message:e instanceof Error?e.message:String(e)}));return}if(!e||"object"!=typeof e||Array.isArray(e))return void T(p("mcp.jsonNotObject"));let n=e;return n.command||n.url||n.socket?void d(g,n):void T(p("mcp.jsonNeedsEntry"))}d(g,z())},disabled:o||!P,style:{...tr(o||!P),background:"var(--accent)",color:"white",borderColor:"var(--accent)"},children:o?p("mcp.saving"):h?p("mcp.saveEdit"):p("mcp.save")}),(0,r.jsx)("button",{type:"button",onClick:u,style:tr(!1),children:p("mcp.cancel")})]}),a&&(0,r.jsx)("div",{style:{fontSize:12,color:"#ef4444",whiteSpace:"pre-wrap"},children:a})]})}function tl({anchorRect:e,cwd:t,hidden:n,onClose:a,embedded:s=!1}){let{t:l}=(0,w.s)(),[d,c]=(0,i.useState)(null),[u,p]=(0,i.useState)(!0),[h,g]=(0,i.useState)(null),[x,f]=(0,i.useState)(!1),[m,v]=(0,i.useState)("global"),[b,y]=(0,i.useState)(null),[k,j]=(0,i.useState)(null),[S,C]=(0,i.useState)(null),[T,M]=(0,i.useState)(null),[I,L]=(0,i.useState)(null),R=(0,i.useRef)(null),E=d?.projectResourcesLoaded??!0,z=(0,i.useMemo)(()=>d?.servers.find(e=>e.name===h)??null,[d,h]),W=(0,i.useMemo)(()=>["project","global"].map(e=>({scope:e,servers:(d?.servers??[]).filter(t=>t.scope===e)})).filter(e=>e.servers.length>0),[d]),P=t??"",$=(0,i.useCallback)(async()=>{if(P){p(!0),j(null);try{let e=await fetch(`/api/mcp?cwd=${encodeURIComponent(P)}`),t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);c(t),g(e=>e&&t.servers.some(t=>t.name===e)?e:t.servers[0]?.name??null)}catch(e){j(e instanceof Error?e.message:String(e))}finally{p(!1)}}},[P]);(0,i.useEffect)(()=>{n||$()},[n,$]),(0,i.useEffect)(()=>{if(n)return;let e=e=>{let t=e.target;R.current?.contains(t)||t.closest?.("#mcp-topbar-btn")||a()},t=e=>{"Escape"===e.key&&a()};return document.addEventListener("pointerdown",e,!0),document.addEventListener("keydown",t,!0),()=>{document.removeEventListener("pointerdown",e,!0),document.removeEventListener("keydown",t,!0)}},[n,a]);let N=(0,i.useCallback)(async(e,t)=>{if(!P)return null;L(`mcp:${e}`),j(null),C(null);try{let n=await fetch("/api/mcp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:P,action:e,...t})}),r=await n.json();if(!n.ok||r.error)throw Error(r.error??`HTTP ${n.status}`);return c(r),r}catch(e){return j(e instanceof Error?e.message:String(e)),null}finally{L(null)}},[P]),D=(0,i.useCallback)(async e=>{await N(e.disabled?"enable":"disable",{name:e.name,scope:e.scope})&&C(e.disabled?l("mcp.msgEnabled",{name:e.name}):l("mcp.msgDisabled",{name:e.name}))},[N,l]),B=(0,i.useCallback)(async e=>{let t=await N("remove",{name:e.name,scope:e.scope});t&&(g(t.servers[0]?.name??null),C(l("mcp.msgDeleted",{name:e.name})),0===t.servers.length&&f(!0))},[N,l]),A=(0,i.useCallback)(async e=>{let t="project"===e.scope?"global":"project";await N("move",{name:e.name,fromScope:e.scope,toScope:t})&&C(l("mcp.msgMoved",{name:e.name,scope:t}))},[N,l]),F=(0,i.useCallback)(async(e,t)=>{let n=!!b,r=n&&b?b.name:e.trim();await N(n?"update":"add",{name:r,scope:m,def:t})&&(g(r),f(!1),y(null),C(n?l("mcp.msgUpdated",{name:r}):l("mcp.msgAdded",{name:r})))},[m,b,N,l]),H=(0,i.useCallback)(async(e,t)=>{if(!P)return null;try{let n=await fetch("/api/mcp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:P,action:"get",name:e,scope:t})}),r=await n.json();if(!n.ok||r.error)throw Error(r.error??`HTTP ${n.status}`);return r.def??null}catch{return null}},[P]),O=(0,i.useCallback)(async e=>{M(e.name),j(null),C(null);try{let t=await fetch("/api/mcp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:P,action:"test",name:e.name,scope:e.scope})}),n=await t.json();if(!t.ok||n.error)throw Error(n.error??`HTTP ${t.status}`);C(l("mcp.msgTestResult",{name:e.name,result:n.message??""}))}catch(t){j(l("mcp.msgTestError",{name:e.name,error:t instanceof Error?t.message:String(t)}))}finally{M(null)}},[P,l]),U=null!==I,_=document.documentElement.clientWidth,q=Math.min(780,_-48),V=e?Math.max(24,Math.min(e.left,_-q-24)):_-q-24,J=(0,r.jsxs)("div",{ref:R,role:"dialog","aria-label":l("mcp.sectionTitle"),style:{...s?{position:"relative",width:"100%"}:{position:"fixed",zIndex:130,top:e?.bottom??e?.top??46,left:V,width:q},maxHeight:"min(72vh, 600px)",display:"flex",flexDirection:"column",background:"var(--popover-glass)",backdropFilter:"blur(var(--glass-blur-panel)) saturate(var(--glass-saturate))",WebkitBackdropFilter:"blur(var(--glass-blur-panel)) saturate(var(--glass-saturate))",transform:"translateZ(0)",border:"1px solid color-mix(in srgb, var(--border) 60%, transparent)",borderTop:"none",borderRadius:"0 0 12px 12px",boxShadow:"0 1px 2px rgba(15,23,42,0.04), 0 4px 16px -8px rgba(15,23,42,0.10)",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:"10px 16px",borderBottom:"1px solid color-mix(in srgb, var(--border) 70%, transparent)",flexShrink:0,background:"transparent"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,fontWeight:600,color:"var(--text)"},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)("circle",{cx:"12",cy:"12",r:"3"}),(0,r.jsx)("path",{d:"M12 2v3M12 19v3M2 12h3M19 12h3M4.9 4.9l2.1 2.1M17 17l2.1 2.1M19.1 4.9L17 7M7 17l-2.1 2.1"})]}),l("mcp.sectionTitle")]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,r.jsx)("button",{onClick:()=>void $(),disabled:u||U,style:tr(u||U),children:l("i18n.refresh")}),(0,r.jsx)("button",{onClick:a,style:tr(!1),children:l("i18n.close")})]})]}),(0,r.jsxs)("div",{style:{display:"flex",flex:"1 1 auto",minHeight:0},children:[(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",...e9,borderRight:"1px solid color-mix(in srgb, var(--border) 60%, transparent)",background:"transparent"},children:[(0,r.jsxs)("div",{style:{flex:"1 1 auto",minHeight:0,overflowY:"auto",paddingTop:8},children:[(0,r.jsx)("div",{style:{padding:"4px 8px 3px",fontSize:10,fontWeight:600,color:"var(--text-meta)",textTransform:"uppercase"},children:l("mcp.sectionTitle")}),u?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:"Loading..."}):!d&&k?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"#ef4444"},children:k}):(d?.servers.length??0)===0?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"var(--text-meta)"},children:l("mcp.emptyList")}):W.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-meta)",textTransform:"uppercase"},children:e.scope}),e.servers.map(e=>{let t=!x&&h===e.name;return(0,r.jsxs)("div",{onClick:()=>{g(e.name),f(!1),y(null),j(null),C(null)},style:{display:"flex",alignItems:"center",gap:7,padding:"8px 8px",borderRadius:5,cursor:"pointer",background:t?"var(--bg-selected)":"none"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,r.jsx)("span",{style:{flexShrink:0,width:7,height:7,borderRadius:"50%",background:e.disabled?"var(--text-meta)":"var(--accent)"}}),(0,r.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,r.jsx)("div",{style:{fontSize:12,fontWeight:t?600:400,color:"var(--text)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),(0,r.jsxs)("div",{style:{fontSize:10,color:"var(--text-meta)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:2},children:[e.kind," \xb7 ",e.disabled?l("mcp.itemDisabled"):l("mcp.itemEnabled")]})]})]},e.name)})]},e.scope))]}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:4,padding:"8px 6px",borderTop:"1px solid var(--border)",flexShrink:0},children:(0,r.jsxs)("button",{type:"button",onClick:()=>{f(!0),y(null),v("global"),j(null),C(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-meta)",fontSize:12},onMouseEnter:e=>{x||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{x||(e.currentTarget.style.background="none")},children:[(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)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,r.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),l("mcp.addButton")]})})]}),(0,r.jsx)("div",{style:{...te,overflowY:"auto",padding:20},children:x?(0,r.jsx)(ts,{cwd:P,scope:m,projectResourcesLoaded:E,busy:U,actionError:k,initial:b,onScopeChange:v,onSave:(e,t)=>void F(e,t),onFetchDef:H,onCancel:()=>{f(!1),y(null)}}):z?(0,r.jsx)(ta,{server:z,cwd:P,busy:U||T===z.name,actionError:k,actionMessage:S,onToggle:()=>void D(z),onRemove:()=>void B(z),onMove:()=>void A(z),onTest:()=>void O(z),onEdit:()=>{y(z),f(!0),j(null),C(null)}},z.name):(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-meta)",fontSize:13},children:l("mcp.emptyDetail")})})]})]});return n?null:s?J:(0,o.createPortal)(J,document.body)}var td=n(23584);let tc=["general","models","skills","agents","plugins"],tu="pi-web:settings-navigation",tp=new Set(["skills","agents","plugins"]);function th(){try{return window.localStorage}catch{return null}}function tg(e){let t=e.getItem(tu);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 tx(e,t){return"models"===e?e:t?JSON.stringify([e,t]):null}function tf(e,t=th()){if(t)try{let n=tg(t);n.section=e,t.setItem(tu,JSON.stringify(n))}catch{}}function tm(e,t,n=th()){if(!n)return null;let r=tx(e,t);if(!r)return null;try{let e=tg(n).selections?.[r];return"string"==typeof e&&e.length>0?e:null}catch{return null}}var tv=n(31590);let tb=["input","output","cacheRead","cacheWrite"];function ty(e){return{input:e?.input===void 0?"":String(e.input),output:e?.output===void 0?"":String(e.output),cacheRead:e?.cacheRead===void 0?"":String(e.cacheRead),cacheWrite:e?.cacheWrite===void 0?"":String(e.cacheWrite)}}function tk(e){if(!tw(e))return;let t=e=>{if(!e.trim())return 0;let t=Number(e);return Number.isFinite(t)&&t>=0?t:void 0},n=t(e.input),r=t(e.output),i=t(e.cacheRead),o=t(e.cacheWrite);if(void 0!==n&&void 0!==r&&void 0!==i&&void 0!==o)return{input:n,output:r,cacheRead:i,cacheWrite:o}}function tw(e){return tb.some(t=>""!==e[t].trim())}function tj(e){return{fill:"currentColor",fillRule:"evenodd",height:e.size??"1em",width:e.size??"1em",style:{flex:"none",lineHeight:1,...e.style},xmlns:"http://www.w3.org/2000/svg"}}let tS=e=>(0,r.jsx)("svg",{...tj(e),viewBox:"0 0 24 24",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"})}),tC=e=>(0,r.jsxs)("svg",{height:e.size??"1em",width:e.size??"1em",style:{flex:"none",lineHeight:1,...e.style},xmlns:"http://www.w3.org/2000/svg",fillRule:"evenodd",viewBox:"0 0 24 24",children:[(0,r.jsx)("path",{fill:"#4285F4",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"}),(0,r.jsx)("path",{fill:"#34A853",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"}),(0,r.jsx)("path",{fill:"#FBBC05",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"}),(0,r.jsx)("path",{fill:"#EB4335",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"})]}),tT=e=>(0,r.jsx)("svg",{...tj(e),viewBox:"0 0 24 24",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"})}),tM=e=>(0,r.jsx)("svg",{...tj(e),viewBox:"0 0 24 24",children:(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"})}),tI=e=>(0,r.jsxs)("svg",{height:e.size??"1em",width:e.size??"1em",style:{flex:"none",lineHeight:1,...e.style},xmlns:"http://www.w3.org/2000/svg",fillRule:"evenodd",viewBox:"0 0 24 24",children:[(0,r.jsx)("path",{fill:"#F38020",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"}),(0,r.jsx)("path",{fill:"#FCAD32",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"})]}),tL=e=>(0,r.jsx)("svg",{...tj(e),viewBox:"0 0 24 24",children:(0,r.jsx)("path",{d:"M16 6H8v12h8V6zm4 16H4V2h16v20z"})}),tR=e=>(0,r.jsx)("svg",{...tj(e),viewBox:"0 0 24 24",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"})}),tE=e=>(0,r.jsx)("svg",{...tj(e),viewBox:"0 0 24 24",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"})}),tz={anthropic:{Icon:e=>(0,r.jsx)("svg",{...tj(e),viewBox:"0 0 24 24",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"})}),hasColor:!1},openai:{Icon:tS,hasColor:!1},"openai-codex":{Icon:tS,hasColor:!1},google:{Icon:tC,hasColor:!0},"google-vertex":{Icon:tC,hasColor:!0},"ant-ling":{Icon:e=>(0,r.jsxs)("svg",{...tj(e),viewBox:"0 0 24 24",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"}),(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"}),(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"})]}),hasColor:!0},deepseek:{Icon:e=>(0,r.jsx)("svg",{height:e.size??"1em",width:e.size??"1em",style:{flex:"none",lineHeight:1,...e.style},xmlns:"http://www.w3.org/2000/svg",fillRule:"evenodd",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{fill:"#4D6BFE",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"})}),hasColor:!0},groq:{Icon:e=>(0,r.jsx)("svg",{...tj(e),viewBox:"0 0 24 24",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"})}),hasColor:!1},mistral:{Icon:e=>(0,r.jsxs)("svg",{height:e.size??"1em",width:e.size??"1em",style:{flex:"none",lineHeight:1,...e.style},xmlns:"http://www.w3.org/2000/svg",fillRule:"evenodd",viewBox:"0 0 24 24",children:[(0,r.jsx)("path",{fill:"gold",d:"M3.428 3.4h3.429v3.428H3.428V3.4zm13.714 0h3.43v3.428h-3.43V3.4z"}),(0,r.jsx)("path",{fill:"#FFAF00",d:"M3.428 6.828h6.857v3.429H3.429V6.828zm10.286 0h6.857v3.429h-6.857V6.828z"}),(0,r.jsx)("path",{fill:"#FF8205",d:"M3.428 10.258h17.144v3.428H3.428v-3.428z"}),(0,r.jsx)("path",{fill:"#FA500F",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"}),(0,r.jsx)("path",{fill:"#E10500",d:"M0 17.114h10.286v3.429H0v-3.429zm13.714 0H24v3.429H13.714v-3.429z"})]}),hasColor:!0},moonshotai:{Icon:tT,hasColor:!1},"moonshotai-cn":{Icon:tT,hasColor:!1},moonshot:{Icon:tT,hasColor:!1},minimax:{Icon:tM,hasColor:!0},"minimax-cn":{Icon:tM,hasColor:!0},fireworks:{Icon:e=>(0,r.jsx)("svg",{height:e.size??"1em",width:e.size??"1em",style:{flex:"none",lineHeight:1,...e.style},xmlns:"http://www.w3.org/2000/svg",fillRule:"evenodd",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{fill:"#5019C5",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"})}),hasColor:!0},huggingface:{Icon:e=>(0,r.jsxs)("svg",{height:e.size??"1em",width:e.size??"1em",style:{flex:"none",lineHeight:1,...e.style},xmlns:"http://www.w3.org/2000/svg",fillRule:"evenodd",viewBox:"0 0 24 24",children:[(0,r.jsx)("path",{fill:"#FF9D0B",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"}),(0,r.jsx)("path",{fill:"#FFD21E",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"}),(0,r.jsx)("path",{fill:"#FF323D",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"}),(0,r.jsx)("path",{fill:"#3A3B45",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"}),(0,r.jsx)("path",{fill:"#FF9D0B",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"}),(0,r.jsx)("path",{fill:"#FFD21E",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"})]}),hasColor:!0},cerebras:{Icon:e=>(0,r.jsxs)("svg",{...tj(e),viewBox:"0 0 24 24",children:[(0,r.jsx)("path",{fill:"#F15A29",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"}),(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"})]}),hasColor:!0},openrouter:{Icon:e=>(0,r.jsx)("svg",{...tj(e),viewBox:"0 0 24 24",children:(0,r.jsx)("path",{d:"M16.804 1.957l7.22 4.105v.087L16.73 10.21l.017-2.117-.821-.03c-1.059-.028-1.611.002-2.268.11-1.064.175-2.038.577-3.147 1.352L8.345 11.03c-.284.195-.495.336-.68.455l-.515.322-.397.234.385.23.53.338c.476.314 1.17.796 2.701 1.866 1.11.775 2.083 1.177 3.147 1.352l.3.045c.694.091 1.375.094 2.825.033l.022-2.159 7.22 4.105v.087L16.589 22l.014-1.862-.635.022c-1.386.042-2.137.002-3.138-.162-1.694-.28-3.26-.926-4.881-2.059l-2.158-1.5a21.997 21.997 0 00-.755-.498l-.467-.28a55.927 55.927 0 00-.76-.43C2.908 14.73.563 14.116 0 14.116V9.888l.14.004c.564-.007 2.91-.622 3.809-1.124l1.016-.58.438-.274c.428-.28 1.072-.726 2.686-1.853 1.621-1.133 3.186-1.78 4.881-2.059 1.152-.19 1.974-.213 3.814-.138l.02-1.907z"})}),hasColor:!1},xai:{Icon:e=>(0,r.jsx)("svg",{...tj(e),viewBox:"0 0 24 24",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"})}),hasColor:!1},"cloudflare-ai-gateway":{Icon:tI,hasColor:!0},"cloudflare-workers-ai":{Icon:tI,hasColor:!0},"vercel-ai-gateway":{Icon:e=>(0,r.jsx)("svg",{...tj(e),viewBox:"0 0 24 24",children:(0,r.jsx)("path",{d:"M12 0l12 20.785H0L12 0z"})}),hasColor:!1},"github-copilot":{Icon:e=>(0,r.jsx)("svg",{...tj(e),viewBox:"0 0 24 24",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"})}),hasColor:!1},"amazon-bedrock":{Icon:e=>(0,r.jsxs)("svg",{...tj(e),viewBox:"0 0 24 24",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",{fill:"#F90",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"})]}),hasColor:!0},"azure-openai-responses":{Icon:e=>(0,r.jsxs)("svg",{...tj(e),viewBox:"0 0 24 24",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"}),(0,r.jsx)("path",{fill:"#0078D4",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"}),(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"}),(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"})]}),hasColor:!0},"kimi-coding":{Icon:e=>(0,r.jsxs)("svg",{height:e.size??"1em",width:e.size??"1em",style:{flex:"none",lineHeight:1,...e.style},xmlns:"http://www.w3.org/2000/svg",fillRule:"evenodd",viewBox:"0 0 24 24",children:[(0,r.jsx)("path",{fill:"#1783FF",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"}),(0,r.jsx)("path",{fill:"#fff",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"})]}),hasColor:!0},nvidia:{Icon:e=>(0,r.jsx)("svg",{height:e.size??"1em",width:e.size??"1em",style:{flex:"none",lineHeight:1,...e.style},xmlns:"http://www.w3.org/2000/svg",fillRule:"evenodd",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{fill:"#74B71B",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"})}),hasColor:!0},opencode:{Icon:tL,hasColor:!1},"opencode-go":{Icon:tL,hasColor:!1},qwen:{Icon:e=>(0,r.jsx)("svg",{...tj(e),viewBox:"0 0 24 24",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"})}),hasColor:!0},xiaomi:{Icon:tR,hasColor:!1},"xiaomi-token-plan-ams":{Icon:tR,hasColor:!1},"xiaomi-token-plan-cn":{Icon:tR,hasColor:!1},"xiaomi-token-plan-sgp":{Icon:tR,hasColor:!1},zai:{Icon:tE,hasColor:!1},"zai-coding-cn":{Icon:tE,hasColor:!1},zhipu:{Icon:e=>(0,r.jsx)("svg",{height:e.size??"1em",width:e.size??"1em",style:{flex:"none",lineHeight:1,...e.style},xmlns:"http://www.w3.org/2000/svg",fillRule:"evenodd",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{fill:"#3859FF",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"})}),hasColor:!0},cohere:{Icon:e=>(0,r.jsxs)("svg",{height:e.size??"1em",width:e.size??"1em",style:{flex:"none",lineHeight:1,...e.style},xmlns:"http://www.w3.org/2000/svg",fillRule:"evenodd",viewBox:"0 0 24 24",children:[(0,r.jsx)("path",{fill:"#39594D",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"}),(0,r.jsx)("path",{fill:"#D18EE2",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"}),(0,r.jsx)("path",{fill:"#FF7759",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"})]}),hasColor:!0},perplexity:{Icon:e=>(0,r.jsx)("svg",{height:e.size??"1em",width:e.size??"1em",style:{flex:"none",lineHeight:1,...e.style},xmlns:"http://www.w3.org/2000/svg",fillRule:"evenodd",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{fill:"#22B8CD",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"})}),hasColor:!0},together:{Icon:e=>(0,r.jsxs)("svg",{height:e.size??"1em",width:e.size??"1em",style:{flex:"none",lineHeight:1,...e.style},xmlns:"http://www.w3.org/2000/svg",fillRule:"evenodd",viewBox:"0 0 24 24",children:[(0,r.jsx)("path",{fill:"#EF2CC1",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"}),(0,r.jsx)("path",{fill:"#CAAEF5",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"}),(0,r.jsx)("path",{fill:"#FC4C02",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"})]}),hasColor:!0},grok:{Icon:e=>(0,r.jsx)("svg",{...tj(e),viewBox:"0 0 24 24",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"})}),hasColor:!1}},tW=["openai-completions","openai-responses","anthropic-messages","google-generative-ai"];function tP({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 t$={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 tN({value:e,onChange:t,placeholder:n,mono:i}){return(0,r.jsx)("input",{value:e,onChange:e=>t(e.target.value),placeholder:n,style:{...t$,fontFamily:i?"var(--font-mono)":"inherit"}})}function tD({value:e,onChange:t,placeholder:n,mono:o,onKeyDown:a,autoComplete:s="off",spellCheck:l=!1,style:d}){let[c,u]=(0,i.useState)(!1),{t:p}=(0,w.s)(),h=(0,j.u)();return(0,i.useEffect)(()=>{e||u(!1)},[e]),(0,r.jsxs)("div",{style:{position:"relative",width:"100%",...d},children:[(0,r.jsx)("input",{type:c?"text":"password",value:e,onChange:e=>t(e.target.value),...h.compositionProps,onKeyDown:e=>{h.isIMEBusy(e)||a?.(e)},placeholder:n,style:{...t$,paddingRight:34,fontFamily:o?"var(--font-mono)":"inherit"},autoComplete:s,spellCheck:l}),(0,r.jsx)("button",{type:"button",onClick:()=>u(e=>!e),"aria-label":p(c?"i18n.hideDetails":"i18n.showDetails"),title:p(c?"i18n.hideDetails":"i18n.showDetails"),style:{position:"absolute",right:5,top:"50%",transform:"translateY(-50%)",width:24,height:24,padding:0,border:"none",background:"transparent",color:"var(--text-dim)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},children:c?(0,r.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("path",{d:"M17.94 17.94A10.94 10.94 0 0 1 12 20C7 20 2.73 16.89 1 12a18.45 18.45 0 0 1 5.06-6.94"}),(0,r.jsx)("path",{d:"M9.9 4.24A10.94 10.94 0 0 1 12 4c5 0 9.27 3.11 11 8a18.5 18.5 0 0 1-2.16 3.19"}),(0,r.jsx)("path",{d:"M14.12 14.12A3 3 0 0 1 9.88 9.88"}),(0,r.jsx)("path",{d:"M1 1l22 22"})]}):(0,r.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8S1 12 1 12Z"}),(0,r.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})})]})}function tB({value:e,onChange:t,placeholder:n}){return(0,r.jsx)("input",{type:"number",value:e,onChange:e=>t(e.target.value),placeholder:n,style:t$})}function tA({value:e,onChange:t,options:n,required:i}){let{t:o}=(0,w.s)();return(0,r.jsxs)("select",{value:e,onChange:e=>t(e.target.value),style:{...t$,color:e?"var(--text)":"var(--text-dim)"},children:[!i&&(0,r.jsxs)("option",{value:"",children:["— ",o("i18n.default")," / none —"]}),n.map(e=>(0,r.jsx)("option",{value:e,children:e},e))]})}function tF({label:e,checked:t,onChange:n}){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=>n(e.target.checked),style:{width:13,height:13,accentColor:"var(--accent)",cursor:"pointer"}}),e]})}function tH({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 tO({name:e,provider:t,onChange:n,onRename:o,onDelete:a,onAddModels:s}){let{t:l}=(0,w.s)(),[d,c]=(0,i.useState)(e),[u,p]=(0,i.useState)({phase:"idle"}),[h,g]=(0,i.useState)(""),[x,f]=(0,i.useState)([]),m=(0,i.useRef)(0),v=(0,i.useRef)(null);(0,i.useEffect)(()=>c(e),[e]);let b=(e,r)=>n({...t,[e]:r});(0,i.useEffect)(()=>{t.api||n({...t,api:"openai-completions"})},[t.api]),(0,i.useEffect)(()=>{m.current+=1,p({phase:"idle"}),g(""),f([])},[e,t.baseUrl,t.api,t.apiKey]);let y=(0,i.useCallback)(async()=>{if(!t.baseUrl?.trim()||"loading"===u.phase)return;let n=++m.current;p({phase:"loading"}),f([]);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}})}),i=await r.json();if(n!==m.current)return;if(!r.ok||i.error||!i.models)return void p({phase:"error",message:i.error??`HTTP ${r.status}`});p({phase:"success",models:i.models,endpoint:i.endpoint??t.baseUrl})}catch(e){if(n!==m.current)return;p({phase:"error",message:e instanceof Error?e.message:String(e)})}},[u.phase,e,t]),k=new Set((t.models??[]).map(e=>e.id)),j="success"===u.phase?u.models:[],S=h.trim().toLocaleLowerCase(),C=j.filter(e=>!S||e.id.toLocaleLowerCase().includes(S)||e.name?.toLocaleLowerCase().includes(S)),T=C.slice(0,300),M=T.filter(e=>!k.has(e.id)).map(e=>e.id),I=x.filter(e=>!k.has(e)).length,L=M.length>0&&M.every(e=>x.includes(e)),R=!L&&M.some(e=>x.includes(e));return(0,i.useEffect)(()=>{v.current&&(v.current.indeterminate=R)},[R]),(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)(tH,{children:l("i18n.provider")}),(0,r.jsx)("button",{onClick:a,style:{padding:"3px 8px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:4,color:"#ef4444",cursor:"pointer",fontSize:11},children:l("i18n.delete")})]}),(0,r.jsxs)(tP,{label:l("i18n.providerName"),children:[(0,r.jsx)(tN,{value:d,onChange:c,placeholder:"provider-name",mono:!0}),d!==e&&d.trim()&&(0,r.jsx)("button",{onClick:()=>o(d.trim()),style:{marginTop:4,padding:"3px 10px",background:"var(--accent)",border:"none",borderRadius:4,color:"#fff",cursor:"pointer",fontSize:11,alignSelf:"flex-start"},children:l("i18n.rename")})]}),(0,r.jsx)(tP,{label:"Base URL",children:(0,r.jsx)(tN,{value:t.baseUrl??"",onChange:e=>b("baseUrl",e||void 0),placeholder:"https://api.example.com/v1",mono:!0})}),(0,r.jsxs)(tP,{label:"API Key",children:[(0,r.jsx)(tD,{value:t.apiKey??"",onChange:e=>b("apiKey",e||void 0),placeholder:"ENV_VAR_NAME, !shell-command, or literal key",mono:!0}),(0,r.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:["Prefix with ",(0,r.jsx)("code",{style:{fontFamily:"var(--font-mono)"},children:"!"})," to run a shell command, or use an env var name"]})]}),(0,r.jsx)(tP,{label:"API",children:(0,r.jsx)(tA,{value:t.api??"openai-completions",onChange:e=>b("api",e),options:tW,required:!0})}),(0,r.jsxs)(tP,{label:"Headers",children:[(0,r.jsx)(tK,{headers:t.headers,onChange:e=>b("headers",e)}),(0,r.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:"Added to every request from this provider (e.g. User-Agent). Useful for gateways with bot detection."})]}),(0,r.jsxs)("div",{style:{borderTop:"1px solid var(--border)",paddingTop:14,display:"flex",flexDirection:"column",gap:10},children:["success"!==u.phase&&(0,r.jsx)("button",{onClick:y,disabled:!t.baseUrl?.trim()||"loading"===u.phase,style:{alignSelf:"flex-start",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?l("models.discoveryFetching"):l("models.discoveryFetch")}),"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:h,onChange:e=>g(e.target.value),placeholder:l("models.discoveryFilterPlaceholder",{count:u.models.length}),"aria-label":l("models.discoveryFilter"),style:{...t$,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:M.length?"pointer":"default",color:"var(--text-muted)",fontSize:10,fontWeight:600},children:[(0,r.jsx)("input",{ref:v,type:"checkbox",checked:L,disabled:0===M.length,onChange:()=>{let e=new Set(M);f(t=>L?t.filter(t=>!e.has(t)):Array.from(new Set([...t,...M])))},style:{width:13,height:13,accentColor:"var(--accent)",flexShrink:0}}),l("models.discoverySelectShown")]}),0===T.length?(0,r.jsx)("div",{style:{padding:12,color:"var(--text-dim)",fontSize:11},children:l("models.discoveryNoMatches")}):T.map((e,t)=>{let n=k.has(e.id),i=x.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:n?"default":"pointer",opacity:n?.65:1},children:[(0,r.jsx)("input",{type:"checkbox",checked:i||n,disabled:n,onChange:()=>{var t;return t=e.id,void f(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})]}),n&&(0,r.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10},children:l("models.discoveryAdded")})]},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?l("models.discoveryShowing",{shown:T.length,total:C.length}):l("models.discoveryFetched",{count:u.models.length})}),(0,r.jsx)("button",{onClick:()=>{if("success"!==u.phase)return;let e=new Set(x),t=u.models.filter(t=>e.has(t.id)&&!k.has(t.id));0!==t.length&&(s(t),f([]))},disabled:0===I,style:{height:28,padding:"0 11px",border:"none",borderRadius:5,background:I?"var(--accent)":"var(--bg-panel)",color:I?"#fff":"var(--text-dim)",cursor:I?"pointer":"not-allowed",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:I?l("models.discoveryAddSelectedCount",{count:I}):l("models.discoveryAddSelected")})]})]})]})]})}let tU=["off","minimal","low","medium","high","xhigh","max"],t_={off:"var(--text-dim)",minimal:"#6b7280",low:"#60a5fa",medium:"#a78bfa",high:"#f472b6",xhigh:"#fb923c",max:"#ef4444"};function tq({value:e,onChange:t}){let n=e??{},i=(e,r)=>{let i={...n};"omit"===r?delete i[e]:i[e]=r,t(Object.keys(i).length?i:void 0)};return(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:2},children:tU.map(e=>{let t=n[e],o=e in n?null===t?"null":"string":"omit",a="string"==typeof t?t:"",s=t_[e],l={padding:"4px 10px",fontSize:10,border:"none",cursor:"pointer",fontWeight:400,transition:"background 0.1s, color 0.1s",whiteSpace:"nowrap",background:"var(--bg-panel)",color:"var(--text-dim)"},d={background:"var(--accent)",color:"#fff",fontWeight:600};return(0,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:s,flexShrink:0,opacity:"null"===o?.3:1}}),(0,r.jsx)("span",{style:{fontSize:11,fontFamily:"var(--font-mono)",color:"null"===o?"var(--text-dim)":"var(--text-muted)",textDecoration:"null"===o?"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:()=>i(e,"omit"),style:{...l,..."omit"===o?d:{}},children:"Default"}),(0,r.jsx)("button",{onClick:()=>i(e,null),style:{...l,borderLeft:"1px solid var(--border)",..."null"===o?{background:"#ef4444",color:"#fff",fontWeight:600}:{}},children:"Disabled"})]}),(0,r.jsxs)("div",{style:{display:"flex",borderRadius:5,border:`1px solid ${"string"===o?"var(--accent)":"var(--border)"}`,overflow:"hidden",transition:"border-color 0.1s"},children:[(0,r.jsx)("button",{onClick:()=>i(e,a||e),style:{...l,..."string"===o?d:{},borderRight:"1px solid var(--border)",flexShrink:0},children:"Custom"}),(0,r.jsx)("input",{value:a,onChange:t=>i(e,t.target.value),onFocus:()=>{"string"!==o&&i(e,a||e)},placeholder:e,maxLength:10,style:{width:"12ch",background:"string"===o?"var(--bg)":"var(--bg-panel)",border:"none",outline:"none",color:"string"===o?"var(--text)":"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11,padding:"4px 7px",transition:"background 0.1s, color 0.1s"}})]})]},e)})})}let tV={thinkingFormat:"deepseek",requiresReasoningContentOnAssistantMessages:!0};function tJ(e){return e.compat?.thinkingFormat==="deepseek"}function tK({headers:e,onChange:t}){let[n,o]=(0,i.useState)(()=>Object.entries(e??{}).map(([e,t],n)=>({id:n,name:e,value:t}))),a=(0,i.useRef)(n.length),s=e=>{o(e),t(function(e){let t={};for(let n of e){let e=n.name.trim();e&&(t[e]=n.value)}return Object.keys(t).length?t:void 0}(e))},l=(e,t)=>{s(n.map(n=>n.id===e?{...n,...t}:n))},d={padding:"6px 9px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:4,color:"#ef4444",cursor:"pointer",fontSize:11,lineHeight:1};return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[n.map(e=>(0,r.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,r.jsx)("input",{value:e.name,onChange:t=>l(e.id,{name:t.target.value}),placeholder:"Header-Name",style:{...t$,fontFamily:"var(--font-mono)",flex:1}}),(0,r.jsx)("input",{value:e.value,onChange:t=>l(e.id,{value:t.target.value}),placeholder:"value",style:{...t$,fontFamily:"var(--font-mono)",flex:1}}),(0,r.jsx)("button",{onClick:()=>{var t;return t=e.id,void s(n.filter(e=>e.id!==t))},style:d,children:"✕"})]},e.id)),(0,r.jsx)("button",{onClick:()=>o(e=>[...e,{id:a.current++,name:"",value:""}]),style:{padding:"5px 9px",background:"none",border:"1px solid var(--border)",borderRadius:4,color:"var(--text-muted)",cursor:"pointer",fontSize:11,display:"inline-flex",alignItems:"center",justifyContent:"center",gap:5,alignSelf:"flex-start"},children:"+ Add header"})]})}function tY({providerName:e,provider:t,model:n,onChange:o,onDelete:a}){let[s,l]=(0,i.useState)({phase:"idle"}),{t:d}=(0,w.s)(),[c,u]=(0,i.useState)({phase:"idle"}),[p,h]=(0,i.useState)(!1),[g,x]=(0,i.useState)(()=>ty(n.cost)),f=(0,i.useRef)(g),[m,v]=(0,i.useState)(!1),b=(0,i.useRef)(0),y=(0,i.useRef)(null),k=(0,i.useRef)(n.cost),j=(e,t)=>o({...n,[e]:t}),S=(()=>{if("idle"===s.phase)return null;if("testing"===s.phase)return d("i18n.testingModel");let e=[void 0!==s.latencyMs?`${s.latencyMs}ms`:null,void 0!==s.status?`HTTP ${s.status}`:null].filter(Boolean);return"success"===s.phase?[d("i18n.connected"),...e,s.responseText||null].filter(Boolean).join(" \xb7 "):[d("i18n.failed"),...e,s.message].filter(Boolean).join(" \xb7 ")})();(0,i.useEffect)(()=>{l({phase:"idle"})},[e,t.baseUrl,t.api,t.apiKey,n.id,n.api]),(0,i.useEffect)(()=>{b.current+=1,u({phase:"idle"}),y.current=null},[e,t.baseUrl,n.id]);let C=(0,i.useCallback)(async()=>{if(n.id.trim()&&"testing"!==s.phase){l({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:n})}),i=await r.json();if(!r.ok||!i.ok)return void l({phase:"error",message:i.error??`HTTP ${r.status}`,latencyMs:i.latencyMs,status:i.status});l({phase:"success",latencyMs:i.latencyMs,status:i.status,responseText:i.responseText})}catch(e){l({phase:"error",message:e instanceof Error?e.message:String(e)})}}},[n,t,e,s.phase]),T=(0,i.useCallback)(async()=>{let r=n.id.trim();if(!r||"loading"===c.phase)return;let i=++b.current;u({phase:"loading"});try{let a=new URLSearchParams({q:r,provider:e,limit:"50"});t.baseUrl?.trim()&&a.set("baseUrl",t.baseUrl.trim());let s=await fetch(`/api/models-config/catalog?${a}`),l=await s.json();if(i!==b.current)return;if(!s.ok||l.error||!l.recommendation)return void u({phase:"error",message:l.error??`HTTP ${s.status}`});let d=function(e,t){let n={...e},r=0;if(!e.name?.trim()&&t.name&&(n.name=t.name,r+=1),void 0===e.reasoning&&!0===t.reasoning&&(n.reasoning=!0,r+=1),!e.input?.length&&t.input?.length&&(n.input=[...t.input],r+=1),void 0===e.contextWindow&&void 0!==t.contextWindow&&(n.contextWindow=t.contextWindow,r+=1),void 0===e.maxTokens&&void 0!==t.maxTokens&&(n.maxTokens=t.maxTokens,r+=1),t.cost){let i={...e.cost??{}},o=0;for(let e of["input","output","cacheRead","cacheWrite"])void 0===i[e]&&void 0!==t.cost[e]&&(i[e]=t.cost[e],o+=1);let a=tk(ty(i));o>0&&a&&(n.cost={...i,...a},r+=o)}return{model:n,appliedCount:r}}(n,l.recommendation.preset);d.appliedCount>0&&(y.current=n,o(d.model)),h(!1),u({phase:"success",recommendation:l.recommendation,appliedCount:d.appliedCount})}catch(e){if(i!==b.current)return;u({phase:"error",message:e instanceof Error?e.message:String(e)})}},[c.phase,n,o,t.baseUrl,e]),M=(()=>{if("success"!==c.phase)return null;let{recommendation:t,appliedCount:n}=c,r=n>0?d("models.catalogFilled",{count:n}):d("models.catalogNoEmptyFields");if("unreliable"===t.price.status){let e="no-exact-match"===t.price.reason?d("models.catalogNoExactMatch"):d("models.catalogPriceUnreliable");return`${r} \xb7 ${e}`}let i="provider"===t.price.method?d("models.catalogPriceProvider",{provider:t.price.providerName??t.price.providerId??e}):"base-url"===t.price.method?d("models.catalogPriceBaseUrl",{provider:t.price.providerName??t.price.providerId??e}):d("models.catalogPriceConsensus",{support:t.price.support,total:t.price.total});return`${r} \xb7 ${i}`})(),I="error"===c.phase?c.message:M,L="error"===c.phase?"#ef4444":"success"===c.phase&&"unreliable"===c.recommendation.price.status?"#d97706":"var(--text-dim)",R=[{key:"input",label:d("models.costInput")},{key:"output",label:d("models.costOutput")},{key:"cacheRead",label:d("models.costCacheRead")},{key:"cacheWrite",label:d("models.costCacheWrite")}],E=new Set(Object.keys(n.compat??{})),z=0;tJ(n)&&(z+=1,E.delete("thinkingFormat"),E.delete("requiresReasoningContentOnAssistantMessages")),Object.prototype.hasOwnProperty.call(n.compat??{},"supportsDeveloperRole")&&(z+=1,E.delete("supportsDeveloperRole")),z+=E.size;let W=[n.api?`API: ${n.api}`:null,Object.keys(n.headers??{}).length?d("models.headersSummary",{count:Object.keys(n.headers??{}).length}):null,z?d("models.compatSummary",{count:z}):null,Object.keys(n.thinkingLevelMap??{}).length?d("models.thinkingSummary",{count:Object.keys(n.thinkingLevelMap??{}).length}):null].filter(e=>!!e),P=W.length?W.join(" \xb7 "):d("models.providerDefaults");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)(tH,{children:d("i18n.model")}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[S&&(0,r.jsx)("span",{title:S,style:{maxWidth:260,height:24,padding:"0 8px",border:`1px solid ${"error"===s.phase?"#fecaca":"success"===s.phase?"#bbf7d0":"var(--border)"}`,borderRadius:4,background:"error"===s.phase?"#fee2e2":"success"===s.phase?"#dcfce7":"#e5e7eb",color:"#111827",fontSize:11,display:"inline-flex",alignItems:"center",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",boxSizing:"border-box"},children:S}),(0,r.jsxs)("button",{onClick:C,disabled:!n.id.trim()||"testing"===s.phase,title:d("i18n.testConnection"),style:{height:24,padding:"0 8px",background:"success"===s.phase?"#16a34a":"none",border:`1px solid ${"success"===s.phase?"#16a34a":"var(--border)"}`,borderRadius:4,color:"success"===s.phase?"#fff":n.id.trim()&&"testing"!==s.phase?"var(--text-muted)":"var(--text-dim)",cursor:n.id.trim()&&"testing"!==s.phase?"pointer":"not-allowed",fontSize:11,display:"inline-flex",alignItems:"center",justifyContent:"center",boxSizing:"border-box",gap:5},children:["success"===s.phase&&(0,r.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:(0,r.jsx)("polyline",{points:"20 6 9 17 4 12"})}),"testing"===s.phase?d("i18n.checking"):"success"===s.phase?d("common.ok"):d("i18n.test")]}),(0,r.jsx)("button",{onClick:a,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:d("i18n.remove")})]})]}),(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[(0,r.jsx)(tP,{label:"ID *",children:(0,r.jsx)(tN,{value:n.id,onChange:e=>j("id",e),placeholder:"model-id",mono:!0})}),(0,r.jsx)(tP,{label:"Name",children:(0,r.jsx)(tN,{value:n.name??"",onChange:e=>j("name",e||void 0),placeholder:"Display name"})})]}),(0,r.jsxs)("div",{style:{padding:"2px 0"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[(0,r.jsx)("button",{onClick:()=>void T(),disabled:!n.id.trim()||"loading"===c.phase,style:{height:28,padding:"0 10px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:n.id.trim()&&"loading"!==c.phase?"var(--text-muted)":"var(--text-dim)",cursor:n.id.trim()&&"loading"!==c.phase?"pointer":"not-allowed",fontSize:11},children:"loading"===c.phase?d("models.catalogFilling"):d("models.catalogFill")}),(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:d("models.catalogSource")})]}),I&&(0,r.jsxs)("div",{"aria-live":"polite",style:{marginTop:8,display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,color:L,fontSize:10},children:[(0,r.jsx)("span",{title:I,style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:I}),y.current&&(0,r.jsx)("button",{onClick:()=>{let e=y.current;e&&(y.current=null,o(e),u({phase:"idle"}))},style:{flexShrink:0,padding:"0 2px",border:"none",background:"none",color:"var(--accent)",cursor:"pointer",fontSize:10},children:d("models.catalogUndo")})]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(tH,{children:d("models.capabilities")}),(0,r.jsxs)("div",{style:{display:"flex",gap:20,flexWrap:"wrap",marginTop:8},children:[(0,r.jsx)(tF,{label:d("models.reasoning"),checked:n.reasoning??!1,onChange:e=>j("reasoning",e||void 0)}),(0,r.jsx)(tF,{label:d("models.imageInput"),checked:n.input?.includes("image")??!1,onChange:e=>j("input",e?["text","image"]:void 0)})]})]}),(0,r.jsxs)("section",{children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12},children:[(0,r.jsx)(tH,{children:d("models.modelSpecs")}),(0,r.jsx)("button",{type:"button",onClick:()=>{if(p)return void h(!1);k.current=n.cost;let e=ty(n.cost);f.current=e,x(e),h(!0)},"aria-expanded":p,style:{padding:"2px 4px",border:"none",background:"transparent",color:"var(--accent)",cursor:"pointer",fontSize:10},children:p?d("models.finishEditingCosts"):d("models.editCosts")})]}),(0,r.jsxs)("div",{style:{marginTop:10,display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(170px, 1fr))",gap:10},children:[(0,r.jsx)(tP,{label:d("models.contextWindow"),children:(0,r.jsx)(tB,{value:void 0!==n.contextWindow?String(n.contextWindow):"",onChange:e=>j("contextWindow",e?parseInt(e):void 0),placeholder:"128000"})}),(0,r.jsx)(tP,{label:d("models.maxOutputTokens"),children:(0,r.jsx)(tB,{value:void 0!==n.maxTokens?String(n.maxTokens):"",onChange:e=>j("maxTokens",e?parseInt(e):void 0),placeholder:"16384"})})]}),(0,r.jsxs)("div",{style:{marginTop:16},children:[(0,r.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",fontWeight:600,textTransform:"uppercase"},children:d("models.costPerMillion")}),p?(0,r.jsxs)("div",{style:{marginTop:8,display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(110px, 1fr))",gap:8},children:[R.map(({key:e,label:t})=>(0,r.jsx)(tP,{label:t,children:(0,r.jsx)(tB,{value:g[e],onChange:t=>{let r,i,a;return i=tk(r={...f.current,[e]:t}),a={...n},void(f.current=r,x(r),i?(a.cost={...k.current??{},...i},k.current=a.cost):delete a.cost,o(a))},placeholder:"0"})},e)),tw(g)&&!tk(g)&&(0,r.jsx)("div",{"aria-live":"polite",style:{gridColumn:"1 / -1",color:"#d97706",fontSize:10},children:d("models.costAllRequired")})]}):(0,r.jsx)("div",{style:{marginTop:8,display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(105px, 1fr))",gap:"8px 16px"},children:R.map(({key:e,label:t})=>{let i,o=n.cost?.[e]===void 0;return(0,r.jsxs)("div",{style:{minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:t}),(0,r.jsx)("div",{style:{marginTop:3,color:o?"var(--text-dim)":"var(--text)",fontSize:12,fontFamily:"var(--font-mono)",fontVariantNumeric:"tabular-nums"},children:void 0===(i=n.cost?.[e])?d("models.notProvided"):`$${String(i)}`})]},e)})})]})]}),(0,r.jsxs)("section",{style:{borderTop:"1px solid var(--border)",paddingTop:4},children:[(0,r.jsxs)("button",{type:"button",onClick:()=>v(e=>!e),"aria-expanded":m,"aria-controls":"model-advanced-settings",style:{width:"100%",minHeight:48,padding:"8px 0",border:"none",background:"transparent",display:"grid",gridTemplateColumns:"minmax(0, 1fr) 18px",alignItems:"center",gap:10,color:"var(--text)",cursor:"pointer",textAlign:"left"},children:[(0,r.jsxs)("span",{style:{minWidth:0},children:[(0,r.jsx)("span",{style:{display:"block",fontSize:11,fontWeight:600},children:d("models.advancedSettings")}),(0,r.jsx)("span",{style:{display:"block",marginTop:3,color:"var(--text-dim)",fontSize:10,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:P})]}),(0,r.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{color:"var(--text-dim)",transform:m?"rotate(180deg)":"none",transition:"transform 0.15s ease"},children:(0,r.jsx)("polyline",{points:"6 9 12 15 18 9"})})]}),m&&(0,r.jsxs)("div",{id:"model-advanced-settings",style:{display:"flex",flexDirection:"column",gap:14,padding:"4px 0 16px"},children:[(0,r.jsx)(tP,{label:d("models.apiOverride"),children:(0,r.jsx)(tA,{value:n.api??"",onChange:e=>j("api",e||void 0),options:tW})}),(0,r.jsxs)(tP,{label:d("models.headers"),children:[(0,r.jsx)(tK,{headers:n.headers,onChange:e=>j("headers",e)}),(0,r.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:d("models.headersHelp")})]}),n.reasoning&&(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[(0,r.jsx)(tH,{children:d("models.compatibility")}),(0,r.jsx)(tF,{label:d("models.deepSeekThinkingCompat"),checked:tJ(n),onChange:e=>o(function(e,t){if(t)return{...e,compat:{...e.compat??{},...tV}};if(!e.compat)return e;let n={...e.compat};return delete n.thinkingFormat,delete n.requiresReasoningContentOnAssistantMessages,{...e,compat:Object.keys(n).length?n:void 0}}(n,e))}),(0,r.jsx)(tF,{label:d("models.developerRole"),checked:!1!==({...t.compat??{},...n.compat??{}}).supportsDeveloperRole,onChange:e=>o({...n,compat:{...n.compat??{},supportsDeveloperRole:e}})}),(0,r.jsxs)("div",{style:{marginTop:4},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:10,marginBottom:8},children:[(0,r.jsx)(tH,{children:d("models.thinkingLevelMap")}),n.thinkingLevelMap&&(0,r.jsx)("button",{type:"button",onClick:()=>j("thinkingLevelMap",void 0),style:{fontSize:10,padding:"2px 5px",background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer"},children:d("models.clearAll")})]}),(0,r.jsx)(tq,{value:n.thinkingLevelMap,onChange:e=>j("thinkingLevelMap",e)})]})]})]})]})]})}function tG({provider:e,onRefresh:t}){let[n,o]=(0,i.useState)({phase:"idle"}),{t:a}=(0,w.s)(),[s,l]=(0,i.useState)(""),d=(0,j.u)(),c=(0,i.useRef)(null),u=(0,i.useRef)(null);(0,i.useEffect)(()=>{("auth"===n.phase||"prompt"===n.phase)&&setTimeout(()=>u.current?.focus(),50)},[n.phase]),(0,i.useEffect)(()=>{o({phase:"idle"}),l(""),c.current?.close(),c.current=null},[e.id]),(0,i.useEffect)(()=>()=>{c.current?.close()},[]);let p=(0,i.useCallback)(()=>{c.current?.close(),o({phase:"connecting"}),l("");let n=new EventSource(`/api/auth/login/${encodeURIComponent(e.id)}`);c.current=n,n.onmessage=e=>{let r=JSON.parse(e.data);"auth"===r.type?(o({phase:"auth",url:r.url,instructions:r.instructions??null,token:r.token}),window.open(r.url,"_blank","noopener,noreferrer")):"device_code"===r.type?(o({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?o({phase:"prompt",message:r.message,placeholder:r.placeholder??null,token:r.token}):"select_request"===r.type?o({phase:"select",message:r.message,options:r.options??[],token:r.token}):"progress"===r.type?o({phase:"progress",message:r.message}):"success"===r.type?(n.close(),o({phase:"success"}),t()):"error"===r.type?(n.close(),o({phase:"error",message:r.message})):"cancelled"===r.type&&(n.close(),o({phase:"idle"}))},n.onerror=()=>{n.close(),o(e=>"success"===e.phase?e:{phase:"error",message:"Connection lost"})}},[e.id,t]),h=(0,i.useCallback)(async()=>{await fetch(`/api/auth/logout/${encodeURIComponent(e.id)}`,{method:"POST"}),o({phase:"idle"}),t()},[e.id,t]),g=(0,i.useCallback)(async(t,n)=>{if(n.trim()){o({phase:"progress",message:"Verifying…"});try{let r=await fetch(`/api/auth/login/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:t,code:n.trim()})});if(!r.ok){let e=await r.json().catch(()=>({}));o({phase:"error",message:e.error??`Server error ${r.status}`});return}l("")}catch(e){o({phase:"error",message:e instanceof Error?e.message:"Network error"})}}},[e.id]),x=(0,i.useCallback)(async(t,n)=>{o({phase:"progress",message:"Continuing…"});try{let r=await fetch(`/api/auth/login/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:t,code:n})});if(!r.ok){let e=await r.json().catch(()=>({}));o({phase:"error",message:e.error??`Server error ${r.status}`})}}catch(e){o({phase:"error",message:e instanceof Error?e.message:"Network error"})}},[e.id]),f="connecting"===n.phase||"progress"===n.phase||"auth"===n.phase||"device_code"===n.phase||"prompt"===n.phase||"select"===n.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)(tH,{children:a("i18n.subscription")}),(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:a(e.loggedIn?"i18n.connected":"i18n.notConnected")})]})]}),(0,r.jsxs)("div",{style:{minHeight:48},children:["idle"===n.phase&&(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:e.loggedIn?"Already connected. You can re-login or disconnect.":`Connect your ${e.name} account.`}),"connecting"===n.phase&&(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)"},children:a("i18n.openingBrowser")}),"select"===n.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:n.message}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:n.options.map(e=>(0,r.jsx)("button",{onClick:()=>x(n.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"===n.phase||"prompt"===n.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"===n.phase?"Complete sign-in in the browser, then copy the redirect URL from the address bar and paste it below.":n.message}),"auth"===n.phase&&(0,r.jsxs)("p",{style:{margin:0,fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:["If the browser window did not open,"," ",(0,r.jsx)("a",{href:n.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)",wordBreak:"break-all"},children:"click here to open the login page"}),"."]}),(0,r.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,r.jsx)("input",{ref:u,value:s,onChange:e=>l(e.target.value),...d.compositionProps,onKeyDown:e=>{d.isIMEBusy(e)||"Enter"===e.key&&g(n.token,s)},placeholder:"auth"===n.phase?"http://localhost:1455/auth/callback?code=…":n.placeholder??"Enter value…",style:{flex:1,padding:"6px 9px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",fontSize:12,outline:"none",fontFamily:"var(--font-mono)",boxSizing:"border-box"}}),(0,r.jsx)("button",{onClick:()=>g(n.token,s),disabled:!s.trim(),style:{padding:"6px 12px",background:s.trim()?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:5,color:s.trim()?"#fff":"var(--text-dim)",cursor:s.trim()?"pointer":"not-allowed",fontSize:12,fontWeight:600,flexShrink:0},children:a("i18n.submit")})]})]}),"device_code"===n.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:"Open the verification page and enter this code:"}),(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:n.userCode}),(0,r.jsxs)("p",{style:{margin:0,fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:[(0,r.jsx)("a",{href:n.verificationUri,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)",wordBreak:"break-all"},children:n.verificationUri}),n.expiresInSeconds?` Expires in ${Math.ceil(n.expiresInSeconds/60)} minutes.`:""]})]}),"progress"===n.phase&&(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)"},children:n.message}),"success"===n.phase&&(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"#4ade80"},children:a("i18n.connectedSuccessfully")}),"error"===n.phase&&(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"#f87171"},children:n.message})]}),(0,r.jsx)("div",{style:{display:"flex",gap:8},children:f?(0,r.jsx)("button",{onClick:()=>{c.current?.close(),o({phase:"idle"})},style:{padding:"5px 12px",background:"none",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:a("i18n.cancel")}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{onClick:p,style:{padding:"5px 14px",background:"var(--accent)",border:"none",borderRadius:5,color:"#fff",cursor:"pointer",fontSize:12,fontWeight:600},children:a(e.loggedIn?"i18n.relogin":"i18n.login")}),e.loggedIn&&(0,r.jsx)("button",{onClick:h,style:{padding:"5px 12px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:5,color:"#ef4444",cursor:"pointer",fontSize:12},children:a("i18n.disconnect")})]})})]})}function tX({provider:e,onRefresh:t}){let[n,o]=(0,i.useState)(""),[a,s]=(0,i.useState)(!1),[l,d]=(0,i.useState)(!1),[c,u]=(0,i.useState)(null),[p,h]=(0,i.useState)(!1),{t:g}=(0,w.s)();(0,i.useEffect)(()=>{o(""),u(null),h(!1)},[e.id]);let x=(0,i.useCallback)(async()=>{if(n.trim()){s(!0),u(null),h(!1);try{let r=await fetch(`/api/auth/api-key/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:n.trim()})}),i=await r.json();!r.ok||i.error?u(i.error??`HTTP ${r.status}`):(o(""),h(!0),setTimeout(()=>h(!1),2e3),t())}catch(e){u(String(e))}finally{s(!1)}}},[n,e.id,t]),f=(0,i.useCallback)(async()=>{d(!0),u(null);try{let n=await fetch(`/api/auth/api-key/${encodeURIComponent(e.id)}`,{method:"DELETE"}),r=await n.json();!n.ok||r.error?u(r.error??`HTTP ${n.status}`):t()}catch(e){u(String(e))}finally{d(!1)}},[e.id,t]);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)(tH,{children:"API Key"}),(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:g(e.configured?"i18n.configured":"i18n.notConfigured")})]})]}),(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:e.configured?"API key is stored. Enter a new key below to replace it, or disconnect to remove it.":`Enter your ${e.displayName} API key to enable ${e.modelCount} model${1!==e.modelCount?"s":""}.`}),(0,r.jsx)(tP,{label:"API Key",children:(0,r.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,r.jsx)(tD,{value:n,onChange:o,onKeyDown:e=>{"Enter"===e.key&&n.trim()&&x()},placeholder:e.configured?"Enter new key to replace…":"sk-…",style:{flex:1},autoComplete:"off",spellCheck:!1,mono:!0}),(0,r.jsxs)("button",{onClick:x,disabled:a||!n.trim()||p,style:{padding:"6px 12px",background:p?"#16a34a":n.trim()?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:5,color:n.trim()||p?"#fff":"var(--text-dim)",cursor:a||!n.trim()||p?"not-allowed":"pointer",fontSize:12,fontWeight:600,flexShrink:0,display:"flex",alignItems:"center",gap:5},children:[p&&(0,r.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:(0,r.jsx)("polyline",{points:"20 6 9 17 4 12"})}),g(p?"i18n.saved":a?"i18n.saving":"i18n.save")]})]})}),c&&(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"#f87171"},children:c}),e.configured&&(0,r.jsx)("button",{onClick:f,disabled:l,style:{alignSelf:"flex-start",padding:"5px 12px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:5,color:"#ef4444",cursor:l?"not-allowed":"pointer",fontSize:12},children:g(l?"i18n.removing":"i18n.disconnect")})]})}function tZ({id:e,size:t}){let n=tz[e];if(!n){let n=e.split(/[-_]/).filter(Boolean).slice(0,2).map(e=>e[0]).join("").toUpperCase()||"?";return(0,r.jsx)("span",{"aria-hidden":"true",style:{width:t,height:t,border:"1px solid var(--border)",borderRadius:4,color:"var(--text-dim)",display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,fontSize:Math.max(8,Math.floor(.42*t)),fontWeight:700,lineHeight:1},children:n})}return n.hasColor?(0,r.jsx)(n.Icon,{size:t}):(0,r.jsx)(n.Icon,{size:t,style:{color:"var(--text-muted)"}})}function tQ({oauthProviders:e,apiKeyProviders:t,onSelectOAuth:n,onSelectApiKey:o,onAddCustom:a,onClose:s}){let[l,d]=(0,i.useState)(""),{t:c}=(0,w.s)(),u=(0,j.u)(),p=(0,i.useRef)(null);(0,i.useEffect)(()=>{setTimeout(()=>p.current?.focus(),30)},[]);let h=l.trim().toLowerCase(),g=e.filter(e=>!e.loggedIn&&(!h||e.name.toLowerCase().includes(h))),x=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),m=g.length+x.length+ +!!f,v={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&&s()},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.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0},children:[(0,r.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,r.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),(0,r.jsx)("input",{ref:p,value:l,onChange:e=>d(e.target.value),...u.compositionProps,onKeyDown:e=>{u.isIMEBusy(e)||"Escape"===e.key&&s()},placeholder:c("i18n.searchProviders"),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===m?(0,r.jsx)("div",{style:{padding:"20px 0",fontSize:12,color:"var(--text-dim)",textAlign:"center"},children:c("i18n.noProviders")}):(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:c("i18n.custom")}),f&&(0,r.jsxs)("button",{onClick:()=>{a(),s()},style:v,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:"OpenAI / Anthropic compatible"}),(0,r.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:c("i18n.customEndpoint")})]}),(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.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)"},children:[(0,r.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,r.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})})]}),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:c("i18n.subscriptions")}),g.map(e=>(0,r.jsxs)("button",{onClick:()=>{n(e.id),s()},style:v,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)(tZ,{id:e.id,size:28})]},e.id)),x.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:"API Key"}),x.map(e=>(0,r.jsxs)("button",{onClick:()=>{o(e.id),s()},style:v,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.jsxs)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:[e.modelCount," models"]})]}),(0,r.jsx)(tZ,{id:e.id,size:28})]},e.id))]})})]})})}function t0({onClose:e,cwd:t,embedded:n=!1}){let o=(0,tv.a)(),{t:a}=(0,w.s)(),[s,l]=(0,i.useState)({providers:{}}),[d,c]=(0,i.useState)(!0),[u,p]=(0,i.useState)(!1),[h,g]=(0,i.useState)(null),[x,f]=(0,i.useState)(!1),[m,v]=(0,i.useState)(null),[b,y]=(0,i.useState)([]),[k,j]=(0,i.useState)([]),[S,C]=(0,i.useState)(!1),T=(0,i.useCallback)(()=>{fetch(t?`/api/auth/providers?cwd=${encodeURIComponent(t)}`:"/api/auth/providers").then(e=>e.json()).then(e=>{Array.isArray(e.providers)&&y(e.providers)}).catch(()=>{})},[t]),M=(0,i.useCallback)(()=>{fetch(t?`/api/auth/all-providers?cwd=${encodeURIComponent(t)}`:"/api/auth/all-providers").then(e=>e.json()).then(e=>{Array.isArray(e.providers)&&j(e.providers)}).catch(()=>{})},[t]),I=(0,i.useCallback)(()=>{T(),M()},[T,M]);(0,i.useEffect)(()=>{fetch("/api/models-config").then(e=>e.json()).then(e=>{let t=e.providers?e:{...e,providers:{}};l(t);let n=Object.keys(t.providers??{});n.length>0&&v({type:"provider",name:n[0]})}).catch(()=>l({providers:{}})).finally(()=>c(!1)),I()},[I]);let L=(0,i.useCallback)(()=>{let e="new-provider",t=1;for(;s.providers?.[e];)e=`new-provider-${t++}`;l(t=>({...t,providers:{...t.providers??{},[e]:{api:"openai-completions"}}})),v({type:"provider",name:e})},[s.providers]),R=(0,i.useCallback)((e,t)=>{l(n=>({...n,providers:{...n.providers??{},[e]:t}}))},[]),E=(0,i.useCallback)((e,t)=>{l(n=>{let r=Object.entries(n.providers??{}),i=r.findIndex(([t])=>t===e);return -1===i?n:(r[i]=[t,r[i][1]],{...n,providers:Object.fromEntries(r)})}),v(n=>n?"provider"===n.type&&n.name===e?{type:"provider",name:t}:"model"===n.type&&n.providerName===e?{...n,providerName:t}:n:n)},[]),z=(0,i.useCallback)(e=>{l(t=>{let n={...t.providers??{}};return delete n[e],{...t,providers:n}}),l(e=>{let t=Object.keys(e.providers??{});return v(t.length>0?{type:"provider",name:t[0]}:null),e})},[]),W=(0,i.useCallback)(e=>{l(t=>{let n=t.providers?.[e]??{},r=[...n.models??[],{id:""}];return{...t,providers:{...t.providers??{},[e]:{...n,models:r}}}}),l(t=>{let n=(t.providers?.[e]?.models?.length??1)-1;return v({type:"model",providerName:e,index:n}),t})},[]),P=(0,i.useCallback)((e,t)=>{l(n=>{let r=n.providers?.[e]??{},i=[...r.models??[]],o=new Set(i.map(e=>e.id));for(let e of t)o.has(e.id)||(o.add(e.id),i.push({id:e.id,name:e.name}));return{...n,providers:{...n.providers??{},[e]:{...r,models:i}}}})},[]),$=(0,i.useCallback)((e,t,n)=>{l(r=>{let i=r.providers?.[e]??{},o=[...i.models??[]];return o[t]=n,{...r,providers:{...r.providers??{},[e]:{...i,models:o}}}})},[]),N=(0,i.useCallback)((e,t)=>{l(n=>{let r=n.providers?.[e]??{},i=[...r.models??[]];return i.splice(t,1),{...n,providers:{...n.providers??{},[e]:{...r,models:i.length?i:void 0}}}}),v({type:"provider",name:e})},[]),D=(0,i.useCallback)(async()=>{p(!0),g(null),f(!1);try{let e=await fetch("/api/models-config",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)}),t=await e.json();!e.ok||t.error?g(t.error??`HTTP ${e.status}`):(f(!0),setTimeout(()=>f(!1),2e3))}catch(e){g(String(e))}finally{p(!1)}},[s]),B=Object.entries(s.providers??{}),A=b.filter(e=>e.loggedIn),F=k.filter(e=>e.configured),H=(()=>{if(!m)return null;if("oauth"===m.type){let e=b.find(e=>e.id===m.providerId);return e?(0,r.jsx)(tG,{provider:e,onRefresh:I},e.id):null}if("apikey"===m.type){let e=k.find(e=>e.id===m.providerId);return e?(0,r.jsx)(tX,{provider:e,onRefresh:I},e.id):null}if("provider"===m.type){let e=s.providers?.[m.name];return e?(0,r.jsx)(tO,{name:m.name,provider:e,onChange:e=>R(m.name,e),onRename:e=>E(m.name,e),onDelete:()=>z(m.name),onAddModels:e=>P(m.name,e)},m.name):null}let e=s.providers?.[m.providerName],t=e?.models?.[m.index];return t?(0,r.jsx)(tY,{providerName:m.providerName,provider:e,model:t,onChange:e=>$(m.providerName,m.index,e),onDelete:()=>N(m.providerName,m.index)},`${m.providerName}-${m.index}`):null})();return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{style:n?{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center"}:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:n?void 0:t=>{t.target===t.currentTarget&&e()},children:(0,r.jsxs)("div",{style:n?{width:"100%",height:"100%",background:"var(--bg)",display:"flex",flexDirection:"column",overflow:"hidden"}:{width:o?"calc(100vw - 16px)":860,maxWidth:"calc(100vw - 16px)",height:o?"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:[!n&&(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("common.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:e,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:o?"column":"row",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{width:o?"100%":210,maxHeight:o?"40vh":void 0,borderRight:o?"none":"1px solid var(--border)",borderBottom:o?"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:[A.map(e=>{let t=m?.type==="oauth"&&m.providerId===e.id;return(0,r.jsxs)("div",{onClick:()=>v({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)(tZ,{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)}),F.map(e=>{let t=m?.type==="apikey"&&m.providerId===e.id;return(0,r.jsxs)("div",{onClick:()=>v({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)(tZ,{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)}),(A.length>0||F.length>0)&&B.length>0&&(0,r.jsx)("div",{style:{margin:"4px 8px",borderTop:"1px solid var(--border)"}}),d?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:a("i18n.loading")}):B.map(([e,t])=>{let n=m?.type==="provider"&&m.name===e,i=t.models??[];return(0,r.jsxs)("div",{style:{marginBottom:2},children:[(0,r.jsxs)("div",{onClick:()=>v({type:"provider",name:e}),style:{display:"flex",alignItems:"center",gap:6,padding:"7px 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.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0},children:[(0,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:{fontSize:12,fontWeight:n?600:400,color:"var(--text)",fontFamily:"var(--font-mono)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e})]}),i.map((t,n)=>{let i=m?.type==="model"&&m.providerName===e&&m.index===n;return(0,r.jsxs)("div",{onClick:()=>v({type:"model",providerName:e,index:n}),style:{display:"flex",alignItems:"center",gap:6,padding:"5px 8px 5px 26px",borderRadius:5,cursor:"pointer",background:i?"var(--bg-selected)":"none"},onMouseEnter:e=>{i||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{i||(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("i18n.newModel")}),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"})]},n)}),(0,r.jsx)("div",{onClick:t=>{t.stopPropagation(),W(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.jsxs)("span",{style:{fontSize:11},children:["+ ",a("i18n.model")]})})]},e)})]}),(0,r.jsx)("div",{style:{borderTop:"1px solid var(--border)",padding:"8px 6px"},children:(0,r.jsxs)("button",{onClick:()=>C(!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("i18n.addProvider")]})})]}),(0,r.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:d?null:H??(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:a("i18n.selectProviderModel")})})]}),(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:[h&&(0,r.jsx)("span",{style:{fontSize:12,color:"#f87171",flex:1},children:h}),(0,r.jsx)("button",{onClick:e,style:{padding:"6px 14px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:13},children:a("i18n.cancel")}),(0,r.jsxs)("button",{onClick:D,disabled:u||x,style:{position:"relative",padding:"6px 16px",minWidth:92,background:x?"#16a34a":u?"var(--bg-panel)":"var(--accent)",border:"none",borderRadius:6,color:x?"#fff":u?"var(--text-muted)":"#fff",cursor:u||x?"default":"pointer",fontSize:13,fontWeight:600,display:"inline-flex",alignItems:"center",justifyContent:"center",gap:6,transition:"background-color 0.2s ease, color 0.2s ease",animation:x?"saved-pop 0.45s ease":void 0},children:[x&&(0,r.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",style:{strokeDasharray:18,animation:"saved-check-draw 0.35s ease forwards",flexShrink:0},children:(0,r.jsx)("polyline",{points:"20 6 9 17 4 12"})}),(0,r.jsx)("span",{children:x?a("i18n.saved"):u?a("i18n.saving"):a("i18n.save")})]})]})]})}),S&&(0,r.jsx)(tQ,{oauthProviders:b,apiKeyProviders:k,onSelectOAuth:e=>v({type:"oauth",providerId:e}),onSelectApiKey:e=>v({type:"apikey",providerId:e}),onAddCustom:L,onClose:()=>C(!1)})]})}function t1(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function t2(e){let t=e.sourceInfo?.source,n=e.sourceInfo?.scope;return"user"===n||"user"===t?"global":"project"===n||"project"===t?"project":"path"}function t4(e){let t=t2(e);return"path"===t?t:e.install?.skillsShUrl?`${t} / skills.sh`:t}function t8(e){return e.install?`${e.install.scope}\0${e.install.package}`:null}function t5(e){return e?e.slice(0,8):"unknown"}function t6({enabled:e,loading:t,onToggle:n}){let{t:i}=(0,w.s)();return(0,r.jsx)("button",{onClick:n,disabled:t,title:i(e?"i18n.visibleInPrompt":"i18n.hiddenFromPrompt"),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 t3({skill:e,cwd:t,onToggle:n,toggling:i,saveError:o,updateStatus:a,checkingUpdate:s,updating:l,updateError:d,onCheckUpdate:c,onUpdate:u}){let{t:p}=(0,w.s)(),h=t2(e),g=!e.disableModelInvocation;return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:20},children:[(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},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: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 n=e.slice(t.length).replace(/^[/\\]/,"");return`./${n}`}return t1(e)}(e.filePath)}),(0,r.jsx)(t6,{enabled:g,loading:i,onToggle:()=>n(e)})]}),(0,r.jsxs)("div",{style:{minHeight:16,display:"flex",alignItems:"center",justifyContent:"flex-end",gap:8,flexWrap:"wrap",textAlign:"right"},children:[!g&&(0,r.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:p("i18n.hiddenButInvocable")}),o&&(0,r.jsx)("span",{style:{fontSize:12,color:"#f87171",overflowWrap:"anywhere"},children:o})]})]}),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:"Source"}),(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:"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:t5(a?.currentVersion??e.install.versionHash)}),e.install.canCheckForUpdates&&(0,r.jsx)("button",{onClick:c,disabled:s||l,style:{padding:"4px 9px",border:"1px solid var(--border)",borderRadius:5,background:"none",color:"var(--text-muted)",cursor:s||l?"not-allowed":"pointer",opacity:s||l?.5:1,fontSize:11},children:p("i18n.check")}),a?.state==="update-available"&&(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:12,color:"#d97706"},children:t5(a.latestVersion)}),(s||a&&"update-available"!==a.state)&&(0,r.jsx)("span",{style:{fontSize:12,color:s?"var(--accent)":a?.state==="up-to-date"?"#16a34a":a?.state==="error"?"#ef4444":"var(--text-dim)"},children:s?p("i18n.checking"):a?.state==="up-to-date"?p("i18n.upToDate"):a?.state==="unsupported"?p("i18n.automaticChecksUnavailable"):a?.message||p("i18n.checkFailed")}),a?.state==="update-available"&&(0,r.jsx)("button",{onClick:u,disabled:l||s,style:{padding:"4px 10px",border:"none",borderRadius:5,background:"var(--accent)",color:"#fff",cursor:l||s?"not-allowed":"pointer",opacity:l||s?.5:1,fontSize:11,fontWeight:600},children:p(l?"i18n.updating":"i18n.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:"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:"Description"}),(0,r.jsx)("span",{style:{fontSize:14,color:"var(--text-muted)",lineHeight:1.6},children:e.description})]})]})}function t7({cwd:e,installedPackages:t,projectResourcesLoaded:n,onInstalled:o}){let{t:a}=(0,w.s)(),s=(0,j.u)(),[l,d]=(0,i.useState)(""),[c,u]=(0,i.useState)([]),[p,h]=(0,i.useState)(!1),[g,x]=(0,i.useState)(null),[f,m]=(0,i.useState)(null),[v,b]=(0,i.useState)(null),[y,k]=(0,i.useState)(new Set),[S,C]=(0,i.useState)("global"),T=(0,i.useRef)(null);(0,i.useEffect)(()=>{T.current?.focus()},[]);let M=(0,i.useCallback)(async e=>{if(e.trim()){h(!0),x(null),u([]);try{let t=await fetch("/api/skills/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:e.trim()})}),n=await t.json();if(n.error)return void x(n.error);u(n.results??[]),0===(n.results??[]).length&&x("No skills found")}catch(e){x(String(e))}finally{h(!1)}}},[]),I=(0,i.useCallback)(async t=>{m(t),b(null);try{let n=await fetch("/api/skills/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({package:t,scope:S,cwd:e})}),r=await n.json();if(!n.ok||r.error)return void b(r.error??`HTTP ${n.status}`);k(e=>new Set(e).add(`${S}:${t}`)),o()}catch(e){b(String(e))}finally{m(null)}},[o,S,e]),L="global"===S?"~/.pi/agent/skills/":`${t1(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:a("i18n.addSkill")}),(0,r.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,r.jsx)("input",{ref:T,value:l,onChange:e=>d(e.target.value),...s.compositionProps,onKeyDown:e=>{s.isIMEBusy(e)||"Enter"===e.key&&M(l)},placeholder:a("i18n.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:()=>M(l),disabled:p||!l.trim(),style:{padding:"7px 16px",fontSize:13,borderRadius:6,border:"none",background:"var(--accent)",color:"#fff",cursor:p||!l.trim()?"not-allowed":"pointer",opacity:p||!l.trim()?.5:1,flexShrink:0},children:p?a("i18n.searching"):a("i18n.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:()=>{("global"===e||n)&&C(e)},disabled:"project"===e&&!n,title:"project"!==e||n?void 0:a("trust.projectScopeUnavailable"),style:{padding:"3px 10px",border:"none",cursor:"project"!==e||n?"pointer":"not-allowed",background:S===e?"var(--bg-selected)":"none",color:S===e?"var(--text)":"var(--text-dim)",fontWeight:S===e?600:400,opacity:"project"!==e||n?1:.45,borderRight:"global"===e?"1px solid var(--border)":"none"},children:e},e))}),(0,r.jsxs)("span",{style:{fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["→ ",L]})]}),g&&(0,r.jsx)("div",{style:{fontSize:12,color:"#f87171"},children:g}),v&&(0,r.jsx)("div",{style:{fontSize:12,color:"#f87171",wordBreak:"break-word"},children:v})]}),c.length>0?(0,r.jsx)("div",{style:{flex:1,overflowY:"auto"},children:c.map(e=>{let n=t[S].has(e.package)||y.has(`${S}:${e.package}`),i=f===e.package,o=e.package.indexOf("@"),s=o>-1?e.package.slice(0,o):e.package,l=o>-1?e.package.slice(o+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??s}),(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:s}),(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:()=>!n&&!i&&I(e.package),disabled:n||i||null!==f,style:{flexShrink:0,padding:"5px 14px",fontSize:12,fontWeight:500,borderRadius:5,border:"1px solid var(--border)",cursor:n||i||null!==f?"not-allowed":"pointer",background:n?"rgba(34,197,94,0.1)":"none",color:n?"#16a34a":i?"var(--accent)":"var(--text-muted)",transition:"color 0.12s"},children:n?`✓ ${a("i18n.installed")}`:i?a("i18n.installing"):a("i18n.install")})]},e.package)})}):!g&&!p&&(0,r.jsxs)("div",{style:{fontSize:13,color:"var(--text-dim)",lineHeight:1.8},children:["Search"," ",(0,r.jsx)("a",{href:"https://skills.sh",target:"_blank",rel:"noreferrer",style:{color:"var(--accent)",textDecoration:"none"},children:"skills.sh"})," ","to discover and install skills for your agent."]})]})}function t9({cwd:e,onClose:t,embedded:n=!1}){let o=(0,tv.a)(),{t:a}=(0,w.s)(),[s,l]=(0,i.useState)([]),[d,c]=(0,i.useState)(!0),[u,p]=(0,i.useState)(null),[h,g]=(0,i.useState)(null),[x,f]=(0,i.useState)(new Set),[m,v]=(0,i.useState)(null),[b,y]=(0,i.useState)(!1),[k,j]=(0,i.useState)({}),[S,C]=(0,i.useState)(new Set),[T,M]=(0,i.useState)(!1),[I,L]=(0,i.useState)(null),[R,E]=(0,i.useState)(null),[z,W]=(0,i.useState)(!0),[P,$]=(0,i.useState)({}),N=(0,i.useCallback)(async()=>{c(!0),p(null);try{let t=await fetch(`/api/skills?cwd=${encodeURIComponent(e)}`),n=await t.json();if(!t.ok||n.error)throw Error(n.error??`HTTP ${t.status}`);let r=n.skills??[];if(l(r),W(n.projectResourcesLoaded??!0),r.length>0&&!h){let e=r.find(e=>!e.disableModelInvocation)??r[0];g(e.filePath),e.disableModelInvocation&&$(t=>({...t,[t4(e)]:!0}))}return r}catch(e){return p(String(e)),[]}finally{c(!1)}},[e,h]);(0,i.useEffect)(()=>{j({}),E(null),N()},[e]);let D=(0,i.useCallback)(async t=>{let n=(t?[t]:s.filter(e=>!!e.install)).map(t8).filter(e=>!!e);if(0!==n.length){E(null),C(e=>new Set([...e,...n])),t||M(!0);try{let n=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 n.json();if(!n.ok||r.error)throw Error(r.error??`HTTP ${n.status}`);j(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{C(e=>{let t=new Set(e);for(let e of n)t.delete(e);return t}),t||M(!1)}}},[e,s]),B=(0,i.useCallback)(async t=>{if(!t.install)return;let n=t8(t);L(n),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})}),i=await r.json();if(!r.ok||i.error||!i.success)throw Error(i.error??`HTTP ${r.status}`);await N();let o=i.skill?.install?.versionHash;j(e=>({...e,[n]:{package:t.install.package,scope:t.install.scope,state:"up-to-date",currentVersion:o,latestVersion:o}}))}catch(e){E(e instanceof Error?e.message:String(e))}finally{L(null)}},[e,N]),A=(0,i.useCallback)(async e=>{let t=!e.disableModelInvocation;f(t=>new Set(t).add(e.filePath)),v(null);try{let n=await fetch("/api/skills",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({filePath:e.filePath,disableModelInvocation:t})}),r=await n.json();if(!n.ok||r.error)return void v(r.error??`HTTP ${n.status}`);l(n=>n.map(n=>n.filePath===e.filePath?{...n,disableModelInvocation:t}:n)),t&&$(t=>({...t,[t4(e)]:!0}))}catch(e){v(String(e))}finally{f(t=>{let n=new Set(t);return n.delete(e.filePath),n})}},[]),F=s.find(e=>e.filePath===h)??null;return(0,r.jsx)("div",{style:n?{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center"}:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:n?void 0:e=>{e.target===e.currentTarget&&t()},children:(0,r.jsxs)("div",{style:n?{width:"100%",height:"100%",background:"var(--bg)",display:"flex",flexDirection:"column",overflow:"hidden"}:{width:o?"calc(100vw - 16px)":860,maxWidth:"calc(100vw - 16px)",height:o?"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:[!n&&(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("common.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:t1(e)})]}),(0,r.jsx)("button",{onClick:t,style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),!z&&(0,r.jsx)("div",{role:"status",style:{padding:"8px 18px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",fontSize:12},children:a("trust.skillsNotLoaded")}),(0,r.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:o?"column":"row",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{width:o?"100%":210,maxHeight:o?"40vh":void 0,borderRight:o?"none":"1px solid var(--border)",borderBottom:o?"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:d?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:a("i18n.loading")}):u?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"#f87171"},children:u}):0===s.length?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"var(--text-dim)"},children:a("i18n.noSkills")}):(()=>{let e=[];for(let{label:t,matches:n}of[{label:"project / skills.sh",matches:e=>"project"===t2(e)&&!!e.install?.skillsShUrl},{label:"project",matches:e=>"project"===t2(e)&&!e.install?.skillsShUrl},{label:"global / skills.sh",matches:e=>"global"===t2(e)&&!!e.install?.skillsShUrl},{label:"global",matches:e=>"global"===t2(e)&&!e.install?.skillsShUrl},{label:"path",matches:e=>"path"===t2(e)}]){let r=s.filter(n);r.length>0&&e.push({label:t,skills:r})}let t=e=>{let t,n,i=!b&&h===e.filePath,o=e.disableModelInvocation;return(0,r.jsxs)("div",{onClick:()=>{g(e.filePath),y(!1)},style:{display:"flex",alignItems:"center",gap:7,padding:"8px 8px",borderRadius:5,cursor:"pointer",background:i?"var(--bg-selected)":"none"},onMouseEnter:e=>{i||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{i||(e.currentTarget.style.background="none")},children:[(0,r.jsx)("span",{style:{flexShrink:0,width:7,height:7,borderRadius:"50%",background:o?"var(--border)":"var(--accent)",boxShadow:o?"none":"0 0 4px var(--accent)",transition:"background 0.15s, box-shadow 0.15s"}}),(0,r.jsx)("span",{style:{fontSize:12,fontWeight:i?600:400,color:o?"var(--text-dim)":"var(--text)",fontFamily:"var(--font-mono)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),(n=(t=t8(e))?k[t]:void 0,n?.state!=="update-available"?null:(0,r.jsx)("span",{title:a("i18n.updateAvailable"),style:{color:"#d97706",fontSize:13,lineHeight:1,flexShrink:0},children:"↑"}))]},e.filePath)};return e.map(({label:e,skills:n})=>{let i=n.filter(e=>!e.disableModelInvocation),o=n.filter(e=>e.disableModelInvocation),s=P[e]??!1;return(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:e}),i.map(t),o.length>0&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{onClick:()=>$(t=>({...t,[e]:!s})),style:{display:"flex",alignItems:"center",gap:5,padding:"4px 8px 3px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.06em",cursor:"pointer",userSelect:"none"},children:[(0,r.jsx)("span",{style:{fontSize:8},children:s?"▾":"▸"}),a("i18n.dormant")," (",o.length,")"]}),s&&o.map(t)]})]},e)})})()}),(0,r.jsx)("div",{style:{padding:"8px 6px",borderTop:"1px solid var(--border)",flexShrink:0},children:(0,r.jsxs)("div",{onClick:()=>y(!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.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,r.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),a("i18n.addSkill")]})})]}),(0,r.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:b?(0,r.jsx)(t7,{cwd:e,projectResourcesLoaded:z,installedPackages:{global:new Set(s.filter(e=>e.install?.scope==="global").map(e=>e.install.package)),project:new Set(s.filter(e=>e.install?.scope==="project").map(e=>e.install.package))},onInstalled:()=>{N()}}):d?null:F?(0,r.jsx)(t3,{skill:F,cwd:e,onToggle:A,toggling:x.has(F.filePath),saveError:m,updateStatus:t8(F)?k[t8(F)]:void 0,checkingUpdate:!!t8(F)&&S.has(t8(F)),updating:I===t8(F),updateError:R,onCheckUpdate:()=>void D(F),onUpdate:()=>void B(F)},F.filePath):(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:a("i18n.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:[s.some(e=>!!e.install)&&(0,r.jsx)("button",{onClick:()=>void D(),disabled:T||null!==I,style:{padding:"6px 12px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:T||null!==I?"not-allowed":"pointer",opacity:T||null!==I?.5:1,fontSize:12},children:T?a("i18n.checking"):a("i18n.checkUpdates")}),Object.values(k).filter(e=>"update-available"===e.state).length>0&&(0,r.jsxs)("span",{style:{fontSize:12,color:"#d97706"},children:[Object.values(k).filter(e=>"update-available"===e.state).length," ",1===Object.values(k).filter(e=>"update-available"===e.state).length?a("i18n.update"):a("i18n.updates")]})]}),(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:a("i18n.close")})]})]})})}var ne=n(32383);let nt={builtin:0,global:1,workspace:2,project:3};function nn({embedded:e,title:t,subtitle:n,closeLabel:i="Close",onClose:o,children:a,width:s=900,height:l="78vh"}){let d=e?void 0:{"--config-panel-width":`${s}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||o()},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}),n&&(0,r.jsx)("code",{className:"config-panel-subtitle",title:n,children:n}),(0,r.jsx)("button",{type:"button",className:"config-close-button",onClick:o,title:i,"aria-label":i,children:"\xd7"})]}),a]})})}function nr({children:e}){return(0,r.jsx)("div",{className:"config-split-view",children:e})}function ni({children:e}){return(0,r.jsx)("aside",{className:"config-sidebar",children:e})}function no({children:e}){return(0,r.jsx)("div",{className:"config-sidebar-list",children:e})}function na({children:e}){return(0,r.jsx)("div",{className:"config-sidebar-group-label",children:e})}function ns({active:e=!1,className:t,children:n,...i}){return(0,r.jsx)("button",{type:"button",...i,"aria-current":e?"page":void 0,className:["config-sidebar-item",t].filter(Boolean).join(" "),children:n})}function nl({className:e,...t}){return(0,r.jsx)("span",{...t,className:["config-sidebar-text",e].filter(Boolean).join(" ")})}function nd({className:e,...t}){return(0,r.jsx)("div",{...t,className:["config-detail-stack",e].filter(Boolean).join(" ")})}function nc({className:e,...t}){return(0,r.jsx)("div",{...t,className:["config-detail-header",e].filter(Boolean).join(" ")})}function nu({className:e,...t}){return(0,r.jsx)("div",{...t,className:["config-detail-header-info",e].filter(Boolean).join(" ")})}function np({className:e,...t}){return(0,r.jsx)("div",{...t,className:["config-detail-actions",e].filter(Boolean).join(" ")})}function nh({label:e,children:t,style:n}){return(0,r.jsxs)("div",{className:"config-field",style:n,children:[(0,r.jsx)("span",{className:"config-field-label",children:e}),t]})}function ng({children:e}){return(0,r.jsx)("div",{className:"config-empty-state",children:e})}function nx({children:e,style:t}){return(0,r.jsx)("div",{className:"config-detail",style:t,children:e})}function nf({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 nm({variant:e="secondary",size:t="default",className:n,children:i,...o}){return(0,r.jsx)("button",{type:"button",...o,className:["config-button",`config-button-${e}`,`config-button-${t}`,n].filter(Boolean).join(" "),children:i})}function nv({checked:e,disabled:t=!1,loading:n=!1,label:i,onChange:o}){let a=t||n;return(0,r.jsx)("button",{type:"button",role:"switch","aria-checked":e,"aria-busy":n||void 0,"aria-label":i,title:i,disabled:a,className:`config-switch${n?" is-loading":""}`,onClick:()=>o(!e),children:(0,r.jsx)("span",{className:"config-switch-knob","aria-hidden":"true"})})}function nb({active:e=!1,children:t,className:n,...i}){return(0,r.jsx)("div",{className:"config-list-action",children:(0,r.jsxs)("button",{type:"button",...i,"aria-current":e?"page":void 0,className:["config-list-action-button",n].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 ny({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 nk=new Intl.Collator(void 0,{numeric:!0,sensitivity:"base"});function nw(e,t){return nk.compare(e.name||e.modelId,t.name||t.modelId)||nk.compare(e.provider,t.provider)||nk.compare(e.modelId,t.modelId)}function nj({options:e,value:t,onChange:n,onClear:o,emptyLabel:a,selectedLabel:s,disabled:l=!1,busy:d=!1,isAutoSelection:c=!1,ariaLabel:u,variant:p="toolbar",placement:h="up"}){let g,x,f,m,v,b,y,k,j,{t:S}=(0,w.s)(),C=(0,tv.a)(),T=(0,i.useRef)(null),M=(0,i.useRef)(null),[I,L]=(0,i.useState)(!1),[R,E]=(0,i.useState)(null),[z,W]=(0,i.useState)(""),P=l||d,$=(0,i.useMemo)(()=>[...e].sort(nw),[e]),N=(g=z.trim().toLocaleLowerCase())?$.filter(e=>`${e.name} ${e.modelId}`.toLocaleLowerCase().includes(g)):$,D=$.length>8,B=[];for(let e of N){let t=B.find(t=>t.provider===e.provider);t?t.options.push(e):B.push({provider:e.provider,options:[e]})}let A=s??(t?$.find(e=>e.modelId===t.modelId&&e.provider===t.provider)?.name??t.modelId:a??($.length>0?"Select model":"No models"));(0,i.useEffect)(()=>{let e=e=>{T.current&&!T.current.contains(e.target)&&M.current&&!M.current.contains(e.target)&&(L(!1),W(""))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,i.useEffect)(()=>{P&&(L(!1),W(""))},[P]);let F="field"===p?{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:P?"var(--bg-panel)":"var(--bg)",color:P?"var(--text-dim)":"var(--text)",cursor:P?"default":"pointer",fontSize:12,textAlign:"left"}:{display:"flex",alignItems:"center",justifyContent:C?"flex-start":void 0,gap:6,width:C?"100%":void 0,maxWidth:C?"100%":220,height:32,padding:C?"8px 10px":"8px 12px",overflow:"hidden",border:"none",borderRadius:9,background:I?"var(--bg-hover)":"none",color:"var(--text-muted)",cursor:P?"not-allowed":"pointer",fontSize:12,opacity:P?.5:1,transition:"background 0.12s, color 0.12s"};return(0,r.jsxs)("div",{ref:T,className:`model-selector is-${p}${P?" is-disabled":""}`,style:{position:"relative",width:"field"===p||C?"100%":void 0,minWidth:0,flex:"toolbar"===p&&C?"1 1 auto":void 0},onKeyDown:e=>{"Escape"===e.key&&!e.nativeEvent.isComposing&&I&&(e.preventDefault(),e.stopPropagation(),W(""),L(!1))},children:[(0,r.jsxs)("button",{type:"button","aria-label":u,"aria-haspopup":"listbox","aria-expanded":I,"aria-busy":d||void 0,disabled:P,title:d?"Switching model":P?A:$.length>0||o?"Change model":"No available models",style:F,onClick:e=>{let t=e.currentTarget.getBoundingClientRect();E({top:t.top,right:t.right,bottom:t.bottom,left:t.left,width:t.width}),L(e=>(e&&W(""),!e))},onMouseEnter:e=>{P||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{if(P){e.currentTarget.style.background="field"===p?"var(--bg-panel)":"none",e.currentTarget.style.color="field"===p?"var(--text-dim)":"var(--text-muted)";return}e.currentTarget.style.background=I?"var(--bg-hover)":"field"===p?"var(--bg)":"none",e.currentTarget.style.color="field"===p?"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:A}),"field"===p&&(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"})})]}),I&&R&&(x=window.visualViewport?.height??window.innerHeight,f=window.visualViewport?.width??window.innerWidth,m=R.top-8,v=x-R.bottom-8,y=Math.max(120,Math.min((b="up"===h||m>v)?m:v,.6*x)),k=b?{bottom:x-R.top+6}:{top:R.bottom+6},j=C?{left:8,right:8,maxWidth:"calc(100vw - 16px)"}:{left:R.left,width:"max-content",minWidth:R.width,maxWidth:Math.max(R.width,f-R.left-8)},(0,r.jsxs)("div",{ref:M,role:"listbox","aria-label":u,style:{position:"fixed",...k,...j,zIndex:500,display:"flex",flexDirection:"column",maxHeight:y,overflow:"hidden",border:"1px solid var(--border)",borderRadius:8,background:"var(--bg)",boxShadow:b?"0 -4px 16px rgba(0,0,0,0.10)":"0 4px 16px rgba(0,0,0,0.10)"},children:[D&&(0,r.jsx)("div",{style:{flexShrink:0,padding:"6px 8px",borderBottom:"1px solid var(--border)"},children:(0,r.jsx)("input",{value:z,onChange:e=>W(e.target.value),placeholder:S("chat.filterModels"),"aria-label":S("chat.filterModels"),autoFocus:!0,autoComplete:"off",spellCheck:!1,style:{boxSizing:"border-box",width:"100%",minWidth:220*!C,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:[o&&!z.trim()&&(0,r.jsx)(nS,{active:!t,label:a??"Default",onClick:()=>{L(!1),W(""),o()}}),0===B.length?(0,r.jsx)("div",{style:{padding:"8px 12px",color:"var(--text-dim)",fontSize:12,whiteSpace:"nowrap"},children:z.trim()?S("chat.noMatchingModels"):"No available models"}):B.map((e,i)=>(0,r.jsxs)("div",{children:[B.length>1&&(0,r.jsx)("div",{style:{padding:"6px 12px 4px",borderTop:i>0||o?"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)(nS,{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(L(!1),W(""),(!r||c)&&n(e.provider,e.modelId))}},`${e.provider}:${e.modelId}`))]},e.provider))]})]}))]})}function nS({active:e,label:t,onClick:n}){return(0,r.jsxs)("button",{type:"button",role:"option","aria-selected":e,onClick:n,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 nC=["read","bash","edit","write","grep","find","ls"],nT=["","off","minimal","low","medium","high","xhigh","max"],nM={name:"custom-agent",displayName:"Custom agent",description:"",systemPrompt:"",tools:["read","bash","edit","write","grep","find","ls"],loadSkills:!1,loadExtensions:!1,promptMode:"append",inheritContext:!1,runInBackground:!1,enabled:!0},nI={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"},nL={background:"var(--bg-panel)",color:"var(--text-dim)",cursor:"default"};function nR(e){return{name:e.name,displayName:e.displayName,description:e.description,systemPrompt:e.systemPrompt,tools:[...e.tools],loadSkills:e.loadSkills,loadExtensions:e.loadExtensions,promptMode:e.promptMode,...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 nE(e){return`${e.scope}:${e.name}`}function nz(e){return"global"===e||"project"===e}function nW(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function nP({label:e,children:t}){return(0,r.jsx)(nh,{label:e,children:t})}function n$({checked:e,disabled:t,label:n,onChange:i}){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=>i(e.target.checked)}),n]})}function nN({cwd:e,sessionId:t=null,onClose:n,onReloaded:o,embedded:a=!1}){let s=(0,tv.a)(),{t:l}=(0,w.s)(),[d,c]=(0,i.useState)([]),[u,p]=(0,i.useState)([]),[h,g]=(0,i.useState)(!0),[x,f]=(0,i.useState)(null),[m,v]=(0,i.useState)(()=>tm("agents",e)),[b,y]=(0,i.useState)(nM),[k,j]=(0,i.useState)("view"),[S,C]=(0,i.useState)("global"),[T,M]=(0,i.useState)(!0),[I,L]=(0,i.useState)(!1),[R,E]=(0,i.useState)(!1),[z,W]=(0,i.useState)(!1),[P,$]=(0,i.useState)(null),[N,D]=(0,i.useState)(!1),[B,A]=(0,i.useState)(10),[F,H]=(0,i.useState)(!0),[O,U]=(0,i.useState)(!1),[_,q]=(0,i.useState)(null),[V,J]=(0,i.useState)(!1),[K,Y]=(0,i.useState)(!1),G=(0,i.useMemo)(()=>d.find(e=>nE(e)===m)??null,[d,m]),X=(0,i.useMemo)(()=>u.map(e=>({provider:e.provider,modelId:e.id,name:e.name})),[u]),Z=(0,i.useCallback)(async t=>{M(!0),$(null);try{let n=await fetch(`/api/subagents/profiles?cwd=${encodeURIComponent(e)}`,{cache:"no-store"}),r=await n.json();if(!n.ok||r.error)throw Error(r.error??`HTTP ${n.status}`);let i=r.profiles??[];c(i);let o=t??tm("agents",e),a=i.find(e=>nE(e)===o)??i.find(e=>"project"===e.scope)??i.find(e=>"global"===e.scope)??i[0]??null;v(a?nE(a):null),a&&(y(nR(a)),j(nz(a.scope)?"edit":"view"),nz(a.scope)&&C(a.scope))}catch(e){$(e instanceof Error?e.message:String(e))}finally{M(!1)}},[e]);(0,i.useEffect)(()=>{Z()},[Z]),(0,i.useEffect)(()=>{let e=new AbortController;return H(!0),q(null),(async()=>{try{let t=await fetch("/api/subagents/settings",{cache:"no-store",signal:e.signal}),n=await t.json();if(!t.ok||n.error||"boolean"!=typeof n.enabled)throw Error(n.error??`HTTP ${t.status}`);D(n.enabled),"number"==typeof n.maxConcurrent&&A(n.maxConcurrent)}catch(t){if(e.signal.aborted)return;q(t instanceof Error?t.message:String(t))}finally{e.signal.aborted||H(!1)}})(),()=>e.abort()},[]),(0,i.useEffect)(()=>{m&&function(e,t,n,r=th()){if(!r||!t)return;let i=tx(e,n);if(i)try{let e=tg(r);e.selections={...e.selections,[i]:t},r.setItem(tu,JSON.stringify(e))}catch{}}("agents",m,e)},[e,m]),(0,i.useEffect)(()=>{let t=new AbortController;return g(!0),f(null),(async()=>{try{let n=await fetch(`/api/models?cwd=${encodeURIComponent(e)}`,{signal:t.signal}),r=await n.json();if(!n.ok||r.error)throw Error(r.error??`HTTP ${n.status}`);p(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 Q=async()=>{L(!0),$(null),E(!1);try{let t=await fetch("/api/subagents/profiles",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,scope:S,profile:b})}),n=await t.json();if(!t.ok||n.error||!n.profile)throw Error(n.error??`HTTP ${t.status}`);await Z(nE(n.profile)),E(!0),setTimeout(()=>E(!1),2e3)}catch(e){$(e instanceof Error?e.message:String(e))}finally{L(!1)}},ee=async()=>{if(G&&nz(G.scope)&&window.confirm(l("agents.deleteConfirm",{name:G.displayName}))){L(!0),$(null);try{let t=await fetch("/api/subagents/profiles",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,scope:G.scope,name:G.name})}),n=await t.json();if(!t.ok||n.error)throw Error(n.error??`HTTP ${t.status}`);await Z()}catch(e){$(e instanceof Error?e.message:String(e))}finally{L(!1)}}},et="view"!==k,en="create"===k,er=!et||I||z,ei=en?S:G?.scope,eo=en?"global"===S?`~/.pi/agent/agents/${b.name||"..."}.md`:`./.pi/agents/${b.name||"..."}.md`:G?function(e,t){if(!e.filePath)return null;if(("project"===e.scope||"workspace"===e.scope)&&e.filePath.startsWith(t)){let n=e.filePath.slice(t.length).replace(/^[/\\]/,"");return`./${n}`}return nW(e.filePath)}(G,e)??l("agents.builtinPath"):"",ea=en?eo:G?.filePath??eo,es=!b.model||u.some(e=>`${e.provider}/${e.id}`===b.model),el=(()=>{if(!b.model)return null;let e=b.model.indexOf("/");return e<0?{provider:"",modelId:b.model}:{provider:b.model.slice(0,e),modelId:b.model.slice(e+1)}})(),ed=er?{...nI,...nL}:nI,ec=(e,t)=>{y(n=>({...n,[e]:t}))},eu=async t=>{if(en)return void ec("enabled",t);if(G&&nz(G.scope)){W(!0),$(null);try{let n=await fetch("/api/subagents/profiles",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,scope:G.scope,name:G.name,enabled:t})}),r=await n.json();if(!n.ok||r.error||!r.profile)throw Error(r.error??`HTTP ${n.status}`);let i=r.profile;c(e=>e.map(e=>nE(e)===nE(i)?i:e)),y(e=>({...e,enabled:i.enabled}))}catch(e){$(e instanceof Error?e.message:String(e))}finally{W(!1)}}},ep=async e=>{U(!0),q(null);try{let n=await fetch("/api/subagents/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:e})}),r=await n.json();if(!n.ok||r.error||"boolean"!=typeof r.enabled)throw Error(r.error??`HTTP ${n.status}`);D(r.enabled),J(!!t)}catch(e){q(e instanceof Error?e.message:String(e))}finally{U(!1)}},eh=async e=>{A(e),q(null);try{let t=await fetch("/api/subagents/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({maxConcurrent:e})}),n=await t.json();if(!t.ok||n.error||"number"!=typeof n.maxConcurrent)throw Error(n.error??`HTTP ${t.status}`);A(n.maxConcurrent)}catch(e){q(e instanceof Error?e.message:String(e))}},eg=async()=>{if(t){Y(!0),q(null);try{await (0,ne.$J)(t,{type:"reload"}),J(!1),o?.()}catch(e){q(e instanceof Error?e.message:String(e))}finally{Y(!1)}}};return(0,r.jsxs)(nn,{embedded:a,title:l("common.agents"),subtitle:nW(e),closeLabel:l("agents.close"),onClose:n,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")}),V&&(0,r.jsx)("span",{role:"status",className:"agents-feature-reload-notice",children:l("agents.reloadRequired")})]}),(0,r.jsxs)("div",{className:"agents-feature-actions",children:[V&&t&&(0,r.jsx)(nm,{size:"small",onClick:()=>void eg(),disabled:K||O,children:K?l("agents.reloading"):l("agents.reloadSession")}),(0,r.jsxs)("label",{className:"agents-concurrency-control",title:l("agents.maxConcurrentDescription"),children:[(0,r.jsx)("span",{children:l("agents.maxConcurrent")}),(0,r.jsx)("input",{"aria-label":l("agents.maxConcurrent"),type:"number",min:1,max:32,value:B,disabled:F||O,onChange:e=>A(Number(e.target.value)),onBlur:()=>void eh(B)})]}),(0,r.jsx)(nv,{checked:N,disabled:F||K,loading:O,label:l("agents.builtInTitle"),onChange:e=>void ep(e)})]})]}),(0,r.jsxs)(nr,{children:[(0,r.jsxs)(ni,{children:[(0,r.jsx)(no,{children:T?(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)(na,{children:l(`agents.scope.${e}`)}),t.map(e=>{let t,n,i=(t=e.name.toLowerCase(),n=nt[e.scope],d.some(e=>e.name.toLowerCase()===t&&nt[e.scope]>n));return(0,r.jsxs)(ns,{active:m===nE(e)&&!en,onClick:()=>{v(nE(e)),y(nR(e)),j(nz(e.scope)?"edit":"view"),nz(e.scope)&&C(e.scope),$(null)},children:[(0,r.jsx)(ny,{active:e.enabled}),(0,r.jsx)(nl,{className:`is-grow${e.enabled?"":" is-muted"}`,children:e.displayName}),i&&(0,r.jsx)("span",{className:"agents-overridden-label",children:l("agents.overridden")})]},nE(e))})]},e)})}),(0,r.jsx)(nb,{active:en,onClick:()=>{let e="custom-agent",t=2;for(;d.some(t=>t.name===e);)e=`custom-agent-${t++}`;v(null),y({...nM,name:e,displayName:e}),j("create"),C("global"),$(null)},children:l("agents.new")})]}),(0,r.jsx)(nx,{children:(0,r.jsx)(nd,{className:"is-fill",children:G||en?(0,r.jsxs)(nd,{children:[(0,r.jsxs)(nc,{children:[(0,r.jsxs)(nu,{children:[ei&&(0,r.jsx)("span",{className:`config-scope-tag${"project"===ei?" is-project":""}`,children:l(`agents.scope.${ei}`)}),(0,r.jsx)("span",{title:ea,className:"config-detail-path",children:eo})]}),(0,r.jsxs)(np,{children:[G&&("view"===k||"edit"===k)&&(0,r.jsx)(nm,{size:"small",onClick:()=>{if(!G)return;let e=function(e,t){let n=new Set(t.map(e=>e.name.toLowerCase())),r=`${e}-copy`,i=r,o=2;for(;n.has(i.toLowerCase());)i=`${r}-${o++}`;return i}(G.name,d);v(null),y({...nR(G),name:e,displayName:l("agents.copyName",{name:G.displayName})}),j("create"),C(nz(G.scope)?G.scope:"global"),$(null)},disabled:I||z,children:l("agents.duplicate")}),G&&nz(G.scope)&&"edit"===k&&(0,r.jsx)(nm,{variant:"danger",size:"small",onClick:()=>void ee(),disabled:I||z,children:l("agents.delete")}),(0,r.jsx)(nv,{checked:b.enabled,disabled:er,label:b.enabled?l("agents.disable"):l("agents.enable"),onChange:e=>void eu(e)})]})]}),en&&(0,r.jsx)(nP,{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:()=>C(e),disabled:I,style:{height:28,border:"none",borderRadius:4,background:S===e?"var(--bg-selected)":"transparent",color:S===e?"var(--text)":"var(--text-muted)",cursor:I?"default":"pointer",fontSize:11,fontWeight:S===e?600:400},children:l(`agents.scope.${e}`)},e))})}),(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:s?"1fr":"minmax(0, 1fr) minmax(0, 1fr)",gap:12},children:[(0,r.jsx)(nP,{label:l("agents.name"),children:en?(0,r.jsx)("input",{"aria-label":l("agents.name"),value:b.name,disabled:er,onChange:e=>ec("name",e.target.value),style:nI}):(0,r.jsx)("code",{style:{minHeight:34,display:"flex",alignItems:"center",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text)",fontSize:12},children:b.name})}),(0,r.jsx)(nP,{label:l("agents.displayName"),children:(0,r.jsx)("input",{"aria-label":l("agents.displayName"),value:b.displayName,disabled:er,onChange:e=>ec("displayName",e.target.value),style:ed})})]}),(0,r.jsx)(nP,{label:l("agents.description"),children:(0,r.jsx)("input",{"aria-label":l("agents.description"),value:b.description,disabled:er,onChange:e=>ec("description",e.target.value),style:ed})}),(0,r.jsx)(nP,{label:l("agents.prompt"),children:(0,r.jsx)("textarea",{className:"agents-system-prompt","aria-label":l("agents.prompt"),value:b.systemPrompt,disabled:er,onChange:e=>ec("systemPrompt",e.target.value),style:{...ed,height:195,minHeight:195,maxHeight:"60vh",padding:9,overflow:"auto",resize:er?"none":"vertical",lineHeight:1.5}})}),(0,r.jsx)(nP,{label:l("agents.tools"),children:(0,r.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px"},children:nC.map(e=>(0,r.jsx)(n$,{label:e,disabled:er,checked:b.tools.includes(e),onChange:t=>ec("tools",t?[...b.tools,e]:b.tools.filter(t=>t!==e))},e))})}),(0,r.jsx)(nP,{label:l("agents.resources"),children:(0,r.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 20px"},children:[(0,r.jsx)(n$,{label:l("agents.loadSkills"),disabled:er,checked:b.loadSkills,onChange:e=>ec("loadSkills",e)}),(0,r.jsx)(n$,{label:l("agents.loadExtensions"),disabled:er,checked:b.loadExtensions,onChange:e=>ec("loadExtensions",e)})]})}),(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:s?"1fr":"minmax(0, 1.5fr) minmax(120px, 0.75fr) minmax(100px, 0.5fr)",gap:12},children:[(0,r.jsx)(nP,{label:l("agents.model"),children:(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)(nj,{options:X,value:el,onChange:(e,t)=>ec("model",`${e}/${t}`),onClear:()=>ec("model",void 0),emptyLabel:h?l("agents.modelsLoading"):l("agents.inherit"),selectedLabel:b.model&&!es?l("agents.modelUnavailable",{model:b.model}):void 0,disabled:er||h||0===u.length&&!b.model,ariaLabel:l("agents.model"),variant:"field",placement:"auto"}),x&&(0,r.jsx)("span",{style:{color:"#ef4444",fontSize:10},children:x})]})}),(0,r.jsx)(nP,{label:l("agents.thinking"),children:(0,r.jsx)("select",{"aria-label":l("agents.thinking"),value:b.thinking??"",disabled:er,onChange:e=>ec("thinking",e.target.value||void 0),style:ed,children:nT.map(e=>(0,r.jsx)("option",{value:e,children:e||l("agents.inherit")},e||"default"))})}),(0,r.jsx)(nP,{label:l("agents.maxTurns"),children:(0,r.jsx)("input",{"aria-label":l("agents.maxTurns"),type:"number",min:1,value:b.maxTurns??"",disabled:er,onChange:e=>ec("maxTurns",e.target.value?Number(e.target.value):void 0),style:ed})})]}),(0,r.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",gap:"10px 20px"},children:[(0,r.jsx)(n$,{label:l("agents.inheritContext"),disabled:er,checked:b.inheritContext,onChange:e=>ec("inheritContext",e)}),(0,r.jsx)(n$,{label:l("agents.background"),disabled:er,checked:b.runInBackground,onChange:e=>ec("runInBackground",e)})]})]}):(0,r.jsx)(ng,{children:l("agents.empty")})})})]}),(0,r.jsx)(nf,{status:(_||P)&&(0,r.jsx)("span",{role:"alert",style:{color:"#ef4444"},children:_||P}),children:et&&(0,r.jsxs)(nm,{variant:"primary",onClick:()=>void Q(),disabled:I||R||z||!b.name.trim(),className:R?"is-success":void 0,children:[R&&(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:R?l("i18n.saved"):I?l("agents.saving"):l("agents.save")})]})})]})}var nD=n(22271);function nB(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function nA(e){let t=e.trim().match(/^\$?\s*pi\s+install\s+(\S+)\s*$/);return t?.[1]??e}function nF(e){return`${e.scope}\0${e.source}`}function nH(e,t){if(e.disabled)return t("i18n.disabled");let n=[e.counts.extensions?t("i18n.resourceCount",{count:e.counts.extensions,label:t("i18n.extensionShort")}):"",e.counts.skills?t("i18n.resourceCount",{count:e.counts.skills,label:t("i18n.skillShort")}):"",e.counts.prompts?t("i18n.resourceCount",{count:e.counts.prompts,label:t("i18n.promptShort")}):"",e.counts.themes?t("i18n.resourceCount",{count:e.counts.themes,label:t("i18n.themeShort")}):""].filter(Boolean);return n.length?n.join(" \xb7 "):t("i18n.noResources")}function nO(e,t){let n=[];return e.version&&n.push(t("i18n.installedVersion",{version:e.version})),e.configuredVersion&&n.push(t("i18n.configuredVersion",{version:e.configuredVersion})),n.length?n.join(" \xb7 "):t("i18n.unknown")}function nU(e){return"loaded"===e?"var(--accent)":"installed"===e?"#f59e0b":"disabled"===e?"var(--text-dim)":"#ef4444"}function n_({pkg:e}){let{t}=(0,w.s)(),n=[["extension",t("i18n.extensions")],["skill",t("i18n.skills")],["prompt",t("i18n.prompts")],["theme",t("i18n.themes")]].map(([t,n])=>({kind:t,label:n,resources:e.resources.filter(e=>e.kind===t)})).filter(e=>e.resources.length>0);return 0===n.length?(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)"},children:t(e.disabled?"i18n.packageDisabled":"i18n.noResolvedResources")}):(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:12},children:n.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 nq({scope:e}){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:e})}function nV(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 nJ({enabled:e,loading:t,onToggle:n,label:i}){return(0,r.jsx)("button",{type:"button",onClick:n,disabled:t,title:i,"aria-label":i,"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 nK({value:e,projectResourcesLoaded:t,onChange:n}){let{t:i}=(0,w.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(o=>{let a=e===o,s="project"===o&&!t;return(0,r.jsx)("button",{onClick:()=>{s||n(o)},disabled:s,title:s?i("trust.projectScopeUnavailable"):void 0,style:{width:76,border:"none",borderRight:"global"===o?"1px solid var(--border)":"none",background:a?"var(--bg-selected)":"none",color:a?"var(--text)":"var(--text-muted)",cursor:s?"not-allowed":"pointer",opacity:s?.45:1,fontSize:12},children:o},o)})})}function nY({cwd:e,source:t,scope:n,projectResourcesLoaded:o,busy:a,actionError:s,onSourceChange:l,onScopeChange:d,onInstall:c}){let{t:u}=(0,w.s)(),p=(0,j.u)(),h=(0,i.useRef)(null);return(0,i.useEffect)(()=>{h.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:u("i18n.addPlugin")}),(0,r.jsxs)("a",{href:"https://pi.dev/packages",target:"_blank",rel:"noopener noreferrer",style:{display:"inline-flex",alignItems:"center",gap:5,color:"var(--accent)",fontSize:12,textDecoration:"none",whiteSpace:"nowrap"},children:[(0,r.jsxs)("svg",{width:"28",height:"28",viewBox:"0 0 800 800","aria-hidden":"true",focusable:"false",style:{flexShrink:0},children:[(0,r.jsx)("path",{fill:"#000",fillRule:"evenodd",d:"M165.29 165.29H517.36V400H400V517.36H282.65V634.72H165.29ZM282.65 282.65V400H400V282.65Z"}),(0,r.jsx)("path",{fill:"#000",d:"M517.36 400H634.72V634.72H517.36Z"})]}),"pi.dev/packages"]})]}),(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:"project"===n?`${nB(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:"Source"}),(0,r.jsx)("input",{id:"plugin-source",ref:h,value:t,onChange:e=>l(e.target.value),onPaste:e=>{let t=(0,nD.Gm)(e.clipboardData),n=t.length>0?t[0]:e.clipboardData.getData("text"),r=nA(n);(r!==n||0!==t.length)&&(e.preventDefault(),l(r))},onBlur:e=>l(nA(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"},...p.compositionProps,onKeyDown:e=>{!p.isIMEBusy(e)&&"Enter"===e.key&&t.trim()&&!a&&c()}})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,r.jsx)(nK,{value:n,projectResourcesLoaded:o,onChange:d}),(0,r.jsx)("button",{type:"button",onClick:c,disabled:a||!t.trim(),style:{...nV(a||!t.trim()),background:"var(--accent)",color:"white",borderColor:"var(--accent)"},children:u(a?"i18n.installing":"i18n.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:"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:()=>l(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))})]}),s&&(0,r.jsx)("div",{style:{fontSize:12,color:"#ef4444",whiteSpace:"pre-wrap"},children:s})]})}function nG({pkg:e,cwd:t,busyKey:n,actionError:i,actionMessage:o,sessionId:a,onAction:s,onReloadSession:l}){let{t:d}=(0,w.s)(),c=nF(e),u=n?.endsWith(c)??!1,p="reload"===n,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)(nJ,{enabled:h,loading:u||p,onToggle:()=>s(e.disabled?"enable":"disable",e),label:d(e.disabled?"i18n.enablePackage":"i18n.disablePackage")}),(0,r.jsx)(nq,{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("i18n.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("i18n.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:()=>s("update",e),disabled:u||p,style:nV(u||p),children:d(n===`update:${c}`?"i18n.updating":"i18n.update")}),(0,r.jsx)("button",{onClick:l,disabled:!a||p||u,style:nV(!a||p||u),title:d(a?"i18n.reloadSession":"i18n.openSessionToReload"),children:d(p?"i18n.reloading":"i18n.reloadSession")}),(0,r.jsx)("button",{onClick:()=>s("remove",e),disabled:u||p,style:nV(u||p,!0),children:d(n===`remove:${c}`?"i18n.removing":"i18n.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("i18n.status")}),(0,r.jsx)("div",{style:{color:nU(e.status),textTransform:"capitalize"},children:e.status}),(0,r.jsx)("div",{style:{color:"var(--text-dim)"},children:d("i18n.version")}),(0,r.jsx)("div",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:nO(e,d)}),(0,r.jsx)("div",{style:{color:"var(--text-dim)"},children:d("i18n.package")}),(0,r.jsx)("div",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)",overflowWrap:"anywhere"},children:e.packageName??d("i18n.unknown")}),(0,r.jsx)("div",{style:{color:"var(--text-dim)"},children:d("i18n.resources")}),(0,r.jsx)("div",{style:{color:"var(--text-muted)"},children:nH(e,d)}),(0,r.jsx)("div",{style:{color:"var(--text-dim)"},children:d("i18n.installedPath")}),(0,r.jsx)("div",{style:{color:e.installedPath?"var(--text-muted)":"#ef4444",fontFamily:"var(--font-mono)",overflowWrap:"anywhere"},children:e.installedPath?nB(e.installedPath):d("i18n.notFound")}),(0,r.jsx)("div",{style:{color:"var(--text-dim)"},children:d("i18n.cwd")}),(0,r.jsx)("div",{style:{color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflowWrap:"anywhere"},children:nB(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("i18n.resolvedResources")}),(0,r.jsx)(n_,{pkg:e})]}),o&&(0,r.jsx)("div",{style:{fontSize:12,color:"#16a34a"},children:o}),i&&(0,r.jsx)("div",{style:{fontSize:12,color:"#ef4444",whiteSpace:"pre-wrap"},children:i})]})}function nX({cwd:e,sessionId:t,onClose:n,onReloaded:o,embedded:a=!1}){let s=(0,tv.a)(),{t:l}=(0,w.s)(),[d,c]=(0,i.useState)(null),[u,p]=(0,i.useState)(!0),[h,g]=(0,i.useState)(null),[x,f]=(0,i.useState)(null),[m,v]=(0,i.useState)(!1),[b,y]=(0,i.useState)(""),[k,j]=(0,i.useState)("global"),[S,C]=(0,i.useState)(null),[T,M]=(0,i.useState)(null),[I,L]=(0,i.useState)(null),R=(0,i.useMemo)(()=>d?.packages??[],[d?.packages]),E=R.find(e=>nF(e)===x)??null,z=d?.projectResourcesLoaded??!0,W=(0,i.useMemo)(()=>["project","global"].map(e=>({scope:e,packages:R.filter(t=>t.scope===e)})).filter(e=>e.packages.length>0),[R]),P=(0,i.useCallback)(async()=>{p(!0),g(null);try{let t=await fetch(`/api/plugins?cwd=${encodeURIComponent(e)}`),n=await t.json();if(!t.ok||n.error)throw Error(n.error??`HTTP ${t.status}`);c(n),v(e=>0===n.packages.length||e),f(e=>e&&n.packages.some(t=>nF(t)===e)?e:n.packages[0]?nF(n.packages[0]):null)}catch(e){g(e instanceof Error?e.message:String(e))}finally{p(!1)}},[e]);(0,i.useEffect)(()=>{P()},[P]);let $=(0,i.useCallback)(async(t,n)=>{let r=nF(n);C(`${t}:${r}`),M(null),L(null);try{let r=await fetch("/api/plugins",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:t,source:n.source,scope:n.scope,cwd:e})}),i=await r.json();if(!r.ok||i.error)throw Error(i.error??`HTTP ${r.status}`);c(i),"remove"===t?(f(i.packages[0]?nF(i.packages[0]):null),0===i.packages.length&&v(!0),L("Package removed.")):L({install:"Package installed.",update:"Package updated.",disable:"Package disabled.",enable:"Package enabled."}[t])}catch(e){M(e instanceof Error?e.message:String(e))}finally{C(null)}},[e]),N=(0,i.useCallback)(async()=>{let t=nA(b).trim();if(!t)return;y(t);let n=`${k}\0${t}`;C(`install:${n}`),M(null),L(null);try{var r;let i,o,a=await fetch("/api/plugins",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"install",source:t,scope:k,cwd:e})}),s=await a.json();if(!a.ok||s.error)throw Error(s.error??`HTTP ${a.status}`);c(s);let l=(r=s.packages,o=(i=t.trim()).startsWith("npm:")?i.slice(4):i,r.find(e=>e.scope===k&&e.source===i)??r.find(e=>e.scope===k&&e.source===`npm:${o}`)??r.find(e=>e.scope===k&&e.source.endsWith(i)));f(l?nF(l):n),v(!1),y(""),L("Package installed.")}catch(e){M(e instanceof Error?e.message:String(e))}finally{C(null)}},[e,k,b]),D=(0,i.useCallback)(async()=>{if(t){C("reload"),M(null),L(null);try{await (0,ne.$J)(t,{type:"reload"}),o?.(),await P(),L("Session reloaded.")}catch(e){M(e instanceof Error?e.message:String(e))}finally{C(null)}}},[P,o,t]),B=S?.startsWith("install:")??!1;return(0,r.jsx)("div",{style:a?{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center"}:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:a?void 0:e=>{e.target===e.currentTarget&&n()},children:(0,r.jsxs)("div",{style:a?{width:"100%",height:"100%",background:"var(--bg)",display:"flex",flexDirection:"column",overflow:"hidden"}:{width:s?"calc(100vw - 16px)":860,maxWidth:"calc(100vw - 16px)",height:s?"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:[!a&&(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("common.plugins")}),(0,r.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:nB(e)})]}),(0,r.jsx)("button",{onClick:n,style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),!z&&(0,r.jsx)("div",{role:"status",style:{padding:"8px 18px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",fontSize:12},children:l("trust.pluginsNotLoaded")}),(0,r.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:s?"column":"row",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{width:s?"100%":245,maxHeight:s?"40vh":void 0,borderRight:s?"none":"1px solid var(--border)",borderBottom:s?"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:u?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:"Loading..."}):h?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"#ef4444"},children:h}):0===R.length?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"var(--text-dim)"},children:"No plugins configured"}):W.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:e.scope}),e.packages.map(e=>{let t=nF(e),n=!m&&x===t;return(0,r.jsxs)("div",{onClick:()=>{f(t),v(!1),M(null),L(null)},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:nU(e.status)}}),(0,r.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,r.jsx)("div",{style:{fontSize:12,fontWeight:n?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:nH(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:nO(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:()=>{v(!0),M(null),L(null)},style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,border:"none",width:"100%",cursor:"pointer",background:m?"var(--bg-selected)":"none",color:m?"var(--accent)":"var(--text-dim)",fontSize:12},onMouseEnter:e=>{m||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{m||(e.currentTarget.style.background="none")},children:[(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,r.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),l("i18n.addPlugin")]})})]}),(0,r.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:m?(0,r.jsx)(nY,{cwd:e,source:b,scope:k,projectResourcesLoaded:z,busy:B,actionError:T,onSourceChange:y,onScopeChange:j,onInstall:N}):u?null:E?(0,r.jsx)(nG,{pkg:E,cwd:e,busyKey:S,actionError:T,actionMessage:I,sessionId:t,onAction:$,onReloadSession:D},nF(E)):(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:l("i18n.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.jsxs)("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:[d.diagnostics.length," diagnostic",1===d.diagnostics.length?"":"s"]}):(0,r.jsx)("span",{children:d?`${d.totals.extensions} ext \xb7 ${d.totals.skills} skills \xb7 ${d.totals.prompts} prompts \xb7 ${d.totals.themes} themes`:""})}),(0,r.jsx)("button",{onClick:()=>void P(),disabled:u||null!==S,style:nV(u||null!==S),children:l("i18n.refresh")}),(0,r.jsx)("button",{onClick:n,style:nV(!1),children:l("i18n.close")})]})]})})}let nZ=[{id:"light",label:"settings.themeLight"},{id:"dark",label:"settings.themeDark"}];function nQ({section:e,size:t=16,strokeWidth:n=1.8}){let i={width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:n,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,className:"settings-section-icon"};return"general"===e?(0,r.jsxs)("svg",{...i,children:[(0,r.jsx)("path",{d:"M20 7h-9M14 17H5"}),(0,r.jsx)("circle",{cx:"7",cy:"7",r:"3"}),(0,r.jsx)("circle",{cx:"17",cy:"17",r:"3"})]}):"models"===e?(0,r.jsxs)("svg",{...i,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)("path",{d:"M9 1v3M15 1v3M9 20v3M15 20v3M20 9h3M20 15h3M1 9h3M1 15h3"})]}):"skills"===e?(0,r.jsxs)("svg",{...i,children:[(0,r.jsx)("path",{d:"m12 2-10 5 10 5 10-5-10-5Z"}),(0,r.jsx)("path",{d:"m2 12 10 5 10-5M2 17l10 5 10-5"})]}):"agents"===e?(0,r.jsxs)("svg",{...i,className:"settings-section-icon is-agent",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.jsx)("svg",{...i,children:(0,r.jsx)("path",{d:"M9 7V2M15 7V2M6 13V8a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v5a6 6 0 0 1-12 0ZM12 19v3"})})}function n0({quoteSelectionEnabled:e,onQuoteSelectionChange:t}){let{locale:n,setLocale:i,supportedLocales:o,t:a}=(0,w.s)(),{preference:s,setPreference:l}=(0,eR.D)(),{width:d,setWidth:c,fontSize:u,setFontSize:p}=(0,td.Uh)();return(0,r.jsxs)("div",{className:"settings-general",children:[(0,r.jsx)("h2",{className:"settings-general-title",children:a("settings.general")}),(0,r.jsxs)("section",{className:"settings-general-section",children:[(0,r.jsx)("h3",{className:"settings-general-heading",children:a("settings.appearance")}),(0,r.jsx)("div",{role:"radiogroup","aria-label":a("settings.appearance"),className:"settings-theme-options",children:nZ.map(e=>{let t=s===e.id;return(0,r.jsxs)("label",{className:"settings-theme-option",children:[(0,r.jsx)("input",{type:"radio",name:"theme",value:e.id,checked:t,onChange:()=>l(e.id),className:"sr-only"}),(0,r.jsx)("span",{className:"settings-theme-option-swatch",style:{background:"dark"===e.id?"#0f172a":"#ffffff",border:"1px solid var(--border)"}}),(0,r.jsx)("span",{className:"settings-theme-option-label",children:a(e.label)})]},e.id)})})]}),(0,r.jsxs)("section",{className:"settings-general-section",children:[(0,r.jsx)("h3",{className:"settings-general-heading",children:a("settings.chat")}),(0,r.jsxs)("div",{className:"settings-chat-options",children:[(0,r.jsxs)("div",{className:"settings-chat-option settings-chat-range-option",children:[(0,r.jsxs)("div",{className:"settings-chat-range-header",children:[(0,r.jsx)("label",{htmlFor:"settings-chat-content-width",children:a("settings.chatContentWidth")}),(0,r.jsxs)("output",{htmlFor:"settings-chat-content-width",children:[d,"px"]}),(0,r.jsx)(nm,{variant:"ghost",size:"small",className:"settings-chat-reset",title:a("settings.resetChatContentWidth"),"aria-label":a("settings.resetChatContentWidth"),disabled:d===td.mi,onClick:()=>c(td.mi),children:(0,r.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8M3 3v5h5"})})})]}),(0,r.jsx)("input",{id:"settings-chat-content-width",type:"range",min:td.lg,max:td.fI,step:10,value:d,onChange:e=>c(Number(e.target.value))})]}),(0,r.jsxs)("div",{className:"settings-chat-option settings-chat-range-option",children:[(0,r.jsxs)("div",{className:"settings-chat-range-header",children:[(0,r.jsx)("label",{htmlFor:"settings-chat-content-font-size",children:a("settings.chatContentFontSize")}),(0,r.jsxs)("output",{htmlFor:"settings-chat-content-font-size",children:[u,"px"]}),(0,r.jsx)(nm,{variant:"ghost",size:"small",className:"settings-chat-reset",title:a("settings.resetChatContentFontSize"),"aria-label":a("settings.resetChatContentFontSize"),disabled:u===td.NN,onClick:()=>p(td.NN),children:(0,r.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8M3 3v5h5"})})})]}),(0,r.jsx)("input",{id:"settings-chat-content-font-size",type:"range",min:td.WH,max:td.Oi,step:1,value:u,onChange:e=>p(Number(e.target.value))})]}),(0,r.jsxs)("div",{className:"settings-chat-option settings-chat-switch-option",children:[(0,r.jsx)("span",{children:a("settings.quoteSelection")}),(0,r.jsx)(nv,{checked:e,label:a("settings.quoteSelection"),onChange:t})]})]})]}),(0,r.jsxs)("section",{className:"settings-general-section",children:[(0,r.jsx)("h3",{className:"settings-general-heading",children:a("common.language")}),(0,r.jsx)("div",{role:"radiogroup","aria-label":a("common.language"),className:"settings-language-options",children:o.map(e=>{let t=n===e.id;return(0,r.jsxs)("button",{type:"button",role:"radio","aria-checked":t,onClick:()=>i(e.id),className:"settings-language-option",children:[(0,r.jsx)("span",{className:"settings-language-radio",children:t&&(0,r.jsx)("span",{className:"settings-language-radio-dot"})}),(0,r.jsx)("span",{className:"settings-language-label",children:e.label}),(0,r.jsx)("span",{className:"settings-language-code",children:e.id})]},e.id)})})]})]})}function n1({cwd:e,sessionId:t,initialSection:n,onClose:o,onSessionReloaded:a,quoteSelectionEnabled:s,onQuoteSelectionChange:l}){let{t:d}=(0,w.s)(),[c,u]=(0,i.useState)(n),[p,h]=(0,i.useState)(()=>new Set([c])),g=[{id:"general",label:d("settings.general"),requiresProject:!1},{id:"models",label:d("common.models"),requiresProject:!1},{id:"skills",label:d("common.skills"),requiresProject:!0},{id:"agents",label:d("common.agents"),requiresProject:!0},{id:"plugins",label:d("common.plugins"),requiresProject:!0}];(0,i.useEffect)(()=>tf(n),[n]),(0,i.useEffect)(()=>{let e=e=>{"Escape"!==e.key||e.isComposing||e.defaultPrevented||(e.preventDefault(),o())};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[o]),(0,i.useEffect)(()=>{e||"skills"!==c&&"agents"!==c&&"plugins"!==c||(u("general"),h(e=>new Set(e).add("general")),tf("general"))},[e,c]);let x=e=>{h(t=>new Set(t).add(e)),u(e),tf(e)},f=(e,t)=>p.has(e)?(0,r.jsx)("div",{hidden:c!==e,className:"settings-section-host",children:t},e):null;return(0,r.jsx)("div",{role:"dialog","aria-modal":"true","aria-label":d("settings.title"),onClick:e=>{e.target===e.currentTarget&&o()},className:"settings-dialog-backdrop",children:(0,r.jsxs)("div",{className:"settings-dialog-surface",children:[(0,r.jsxs)("div",{className:"settings-dialog-header",children:[(0,r.jsx)("strong",{className:"settings-dialog-title",children:d("settings.title")}),(0,r.jsx)("select",{"aria-label":d("settings.title"),value:c,onChange:e=>x(e.target.value),className:"settings-mobile-section-picker",children:g.map(t=>(0,r.jsx)("option",{value:t.id,disabled:t.requiresProject&&!e,children:t.label},t.id))}),(0,r.jsx)("nav",{"aria-label":d("settings.title"),className:"settings-section-tabs",children:g.map(t=>{let n=c===t.id,i=t.requiresProject&&!e;return(0,r.jsxs)("button",{type:"button",className:"settings-section-tab",disabled:i,title:i?d("settings.projectRequired"):t.label,"aria-current":n?"page":void 0,onClick:()=>x(t.id),children:[(0,r.jsx)(nQ,{section:t.id}),(0,r.jsx)("span",{children:t.label})]},t.id)})}),(0,r.jsx)("button",{type:"button",onClick:o,title:d("i18n.close"),"aria-label":d("i18n.close"),className:"config-close-button settings-dialog-close",children:"\xd7"})]}),(0,r.jsxs)("main",{className:"settings-dialog-main",children:[f("general",(0,r.jsx)(n0,{quoteSelectionEnabled:s,onQuoteSelectionChange:l})),f("models",(0,r.jsx)(t0,{embedded:!0,onClose:o})),e&&f("skills",(0,r.jsx)(t9,{embedded:!0,cwd:e,onClose:o},e)),e&&f("agents",(0,r.jsx)(nN,{embedded:!0,cwd:e,sessionId:t,onClose:o,onReloaded:a},e)),e&&f("plugins",(0,r.jsx)(nX,{embedded:!0,cwd:e,sessionId:t,onClose:o,onReloaded:a},e))]})]})})}function n2(e){if("string"==typeof e)return e;if(void 0===e)return"";try{return JSON.stringify(e)}catch{return String(e)}}function n4({children:e}){return(0,r.jsx)("div",{className:"tool-definitions-empty",children:e})}function n8({loading:e,tools:t,translate:n}){let o=(0,i.useMemo)(()=>t?.filter(e=>e.active)??null,[t]),[a,s]=(0,i.useState)(null);(0,i.useEffect)(()=>{s(e=>o?.some(t=>t.name===e)?e:o?.[0]?.name??null)},[o]);let l=o?.find(e=>e.name===a)??o?.[0]??null,d=l?function(e){if(!e||!e.properties||"object"!=typeof e.properties)return[];let t=e.properties,n=new Set(Array.isArray(e.required)?e.required.filter(e=>"string"==typeof e):[]);return Object.entries(t).map(([e,t])=>{let r=t&&"object"==typeof t?t:{};return{name:e,type:function e(t){let n=Array.isArray(t.anyOf)?t.anyOf:Array.isArray(t.oneOf)?t.oneOf:null;if(n)return n.map(t=>t&&"object"==typeof t?e(t):"unknown").filter((e,t,n)=>n.indexOf(e)===t).join(" | ");if(void 0!==t.const)return n2(t.const);if(Array.isArray(t.enum)&&t.enum.length>0&&void 0===t.type)return[...new Set(t.enum.map(e=>null===e?"null":typeof e))].join(" | ");let r=t.type,i=Array.isArray(r)?r.filter(e=>"string"==typeof e).join(" | "):"string"==typeof r?r:"string"==typeof t.$ref?t.$ref.split("/").pop()??"object":"unknown";if("array"===i){let n=t.items,r=n&&"object"==typeof n?e(n):"unknown";return`${r}[]`}return i}(r),description:"string"==typeof r.description?r.description:void 0,required:n.has(e),allowedValues:Array.isArray(r.enum)?r.enum.map(n2).join(", "):void 0,defaultValue:void 0===r.default?void 0:n2(r.default)}})}(l.parameters):[];return(0,r.jsxs)("div",{className:"tool-definitions-panel",children:[(0,r.jsx)("nav",{className:"tool-definitions-sidebar","aria-label":n("tools.title"),children:(0,r.jsx)("div",{className:"tool-definitions-list",children:o&&o.length>0?o.map(e=>{let t=e.name===l?.name;return(0,r.jsx)("button",{type:"button",className:`tool-definitions-item${t?" selected":""}`,"aria-pressed":t,onClick:()=>s(e.name),children:(0,r.jsx)("code",{children:e.name})},e.name)}):o?(0,r.jsx)(n4,{children:n("tools.noTools")}):(0,r.jsx)(n4,{children:e?n("tools.loading"):n("tools.load")})})}),(0,r.jsx)("section",{className:"tool-definition-detail","aria-label":n("tools.details"),children:l?(0,r.jsxs)("div",{className:"tool-definition-scroll",children:[l.description&&(0,r.jsxs)("section",{className:"tool-definition-section",children:[(0,r.jsx)("div",{className:"tool-definition-section-label",children:n("tools.description")}),(0,r.jsx)("div",{className:"tool-definition-description",children:l.description})]}),(0,r.jsxs)("section",{className:"tool-definition-section",children:[(0,r.jsxs)("div",{className:"tool-definition-section-label",children:[(0,r.jsx)("span",{children:n("tools.parameters")}),(0,r.jsx)("span",{children:n("tools.parameterCount",{count:d.length})})]}),d.length>0?(0,r.jsx)("div",{className:"tool-definition-fields",children:d.map(e=>(0,r.jsxs)("div",{className:"tool-definition-field",children:[(0,r.jsxs)("div",{className:"tool-definition-field-name",children:[(0,r.jsx)("code",{children:e.name}),(0,r.jsx)("span",{className:e.required?"required":void 0,children:n(e.required?"tools.required":"tools.optional")})]}),(0,r.jsxs)("div",{className:"tool-definition-field-value",children:[(0,r.jsx)("code",{className:"tool-definition-type",children:e.type}),e.description&&(0,r.jsx)("div",{children:e.description}),e.allowedValues&&(0,r.jsxs)("div",{className:"tool-definition-meta",children:[n("tools.allowedValues"),": ",(0,r.jsx)("code",{children:e.allowedValues})]}),void 0!==e.defaultValue&&(0,r.jsxs)("div",{className:"tool-definition-meta",children:[n("tools.defaultValue"),": ",(0,r.jsx)("code",{children:e.defaultValue})]})]})]},e.name))}):(0,r.jsx)("div",{className:"tool-definition-no-parameters",children:n("tools.noParameters")})]}),l.promptGuidelines&&l.promptGuidelines.length>0&&(0,r.jsxs)("section",{className:"tool-definition-section",children:[(0,r.jsx)("div",{className:"tool-definition-section-label",children:n("tools.guidelines")}),(0,r.jsx)("ul",{className:"tool-definition-guidelines",children:l.promptGuidelines.map((e,t)=>(0,r.jsx)("li",{children:e},`${l.name}:${t}`))})]})]}):(0,r.jsx)(n4,{children:o?n("tools.noTools"):e?n("tools.loading"):n("tools.load")})}),(0,r.jsx)("style",{children:`
|
|
9
|
-
.tool-definitions-panel {
|
|
10
|
-
display: grid;
|
|
11
|
-
grid-template-columns: clamp(112px, 26%, 220px) minmax(0, 1fr);
|
|
12
|
-
height: min(600px, 75dvh);
|
|
13
|
-
min-height: 240px;
|
|
14
|
-
overflow: hidden;
|
|
15
|
-
background: var(--bg-panel);
|
|
16
|
-
border-bottom: 1px solid var(--border);
|
|
17
|
-
}
|
|
18
|
-
.tool-definitions-sidebar,
|
|
19
|
-
.tool-definition-detail {
|
|
20
|
-
display: flex;
|
|
21
|
-
min-width: 0;
|
|
22
|
-
min-height: 0;
|
|
23
|
-
flex-direction: column;
|
|
24
|
-
}
|
|
25
|
-
.tool-definitions-sidebar {
|
|
26
|
-
border-right: 1px solid var(--border);
|
|
27
|
-
background: color-mix(in srgb, var(--bg-panel) 94%, var(--bg));
|
|
28
|
-
}
|
|
29
|
-
.tool-definitions-list,
|
|
30
|
-
.tool-definition-scroll {
|
|
31
|
-
min-height: 0;
|
|
32
|
-
flex: 1;
|
|
33
|
-
overflow: auto;
|
|
34
|
-
}
|
|
35
|
-
.tool-definitions-item {
|
|
36
|
-
display: flex;
|
|
37
|
-
width: 100%;
|
|
38
|
-
min-height: 38px;
|
|
39
|
-
align-items: center;
|
|
40
|
-
padding: 8px 12px;
|
|
41
|
-
border: none;
|
|
42
|
-
border-bottom: 1px solid var(--border);
|
|
43
|
-
background: transparent;
|
|
44
|
-
color: var(--text-muted);
|
|
45
|
-
cursor: pointer;
|
|
46
|
-
text-align: left;
|
|
47
|
-
}
|
|
48
|
-
.tool-definitions-item:hover {
|
|
49
|
-
background: var(--bg-hover);
|
|
50
|
-
color: var(--text);
|
|
51
|
-
}
|
|
52
|
-
.tool-definitions-item.selected {
|
|
53
|
-
background: var(--bg-selected);
|
|
54
|
-
box-shadow: inset 2px 0 0 var(--accent);
|
|
55
|
-
color: var(--text);
|
|
56
|
-
}
|
|
57
|
-
.tool-definitions-item code {
|
|
58
|
-
max-width: 100%;
|
|
59
|
-
color: inherit;
|
|
60
|
-
font-size: 11px;
|
|
61
|
-
font-weight: 600;
|
|
62
|
-
overflow-wrap: anywhere;
|
|
63
|
-
}
|
|
64
|
-
.tool-definition-scroll {
|
|
65
|
-
padding: 14px 16px 20px;
|
|
66
|
-
}
|
|
67
|
-
.tool-definition-section + .tool-definition-section {
|
|
68
|
-
margin-top: 18px;
|
|
69
|
-
}
|
|
70
|
-
.tool-definition-section-label {
|
|
71
|
-
display: flex;
|
|
72
|
-
align-items: center;
|
|
73
|
-
justify-content: space-between;
|
|
74
|
-
gap: 8px;
|
|
75
|
-
margin-bottom: 7px;
|
|
76
|
-
color: var(--text-dim);
|
|
77
|
-
font-size: 11px;
|
|
78
|
-
font-weight: 600;
|
|
79
|
-
}
|
|
80
|
-
.tool-definition-section-label > span:last-child {
|
|
81
|
-
font-weight: 400;
|
|
82
|
-
white-space: nowrap;
|
|
83
|
-
}
|
|
84
|
-
.tool-definition-description {
|
|
85
|
-
color: var(--text-muted);
|
|
86
|
-
font-size: 12px;
|
|
87
|
-
line-height: 1.55;
|
|
88
|
-
overflow-wrap: anywhere;
|
|
89
|
-
white-space: pre-wrap;
|
|
90
|
-
}
|
|
91
|
-
.tool-definition-fields {
|
|
92
|
-
border-top: 1px solid var(--border);
|
|
93
|
-
}
|
|
94
|
-
.tool-definition-field {
|
|
95
|
-
display: grid;
|
|
96
|
-
grid-template-columns: minmax(88px, 0.75fr) minmax(0, 1.5fr);
|
|
97
|
-
gap: 12px;
|
|
98
|
-
padding: 9px 0;
|
|
99
|
-
border-bottom: 1px solid var(--border);
|
|
100
|
-
font-size: 11px;
|
|
101
|
-
line-height: 1.45;
|
|
102
|
-
}
|
|
103
|
-
.tool-definition-field-name {
|
|
104
|
-
display: flex;
|
|
105
|
-
min-width: 0;
|
|
106
|
-
flex-direction: column;
|
|
107
|
-
gap: 3px;
|
|
108
|
-
color: var(--text);
|
|
109
|
-
}
|
|
110
|
-
.tool-definition-field-name code {
|
|
111
|
-
overflow-wrap: anywhere;
|
|
112
|
-
}
|
|
113
|
-
.tool-definition-field-name span {
|
|
114
|
-
color: var(--text-dim);
|
|
115
|
-
font-size: 10px;
|
|
116
|
-
}
|
|
117
|
-
.tool-definition-field-name span.required {
|
|
118
|
-
color: var(--accent);
|
|
119
|
-
}
|
|
120
|
-
.tool-definition-field-value {
|
|
121
|
-
min-width: 0;
|
|
122
|
-
color: var(--text-muted);
|
|
123
|
-
overflow-wrap: anywhere;
|
|
124
|
-
}
|
|
125
|
-
.tool-definition-type {
|
|
126
|
-
display: block;
|
|
127
|
-
margin-bottom: 3px;
|
|
128
|
-
color: var(--text);
|
|
129
|
-
}
|
|
130
|
-
.tool-definition-meta {
|
|
131
|
-
margin-top: 4px;
|
|
132
|
-
color: var(--text-dim);
|
|
133
|
-
}
|
|
134
|
-
.tool-definition-meta code {
|
|
135
|
-
color: var(--text-muted);
|
|
136
|
-
}
|
|
137
|
-
.tool-definition-no-parameters {
|
|
138
|
-
padding: 2px 0 10px;
|
|
139
|
-
color: var(--text-dim);
|
|
140
|
-
font-size: 11px;
|
|
141
|
-
}
|
|
142
|
-
.tool-definition-guidelines {
|
|
143
|
-
margin: 0;
|
|
144
|
-
padding-left: 18px;
|
|
145
|
-
color: var(--text-muted);
|
|
146
|
-
font-size: 11px;
|
|
147
|
-
line-height: 1.5;
|
|
148
|
-
}
|
|
149
|
-
.tool-definitions-empty {
|
|
150
|
-
padding: 14px 12px;
|
|
151
|
-
color: var(--text-muted);
|
|
152
|
-
font-size: 12px;
|
|
153
|
-
font-style: italic;
|
|
154
|
-
overflow-wrap: anywhere;
|
|
155
|
-
}
|
|
156
|
-
@media (max-width: 640px) {
|
|
157
|
-
.tool-definitions-panel {
|
|
158
|
-
grid-template-columns: 112px minmax(0, 1fr);
|
|
159
|
-
}
|
|
160
|
-
.tool-definitions-item {
|
|
161
|
-
padding: 8px 10px;
|
|
162
|
-
}
|
|
163
|
-
.tool-definition-scroll {
|
|
164
|
-
padding: 12px;
|
|
165
|
-
}
|
|
166
|
-
.tool-definition-field {
|
|
167
|
-
grid-template-columns: minmax(74px, 0.7fr) minmax(0, 1.3fr);
|
|
168
|
-
gap: 9px;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
`})]})}function n5({cwd:e,busy:t,error:n,onCancel:i,onConfirm:o}){let{t:a}=(0,w.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||i()},children:(0,r.jsxs)("div",{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.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"#f59e0b",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{flexShrink:0,marginTop:1},children:[(0,r.jsx)("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10Z"}),(0,r.jsx)("path",{d:"m9 12 2 2 4-4"})]}),(0,r.jsxs)("div",{style:{minWidth:0},children:[(0,r.jsx)("div",{id:"project-trust-title",style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:a("trust.dialogTitle")}),(0,r.jsx)("div",{style:{marginTop:7,fontSize:12,lineHeight:1.6,color:"var(--text-muted)"},children:a("trust.dialogBody")}),(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}),n&&(0,r.jsx)("div",{role:"alert",style:{marginTop:10,color:"#ef4444",fontSize:12,lineHeight:1.5},children:n})]})]}),(0,r.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,padding:"10px 18px",borderTop:"1px solid var(--border)"},children:[(0,r.jsx)("button",{type:"button",onClick:i,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:a("trust.cancel")}),(0,r.jsx)("button",{type:"button",onClick:o,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:a(t?"trust.trusting":"trust.trustProject")})]})]})})}function n6(e){return"message"===e.type&&"message"in e}function n3(e){let t=e,n=t.branchPreview,r=n6(t.entry)?t.entry:null,i=t.compressedEntryIds?.length??0;for(;1===t.children.length;)t=t.children[0],n??=t.branchPreview,!r&&n6(t.entry)&&(r=t.entry),i+=1+(t.compressedEntryIds?.length??0);return{node:t,skipped:i,branchPreview:n,labelEntry:r??t.entry}}function n7({node:e,activePathIds:t,depth:n,isLast:i,parentLines:o,onSelect:a}){let{node:s,skipped:l,branchPreview:d,labelEntry:c}=n3(e),u=t.has(s.entry.id),p=t.has(e.entry.id)||t.has(s.entry.id),h=d?.text??function(e){if("message"===e.type&&"message"in e){let t=e.message,n=t.content,r="";if("string"==typeof n?r=n:Array.isArray(n)&&(r=n.filter(e=>"text"===e.type).map(e=>e.text).join(" ")),r.length>40&&(r=r.slice(0,40)+"…"),r)return r;if("assistant"===t.role)return"[assistant]"}return e.type}(c),g=d?d.role??null:n6(c)?c.message.role:null;return(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",height:24,cursor:"pointer"},onClick:()=>a(s.entry.id),children:[o.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:i?"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:u?"var(--accent)":p?"var(--text-muted)":"var(--border)",border:u?"none":"1px solid var(--text-dim)",marginRight:6,transition:"background 0.12s"}}),g&&(0,r.jsx)("span",{style:{fontSize:9,fontFamily:"var(--font-mono)",color:"user"===g?"var(--accent)":"var(--text-dim)",background:"user"===g?"rgba(37,99,235,0.08)":"var(--bg-hover)",border:`1px solid ${"user"===g?"rgba(37,99,235,0.2)":"var(--border)"}`,borderRadius:3,padding:"0 4px",marginRight:5,flexShrink:0,lineHeight:"16px"},children:"user"===g?"U":"A"}),l>0&&(0,r.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",marginRight:5,flexShrink:0},children:["+",l]}),(0,r.jsx)("span",{style:{fontSize:11,color:u?"var(--text)":p?"var(--text-muted)":"var(--text-dim)",fontWeight:u?500:400,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,minWidth:0},children:h})]}),s.children.map((e,l)=>(0,r.jsx)(n7,{node:e,activePathIds:t,depth:n+1,isLast:l===s.children.length-1,parentLines:[...o,!i],onSelect:a},e.entry.id))]})}function n9({tree:e,activeLeafId:t,onLeafChange:n,inline:a,containerRef:s,open:l,onToggle:d,hasSession:c,compact:u,hideInlineButton:p,portalDropdown:h=!1,dropdownWidth:g}){let{t:x}=(0,w.s)(),[f,m]=(0,i.useState)(!1),v=void 0!==l?l:f,b=(0,i.useRef)(null),[y,k]=(0,i.useState)(null);(0,i.useEffect)(()=>{if(!v||!a)return;let e=s?.current??b.current;if(!e)return;let t=()=>{let t=e.getBoundingClientRect(),n=e.closest?.("[data-session-titlebar]"),r=n?.getBoundingClientRect();k({top:r?r.bottom:t.bottom,left:r?r.left:t.left,width:g??t.width})};t();let n=new ResizeObserver(t);return n.observe(e),e.closest?.("[data-session-titlebar]")&&n.observe(e.closest("[data-session-titlebar]")),()=>n.disconnect()},[v,a,s,g]);let j=(0,i.useMemo)(()=>(function(e,t){if(!t)return new Set;let n=e.map(e=>({node:e,path:[e.entry.id]}));for(;n.length>0;){let{node:e,path:r}=n.pop();if(e.entry.id===t||e.compressedEntryIds?.includes(t))return new Set(r);for(let t of e.children)n.push({node:t,path:[...r,t.entry.id]})}return new Set})(e,t),[e,t]),S=(0,i.useCallback)(e=>{n(e)},[n]),C=c?!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 n of e.children)t.push(n)}return!1}(e)?x("i18n.noBranches"):null:x("i18n.noActiveSession"),T=function(e){if(e.length>1)return e;if(0===e.length)return[];let t=n3(e[0]).node;return t.children.length>1?t.children:[]}(e),M=!C&&T.length>0,I=(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:M?"var(--accent)":"var(--text-dim)",flexShrink:0},children:[(0,r.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,r.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,r.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,r.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),L=(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{marginLeft:2,transform:v?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,r.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})});if(a){let e=v&&y?(0,r.jsx)("div",{style:{position:"fixed",top:y.top,left:y.left,width:y.width,zIndex:500,borderRadius:"0 0 12px 12px",border:"1px solid color-mix(in srgb, var(--border) 60%, transparent)",borderTop:"none"},className:"glass-panel",children:M?(0,r.jsx)("div",{style:{padding:"4px 12px 8px 12px",maxHeight:260,overflowY:"auto"},children:T.map((e,t)=>(0,r.jsx)(n7,{node:e,activePathIds:j,depth:0,isLast:t===T.length-1,parentLines:[],onSelect:S},e.entry.id))}):(0,r.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:C})}):null;return(0,r.jsxs)("div",{style:{height:"100%",display:"flex",alignItems:"stretch",borderRight:p?"none":"1px solid var(--border)"},children:[(0,r.jsxs)("button",{ref:b,"data-top-panel-trigger":!0,onClick:()=>d?d():m(e=>!e),style:{display:p?"none":"flex",alignItems:"center",alignSelf:"center",gap:4,height:26,padding:"0 6px",background:v?"color-mix(in srgb, var(--glass-bg-strong) 60%, transparent)":"transparent",border:"none",borderRadius:6,cursor:"pointer",color:v?"var(--accent)":"var(--text-muted)",fontSize:11,fontWeight:600,whiteSpace:"nowrap",transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="color-mix(in srgb, var(--glass-bg-strong) 40%, transparent)"},onMouseLeave:e=>{e.currentTarget.style.color=v?"var(--accent)":"var(--text-muted)",e.currentTarget.style.background=v?"color-mix(in srgb, var(--glass-bg-strong) 60%, transparent)":"transparent"},title:x("i18n.branches"),"aria-label":x("i18n.branches"),"aria-pressed":v,children:[I,!u&&(0,r.jsx)("span",{children:x("i18n.branches")})]}),h?(0,o.createPortal)(e,document.body):e]})}return(0,r.jsxs)("div",{style:{borderBottom:"1px solid var(--border)",background:"var(--bg)",flexShrink:0,position:"relative"},children:[(0,r.jsxs)("button",{onClick:()=>m(e=>!e),style:{display:"flex",alignItems:"center",gap:6,width:"100%",padding:"5px 12px",background:"none",border:"none",cursor:"pointer",color:"var(--text)",fontSize:11,textAlign:"left"},children:[I,(0,r.jsx)("span",{style:{color:"var(--text)"},children:x("i18n.branches")}),L]}),v&&(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:M?(0,r.jsx)("div",{style:{padding:"4px 12px 8px 12px",maxHeight:260,overflowY:"auto"},children:T.map((e,t)=>(0,r.jsx)(n7,{node:e,activePathIds:j,depth:0,isLast:t===T.length-1,parentLines:[],onSelect:S},e.entry.id))}):(0,r.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:C??x("i18n.noBranches")})})]})}function re({onSelectSession:e,onOpenBoard:t}){let{t:n}=(0,w.s)(),s=(0,tv.a)();(0,a.useRouter)();let[l,d]=(0,i.useState)(""),[c,u]=(0,i.useState)(null),[p,h]=(0,i.useState)(!1),[g,x]=(0,i.useState)(!1),[f,m]=(0,i.useState)(!1),[v,b]=(0,i.useState)(null),y=(0,i.useRef)(null),k=(0,i.useRef)(null),j=(0,i.useRef)(null),S=(0,i.useRef)(null);(0,i.useEffect)(()=>{if(!g||!y.current||s)return;let e=()=>{let e=y.current?.getBoundingClientRect();e&&b({top:e.bottom+4,left:e.left,width:Math.max(320,e.width)})};e();let t=new ResizeObserver(e);return t.observe(document.documentElement),window.addEventListener("resize",e),window.addEventListener("scroll",e,!0),()=>{t.disconnect(),window.removeEventListener("resize",e),window.removeEventListener("scroll",e,!0)}},[g,s]),(0,i.useEffect)(()=>{if(!l.trim())return;let e=l.trim(),t=setTimeout(()=>{S.current?.abort();let t=new AbortController;S.current=t,x(!0),h(!0),fetch(`/api/search?q=${encodeURIComponent(e)}&limit=20`,{signal:t.signal}).then(e=>e.ok?e.json():null).then(e=>{e&&(u(e.results??[]),h(e.indexing))}).catch(()=>{}).finally(()=>{t.signal.aborted||h(!1)})},350);return()=>clearTimeout(t)},[l,s]),(0,i.useEffect)(()=>{f&&setTimeout(()=>j.current?.focus(),0)},[f]);let C=(0,i.useCallback)(()=>{x(!1),m(!1),d(""),u(null)},[]);(0,i.useEffect)(()=>{if(!g&&!f)return;let e=e=>{let t=e.target;k.current?.contains(t)||y.current?.contains(t)||j.current?.closest("[data-mobile-search]")?.contains(t)||C()},t=e=>{"Escape"===e.key&&C()};return document.addEventListener("mousedown",e,!0),document.addEventListener("keydown",t,!0),()=>{document.removeEventListener("mousedown",e,!0),document.removeEventListener("keydown",t,!0)}},[g,f,C]);let T=(0,i.useCallback)(t=>{C(),e(t)},[C,e]),M=(0,i.useCallback)(e=>{C(),t?.(e.boardId)},[C,t]),I=(e,t)=>(0,r.jsx)("div",{ref:k,className:"glass-top-panel",style:{overflow:"hidden",maxHeight:"min(420px, 60vh)",display:"flex",flexDirection:"column"},children:t?(0,r.jsx)("div",{style:{padding:"10px 14px",fontSize:12,color:"var(--text-muted)"},children:n("search.indexing")}):null===e||0===e.length?(0,r.jsx)("div",{style:{padding:"10px 14px",fontSize:12,color:"var(--text-muted)"},children:l.trim()?n("search.noResults"):n("search.empty")}):(0,r.jsxs)("div",{style:{overflowY:"auto"},children:[e.some(e=>"task-card"===e.kind)&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{style:{padding:"6px 12px 2px",fontSize:10,fontWeight:700,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:.5},children:n("search.taskCards")}),e.filter(e=>"task-card"===e.kind).map(e=>{let t=e.card;return(0,r.jsxs)("button",{type:"button",onClick:()=>M(t),style:{display:"block",width:"100%",padding:"8px 12px",background:"none",border:"none",borderBottom:"1px solid var(--border)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,minWidth:0},children:[e.titleMatch&&(0,r.jsx)("span",{style:{flexShrink:0,fontSize:9,fontFamily:"var(--font-mono)",color:"var(--accent)",background:"var(--side-selected)",border:"1px solid color-mix(in srgb, var(--accent) 30%, transparent)",borderRadius:3,padding:"0 4px",lineHeight:"15px"},children:n("search.title")}),(0,r.jsxs)("span",{style:{flexShrink:0,fontSize:10,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:["#",t.number]}),(0,r.jsx)("span",{style:{flex:1,minWidth:0,fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:500},children:t.name})]}),e.snippet&&(0,r.jsx)("div",{style:{marginTop:3,fontSize:11,color:"var(--text-muted)",lineHeight:1.5,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.snippet})]},`task-${t.id}`)})]}),e.some(e=>"session"===e.kind)&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{style:{padding:"6px 12px 2px",fontSize:10,fontWeight:700,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:.5},children:n("search.sessions")}),e.filter(e=>"session"===e.kind).map(e=>{let t=e.result.session,i=t.name||t.firstMessage.slice(0,50)||t.id.slice(0,12);return(0,r.jsxs)("button",{type:"button",onClick:()=>T(t),style:{display:"block",width:"100%",padding:"8px 12px",background:"none",border:"none",borderBottom:"1px solid var(--border)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,minWidth:0},children:[e.result.titleMatch&&(0,r.jsx)("span",{style:{flexShrink:0,fontSize:9,fontFamily:"var(--font-mono)",color:"var(--accent)",background:"var(--side-selected)",border:"1px solid color-mix(in srgb, var(--accent) 30%, transparent)",borderRadius:3,padding:"0 4px",lineHeight:"15px"},children:n("search.title")}),(0,r.jsx)("span",{style:{flex:1,minWidth:0,fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:500},children:i}),(0,r.jsx)("span",{style:{flexShrink:0,fontSize:10,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:t.cwd.split(/[\\/]/).filter(Boolean).pop()})]}),e.result.snippet&&(0,r.jsx)("div",{style:{marginTop:3,fontSize:11,color:"var(--text-muted)",lineHeight:1.5,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:function(e){if(!e)return null;let t=e.split(/([\[\]])/g),n=!1;return t.map((e,t)=>"["===e?(n=!0,null):"]"===e?(n=!1,null):e?n?(0,r.jsx)("mark",{style:{background:"color-mix(in srgb, var(--accent) 22%, transparent)",color:"var(--text)",borderRadius:2},children:e},t):(0,r.jsx)("span",{children:e},t):null)}(e.result.snippet)})]},t.id)})]})]})});return s?(0,r.jsxs)("div",{"data-mobile-search":!0,style:{height:"100%",display:"flex",alignItems:"stretch",position:"relative",flexShrink:0},children:[(0,r.jsx)("button",{type:"button",onClick:()=>m(e=>!e),title:n("search.placeholder"),"aria-label":n("search.placeholder"),"aria-expanded":f,style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:"100%",padding:0,background:f?"var(--bg-selected)":"none",border:"none",borderRight:"1px solid var(--border)",color:f?"var(--text)":"var(--text-muted)",cursor:"pointer"},children:(0,r.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"11",cy:"11",r:"7"}),(0,r.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}),f&&(0,o.createPortal)((0,r.jsxs)("div",{style:{position:"fixed",top:0,left:0,right:0,zIndex:480,background:"var(--frame-glass)",backdropFilter:"blur(var(--glass-blur-heavy)) saturate(var(--glass-saturate))",WebkitBackdropFilter:"blur(var(--glass-blur-heavy)) saturate(var(--glass-saturate))",borderBottom:"1px solid var(--border)",boxShadow:"0 10px 28px rgba(0,0,0,0.14)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"8px 10px"},children:[(0,r.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-muted)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,r.jsx)("circle",{cx:"11",cy:"11",r:"7"}),(0,r.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),(0,r.jsx)("input",{ref:j,value:l,onChange:e=>d(e.target.value),placeholder:n("search.placeholder"),style:{width:"100%",height:"100%",padding:"0 8px",border:"none",outline:"none",background:"var(--glass-bg-input)",color:"var(--text)",fontSize:12,flex:1,background:"transparent"}}),(0,r.jsx)("button",{type:"button",onClick:C,style:{flexShrink:0,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:12,padding:"4px 6px"},children:n("sidebar.cancel")})]}),l.trim()&&I(c,p)]}),document.body)]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{ref:y,onMouseEnter:e=>{g||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{g||(e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)")},style:{position:"relative",height:"100%",display:"flex",alignItems:"center",gap:6,flexShrink:0,width:190,padding:"0 12px",borderRight:"1px solid var(--border)",background:g?"var(--bg-selected)":"transparent",color:g?"var(--text)":"var(--text-muted)",cursor:"text",transition:"background 0.12s, color 0.12s"},children:[(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},"aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"11",cy:"11",r:"7"}),(0,r.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),(0,r.jsx)("input",{value:l,onChange:e=>{d(e.target.value),u(null)},onFocus:()=>x(!0),placeholder:n("search.placeholder"),style:{flex:1,minWidth:0,height:"100%",padding:0,border:"none",outline:"none",background:"transparent",color:"inherit",fontSize:12}})]}),g&&v&&(0,o.createPortal)((0,r.jsx)("div",{style:{position:"fixed",top:v.top,left:v.left,width:v.width,zIndex:520},children:I(c,p)}),document.body)]})}var rt=n(59185),rn=n(36268);function rr(e,t,n){let r=Number.isFinite(e)?e:t,i=Math.max(t,n);return Math.round(Math.max(t,Math.min(i,r)))}function ri(e,t){try{window.localStorage.setItem(e,String(t))}catch{}}function ro(e){let{ariaLabel:t,cssVariable:n,defaultWidth:r,getDefaultWidth:o,getMaxWidth:a,growthDirection:s,maxWidth:l,minWidth:d,storageKey:c,widthRef:u}=e,p=(0,i.useRef)(null),h=(0,i.useRef)(null),g=(0,i.useRef)(!1),[x,f]=(0,i.useState)(r),[m,v]=(0,i.useState)(!1),[b,y]=(0,i.useState)(!1);(0,i.useEffect)(()=>{y(!0)},[]);let k=(0,i.useCallback)(()=>Math.min(l,Math.max(d,a())),[a,l,d]),w=(0,i.useCallback)(e=>rr(e,d,k()),[k,d]),j=(0,i.useCallback)(e=>{u.current=e,p.current?.style.setProperty(n,`${e}px`)},[n,u]),S=(0,i.useCallback)((e,t={})=>{let{forcePersist:n=!1,persist:r=!0}=t,i=w(e),o=i!==u.current;return j(i),f(i),r&&(o||n)&&ri(c,i),i},[j,w,c,u]),C=(0,i.useCallback)(e=>{document.body.style.cursor=e.previousCursor,document.body.style.userSelect=e.previousUserSelect},[]),T=(0,i.useCallback)(e=>{let t=h.current;if(t&&t.pointerId===e){h.current=null,C(t),v(!1),S(u.current,{forcePersist:!0});try{t.target.hasPointerCapture(e)&&t.target.releasePointerCapture(e)}catch{}}},[S,C,u]),M=(0,i.useCallback)(e=>{if("mouse"===e.pointerType&&0!==e.button)return;e.preventDefault(),e.stopPropagation();let t=h.current;t&&T(t.pointerId);let n=e.currentTarget;n.focus({preventScroll:!0}),n.setPointerCapture(e.pointerId),h.current={pointerId:e.pointerId,startX:e.clientX,startWidth:u.current,target:n,previousCursor:document.body.style.cursor,previousUserSelect:document.body.style.userSelect},document.body.style.cursor="col-resize",document.body.style.userSelect="none",v(!0)},[T,u]),I=(0,i.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 n="right"===s?1:-1,r=w(t.startWidth+(e.clientX-t.startX)*n);j(r),e.currentTarget.setAttribute("aria-valuenow",String(r)),e.currentTarget.setAttribute("aria-valuetext",`${r} px`)},[j,w,T,s]),L=(0,i.useCallback)(e=>{T(e.pointerId)},[T]),R=(0,i.useCallback)(e=>{T(e.pointerId)},[T]),E=(0,i.useCallback)(e=>{T(e.pointerId)},[T]),z=(0,i.useCallback)(()=>{S(o?.()??r,{forcePersist:!0})},[S,r,o]),W=(0,i.useCallback)(()=>{S(u.current)},[S,u]),P=(0,i.useCallback)(e=>{let t=e.shiftKey?32:12,n="right"===s?"ArrowRight":"ArrowLeft",r="right"===s?"ArrowLeft":"ArrowRight";e.key===n?(e.preventDefault(),S(u.current+t,{forcePersist:!0})):e.key===r?(e.preventDefault(),S(u.current-t,{forcePersist:!0})):"Home"===e.key?(e.preventDefault(),S(d,{forcePersist:!0})):"End"===e.key?(e.preventDefault(),S(k(),{forcePersist:!0})):"Enter"===e.key&&(e.preventDefault(),z())},[S,k,s,d,z,u]);return(0,i.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 n=Number.parseInt(t,10);return Number.isFinite(n)?n:null}catch{return null}}(c),t=S(e??o?.()??r,{persist:!1});null!==e&&e!==t&&ri(c,t)},[S,r,o,c]),(0,i.useEffect)(()=>{if(!g.current)return;S(u.current);let e=()=>{S(u.current)};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[S,u]),(0,i.useEffect)(()=>{if(!m)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,m]),(0,i.useEffect)(()=>()=>{let e=h.current;e&&(h.current=null,C(e))},[C]),{isResizing:m,panelRef:p,reclampWidth:W,resetWidth:z,separatorProps:{"aria-label":t,"aria-orientation":"vertical","aria-valuemax":b?k():l,"aria-valuemin":d,"aria-valuenow":x,"aria-valuetext":`${x} px`,onDoubleClick:z,onKeyDown:P,onLostPointerCapture:E,onPointerCancel:R,onPointerDown:M,onPointerMove:I,onPointerUp:L,role:"separator",tabIndex:0},width:x}}var ra=n(32782);let rs="bg-image",rl="wallpaper";function rd(){return new Promise((e,t)=>{let n=indexedDB.open("pi-web",1);n.onupgradeneeded=()=>{n.result.objectStoreNames.contains(rs)||n.result.createObjectStore(rs)},n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)})}let rc=null,ru=null;async function rp(e){let t;if("image/gif"===e.type)return null;if("image/webp"===e.type||"image/avif"===e.type)return e;try{t=await createImageBitmap(e)}catch{return e}try{let n=document.createElement("canvas");n.width=t.width,n.height=t.height;let r=n.getContext("2d");if(!r)return e;r.drawImage(t,0,0);let i=await new Promise(e=>n.toBlob(e,"image/png"));if(!i)return e;return i.size<e.size?i:e}finally{t.close()}}function rh(e){rc&&URL.revokeObjectURL(rc),ru=e&&e.type.startsWith("image/")?"image":null,rc=e?URL.createObjectURL(e):null;let t=document.documentElement.style;return"image"===ru&&rc?t.setProperty("--app-bg-image",`url("${rc}")`):t.setProperty("--app-bg-image","none"),{url:rc,kind:ru}}async function rg(){try{let e=await rd(),t=await new Promise((t,n)=>{let r=e.transaction(rs,"readonly").objectStore(rs).get(rl);r.onsuccess=()=>t(r.result??null),r.onerror=()=>n(r.error)});if(!t)return{loaded:!1,...rh(null)};return{loaded:!0,...rh(t)}}catch{return{loaded:!1,...rh(null)}}}async function rx(e){let t=await rd();await new Promise((n,r)=>{let i=t.transaction(rs,"readwrite"),o=i.objectStore(rs);e?o.put(e,rl):o.delete(rl),i.oncomplete=()=>n(),i.onerror=()=>r(i.error)})}let rf={repeat:!1,offsetX:0,fill:!1,fillColorLeft:"#000000",fillColorRight:"#000000",bubbleOpacity:44,bubbleBlur:8,scrimAlpha:0,scrimBlur:0},rm="wallpaper-settings";async function rv(e){try{let t=await createImageBitmap(e),n=Math.max(1,Math.round(8*t.width/t.height)),r=document.createElement("canvas");r.width=n,r.height=8;let i=r.getContext("2d",{willReadFrequently:!0});if(!i)return null;i.drawImage(t,0,0,n,8);let o=e=>{let t=i.getImageData(e,0,1,8).data,n=0,r=0,o=0;for(let e=0;e<8;e++)n+=t[4*e],r+=t[4*e+1],o+=t[4*e+2];return`rgb(${Math.round(n/8)}, ${Math.round(r/8)}, ${Math.round(o/8)})`},a={left:o(0),right:o(n-1)};return t.close(),a}catch{return null}}var rb=n(7834),ry=n(3099),rk=n(4325);let rw=(0,s.default)(()=>Promise.all([n.e(1838),n.e(3888),n.e(3266)]).then(n.bind(n,83266)).then(e=>e.TerminalPanel),{loadableGenerated:{webpack:()=>[83266]},ssr:!1}),rj=(0,s.default)(()=>Promise.all([n.e(1375),n.e(3862),n.e(3546),n.e(2619),n.e(97),n.e(752)]).then(n.bind(n,60752)).then(e=>e.SessionCanvas),{loadableGenerated:{webpack:()=>[60752]},ssr:!1,loading:()=>(0,r.jsx)(eT.N,{label:"正在加载画布…"})});function rS(){return new URLSearchParams(window.location.search).get("board")}function rC({label:e,icon:t,value:n,min:o,max:a,unit:s,onCommit:l,preview:d}){let[c,u]=(0,i.useState)(n),p=(0,i.useRef)(null);(0,i.useEffect)(()=>u(n),[n]);let h=()=>{p.current&&l(Number(p.current.value))};return(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 10px",color:"var(--text)",border:"1px solid var(--border)",borderRadius:8,fontSize:12.5},children:[(0,r.jsx)("span",{style:{width:14,flexShrink:0,textAlign:"center",fontSize:12},children:t}),(0,r.jsx)("span",{style:{flexShrink:0},children:e}),(0,r.jsx)("input",{ref:p,type:"range",min:o,max:a,defaultValue:n,onChange:e=>{let t=Number(e.target.value);u(t),d?.(t)},onMouseUp:h,onTouchEnd:h,onKeyUp:e=>{e.key.startsWith("Arrow")&&h()},style:{flex:1,minWidth:0,accentColor:"var(--accent)",cursor:"pointer"},"aria-label":e}),(0,r.jsxs)("span",{style:{width:30,flexShrink:0,textAlign:"right",fontSize:11,color:"var(--text-dim)"},children:[c,s]})]})}function rT(e){document.documentElement.style.setProperty("--bubble-alpha",String(e/100))}function rM(){let e,t,n,s,c,p,v,b,y,k,j,S,C,T=(0,a.useRouter)(),M=(0,a.useSearchParams)(),[L]=(0,i.useState)(()=>{let e;return{requestedCwd:e=M.get("cwd")?.trim()||null,sessionId:e?null:M.get("session"),boardId:M.get("board")?.trim()||null}}),{preference:R,toggleTheme:E}=(0,eR.D)();(0,td.Uh)();let{hasBg:z,ready:W,pick:P,remove:$,kind:N,url:D}=function(){let[e,t]=(0,i.useState)(!1),[n,r]=(0,i.useState)(!1),[o,a]=(0,i.useState)(null),[s,l]=(0,i.useState)(null);return(0,i.useEffect)(()=>{let e=!0;return rg().then(n=>{e&&(t(n.loaded),l(n.url),a(n.kind),r(!0))}),()=>{e=!1}},[]),{hasBg:e,ready:n,pick:(0,i.useCallback)(async e=>{let n=await rp(e);if(!n)return;await rx(n);let r=rh(n);l(r.url),a(r.kind),t(!0)},[]),remove:(0,i.useCallback)(async()=>{await rx(null),rh(null),l(null),a(null),t(!1)},[]),kind:o,url:s}}(),{settings:B,update:A}=function(e){let[t,n]=(0,i.useState)(()=>(function(){try{let e=localStorage.getItem(rm);if(!e)return{...rf};return{...rf,...JSON.parse(e)}}catch{return{...rf}}})());return(0,i.useEffect)(()=>{let n;(n=document.documentElement.style).setProperty("--app-bg-repeat",t.repeat?"repeat-x":"no-repeat"),n.setProperty("--app-bg-size","cover"),n.setProperty("--app-bg-pos-x",`calc(50% + ${Math.round(t.offsetX)}px)`),n.setProperty("--bubble-alpha",String(t.bubbleOpacity/100)),n.setProperty("--glass-blur-bubble",`${Math.round(t.bubbleBlur)}px`),n.setProperty("--board-scrim-alpha",String(t.scrimAlpha/100)),n.setProperty("--board-scrim-blur",`${Math.round(t.scrimBlur)}px`),n.setProperty("--board-scrim-filter",t.scrimBlur>0?`blur(${Math.round(t.scrimBlur)}px)`:"none"),t.fill&&!t.repeat&&e?n.setProperty("--app-bg-fill",`linear-gradient(90deg, ${t.fillColorLeft}, ${t.fillColorLeft} 50%, ${t.fillColorRight} 50%, ${t.fillColorRight})`):n.removeProperty("--app-bg-fill")},[t,e]),{settings:t,update:(0,i.useCallback)(e=>n(t=>{let n={...t,...e};try{localStorage.setItem(rm,JSON.stringify(n))}catch{}return n}),[])}}(z&&"image"===N),F=(0,d.qE)(z&&"image"===N);(0,d.mf)(D,"image"===N,{offsetX:B.offsetX,repeat:B.repeat,fill:B.fill,bubbleBlur:B.bubbleBlur,scrimBlur:B.scrimBlur},F);let[H,O]=(0,i.useState)(!1);(0,i.useEffect)(()=>{if(!H)return;let e=document.body.style.userSelect;document.body.style.userSelect="none";let t=e=>{"Escape"===e.key&&O(!1)};return window.addEventListener("keydown",t),()=>{document.body.style.userSelect=e,window.removeEventListener("keydown",t)}},[H]);let U="light"===R?"theme.light":"theme.dark",{locale:_,setLocale:q,t:V,supportedLocales:J}=(0,w.s)(),K=(0,tv.a)();(0,i.useEffect)(()=>{let e=window.visualViewport;if(!e)return;let t=document.documentElement,n=null,r=()=>{let r;n=null,!function({hasFocusedEditable:e,innerHeight:t,viewportHeight:n,viewportScale:r}){let i=.01>Math.abs(r-1);return e&&i&&t-n>1}({hasFocusedEditable:(r=document.activeElement)instanceof HTMLElement&&(r.isContentEditable||"INPUT"===r.tagName||"SELECT"===r.tagName||"TEXTAREA"===r.tagName),innerHeight:window.innerHeight,viewportHeight:e.height,viewportScale:e.scale})?t.style.removeProperty("--app-viewport-height"):t.style.setProperty("--app-viewport-height",`${e.height}px`);let i=0!==window.scrollX||0!==window.scrollY,o=.01>Math.abs(e.scale-1);i&&o&&window.scrollTo(0,0)},i=()=>{null!==n&&window.cancelAnimationFrame(n),n=window.requestAnimationFrame(r)};return i(),e.addEventListener("resize",i),e.addEventListener("scroll",i),window.addEventListener("resize",i),window.addEventListener("focusin",i),window.addEventListener("focusout",i),window.addEventListener("pageshow",i),()=>{e.removeEventListener("resize",i),e.removeEventListener("scroll",i),window.removeEventListener("resize",i),window.removeEventListener("focusin",i),window.removeEventListener("focusout",i),window.removeEventListener("pageshow",i),null!==n&&window.cancelAnimationFrame(n),t.style.removeProperty("--app-viewport-height")}},[]);let{soundEnabled:Y,onSoundToggle:G,playDoneSound:X,unlockAudio:Z,soundEnabledRef:Q}=(0,ra.G)(),ee=(0,i.useRef)(new Set),et=(0,i.useRef)(new Set),en=(0,i.useCallback)(e=>{if(e&&e.length>0){let t=et.current,n=e.every(e=>t.has(e));for(let n of e)t.delete(n);if(n)return}Q.current&&X()},[X,Q]),er=(0,eC.I9)(),[ei,eo]=(0,i.useState)(null),[ea,es]=(0,i.useState)(()=>new Set),[el,ec]=(0,i.useState)(()=>L.boardId),[eu,ep]=(0,i.useState)(null),eh=(0,i.useCallback)(e=>{es(t=>t.size===e.size&&[...e].every(e=>t.has(e))?t:e)},[]),eg=(0,i.useCallback)(e=>{ec(e),ep(null),eo(null),t1(null),t5([]),nu(null),ng(null),T.replace(`?board=${encodeURIComponent(e)}`,{scroll:!1})},[T]),[ex,ef]=(0,i.useState)(null),[em,ev]=(0,i.useState)(()=>(0,u.S)()),eb=(0,i.useRef)(null),[ey,ek]=(0,i.useState)(()=>L.requestedCwd?"validating":"idle"),[ej,eT]=(0,i.useState)(null),[eM,eI]=(0,i.useState)(0),[eL,eE]=(0,i.useState)(0),[ez,eW]=(0,i.useState)(0),[eP,e$]=(0,i.useState)(0),[eN,eD]=(0,i.useState)(null),[eB,eA]=(0,i.useState)(!1),[eF,eH]=(0,i.useState)(!1),[eO,eU]=(0,i.useState)(null),[e_,eq]=(0,i.useState)(!0),[eV,eJ]=(0,i.useState)(!1),[eK,eY]=(0,i.useState)("top"),[eG,eX]=(0,i.useState)(null),eZ=(0,i.useRef)(null),[eQ,e0]=(0,i.useState)(null),[e1,e2]=(0,i.useState)(null),[e4,e8]=(0,i.useState)(!1),[e5,e3]=(0,i.useState)(!1),[e9,te]=(0,i.useState)(null);(0,i.useEffect)(()=>{try{e3("true"===localStorage.getItem("pi-quote-selection-enabled"))}catch{}},[]);let tt=(0,i.useCallback)(e=>{e3(e);try{localStorage.setItem("pi-quote-selection-enabled",String(e))}catch{}},[]),[tn,tr]=(0,i.useState)(!1),[ti,to]=(0,i.useState)(!1),[ta,ts]=(0,i.useState)(!1),tu=(0,i.useRef)(null),tx=(0,i.useRef)(null),tf=(0,i.useRef)(null),[tm,tb]=(0,i.useState)(null),[ty,tk]=(0,i.useState)(!1),tw=(0,i.useRef)(260),tj=(0,i.useRef)(560),tS=(0,i.useCallback)(()=>rr(.42*window.innerWidth,360,640),[]),tC=(0,i.useCallback)(()=>(function(e){let{viewportWidth:t,rightPanelOpen:n,rightPanelWidth:r}=e;if(t<=640)return 480;let i=t<960;return Math.min(480,t-(i?320:420)-(!i&&n?r:0))})({viewportWidth:window.innerWidth,rightPanelOpen:tn,rightPanelWidth:tj.current}),[tn]),tT=(0,i.useCallback)(()=>(function(e){let{viewportWidth:t,sidebarOpen:n,sidebarWidth:r}=e;return t<960?1200:Math.min(1200,t-420-(n?r:0))})({viewportWidth:window.innerWidth,sidebarOpen:e_,sidebarWidth:tw.current}),[e_]),tM=ro({ariaLabel:V("layout.resizeSidebar"),cssVariable:"--sidebar-width",defaultWidth:260,getMaxWidth:tC,growthDirection:"right",maxWidth:480,minWidth:180,storageKey:"pi-sidebar-width",widthRef:tw}),tI=ro({ariaLabel:V("layout.resizeFilePanel"),cssVariable:"--right-panel-width",defaultWidth:560,getDefaultWidth:tS,getMaxWidth:tT,growthDirection:"left",maxWidth:1200,minWidth:300,storageKey:"pi-right-panel-width",widthRef:tj}),tL=tM.reclampWidth,tR=tI.reclampWidth;(0,i.useEffect)(()=>{K&&eq(!1)},[K]);let tE=(0,i.useCallback)(e=>{let t=e.currentTarget.getBoundingClientRect(),n=t.left;n+264>window.innerWidth-8&&(n=Math.max(8,window.innerWidth-264-8)),tb({left:n,top:t.bottom}),ts(e=>!e)},[]);(0,i.useEffect)(()=>{if(!ta)return;let e=e=>{tu.current&&!tu.current.contains(e.target)&&tf.current&&!tf.current.contains(e.target)&&ts(!1)},t=e=>{"Escape"===e.key&&ts(!1)};return document.addEventListener("mousedown",e,!0),document.addEventListener("keydown",t,!0),()=>{document.removeEventListener("mousedown",e,!0),document.removeEventListener("keydown",t,!0)}},[ta]),(0,i.useEffect)(()=>{tk(!0)},[]),(0,i.useEffect)(()=>{tn&&(tL(),tR())},[tR,tL,tn]);let tz=(0,i.useRef)(null),tW=(0,i.useRef)(null),tP=(0,i.useRef)(null),t$=(0,i.useRef)(null),[tN,tD]=(0,i.useState)([]),[tB,tA]=(0,i.useState)(null),tF=(0,i.useRef)(null),tH=(0,i.useRef)(null),tO=(0,i.useRef)(!1),tU=(0,i.useCallback)((e,t,n)=>{tD(e),tA(t),tF.current=n},[]),t_=(0,i.useCallback)(e=>{tF.current?.(e)},[]),[tq,tV]=(0,i.useState)(null),[tJ,tK]=(0,i.useState)(!1),tY=(0,i.useRef)(null),tG=(0,i.useRef)(0),tX=(0,i.useRef)(null),tZ=(0,i.useCallback)(e=>{tV(e),tK(!1)},[]),tQ=(0,i.useCallback)(e=>{tG.current+=1,tY.current=e,tK(!1)},[]),[t0,t1]=(0,i.useState)(null),[t2,t4]=(0,i.useState)(null),[t8,t5]=(0,i.useState)([]),[t6,t3]=(0,i.useState)(!1),[t7,t9]=(0,i.useState)(null),nt=(0,i.useRef)(null),nn=(0,i.useRef)(null),nr=(0,i.useCallback)(e=>{t1(e)},[]),ni=(0,i.useCallback)(e=>{t5(e)},[]),no=(0,i.useCallback)(async e=>{try{let t=await fetch(`/api/sessions/${encodeURIComponent(e)}/todos`);if(!t.ok)return;let n=await t.json();Array.isArray(n.todos)&&t5(n.todos)}catch{}},[]),[na,ns]=(0,i.useState)(null),nl=(0,i.useRef)(null),nd=(0,i.useCallback)((e,t)=>{(0,rb.D)(t).then(()=>{nl.current&&clearTimeout(nl.current),ns(e),nl.current=setTimeout(()=>ns(null),1400)})},[]);(0,i.useEffect)(()=>()=>{nl.current&&clearTimeout(nl.current)},[]);let[nc,nu]=(0,i.useState)(null),np=(0,i.useCallback)(e=>{nu(e)},[]),[nh,ng]=(0,i.useState)(null),[nx,nf]=(0,i.useState)(null),nm=(0,i.useRef)(null);(0,i.useEffect)(()=>{if("session"!==nh||!ei?.id)return void t4(null);let e=!1;return t4(null),fetch(`/api/sessions/${encodeURIComponent(ei.id)}`,{cache:"no-store"}).then(e=>e.ok?e.json():null).then(t=>{e||t4(t?.info?.taskName??null)}).catch(()=>{}),()=>{e=!0}},[nh,ei?.id]);let nv=(0,i.useCallback)((e,t=!1)=>{K&&eq(!1),t3(!1),ng(t=>t===e?null:e),K&&t&&to(!0)},[K]),nb=(0,i.useCallback)((e=!1)=>{let t="system"!==nh;if(nv("system",e),!t||tJ)return;let n=tY.current;if(!n)return;let r=++tG.current;tK(!0),n().catch(e=>{console.error("Failed to load system prompt:",e)}).finally(()=>{tG.current===r&&tK(!1)})},[nh,tJ,nv]),ny=(0,i.useCallback)(()=>{K&&eq(!1),to(!1),t3(!1),ng("session")},[K]),nk=(0,i.useCallback)(()=>{K&&eq(!1),to(!1),ng(null),!t6&&ei?.id&&no(ei.id),t3(e=>!e)},[K,t6,ei?.id,no]);(0,i.useEffect)(()=>{if(!t6||!nt.current)return;let e=()=>{let e=nt.current;if(!e)return;let t=e.getBoundingClientRect();t9({top:t.bottom,right:Math.max(8,Math.round(window.innerWidth-t.right))})};e();let t=new ResizeObserver(e);t.observe(document.documentElement);let n=nt.current.parentElement;for(;n;)t.observe(n),n=n.parentElement;return window.addEventListener("resize",e),window.addEventListener("scroll",e,!0),()=>{t.disconnect(),window.removeEventListener("resize",e),window.removeEventListener("scroll",e,!0)}},[t6]),(0,i.useEffect)(()=>{if(!t6)return;let e=e=>{let t=e.target;nt.current?.contains(t)||nn.current?.contains(t)||t3(!1)},t=e=>{"Escape"===e.key&&t3(!1)};return document.addEventListener("pointerdown",e,!0),document.addEventListener("keydown",t,!0),()=>{document.removeEventListener("pointerdown",e,!0),document.removeEventListener("keydown",t,!0)}},[t6]),(0,i.useEffect)(()=>{if(!eV)return;let e=()=>{let e="top"===eK?eZ.current:document.getElementById("terminal-bottombar-btn");if(!e)return;let t=e.getBoundingClientRect();eX({top:t.top,left:t.left,right:t.right,bottom:t.bottom})};e();let t=new ResizeObserver(e);return t.observe(document.documentElement),window.addEventListener("resize",e),window.addEventListener("scroll",e,!0),()=>{t.disconnect(),window.removeEventListener("resize",e),window.removeEventListener("scroll",e,!0)}},[eV,eK]);let nw=(0,i.useCallback)(e=>{eY(e),eJ(t=>e!==eK||!t)},[eK]);(0,i.useEffect)(()=>{if(!nh)return;let e=e=>{let t=e.target;nm.current?.contains(t)||t.closest?.("button[data-top-panel-trigger]")||ng(null)},t=e=>{"Escape"===e.key&&ng(null)};return document.addEventListener("pointerdown",e,!0),document.addEventListener("keydown",t,!0),()=>{document.removeEventListener("pointerdown",e,!0),document.removeEventListener("keydown",t,!0)}},[nh]);let nj=(0,i.useCallback)(()=>{K&&(ng(null),t3(!1),to(!1)),eq(e=>!e)},[K]),nS=(0,i.useCallback)(()=>{eq(!1),ng(null),t3(!1),to(e=>!e)},[]),nC=(0,i.useCallback)(()=>{K&&(eq(!1),ng(null),to(!1)),tr(e=>!e)},[K]);(0,i.useEffect)(()=>{if(!ti)return;let e=e=>{let t=tP.current;t&&e.composedPath().includes(t)||to(!1)},t=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),to(!1))};return document.addEventListener("pointerdown",e,!0),document.addEventListener("keydown",t,!0),()=>{document.removeEventListener("pointerdown",e,!0),document.removeEventListener("keydown",t,!0)}},[ti]),(0,i.useEffect)(()=>{to(!1)},[K,ei?.id,em]),(0,i.useEffect)(()=>{if(!nh||!tW.current)return;let e=()=>{let e=tW.current.getBoundingClientRect();if("language"===nh&&!K&&t$.current){let t=t$.current.getBoundingClientRect(),n=Math.min(176,e.width),r=Math.min(t.left-1,Math.max(e.left,e.right-n));nf({top:e.bottom,left:r,width:n});return}nf({top:e.bottom,left:e.left,width:e.width})};e();let t=new ResizeObserver(e);return t.observe(tW.current),t$.current&&t.observe(t$.current),()=>t.disconnect()},[nh,K]);let[nT,nM]=(0,i.useState)([]),[nI,nL]=(0,i.useState)(null),nR=(0,i.useCallback)((e,t,n)=>{nM(r=>(function(e,t,n,r){let i=e.findIndex(e=>e.id===t);if(-1===i||(e[i].viewerRevision??0)!==n)return e;let o=[...e];return o[i]={...o[i],viewerState:r},o})(r,e,t,n))},[]),nE=(0,i.useCallback)((e,t)=>{tz.current?.insertText((0,ry.$C)(e,t)),K&&(tr(!1),eq(!1))},[K]),nz=(0,i.useCallback)(e=>{let t=(0,ry.SO)(e);t&&tz.current?.insertText(t),K&&(tr(!1),eq(!1))},[K]),nW=(0,i.useCallback)((e,t,n)=>{tz.current?.insertText((0,ry.sn)(e,t,n)),K&&(tr(!1),eq(!1))},[K]),nP=L.sessionId,[n$,nN]=(0,i.useState)(null),[nD,nB]=(0,i.useState)(null),nA=(0,i.useRef)(null),[nF,nH]=(0,i.useState)(()=>!nP),nO=(0,i.useRef)(!1),nU=(0,i.useRef)(0),n_=(0,i.useCallback)(()=>{nU.current+=1},[]);(0,i.useEffect)(()=>{ei&&function(e,t,n=g()){if(n)try{let r=x(n);r[e]=t,n.setItem(h,JSON.stringify(r))}catch{}}(ei.projectKey??nA.current??m(ei),ei.id)},[ei]),(0,i.useEffect)(()=>{let e=L.requestedCwd;if(!e)return;let t=new AbortController;return ek("validating"),eT(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}`);nO.current=!0,ev((0,u.S)()),eb.current=null,ef(t.cwd),ek("ready")}).catch(e=>{t.signal.aborted||(eT(e instanceof Error?e.message:String(e)),ek("error"))}),()=>t.abort()},[L]);let nq=(0,i.useCallback)(e=>{if(rS())return;let t=++nU.current,n=function(e,t=g()){if(!t)return null;try{let n=x(t)[e];return"string"==typeof n&&n.length>0?n:null}catch{return null}}(e);n&&fetch(`/api/sessions/${encodeURIComponent(n)}?deferThinking=1`).then(n=>404===n.status?(t===nU.current&&f(e),null):n.ok?n.json():null).then(n=>{if(t!==nU.current||!n)return;let r=n.info;if(r&&r.id){if(m(r)!==e)return void f(e);eo(r),eE(e=>e+1),new URLSearchParams(window.location.search).get("session")!==r.id&&T.replace(`?session=${encodeURIComponent(r.id)}`,{scroll:!1})}}).catch(()=>{})},[T]),nV=(0,i.useCallback)((e,t,n)=>{n_();let r=ex??n$;if(nN(e),!e)return;let i=n??t??e,o=nA.current??(ei?m(ei):null);if(nA.current=i,nO.current){nO.current=!1;return}r===e&&o!==i||o===i&&(null!==ei||r===e)||(ev((0,u.S)()),eb.current=null,eo(null),ef(t=>t&&t!==e?null:t),eE(e=>e+1),tD([]),tA(null),tV(null),tK(!1),ng(null),o!==i&&(nM([]),nL(null),tr(!1),tO.current?tO.current=!1:nq(i)),T.replace(function(){let e=rS();if(!e)return"/";let t="/".replace(/^\?/,"");if(!t||"/"===t)return`?board=${encodeURIComponent(e)}`;let n=new URLSearchParams(t);return n.set("board",e),`?${n.toString()}`}(),{scroll:!1}))},[n$,n_,ex,T,ei,nq]),nJ=(0,i.useCallback)((e,t=!1)=>{if(n_(),eb.current=null,!t&&ei){let t=m(ei)===m(e);if(ei.id===e.id&&t){K&&eq(!1);return}}ef(null),eo(e),ec(null),eE(e=>e+1),tV(null),tK(!1),nH(!0),K&&!t&&eq(!1),t&&(nO.current=!0),t||T.replace(`?session=${encodeURIComponent(e.id)}`,{scroll:!1})},[n_,T,K,ei]),nK=(0,i.useCallback)(e=>{tO.current=!0,nJ(e)},[nJ]),nY=(0,i.useCallback)((e,t)=>{n_(),eb.current=e,ev(e),eo(null),ef(t),eE(e=>e+1),tD([]),tA(null),tV(null),tK(!1),ng(null),ec(null),K&&eq(!1),T.replace("/",{scroll:!1})},[n_,T,K]),nG=(0,i.useCallback)((e,t)=>{let n=ei?.cwd??ex??n$;if(!n)return;let r=(0,u.S)();tH.current={taskId:e,projectKey:t,draftId:r},nY(r,n)},[ei?.cwd,ex,n$,nY]),nX=(0,i.useCallback)((e,t)=>{ef(e),nN(e),t&&nB(t)},[]),nZ=(0,i.useRef)(nX);nZ.current=nX;let n0=(0,i.useCallback)(e=>{fetch(`/api/tasks/${encodeURIComponent(e)}/board`,{cache:"no-store"}).then(e=>e.ok?e.json():null).then(t=>{t?.board?.id&&(eg(t.board.id),ep(e))}).catch(()=>{})},[eg]);(0,l.n)({onNewSession:e=>nY(`kb-${Date.now()}`,e),activeCwd:n$});let n2=(0,i.useRef)([]),n4=(0,i.useRef)(null),n6=(0,i.useCallback)(e=>{let t=n2.current.find(t=>t.id===e);t?eo(n=>n?.id===e?{...n,...t,transient:t.transient??!1}:n):n4.current=e},[]),n3=(0,i.useCallback)(e=>{n2.current=e;let t=n4.current;if(!t)return;let n=e.find(e=>e.id===t);n&&(n4.current=null,eo(e=>e?.id===t?{...e,...n,transient:n.transient??!1}:e))},[]),n7=(0,i.useCallback)((e,t)=>{eI(e=>e+1),eb.current===t&&(n_(),eb.current=null,ef(null),eo(e),n6(e.id),T.replace(`?session=${encodeURIComponent(e.id)}`,{scroll:!1}),tH.current=null)},[n_,T,n6]),ri=(0,i.useCallback)(({targetSession:e,title:t,body:n,tag:r})=>{if(!("Notification"in window))return;let i=()=>{let i=e?`/?session=${encodeURIComponent(e.id)}`:"/";(0,rk.dL)({title:t,body:n,sessionUrl:i,tag:r,onClick:()=>{window.focus(),e&&nJ(e)}})};"granted"===Notification.permission?i():"default"===Notification.permission&&Notification.requestPermission().then(e=>{"granted"===e&&i()})},[nJ]),rs=(0,i.useCallback)(()=>{eI(e=>e+1),eW(e=>e+1),ei&&n6(ei.id),(0,rk.SH)()&&ri({targetSession:ei,title:ei?.name??V("i18n.sessionComplete"),body:V("i18n.taskFinished")})},[ri,n6,ei,V]),rl=(0,i.useCallback)(e=>{!(0,rk.SH)()||(0,rk.$N)(e,ee.current)&&ri({targetSession:ei,title:V("i18n.attentionNeeded"),body:"custom"===e.method?V("i18n.extensionInputNeeded"):e.title,tag:`pi-extension-ui:${e.id}`})},[ri,ei,V]);(0,i.useEffect)(()=>{t3(!1);let e=ei?.id;e&&no(e)},[ei?.id,no]),(0,i.useEffect)(()=>{0===t8.length&&t3(!1)},[t8.length]);let rd=(0,i.useCallback)(()=>{eW(e=>e+1)},[]),rc=(0,i.useCallback)(e=>{n_(),eb.current=null,eI(e=>e+1),eE(e=>e+1),ef(null),eo(t=>({...t??{path:"",cwd:"",created:"",modified:"",messageCount:0,firstMessage:""},id:e,transient:!1})),n6(e),T.replace(`?session=${encodeURIComponent(e)}`,{scroll:!1})},[n_,T,n6]),ru=(0,i.useCallback)(async(e,t,n)=>{let r=await (0,ne.$J)(t,{type:"fork_branch",entryId:n});if(!r?.newSessionId)throw Error(V("chat.quoteForkFailed"));te({sessionId:r.newSessionId,text:e}),rc(r.newSessionId)},[rc,V]),rM=(0,i.useCallback)(()=>{nH(!0)},[]),rI=(0,i.useCallback)(e=>{if(n_(),eI(e=>e+1),ei?.id===e){let e=ei.cwd;ev((0,u.S)()),eb.current=null,eo(null),ef(e??null),eE(e=>e+1),tD([]),tA(null),tV(null),tK(!1),ng(null),T.replace("/",{scroll:!1})}},[n_,ei,T]),rL=(0,i.useCallback)((e,t,n)=>{let r=n?.sourceSessionId,i=n?.modeHint,o=`file:${e}`;nM(n=>(function(e,t){let n=e.find(e=>e.id===t.tabId);if(!n)return[...e,{id:t.tabId,label:t.fileName,filePath:t.filePath,sourceSessionId:t.sourceSessionId,initialDisplayMode:t.modeHint,viewerState:t.modeHint?{displayMode:t.modeHint,wrapLines:!1,scrollTop:0,scrollLeft:0}:void 0,viewerRevision:0}];let r=!!(t.sourceSessionId&&n.sourceSessionId!==t.sourceSessionId);return r||t.modeHint?e.map(e=>{if(e.id!==t.tabId)return e;let n={...e};return r&&(n.sourceSessionId=t.sourceSessionId),t.modeHint?(n.initialDisplayMode=t.modeHint,n.viewerState={displayMode:t.modeHint,wrapLines:e.viewerState?.wrapLines??!1,scrollTop:0,scrollLeft:0},n.viewerRevision=(e.viewerRevision??0)+1):r&&(n.viewerRevision=(e.viewerRevision??0)+1),n}):e})(n,{fileName:t,filePath:e,modeHint:i,sourceSessionId:r,tabId:o})),nL(o),tr(!0),K&&eq(!1)},[K]),rR=(0,i.useCallback)(e=>{rL(e,(0,I.WP)(e),{sourceSessionId:ei?.id??null})},[rL,ei?.id]);(0,i.useEffect)(()=>{let e=e=>{let t=e.detail;t?.filePath&&rL(t.filePath,(0,I.WP)(t.filePath),{sourceSessionId:t.sessionId})},t=e=>{let t=e.detail;t?.newSessionId&&(eI(e=>e+1),eW(e=>e+1))},n=e=>{let t=e.detail;t?.sessionId&&(eI(e=>e+1),eW(e=>e+1))},r=()=>{eI(e=>e+1)},i=e=>{let t=e.detail;t?.sessionId&&eI(e=>e+1)},o=e=>{let t=e.detail;if(!t?.sessionId)return;let n=et.current;if(n.add(t.sessionId),n.size>100)for(let e of[...n].slice(0,n.size-100))n.delete(e);eI(e=>e+1),eW(e=>e+1),(0,rk.SH)()&&ri({targetSession:null,title:t.sessionName??V("i18n.sessionComplete"),body:V("i18n.taskFinished")})},a=e=>{let t=e.detail;!t?.sessionId||(0,rk.SH)()&&ri({targetSession:null,title:V("i18n.attentionNeeded"),body:t.title??V("i18n.extensionInputNeeded"),tag:`pi-extension-ui:${t.sessionId}`})},s=e=>{let t=e.detail;t?.cwd&&nZ.current(t.cwd)};return window.addEventListener("pi-web:board-open-file",e),window.addEventListener("pi-web:board-cwd-switch",s),window.addEventListener("pi-web:board-session-forked",t),window.addEventListener("pi-web:board-session-created",n),window.addEventListener("pi-web:board-session-renamed",i),window.addEventListener("pi-web:board-tasks-changed",r),window.addEventListener("pi-web:board-agent-end",o),window.addEventListener("pi-web:board-attention-needed",a),()=>{window.removeEventListener("pi-web:board-open-file",e),window.removeEventListener("pi-web:board-cwd-switch",s),window.removeEventListener("pi-web:board-session-forked",t),window.removeEventListener("pi-web:board-session-created",n),window.removeEventListener("pi-web:board-session-renamed",i),window.removeEventListener("pi-web:board-tasks-changed",r),window.removeEventListener("pi-web:board-agent-end",o),window.removeEventListener("pi-web:board-attention-needed",a)}},[ri,rL,V]);let rE=(0,i.useCallback)(e=>{nM(t=>{let n=t.filter(t=>t.id!==e);return 0===n.length&&tr(!1),n}),nL(t=>{if(t!==e)return t;let n=nT.filter(t=>t.id!==e);return n.length>0?n[n.length-1].id:null})},[nT]),rz=(0,i.useCallback)(()=>{ei&&window.open(`/api/sessions/${encodeURIComponent(ei.id)}/export?inline=1`,"_blank","noopener,noreferrer")},[ei]),rW=ex??(null===ei&&n$?n$:null),rP=null===ei&&null!==rW,r$=rP?em:null,rN=tH.current,rD=rP&&rN?.draftId===em?rN.taskId??null:null,rB=nA.current??rW,rA=rP?rD?`task_${rD}`:`tmp_new_${rB}`:null;(0,i.useLayoutEffect)(()=>{eb.current=r$},[r$]);let rF=null!==ei||null!==rW,rH=ei?.cwd??rW,rO=nF&&!rF;(0,i.useEffect)(()=>{if(eD(null),eA(!1),eU(null),!rH)return;let e=new AbortController;return fetch(`/api/project-trust?cwd=${encodeURIComponent(rH)}`,{signal:e.signal}).then(async e=>{let t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);eD(t)}).catch(e=>{e instanceof DOMException&&"AbortError"===e.name||console.error("Failed to load project trust:",e)}),()=>e.abort()},[rH]);let rU=(0,i.useCallback)(async()=>{if(rH&&!eF){eH(!0),eU(null);try{let e=await fetch("/api/project-trust",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:rH})}),t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);eD(t),eA(!1),e$(e=>e+1),eE(e=>e+1)}catch(e){eU(e instanceof Error?e.message:String(e))}finally{eH(!1)}}},[eF,rH]),r_=nT.find(e=>e.id===nI)??null,rq="Pi Web";(0,i.useEffect)(()=>{let e=()=>{document.title!==rq&&(document.title=rq)};e();let t=new MutationObserver(e);return t.observe(document.head,{childList:!0,subtree:!0,characterData:!0}),()=>t.disconnect()},[rq]);let rV=(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(ed,{selectedSessionId:ei?.id??null,onSelectSession:nJ,onNewSession:nY,initialSessionId:nP,skipInitialProjectSelection:null!==L.requestedCwd,onInitialRestoreDone:rM,refreshKey:eM,onSessionDeleted:rI,selectedCwd:ei?.cwd??ex??null,activeWorktreeProject:nD,onCwdChange:nV,onOpenFile:rL,explorerRefreshKey:ez,onExplorerRefresh:rd,onRefresh:()=>eI(e=>e+1),onSessionsLoaded:n3,onAtMention:nE,onAtMentions:nz,onBackgroundTaskDone:en,onRunningSessionIdsChange:eh,onNewSessionFromTask:nG,onOpenBoard:eg,onOpenTaskBoard:n0,onExitBoard:()=>ec(null),activeBoardId:el}),(0,r.jsx)("div",{style:{position:"absolute",left:0,right:0,bottom:0,padding:"8px",display:"flex",justifyContent:"space-between",gap:4,zIndex:5},children:[{label:V("common.models"),onClick:()=>e0("models"),disabled:!1,icon:(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",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"})]})},{label:V("common.skills"),onClick:()=>e0("skills"),disabled:!rH,icon:(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),(0,r.jsx)("path",{d:"M2 17l10 5 10-5"}),(0,r.jsx)("path",{d:"M2 12l10 5 10-5"})]})},{label:V("common.settings"),onClick:()=>e0(function(e,t=th()){if(!t)return"general";try{let n=tg(t).section;if(!("string"==typeof n&&tc.includes(n)))return"general";return tp.has(n)&&!e?"general":n}catch{return"general"}}(rH)),disabled:!1,icon:(0,r.jsx)(nQ,{section:"general",size:14,strokeWidth:2})}].map(({label:e,onClick:t,disabled:n,icon:i})=>(0,r.jsxs)("button",{onClick:t,disabled:n,title:e,style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",gap:6,height:32,padding:0,background:"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:n?"default":"pointer",fontSize:12,opacity:n?.35:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{n||(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,e]},e))})]}),rJ=e=>(0,r.jsx)("button",{type:"button",onClick:t=>{let n=t.currentTarget.getBoundingClientRect();E({x:n.left+n.width/2,y:n.top+n.height/2}),e&&to(!0)},title:V(U),"aria-label":V(U),style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"none",border:"none",borderRight:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)"},"data-mobile-toolbar-action":e?"theme":void 0,children:"light"===R?(0,r.jsxs)("svg",{width:"16",height:"16",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:"5"}),(0,r.jsx)("line",{x1:"12",y1:"1",x2:"12",y2:"3"}),(0,r.jsx)("line",{x1:"12",y1:"21",x2:"12",y2:"23"}),(0,r.jsx)("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"}),(0,r.jsx)("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"}),(0,r.jsx)("line",{x1:"1",y1:"12",x2:"3",y2:"12"}),(0,r.jsx)("line",{x1:"21",y1:"12",x2:"23",y2:"12"}),(0,r.jsx)("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"}),(0,r.jsx)("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"})]}):"dark"===R?(0,r.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"})}):(0,r.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2"}),(0,r.jsx)("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),(0,r.jsx)("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]})}),rK=e=>(0,r.jsx)("button",{ref:tf,type:"button",onClick:t=>{tE(t),e&&to(!0)},title:V("bg.title"),"aria-label":V("bg.title"),"aria-haspopup":"menu","aria-expanded":ta,style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:ta?"var(--bg-selected)":"none",border:"none",borderRight:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)"},"data-mobile-toolbar-action":e?"bg":void 0,children:(0,r.jsxs)("span",{style:{position:"relative",display:"inline-flex"},children:[(0,r.jsxs)("svg",{width:"16",height:"16",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:"3",width:"18",height:"18",rx:"2"}),(0,r.jsx)("circle",{cx:"8.5",cy:"8.5",r:"1.5"}),(0,r.jsx)("path",{d:"M21 15l-5-5L5 21"})]}),z&&(0,r.jsx)("span",{"aria-label":V("bg.title"),title:V("bg.title"),style:{position:"absolute",top:-2,right:-2,width:7,height:7,borderRadius:"50%",background:"var(--accent)",boxShadow:"0 0 0 2px var(--bg-panel)"}})]})}),rY=e=>(0,r.jsx)("button",{ref:t$,type:"button","data-top-panel-trigger":!0,onClick:()=>nv("language",e),title:V("common.language"),"aria-label":V("common.language"),"aria-haspopup":"menu","aria-expanded":"language"===nh,"aria-pressed":"language"===nh,style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"language"===nh?"var(--bg-selected)":"none",border:"none",borderRight:"1px solid var(--border)",color:"language"===nh?"var(--text)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="language"===nh?"var(--text)":"var(--text-muted)"},"data-mobile-toolbar-action":e?"language":void 0,children:(0,r.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("path",{d:"m5 8 6 6"}),(0,r.jsx)("path",{d:"m4 14 6-6 2-3"}),(0,r.jsx)("path",{d:"M2 5h12"}),(0,r.jsx)("path",{d:"M7 2h1"}),(0,r.jsx)("path",{d:"m22 22-5-10-5 10"}),(0,r.jsx)("path",{d:"M14 18h6"})]})}),rG=e=>rF&&eN?.requiresTrust&&!eN.trusted?(0,r.jsxs)("button",{type:"button",onClick:()=>{eU(null),eA(!0)},title:V("trust.resourcesNotLoaded"),"aria-label":V("trust.resourcesNotLoaded"),style:{display:"flex",alignItems:"center",justifyContent:e?"flex-start":"center",gap:6,width:e?"100%":void 0,minHeight:e?32:void 0,height:e?void 0:"100%",padding:e?"6px 12px":"0 12px",background:e?"color-mix(in srgb, #d97706 8%, var(--bg-panel))":"none",border:"none",borderRight:e?"none":"1px solid var(--border)",borderBottom:e?"1px solid var(--border)":"none",color:"#d97706",cursor:"pointer",flexShrink:0,fontSize:11,lineHeight:1.35,textAlign:"left"},"data-mobile-trust-banner":e?"true":void 0,children:[(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",style:{flexShrink:0},children:[(0,r.jsx)("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10Z"}),(0,r.jsx)("path",{d:"M12 8v4"}),(0,r.jsx)("path",{d:"M12 16h.01"})]}),(0,r.jsx)("span",{children:V("trust.resourcesNotLoaded")})]}):null,rX=e=>e||rF?!e&&el?(0,r.jsxs)("div",{style:{display:"flex",alignItems:"stretch",height:"100%"},children:[r0(),r1(),r2()]}):(0,r.jsxs)("div",{style:{display:"flex",alignItems:"stretch",height:"100%"},children:[(0,r.jsxs)("button",{type:"button",onClick:()=>{rz(),e&&to(!0)},disabled:!ei,title:ei?V("history.full"):V("history.unsaved"),"aria-label":V("history.full"),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,width:e?36:void 0,height:"100%",padding:e?0:"0 12px",background:"none",border:"none",borderTop:"2px solid transparent",borderRight:"1px solid var(--border)",color:ei?"var(--text-muted)":"var(--text-dim)",cursor:ei?"pointer":"not-allowed",opacity:ei?1:.45,flexShrink:0,fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s, opacity 0.1s"},onMouseEnter:e=>{ei&&(e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{e.currentTarget.style.color=ei?"var(--text-muted)":"var(--text-dim)",e.currentTarget.style.background="none"},"data-mobile-toolbar-action":e?"history":void 0,children:[(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:ei?"var(--text-muted)":"var(--text-dim)",flexShrink:0},"aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M3 12a9 9 0 1 0 3-6.7L3 8"}),(0,r.jsx)("path",{d:"M3 3v5h5"}),(0,r.jsx)("path",{d:"M12 7v5l3 2"})]}),!e&&(0,r.jsx)("span",{children:V("history.label")})]}),e?(0,r.jsx)("button",{type:"button","data-top-panel-trigger":!0,onClick:()=>nv("branches",!0),title:V("i18n.branches"),"aria-label":V("i18n.branches"),"aria-pressed":"branches"===nh,style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:"100%",padding:0,background:"branches"===nh?"var(--bg-selected)":"none",border:"none",borderTop:"branches"===nh?"2px solid var(--accent)":"2px solid transparent",borderRight:"1px solid var(--border)",color:"branches"===nh?"var(--text)":"var(--text-muted)",cursor:"pointer",flexShrink:0},"data-mobile-toolbar-action":"branches",children:(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:tN.length>0?"var(--accent)":"var(--text-dim)"},"aria-hidden":"true",children:[(0,r.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,r.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,r.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,r.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]})}):(0,r.jsx)(n9,{tree:tN,activeLeafId:tB,onLeafChange:t_,inline:!0,containerRef:tW,open:"branches"===nh,onToggle:()=>nv("branches"),hasSession:!0}),(0,r.jsxs)("button",{ref:tX,type:"button","data-top-panel-trigger":!0,onClick:()=>nb(e),disabled:e&&!rF,title:V("system.prompt"),"aria-label":V("system.prompt"),"aria-pressed":"system"===nh,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,width:e?36:void 0,height:"100%",padding:e?0:"0 12px",background:"system"===nh?"var(--bg-selected)":"none",border:"none",borderTop:"system"===nh?"2px solid var(--accent)":"2px solid transparent",borderRight:"1px solid var(--border)",cursor:e&&!rF?"not-allowed":"pointer",color:"system"===nh?"var(--text)":"var(--text-muted)",opacity:e&&!rF?.45:1,fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s"},onMouseEnter:t=>{(!e||rF)&&(t.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.color="system"===nh?"var(--text)":"var(--text-muted)"},"data-mobile-toolbar-action":e?"system":void 0,children:[(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:tq?"var(--accent)":"var(--text-dim)",flexShrink:0},"aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,r.jsx)("polyline",{points:"14 2 14 8 20 8"}),(0,r.jsx)("line",{x1:"8",y1:"13",x2:"16",y2:"13"}),(0,r.jsx)("line",{x1:"8",y1:"17",x2:"13",y2:"17"})]}),!e&&(0,r.jsx)("span",{children:V("system.label")})]}),!e&&r0(),!e&&r1(),!e&&r2(),e&&rJ(!0),e&&rY(!0),e&&rK(!0)]}):null,rZ=e=>{if(!e&&(!rF||!t0&&!nc))return null;let t=t0?.tokens,n=t0?.cost??0,i=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(0)}k`:String(e),o=n>0?n>=.01?`$${n.toFixed(2)}`:"<$0.01":null,a="var(--text-muted)",s=null,l=null;if(nc?.contextWindow){let e=nc.percent;null!==e&&e>90?a="#ef4444":null!==e&&e>70&&(a="rgba(234,179,8,0.95)"),s=null!==e?`${e.toFixed(0)}% / ${i(nc.contextWindow)}`:`? / ${i(nc.contextWindow)}`,l=null!==e?`${e.toFixed(0)}%`:null}let d=function(e,t,n){if(!e)return"";let r=e.tokens,i=e.cost??0,o=[];if(o.push(`in: ${r.input.toLocaleString(n)}`),o.push(`out: ${r.output.toLocaleString(n)}`),o.push(`cache read: ${r.cacheRead.toLocaleString(n)}`),o.push(`cache write: ${r.cacheWrite.toLocaleString(n)}`),i>0&&o.push(`cost: $${i.toFixed(4)}`),t?.contextWindow){let e=t.percent;o.push(`context: ${null!==e?e.toFixed(1)+"%":"unknown"} of ${t.contextWindow.toLocaleString(n)} tokens`)}return o.join(" | ")}(t0,nc,_),c=e&&ti,u=!!(t&&(t.input>0||t.output>0)||o||l);return(0,r.jsx)("button",{type:"button","data-top-panel-trigger":!0,onClick:()=>nv("session"),disabled:!rF||c,tabIndex:c?-1:void 0,title:d||V("session.title"),"aria-label":V("session.title"),"aria-pressed":"session"===nh,"aria-hidden":!!c||void 0,className:e?"mobile-session-stats":void 0,"data-mobile-toolbar-stats":e?"true":void 0,style:{marginLeft:e?0:"auto",display:"flex",alignItems:"center",justifyContent:"flex-end",flex:e?1:void 0,minWidth:0,gap:e?7:10,paddingLeft:e?6:12,paddingRight:e?6:12,height:"100%",overflow:"hidden",visibility:c?"hidden":"visible",pointerEvents:c?"none":"auto",background:"session"===nh?"var(--bg-selected)":"none",border:"none",borderTop:"session"===nh?"2px solid var(--accent)":"2px solid transparent",fontSize:11,color:"var(--text-muted)",whiteSpace:"nowrap",cursor:rF?"pointer":"default",fontVariantNumeric:"tabular-nums",transition:"color 0.1s, background 0.1s"},onMouseEnter:e=>{rF&&!c&&(e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.color="session"===nh?"var(--text)":"var(--text-muted)"},children:e?(0,r.jsxs)(r.Fragment,{children:[t&&t.input>0&&(0,r.jsxs)("span",{className:"mobile-session-stat-io",style:{display:"flex",alignItems:"center",gap:2,flexShrink:0},children:[(0,r.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("line",{x1:"5",y1:"8.5",x2:"5",y2:"1.5"}),(0,r.jsx)("polyline",{points:"2 4 5 1.5 8 4"})]}),i(t.input)]}),t&&t.output>0&&(0,r.jsxs)("span",{className:"mobile-session-stat-io",style:{display:"flex",alignItems:"center",gap:2,flexShrink:0},children:[(0,r.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("line",{x1:"5",y1:"1.5",x2:"5",y2:"8.5"}),(0,r.jsx)("polyline",{points:"2 6 5 8.5 8 6"})]}),i(t.output)]}),o&&(0,r.jsx)("span",{className:"mobile-session-stat-cost",style:{color:"var(--text)",fontWeight:500,flexShrink:0},children:o}),l&&(0,r.jsx)("span",{style:{color:a,flexShrink:0},children:l}),!u&&rF&&(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",color:"var(--text-dim)"},children:V("session.title")})]}):(0,r.jsxs)(r.Fragment,{children:[t&&t.input>0&&(0,r.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("line",{x1:"5",y1:"8.5",x2:"5",y2:"1.5"}),(0,r.jsx)("polyline",{points:"2 4 5 1.5 8 4"})]}),i(t.input)]}),t&&t.output>0&&(0,r.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("line",{x1:"5",y1:"1.5",x2:"5",y2:"8.5"}),(0,r.jsx)("polyline",{points:"2 6 5 8.5 8 6"})]}),i(t.output)]}),t&&t.cacheRead>0&&(0,r.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M8.5 5a3.5 3.5 0 1 1-1-2.45"}),(0,r.jsx)("polyline",{points:"6.5 1.5 8.5 2.5 7.5 4.5"})]}),i(t.cacheRead)]}),o&&(0,r.jsx)("span",{style:{display:"flex",alignItems:"center",color:"var(--text)",fontWeight:500},children:o}),s&&(0,r.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4,color:a},children:[(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M1 9 L1 5 Q1 1 5 1 Q9 1 9 5 L9 9"}),(0,r.jsx)("line",{x1:"1",y1:"9",x2:"9",y2:"9"})]}),s]})]})})},rQ=e=>{if(0===t8.length)return null;let t=`${V("todo.title")} \xb7 ${(0,rn.HH)(t8)} ${V("todo.completed")}`,n=t6&&!e;return(0,r.jsx)("button",{type:"button",ref:nt,onClick:nk,title:t,"aria-label":t,"aria-expanded":t6,style:{display:"flex",alignItems:"center",justifyContent:"center",width:e?void 0:36,height:36,padding:e?"0 8px":0,background:n?"var(--bg-selected)":"none",border:"none",borderTop:n?"2px solid var(--accent)":"2px solid transparent",borderLeft:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.1s, background 0.1s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color=n?"var(--text)":"var(--text-muted)"},children:(0,r.jsxs)("svg",{width:"16",height:"16",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:"4",width:"18",height:"16",rx:"3"}),(0,r.jsx)("path",{d:"M8 9h8M8 13h5"})]})})},r0=()=>{let e=eV&&"top"===eK;return(0,r.jsxs)("button",{type:"button",id:"terminal-topbar-btn",ref:eZ,onClick:()=>nw("top"),title:V("terminal.title"),"aria-label":V("terminal.title"),"aria-expanded":e,style:{display:"flex",alignItems:"center",justifyContent:"center",width:"auto",height:"100%",padding:"0 10px",gap:5,background:e?"var(--bg-selected)":"none",border:"none",borderTop:e?"2px solid var(--accent)":"2px solid transparent",borderRight:"1px solid var(--border)",color:e?"var(--text)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s",fontSize:11,whiteSpace:"nowrap"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:t=>{t.currentTarget.style.color=e?"var(--text)":"var(--text-muted)"},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)("polyline",{points:"4 17 10 11 4 5"}),(0,r.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]}),(0,r.jsx)("span",{children:V("terminal.title")})]})},r1=()=>{let e="mcp"===nh;return(0,r.jsxs)("button",{type:"button",id:"mcp-topbar-btn","data-top-panel-trigger":!0,onClick:()=>nv("mcp"),title:"MCP","aria-label":"MCP","aria-expanded":e,"aria-pressed":e,style:{display:"flex",alignItems:"center",justifyContent:"center",width:"auto",height:"100%",padding:"0 10px",gap:5,background:e?"var(--bg-selected)":"none",border:"none",borderTop:e?"2px solid var(--accent)":"2px solid transparent",borderRight:"1px solid var(--border)",color:e?"var(--text)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s",fontSize:11,whiteSpace:"nowrap"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:t=>{t.currentTarget.style.color=e?"var(--text)":"var(--text-muted)"},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)("circle",{cx:"12",cy:"12",r:"3"}),(0,r.jsx)("path",{d:"M12 2v3M12 19v3M2 12h3M19 12h3M4.9 4.9l2.1 2.1M17 17l2.1 2.1M19.1 4.9L17 7M7 17l-2.1 2.1"})]}),(0,r.jsx)("span",{children:"MCP"})]})},r2=()=>{let e="tools"===nh;return(0,r.jsxs)("button",{type:"button",id:"tools-topbar-btn","data-top-panel-trigger":!0,onClick:()=>{e||!ei||null!==e1||e4||(e8(!0),(0,ne.$J)(ei.id,{type:"get_tools"}).then(e=>e2(e)).catch(()=>e2(null)).finally(()=>e8(!1))),nv("tools")},title:V("tools.title"),"aria-label":V("tools.title"),"aria-expanded":e,"aria-pressed":e,style:{display:"flex",alignItems:"center",justifyContent:"center",width:"auto",height:"100%",padding:"0 10px",gap:5,background:e?"var(--bg-selected)":"none",border:"none",borderTop:e?"2px solid var(--accent)":"2px solid transparent",borderRight:"1px solid var(--border)",color:e?"var(--text)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s",fontSize:12,whiteSpace:"nowrap"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:t=>{t.currentTarget.style.color=e?"var(--text)":"var(--text-muted)"},children:[(0,r.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:e1?.some(e=>e.active)?"var(--accent)":"var(--text-dim)",flexShrink:0},"aria-hidden":"true",children:(0,r.jsx)("path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.8-3.8a6 6 0 0 1-7.9 7.9l-6.9 6.9a2.1 2.1 0 0 1-3-3l6.9-6.9a6 6 0 0 1 7.9-7.9z"})}),(0,r.jsx)("span",{children:V("tools.label")})]})},r4=e=>{let t=e&&ti;return(0,r.jsx)("button",{type:"button",onClick:nC,disabled:t,tabIndex:t?-1:void 0,"aria-controls":"file-panel","aria-expanded":tn,"aria-hidden":!!t||void 0,title:tn?V("files.hidePanel"):V("files.showPanel"),"aria-label":tn?V("files.hidePanel"):V("files.showPanel"),"data-mobile-toolbar-file":e?"true":void 0,style:{marginLeft:e||t0||nc?0:"auto",display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,visibility:t?"hidden":"visible",pointerEvents:t?"none":"auto",background:tn?"var(--bg-selected)":"none",border:"none",borderLeft:"1px solid var(--border)",color:tn?"var(--text)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{t||(e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.color=tn?"var(--text)":"var(--text-muted)"},children:(0,r.jsxs)("svg",{width:"16",height:"16",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:"3",width:"18",height:"18",rx:"2"}),(0,r.jsx)("line",{x1:"15",y1:"3",x2:"15",y2:"21"})]})})},r8=(0,i.useMemo)(()=>{if(ei){let e=ei.projectRoot??ei.cwd,t=e.split(/[\\/]/).filter(Boolean).pop()??e;return ei.isWorktree&&ei.branch?`${t}\xb7${ei.branch}`:t}return rW?rW.split(/[\\/]/).filter(Boolean).pop()??rW:null},[ei,rW]);return(0,r.jsxs)(r.Fragment,{children:[er.map((e,t)=>(0,r.jsx)(eS,{item:e,zIndex:3e3+t,active:t===er.length-1,onClose:eC.i5,onActivate:eC.Dq,onMove:eC.R9},e.id)),(0,r.jsx)("style",{children:`
|
|
172
|
-
@keyframes session-info-pop {
|
|
173
|
-
0% {
|
|
174
|
-
opacity: 0;
|
|
175
|
-
transform: translateY(-24px);
|
|
176
|
-
filter: blur(6px);
|
|
177
|
-
box-shadow: 0 2px 8px rgba(0,0,0,0);
|
|
178
|
-
}
|
|
179
|
-
55% {
|
|
180
|
-
opacity: 1;
|
|
181
|
-
transform: translateY(0);
|
|
182
|
-
filter: blur(0);
|
|
183
|
-
background: color-mix(in srgb, var(--accent) 8%, var(--bg-panel));
|
|
184
|
-
box-shadow: 0 18px 44px rgba(37,99,235,0.16);
|
|
185
|
-
}
|
|
186
|
-
100% {
|
|
187
|
-
opacity: 1;
|
|
188
|
-
transform: translateY(0);
|
|
189
|
-
filter: blur(0);
|
|
190
|
-
background: var(--bg-panel);
|
|
191
|
-
box-shadow: 0 10px 28px rgba(0,0,0,0.10);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
@keyframes session-info-light-wash {
|
|
195
|
-
0% {
|
|
196
|
-
opacity: 0;
|
|
197
|
-
transform: translateX(-110%) skewX(-16deg);
|
|
198
|
-
}
|
|
199
|
-
24% {
|
|
200
|
-
opacity: 0.42;
|
|
201
|
-
}
|
|
202
|
-
100% {
|
|
203
|
-
opacity: 0;
|
|
204
|
-
transform: translateX(115%) skewX(-16deg);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
.session-info-popover {
|
|
208
|
-
position: relative;
|
|
209
|
-
overflow: hidden;
|
|
210
|
-
transform-origin: top right;
|
|
211
|
-
animation: session-info-pop 360ms ease-out both;
|
|
212
|
-
/* 不设 will-change:会压住 glass-top-panel 的 backdrop-filter,
|
|
213
|
-
导致浏览器在合成层不渲染毛玻璃模糊(此前会话信息面板 blur 失效)。
|
|
214
|
-
动画很短,去掉优化提示无感知损失。 */
|
|
215
|
-
}
|
|
216
|
-
.session-info-popover::after {
|
|
217
|
-
content: "";
|
|
218
|
-
position: absolute;
|
|
219
|
-
top: 0;
|
|
220
|
-
bottom: 0;
|
|
221
|
-
left: 0;
|
|
222
|
-
width: 44%;
|
|
223
|
-
pointer-events: none;
|
|
224
|
-
background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--accent) 24%, transparent), transparent);
|
|
225
|
-
animation: session-info-light-wash 620ms ease-out both;
|
|
226
|
-
}
|
|
227
|
-
@media (prefers-reduced-motion: reduce) {
|
|
228
|
-
.session-info-popover,
|
|
229
|
-
.session-info-popover::after {
|
|
230
|
-
animation: none;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
.mobile-session-stats {
|
|
234
|
-
container-type: inline-size;
|
|
235
|
-
}
|
|
236
|
-
@container (max-width: 158px) {
|
|
237
|
-
.mobile-session-stat-io {
|
|
238
|
-
display: none !important;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
@container (max-width: 88px) {
|
|
242
|
-
.mobile-session-stat-cost {
|
|
243
|
-
display: none !important;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
@media (max-width: 640px) {
|
|
247
|
-
.sidebar-overlay-backdrop.sidebar-mobile-pending {
|
|
248
|
-
opacity: 0 !important;
|
|
249
|
-
pointer-events: none !important;
|
|
250
|
-
}
|
|
251
|
-
.sidebar-container.sidebar-mobile-pending.sidebar-open {
|
|
252
|
-
transform: translateX(calc(-100% - env(safe-area-inset-left)));
|
|
253
|
-
box-shadow: none;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
`}),(0,r.jsxs)("div",{style:{display:"flex",width:"100%",height:"var(--app-viewport-height, 100dvh)",paddingLeft:"env(safe-area-inset-left)",paddingRight:"env(safe-area-inset-right)",overflow:"hidden",background:"transparent"},children:[ta&&tm&&(0,r.jsxs)("div",{ref:tu,role:"menu","aria-label":V("bg.title"),className:"glass-top-panel",style:{position:"fixed",top:tm.top,left:tm.left,zIndex:600,width:264,padding:12,fontFamily:"inherit"},children:[(0,r.jsx)("div",{style:{fontSize:12,fontWeight:700,color:"var(--text)",letterSpacing:0,marginBottom:10},children:V("bg.title")}),(0,r.jsx)("input",{ref:tx,type:"file",accept:"image/jpeg,image/png,image/webp,image/avif",style:{display:"none"},onChange:async e=>{let t=e.target.files?.[0];t&&(await P(t),A({offsetX:0})),e.target.value=""}}),(0,r.jsxs)("button",{type:"button",onClick:()=>tx.current?.click(),disabled:!W,style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"var(--accent)",color:"#fff",border:"none",borderRadius:8,fontSize:13,fontWeight:600,cursor:"pointer",transition:"opacity 0.12s"},children:[(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)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,r.jsx)("polyline",{points:"17 8 12 3 7 8"}),(0,r.jsx)("line",{x1:"12",y1:"3",x2:"12",y2:"15"})]}),z?V("bg.replace"):V("bg.choose")]}),z&&(0,r.jsxs)("button",{type:"button",onClick:async()=>{await $(),ts(!1)},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",marginTop:6,background:"rgba(239,68,68,0.08)",color:"#dc2626",border:"1px solid rgba(239,68,68,0.25)",borderRadius:8,fontSize:13,cursor:"pointer",transition:"background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.14)"},onMouseLeave:e=>{e.currentTarget.style.background="rgba(239,68,68,0.08)"},children:[(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:"3 6 5 6 21 6"}),(0,r.jsx)("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})]}),V("bg.remove")]}),z&&(0,r.jsxs)("div",{style:{marginTop:8,display:"flex",flexDirection:"column",gap:4},children:["image"===N&&(0,r.jsxs)("button",{type:"button",role:"menuitemcheckbox","aria-checked":B.repeat,onClick:()=>A({repeat:!B.repeat}),style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 10px",background:B.repeat?"var(--bg-selected)":"transparent",color:"var(--text)",border:"1px solid var(--border)",borderRadius:8,fontSize:12.5,cursor:"pointer",textAlign:"left",transition:"background 0.12s"},children:[(0,r.jsx)("span",{style:{width:14,flexShrink:0,textAlign:"center",color:"var(--accent)"},children:B.repeat?"✓":""}),V("bg.repeat")]}),"image"===N&&!B.repeat&&(0,r.jsxs)("button",{type:"button",role:"menuitemcheckbox","aria-checked":B.fill,onClick:async()=>{let e=!B.fill;if(e&&D)try{let t=await (await fetch(D)).blob(),n=await rv(t);if(n)return void A({fill:e,fillColorLeft:n.left,fillColorRight:n.right})}catch{}A({fill:e})},disabled:!W,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 10px",background:B.fill?"var(--bg-selected)":"transparent",color:"var(--text)",border:"1px solid var(--border)",borderRadius:8,fontSize:12.5,cursor:"pointer",textAlign:"left",transition:"background 0.12s"},children:[(0,r.jsx)("span",{style:{width:14,flexShrink:0,textAlign:"center",color:"var(--accent)"},children:B.fill?"✓":""}),V("bg.fill")]}),(0,r.jsxs)("button",{type:"button",onClick:()=>O(!0),style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 10px",background:"transparent",color:"var(--text)",border:"1px solid var(--border)",borderRadius:8,fontSize:12.5,cursor:"pointer",textAlign:"left",transition:"background 0.12s"},children:[(0,r.jsx)("span",{style:{width:14,flexShrink:0,textAlign:"center"},children:"↔"}),V("bg.adjust")]}),(0,r.jsxs)("button",{type:"button",onClick:()=>A({offsetX:0}),disabled:0===B.offsetX,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 10px",background:(B.offsetX,"transparent"),color:0===B.offsetX?"var(--text-dim)":"var(--text)",border:"1px solid var(--border)",borderRadius:8,fontSize:12.5,cursor:0===B.offsetX?"default":"pointer",textAlign:"left",opacity:0===B.offsetX?.55:1,transition:"background 0.12s"},children:[(0,r.jsx)("span",{style:{width:14,flexShrink:0,textAlign:"center"},children:"↺"}),V("bg.reset")]}),(0,r.jsx)(rC,{label:V("bg.bubbleOpacity"),icon:"◐",value:B.bubbleOpacity,min:0,max:100,unit:"%",preview:rT,onCommit:e=>A({bubbleOpacity:e})}),(0,r.jsx)(rC,{label:V("bg.bubbleBlur"),icon:"❄",value:B.bubbleBlur,min:0,max:30,unit:"px",preview:e=>(0,d.gx)(e),onCommit:e=>A({bubbleBlur:e})}),(0,r.jsxs)("button",{type:"button",onClick:()=>A({bubbleOpacity:44,bubbleBlur:8}),disabled:44===B.bubbleOpacity&&8===B.bubbleBlur,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 10px",background:"transparent",color:44===B.bubbleOpacity&&8===B.bubbleBlur?"var(--text-dim)":"var(--text)",border:"1px solid var(--border)",borderRadius:8,fontSize:12.5,cursor:44===B.bubbleOpacity&&8===B.bubbleBlur?"default":"pointer",textAlign:"left",opacity:44===B.bubbleOpacity&&8===B.bubbleBlur?.55:1,transition:"background 0.12s"},children:[(0,r.jsx)("span",{style:{width:14,flexShrink:0,textAlign:"center"},children:"↺"}),V("bg.bubbleReset")]})]}),(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",lineHeight:1.5,marginTop:10},children:V("bg.hint")})]}),H&&(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:700,cursor:"ew-resize",touchAction:"none"},onPointerDown:e=>{e.preventDefault();let t=e.currentTarget;t.setPointerCapture(e.pointerId);let n=e.clientX,r=B.offsetX,i=e=>{A({offsetX:r+e.clientX-n})},o=()=>{t.removeEventListener("pointermove",i),t.removeEventListener("pointerup",o),B.fill&&D&&fetch(D).then(e=>e.blob()).then(async e=>{let t=await rv(e);t&&A({fillColorLeft:t.left,fillColorRight:t.right})}).catch(()=>{})};t.addEventListener("pointermove",i),t.addEventListener("pointerup",o)},children:(0,r.jsxs)("div",{onPointerDown:e=>e.stopPropagation(),style:{position:"absolute",left:"50%",top:16,transform:"translateX(-50%)",display:"flex",alignItems:"center",gap:10,padding:"8px 14px",borderRadius:999,background:"var(--panel-glass)",color:"var(--text)",border:"1px solid var(--border)",fontSize:12,whiteSpace:"nowrap"},children:[V("bg.adjustHint"),(0,r.jsx)("button",{type:"button",onClick:()=>O(!1),style:{background:"var(--accent)",color:"#fff",border:"none",borderRadius:999,padding:"4px 12px",fontSize:12,fontWeight:600,cursor:"pointer",flexShrink:0},children:V("bg.adjustDone")})]})}),(0,r.jsx)("div",{className:`sidebar-overlay-backdrop${ty?"":" sidebar-mobile-pending"}`,onClick:()=>eq(!1),style:{position:"fixed",inset:0,zIndex:199,background:"rgba(0,0,0,0.4)",opacity:+!!e_,pointerEvents:e_?"auto":"none",transition:"opacity 0.25s ease"}}),(0,r.jsx)("div",{ref:tM.panelRef,id:"session-sidebar",className:`sidebar-container glass-canvas${e_?" sidebar-open":" sidebar-closed"}${ty?"":" sidebar-mobile-pending"}${tM.isResizing?" sidebar-resizing":""}`,style:{"--sidebar-width":`${tM.width}px`,backgroundColor:"var(--side-panel)",flexDirection:"column",flexShrink:0,paddingTop:"env(safe-area-inset-top)",paddingBottom:"calc(48px + env(safe-area-inset-bottom))",zIndex:200},children:rV}),e_&&(0,r.jsx)("div",{...tM.separatorProps,"aria-controls":"session-sidebar",className:`panel-resize-handle sidebar-resize-handle${tM.isResizing?" is-resizing":""}`,"data-resize-handle":"sidebar",title:`${V("layout.resizeSidebar")}: ${V("layout.resizeHint")}`}),(0,r.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden",minWidth:0},children:[(0,r.jsxs)("div",{ref:tW,className:"glass-canvas",style:{position:"relative",zIndex:300,flexShrink:0,backgroundColor:"var(--frame-glass)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",position:"relative",borderBottom:"1px solid var(--border)",height:"calc(36px + env(safe-area-inset-top))",paddingTop:"env(safe-area-inset-top)"},children:[(0,r.jsx)("button",{onClick:nj,title:e_?V("sidebar.hide"):V("sidebar.show"),"aria-label":e_?V("sidebar.hide"):V("sidebar.show"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"none",border:"none",borderRight:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)"},children:e_?(0,r.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,r.jsx)("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]}):(0,r.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,r.jsx)("line",{x1:"3",y1:"6",x2:"21",y2:"6"}),(0,r.jsx)("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),(0,r.jsx)("line",{x1:"3",y1:"18",x2:"21",y2:"18"})]})}),K&&(0,r.jsxs)("div",{ref:tP,"data-mobile-toolbar":"true",style:{position:"relative",display:"flex",alignItems:"stretch",flex:1,minWidth:0,height:"100%"},children:[(0,r.jsx)("button",{type:"button",onClick:nS,title:ti?V("chat.close"):V("chat.moreControls"),"aria-label":ti?V("chat.close"):V("chat.moreControls"),"aria-controls":"mobile-toolbar-actions","aria-expanded":ti,"data-mobile-toolbar-more":"true",style:{position:"relative",zIndex:ti?21:void 0,display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:ti?"var(--bg-selected)":"none",border:"none",borderRight:"1px solid var(--border)",color:ti?"var(--text)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},children:ti?(0,r.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:[(0,r.jsx)("line",{x1:"5",y1:"5",x2:"19",y2:"19"}),(0,r.jsx)("line",{x1:"19",y1:"5",x2:"5",y2:"19"})]}):(0,r.jsxs)("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"5",cy:"12",r:"1.5"}),(0,r.jsx)("circle",{cx:"12",cy:"12",r:"1.5"}),(0,r.jsx)("circle",{cx:"19",cy:"12",r:"1.5"})]})}),K&&(0,r.jsx)("div",{style:{height:"100%",flexShrink:0},children:(0,r.jsx)(re,{onSelectSession:nK,onOpenBoard:eg})}),rZ(!0),rQ(!0),r4(!0),ti&&(0,r.jsx)("div",{id:"mobile-toolbar-actions",role:"toolbar","aria-label":V("chat.moreControls"),"data-mobile-toolbar-actions":"true",style:{position:"absolute",top:0,right:0,bottom:0,left:36,zIndex:20,display:"flex",alignItems:"stretch",background:"color-mix(in srgb, var(--glass-bg-strong) 60%, transparent)",boxShadow:"4px 0 18px rgba(0,0,0,0.12)",backdropFilter:"blur(var(--glass-blur-popover)) saturate(var(--glass-saturate))"},children:rX(!0)})]}),!K&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{style:{height:"100%",flexShrink:0},children:(0,r.jsx)(re,{onSelectSession:nK,onOpenBoard:eg})}),rK(!1),rJ(!1),rY(!1),rG(!1),rX(!1),rZ(!1),rQ(!1)]}),!K&&r4(!1),K&&(0,r.jsx)(n9,{tree:tN,activeLeafId:tB,onLeafChange:t_,inline:!0,compact:!0,containerRef:tW,open:"branches"===nh,onToggle:()=>nv("branches"),hasSession:rF,hideInlineButton:!0}),nh&&nx&&(0,o.createPortal)((0,r.jsxs)("div",{ref:nm,style:{position:"fixed",top:nx.top,left:nx.left,width:nx.width,maxHeight:`calc(100dvh - ${nx.top}px)`,overflowY:"auto",zIndex:500},children:["language"===nh&&(0,r.jsx)("div",{role:"menu","aria-label":V("common.language"),className:"glass-top-panel",style:{overflow:"hidden",padding:4},children:J.map(e=>(0,r.jsx)("button",{type:"button",onClick:()=>{q(e.id),ng(null)},role:"menuitemradio","aria-checked":_===e.id,style:{display:"flex",alignItems:"center",width:"100%",height:34,padding:"0 10px",border:"none",borderRadius:4,background:_===e.id?"var(--side-selected)":"transparent",color:_===e.id?"var(--accent)":"var(--text)",cursor:"pointer",textAlign:"left",fontSize:12,transition:"background 0.1s",fontWeight:_===e.id?600:400},onMouseEnter:t=>{_!==e.id&&(t.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:t=>{_!==e.id&&(t.currentTarget.style.background="transparent")},children:(0,r.jsx)("span",{children:e.label})},e.id))}),"system"===nh&&(0,r.jsx)("div",{className:"glass-top-panel",children:tq?(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:tq}):""===tq?(0,r.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:V("system.empty")}):(0,r.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:tJ?V("system.loading"):V("system.load")})}),"mcp"===nh&&(0,r.jsx)(tl,{embedded:!0,cwd:ei?.cwd??rW??null,hidden:!1,onClose:()=>ng(null)}),"tools"===nh&&(0,r.jsx)(n8,{loading:e4,tools:e1,translate:V}),"session"===nh&&(0,r.jsx)("div",{className:"session-info-popover glass-top-panel",style:{padding:"12px 16px",maxWidth:"min(560px, 100%)",marginLeft:"auto"},children:t0?(e=t0.totalActiveMs??0,t=[...t0.sessionName?[{label:V("session.name"),value:t0.sessionName,copyField:null}]:[],...t2?[{label:V("session.task"),value:t2,copyField:null}]:[],{label:V("session.file"),value:t0.sessionFile??V("session.inMemory"),copyField:"file"},{label:V("session.id"),value:t0.sessionId,copyField:"id"},...e>0?[{label:V("session.totalActive"),value:(e=>{if(e<=0)return"0s";let t=Math.floor(e/1e3),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=t%60;return n>0?`${n}h ${r}m`:r>0?`${r}m ${i}s`:`${i}s`})(e),copyField:null}]:[]],n=[...ei?[{label:V("session.projectDir"),value:ei.projectRoot??ei.cwd,copyField:"projectDir"}]:[],...ei?.branch?[{label:V("session.gitBranch"),value:ei.branch,copyField:"gitBranch"}]:[],...ei?.isWorktree?[{label:V("session.gitWorktree"),value:ei.cwd,copyField:"gitWorktree"}]:[]],s=[[V("session.user"),t0.userMessages.toLocaleString(_)],[V("session.assistant"),t0.assistantMessages.toLocaleString(_)],[V("session.toolCalls"),t0.toolCalls.toLocaleString(_)],[V("session.toolResults"),t0.toolResults.toLocaleString(_)],[V("session.total"),t0.totalMessages.toLocaleString(_)]],c=[[V("session.input"),t0.tokens.input.toLocaleString(_)],[V("session.output"),t0.tokens.output.toLocaleString(_)],...t0.tokens.cacheRead>0?[[V("session.cacheRead"),t0.tokens.cacheRead.toLocaleString(_)]]:[],...t0.tokens.cacheWrite>0?[[V("session.cacheWrite"),t0.tokens.cacheWrite.toLocaleString(_)]]:[],[V("session.total"),t0.tokens.total.toLocaleString(_)]],p=nc??t0.contextUsage,b=[...t0.cost>0?[[V("session.cost"),`$${t0.cost.toFixed(4)}`]]:[],...p?.contextWindow?[[V("session.context"),`${null!==p.percent?`${p.percent.toFixed(1)}%`:"?"} / ${(v=p.contextWindow)>=1e6?`${(v/1e6).toFixed(1)}M`:v>=1e3?`${(v/1e3).toFixed(0)}k`:String(v)}`]]:[],...t0.tokens.cacheRead+t0.tokens.cacheWrite>0&&t0.tokens.cacheRead+t0.tokens.cacheWrite+t0.tokens.input>0?[[V("session.cacheHitRate"),`${(t0.tokens.cacheRead/(t0.tokens.cacheRead+t0.tokens.cacheWrite+t0.tokens.input)*100).toFixed(1)}%`]]:[]],y=(e,t,n="left",i=!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:i?"max-content minmax(0, 1fr)":"auto minmax(0, 1fr)",columnGap:i?14:12,rowGap:4,justifyContent:i?"start":void 0},children:t.map(([t,i])=>(0,r.jsxs)("div",{style:{display:"contents"},children:[(0,r.jsx)("div",{style:{color:"var(--text-meta)",whiteSpace:"nowrap"},children:t}),(0,r.jsx)("div",{style:{color:"var(--text-muted)",minWidth:0,overflowWrap:"anywhere",textAlign:n,whiteSpace:"normal"},children:i})]},`${e}:${t}`))})]}),k={file:"session.copyFile",id:"session.copyId",projectDir:"session.copyProjectDir",gitBranch:"session.copyGitBranch",gitWorktree:"session.copyGitWorktree"},j=(e,t)=>{let n=na===e;return(0,r.jsx)("button",{type:"button",title:n?V("session.copied"):V(k[e]),onClick:()=>nd(e,t),style:{alignSelf:"start",display:"inline-flex",alignItems:"center",justifyContent:"center",width:22,height:22,marginTop:-2,color:n?"var(--accent)":"var(--text-meta)",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=n?"var(--accent)":"var(--text-meta)",e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.background="transparent"},children:n?(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",children:(0,r.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})},S=(0,r.jsxs)("div",{style:{minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:11,fontWeight:700,color:"var(--text)",marginBottom:6},children:V("session.infoSection")}),(0,r.jsx)("div",{style:{display:"grid",gridTemplateColumns:"auto minmax(0, 1fr) auto",columnGap:12,rowGap:8,alignItems:"start"},children:t.map(e=>(0,r.jsxs)("div",{style:{display:"contents"},children:[(0,r.jsx)("div",{style:{color:"var(--text-meta)",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?j(e.copyField,e.value):null})]},`session-info:${e.label}`))})]}),C=n.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:V("session.projectSection")}),(0,r.jsx)("div",{style:{display:"grid",gridTemplateColumns:"auto minmax(0, 1fr) auto",columnGap:12,rowGap:8,alignItems:"start"},children:n.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?j(e.copyField,e.value):null})]},`project-info:${e.label}`))})]}):null,(0,r.jsxs)("div",{style:{display:"grid",gap:K?16:20,fontSize:12,lineHeight:1.5,fontFamily:"var(--font-mono)"},children:[(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:K?16:20},children:[S,C]}),(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:K?"1fr":"minmax(160px, 0.5fr) minmax(240px, 0.7fr)",gap:K?16:24},children:[y(V("session.messages"),s),y(V("session.tokens"),[...c,...b],"right",!0)]})]})):(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:V("session.load")})})]}),document.body),t6&&t7&&t8.length>0&&(0,o.createPortal)((0,r.jsx)("div",{ref:nn,role:"menu","aria-label":V("todo.title"),style:{position:"fixed",top:t7.top,right:t7.right,width:300,maxHeight:"min(440px, calc(100dvh - 44px))",overflowY:"auto",zIndex:500,background:"var(--popover-glass)",backdropFilter:"blur(var(--glass-blur-panel)) saturate(var(--glass-saturate))",WebkitBackdropFilter:"blur(var(--glass-blur-panel)) saturate(var(--glass-saturate))",transform:"translateZ(0)",border:"1px solid color-mix(in srgb, var(--border) 60%, transparent)",borderRadius:"0 0 12px 12px",boxShadow:"0 1px 2px rgba(15,23,42,0.04), 0 4px 16px -8px rgba(15,23,42,0.10)",fontFamily:"inherit"},children:(0,r.jsx)(rt.t,{todos:t8})}),document.body)]}),K&&rG(!0)]}),(0,r.jsx)("div",{style:{flex:1,overflow:"hidden",position:"relative"},children:el?(0,r.jsx)(rj,{boardId:el,taskId:eu??void 0,newSessionCwd:n$??void 0,onExit:()=>ec(null),onRunningSessionIdsChange:eh,wallSettings:B,updateWallSettings:A},el):rF?(0,r.jsx)(ew.l,{session:ei,sessionRunning:!!(ei&&ea.has(ei.id)),newSessionCwd:rW,newSessionId:r$,newSessionDraftKey:rA,newSessionTaskId:rD,pendingNewSessionTaskRef:tH,onEnvWorktreeChange:nX,onAgentEnd:rs,onAttentionNeeded:rl,onSessionCreated:n7,onSessionForked:rc,modelsRefreshKey:eP,chatInputRef:tz,onBranchDataChange:tU,onSystemPromptChange:tZ,onSystemPromptLoaderChange:tQ,onSessionStatsChange:nr,onSessionStatsPanelOpen:ny,onTodosChange:ni,onContextUsageChange:np,onOpenFile:rR,soundEnabled:Y,onSoundToggle:G,playDoneSound:X,unlockAudio:Z,terminalOpen:eV&&"bottombar"===eK,onToggleTerminal:()=>nw("bottombar"),onAskInNewChat:ru,quoteSelectionEnabled:e5,initialPrompt:e9?.sessionId===ei?.id?e9?.text:void 0,onInitialPromptConsumed:()=>te(null)},eL):"validating"===ey?(0,r.jsxs)("div",{role:"status",style:{height:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:8,padding:24,color:"var(--text-muted)",textAlign:"center"},children:[(0,r.jsx)("div",{style:{fontSize:14,color:"var(--text)"},children:V("workspace.opening")}),(0,r.jsx)("div",{style:{maxWidth:"min(720px, 100%)",overflowWrap:"anywhere",fontFamily:"var(--font-mono)",fontSize:12},children:L.requestedCwd})]}):"error"===ey?(0,r.jsxs)("div",{role:"alert",style:{height:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:8,padding:24,color:"var(--text-muted)",textAlign:"center"},children:[(0,r.jsx)("div",{style:{fontSize:14,color:"#dc2626"},children:V("workspace.unable")}),(0,r.jsx)("div",{style:{maxWidth:"min(720px, 100%)",overflowWrap:"anywhere",fontFamily:"var(--font-mono)",fontSize:12},children:L.requestedCwd}),(0,r.jsx)("div",{style:{maxWidth:720,fontSize:12},children:ej})]}):rO?n$?(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:15},children:V("workspace.selectSession")}):(0,r.jsxs)("div",{style:{position:"absolute",top:12,left:12,display:"flex",alignItems:"flex-start",gap:8,userSelect:"none",pointerEvents:"none"},children:[(0,r.jsxs)("svg",{width:"44",height:"44",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:.7,flexShrink:0},children:[(0,r.jsx)("line",{x1:"20",y1:"12",x2:"4",y2:"12"}),(0,r.jsx)("polyline",{points:"10 6 4 12 10 18"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{style:{fontSize:18,fontWeight:600,color:"var(--text)",marginBottom:8},children:V("workspace.getStarted")}),(0,r.jsxs)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.8},children:[(0,r.jsx)("span",{style:{color:"var(--text-meta)",marginRight:6},children:"1."}),V("workspace.selectProject"),(0,r.jsx)("br",{}),(0,r.jsx)("span",{style:{color:"var(--text-meta)",marginRight:6},children:"2."}),V("workspace.addModels")]})]})]}):null})]}),(0,r.jsx)("div",{"aria-hidden":"true",className:`right-panel-overlay-backdrop${tn?" is-open":""}`,onClick:()=>tr(!1)}),tn&&(0,r.jsx)("div",{...tI.separatorProps,"aria-controls":"file-panel",className:`panel-resize-handle right-panel-resize-handle${tI.isResizing?" is-resizing":""}`,"data-resize-handle":"right-panel",title:`${V("layout.resizeFilePanel")}: ${V("layout.resizeHint")}`}),(0,r.jsxs)("div",{ref:tI.panelRef,id:"file-panel",className:`right-panel-container glass-canvas${tn?" right-panel-open":" right-panel-closed"}${tI.isResizing?" right-panel-resizing":""}`,style:{"--right-panel-width":`${tI.width}px`,display:"flex",flexDirection:"column",borderLeft:"1px solid color-mix(in srgb, var(--border) 80%, transparent)",backgroundColor:"var(--file-panel)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",flexShrink:0,height:"calc(36px + env(safe-area-inset-top))",paddingTop:"env(safe-area-inset-top)",background:"var(--file-panel-chrome)",borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)("div",{style:{flex:1,overflow:"hidden"},children:(0,r.jsx)(e7,{tabs:nT,activeTabId:nI??"",onSelectTab:nL,onCloseTab:rE})}),(0,r.jsx)("button",{type:"button",onClick:()=>tr(!1),"aria-controls":"file-panel","aria-expanded":tn,title:V("files.hidePanel"),"aria-label":V("files.hidePanel"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"var(--side-active)",border:"none",borderLeft:"1px solid var(--border)",color:"var(--text)",cursor:"pointer",flexShrink:0,transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text)"},children:(0,r.jsxs)("svg",{width:"16",height:"16",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:"3",width:"18",height:"18",rx:"2"}),(0,r.jsx)("line",{x1:"15",y1:"3",x2:"15",y2:"21"})]})})]}),(0,r.jsx)("div",{style:{flex:1,overflow:"hidden",paddingBottom:"env(safe-area-inset-bottom)"},children:r_?.filePath?(0,r.jsx)(e6,{filePath:r_.filePath,cwd:n$??void 0,sourceSessionId:r_.sourceSessionId,gitRefreshKey:ez,initialDisplayMode:r_.initialDisplayMode,initialState:r_.viewerState,watchEnabled:tn,onStateChange:e=>nR(r_.id,r_.viewerRevision??0,e),onMentionLines:tn?nW:void 0,onAtMention:nE,onOpenFile:e=>rL(e,(0,I.WP)(e),{sourceSessionId:r_.sourceSessionId})},`${r_.id}:${r_.viewerRevision??0}`):(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-meta)",fontSize:12},children:V("files.noneOpen")})})]})]}),(0,r.jsx)(rw,{origin:eK,anchorRect:eG,activeCwd:ei?.cwd??rW??null,activeProjectLabel:r8,hidden:!eV,onClose:()=>eJ(!1)}),eQ&&(0,r.jsx)(n1,{cwd:ei?.cwd??rW??null,sessionId:ei?.id??null,initialSection:eQ,quoteSelectionEnabled:e5,onQuoteSelectionChange:tt,onClose:()=>{e0(null),e$(e=>e+1)},onSessionReloaded:()=>eE(e=>e+1)}),eB&&rH&&(0,r.jsx)(n5,{cwd:rH,busy:eF,error:eO,onCancel:()=>{eF||eA(!1)},onConfirm:()=>void rU()})]})}}},e=>{e.O(0,[3578,7330,5362,8441,3794,7358],()=>e(e.s=26365)),_N_E=e.O()}]);
|