@baique/pi-web-sky 0.1.48 → 0.1.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/app-path-routes-manifest.json +17 -17
  3. package/.next/build-manifest.json +2 -2
  4. package/.next/required-server-files.js +1 -1
  5. package/.next/required-server-files.json +1 -1
  6. package/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  7. package/.next/server/app/_global-error.html +1 -1
  8. package/.next/server/app/_global-error.rsc +1 -1
  9. package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  10. package/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  11. package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  12. package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  13. package/.next/server/app/_not-found.html +1 -1
  14. package/.next/server/app/_not-found.rsc +2 -2
  15. package/.next/server/app/_not-found.segments/_full.segment.rsc +2 -2
  16. package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +2 -2
  17. package/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  18. package/.next/server/app/api/agent/[id]/bash-output/route.js +2 -2
  19. package/.next/server/app/api/app-update/route.js +1 -1
  20. package/.next/server/app/api/board-assets/[...path]/route.js +2 -2
  21. package/.next/server/app/api/board-assets/route.js +2 -2
  22. package/.next/server/app/api/boards/reorder/route.js +2 -2
  23. package/.next/server/app/api/boards/route.js +2 -2
  24. package/.next/server/app/api/cwd/validate/route.js +2 -2
  25. package/.next/server/app/api/default-cwd/route.js +2 -2
  26. package/.next/server/app/api/file-index/route.js +2 -2
  27. package/.next/server/app/api/files/[...path]/route.js +2 -2
  28. package/.next/server/app/api/mcp/route.js +2 -2
  29. package/.next/server/app/api/models/route.js +2 -2
  30. package/.next/server/app/api/plugins/route.js +2 -2
  31. package/.next/server/app/api/search/route.js +2 -2
  32. package/.next/server/app/api/sessions/[id]/entries/[entryId]/thinking/route.js +2 -2
  33. package/.next/server/app/api/sessions/[id]/export/route.js +2 -2
  34. package/.next/server/app/api/sessions/summary/route.js +2 -2
  35. package/.next/server/app/api/skills/install/route.js +2 -2
  36. package/.next/server/app/api/task-card-questions/[id]/answer/route.js +1 -1
  37. package/.next/server/app/api/task-card-questions/route.js +1 -1
  38. package/.next/server/app/api/tasks/[id]/assign-session/route.js +2 -2
  39. package/.next/server/app/api/tasks/reorder/route.js +2 -2
  40. package/.next/server/app/api/tasks/route.js +2 -2
  41. package/.next/server/app/api/worktrees/route.js +2 -2
  42. package/.next/server/app/index.html +1 -1
  43. package/.next/server/app/index.rsc +4 -4
  44. package/.next/server/app/index.segments/__PAGE__.segment.rsc +4 -4
  45. package/.next/server/app/index.segments/_full.segment.rsc +4 -4
  46. package/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  47. package/.next/server/app/page.js +1 -1
  48. package/.next/server/app/page_client-reference-manifest.js +1 -1
  49. package/.next/server/app-paths-manifest.json +17 -17
  50. package/.next/server/chunks/3500.js +2 -2
  51. package/.next/server/chunks/4226.js +2 -2
  52. package/.next/server/chunks/5794.js +2 -2
  53. package/.next/server/chunks/5940.js +2 -2
  54. package/.next/server/chunks/6525.js +2 -2
  55. package/.next/server/middleware-build-manifest.js +1 -1
  56. package/.next/server/pages/404.html +1 -1
  57. package/.next/server/pages/500.html +1 -1
  58. package/.next/static/chunks/app/{layout-34c3afa7e57644fe.js → layout-eb4df7493f8710df.js} +1 -1
  59. package/.next/static/chunks/app/{page-72aa0bf9f2c8b93d.js → page-6ff5ffc29de8ba5f.js} +1 -1
  60. package/.next/trace +7 -7
  61. package/.next/trace-build +1 -1
  62. package/bin/pi-web-options.js +1 -1
  63. package/lib/pi-web-options.test.mjs +3 -3
  64. package/lib/project-command-env.test.mjs +4 -4
  65. package/lib/request-security.test.mjs +50 -50
  66. package/lib/request-security.ts +1 -1
  67. package/lib/sqlite-db.ts +5 -0
  68. package/package.json +1 -1
  69. /package/.next/static/{m9gWh8uFYWdcMxBdc3tY5 → -gLK6QyBXk9SPd4ajO5tR}/_buildManifest.js +0 -0
  70. /package/.next/static/{m9gWh8uFYWdcMxBdc3tY5 → -gLK6QyBXk9SPd4ajO5tR}/_ssgManifest.js +0 -0
@@ -1,4 +1,4 @@
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:()=>u});var r=n(95155),i=n(12115),o=n(47650),a=n(39247),s=n(20985);function l(e,t){return t&&e.startsWith(t)?"~"+e.slice(t.length):e}function d({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 c=(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 u({cwd:e,onSelect:t,style:n,labelStyle:p,onOpenChange:h,showMainLabel:g=!0,compact:x=!1}){let{t:f}=(0,a.s)(),[m,v]=(0,i.useState)(null),[b,y]=(0,i.useState)(!1),[k,w]=(0,i.useState)(""),[j,S]=(0,i.useState)(!1),[C,T]=(0,i.useState)(!1),[M,R]=(0,i.useState)(""),[I,L]=(0,i.useState)(!1),[z,E]=(0,i.useState)(""),[W,P]=(0,i.useState)(null),[$,D]=(0,i.useState)(!1),[B,A]=(0,i.useState)(null),F=(0,i.useRef)(null),N=(0,i.useRef)(null),H=(0,i.useRef)(null),O=(0,i.useRef)(null),[U,_]=(0,i.useState)(null);(0,i.useEffect)(()=>{fetch("/api/home").then(e=>e.json()).then(e=>{e.home&&w(e.home)}).catch(()=>{})},[]);let V=(0,i.useRef)(null);(0,i.useEffect)(()=>{if(!e||V.current===e)return;let t=!1;return y(!0),fetch(`/api/worktrees?cwd=${encodeURIComponent(e)}`).then(e=>e.json()).then(n=>{if(!t){if(y(!1),n.error||!n.projectRoot)return void v(null);v({forCwd:e,projectRoot:n.projectRoot,projectKey:n.projectKey??"",isGit:n.isGit??!1,isTopLevel:n.isTopLevel??!1,currentWorktreePath:n.currentWorktreePath??null,worktrees:n.worktrees??[]}),V.current=e}}).catch(()=>{t||y(!1)}),()=>{t=!0}},[e]);let q=m?m.worktrees.find(t=>t.path===e)??(m.forCwd===e&&m.currentWorktreePath?m.worktrees.find(e=>e.path===m.currentWorktreePath):void 0)??m.worktrees.find(e=>e.isMain):void 0,J=(0,i.useCallback)(()=>{let e=N.current?.getBoundingClientRect();if(!e)return;let t=window.innerHeight-e.bottom<Math.min(320,e.top);_({left:e.left,top:t?e.top:e.bottom,width:e.width,up:t}),S(!0)},[]);(0,i.useEffect)(()=>{h?.(j)},[j,h]);let K=(0,i.useCallback)(e=>{S(!1),P(null),R(""),t?.(e,m?{projectRoot:m.projectRoot,projectKey:m.projectKey,worktreePaths:m.worktrees.map(e=>e.path)}:void 0)},[t,m]),Y=(0,i.useCallback)(async()=>{let e=z.trim();if(e&&!$&&m){D(!0),P(null);try{let n=await fetch("/api/worktrees",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:m.projectRoot,branch:e})}),r=await n.json().catch(()=>({}));if(!n.ok||r.error||!r.path)return void P(r.error??`HTTP ${n.status}`);L(!1),E(""),v(t=>t?{...t,worktrees:[...t.worktrees,{path:r.path,branch:e,isMain:!1}]}:t),S(!1),P(null),R(""),t?.(r.path,m?{projectRoot:m.projectRoot,projectKey:m.projectKey,worktreePaths:[...m.worktrees.map(e=>e.path),r.path]}:void 0)}catch(e){P(e instanceof Error?e.message:String(e))}finally{D(!1)}}},[z,$,m,t]),G=(0,i.useCallback)(async(e,n)=>{if(m&&!$){D(!0),P(null);try{let r=await fetch("/api/worktrees",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:m.projectRoot,path:e,force:n})}),i=await r.json().catch(()=>({}));if(!r.ok){if(i.dirty&&!n)return void A(e);P(i.error??`HTTP ${r.status}`);return}A(null),v(t=>t?{...t,worktrees:t.worktrees.filter(t=>t.path!==e)}:t),q?.path===e&&(S(!1),P(null),R(""),t?.(m.projectRoot,m?{projectRoot:m.projectRoot,projectKey:m.projectKey,worktreePaths:m.worktrees.filter(t=>t.path!==e).map(e=>e.path)}:void 0))}catch(e){P(e instanceof Error?e.message:String(e))}finally{D(!1)}}},[m,$,q?.path,t]);(0,i.useEffect)(()=>{let e=e=>{let t=e.target;F.current?.contains(t)||H.current?.contains(t)||(S(!1),L(!1),E(""),P(null),A(null),R(""))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let X=(m?.worktrees.length??0)>=8,Z=X&&M.trim()?(m?.worktrees??[]).filter(e=>(e.branch??l(e.path,k)).toLowerCase().includes(M.trim().toLowerCase())):m?.worktrees??[],Q=q?.path??null,ee=null!==m&&!(m.isGit&&m.isTopLevel),et=ee?m.isGit?"当前为仓库子目录,子目录会话保持自身项目身份":"该目录不是 git 仓库,worktree 切换不可用":null;return(0,r.jsxs)("div",{ref:F,style:{position:"relative"},children:[(0,r.jsxs)("button",{ref:N,onClick:ee?void 0:J,title:ee?et??void 0:q?q.path:f("sidebar.switchWorktree"),style:{display:"flex",alignItems:"center",gap:6,height:28,boxSizing:"border-box",padding:x?"0 6px":"0 10px",maxWidth:x?85:void 0,background:j?"var(--side-active)":C?"var(--side-hover)":"transparent",border:"none",borderRadius:5,cursor:ee?"default":"pointer",fontSize:11,lineHeight:1.35,color:"var(--text-muted)",textAlign:"left",transition:"background 0.12s",...n},onMouseEnter:()=>T(!0),onMouseLeave:()=>T(!1),children:[c,(0,r.jsx)(d,{text:q?q.branch??l(q.path,k):b?"…":f("sidebar.worktrees"),style:{flex:1,fontFamily:"var(--font-mono)",color:"var(--text)",...p}}),g&&q?.isMain&&(0,r.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10},children:f("sidebar.main")}),!x&&!ee&&(m?.worktrees.length??0)>1&&(0,r.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10},children:m.worktrees.length}),!x&&!ee&&(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"})})]}),U&&(0,o.createPortal)((0,r.jsx)("div",{ref:H,style:{position:"fixed",left:U.left,top:U.top,width:U.width,zIndex:1e3},children:(0,r.jsxs)(s.f,{open:j,up:U.up,style:{position:"absolute",top:U.up?"auto":4,bottom:U.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:[X&&(0,r.jsx)("div",{style:{padding:"6px 8px",borderBottom:"1px solid var(--border)"},children:(0,r.jsx)("input",{value:M,onChange:e=>R(e.target.value),onKeyDown:e=>{"Escape"===e.key&&(R(""),S(!1))},placeholder:f("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:[Z.map(e=>{let t=e.path===Q;return B===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:f("sidebar.forceRemoveCheckout")}),(0,r.jsx)("button",{onClick:()=>void G(e.path,!0),disabled:$,style:{padding:"3px 9px",background:"#ef4444",border:"none",borderRadius:5,color:"#fff",fontSize:11,fontWeight:600,cursor:"pointer",flexShrink:0},children:f("sidebar.force")}),(0,r.jsx)("button",{onClick:()=>A(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:f("sidebar.cancel")})]},e.path):(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",borderBottom:"1px solid var(--border)"},children:[(0,r.jsxs)("button",{onClick:()=>K(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)(d,{text:e.branch??l(e.path,k),style:{flex:1}}),e.isMain&&(0,r.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10},children:f("sidebar.main")})]}),!e.isMain&&(0,r.jsx)("button",{onClick:()=>void G(e.path,!1),disabled:$,title:f("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)}),X&&0===Z.length&&M.trim()&&(0,r.jsx)("div",{style:{padding:"8px 10px",fontSize:11,color:"var(--text-dim)"},children:f("sidebar.noMatchingWorktrees")})]}),I?(0,r.jsxs)("div",{style:{padding:"6px 8px"},children:[(0,r.jsx)("input",{ref:O,value:z,onChange:e=>{E(e.target.value),P(null)},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),Y()),"Escape"===e.key&&(L(!1),E(""),P(null))},placeholder:f("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 Y(),disabled:$||!z.trim(),style:{flex:1,padding:"4px 0",background:"var(--accent)",border:"none",borderRadius:5,color:"#fff",fontSize:11,fontWeight:600,cursor:$||!z.trim()?"not-allowed":"pointer",opacity:$||!z.trim()?.65:1},children:$?f("sidebar.creating"):f("sidebar.create")}),(0,r.jsx)("button",{onClick:()=>{L(!1),E(""),P(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:f("sidebar.cancel")})]})]}):(0,r.jsxs)("button",{onClick:e=>{e.stopPropagation(),L(!0),P(null),setTimeout(()=>O.current?.focus(),0)},title:f("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:f("sidebar.newWorktree")})]}),W&&(0,r.jsx)("div",{style:{padding:"5px 10px 8px",color:"#dc2626",fontSize:11,lineHeight:1.35,overflowWrap:"anywhere"},children:W})]})}),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):""}},25069:(e,t,n)=>{"use strict";n.d(t,{AppShell:()=>nk});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(1518);let p="pi-web:last-open-by-workspace";function h(){try{return window.localStorage}catch{return null}}function g(e){let t=e.getItem(p);if(!t)return{};try{let e=JSON.parse(t);return null===e||"object"!=typeof e||Array.isArray(e)?{}:e}catch{return{}}}function x(e,t=h()){if(t)try{let n=g(t);if(!(e in n))return;delete n[e],0===Object.keys(n).length?t.removeItem(p):t.setItem(p,JSON.stringify(n))}catch{}}function f(e){return e.projectKey??e.projectRoot??e.cwd}function m(e){let t=new Map;for(let n of e){let e=n.projectRoot??n.cwd;if(!e)continue;let r=f(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}))}var v=n(39247),b=n(20985);function y(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 k=n(29608),w=n(30527),j=n(28999);async function S(e){let t=(0,j.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,j.e_)(e,t.name),isDir:t.isDir,size:t.size,children:t.isDir?[]:void 0,loaded:!t.isDir}))}async function C(e,t){let n=new URLSearchParams({type:"search",q:t}),r=await fetch(`/api/files/${(0,j.HG)(e)}?${n.toString()}`);if(!r.ok)throw Error(`Search failed (HTTP ${r.status})`);return r.json()}async function T(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 M={modified:"files.modified",added:"files.added",deleted:"files.deleted",renamed:"files.renamed",untracked:"files.untracked",conflict:"files.conflict"},R={modified:"#d6a84b",added:"#4ade80",deleted:"#f87171",renamed:"#60a5fa",untracked:"#4ade80",conflict:"#f87171"};function I({status:e,t}){return(0,r.jsx)("span",{title:t(M[e.status]),"aria-label":t(M[e.status]),style:{width:14,height:14,flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",color:R[e.status],fontFamily:"var(--font-mono)",fontSize:11,fontWeight:600},children:e.code})}function L({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 z({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 E({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,j.A0)(e.fullPath),m=u.get(f),v=e.isDir&&(void 0!==m||p.has(f)),[b,y]=(0,i.useState)(e.children??[]),[k,C]=(0,i.useState)(e.loaded??!1),[T,M]=(0,i.useState)(!1),[R,z]=(0,i.useState)(!1),W=(0,i.useCallback)(async(t=!1)=>{if(!k||t){M(!0);try{let t=await S(e.fullPath);y(t),C(!0)}catch{}finally{M(!1)}}},[k,e.fullPath]);(0,i.useEffect)(()=>{g&&k&&W(!0)},[d]);let P=(0,i.useCallback)(()=>{if(e.isDir){let t=!g;l(e.fullPath,t),t&&!k&&W()}else o(e.fullPath,e.name)},[e.isDir,e.fullPath,e.name,k,g,W,o,l]);return(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{onClick:P,onMouseEnter:()=>z(!0),onMouseLeave:()=>z(!1),style:{position:"relative",display:"flex",alignItems:"center",gap:4,paddingLeft:8+14*t,paddingRight:8,height:24,cursor:"pointer",background:R?"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)(w.sj,{size:14,open:g}):(0,w.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"}})}),!R&&!e.isDir&&m&&(0,r.jsx)(I,{status:m,t:h}),!R&&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"}})}),T&&(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&&R&&(0,r.jsxs)("button",{onClick:t=>{t.stopPropagation(),a((0,j.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)(L,{}),h("files.mention")]}),R&&!e.isDir&&(0,r.jsx)("a",{href:`/api/files/${(0,j.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)(E,{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 W({status:e,cwd:t,onOpenFile:n,t:o}){let[a,s]=(0,i.useState)(!1),l=(0,j.WP)(e.filePath),d=(0,j.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)(I,{status:e,t:o}),(0,r.jsx)("span",{style:{flexShrink:0,display:"flex",alignItems:"center",opacity:.85},children:(0,w.I3)(l,13)}),(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:d})]})}function P({match:e,cwd:t,onOpenFile:n}){let[o,a]=(0,i.useState)(!1),s=(0,j.WP)(e.path);return(0,r.jsxs)("div",{onClick:()=>n((0,j.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)(w.sj,{size:13}):(0,w.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 $=(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,v.s)(),[h,g]=(0,i.useState)([]),[x,f]=(0,i.useState)(!0),[m,b]=(0,i.useState)(null),[y,k]=(0,i.useState)(new Set),[w,M]=(0,i.useState)(0),[I,$]=(0,i.useState)(new Set),[D,B]=(0,i.useState)([]),[A,F]=(0,i.useState)({additions:0,deletions:0}),[N,H]=(0,i.useState)("idle"),[O,U]=(0,i.useState)(0),[_,V]=(0,i.useState)(null),[q,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}:${w}`,er="idle"!==N,ei=(0,i.useMemo)(()=>new Map(D.map(e=>[(0,j.A0)(e.filePath),e])),[D]),eo=(0,i.useMemo)(()=>{let t=new Set,n=(0,j.A0)(e).replace(/\/$/,"");for(let e of D){let r=(0,j.gX)((0,j.A0)(e.filePath));for(;(r===n||r.startsWith(`${n}/`))&&(t.add(r),r!==n);){let e=(0,j.gX)(r);if(e===r)break;r=e}}return t},[e,D]),ea=(0,i.useCallback)((e,t)=>{k(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&&($(new Set(n.map(t=>(0,j.e_)(e,t)))),M(e=>e+1))},[e]),el=(0,i.useCallback)(async(t,n)=>{Y(null),V(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,j.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){V(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),$(new Set),Y(null),V(null),U(0),H("checking");try{let n=await fetch(`/api/files/${(0,j.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){V(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&&(k(new Set),$(new Set),J(null),Y(null),V(null),X(""),Q(null)),f(t),b(null);let n=!1;return S(e).then(e=>{n||g(e)}).catch(e=>{n||b(e instanceof Error?e.message:String(e))}).finally(()=>{n||f(!1)}),()=>{n=!0}},[e,n,w]),(0,i.useEffect)(()=>{let t=!1;return T(e).then(e=>{t||(B(e.isGitRepository?e.files:[]),F(e.isGitRepository?{additions:e.additions,deletions:e.deletions}:{additions:0,deletions:0}))}).catch(()=>{t||(B([]),F({additions:0,deletions:0}))}),()=>{t=!0}},[e,n,w]),(0,i.useEffect)(()=>{let t=G.trim();if(!t)return void Q(null);let n=!1,r=setTimeout(()=>{C(e,t).then(e=>{n||Q(e.matches)}).catch(()=>{n||Q([])})},200);return()=>{n=!0,clearTimeout(r)}},[e,G]),(0,i.useEffect)(()=>{d?.(D.length)},[D,d]);let eu=er||null!==K||null!==_||null!==q,ep=!l&&D.length>0,eh=(0,i.useCallback)(()=>{q&&0!==q.uploaded.length&&a?.(q.uploaded.map(t=>(0,j.qP)((0,j.e_)(e,t),e)))},[e,a,q]);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"===N?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"===N?(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"===N&&(0,r.jsxs)("span",{style:{fontSize:10},children:[O,"%"]})]}),"uploading"===N&&(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)(z,{onClick:()=>V(null),title:p("files.dismissError")})]}),q&&(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:[q.uploaded.length>0&&(0,r.jsxs)("span",{title:`${q.uploaded.length} uploaded`,"aria-label":`${q.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:q.uploaded.length})]}),q.skipped.length>0&&(0,r.jsxs)("span",{title:`${q.skipped.length} skipped`,"aria-label":`${q.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:q.skipped.length})]}),q.errors.length>0&&(0,r.jsxs)("span",{title:`${q.errors.length} failed`,"aria-label":`${q.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:q.errors.length})]})]}),q.uploaded.length>0&&a&&(0,r.jsxs)("button",{type:"button",onClick:eh,title:1===q.uploaded.length?p("files.addUploadedFile"):p("files.addAllUploadedFiles"),"aria-label":1===q.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)(L,{}),p("files.mention")]}),(0,r.jsx)(z,{onClick:()=>J(null),title:p("files.dismissUploadResults")})]}),q.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:D.length,additions:A.additions,deletions:A.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:D.length})}),(0,r.jsxs)("span",{style:{color:R.added,fontFamily:"var(--font-mono)"},children:["+",A.additions]}),(0,r.jsxs)("span",{style:{color:R.deleted,fontFamily:"var(--font-mono)"},children:["-",A.deletions]})]}),D.map(n=>(0,r.jsx)(W,{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)(P,{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)(E,{node:n,depth:0,cwd:e,onOpenFile:t,onAtMention:o,expandedPaths:y,onToggleExpanded:ea,refreshToken:en,highlightedPaths:I,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 D({active:e,onChange:t,runningCount:n=0}){let{t:o}=(0,v.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)})})}function B({activeBoardId:e,collapsed:t,onToggleCollapsed:n,onOpenBoard:o,onExitBoard:a,refreshKey:s}){let{t:l}=(0,v.s)(),[d,c]=(0,i.useState)([]),[,u]=(0,i.useState)(!0),[p,h]=(0,i.useState)(!1),[g,x]=(0,i.useState)(""),[f,m]=(0,i.useState)(null),[b,y]=(0,i.useState)(""),[k,w]=(0,i.useState)(null),[j,S]=(0,i.useState)(!1),[C,T]=(0,i.useState)(null),[M,R]=(0,i.useState)(null),I=(0,i.useRef)(null),L=(0,i.useRef)(null),z=(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 c(t.boards),t.boards}catch{return null}finally{u(!1)}},[]);(0,i.useEffect)(()=>{z()},[z,s]),(0,i.useEffect)(()=>{p&&I.current?.focus()},[p]),(0,i.useEffect)(()=>{f&&L.current?.focus()},[f]);let E=async()=>{let e=g.trim();if(e&&!j){S(!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();x(""),h(!1),await z(),o(e.board.id)}}finally{S(!1)}}},W=async e=>{if(j)return;let t=b.trim();if(!t)return void m(null);S(!0);try{(await fetch(`/api/boards/${encodeURIComponent(e)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t})})).ok&&(m(null),await z())}finally{S(!1)}},P=async t=>{if(!j){S(!0);try{if((await fetch(`/api/boards/${encodeURIComponent(t)}`,{method:"DELETE"})).ok){w(null);let n=await z();if(e===t){let e=(n??[]).find(e=>!e.isSystem&&null==e.taskId&&e.id!==t);e?o(e.id):a?.()}}}finally{S(!1)}}},$=(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",T({id:e}),R(null))},[]),D=(0,i.useCallback)(e=>t=>{if(!t.dataTransfer.types.includes("application/x-board-id")||!C||C.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})},[C]),F=(0,i.useCallback)(e=>t=>{t.preventDefault();let n=t.dataTransfer.getData("application/x-board-id")||C?.id;if(!n||!M||M.targetId!==e){T(null),R(null);return}let r=d.filter(e=>!e.isSystem&&null==e.taskId).map(e=>e.id),i=r.indexOf(n),o=r.indexOf(e);if(T(null),R(null),-1===i||-1===o)return;let a=[...r];a.splice(i,1);let s=a.indexOf(e)+ +!M.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 z()}).catch(()=>{})},[d,M,C,z]),N=d.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:()=>h(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:[p&&(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:I,value:g,onChange:e=>x(e.target.value),onKeyDown:e=>{"Enter"===e.key&&E(),"Escape"===e.key&&(h(!1),x(""))},onBlur:()=>{g.trim()&&E(),h(!1),x("")},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:!g.trim(),onMouseDown:e=>e.preventDefault(),onClick:()=>void E(),style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,background:"transparent",border:"none",borderRadius:5,color:g.trim()?"var(--accent)":"var(--text-dim)",cursor:g.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:()=>{h(!1),x("")},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===N.length&&(0,r.jsx)("div",{style:{padding:"6px 10px",color:"var(--text-muted)",fontSize:11.5,fontStyle:"italic"},children:l("boards.empty")}),N.map(t=>(0,r.jsx)(A,{board:t,isActive:e===t.id,isDragging:C?.id===t.id,dropBefore:M?.targetId===t.id&&M.before,dropAfter:M?.targetId===t.id&&!M.before,renaming:f===t.id,renameValue:b,renameInputRef:L,onRenameValueChange:y,onStartRename:()=>{m(t.id),y(t.name)},onCommitRename:()=>void W(t.id),onCancelRename:()=>m(null),onDelete:()=>w(t.id),onDragStart:$(t.id),onDragEnd:()=>{T(null),R(null)},onDragOver:D(t.id),onDrop:F(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:()=>w(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:()=>w(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 P(k),disabled:j,style:{display:"flex",alignItems:"center",gap:6,padding:"5px 12px",border:"none",borderRadius:6,background:"#dc2626",color:"#fff",cursor:j?"default":"pointer",fontSize:12,opacity:j?.7:1},children:[j&&(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(j?"boards.deleting":"boards.delete")]})]})]})})]})}function A({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:b,onOpenBoard:y}){let{t:k}=(0,v.s)(),[w,j]=(0,i.useState)(!1),S=(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"})]}),C={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:m,onDrop:b,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:y,"data-board-row":e.id,title:e.name,onMouseEnter:()=>j(!0),onMouseLeave:()=>j(!1),style:{display:"flex",alignItems:"center",gap:4,minHeight:38,padding:"0 8px 0 5px",borderRadius:6,background:t?"var(--side-active)":w?"var(--side-hover)":"transparent",cursor:s?"default":"pointer",transition:"background 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:S}),(0,r.jsx)("input",{ref:d,value:l,onChange:e=>c(e.target.value),onKeyDown:e=>{"Enter"===e.key&&p(),"Escape"===e.key&&h()},onBlur:p,autoFocus:!0,placeholder:k("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:S}),(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}),w&&(0,r.jsxs)("span",{style:{position:"relative",display:"flex",gap:3,flexShrink:0,alignItems:"center"},children:[(0,r.jsx)("button",{type:"button",title:k("boards.rename"),"aria-label":k("boards.rename"),onClick:e=>{e.stopPropagation(),u()},style:C,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:k("boards.delete"),"aria-label":k("boards.delete"),onClick:e=>{e.stopPropagation(),g()},style:C,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 F="text/session-id",N=(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"})}),H=(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"})]}),O=(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"})}),U=(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.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"})]}),V="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:k,onOpenBoard:j,onDragStartTask:S,onDragOverTask:C,onDropTask:T,onDragEndTask:M,isDragging:R,dropBefore:I,dropAfter:L}){let{t:z}=(0,v.s)(),[E,W]=(0,i.useState)(!0),P=null!=p&&e.sessionIds.includes(p);(0,i.useEffect)(()=>{P&&W(!1)},[P]);let[$,D]=(0,i.useState)(!1),[B,A]=(0,i.useState)(!1),[J,K]=(0,i.useState)(!1),[Y,G]=(0,i.useState)(""),[X,Z]=(0,i.useState)(!1),[Q,ee]=(0,i.useState)(!1),[et,en]=(0,i.useState)(!1),[er,ei]=(0,i.useState)(!1),eo=(0,i.useRef)(null),ea=(0,i.useRef)(null),es=(0,i.useRef)(null);(0,i.useEffect)(()=>{if(!et&&!X)return;let e=e=>{let t=e.target;ea.current?.contains(t)||es.current?.contains(t)||(en(!1),Z(!1))},t=e=>{"Escape"===e.key&&(en(!1),Z(!1))};return document.addEventListener("pointerdown",e,!0),document.addEventListener("keydown",t),()=>{document.removeEventListener("pointerdown",e,!0),document.removeEventListener("keydown",t)}},[et,X]);let el=(0,i.useCallback)(e=>{if(e.stopPropagation(),et)return void en(!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;ei(!(o>=114)&&(a>=114||a>o)),en(!0)},[et]);(0,i.useEffect)(()=>{if(J){let e=requestAnimationFrame(()=>eo.current?.select());return()=>cancelAnimationFrame(e)}},[J]);let ed=(0,i.useCallback)(()=>{let t=Y.trim();t&&x(e.id,t),K(!1)},[Y,x,e.id]),ec=(0,i.useCallback)(t=>{if(t.dataTransfer.types.includes(V)){let n=t.currentTarget.getBoundingClientRect(),r=t.clientY<n.top+n.height/2,i=C(e.id,r);D(!1),i&&(t.preventDefault(),t.dataTransfer.dropEffect="move");return}t.dataTransfer.types.includes(F)&&(t.preventDefault(),t.dataTransfer.dropEffect="move",D(!0))},[C,e.id]),eu=(0,i.useCallback)(t=>{t.preventDefault(),D(!1);let n=t.dataTransfer.getData(F);n?g(e.id,n):t.dataTransfer.types.includes(V)&&T(e.id)},[g,e.id,T]),ep=(0,i.useCallback)(t=>{t.target.closest("button, input, textarea, a, [role=menuitem]")?t.preventDefault():(t.dataTransfer.setData(V,e.id),t.dataTransfer.effectAllowed="move",S(e))},[e,S]),eh={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:ec,onDragLeave:()=>D(!1),onDrop:eu,style:{position:"relative",margin:"0 4px 2px",borderRadius:6,background:$?"color-mix(in srgb, var(--accent) 8%, transparent)":"transparent",border:"none",boxShadow:$?"inset 2px 0 0 var(--accent)":"none",borderTop:I?"2px solid var(--accent)":"none",borderBottom:L?"2px solid var(--accent)":"none",opacity:R?.4:1,transition:"background 0.12s, box-shadow 0.12s"},children:[(0,r.jsx)("div",{draggable:!0,onDragStart:ep,onDragEnd:M,onClick:()=>{e.sessionIds.length>0&&W(e=>!e)},onMouseEnter:()=>A(!0),onMouseLeave:()=>A(!1),style:{display:"flex",alignItems:"center",gap:4,minHeight:38,padding:"0 8px 0 5px",borderRadius:6,background:h?"var(--side-active)":B?"var(--side-hover)":"transparent",cursor:"pointer",transition:"background 0.12s"},children:J?(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)(w.sj,{size:13,open:!E})}),(0,r.jsx)("input",{ref:eo,value:Y,onChange:e=>G(e.target.value),onKeyDown:e=>{"Enter"===e.key&&ed(),"Escape"===e.key&&K(!1)},onBlur:ed,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)(w.sj,{size:13,open:!E})}),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&&!J&&!X&&(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"})]})}),(B||et||X)&&!J&&(0,r.jsxs)("span",{ref:ea,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(),j(e.id)},style:{...eh,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:U}),(0,r.jsx)("button",{type:"button",title:z("sidebar.newTaskSession"),onClick:t=>{t.stopPropagation(),m(e.id)},style:{...eh,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:O}),(0,r.jsx)("button",{type:"button",title:z("sidebar.rename"),onClick:t=>{t.stopPropagation(),G(e.name),K(!0),en(!1)},style:{...eh,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:N}),(0,r.jsx)("button",{type:"button",title:z("sidebar.moreActions"),"aria-expanded":et,"aria-haspopup":"menu",onClick:el,style:{...eh,width:28,height:28,background:et?"var(--side-active)":"transparent",color:et?"var(--accent)":"var(--text-muted)"},onMouseEnter:e=>{et||(e.currentTarget.style.background="var(--side-active)",e.currentTarget.style.color="var(--accent)")},onMouseLeave:e=>{et||(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)(b.f,{open:et,up:er,style:{position:"absolute",top:er?"auto":"calc(100% + 4px)",bottom:er?"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(),en(!1),k(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:_}),z(e.pinned?"sidebar.unpinTask":"sidebar.pinTask")]}),(0,r.jsxs)("button",{role:"menuitem",onClick:t=>{t.stopPropagation(),en(!1),G(e.name),K(!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:N}),z("sidebar.rename")]}),(0,r.jsxs)("button",{role:"menuitem",onClick:e=>{e.stopPropagation(),en(!1),ee(!!ea.current&&y(ea.current,96)),Z(!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:H}),z("sidebar.deleteTask")]})]})}),X&&(0,r.jsxs)("div",{ref:es,role:"alertdialog",style:{position:"absolute",...Q?{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),Z(!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(),Z(!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")})]})]})]})]})}),!E&&(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 J({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,v.s)(),[m,b]=(0,i.useState)(""),[y,k]=(0,i.useState)(!1),[j,S]=(0,i.useState)(!1),C=(0,i.useRef)(null),[T,M]=(0,i.useState)(null),[R,I]=(0,i.useState)(null),[L,z]=(0,i.useState)(null);(0,i.useEffect)(()=>{a&&C.current?.focus()},[a]);let E=(0,i.useCallback)(()=>{let e=m.trim();e&&(l(e),b(""),s(!1))},[m,l,s]),W=(0,i.useCallback)(e=>{I({id:e.id,pinned:!!e.pinned}),z(null)},[]),P=(0,i.useCallback)(()=>{I(null),z(null)},[]),$=(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&&(z({targetId:t,before:n}),!0)},[R,e]),D=(0,i.useCallback)(t=>{if(!R||!L||L.targetId!==t)return void P();let n=e.map(e=>e.task.id),r=n.indexOf(R.id),i=n.indexOf(t);if(-1===r||-1===i)return void P();let o=[...n];o.splice(r,1);let a=o.indexOf(t)+ +!L.before;o.splice(a,0,R.id),P(),x(o)},[R,e,P,x,L]);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)(w.sj,{size:13,open:!1})}),(0,r.jsx)("input",{ref:C,value:m,onChange:e=>b(e.target.value),onKeyDown:e=>{"Enter"===e.key&&E(),"Escape"===e.key&&(s(!1),b(""))},onBlur:()=>{let e=m.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:!m.trim(),onMouseDown:e=>e.preventDefault(),onClick:E,onMouseEnter:()=>k(!0),onMouseLeave:()=>k(!1),style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,background:y&&m.trim()?"var(--side-hover)":"transparent",border:"none",borderRadius:5,color:m.trim()?"var(--accent)":"var(--text-dim)",cursor:m.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:()=>S(!0),onMouseLeave:()=>S(!1),style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,background:j?"var(--side-hover)":"transparent",border:"none",borderRadius:5,color:j?"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()=>{M(a.id);try{await b()}finally{M(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:T===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:W,onDragOverTask:$,onDropTask:D,onDragEndTask:P,isDragging:R?.id===a.id,dropBefore:L?.targetId===a.id&&L.before,dropAfter:L?.targetId===a.id&&!L.before})]},a.id)})]})}function K({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 Y="pi-web:unread-session-ids";function G(e,t){return t&&e.startsWith(t)?"~"+e.slice(t.length):e}function X({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 Z(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 Q="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";function ee(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 et(){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:Q[Math.floor(Math.random()*Q.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.48p0.84.3":"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 en({selectedSessionId:e,onSelectSession:t,onNewSession:n,initialSessionId:o,skipInitialProjectSelection:a,onInitialRestoreDone:s,refreshKey:l,onSessionDeleted:d,selectedCwd:u,onCwdChange:p,onOpenFile:h,explorerRefreshKey:g,onExplorerRefresh:x,onRefresh:y,onSessionsLoaded:w,onAtMention:j,onAtMentions:S,onBackgroundTaskDone:C,onRunningSessionIdsChange:T,onNewSessionFromTask:M,onOpenBoard:R,onOpenTaskBoard:I,onExitBoard:L,activeBoardId:z,activeWorktreeProject:E}){let{t:W}=(0,v.s)(),[P,A]=(0,i.useState)([]),[F,N]=(0,i.useState)([]),[H,O]=(0,i.useState)(!1),U=(0,i.useRef)(null),[_,V]=(0,i.useState)(!0),[q,Q]=(0,i.useState)(null),[ei,eo]=(0,i.useState)(null),[ea,eh]=(0,i.useState)(""),[eg,ex]=(0,i.useState)(!1),[ef,em]=(0,i.useState)(!1),[ev,eb]=(0,i.useState)(""),[ey,ek]=(0,i.useState)(!1),[ew,ej]=(0,i.useState)(""),[eS,eC]=(0,i.useState)(null),[eT,eM]=(0,i.useState)(!1),[eR,eI]=(0,i.useState)(null),[eL,ez]=(0,i.useState)(null),eE=E??eL,eW=(0,i.useRef)(null),[eP,e$]=(0,i.useState)("sessions"),[eD,eB]=(0,i.useState)(!1),[eA,eF]=(0,i.useState)(!1),[eN,eH]=(0,i.useState)(!1),[eO,eU]=(0,i.useState)(!1),[e_,eV]=(0,i.useState)([]),[eq,eJ]=(0,i.useState)(!1),[eK,eY]=(0,i.useState)(0),[eG,eX]=(0,i.useState)(!1),[eZ,eQ]=(0,i.useState)(0),[e0,e1]=(0,i.useState)(!0),[e2,e4]=(0,i.useState)(!1),[e8,e5]=(0,i.useState)(!1),[e6,e3]=(0,i.useState)(()=>new Set),[e7,e9]=(0,i.useState)(()=>new Set),te=(0,i.useRef)(new Set);(0,i.useEffect)(()=>{e$(function(){try{return"files"===window.localStorage.getItem(es)?"files":"sessions"}catch{return"sessions"}}()),eB(eu(el)),eF(eu(ed)),eH(eu(ec)),e9(function(){try{let e=window.localStorage.getItem(Y);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 tt=(0,i.useRef)(!1),tn=(0,i.useRef)(null),tr=(0,i.useRef)(null),ti=(0,i.useRef)(null),to=(0,i.useRef)(null),ta=(0,i.useCallback)(async()=>{let e=U.current;if(!e)return;let t=to.current;if(t&&t.key===e)return t.promise;let n=(async()=>{O(!0);try{let t=await fetch(`/api/sessions?project=${encodeURIComponent(e)}`,{cache:"no-store"});if(!t.ok)return;let n=await t.json();U.current===e&&(N(n.sessions??[]),tt.current||e3(new Set(n.runningSessionIds??[])))}catch{}finally{O(!1)}})();to.current={key:e,promise:n};try{await n}finally{to.current?.key===e&&(to.current=null)}},[]),ts=(0,i.useCallback)(async(e=!1)=>{try{e&&V(!0),await ta();let t=await fetch("/api/sessions",{cache:"no-store"});if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();A(n.sessions),w?.(n.sessions),tt.current||e3(new Set(n.runningSessionIds??[]));let r=new Set(n.sessions.map(e=>e.id));e9(e=>{if(0===e.size)return e;let t=new Set([...e].filter(e=>r.has(e)));return t.size===e.size?e:t}),Q(null),e||(e4(!0),tn.current&&clearTimeout(tn.current),tn.current=setTimeout(()=>e4(!1),2e3))}catch(e){Q(String(e))}finally{e&&V(!1)}},[w,ta]);(0,i.useEffect)(()=>{try{0===e7.size?window.localStorage.removeItem(Y):window.localStorage.setItem(Y,JSON.stringify([...e7]))}catch{}},[e7]),(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;tt.current=!0,e3(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)(()=>{T?.(e6)},[T,e6]),(0,i.useEffect)(()=>{let t=te.current,n=[...t].filter(t=>!e6.has(t)&&t!==e),r=[...e6].filter(e=>!t.has(e));(n.length>0||r.length>0)&&e9(e=>{let t=new Set(e);return e6.forEach(e=>t.delete(e)),n.forEach(e=>t.add(e)),t});let i=r.some(e=>!P.some(t=>t.id===e));(n.length>0||i)&&ts(!1),n.length>0&&C?.(n),te.current=e6},[e6,e,P,ts,C]),(0,i.useEffect)(()=>{e&&e9(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[e]),(0,i.useEffect)(()=>{void 0!==g&&eY(e=>e+1)},[g]),(0,i.useEffect)(()=>{fetch("/api/home").then(e=>e.json()).then(e=>{e.home&&eh(e.home)}).catch(()=>{})},[]);let tl=(0,i.useRef)(!1),td=(0,i.useCallback)((e,t)=>({root:e,key:t}),[]),tc=(0,i.useCallback)(e=>{if(!e)return null;if(eR?.cwd===e)return td(eR.root,eR.key);if(eE&&(e===eE.projectRoot||eE.worktreePaths.includes(e)))return td(eE.projectRoot,eE.projectKey);let t=P.find(t=>t.cwd===e||(t.projectRoot??t.cwd)===e);return t?td(t.projectRoot??t.cwd,f(t)):td(e,e)},[eR,eE,P,td]),tu=(0,i.useRef)(null);(0,i.useEffect)(()=>{let e=tc(ei),t=tu.current;(t?.cwd!==ei||t.key!==(e?.key??null))&&(tu.current={cwd:ei,key:e?.key??null},p?.(ei,e?.root??null,e?.key??null))},[ei,p,tc]);let tp=(0,i.useRef)(null);(0,i.useEffect)(()=>{u&&u!==tp.current&&(tp.current=u,eo(u))},[u]),(0,i.useEffect)(()=>{if(0!==P.length&&!a&&null===ei){if(o&&!tl.current){tl.current=!0;let e=P.find(e=>e.id===o);if(e){eo(e.cwd),t(e,!0);return}s?.()}let e=m(P);e.length>0&&eo(e[0].root)}},[P,ei,o,a,t,s]);let th=(0,i.useCallback)(async e=>{let t=(e??ew).trim();if(t&&!eT){eM(!0),eC(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 eC(n.error??`HTTP ${e.status}`);eI({cwd:n.cwd,root:n.projectRoot,key:n.projectKey}),eo(n.cwd),ek(!1),ej(""),ex(!1)}catch(e){eC(e instanceof Error?e.message:String(e))}finally{eM(!1)}}},[ew,eT]),tg=(0,i.useCallback)(()=>{ek(!0),eC(null),ex(!1)},[]),tx=(0,i.useCallback)(async()=>{try{let e=await fetch("/api/default-cwd",{method:"POST"}),t=await e.json();t.cwd&&(eo(t.cwd),ek(!1),ej(""),eC(null),ex(!1))}catch{}},[]);(0,i.useEffect)(()=>{let e=e=>{eW.current&&!eW.current.contains(e.target)&&(ex(!1),eb(""))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let tf=(0,i.useCallback)(e=>{e.cwd&&eo(e.cwd),t(e)},[t]),tm=(0,i.useCallback)(()=>{if(!ei)return;let e="function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}-${Math.random().toString(36).slice(2)}`;n?.(e,ei)},[ei,n]),tv=m(P),tb=tv.length>8,ty=ev.trim()?tv.filter(e=>e.root.toLowerCase().includes(ev.trim().toLowerCase())):tv,tk=tc(ei);U.current=tk?.key??null;let tw=(0,i.useRef)(null);(0,i.useEffect)(()=>{let e=tk?.key??null;tw.current===e||(tw.current=e,e&&ta())},[tk?.key,ta]);let tj=(0,i.useMemo)(()=>(function(e,t,n){let r=new Map;for(let i of e){let e=f(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})(P,e6,e7),[P,e6,e7]),tS=(0,i.useMemo)(()=>[...tj.entries()].some(([e,{running:t,unread:n}])=>e!==tk?.key&&(t>0||n>0)),[tj,tk]),tC=(0,i.useRef)(0),tT=(0,i.useCallback)(()=>{let e=tk?.key,t=++tC.current;e?fetch(`/api/tasks?projectKey=${encodeURIComponent(e)}`,{cache:"no-store"}).then(e=>e.ok?e.json():null).then(e=>{t===tC.current&&eV(t=>ee(t,Array.isArray(e?.tasks)?e.tasks:[]))}).catch(()=>{}):eV([])},[tk?.key]);(0,i.useEffect)(()=>{tT()},[tT]);let tM=(0,i.useRef)(!1),tR=(0,i.useRef)(null),tI=(0,i.useRef)(!1);(0,i.useEffect)(()=>{let e=!tM.current;if(tM.current=!0,e)return void ts(!0);if(tI.current){tI.current=!1,ts(!1),tT();return}return tR.current&&clearTimeout(tR.current),tR.current=setTimeout(()=>{tR.current=null,ts(!1),tT()},300),()=>{tR.current&&clearTimeout(tR.current)}},[ts,tT,l]);let tL=(0,i.useCallback)(async()=>{let e=tk?.key;if(!e)return;let t=await fetch(`/api/tasks?projectKey=${encodeURIComponent(e)}`,{cache:"no-store"}),n=await t.json().catch(()=>({}));eV(e=>ee(e,Array.isArray(n.tasks)?n.tasks:[]))},[tk?.key]),tz=(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;eV(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{}},[]),tE=(0,i.useCallback)((e,t)=>{A(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;N(e=>e.map(n)),eV(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(()=>{tL(),ta()})},[tL,ta]),tW=(0,i.useCallback)(e=>{let t=e_.find(t=>t.id===e);if(!t)return;let n=!t.pinned;eV(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(()=>tL())},[e_,tL]),tP=(0,i.useCallback)(e=>{let t=tk?.key;if(!t)return;let n=new Map(e_.map(e=>[e.id,e])),r=[],i=[];for(let t of e){let e=n.get(t);e&&(e.pinned?r:i).push(t)}eV(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(()=>{})},[e_,tk?.key]),t$=(0,i.useCallback)((e,t)=>{let n=n=>n.id===e?{...n,name:t}:n;A(e=>e.map(n)),N(e=>e.map(n)),eV(e=>e.map(e=>({...e,sessions:(e.sessions??[]).map(n)})))},[]);(0,i.useEffect)(()=>{let e=e=>{let t=e.detail;t?.sessionId&&t?.name&&t$(t.sessionId,t.name)};return window.addEventListener("pi-web:board-session-renamed",e),()=>window.removeEventListener("pi-web:board-session-renamed",e)},[t$]),(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 tD=(0,i.useCallback)(async e=>{let t=tk?.key;t&&(await fetch("/api/tasks",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({projectKey:t,name:e})}),await tL())},[tk?.key,tL]),tB=(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 tL()},[tL]),tA=(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 tL()},[tL,d]),tF=(0,i.useCallback)(async(e,t)=>{let n=e_.find(t=>t.id===e);!n||n.sessionIds.includes(t)||(await fetch(`/api/tasks/${encodeURIComponent(e)}/assign-session`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:t})}),await tL())},[e_,tL]),tN=(0,i.useCallback)(async e=>{let t=e_.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 tL())},[e_,tL]);function tH(e){let t=(e,t)=>e.session.modified<t.session.modified?1:e.session.modified>t.session.modified?-1:0;return[...e.filter(e=>e.session.pinned).sort(t),...e.filter(e=>!e.session.pinned).sort(t)]}let tO=e=>e.reduce((e,t)=>e+1+tO(t.children),0),tU=(0,i.useMemo)(()=>e_.map(e=>{let t=tH(Z(e.sessions??[])),n=e.sessionTotal??tO(t);return{task:e,nodes:t,sessionTotal:n}}),[e_]),t_=(0,i.useMemo)(()=>tH(Z([...F.filter(e=>e6.has(e.id)),...F.filter(e=>!e6.has(e.id))])),[F,e6]);return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[ey&&(0,r.jsx)(k.K,{busy:eT,error:eS,onCancel:()=>{ek(!1),eC(null)},onSelect:e=>void th(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)(et,{}),(0,r.jsxs)("div",{style:{display:"flex",gap:2,alignItems:"center"},children:[(0,r.jsxs)("button",{onClick:tm,disabled:!ei,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,background:"transparent",border:"none",color:ei?"var(--text-muted)":"var(--text-dim)",cursor:ei?"pointer":"not-allowed",padding:"3px 6px",borderRadius:4,fontSize:12,fontWeight:500,letterSpacing:"-0.01em",flexShrink:0,textDecoration:"none",transition:"color 0.12s"},title:ei?W("sidebar.newSessionTitle",{path:ei}):W("sidebar.selectProject"),onMouseEnter:e=>{ei&&(e.currentTarget.style.color="var(--accent)",e.currentTarget.style.textDecoration="underline")},onMouseLeave:e=>{e.currentTarget.style.color=ei?"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"})}),W("sidebar.tempSessions")]}),(0,r.jsxs)("button",{onClick:()=>{y?(tI.current=!0,y()):(ts(!1),tT())},style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,background:e2?"rgba(74,222,128,0.12)":"transparent",border:"none",color:e2?"#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=>{e2||(e.currentTarget.style.color="var(--accent)",e.currentTarget.style.textDecoration="underline")},onMouseLeave:e=>{e2||(e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.textDecoration="none")},title:W("sidebar.refresh"),children:[e2?(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"})]}),W("sidebar.refresh")]})]})]}),(0,r.jsxs)("div",{ref:eW,style:{position:"relative",display:"flex",alignItems:"center",borderRadius:7,background:eg?"var(--side-active)":ef?"var(--side-hover)":ei?"color-mix(in srgb, var(--glass-bg-strong) 55%, transparent)":"color-mix(in srgb, var(--accent) 8%, transparent)",border:ei?"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:()=>em(!0),onMouseLeave:()=>em(!1),children:[(0,r.jsxs)("button",{onClick:()=>ex(e=>!e),title:tk?.root??ei??"",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:[ei?(0,r.jsx)(X,{text:G(tk?.root??ei,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&&!tl.current?"":W("sidebar.selectProject")}),tS&&(0,r.jsx)("span",{title:W("sidebar.newActivity"),"aria-label":W("sidebar.newActivity"),style:{width:8,height:8,borderRadius:"50%",flexShrink:0,marginLeft:6,background:"var(--accent)"}})]}),ei&&(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:ei,onSelect:(e,t)=>{t&&ez(t),eo(e),ex(!1)},onOpenChange:e=>{e&&ex(!1)},showMainLabel:!1,compact:!0,style:{height:"auto",background:"transparent",flexShrink:0,borderRadius:0,maxWidth:85}})]}),(0,r.jsxs)(b.f,{open:eg,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:[tb&&(0,r.jsx)("div",{style:{padding:"6px 8px",borderBottom:"1px solid var(--border)"},children:(0,r.jsx)("input",{value:ev,onChange:e=>eb(e.target.value),onKeyDown:e=>{"Escape"===e.key&&(eb(""),ex(!1))},placeholder:W("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:[ty.map(e=>{var t,n;return(0,r.jsxs)("button",{onClick:()=>{eo(e.root),eb(""),ek(!1),ej(""),eC(null),ex(!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===tk?.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===tk?.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!==tk?.key&&(0,r.jsx)("span",{style:{width:10,flexShrink:0}}),(0,r.jsx)(X,{text:G(e.root,ea),style:{flex:1}}),(t=tj.get(e.key),n=W,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===ty.length&&ev.trim()&&(0,r.jsx)("div",{style:{padding:"8px 10px",fontSize:11,color:"var(--text-dim)"},children:W("sidebar.noMatchingProjects")})]}),!ey&&(0,r.jsxs)("button",{onClick:e=>{e.stopPropagation(),tx()},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",borderTop:ty.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:W("sidebar.useDefaultDirectory")})]}),(0,r.jsxs)("button",{onClick:e=>{e.stopPropagation(),tg()},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:W("sidebar.customPath")})]})]})]})]}),(0,r.jsx)(D,{active:eP,runningCount:e6.size,onChange:e=>{e$(e),function(e){try{window.localStorage.setItem(es,e)}catch{}}(e)}}),(0,r.jsx)("div",{style:{flex:1,minHeight:0,display:"sessions"===eP?"flex":"none",flexDirection:"column",overflowY:"auto",overflowX:"hidden"},children:_?(0,r.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:W("sidebar.loading")}):q?(0,r.jsx)("div",{style:{padding:"12px 14px",color:"#f87171",fontSize:12},children:q}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(B,{activeBoardId:z??null,collapsed:eD,refreshKey:l,onToggleCollapsed:()=>{let e=!eD;eB(e),ep(el,e)},onOpenBoard:e=>R?.(e),onExitBoard:L}),(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=!eA;eF(e),ep(ed,e)},"aria-expanded":!eA,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:W("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:eA?"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:()=>eU(e=>!e),title:W("sidebar.newTask"),"aria-label":W("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"})]})})]}),!eA&&(0,r.jsx)("div",{style:{overflowX:"hidden"},children:(0,r.jsx)(J,{groups:tU.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:()=>tz(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)(er,{node:t,selectedSessionId:e,runningSessionIds:e6,unreadSessionIds:e7,onSelectSession:tf,onRenamed:(e,t)=>t$(e,t),onSessionDeleted:e=>{d?.(e)},onTogglePin:tE,depth:0},t.session.id))}),(0,r.jsx)("div",{style:{paddingLeft:14,paddingBottom:2},children:o})}}}),selectedSessionId:e,activeBoardId:z,runningSessionIds:e6,newTaskOpen:eO,onNewTaskOpenChange:eU,onNewTask:e=>void tD(e),onRenameTask:(e,t)=>void tB(e,t),onDeleteTask:e=>void tA(e),onNewSessionFromTask:e=>M?.(e,tk?.key??void 0),onToggleTaskPin:tW,onOpenTaskBoard:e=>I?.(e),onDropSessionToTask:(e,t)=>void tF(e,t),onReorderTasks:tP})})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",minHeight:0,flex:eN?"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=!eN;eH(e),ep(ec,e)},"aria-expanded":!eN,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:W("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:eN?"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"})})]})}),!eN&&(0,r.jsxs)("div",{onDragOver:e=>{e.dataTransfer.types.includes("text/session-id")&&(e.preventDefault(),e.dataTransfer.dropEffect="move",eJ(!0))},onDragLeave:()=>eJ(!1),onDrop:e=>{e.preventDefault(),eJ(!1);let t=e.dataTransfer.getData("text/session-id");t&&tN(t)},style:{flex:1,minHeight:0,overflowY:"auto",overflowX:"hidden",background:eq?"color-mix(in srgb, var(--accent) 8%, transparent)":"transparent"},children:[t_.map((t,n)=>{let i=!!t.session.pinned,o=n>0&&!!t_[n-1].session.pinned;return(0,r.jsxs)("div",{children:[o&&!i&&(0,r.jsx)("div",{style:{margin:"2px 6px 4px",height:1,background:"color-mix(in srgb, var(--border) 45%, transparent)"}}),(0,r.jsx)(er,{node:t,selectedSessionId:e,runningSessionIds:e6,unreadSessionIds:e7,onSelectSession:tf,onRenamed:(e,t)=>t$(e,t),onSessionDeleted:e=>{d?.(e)},onTogglePin:tE,depth:0})]},t.session.id)}),0===t_.length&&0===tU.length&&(0,r.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:W("sidebar.noSessions")}),t_.length>0&&(0,r.jsx)(r.Fragment,{children:H&&(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:W("sidebar.loading")})]})})]})]})]})}),(0,r.jsx)("div",{style:{flex:1,display:"files"===eP?"flex":"none",flexDirection:"column",minHeight:0,overflow:"hidden"},children:(u||ei)&&(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)($,{ref:ti,cwd:ei??u,onOpenFile:h??(()=>{}),refreshKey:eK,onAtMention:j,onAtMentions:S,onUploadBusyChange:eX,changesCollapsed:e0,onChangesCountChange:eQ,toolbar:(0,r.jsxs)(r.Fragment,{children:[eZ>0&&(0,r.jsx)(K,{onClick:()=>e1(e=>!e),title:W("sidebar.changedFiles",{count:eZ}),ariaPressed:!e0,color:e0?"var(--text-dim)":"var(--accent)",background:e0?"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)(K,{onClick:()=>ti.current?.openUploadPicker(),disabled:eG,title:W("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)(K,{onClick:()=>{x?x():eY(e=>e+1),e5(!0),tr.current&&clearTimeout(tr.current),tr.current=setTimeout(()=>e5(!1),2e3)},title:W("sidebar.refreshExplorer"),skipHover:e8,color:e8?"#4ade80":"var(--text-dim)",background:e8?"rgba(74,222,128,0.18)":"none",marginRight:0,children:e8?(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"})]})})]})})})})})]})}function er({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)(ea,{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)(er,{node:e,selectedSessionId:t,runningSessionIds:n,unreadSessionIds:o,onSelectSession:a,onRenamed:s,onSessionDeleted:l,onTogglePin:d,depth:c+1},e.session.id))})]})}function ei(){let{t:e}=(0,v.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 eo(){let{t:e}=(0,v.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 ea({session:e,isSelected:t,isRunning:n,isUnread:o,onClick:a,onRenamed:s,onDeleted:l,onTogglePin:d,depth:c=0,hasChildren:p=!1,collapsed:h=!1,onToggleCollapse:g}){let{t:x}=(0,v.s)(),[f,m]=(0,i.useState)(!1),[k,w]=(0,i.useState)(!1),[j,S]=(0,i.useState)(""),[C,T]=(0,i.useState)(!1),[M,R]=(0,i.useState)(!1),[I,L]=(0,i.useState)(!1),[z,E]=(0,i.useState)(!1),[W,P]=(0,i.useState)(!1),$=(0,i.useRef)(null),D=(0,i.useRef)(null);(0,i.useEffect)(()=>{if(!z&&!C)return;let e=e=>{D.current&&!D.current.contains(e.target)&&(E(!1),T(!1))},t=e=>{"Escape"===e.key&&(E(!1),T(!1))};return document.addEventListener("pointerdown",e,!0),document.addEventListener("keydown",t),()=>{document.removeEventListener("pointerdown",e,!0),document.removeEventListener("keydown",t)}},[z,C]);let B=(0,i.useCallback)(e=>{if(e.stopPropagation(),z)return void E(!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;P(!(o>=114)&&(a>=114||a>o)),E(!0)},[z]);(0,i.useEffect)(()=>{if(k){let e=requestAnimationFrame(()=>$.current?.select());return()=>cancelAnimationFrame(e)}},[k]);let A=(0,u.d)(e.firstMessage),F=A?.command??e.firstMessage,N=e.name||F.slice(0,50)||e.id.slice(0,12),H=(0,i.useCallback)(t=>{t.stopPropagation(),e.transient||(E(!1),S(e.name||F.slice(0,50)||e.id.slice(0,12)),w(!0))},[e.name,e.transient,F,e.id]),O=(0,i.useCallback)(async()=>{let t=j.trim();if(w(!1),j!==N&&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{}},[j,e.id,e.name,s,N]),U=(0,i.useCallback)(async()=>{if(!e.transient){T(!1),L(!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{L(!1)}}},[e.id,e.transient,l]),_=(0,i.useCallback)(e=>{e.stopPropagation(),E(!1),R(!!D.current&&y(D.current,96)),T(!0)},[]),V=(0,i.useCallback)(e=>{e.stopPropagation(),U()},[U]),q=(0,i.useCallback)(e=>{e.stopPropagation(),T(!1)},[]),J=(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:C||k?void 0:a,onContextMenu:C||k?void 0:J,onMouseEnter:()=>m(!0),onMouseLeave:()=>{m(!1)},draggable:!k&&!C,onDragStart:t=>{E(!1),t.dataTransfer.setData("text/session-id",e.id),t.dataTransfer.setData("text/session-title",N),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:C||k?"default":"pointer",background:C?"color-mix(in srgb, #ef4444 7%, transparent)":t?"color-mix(in srgb, var(--accent) 8%, transparent)":f?"var(--side-hover)":"transparent",borderLeft:"2px solid transparent",transition:"background 0.1s",opacity:I?.5:1,gap:6},children:k?(0,r.jsx)("input",{ref:$,value:j,onChange:e=>S(e.target.value),onBlur:O,onKeyDown:e=>{"Enter"===e.key&&O(),"Escape"===e.key&&w(!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)(ei,{}):o?(0,r.jsx)(eo,{}):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:N,style:{flex:1,minWidth:0,fontSize:12,fontWeight:t?500:400,lineHeight:1.4,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:N})]}),f&&p&&!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"})})}),(f||z||C)&&!e.transient&&(0,r.jsxs)("div",{ref:D,style:{position:"relative",display:"flex",gap:4,flexShrink:0,alignItems:"center"},children:[(0,r.jsx)("button",{onClick:H,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:B,"aria-expanded":z,"aria-haspopup":"menu",title:x("sidebar.moreActions"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:z?"var(--side-active)":"transparent",border:"1px solid transparent",borderRadius:7,color:z?"var(--accent)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{z||(e.currentTarget.style.background="var(--side-active)",e.currentTarget.style.color="var(--accent)")},onMouseLeave:e=>{z||(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)(b.f,{open:z,up:W,style:{position:"absolute",top:W?"auto":"calc(100% + 4px)",bottom:W?"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(),E(!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(),E(!1),H(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(),E(!1),_(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")]})]})}),C&&(0,r.jsxs)("div",{role:"alertdialog",style:{position:"absolute",...M?{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:N.slice(0,30)+(N.length>30?"…":"")})}),(0,r.jsxs)("div",{style:{display:"flex",gap:6,justifyContent:"flex-end"},children:[(0,r.jsx)("button",{onClick:V,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:q,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 es="pi-sidebar-tab",el="pi-sidebar-boards-collapsed",ed="pi-sidebar-tasks-collapsed",ec="pi-sidebar-chat-collapsed";function eu(e){try{return"1"===window.localStorage.getItem(e)}catch{return!1}}function ep(e,t){try{t?window.localStorage.setItem(e,"1"):window.localStorage.removeItem(e)}catch{}}var eh=n(71594),eg=n(84876),ex=n(50640),ef=n(65063),em=n(7644),ev=n(32316),eb=n(96793);let ey={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"},ek={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",webm:"audio/webm"};function ew(e){return(e.replace(/\\/g,"/").split("/").pop()??"").toLowerCase().split(".").pop()??""}var ej=n(19870),eS=n(73620);let eC=/^(?:\uFEFF)?---[ \t]*(?:\r\n|\n|\r)/;function eT(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 eM=n(68925),eR=n(40233);let eI=["tags","categories","keywords","tag","category"];function eL({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=eI.find(t=>Array.isArray(e[t])),a=o?e[o].map(eT).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=eT(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 ez=n(82490);let eE={source:"Source",preview:"Preview",diff:"Diff"},eW={fontFamily:"var(--font-mono)",fontSize:13,lineHeight:1.6},eP={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 e$(){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 eD(e){let t=e.nodeType===Node.ELEMENT_NODE?e:e.parentElement;return t?.closest(".file-source-line[data-line-number]")??null}function eB(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=eD(n.startContainer),i=eD(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 eA({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,ex.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,ex.Ay)({node:e,stylesheet:t,useInlineStyles:n,key:`source-token-${o}-${r}`}))})]},`source-line-${o}`)})}function eF(e,t,n,r={}){let i=(0,j.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 eN({filePath:e,sourceSessionId:t}){let{t:n}=(0,v.s)();return(0,r.jsx)("a",{href:eF(e,"download",t),download:(0,j.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 eH(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function eO({patch:e}){let t,{t:n}=(0,v.s)(),i=(t=(0,ez.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%",...eW},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:eP,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 eU({filePath:e,cwd:t,sourceSessionId:n,watchEnabled:o=!0}){let{t:a}=(0,v.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),b=(0,i.useRef)(0),y=(0,j.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(eF(e,"watch",n));m.current=r,r.addEventListener("connected",()=>{let r;l(!0),r=++b.current,fetch(eF(e,"meta",n)).then(e=>e.json()).then(e=>{if(t&&r===b.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===b.current&&f(String(e))})}),r.addEventListener("change",e=>{b.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 k=eF(e,"read",n,d?{v:d}:void 0),w=null!=u?eH(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,j.qP)(e,t)}),(0,r.jsx)("span",{style:{marginLeft:"auto"},children:y||"image"}),h&&(0,r.jsxs)("span",{children:[h.w," \xd7 ",h.h]}),w&&(0,r.jsx)("span",{children:w}),(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)(eN,{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:k,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 e_({filePath:e,cwd:t,sourceSessionId:n,watchEnabled:o=!0}){let{t:a}=(0,v.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),b=(0,i.useRef)(0),y=(0,j.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(eF(e,"watch",n));m.current=r,r.addEventListener("connected",()=>{let r;l(!0),r=++b.current,fetch(eF(e,"meta",n)).then(e=>e.json()).then(e=>{if(t&&r===b.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===b.current&&f(String(e))})}),r.addEventListener("change",e=>{b.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 k=eF(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,j.qP)(e,t)}),(0,r.jsx)("span",{style:{marginLeft:"auto"},children:y||"audio"}),null!=h&&(0,r.jsx)("span",{children:function(e){if(!Number.isFinite(e))return"";let t=Math.round(e),n=Math.floor(t/60);return`${n}:${String(t%60).padStart(2,"0")}`}(h)}),null!=u&&(0,r.jsx)("span",{children:eH(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)(eN,{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:k,onLoadedMetadata:e=>g(e.currentTarget.duration),onError:()=>f("Failed to load audio"),style:{width:"100%"}},k)]})})]})}function eV({filePath:e,cwd:t,sourceSessionId:n,watchEnabled:o=!0}){let{t:a}=(0,v.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=ew(e),b="pdf"===m,y=b?eF(e,"read",n,d?{v:d}:void 0):eF(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(eF(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),!b&&e.size>0xa00000&&g("DOCX too large for preview (>10MB)")))}).catch(e=>{t&&r===f.current&&g(String(e))}),()=>{t=!1}},[e,b,n]),(0,i.useEffect)(()=>{if(l(!1),x.current&&(x.current.close(),x.current=null),!o)return;let t=!0,r=new EventSource(eF(e,"watch",n));x.current=r,r.addEventListener("connected",()=>{let r;l(!0),r=++f.current,fetch(eF(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),!b&&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),!b&&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,b,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,j.qP)(e,t)}),(0,r.jsx)("span",{style:{marginLeft:"auto"},children:"docx"===m?"docx preview":"pdf"}),null!=u&&(0,r.jsx)("span",{children:eH(u)}),(0,r.jsx)(eN,{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:y,sandbox:b?void 0:"allow-same-origin",title:a("i18n.previewFile",{file:(0,j.WP)(e)}),style:{width:"100%",height:"100%",border:"none",background:b?"var(--bg)":"#eef1f5"}},y)})]})}function eq({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!==(ey[ew(e)]??null)?(0,r.jsx)(eU,{filePath:e,cwd:t,sourceSessionId:n,watchEnabled:u}):null!==(ek[ew(e)]??null)?(0,r.jsx)(e_,{filePath:e,cwd:t,sourceSessionId:n,watchEnabled:u}):null!==("pdf"===(p=ew(e))||"docx"===p?p:null)?(0,r.jsx)(eV,{filePath:e,cwd:t,sourceSessionId:n,watchEnabled:u}):(0,r.jsx)(eJ,{filePath:e,cwd:t,sourceSessionId:n,onOpenFile:i,onMentionLines:o,onAtMention:a,gitRefreshKey:s,initialDisplayMode:l,initialState:d,onStateChange:c,watchEnabled:u})}function eJ({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,eb.D)(),{t:g}=(0,v.s)(),[x,f]=(0,i.useState)(null),[m,b]=(0,i.useState)(null),[y,k]=(0,i.useState)(!1),[w,S]=(0,i.useState)(!1),[C,T]=(0,i.useState)(!0),[M,R]=(0,i.useState)(null),I=c?.displayMode??d??"source",L=c?.wrapLines??!1,z=c?.scrollTop??0,E=c?.scrollLeft??0,[W,P]=(0,i.useState)(I),[$,D]=(0,i.useState)(L),[B,A]=(0,i.useState)(!1),F=(0,i.useRef)(null),N=(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),V=(0,i.useRef)(!0),q=(0,i.useRef)({displayMode:I,wrapLines:L,scrollTop:z,scrollLeft:E}),J=(0,i.useRef)(u),[K,Y]=(0,i.useState)(null);J.current=u;let G=(0,i.useCallback)(e=>{q.current.displayMode=e,P(e)},[]),X=(0,i.useCallback)(()=>{D(e=>{let t=!e;return q.current.wrapLines=t,t})},[]);(0,i.useEffect)(()=>(q.current={displayMode:I,wrapLines:L,scrollTop:z,scrollLeft:E},V.current=!0,U.current=!1,P(I),D(L),()=>{J.current?.({...q.current})}),[e,n,I,L,z,E]);let Z=(0,i.useCallback)(e=>{let t=++N.current;return fetch(eF(e,"read",n)).then(e=>e.json()).then(e=>t!==N.current?null:e.error?(R(e.error),null):(R(null),f(e),e)).catch(e=>(t!==N.current||R(String(e)),null))},[n]),Q=(0,i.useCallback)(async e=>{let n=++H.current;if(k(!0),!t){b(null),k(!1),S(!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;b(i.ok&&o.supported&&"string"==typeof o.patch?o:null)}catch{n===H.current&&b(null)}finally{n===H.current&&(k(!1),S(!0))}},[t]);(0,i.useEffect)(()=>{let t=!0;return T(!0),R(null),f(null),b(null),S(!1),A(!1),Z(e).finally(()=>{t&&T(!1)}),()=>{t=!1}},[e,Z,n]),(0,i.useEffect)(()=>{if(A(!1),F.current&&(F.current.close(),F.current=null),!p)return;let t=()=>{Z(e),Q(e)},r=new EventSource(eF(e,"watch",n));F.current=r,r.addEventListener("connected",()=>{A(!0),t()}),r.addEventListener("change",t);let i=()=>{A(!1)};return r.addEventListener("error",i),r.onerror=i,()=>{r.close(),F.current===r&&(F.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)(()=>{w&&!ee&&"diff"===W&&G("source")},[W,w,ee,G]),(0,i.useEffect)(()=>{"diff"===I&&ee&&!U.current&&(U.current=!0,G("diff"))},[I,ee,G]);let en=(0,i.useMemo)(()=>x?.language==="markdown"?(0,eM.Ep)(x.content):"",[x]),er=(0,i.useMemo)(()=>x?.language==="markdown"?function(e){let t=function(e){let t=eC.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,eS.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?eB(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,j.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?eB(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(!V.current||C||M&&!et||"diff"===I&&!w||"diff"===I&&ee&&"diff"!==W)return;let e=O.current;e&&(e.scrollTop=q.current.scrollTop,e.scrollLeft=q.current.scrollLeft,V.current=!1)},[x?.content,W,M,w,ee,et,C,I]),C||"diff"===I&&y&&!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(M&&!et)return(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#f87171",fontSize:13},children:M});if(!x&&!et)return null;let eo=x?.language??"text",ea=x?.content??"",es="html"===eo,el="markdown"===eo,ed=(0,j.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 ${eH(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,j.qP)(e,t)}),(0,r.jsx)("span",{className:"file-viewer-meta",title:eh,children:eh}),!et&&(0,r.jsx)("span",{title:B?g("i18n.liveSync"):g("i18n.notWatching"),"aria-label":B?g("i18n.liveSync"):g("i18n.notWatching"),className:"file-viewer-live-indicator",style:{background:B?"#4ade80":"var(--border)",boxShadow:B?"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:eE[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,j.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)(e$,{})}),"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)(eN,{filePath:e,sourceSessionId:n})]})]}),(0,r.jsx)("div",{ref:O,className:"file-viewer-content",onScroll:e=>{q.current.scrollTop=e.currentTarget.scrollTop,q.current.scrollLeft=e.currentTarget.scrollLeft},style:{flex:1,overflow:"auto",background:"transparent"},children:"diff"===eu&&ee?(0,r.jsx)(eO,{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)(eL,{data:er.data}),(0,r.jsx)(ev.oz,{remarkPlugins:eM.iA,rehypePlugins:eM.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)(eR.t,{code:o.replace(/\n$/,""),defaultPreview:!0}):(0,r.jsx)(eR.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,ej.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,ej.V)(e,ed,t??ed):null,s=a?eF(a,"read",n):e;return(0,r.jsx)("img",{src:s,alt:i??"",loading:"lazy",...o})}},children:en})]}):(0,r.jsx)(ef.A,{className:$?"file-source-view is-wrapped":"file-source-view",language:"text"===eo?"plaintext":eo,style:h?em.xJ:em.vs,showLineNumbers:!0,lineNumberStyle:{...eP},customStyle:{margin:0,padding:0,border:0,background:"transparent",...eW,width:$?"100%":"max-content",minWidth:"100%",minHeight:"100%",overflow:"visible"},codeTagProps:{style:{fontFamily:"var(--font-mono)",overflowWrap:$?"anywhere":"normal"}},renderer:e=>(0,r.jsx)(eA,{...e,wrapLines:$}),wrapLongLines:$,children:ea})})]})}function eK({tabs:e,activeTabId:t,onSelectTab:n,onCloseTab:o}){let{t:a}=(0,v.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,w.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)})})}var eY=n(31590);let eG=["input","output","cacheRead","cacheWrite"];function eX(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 eZ(e){if(!eQ(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 eQ(e){return eG.some(t=>""!==e[t].trim())}function e0(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 e1=e=>(0,r.jsx)("svg",{...e0(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"})}),e2=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"})]}),e4=e=>(0,r.jsx)("svg",{...e0(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"})}),e8=e=>(0,r.jsx)("svg",{...e0(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"})}),e5=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"})]}),e6=e=>(0,r.jsx)("svg",{...e0(e),viewBox:"0 0 24 24",children:(0,r.jsx)("path",{d:"M16 6H8v12h8V6zm4 16H4V2h16v20z"})}),e3=e=>(0,r.jsx)("svg",{...e0(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"})}),e7=e=>(0,r.jsx)("svg",{...e0(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"})}),e9={anthropic:{Icon:e=>(0,r.jsx)("svg",{...e0(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:e1,hasColor:!1},"openai-codex":{Icon:e1,hasColor:!1},google:{Icon:e2,hasColor:!0},"google-vertex":{Icon:e2,hasColor:!0},"ant-ling":{Icon:e=>(0,r.jsxs)("svg",{...e0(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",{...e0(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:e4,hasColor:!1},"moonshotai-cn":{Icon:e4,hasColor:!1},moonshot:{Icon:e4,hasColor:!1},minimax:{Icon:e8,hasColor:!0},"minimax-cn":{Icon:e8,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",{...e0(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",{...e0(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",{...e0(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:e5,hasColor:!0},"cloudflare-workers-ai":{Icon:e5,hasColor:!0},"vercel-ai-gateway":{Icon:e=>(0,r.jsx)("svg",{...e0(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",{...e0(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",{...e0(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",{...e0(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:e6,hasColor:!1},"opencode-go":{Icon:e6,hasColor:!1},qwen:{Icon:e=>(0,r.jsx)("svg",{...e0(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:e3,hasColor:!1},"xiaomi-token-plan-ams":{Icon:e3,hasColor:!1},"xiaomi-token-plan-cn":{Icon:e3,hasColor:!1},"xiaomi-token-plan-sgp":{Icon:e3,hasColor:!1},zai:{Icon:e7,hasColor:!1},"zai-coding-cn":{Icon:e7,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",{...e0(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}},te=["openai-completions","openai-responses","anthropic-messages","google-generative-ai"];function tt({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 tn={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 tr({value:e,onChange:t,placeholder:n,mono:i}){return(0,r.jsx)("input",{value:e,onChange:e=>t(e.target.value),placeholder:n,style:{...tn,fontFamily:i?"var(--font-mono)":"inherit"}})}function ti({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,v.s)();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),onKeyDown:a,placeholder:n,style:{...tn,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 to({value:e,onChange:t,placeholder:n}){return(0,r.jsx)("input",{type:"number",value:e,onChange:e=>t(e.target.value),placeholder:n,style:tn})}function ta({value:e,onChange:t,options:n,required:i}){let{t:o}=(0,v.s)();return(0,r.jsxs)("select",{value:e,onChange:e=>t(e.target.value),style:{...tn,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 ts({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 tl({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 td({name:e,provider:t,onChange:n,onRename:o,onDelete:a,onAddModels:s}){let{t:l}=(0,v.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),b=(0,i.useRef)(null);(0,i.useEffect)(()=>c(e),[e]);let y=(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 k=(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]),w=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=>!w.has(e.id)).map(e=>e.id),R=x.filter(e=>!w.has(e)).length,I=M.length>0&&M.every(e=>x.includes(e)),L=!I&&M.some(e=>x.includes(e));return(0,i.useEffect)(()=>{b.current&&(b.current.indeterminate=L)},[L]),(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)(tl,{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)(tt,{label:l("i18n.providerName"),children:[(0,r.jsx)(tr,{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)(tt,{label:"Base URL",children:(0,r.jsx)(tr,{value:t.baseUrl??"",onChange:e=>y("baseUrl",e||void 0),placeholder:"https://api.example.com/v1",mono:!0})}),(0,r.jsxs)(tt,{label:"API Key",children:[(0,r.jsx)(ti,{value:t.apiKey??"",onChange:e=>y("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)(tt,{label:"API",children:(0,r.jsx)(ta,{value:t.api??"openai-completions",onChange:e=>y("api",e),options:te,required:!0})}),(0,r.jsxs)(tt,{label:"Headers",children:[(0,r.jsx)(tx,{headers:t.headers,onChange:e=>y("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:k,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:{...tn,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:b,type:"checkbox",checked:I,disabled:0===M.length,onChange:()=>{let e=new Set(M);f(t=>I?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=w.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)&&!w.has(t.id));0!==t.length&&(s(t),f([]))},disabled:0===R,style:{height:28,padding:"0 11px",border:"none",borderRadius:5,background:R?"var(--accent)":"var(--bg-panel)",color:R?"#fff":"var(--text-dim)",cursor:R?"pointer":"not-allowed",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:R?l("models.discoveryAddSelectedCount",{count:R}):l("models.discoveryAddSelected")})]})]})]})]})}let tc=["off","minimal","low","medium","high","xhigh","max"],tu={off:"var(--text-dim)",minimal:"#6b7280",low:"#60a5fa",medium:"#a78bfa",high:"#f472b6",xhigh:"#fb923c",max:"#ef4444"};function tp({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:tc.map(e=>{let t=n[e],o=e in n?null===t?"null":"string":"omit",a="string"==typeof t?t:"",s=tu[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 th={thinkingFormat:"deepseek",requiresReasoningContentOnAssistantMessages:!0};function tg(e){return e.compat?.thinkingFormat==="deepseek"}function tx({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:{...tn,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:{...tn,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 tf({providerName:e,provider:t,model:n,onChange:o,onDelete:a}){let[s,l]=(0,i.useState)({phase:"idle"}),{t:d}=(0,v.s)(),[c,u]=(0,i.useState)({phase:"idle"}),[p,h]=(0,i.useState)(!1),[g,x]=(0,i.useState)(()=>eX(n.cost)),f=(0,i.useRef)(g),[m,b]=(0,i.useState)(!1),y=(0,i.useRef)(0),k=(0,i.useRef)(null),w=(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)(()=>{y.current+=1,u({phase:"idle"}),k.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=++y.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!==y.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=eZ(eX(i));o>0&&a&&(n.cost={...i,...a},r+=o)}return{model:n,appliedCount:r}}(n,l.recommendation.preset);d.appliedCount>0&&(k.current=n,o(d.model)),h(!1),u({phase:"success",recommendation:l.recommendation,appliedCount:d.appliedCount})}catch(e){if(i!==y.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}`})(),R="error"===c.phase?c.message:M,I="error"===c.phase?"#ef4444":"success"===c.phase&&"unreliable"===c.recommendation.price.status?"#d97706":"var(--text-dim)",L=[{key:"input",label:d("models.costInput")},{key:"output",label:d("models.costOutput")},{key:"cacheRead",label:d("models.costCacheRead")},{key:"cacheWrite",label:d("models.costCacheWrite")}],z=new Set(Object.keys(n.compat??{})),E=0;tg(n)&&(E+=1,z.delete("thinkingFormat"),z.delete("requiresReasoningContentOnAssistantMessages")),Object.prototype.hasOwnProperty.call(n.compat??{},"supportsDeveloperRole")&&(E+=1,z.delete("supportsDeveloperRole")),E+=z.size;let W=[n.api?`API: ${n.api}`:null,Object.keys(n.headers??{}).length?d("models.headersSummary",{count:Object.keys(n.headers??{}).length}):null,E?d("models.compatSummary",{count:E}):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)(tl,{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)(tt,{label:"ID *",children:(0,r.jsx)(tr,{value:n.id,onChange:e=>j("id",e),placeholder:"model-id",mono:!0})}),(0,r.jsx)(tt,{label:"Name",children:(0,r.jsx)(tr,{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")})]}),R&&(0,r.jsxs)("div",{"aria-live":"polite",style:{marginTop:8,display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,color:I,fontSize:10},children:[(0,r.jsx)("span",{title:R,style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:R}),k.current&&(0,r.jsx)("button",{onClick:()=>{let e=k.current;e&&(k.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)(tl,{children:d("models.capabilities")}),(0,r.jsxs)("div",{style:{display:"flex",gap:20,flexWrap:"wrap",marginTop:8},children:[(0,r.jsx)(ts,{label:d("models.reasoning"),checked:n.reasoning??!1,onChange:e=>j("reasoning",e||void 0)}),(0,r.jsx)(ts,{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)(tl,{children:d("models.modelSpecs")}),(0,r.jsx)("button",{type:"button",onClick:()=>{if(p)return void h(!1);w.current=n.cost;let e=eX(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)(tt,{label:d("models.contextWindow"),children:(0,r.jsx)(to,{value:void 0!==n.contextWindow?String(n.contextWindow):"",onChange:e=>j("contextWindow",e?parseInt(e):void 0),placeholder:"128000"})}),(0,r.jsx)(tt,{label:d("models.maxOutputTokens"),children:(0,r.jsx)(to,{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:[L.map(({key:e,label:t})=>(0,r.jsx)(tt,{label:t,children:(0,r.jsx)(to,{value:g[e],onChange:t=>{let r,i,a;return i=eZ(r={...f.current,[e]:t}),a={...n},void(f.current=r,x(r),i?(a.cost={...w.current??{},...i},w.current=a.cost):delete a.cost,o(a))},placeholder:"0"})},e)),eQ(g)&&!eZ(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:L.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:()=>b(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)(tt,{label:d("models.apiOverride"),children:(0,r.jsx)(ta,{value:n.api??"",onChange:e=>j("api",e||void 0),options:te})}),(0,r.jsxs)(tt,{label:d("models.headers"),children:[(0,r.jsx)(tx,{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)(tl,{children:d("models.compatibility")}),(0,r.jsx)(ts,{label:d("models.deepSeekThinkingCompat"),checked:tg(n),onChange:e=>o(function(e,t){if(t)return{...e,compat:{...e.compat??{},...th}};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)(ts,{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)(tl,{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)(tp,{value:n.thinkingLevelMap,onChange:e=>j("thinkingLevelMap",e)})]})]})]})]})]})}function tm({provider:e,onRefresh:t}){let[n,o]=(0,i.useState)({phase:"idle"}),{t:a}=(0,v.s)(),[s,l]=(0,i.useState)(""),d=(0,i.useRef)(null),c=(0,i.useRef)(null);(0,i.useEffect)(()=>{("auth"===n.phase||"prompt"===n.phase)&&setTimeout(()=>c.current?.focus(),50)},[n.phase]),(0,i.useEffect)(()=>{o({phase:"idle"}),l(""),d.current?.close(),d.current=null},[e.id]),(0,i.useEffect)(()=>()=>{d.current?.close()},[]);let u=(0,i.useCallback)(()=>{d.current?.close(),o({phase:"connecting"}),l("");let n=new EventSource(`/api/auth/login/${encodeURIComponent(e.id)}`);d.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]),p=(0,i.useCallback)(async()=>{await fetch(`/api/auth/logout/${encodeURIComponent(e.id)}`,{method:"POST"}),o({phase:"idle"}),t()},[e.id,t]),h=(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]),g=(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]),x="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)(tl,{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:()=>g(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:c,value:s,onChange:e=>l(e.target.value),onKeyDown:e=>{"Enter"===e.key&&h(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:()=>h(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:x?(0,r.jsx)("button",{onClick:()=>{d.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:u,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:p,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 tv({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,v.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)(tl,{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)(tt,{label:"API Key",children:(0,r.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,r.jsx)(ti,{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 tb({id:e,size:t}){let n=e9[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 ty({oauthProviders:e,apiKeyProviders:t,onSelectOAuth:n,onSelectApiKey:o,onAddCustom:a,onClose:s}){let[l,d]=(0,i.useState)(""),{t:c}=(0,v.s)(),u=(0,i.useRef)(null);(0,i.useEffect)(()=>{setTimeout(()=>u.current?.focus(),30)},[]);let p=l.trim().toLowerCase(),h=e.filter(e=>!e.loggedIn&&(!p||e.name.toLowerCase().includes(p))),g=t.filter(e=>!e.configured&&(!p||e.displayName.toLowerCase().includes(p)||e.id.toLowerCase().includes(p))),x=!p||"custom".includes(p)||"openai-compatible".includes(p)||"anthropic-compatible".includes(p),f=h.length+g.length+ +!!x,m={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:u,value:l,onChange:e=>d(e.target.value),onKeyDown: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===f?(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:[x&&(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")}),x&&(0,r.jsxs)("button",{onClick:()=>{a(),s()},style:m,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"})]})})]}),h.length>0&&(0,r.jsx)("div",{style:{gridColumn:"1 / -1",paddingTop:6*!!x,fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:c("i18n.subscriptions")}),h.map(e=>(0,r.jsxs)("button",{onClick:()=>{n(e.id),s()},style:m,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)(tb,{id:e.id,size:28})]},e.id)),g.length>0&&(0,r.jsx)("div",{style:{gridColumn:"1 / -1",paddingTop:6*(h.length>0),fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"API Key"}),g.map(e=>(0,r.jsxs)("button",{onClick:()=>{o(e.id),s()},style:m,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)(tb,{id:e.id,size:28})]},e.id))]})})]})})}function tk({onClose:e,cwd:t}){let n=(0,eY.a)(),{t:o}=(0,v.s)(),[a,s]=(0,i.useState)({providers:{}}),[l,d]=(0,i.useState)(!0),[c,u]=(0,i.useState)(!1),[p,h]=(0,i.useState)(null),[g,x]=(0,i.useState)(!1),[f,m]=(0,i.useState)(null),[b,y]=(0,i.useState)([]),[k,w]=(0,i.useState)([]),[j,S]=(0,i.useState)(!1),C=(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]),T=(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)&&w(e.providers)}).catch(()=>{})},[t]),M=(0,i.useCallback)(()=>{C(),T()},[C,T]);(0,i.useEffect)(()=>{fetch("/api/models-config").then(e=>e.json()).then(e=>{let t=e.providers?e:{...e,providers:{}};s(t);let n=Object.keys(t.providers??{});n.length>0&&m({type:"provider",name:n[0]})}).catch(()=>s({providers:{}})).finally(()=>d(!1)),M()},[M]);let R=(0,i.useCallback)(()=>{let e="new-provider",t=1;for(;a.providers?.[e];)e=`new-provider-${t++}`;s(t=>({...t,providers:{...t.providers??{},[e]:{api:"openai-completions"}}})),m({type:"provider",name:e})},[a.providers]),I=(0,i.useCallback)((e,t)=>{s(n=>({...n,providers:{...n.providers??{},[e]:t}}))},[]),L=(0,i.useCallback)((e,t)=>{s(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)})}),m(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=>{s(t=>{let n={...t.providers??{}};return delete n[e],{...t,providers:n}}),s(e=>{let t=Object.keys(e.providers??{});return m(t.length>0?{type:"provider",name:t[0]}:null),e})},[]),E=(0,i.useCallback)(e=>{s(t=>{let n=t.providers?.[e]??{},r=[...n.models??[],{id:""}];return{...t,providers:{...t.providers??{},[e]:{...n,models:r}}}}),s(t=>{let n=(t.providers?.[e]?.models?.length??1)-1;return m({type:"model",providerName:e,index:n}),t})},[]),W=(0,i.useCallback)((e,t)=>{s(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}}}})},[]),P=(0,i.useCallback)((e,t,n)=>{s(r=>{let i=r.providers?.[e]??{},o=[...i.models??[]];return o[t]=n,{...r,providers:{...r.providers??{},[e]:{...i,models:o}}}})},[]),$=(0,i.useCallback)((e,t)=>{s(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}}}}),m({type:"provider",name:e})},[]),D=(0,i.useCallback)(async()=>{u(!0),h(null),x(!1);try{let e=await fetch("/api/models-config",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)}),t=await e.json();!e.ok||t.error?h(t.error??`HTTP ${e.status}`):(x(!0),setTimeout(()=>x(!1),2e3))}catch(e){h(String(e))}finally{u(!1)}},[a]),B=Object.entries(a.providers??{}),A=b.filter(e=>e.loggedIn),F=k.filter(e=>e.configured),N=(()=>{if(!f)return null;if("oauth"===f.type){let e=b.find(e=>e.id===f.providerId);return e?(0,r.jsx)(tm,{provider:e,onRefresh:M},e.id):null}if("apikey"===f.type){let e=k.find(e=>e.id===f.providerId);return e?(0,r.jsx)(tv,{provider:e,onRefresh:M},e.id):null}if("provider"===f.type){let e=a.providers?.[f.name];return e?(0,r.jsx)(td,{name:f.name,provider:e,onChange:e=>I(f.name,e),onRename:e=>L(f.name,e),onDelete:()=>z(f.name),onAddModels:e=>W(f.name,e)},f.name):null}let e=a.providers?.[f.providerName],t=e?.models?.[f.index];return t?(0,r.jsx)(tf,{providerName:f.providerName,provider:e,model:t,onChange:e=>P(f.providerName,f.index,e),onDelete:()=>$(f.providerName,f.index)},`${f.providerName}-${f.index}`):null})();return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:t=>{t.target===t.currentTarget&&e()},children:(0,r.jsxs)("div",{style:{width:n?"calc(100vw - 16px)":860,maxWidth:"calc(100vw - 16px)",height:n?"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:[(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:o("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:n?"column":"row",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{width:n?"100%":210,maxHeight:n?"40vh":void 0,borderRight:n?"none":"1px solid var(--border)",borderBottom:n?"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=f?.type==="oauth"&&f.providerId===e.id;return(0,r.jsxs)("div",{onClick:()=>m({type:"oauth",providerId:e.id}),style:{display:"flex",alignItems:"center",gap:7,padding:"5px 8px",borderRadius:5,cursor:"pointer",background:t?"var(--bg-selected)":"none"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,r.jsx)(tb,{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=f?.type==="apikey"&&f.providerId===e.id;return(0,r.jsxs)("div",{onClick:()=>m({type:"apikey",providerId:e.id}),style:{display:"flex",alignItems:"center",gap:7,padding:"5px 8px",borderRadius:5,cursor:"pointer",background:t?"var(--bg-selected)":"none"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,r.jsx)(tb,{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)"}}),l?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:o("i18n.loading")}):B.map(([e,t])=>{let n=f?.type==="provider"&&f.name===e,i=t.models??[];return(0,r.jsxs)("div",{style:{marginBottom:2},children:[(0,r.jsxs)("div",{onClick:()=>m({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=f?.type==="model"&&f.providerName===e&&f.index===n;return(0,r.jsxs)("div",{onClick:()=>m({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||o("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(),E(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:["+ ",o("i18n.model")]})})]},e)})]}),(0,r.jsx)("div",{style:{borderTop:"1px solid var(--border)",padding:"8px 6px"},children:(0,r.jsxs)("button",{onClick:()=>S(!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:["+ ",o("i18n.addProvider")]})})]}),(0,r.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:l?null:N??(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:o("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:[p&&(0,r.jsx)("span",{style:{fontSize:12,color:"#f87171",flex:1},children:p}),(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:o("i18n.cancel")}),(0,r.jsxs)("button",{onClick:D,disabled:c||g,style:{position:"relative",padding:"6px 16px",minWidth:92,background:g?"#16a34a":c?"var(--bg-panel)":"var(--accent)",border:"none",borderRadius:6,color:g?"#fff":c?"var(--text-muted)":"#fff",cursor:c||g?"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:g?"saved-pop 0.45s ease":void 0},children:[g&&(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:g?o("i18n.saved"):c?o("i18n.saving"):o("i18n.save")})]})]})]})}),j&&(0,r.jsx)(ty,{oauthProviders:b,apiKeyProviders:k,onSelectOAuth:e=>m({type:"oauth",providerId:e}),onSelectApiKey:e=>m({type:"apikey",providerId:e}),onAddCustom:R,onClose:()=>S(!1)})]})}function tw(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function tj(e){let t=e.sourceInfo?.source,n=e.sourceInfo?.scope;return"user"===n||"user"===t?"global":"project"===n||"project"===t?"project":"path"}function tS(e){let t=tj(e);return"path"===t?t:e.install?.skillsShUrl?`${t} / skills.sh`:t}function tC(e){return e.install?`${e.install.scope}\0${e.install.package}`:null}function tT(e){return e?e.slice(0,8):"unknown"}function tM({enabled:e,loading:t,onToggle:n}){let{t:i}=(0,v.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 tR({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,v.s)(),h=tj(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 tw(e)}(e.filePath)}),(0,r.jsx)(tM,{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:tT(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:tT(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 tI({cwd:e,installedPackages:t,projectResourcesLoaded:n,onInstalled:o}){let{t:a}=(0,v.s)(),[s,l]=(0,i.useState)(""),[d,c]=(0,i.useState)([]),[u,p]=(0,i.useState)(!1),[h,g]=(0,i.useState)(null),[x,f]=(0,i.useState)(null),[m,b]=(0,i.useState)(null),[y,k]=(0,i.useState)(new Set),[w,j]=(0,i.useState)("global"),S=(0,i.useRef)(null);(0,i.useEffect)(()=>{S.current?.focus()},[]);let C=(0,i.useCallback)(async e=>{if(e.trim()){p(!0),g(null),c([]);try{let t=await fetch("/api/skills/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:e.trim()})}),n=await t.json();if(n.error)return void g(n.error);c(n.results??[]),0===(n.results??[]).length&&g("No skills found")}catch(e){g(String(e))}finally{p(!1)}}},[]),T=(0,i.useCallback)(async t=>{f(t),b(null);try{let n=await fetch("/api/skills/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({package:t,scope:w,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(`${w}:${t}`)),o()}catch(e){b(String(e))}finally{f(null)}},[o,w,e]),M="global"===w?"~/.pi/agent/skills/":`${tw(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:S,value:s,onChange:e=>l(e.target.value),onKeyDown:e=>{"Enter"===e.key&&C(s)},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:()=>C(s),disabled:u||!s.trim(),style:{padding:"7px 16px",fontSize:13,borderRadius:6,border:"none",background:"var(--accent)",color:"#fff",cursor:u||!s.trim()?"not-allowed":"pointer",opacity:u||!s.trim()?.5:1,flexShrink:0},children:u?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)&&j(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:w===e?"var(--bg-selected)":"none",color:w===e?"var(--text)":"var(--text-dim)",fontWeight:w===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:["→ ",M]})]}),h&&(0,r.jsx)("div",{style:{fontSize:12,color:"#f87171"},children:h}),m&&(0,r.jsx)("div",{style:{fontSize:12,color:"#f87171",wordBreak:"break-word"},children:m})]}),d.length>0?(0,r.jsx)("div",{style:{flex:1,overflowY:"auto"},children:d.map(e=>{let n=t[w].has(e.package)||y.has(`${w}:${e.package}`),i=x===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&&T(e.package),disabled:n||i||null!==x,style:{flexShrink:0,padding:"5px 14px",fontSize:12,fontWeight:500,borderRadius:5,border:"1px solid var(--border)",cursor:n||i||null!==x?"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)})}):!h&&!u&&(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 tL({cwd:e,onClose:t}){let n=(0,eY.a)(),{t:o}=(0,v.s)(),[a,s]=(0,i.useState)([]),[l,d]=(0,i.useState)(!0),[c,u]=(0,i.useState)(null),[p,h]=(0,i.useState)(null),[g,x]=(0,i.useState)(new Set),[f,m]=(0,i.useState)(null),[b,y]=(0,i.useState)(!1),[k,w]=(0,i.useState)({}),[j,S]=(0,i.useState)(new Set),[C,T]=(0,i.useState)(!1),[M,R]=(0,i.useState)(null),[I,L]=(0,i.useState)(null),[z,E]=(0,i.useState)(!0),[W,P]=(0,i.useState)({}),$=(0,i.useCallback)(async()=>{d(!0),u(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(s(r),E(n.projectResourcesLoaded??!0),r.length>0&&!p){let e=r.find(e=>!e.disableModelInvocation)??r[0];h(e.filePath),e.disableModelInvocation&&P(t=>({...t,[tS(e)]:!0}))}return r}catch(e){return u(String(e)),[]}finally{d(!1)}},[e,p]);(0,i.useEffect)(()=>{w({}),L(null),$()},[e]);let D=(0,i.useCallback)(async t=>{let n=(t?[t]:a.filter(e=>!!e.install)).map(tC).filter(e=>!!e);if(0!==n.length){L(null),S(e=>new Set([...e,...n])),t||T(!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}`);w(e=>{let t={...e};for(let e of r.updates??[])t[`${e.scope}\0${e.package}`]=e;return t})}catch(e){L(e instanceof Error?e.message:String(e))}finally{S(e=>{let t=new Set(e);for(let e of n)t.delete(e);return t}),t||T(!1)}}},[e,a]),B=(0,i.useCallback)(async t=>{if(!t.install)return;let n=tC(t);R(n),L(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 $();let o=i.skill?.install?.versionHash;w(e=>({...e,[n]:{package:t.install.package,scope:t.install.scope,state:"up-to-date",currentVersion:o,latestVersion:o}}))}catch(e){L(e instanceof Error?e.message:String(e))}finally{R(null)}},[e,$]),A=(0,i.useCallback)(async e=>{let t=!e.disableModelInvocation;x(t=>new Set(t).add(e.filePath)),m(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 m(r.error??`HTTP ${n.status}`);s(n=>n.map(n=>n.filePath===e.filePath?{...n,disableModelInvocation:t}:n)),t&&P(t=>({...t,[tS(e)]:!0}))}catch(e){m(String(e))}finally{x(t=>{let n=new Set(t);return n.delete(e.filePath),n})}},[]),F=a.find(e=>e.filePath===p)??null;return(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:e=>{e.target===e.currentTarget&&t()},children:(0,r.jsxs)("div",{style:{width:n?"calc(100vw - 16px)":860,maxWidth:"calc(100vw - 16px)",height:n?"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:[(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:o("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:tw(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:o("trust.skillsNotLoaded")}),(0,r.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:n?"column":"row",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{width:n?"100%":210,maxHeight:n?"40vh":void 0,borderRight:n?"none":"1px solid var(--border)",borderBottom:n?"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:l?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:o("i18n.loading")}):c?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"#f87171"},children:c}):0===a.length?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"var(--text-dim)"},children:o("i18n.noSkills")}):(()=>{let e=[];for(let{label:t,matches:n}of[{label:"project / skills.sh",matches:e=>"project"===tj(e)&&!!e.install?.skillsShUrl},{label:"project",matches:e=>"project"===tj(e)&&!e.install?.skillsShUrl},{label:"global / skills.sh",matches:e=>"global"===tj(e)&&!!e.install?.skillsShUrl},{label:"global",matches:e=>"global"===tj(e)&&!e.install?.skillsShUrl},{label:"path",matches:e=>"path"===tj(e)}]){let r=a.filter(n);r.length>0&&e.push({label:t,skills:r})}let t=e=>{let t,n,i=!b&&p===e.filePath,a=e.disableModelInvocation;return(0,r.jsxs)("div",{onClick:()=>{h(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:a?"var(--border)":"var(--accent)",boxShadow:a?"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:a?"var(--text-dim)":"var(--text)",fontFamily:"var(--font-mono)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),(n=(t=tC(e))?k[t]:void 0,n?.state!=="update-available"?null:(0,r.jsx)("span",{title:o("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),a=n.filter(e=>e.disableModelInvocation),s=W[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),a.length>0&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{onClick:()=>P(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?"▾":"▸"}),o("i18n.dormant")," (",a.length,")"]}),s&&a.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"})]}),o("i18n.addSkill")]})})]}),(0,r.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:b?(0,r.jsx)(tI,{cwd:e,projectResourcesLoaded:z,installedPackages:{global:new Set(a.filter(e=>e.install?.scope==="global").map(e=>e.install.package)),project:new Set(a.filter(e=>e.install?.scope==="project").map(e=>e.install.package))},onInstalled:()=>{$()}}):l?null:F?(0,r.jsx)(tR,{skill:F,cwd:e,onToggle:A,toggling:g.has(F.filePath),saveError:f,updateStatus:tC(F)?k[tC(F)]:void 0,checkingUpdate:!!tC(F)&&j.has(tC(F)),updating:M===tC(F),updateError:I,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:o("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:[a.some(e=>!!e.install)&&(0,r.jsx)("button",{onClick:()=>void D(),disabled:C||null!==M,style:{padding:"6px 12px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:C||null!==M?"not-allowed":"pointer",opacity:C||null!==M?.5:1,fontSize:12},children:C?o("i18n.checking"):o("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?o("i18n.update"):o("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:o("i18n.close")})]})]})})}var tz=n(32383),tE=n(22271);function tW(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function tP(e){let t=e.trim().match(/^\$?\s*pi\s+install\s+(\S+)\s*$/);return t?.[1]??e}function t$(e){return`${e.scope}\0${e.source}`}function tD(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 tB(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 tA(e){return"loaded"===e?"var(--accent)":"installed"===e?"#f59e0b":"disabled"===e?"var(--text-dim)":"#ef4444"}function tF({pkg:e}){let{t}=(0,v.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 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-dim)"},children:e})}function tH(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 tO({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 tU({value:e,projectResourcesLoaded:t,onChange:n}){let{t:i}=(0,v.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 t_({cwd:e,source:t,scope:n,projectResourcesLoaded:o,busy:a,actionError:s,onSourceChange:l,onScopeChange:d,onInstall:c}){let{t:u}=(0,v.s)(),p=(0,i.useRef)(null);return(0,i.useEffect)(()=>{p.current?.focus()},[]),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:18,maxWidth:660,minHeight:"100%"},children:[(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,flexWrap:"wrap"},children:[(0,r.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)"},children: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?`${tW(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:p,value:t,onChange:e=>l(e.target.value),onPaste:e=>{let t=(0,tE.Gm)(e.clipboardData),n=t.length>0?t[0]:e.clipboardData.getData("text"),r=tP(n);(r!==n||0!==t.length)&&(e.preventDefault(),l(r))},onBlur:e=>l(tP(e.currentTarget.value)),placeholder:"npm:@scope/package",style:{width:"100%",height:36,padding:"0 11px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:13,outline:"none"},onKeyDown:e=>{"Enter"===e.key&&t.trim()&&!a&&c()}})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,r.jsx)(tU,{value:n,projectResourcesLoaded:o,onChange:d}),(0,r.jsx)("button",{type:"button",onClick:c,disabled:a||!t.trim(),style:{...tH(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 tV({pkg:e,cwd:t,busyKey:n,actionError:i,actionMessage:o,sessionId:a,onAction:s,onReloadSession:l}){let{t:d}=(0,v.s)(),c=t$(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)(tO,{enabled:h,loading:u||p,onToggle:()=>s(e.disabled?"enable":"disable",e),label:d(e.disabled?"i18n.enablePackage":"i18n.disablePackage")}),(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-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:tH(u||p),children:d(n===`update:${c}`?"i18n.updating":"i18n.update")}),(0,r.jsx)("button",{onClick:l,disabled:!a||p||u,style:tH(!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:tH(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:tA(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:tB(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:tD(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?tW(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:tW(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)(tF,{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 tq({cwd:e,sessionId:t,onClose:n,onReloaded:o}){let a=(0,eY.a)(),{t:s}=(0,v.s)(),[l,d]=(0,i.useState)(null),[c,u]=(0,i.useState)(!0),[p,h]=(0,i.useState)(null),[g,x]=(0,i.useState)(null),[f,m]=(0,i.useState)(!1),[b,y]=(0,i.useState)(""),[k,w]=(0,i.useState)("global"),[j,S]=(0,i.useState)(null),[C,T]=(0,i.useState)(null),[M,R]=(0,i.useState)(null),I=(0,i.useMemo)(()=>l?.packages??[],[l?.packages]),L=I.find(e=>t$(e)===g)??null,z=l?.projectResourcesLoaded??!0,E=(0,i.useMemo)(()=>["project","global"].map(e=>({scope:e,packages:I.filter(t=>t.scope===e)})).filter(e=>e.packages.length>0),[I]),W=(0,i.useCallback)(async()=>{u(!0),h(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}`);d(n),m(e=>0===n.packages.length||e),x(e=>e&&n.packages.some(t=>t$(t)===e)?e:n.packages[0]?t$(n.packages[0]):null)}catch(e){h(e instanceof Error?e.message:String(e))}finally{u(!1)}},[e]);(0,i.useEffect)(()=>{W()},[W]);let P=(0,i.useCallback)(async(t,n)=>{let r=t$(n);S(`${t}:${r}`),T(null),R(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}`);d(i),"remove"===t?(x(i.packages[0]?t$(i.packages[0]):null),0===i.packages.length&&m(!0),R("Package removed.")):R({install:"Package installed.",update:"Package updated.",disable:"Package disabled.",enable:"Package enabled."}[t])}catch(e){T(e instanceof Error?e.message:String(e))}finally{S(null)}},[e]),$=(0,i.useCallback)(async()=>{let t=tP(b).trim();if(!t)return;y(t);let n=`${k}\0${t}`;S(`install:${n}`),T(null),R(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}`);d(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)));x(l?t$(l):n),m(!1),y(""),R("Package installed.")}catch(e){T(e instanceof Error?e.message:String(e))}finally{S(null)}},[e,k,b]),D=(0,i.useCallback)(async()=>{if(t){S("reload"),T(null),R(null);try{await (0,tz.$J)(t,{type:"reload"}),o?.(),await W(),R("Session reloaded.")}catch(e){T(e instanceof Error?e.message:String(e))}finally{S(null)}}},[W,o,t]),B=j?.startsWith("install:")??!1;return(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:e=>{e.target===e.currentTarget&&n()},children:(0,r.jsxs)("div",{style:{width:a?"calc(100vw - 16px)":860,maxWidth:"calc(100vw - 16px)",height:a?"calc(100dvh - 16px)":"76vh",maxHeight:"calc(100dvh - 16px)",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.18)",overflow:"hidden"},children:[(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:s("common.plugins")}),(0,r.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:tW(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:s("trust.pluginsNotLoaded")}),(0,r.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:a?"column":"row",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{width:a?"100%":245,maxHeight:a?"40vh":void 0,borderRight:a?"none":"1px solid var(--border)",borderBottom:a?"1px solid var(--border)":"none",display:"flex",flexDirection:"column",flexShrink:0,background:"var(--bg-panel)"},children:[(0,r.jsx)("div",{style:{flex:1,overflowY:"auto",padding:"8px 6px"},children:c?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:"Loading..."}):p?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"#ef4444"},children:p}):0===I.length?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"var(--text-dim)"},children:"No plugins configured"}):E.map(e=>(0,r.jsxs)("div",{style:{marginBottom:6},children:[(0,r.jsx)("div",{style:{padding:"4px 8px 3px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase"},children:e.scope}),e.packages.map(e=>{let t=t$(e),n=!f&&g===t;return(0,r.jsxs)("div",{onClick:()=>{x(t),m(!1),T(null),R(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:tA(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:tD(e,s)}),(e.version||e.configuredVersion)&&(0,r.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:2},children:tB(e,s)})]})]},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:()=>{m(!0),T(null),R(null)},style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,border:"none",width:"100%",cursor:"pointer",background:f?"var(--bg-selected)":"none",color:f?"var(--accent)":"var(--text-dim)",fontSize:12},onMouseEnter:e=>{f||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{f||(e.currentTarget.style.background="none")},children:[(0,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"})]}),s("i18n.addPlugin")]})})]}),(0,r.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:f?(0,r.jsx)(t_,{cwd:e,source:b,scope:k,projectResourcesLoaded:z,busy:B,actionError:C,onSourceChange:y,onScopeChange:w,onInstall:$}):c?null:L?(0,r.jsx)(tV,{pkg:L,cwd:e,busyKey:j,actionError:C,actionMessage:M,sessionId:t,onAction:P,onReloadSession:D},t$(L)):(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:s("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:l?.diagnostics.length?(0,r.jsxs)("span",{title:l.diagnostics.map(e=>`${e.type}: ${e.source?`${e.source}: `:""}${e.message}`).join("\n"),style:{color:l.diagnostics.some(e=>"error"===e.type)?"#ef4444":"#d97706"},children:[l.diagnostics.length," diagnostic",1===l.diagnostics.length?"":"s"]}):(0,r.jsx)("span",{children:l?`${l.totals.extensions} ext \xb7 ${l.totals.skills} skills \xb7 ${l.totals.prompts} prompts \xb7 ${l.totals.themes} themes`:""})}),(0,r.jsx)("button",{onClick:()=>void W(),disabled:c||null!==j,style:tH(c||null!==j),children:s("i18n.refresh")}),(0,r.jsx)("button",{onClick:n,style:tH(!1),children:s("i18n.close")})]})]})})}function tJ(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function tK({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 tY(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 tG({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 tX({value:e,projectResourcesLoaded:t,onChange:n}){let{t:i}=(0,v.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 tZ({server:e,cwd:t,busy:n,actionError:i,actionMessage:o,onToggle:a,onRemove:s,onMove:l,onTest:d,onEdit:c}){let{t:u}=(0,v.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,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)(tG,{enabled:p,loading:n,onToggle:a,label:u(p?"mcp.disable":"mcp.enable")}),(0,r.jsx)(tK,{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:tY(n),children:u(n?"mcp.testing":"mcp.test")}),(0,r.jsx)("button",{onClick:c,disabled:n,style:tY(n),children:u("mcp.edit")}),(0,r.jsx)("button",{onClick:l,disabled:n,style:tY(n),children:u("project"===h?"mcp.moveToProject":"mcp.moveToGlobal")}),(0,r.jsx)("button",{onClick:s,disabled:n,style:tY(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:tJ(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:tJ(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 tQ({cwd:e,scope:t,projectResourcesLoaded:n,busy:o,actionError:a,initial:s,onScopeChange:l,onSave:d,onFetchDef:c,onCancel:u}){let{t:p}=(0,v.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??"":""),[b,y]=(0,i.useState)(""),[k,w]=(0,i.useState)("basic"),[j,S]=(0,i.useState)(null),[C,T]=(0,i.useState)(null),[M,R]=(0,i.useState)(!1),I={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"},L={fontSize:12,fontWeight:600,color:"var(--text-muted)"},z=/^https?:\/\//.test(f.trim()),E=()=>{let e=f.trim();if(/^https?:\/\//.test(e))return{url:e};let t=e.split(/\s+/),n=t[0]??"",r=b.trim()?b.trim().split(/\s+/):[];return{command:n,args:[...t.slice(1),...r]}},W=async()=>{if(T(null),null!==j)return void w("json");if(h&&s){w("json"),R(!0);try{let e=await c(s.name,s.scope);S(JSON.stringify(e??E(),null,2))}finally{R(!1)}}else S(JSON.stringify(E(),null,2)),w("json")},P=g.trim()&&("json"===k?(j??"").trim().length>0:f.trim().length>0);return(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.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?`${tJ(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():w("basic"),style:{padding:"6px 14px",borderRadius:6,border:"1px solid var(--border)",cursor:"pointer",fontSize:12,background:k===e?"var(--accent)":"none",color:k===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:L,children:p("mcp.nameLabel")}),(0,r.jsx)("input",{value:g,onChange:e=>x(e.target.value),placeholder:p("mcp.namePlaceholder"),style:I})]}),"json"===k?(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:7},children:[(0,r.jsx)("label",{style:L,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:L,children:p("mcp.specLabel")}),(0,r.jsx)("input",{value:f,onChange:e=>m(e.target.value),placeholder:p("mcp.specPlaceholder"),style:I})]}),!z&&(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:7},children:[(0,r.jsx)("label",{style:L,children:p("mcp.argsLabel")}),(0,r.jsx)("input",{value:b,onChange:e=>y(e.target.value),style:I})]})]}),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)(tX,{value:t,projectResourcesLoaded:n,onChange:l}),(0,r.jsx)("button",{type:"button",onClick:()=>{if(T(null),"json"===k){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,E())},disabled:o||!P,style:{...tY(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:tY(!1),children:p("mcp.cancel")})]}),a&&(0,r.jsx)("div",{style:{fontSize:12,color:"#ef4444",whiteSpace:"pre-wrap"},children:a})]})}function t0({anchorRect:e,cwd:t,hidden:n,onClose:a}){let{t:s}=(0,v.s)(),[l,d]=(0,i.useState)(null),[c,u]=(0,i.useState)(!0),[p,h]=(0,i.useState)(null),[g,x]=(0,i.useState)(!1),[f,m]=(0,i.useState)("global"),[b,y]=(0,i.useState)(null),[k,w]=(0,i.useState)(null),[j,S]=(0,i.useState)(null),[C,T]=(0,i.useState)(null),[M,R]=(0,i.useState)(null),I=(0,i.useRef)(null),L=l?.projectResourcesLoaded??!0,z=(0,i.useMemo)(()=>l?.servers.find(e=>e.name===p)??null,[l,p]),E=(0,i.useMemo)(()=>["project","global"].map(e=>({scope:e,servers:(l?.servers??[]).filter(t=>t.scope===e)})).filter(e=>e.servers.length>0),[l]),W=t??"",P=(0,i.useCallback)(async()=>{if(W){u(!0),w(null);try{let e=await fetch(`/api/mcp?cwd=${encodeURIComponent(W)}`),t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);d(t),h(e=>e&&t.servers.some(t=>t.name===e)?e:t.servers[0]?.name??null)}catch(e){w(e instanceof Error?e.message:String(e))}finally{u(!1)}}},[W]);(0,i.useEffect)(()=>{n||P()},[n,P]),(0,i.useEffect)(()=>{if(n)return;let e=e=>{let t=e.target;I.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 $=(0,i.useCallback)(async(e,t)=>{if(!W)return null;R(`mcp:${e}`),w(null),S(null);try{let n=await fetch("/api/mcp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:W,action:e,...t})}),r=await n.json();if(!n.ok||r.error)throw Error(r.error??`HTTP ${n.status}`);return d(r),r}catch(e){return w(e instanceof Error?e.message:String(e)),null}finally{R(null)}},[W]),D=(0,i.useCallback)(async e=>{await $(e.disabled?"enable":"disable",{name:e.name,scope:e.scope})&&S(e.disabled?s("mcp.msgEnabled",{name:e.name}):s("mcp.msgDisabled",{name:e.name}))},[$,s]),B=(0,i.useCallback)(async e=>{let t=await $("remove",{name:e.name,scope:e.scope});t&&(h(t.servers[0]?.name??null),S(s("mcp.msgDeleted",{name:e.name})),0===t.servers.length&&x(!0))},[$,s]),A=(0,i.useCallback)(async e=>{let t="project"===e.scope?"global":"project";await $("move",{name:e.name,fromScope:e.scope,toScope:t})&&S(s("mcp.msgMoved",{name:e.name,scope:t}))},[$,s]),F=(0,i.useCallback)(async(e,t)=>{let n=!!b,r=n&&b?b.name:e.trim();await $(n?"update":"add",{name:r,scope:f,def:t})&&(h(r),x(!1),y(null),S(n?s("mcp.msgUpdated",{name:r}):s("mcp.msgAdded",{name:r})))},[f,b,$,s]),N=(0,i.useCallback)(async(e,t)=>{if(!W)return null;try{let n=await fetch("/api/mcp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:W,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}},[W]),H=(0,i.useCallback)(async e=>{T(e.name),w(null),S(null);try{let t=await fetch("/api/mcp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:W,action:"test",name:e.name,scope:e.scope})}),n=await t.json();if(!t.ok||n.error)throw Error(n.error??`HTTP ${t.status}`);S(s("mcp.msgTestResult",{name:e.name,result:n.message??""}))}catch(t){w(s("mcp.msgTestError",{name:e.name,error:t instanceof Error?t.message:String(t)}))}finally{T(null)}},[W,s]),O=null!==M,U=document.documentElement.clientWidth,_=Math.min(780,U-48),V=e?Math.max(24,Math.min(e.left,U-_-24)):U-_-24,q=(0,r.jsxs)("div",{ref:I,role:"dialog","aria-label":s("mcp.sectionTitle"),style:{position:"fixed",zIndex:130,top:e?.bottom??e?.top??46,left:V,width:_,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"})]}),s("mcp.sectionTitle")]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,r.jsx)("button",{onClick:()=>void P(),disabled:c||O,style:tY(c||O),children:s("i18n.refresh")}),(0,r.jsx)("button",{onClick:a,style:tY(!1),children:s("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",width:168,flexShrink:0,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:s("mcp.sectionTitle")}),c?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:"Loading..."}):!l&&k?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"#ef4444"},children:k}):(l?.servers.length??0)===0?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"var(--text-meta)"},children:s("mcp.emptyList")}):E.map(e=>(0,r.jsxs)("div",{style:{marginBottom:6},children:[(0,r.jsx)("div",{style:{padding:"4px 8px 3px",fontSize:10,fontWeight:600,color:"var(--text-meta)",textTransform:"uppercase"},children:e.scope}),e.servers.map(e=>{let t=!g&&p===e.name;return(0,r.jsxs)("div",{onClick:()=>{h(e.name),x(!1),y(null),w(null),S(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?s("mcp.itemDisabled"):s("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:()=>{x(!0),y(null),m("global"),w(null),S(null)},style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,border:"none",width:"100%",cursor:"pointer",background:g?"var(--bg-selected)":"none",color:g?"var(--accent)":"var(--text-meta)",fontSize:12},onMouseEnter:e=>{g||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{g||(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"})]}),s("mcp.addButton")]})})]}),(0,r.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:g?(0,r.jsx)(tQ,{cwd:W,scope:f,projectResourcesLoaded:L,busy:O,actionError:k,initial:b,onScopeChange:m,onSave:(e,t)=>void F(e,t),onFetchDef:N,onCancel:()=>{x(!1),y(null)}}):z?(0,r.jsx)(tZ,{server:z,cwd:W,busy:O||C===z.name,actionError:k,actionMessage:j,onToggle:()=>void D(z),onRemove:()=>void B(z),onMove:()=>void A(z),onTest:()=>void H(z),onEdit:()=>{y(z),x(!0),w(null),S(null)}},z.name):(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-meta)",fontSize:13},children:s("mcp.emptyDetail")})})]})]});return n?null:(0,o.createPortal)(q,document.body)}function t1({cwd:e,busy:t,error:n,onCancel:i,onConfirm:o}){let{t:a}=(0,v.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 t2(e){return"message"===e.type&&"message"in e}function t4(e){let t=e,n=t.branchPreview,r=t2(t.entry)?t.entry:null,i=t.compressedEntryIds?.length??0;for(;1===t.children.length;)t=t.children[0],n??=t.branchPreview,!r&&t2(t.entry)&&(r=t.entry),i+=1+(t.compressedEntryIds?.length??0);return{node:t,skipped:i,branchPreview:n,labelEntry:r??t.entry}}function t8({node:e,activePathIds:t,depth:n,isLast:i,parentLines:o,onSelect:a}){let{node:s,skipped:l,branchPreview:d,labelEntry:c}=t4(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:t2(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)(t8,{node:e,activePathIds:t,depth:n+1,isLast:l===s.children.length-1,parentLines:[...o,!i],onSelect:a},e.entry.id))]})}function t5({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,v.s)(),[f,m]=(0,i.useState)(!1),b=void 0!==l?l:f,y=(0,i.useRef)(null),[k,w]=(0,i.useState)(null);(0,i.useEffect)(()=>{if(!b||!a)return;let e=s?.current??y.current;if(!e)return;let t=()=>{let t=e.getBoundingClientRect(),n=e.closest?.("[data-session-titlebar]"),r=n?.getBoundingClientRect();w({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()},[b,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=t4(e[0]).node;return t.children.length>1?t.children:[]}(e),M=!C&&T.length>0,R=(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"})]}),I=(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:b?"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=b&&k?(0,r.jsx)("div",{style:{position:"fixed",top:k.top,left:k.left,width:k.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)(t8,{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:y,"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:b?"color-mix(in srgb, var(--glass-bg-strong) 60%, transparent)":"transparent",border:"none",borderRadius:6,cursor:"pointer",color:b?"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=b?"var(--accent)":"var(--text-muted)",e.currentTarget.style.background=b?"color-mix(in srgb, var(--glass-bg-strong) 60%, transparent)":"transparent"},title:x("i18n.branches"),"aria-label":x("i18n.branches"),"aria-pressed":b,children:[R,!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:[R,(0,r.jsx)("span",{style:{color:"var(--text)"},children:x("i18n.branches")}),I]}),b&&(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)(t8,{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 t6({onSelectSession:e,onOpenBoard:t}){let{t:n}=(0,v.s)(),s=(0,eY.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),[b,y]=(0,i.useState)(null),k=(0,i.useRef)(null),w=(0,i.useRef)(null),j=(0,i.useRef)(null),S=(0,i.useRef)(null);(0,i.useEffect)(()=>{if(!g||!k.current||s)return;let e=()=>{let e=k.current?.getBoundingClientRect();e&&y({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;w.current?.contains(t)||k.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]),R=(e,t)=>(0,r.jsx)("div",{ref:w,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()&&R(c,p)]}),document.body)]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{ref:k,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&&b&&(0,o.createPortal)((0,r.jsx)("div",{style:{position:"fixed",top:b.top,left:b.left,width:b.width,zIndex:520},children:R(c,p)}),document.body)]})}function t3(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 t7(e,t){try{window.localStorage.setItem(e,String(t))}catch{}}function t9(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=>t3(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)&&t7(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]),R=(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]),I=(0,i.useCallback)(e=>{T(e.pointerId)},[T]),L=(0,i.useCallback)(e=>{T(e.pointerId)},[T]),z=(0,i.useCallback)(e=>{T(e.pointerId)},[T]),E=(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(),E())},[S,k,s,d,E,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&&t7(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:E,separatorProps:{"aria-label":t,"aria-orientation":"vertical","aria-valuemax":b?k():l,"aria-valuemin":d,"aria-valuenow":x,"aria-valuetext":`${x} px`,onDoubleClick:E,onKeyDown:P,onLostPointerCapture:z,onPointerCancel:L,onPointerDown:M,onPointerMove:R,onPointerUp:I,role:"separator",tabIndex:0},width:x}}var ne=n(32782);let nt="bg-image",nn="wallpaper";function nr(){return new Promise((e,t)=>{let n=indexedDB.open("pi-web",1);n.onupgradeneeded=()=>{n.result.objectStoreNames.contains(nt)||n.result.createObjectStore(nt)},n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)})}let ni=null,no=null;async function na(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 ns(e){ni&&URL.revokeObjectURL(ni),no=e&&e.type.startsWith("image/")?"image":null,ni=e?URL.createObjectURL(e):null;let t=document.documentElement.style;return"image"===no&&ni?t.setProperty("--app-bg-image",`url("${ni}")`):t.setProperty("--app-bg-image","none"),{url:ni,kind:no}}async function nl(){try{let e=await nr(),t=await new Promise((t,n)=>{let r=e.transaction(nt,"readonly").objectStore(nt).get(nn);r.onsuccess=()=>t(r.result??null),r.onerror=()=>n(r.error)});if(!t)return{loaded:!1,...ns(null)};return{loaded:!0,...ns(t)}}catch{return{loaded:!1,...ns(null)}}}async function nd(e){let t=await nr();await new Promise((n,r)=>{let i=t.transaction(nt,"readwrite"),o=i.objectStore(nt);e?o.put(e,nn):o.delete(nn),i.oncomplete=()=>n(),i.onerror=()=>r(i.error)})}let nc={repeat:!1,offsetX:0,fill:!1,fillColorLeft:"#000000",fillColorRight:"#000000",bubbleOpacity:44,bubbleBlur:8,scrimAlpha:0,scrimBlur:0},nu="wallpaper-settings";async function np(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 nh=n(7834),ng=n(3099),nx=n(4325);let nf=(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}),nm=(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)(eg.N,{label:"正在加载画布…"})});function nv(){return new URLSearchParams(window.location.search).get("board")}function nb({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 ny(e){document.documentElement.style.setProperty("--bubble-alpha",String(e/100))}function nk(){let e,t,n,s,c,u,m,b,y,k,w,S,C,T=(0,a.useRouter)(),M=(0,a.useSearchParams)(),[R]=(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:I,toggleTheme:L}=(0,eb.D)(),{hasBg:z,ready:E,pick:W,remove:P,kind:$,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 nl().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 na(e);if(!n)return;await nd(n);let r=ns(n);l(r.url),a(r.kind),t(!0)},[]),remove:(0,i.useCallback)(async()=>{await nd(null),ns(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(nu);if(!e)return{...nc};return{...nc,...JSON.parse(e)}}catch{return{...nc}}})());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(nu,JSON.stringify(n))}catch{}return n}),[])}}(z&&"image"===$),F=(0,d.qE)(z&&"image"===$);(0,d.mf)(D,"image"===$,{offsetX:B.offsetX,repeat:B.repeat,fill:B.fill,bubbleBlur:B.bubbleBlur,scrimBlur:B.scrimBlur},F);let[N,H]=(0,i.useState)(!1);(0,i.useEffect)(()=>{if(!N)return;let e=document.body.style.userSelect;document.body.style.userSelect="none";let t=e=>{"Escape"===e.key&&H(!1)};return window.addEventListener("keydown",t),()=>{document.body.style.userSelect=e,window.removeEventListener("keydown",t)}},[N]);let O="light"===I?"theme.light":"theme.dark",{locale:U,setLocale:_,t:V,supportedLocales:q}=(0,v.s)(),J=(0,eY.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:K,onSoundToggle:Y,playDoneSound:G,unlockAudio:X,soundEnabledRef:Z}=(0,ne.G)(),Q=(0,i.useRef)(new Set),ee=(0,i.useRef)(new Set),et=(0,i.useCallback)(e=>{if(e&&e.length>0){let t=ee.current,n=e.every(e=>t.has(e));for(let n of e)t.delete(n);if(n)return}Z.current&&G()},[G,Z]),[er,ei]=(0,i.useState)(null),[eo,ea]=(0,i.useState)(()=>new Set),[es,el]=(0,i.useState)(()=>R.boardId),[ed,ec]=(0,i.useState)(null),eu=(0,i.useCallback)(e=>{ea(t=>t.size===e.size&&[...e].every(e=>t.has(e))?t:e)},[]),ep=(0,i.useCallback)(e=>{el(e),ec(null),ei(null),tV(null),tG([]),nj(null),nT(null),T.replace(`?board=${encodeURIComponent(e)}`,{scroll:!1})},[T]),[eg,ex]=(0,i.useState)(null),[ef,em]=(0,i.useState)("initial"),ev=(0,i.useRef)(null),[ey,ek]=(0,i.useState)(()=>R.requestedCwd?"validating":"idle"),[ew,ej]=(0,i.useState)(null),[eS,eC]=(0,i.useState)(0),[eT,eM]=(0,i.useState)(0),[eR,eI]=(0,i.useState)(0),[eL,ez]=(0,i.useState)(!1),[eE,eW]=(0,i.useState)(0),[eP,e$]=(0,i.useState)(!1),[eD,eB]=(0,i.useState)(!1),[eA,eF]=(0,i.useState)(null),[eN,eH]=(0,i.useState)(!1),[eO,eU]=(0,i.useState)(!1),[e_,eV]=(0,i.useState)(null),[eJ,eG]=(0,i.useState)(!0),[eX,eZ]=(0,i.useState)(!1),[eQ,e0]=(0,i.useState)("top"),[e1,e2]=(0,i.useState)(null),e4=(0,i.useRef)(null),[e8,e5]=(0,i.useState)(!1),e6=(0,i.useRef)(null),[e3,e7]=(0,i.useState)(!1),[e9,te]=(0,i.useState)(!1),[tt,tn]=(0,i.useState)(!1),tr=(0,i.useRef)(null),ti=(0,i.useRef)(null),to=(0,i.useRef)(null),[ta,ts]=(0,i.useState)(null),[tl,td]=(0,i.useState)(!1),tc=(0,i.useRef)(260),tu=(0,i.useRef)(560),tp=(0,i.useCallback)(()=>t3(.42*window.innerWidth,360,640),[]),th=(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:e3,rightPanelWidth:tu.current}),[e3]),tg=(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:eJ,sidebarWidth:tc.current}),[eJ]),tx=t9({ariaLabel:V("layout.resizeSidebar"),cssVariable:"--sidebar-width",defaultWidth:260,getMaxWidth:th,growthDirection:"right",maxWidth:480,minWidth:180,storageKey:"pi-sidebar-width",widthRef:tc}),tf=t9({ariaLabel:V("layout.resizeFilePanel"),cssVariable:"--right-panel-width",defaultWidth:560,getDefaultWidth:tp,getMaxWidth:tg,growthDirection:"left",maxWidth:1200,minWidth:300,storageKey:"pi-right-panel-width",widthRef:tu}),tm=tx.reclampWidth,tv=tf.reclampWidth;(0,i.useEffect)(()=>{J&&eG(!1)},[J]);let tb=(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)),ts({left:n,top:t.bottom}),tn(e=>!e)},[]);(0,i.useEffect)(()=>{if(!tt)return;let e=e=>{tr.current&&!tr.current.contains(e.target)&&to.current&&!to.current.contains(e.target)&&tn(!1)},t=e=>{"Escape"===e.key&&tn(!1)};return document.addEventListener("mousedown",e,!0),document.addEventListener("keydown",t,!0),()=>{document.removeEventListener("mousedown",e,!0),document.removeEventListener("keydown",t,!0)}},[tt]),(0,i.useEffect)(()=>{td(!0)},[]),(0,i.useEffect)(()=>{e3&&(tm(),tv())},[tv,tm,e3]);let ty=(0,i.useRef)(null),tw=(0,i.useRef)(null),tj=(0,i.useRef)(null),tS=(0,i.useRef)(null),[tC,tT]=(0,i.useState)([]),[tM,tR]=(0,i.useState)(null),tI=(0,i.useRef)(null),tz=(0,i.useRef)(null),tE=(0,i.useRef)(!1),tW=(0,i.useCallback)((e,t,n)=>{tT(e),tR(t),tI.current=n},[]),tP=(0,i.useCallback)(e=>{tI.current?.(e)},[]),[t$,tD]=(0,i.useState)(null),[tB,tA]=(0,i.useState)(!1),tF=(0,i.useRef)(null),tN=(0,i.useRef)(0),tH=(0,i.useRef)(null),tO=(0,i.useCallback)(e=>{tD(e),tA(!1)},[]),tU=(0,i.useCallback)(e=>{tN.current+=1,tF.current=e,tA(!1)},[]),[t_,tV]=(0,i.useState)(null),[tJ,tK]=(0,i.useState)(null),[tY,tG]=(0,i.useState)([]),[tX,tZ]=(0,i.useState)(!1),[tQ,t2]=(0,i.useState)(null),t4=(0,i.useRef)(null),t8=(0,i.useRef)(null),t7=(0,i.useCallback)(e=>{tV(e)},[]),nt=(0,i.useCallback)(e=>{tG(e)},[]),nn=(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)&&tG(n.todos)}catch{}},[]),[nr,ni]=(0,i.useState)(null),no=(0,i.useRef)(null),nk=(0,i.useCallback)((e,t)=>{(0,nh.D)(t).then(()=>{no.current&&clearTimeout(no.current),ni(e),no.current=setTimeout(()=>ni(null),1400)})},[]);(0,i.useEffect)(()=>()=>{no.current&&clearTimeout(no.current)},[]);let[nw,nj]=(0,i.useState)(null),nS=(0,i.useCallback)(e=>{nj(e)},[]),[nC,nT]=(0,i.useState)(null),[nM,nR]=(0,i.useState)(null),nI=(0,i.useRef)(null);(0,i.useEffect)(()=>{if("session"!==nC||!er?.id)return void tK(null);let e=!1;return tK(null),fetch(`/api/sessions/${encodeURIComponent(er.id)}`,{cache:"no-store"}).then(e=>e.ok?e.json():null).then(t=>{e||tK(t?.info?.taskName??null)}).catch(()=>{}),()=>{e=!0}},[nC,er?.id]);let nL=(0,i.useCallback)((e,t=!1)=>{J&&eG(!1),tZ(!1),nT(t=>t===e?null:e),J&&t&&te(!0)},[J]),nz=(0,i.useCallback)((e=!1)=>{let t="system"!==nC;if(nL("system",e),!t||tB)return;let n=tF.current;if(!n)return;let r=++tN.current;tA(!0),n().catch(e=>{console.error("Failed to load system prompt:",e)}).finally(()=>{tN.current===r&&tA(!1)})},[nC,tB,nL]),nE=(0,i.useCallback)(()=>{J&&eG(!1),te(!1),tZ(!1),nT("session")},[J]),nW=(0,i.useCallback)(()=>{J&&eG(!1),te(!1),nT(null),!tX&&er?.id&&nn(er.id),tZ(e=>!e)},[J,tX,er?.id,nn]);(0,i.useEffect)(()=>{if(!tX||!t4.current)return;let e=()=>{let e=t4.current;if(!e)return;let t=e.getBoundingClientRect();t2({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=t4.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)}},[tX]),(0,i.useEffect)(()=>{if(!tX)return;let e=e=>{let t=e.target;t4.current?.contains(t)||t8.current?.contains(t)||tZ(!1)},t=e=>{"Escape"===e.key&&tZ(!1)};return document.addEventListener("pointerdown",e,!0),document.addEventListener("keydown",t,!0),()=>{document.removeEventListener("pointerdown",e,!0),document.removeEventListener("keydown",t,!0)}},[tX]),(0,i.useEffect)(()=>{if(!eX)return;let e=()=>{let e="top"===eQ?e4.current:document.getElementById("terminal-bottombar-btn");if(!e)return;let t=e.getBoundingClientRect();e2({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)}},[eX,eQ]);let nP=(0,i.useCallback)(e=>{e0(e),eZ(t=>e!==eQ||!t)},[eQ]);(0,i.useEffect)(()=>{if(!nC)return;let e=e=>{let t=e.target;nI.current?.contains(t)||t.closest?.("button[data-top-panel-trigger]")||nT(null)},t=e=>{"Escape"===e.key&&nT(null)};return document.addEventListener("pointerdown",e,!0),document.addEventListener("keydown",t,!0),()=>{document.removeEventListener("pointerdown",e,!0),document.removeEventListener("keydown",t,!0)}},[nC]);let n$=(0,i.useCallback)(()=>{J&&(nT(null),tZ(!1),te(!1)),eG(e=>!e)},[J]),nD=(0,i.useCallback)(()=>{eG(!1),nT(null),tZ(!1),te(e=>!e)},[]),nB=(0,i.useCallback)(()=>{J&&(eG(!1),nT(null),te(!1)),e7(e=>!e)},[J]);(0,i.useEffect)(()=>{if(!e9)return;let e=e=>{let t=tj.current;t&&e.composedPath().includes(t)||te(!1)},t=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),te(!1))};return document.addEventListener("pointerdown",e,!0),document.addEventListener("keydown",t,!0),()=>{document.removeEventListener("pointerdown",e,!0),document.removeEventListener("keydown",t,!0)}},[e9]),(0,i.useEffect)(()=>{te(!1)},[J,er?.id,ef]),(0,i.useEffect)(()=>{if(!nC||!tw.current)return;let e=()=>{let e=tw.current.getBoundingClientRect();if("language"===nC&&!J&&tS.current){let t=tS.current.getBoundingClientRect(),n=Math.min(176,e.width),r=Math.min(t.left-1,Math.max(e.left,e.right-n));nR({top:e.bottom,left:r,width:n});return}nR({top:e.bottom,left:e.left,width:e.width})};e();let t=new ResizeObserver(e);return t.observe(tw.current),tS.current&&t.observe(tS.current),()=>t.disconnect()},[nC,J]);let[nA,nF]=(0,i.useState)([]),[nN,nH]=(0,i.useState)(null),nO=(0,i.useCallback)((e,t,n)=>{nF(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))},[]),nU=(0,i.useCallback)((e,t)=>{ty.current?.insertText((0,ng.$C)(e,t)),J&&(e7(!1),eG(!1))},[J]),n_=(0,i.useCallback)(e=>{let t=(0,ng.SO)(e);t&&ty.current?.insertText(t),J&&(e7(!1),eG(!1))},[J]),nV=(0,i.useCallback)((e,t,n)=>{ty.current?.insertText((0,ng.sn)(e,t,n)),J&&(e7(!1),eG(!1))},[J]),nq=R.sessionId,[nJ,nK]=(0,i.useState)(null),[nY,nG]=(0,i.useState)(null),nX=(0,i.useRef)(null),[nZ,nQ]=(0,i.useState)(()=>!nq),n0=(0,i.useRef)(!1),n1=(0,i.useRef)(0),n2=(0,i.useCallback)(()=>{n1.current+=1},[]);(0,i.useEffect)(()=>{er&&function(e,t,n=h()){if(n)try{let r=g(n);r[e]=t,n.setItem(p,JSON.stringify(r))}catch{}}(er.projectKey??nX.current??f(er),er.id)},[er]),(0,i.useEffect)(()=>{let e=R.requestedCwd;if(!e)return;let t=new AbortController;return ek("validating"),ej(null),fetch("/api/cwd/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e}),signal:t.signal}).then(async t=>{let n=await t.json().catch(()=>({}));if(!t.ok||!n.cwd)throw Error(n.error??`HTTP ${t.status}`);n0.current=!0;let r=`initial:${e}`;em(r),ev.current=`new:${r}:${n.cwd}`,ex(n.cwd),ek("ready")}).catch(e=>{t.signal.aborted||(ej(e instanceof Error?e.message:String(e)),ek("error"))}),()=>t.abort()},[R]);let n4=(0,i.useCallback)(e=>{if(nv())return;let t=++n1.current,n=function(e,t=h()){if(!t)return null;try{let n=g(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===n1.current&&x(e),null):n.ok?n.json():null).then(n=>{if(t!==n1.current||!n)return;let r=n.info;if(r&&r.id){if(f(r)!==e)return void x(e);ei(r),eM(e=>e+1),new URLSearchParams(window.location.search).get("session")!==r.id&&T.replace(`?session=${encodeURIComponent(r.id)}`,{scroll:!1})}}).catch(()=>{})},[T]),n8=(0,i.useCallback)((e,t,n)=>{n2();let r=eg??nJ;if(nK(e),!e)return;let i=n??t??e,o=nX.current??(er?f(er):null);if(nX.current=i,n0.current){n0.current=!1;return}if(r===e&&o!==i||o===i&&(null!==er||r===e))return;let a="function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;em(a),ev.current=`new:${a}:${e}`,ei(null),ex(t=>t&&t!==e?null:t),eM(e=>e+1),tT([]),tR(null),tD(null),tA(!1),nT(null),o!==i&&(nF([]),nH(null),e7(!1),tE.current?tE.current=!1:n4(i)),T.replace(function(){let e=nv();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})},[nJ,n2,eg,T,er,n4]),n5=(0,i.useCallback)((e,t=!1)=>{if(n2(),ev.current=null,!t&&er){let t=f(er)===f(e);if(er.id===e.id&&t){J&&eG(!1);return}}ex(null),ei(e),el(null),eM(e=>e+1),tD(null),tA(!1),nQ(!0),J&&!t&&eG(!1),t&&(n0.current=!0),t||T.replace(`?session=${encodeURIComponent(e.id)}`,{scroll:!1})},[n2,T,J,er]),n6=(0,i.useCallback)(e=>{tE.current=!0,n5(e)},[n5]),n3=(0,i.useCallback)((e,t)=>{n2(),ev.current=e,em(e),ei(null),ex(t),eM(e=>e+1),tT([]),tR(null),tD(null),tA(!1),nT(null),el(null),J&&eG(!1),T.replace("/",{scroll:!1})},[n2,T,J]),n7=(0,i.useCallback)((e,t)=>{let n=er?.cwd??eg??nJ;n&&(tz.current={taskId:e,projectKey:t},n3(crypto.randomUUID(),n))},[er?.cwd,eg,nJ,n3]),n9=(0,i.useCallback)((e,t)=>{ex(e),nK(e),t&&nG(t)},[]),re=(0,i.useRef)(n9);re.current=n9;let rt=(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&&(ep(t.board.id),ec(e))}).catch(()=>{})},[ep]);(0,l.n)({onNewSession:e=>n3(`kb-${Date.now()}`,e),activeCwd:nJ});let rn=(0,i.useRef)([]),rr=(0,i.useRef)(null),ri=(0,i.useCallback)(e=>{let t=rn.current.find(t=>t.id===e);t?ei(n=>n?.id===e?{...n,...t,transient:t.transient??!1}:n):rr.current=e},[]),ro=(0,i.useCallback)(e=>{rn.current=e;let t=rr.current;if(!t)return;let n=e.find(e=>e.id===t);n&&(rr.current=null,ei(e=>e?.id===t?{...e,...n,transient:n.transient??!1}:e))},[]),ra=(0,i.useCallback)((e,t)=>{eC(e=>e+1),ev.current===t&&(n2(),ev.current=null,ex(null),ei(e),ri(e.id),T.replace(`?session=${encodeURIComponent(e.id)}`,{scroll:!1}),tz.current=null)},[n2,T,ri]),rs=(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,nx.dL)({title:t,body:n,sessionUrl:i,tag:r,onClick:()=>{window.focus(),e&&n5(e)}})};"granted"===Notification.permission?i():"default"===Notification.permission&&Notification.requestPermission().then(e=>{"granted"===e&&i()})},[n5]),rl=(0,i.useCallback)(()=>{eC(e=>e+1),eI(e=>e+1),er&&ri(er.id),(0,nx.SH)()&&rs({targetSession:er,title:er?.name??V("i18n.sessionComplete"),body:V("i18n.taskFinished")})},[rs,ri,er,V]),rd=(0,i.useCallback)(e=>{!(0,nx.SH)()||(0,nx.$N)(e,Q.current)&&rs({targetSession:er,title:V("i18n.attentionNeeded"),body:"custom"===e.method?V("i18n.extensionInputNeeded"):e.title,tag:`pi-extension-ui:${e.id}`})},[rs,er,V]);(0,i.useEffect)(()=>{tZ(!1);let e=er?.id;e&&nn(e)},[er?.id,nn]);let rc=!!(er?.id&&eo.has(er.id));(0,i.useEffect)(()=>{let e,t=er?.id;if(!t||!rc)return;let n=!1,r=async()=>{await nn(t),n||(e=setTimeout(r,6e3))};return r(),()=>{n=!0,e&&clearTimeout(e)}},[er?.id,rc,nn]);let ru=(0,i.useCallback)(()=>{eI(e=>e+1)},[]),rp=(0,i.useCallback)(e=>{n2(),ev.current=null,eC(e=>e+1),eM(e=>e+1),ex(null),ei(t=>({...t??{path:"",cwd:"",created:"",modified:"",messageCount:0,firstMessage:""},id:e,transient:!1})),ri(e),T.replace(`?session=${encodeURIComponent(e)}`,{scroll:!1})},[n2,T,ri]),rh=(0,i.useCallback)(()=>{nQ(!0)},[]),rg=(0,i.useCallback)(e=>{if(n2(),eC(e=>e+1),er?.id===e){let e=er.cwd,t="function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;em(t),ev.current=e?`new:${t}:${e}`:null,ei(null),ex(e??null),eM(e=>e+1),tT([]),tR(null),tD(null),tA(!1),nT(null),T.replace("/",{scroll:!1})}},[n2,er,T]),rx=(0,i.useCallback)((e,t,n)=>{let r=n?.sourceSessionId,i=n?.modeHint,o=`file:${e}`;nF(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})),nH(o),e7(!0),J&&eG(!1)},[J]),rf=(0,i.useCallback)(e=>{rx(e,(0,j.WP)(e),{sourceSessionId:er?.id??null})},[rx,er?.id]);(0,i.useEffect)(()=>{let e=e=>{let t=e.detail;t?.filePath&&rx(t.filePath,(0,j.WP)(t.filePath),{sourceSessionId:t.sessionId})},t=e=>{let t=e.detail;t?.newSessionId&&(eC(e=>e+1),eI(e=>e+1))},n=e=>{let t=e.detail;t?.sessionId&&(eC(e=>e+1),eI(e=>e+1))},r=()=>{eC(e=>e+1)},i=e=>{let t=e.detail;t?.sessionId&&eC(e=>e+1)},o=e=>{let t=e.detail;if(!t?.sessionId)return;let n=ee.current;if(n.add(t.sessionId),n.size>100)for(let e of[...n].slice(0,n.size-100))n.delete(e);eC(e=>e+1),eI(e=>e+1),(0,nx.SH)()&&rs({targetSession:null,title:t.sessionName??V("i18n.sessionComplete"),body:V("i18n.taskFinished")})},a=e=>{let t=e.detail;!t?.sessionId||(0,nx.SH)()&&rs({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&&re.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)}},[rs,rx,V]);let rm=(0,i.useCallback)(e=>{nF(t=>{let n=t.filter(t=>t.id!==e);return 0===n.length&&e7(!1),n}),nH(t=>{if(t!==e)return t;let n=nA.filter(t=>t.id!==e);return n.length>0?n[n.length-1].id:null})},[nA]),rv=(0,i.useCallback)(()=>{er&&window.open(`/api/sessions/${encodeURIComponent(er.id)}/export?inline=1`,"_blank","noopener,noreferrer")},[er]),rb=eg??(null===er&&nJ?nJ:null),ry=null===er&&rb?ef:null;(0,i.useLayoutEffect)(()=>{ev.current=ry},[ry]);let rk=null!==er||null!==rb,rw=er?.cwd??rb,rj=nZ&&!rk;(0,i.useEffect)(()=>{if(eF(null),eH(!1),eV(null),!rw)return;let e=new AbortController;return fetch(`/api/project-trust?cwd=${encodeURIComponent(rw)}`,{signal:e.signal}).then(async e=>{let t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);eF(t)}).catch(e=>{e instanceof DOMException&&"AbortError"===e.name||console.error("Failed to load project trust:",e)}),()=>e.abort()},[rw]);let rS=(0,i.useCallback)(async()=>{if(rw&&!eO){eU(!0),eV(null);try{let e=await fetch("/api/project-trust",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:rw})}),t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);eF(t),eH(!1),eW(e=>e+1),eM(e=>e+1)}catch(e){eV(e instanceof Error?e.message:String(e))}finally{eU(!1)}}},[eO,rw]),rC=nA.find(e=>e.id===nN)??null,rT="Pi Web";(0,i.useEffect)(()=>{let e=()=>{document.title!==rT&&(document.title=rT)};e();let t=new MutationObserver(e);return t.observe(document.head,{childList:!0,subtree:!0,characterData:!0}),()=>t.disconnect()},[rT]);let rM=(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(en,{selectedSessionId:er?.id??null,onSelectSession:n5,onNewSession:n3,initialSessionId:nq,skipInitialProjectSelection:null!==R.requestedCwd,onInitialRestoreDone:rh,refreshKey:eS,onSessionDeleted:rg,selectedCwd:er?.cwd??eg??null,activeWorktreeProject:nY,onCwdChange:n8,onOpenFile:rx,explorerRefreshKey:eR,onExplorerRefresh:ru,onRefresh:()=>eC(e=>e+1),onSessionsLoaded:ro,onAtMention:nU,onAtMentions:n_,onBackgroundTaskDone:et,onRunningSessionIdsChange:eu,onNewSessionFromTask:n7,onOpenBoard:ep,onOpenTaskBoard:rt,onExitBoard:()=>el(null),activeBoardId:es}),(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:()=>ez(!0),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:()=>e$(!0),disabled:!nJ&&!er?.cwd&&!eg,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.plugins"),onClick:()=>eB(!0),disabled:!nJ&&!er?.cwd&&!eg,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:"M9 7V2"}),(0,r.jsx)("path",{d:"M15 7V2"}),(0,r.jsx)("path",{d:"M6 13V8a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v5a6 6 0 0 1-12 0Z"}),(0,r.jsx)("path",{d:"M12 19v3"})]})}].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))})]}),rR=e=>(0,r.jsx)("button",{type:"button",onClick:t=>{let n=t.currentTarget.getBoundingClientRect();L({x:n.left+n.width/2,y:n.top+n.height/2}),e&&te(!0)},title:V(O),"aria-label":V(O),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"===I?(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"===I?(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"})]})}),rI=e=>(0,r.jsx)("button",{ref:to,type:"button",onClick:t=>{tb(t),e&&te(!0)},title:V("bg.title"),"aria-label":V("bg.title"),"aria-haspopup":"menu","aria-expanded":tt,style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:tt?"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)"}})]})}),rL=e=>(0,r.jsx)("button",{ref:tS,type:"button","data-top-panel-trigger":!0,onClick:()=>nL("language",e),title:V("common.language"),"aria-label":V("common.language"),"aria-haspopup":"menu","aria-expanded":"language"===nC,"aria-pressed":"language"===nC,style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"language"===nC?"var(--bg-selected)":"none",border:"none",borderRight:"1px solid var(--border)",color:"language"===nC?"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"===nC?"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"})]})}),rz=e=>rk&&eA?.requiresTrust&&!eA.trusted?(0,r.jsxs)("button",{type:"button",onClick:()=>{eV(null),eH(!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,rE=e=>e||rk?!e&&es?(0,r.jsxs)("div",{style:{display:"flex",alignItems:"stretch",height:"100%"},children:[r$(),rD()]}):(0,r.jsxs)("div",{style:{display:"flex",alignItems:"stretch",height:"100%"},children:[(0,r.jsxs)("button",{type:"button",onClick:()=>{rv(),e&&te(!0)},disabled:!er,title:er?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:er?"var(--text-muted)":"var(--text-dim)",cursor:er?"pointer":"not-allowed",opacity:er?1:.45,flexShrink:0,fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s, opacity 0.1s"},onMouseEnter:e=>{er&&(e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{e.currentTarget.style.color=er?"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:er?"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:()=>nL("branches",!0),title:V("i18n.branches"),"aria-label":V("i18n.branches"),"aria-pressed":"branches"===nC,style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:"100%",padding:0,background:"branches"===nC?"var(--bg-selected)":"none",border:"none",borderTop:"branches"===nC?"2px solid var(--accent)":"2px solid transparent",borderRight:"1px solid var(--border)",color:"branches"===nC?"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:tC.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)(t5,{tree:tC,activeLeafId:tM,onLeafChange:tP,inline:!0,containerRef:tw,open:"branches"===nC,onToggle:()=>nL("branches"),hasSession:!0}),(0,r.jsxs)("button",{ref:tH,type:"button","data-top-panel-trigger":!0,onClick:()=>nz(e),disabled:e&&!rk,title:V("system.prompt"),"aria-label":V("system.prompt"),"aria-pressed":"system"===nC,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,width:e?36:void 0,height:"100%",padding:e?0:"0 12px",background:"system"===nC?"var(--bg-selected)":"none",border:"none",borderTop:"system"===nC?"2px solid var(--accent)":"2px solid transparent",borderRight:"1px solid var(--border)",cursor:e&&!rk?"not-allowed":"pointer",color:"system"===nC?"var(--text)":"var(--text-muted)",opacity:e&&!rk?.45:1,fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s"},onMouseEnter:t=>{(!e||rk)&&(t.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.color="system"===nC?"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:t$?"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&&r$(),!e&&rD(),e&&rR(!0),e&&rL(!0),e&&rI(!0)]}):null,rW=e=>{if(!e&&(!rk||!t_&&!nw))return null;let t=t_?.tokens,n=t_?.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(nw?.contextWindow){let e=nw.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(nw.contextWindow)}`:`? / ${i(nw.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(" | ")}(t_,nw,U),c=e&&e9,u=!!(t&&(t.input>0||t.output>0)||o||l);return(0,r.jsx)("button",{type:"button","data-top-panel-trigger":!0,onClick:()=>nL("session"),disabled:!rk||c,tabIndex:c?-1:void 0,title:d||V("session.title"),"aria-label":V("session.title"),"aria-pressed":"session"===nC,"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"===nC?"var(--bg-selected)":"none",border:"none",borderTop:"session"===nC?"2px solid var(--accent)":"2px solid transparent",fontSize:11,color:"var(--text-muted)",whiteSpace:"nowrap",cursor:rk?"pointer":"default",fontVariantNumeric:"tabular-nums",transition:"color 0.1s, background 0.1s"},onMouseEnter:e=>{rk&&!c&&(e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.color="session"===nC?"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&&rk&&(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]})]})})},rP=e=>{if(0===tY.length)return null;let t=tY.filter(e=>"completed"!==e.status).length,n=tX&&!e;return(0,r.jsxs)("button",{type:"button",ref:t4,onClick:nW,title:V("todo.title"),"aria-label":V("todo.title"),"aria-expanded":tX,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,height:"100%",padding:e?"0 8px":"0 12px",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",fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color=n?"var(--text)":"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)("rect",{x:"3",y:"4",width:"18",height:"16",rx:"3"}),(0,r.jsx)("path",{d:"M8 9h8M8 13h5"})]}),(0,r.jsx)("span",{children:t>0?t:"✓"})]})},r$=()=>{let e=eX&&"top"===eQ;return(0,r.jsxs)("button",{type:"button",id:"terminal-topbar-btn",ref:e4,onClick:()=>nP("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")})]})},rD=()=>(0,r.jsxs)("button",{type:"button",id:"mcp-topbar-btn",ref:e6,onClick:()=>e5(e=>!e),title:"MCP","aria-label":"MCP","aria-expanded":e8,style:{display:"flex",alignItems:"center",justifyContent:"center",width:"auto",height:"100%",padding:"0 10px",gap:5,background:e8?"var(--bg-selected)":"none",border:"none",borderTop:e8?"2px solid var(--accent)":"2px solid transparent",borderRight:"1px solid var(--border)",color:e8?"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:e=>{e.currentTarget.style.color=e8?"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"})]}),rB=e=>{let t=e&&e9;return(0,r.jsx)("button",{type:"button",onClick:nB,disabled:t,tabIndex:t?-1:void 0,"aria-controls":"file-panel","aria-expanded":e3,"aria-hidden":!!t||void 0,title:e3?V("files.hidePanel"):V("files.showPanel"),"aria-label":e3?V("files.hidePanel"):V("files.showPanel"),"data-mobile-toolbar-file":e?"true":void 0,style:{marginLeft:e||t_||nw?0:"auto",display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,visibility:t?"hidden":"visible",pointerEvents:t?"none":"auto",background:e3?"var(--bg-selected)":"none",border:"none",borderLeft:"1px solid var(--border)",color:e3?"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=e3?"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"})]})})},rA=(0,i.useMemo)(()=>{if(er){let e=er.projectRoot??er.cwd,t=e.split(/[\\/]/).filter(Boolean).pop()??e;return er.isWorktree&&er.branch?`${t}\xb7${er.branch}`:t}return rb?rb.split(/[\\/]/).filter(Boolean).pop()??rb:null},[er,rb]);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("style",{children:`
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:()=>u});var r=n(95155),i=n(12115),o=n(47650),a=n(39247),s=n(20985);function l(e,t){return t&&e.startsWith(t)?"~"+e.slice(t.length):e}function d({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 c=(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 u({cwd:e,onSelect:t,style:n,labelStyle:p,onOpenChange:h,showMainLabel:g=!0,compact:x=!1}){let{t:f}=(0,a.s)(),[m,v]=(0,i.useState)(null),[b,y]=(0,i.useState)(!1),[k,w]=(0,i.useState)(""),[j,S]=(0,i.useState)(!1),[C,T]=(0,i.useState)(!1),[M,R]=(0,i.useState)(""),[I,L]=(0,i.useState)(!1),[z,E]=(0,i.useState)(""),[W,P]=(0,i.useState)(null),[$,D]=(0,i.useState)(!1),[B,A]=(0,i.useState)(null),F=(0,i.useRef)(null),N=(0,i.useRef)(null),H=(0,i.useRef)(null),O=(0,i.useRef)(null),[U,_]=(0,i.useState)(null);(0,i.useEffect)(()=>{fetch("/api/home").then(e=>e.json()).then(e=>{e.home&&w(e.home)}).catch(()=>{})},[]);let V=(0,i.useRef)(null);(0,i.useEffect)(()=>{if(!e||V.current===e)return;let t=!1;return y(!0),fetch(`/api/worktrees?cwd=${encodeURIComponent(e)}`).then(e=>e.json()).then(n=>{if(!t){if(y(!1),n.error||!n.projectRoot)return void v(null);v({forCwd:e,projectRoot:n.projectRoot,projectKey:n.projectKey??"",isGit:n.isGit??!1,isTopLevel:n.isTopLevel??!1,currentWorktreePath:n.currentWorktreePath??null,worktrees:n.worktrees??[]}),V.current=e}}).catch(()=>{t||y(!1)}),()=>{t=!0}},[e]);let q=m?m.worktrees.find(t=>t.path===e)??(m.forCwd===e&&m.currentWorktreePath?m.worktrees.find(e=>e.path===m.currentWorktreePath):void 0)??m.worktrees.find(e=>e.isMain):void 0,J=(0,i.useCallback)(()=>{let e=N.current?.getBoundingClientRect();if(!e)return;let t=window.innerHeight-e.bottom<Math.min(320,e.top);_({left:e.left,top:t?e.top:e.bottom,width:e.width,up:t}),S(!0)},[]);(0,i.useEffect)(()=>{h?.(j)},[j,h]);let K=(0,i.useCallback)(e=>{S(!1),P(null),R(""),t?.(e,m?{projectRoot:m.projectRoot,projectKey:m.projectKey,worktreePaths:m.worktrees.map(e=>e.path)}:void 0)},[t,m]),Y=(0,i.useCallback)(async()=>{let e=z.trim();if(e&&!$&&m){D(!0),P(null);try{let n=await fetch("/api/worktrees",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:m.projectRoot,branch:e})}),r=await n.json().catch(()=>({}));if(!n.ok||r.error||!r.path)return void P(r.error??`HTTP ${n.status}`);L(!1),E(""),v(t=>t?{...t,worktrees:[...t.worktrees,{path:r.path,branch:e,isMain:!1}]}:t),S(!1),P(null),R(""),t?.(r.path,m?{projectRoot:m.projectRoot,projectKey:m.projectKey,worktreePaths:[...m.worktrees.map(e=>e.path),r.path]}:void 0)}catch(e){P(e instanceof Error?e.message:String(e))}finally{D(!1)}}},[z,$,m,t]),G=(0,i.useCallback)(async(e,n)=>{if(m&&!$){D(!0),P(null);try{let r=await fetch("/api/worktrees",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:m.projectRoot,path:e,force:n})}),i=await r.json().catch(()=>({}));if(!r.ok){if(i.dirty&&!n)return void A(e);P(i.error??`HTTP ${r.status}`);return}A(null),v(t=>t?{...t,worktrees:t.worktrees.filter(t=>t.path!==e)}:t),q?.path===e&&(S(!1),P(null),R(""),t?.(m.projectRoot,m?{projectRoot:m.projectRoot,projectKey:m.projectKey,worktreePaths:m.worktrees.filter(t=>t.path!==e).map(e=>e.path)}:void 0))}catch(e){P(e instanceof Error?e.message:String(e))}finally{D(!1)}}},[m,$,q?.path,t]);(0,i.useEffect)(()=>{let e=e=>{let t=e.target;F.current?.contains(t)||H.current?.contains(t)||(S(!1),L(!1),E(""),P(null),A(null),R(""))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let X=(m?.worktrees.length??0)>=8,Z=X&&M.trim()?(m?.worktrees??[]).filter(e=>(e.branch??l(e.path,k)).toLowerCase().includes(M.trim().toLowerCase())):m?.worktrees??[],Q=q?.path??null,ee=null!==m&&!(m.isGit&&m.isTopLevel),et=ee?m.isGit?"当前为仓库子目录,子目录会话保持自身项目身份":"该目录不是 git 仓库,worktree 切换不可用":null;return(0,r.jsxs)("div",{ref:F,style:{position:"relative"},children:[(0,r.jsxs)("button",{ref:N,onClick:ee?void 0:J,title:ee?et??void 0:q?q.path:f("sidebar.switchWorktree"),style:{display:"flex",alignItems:"center",gap:6,height:28,boxSizing:"border-box",padding:x?"0 6px":"0 10px",maxWidth:x?85:void 0,background:j?"var(--side-active)":C?"var(--side-hover)":"transparent",border:"none",borderRadius:5,cursor:ee?"default":"pointer",fontSize:11,lineHeight:1.35,color:"var(--text-muted)",textAlign:"left",transition:"background 0.12s",...n},onMouseEnter:()=>T(!0),onMouseLeave:()=>T(!1),children:[c,(0,r.jsx)(d,{text:q?q.branch??l(q.path,k):b?"…":f("sidebar.worktrees"),style:{flex:1,fontFamily:"var(--font-mono)",color:"var(--text)",...p}}),g&&q?.isMain&&(0,r.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10},children:f("sidebar.main")}),!x&&!ee&&(m?.worktrees.length??0)>1&&(0,r.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10},children:m.worktrees.length}),!x&&!ee&&(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"})})]}),U&&(0,o.createPortal)((0,r.jsx)("div",{ref:H,style:{position:"fixed",left:U.left,top:U.top,width:U.width,zIndex:1e3},children:(0,r.jsxs)(s.f,{open:j,up:U.up,style:{position:"absolute",top:U.up?"auto":4,bottom:U.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:[X&&(0,r.jsx)("div",{style:{padding:"6px 8px",borderBottom:"1px solid var(--border)"},children:(0,r.jsx)("input",{value:M,onChange:e=>R(e.target.value),onKeyDown:e=>{"Escape"===e.key&&(R(""),S(!1))},placeholder:f("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:[Z.map(e=>{let t=e.path===Q;return B===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:f("sidebar.forceRemoveCheckout")}),(0,r.jsx)("button",{onClick:()=>void G(e.path,!0),disabled:$,style:{padding:"3px 9px",background:"#ef4444",border:"none",borderRadius:5,color:"#fff",fontSize:11,fontWeight:600,cursor:"pointer",flexShrink:0},children:f("sidebar.force")}),(0,r.jsx)("button",{onClick:()=>A(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:f("sidebar.cancel")})]},e.path):(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",borderBottom:"1px solid var(--border)"},children:[(0,r.jsxs)("button",{onClick:()=>K(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)(d,{text:e.branch??l(e.path,k),style:{flex:1}}),e.isMain&&(0,r.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10},children:f("sidebar.main")})]}),!e.isMain&&(0,r.jsx)("button",{onClick:()=>void G(e.path,!1),disabled:$,title:f("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)}),X&&0===Z.length&&M.trim()&&(0,r.jsx)("div",{style:{padding:"8px 10px",fontSize:11,color:"var(--text-dim)"},children:f("sidebar.noMatchingWorktrees")})]}),I?(0,r.jsxs)("div",{style:{padding:"6px 8px"},children:[(0,r.jsx)("input",{ref:O,value:z,onChange:e=>{E(e.target.value),P(null)},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),Y()),"Escape"===e.key&&(L(!1),E(""),P(null))},placeholder:f("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 Y(),disabled:$||!z.trim(),style:{flex:1,padding:"4px 0",background:"var(--accent)",border:"none",borderRadius:5,color:"#fff",fontSize:11,fontWeight:600,cursor:$||!z.trim()?"not-allowed":"pointer",opacity:$||!z.trim()?.65:1},children:$?f("sidebar.creating"):f("sidebar.create")}),(0,r.jsx)("button",{onClick:()=>{L(!1),E(""),P(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:f("sidebar.cancel")})]})]}):(0,r.jsxs)("button",{onClick:e=>{e.stopPropagation(),L(!0),P(null),setTimeout(()=>O.current?.focus(),0)},title:f("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:f("sidebar.newWorktree")})]}),W&&(0,r.jsx)("div",{style:{padding:"5px 10px 8px",color:"#dc2626",fontSize:11,lineHeight:1.35,overflowWrap:"anywhere"},children:W})]})}),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):""}},25069:(e,t,n)=>{"use strict";n.d(t,{AppShell:()=>nk});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(1518);let p="pi-web:last-open-by-workspace";function h(){try{return window.localStorage}catch{return null}}function g(e){let t=e.getItem(p);if(!t)return{};try{let e=JSON.parse(t);return null===e||"object"!=typeof e||Array.isArray(e)?{}:e}catch{return{}}}function x(e,t=h()){if(t)try{let n=g(t);if(!(e in n))return;delete n[e],0===Object.keys(n).length?t.removeItem(p):t.setItem(p,JSON.stringify(n))}catch{}}function f(e){return e.projectKey??e.projectRoot??e.cwd}function m(e){let t=new Map;for(let n of e){let e=n.projectRoot??n.cwd;if(!e)continue;let r=f(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}))}var v=n(39247),b=n(20985);function y(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 k=n(29608),w=n(30527),j=n(28999);async function S(e){let t=(0,j.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,j.e_)(e,t.name),isDir:t.isDir,size:t.size,children:t.isDir?[]:void 0,loaded:!t.isDir}))}async function C(e,t){let n=new URLSearchParams({type:"search",q:t}),r=await fetch(`/api/files/${(0,j.HG)(e)}?${n.toString()}`);if(!r.ok)throw Error(`Search failed (HTTP ${r.status})`);return r.json()}async function T(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 M={modified:"files.modified",added:"files.added",deleted:"files.deleted",renamed:"files.renamed",untracked:"files.untracked",conflict:"files.conflict"},R={modified:"#d6a84b",added:"#4ade80",deleted:"#f87171",renamed:"#60a5fa",untracked:"#4ade80",conflict:"#f87171"};function I({status:e,t}){return(0,r.jsx)("span",{title:t(M[e.status]),"aria-label":t(M[e.status]),style:{width:14,height:14,flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",color:R[e.status],fontFamily:"var(--font-mono)",fontSize:11,fontWeight:600},children:e.code})}function L({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 z({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 E({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,j.A0)(e.fullPath),m=u.get(f),v=e.isDir&&(void 0!==m||p.has(f)),[b,y]=(0,i.useState)(e.children??[]),[k,C]=(0,i.useState)(e.loaded??!1),[T,M]=(0,i.useState)(!1),[R,z]=(0,i.useState)(!1),W=(0,i.useCallback)(async(t=!1)=>{if(!k||t){M(!0);try{let t=await S(e.fullPath);y(t),C(!0)}catch{}finally{M(!1)}}},[k,e.fullPath]);(0,i.useEffect)(()=>{g&&k&&W(!0)},[d]);let P=(0,i.useCallback)(()=>{if(e.isDir){let t=!g;l(e.fullPath,t),t&&!k&&W()}else o(e.fullPath,e.name)},[e.isDir,e.fullPath,e.name,k,g,W,o,l]);return(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{onClick:P,onMouseEnter:()=>z(!0),onMouseLeave:()=>z(!1),style:{position:"relative",display:"flex",alignItems:"center",gap:4,paddingLeft:8+14*t,paddingRight:8,height:24,cursor:"pointer",background:R?"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)(w.sj,{size:14,open:g}):(0,w.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"}})}),!R&&!e.isDir&&m&&(0,r.jsx)(I,{status:m,t:h}),!R&&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"}})}),T&&(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&&R&&(0,r.jsxs)("button",{onClick:t=>{t.stopPropagation(),a((0,j.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)(L,{}),h("files.mention")]}),R&&!e.isDir&&(0,r.jsx)("a",{href:`/api/files/${(0,j.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)(E,{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 W({status:e,cwd:t,onOpenFile:n,t:o}){let[a,s]=(0,i.useState)(!1),l=(0,j.WP)(e.filePath),d=(0,j.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)(I,{status:e,t:o}),(0,r.jsx)("span",{style:{flexShrink:0,display:"flex",alignItems:"center",opacity:.85},children:(0,w.I3)(l,13)}),(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:d})]})}function P({match:e,cwd:t,onOpenFile:n}){let[o,a]=(0,i.useState)(!1),s=(0,j.WP)(e.path);return(0,r.jsxs)("div",{onClick:()=>n((0,j.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)(w.sj,{size:13}):(0,w.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 $=(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,v.s)(),[h,g]=(0,i.useState)([]),[x,f]=(0,i.useState)(!0),[m,b]=(0,i.useState)(null),[y,k]=(0,i.useState)(new Set),[w,M]=(0,i.useState)(0),[I,$]=(0,i.useState)(new Set),[D,B]=(0,i.useState)([]),[A,F]=(0,i.useState)({additions:0,deletions:0}),[N,H]=(0,i.useState)("idle"),[O,U]=(0,i.useState)(0),[_,V]=(0,i.useState)(null),[q,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}:${w}`,er="idle"!==N,ei=(0,i.useMemo)(()=>new Map(D.map(e=>[(0,j.A0)(e.filePath),e])),[D]),eo=(0,i.useMemo)(()=>{let t=new Set,n=(0,j.A0)(e).replace(/\/$/,"");for(let e of D){let r=(0,j.gX)((0,j.A0)(e.filePath));for(;(r===n||r.startsWith(`${n}/`))&&(t.add(r),r!==n);){let e=(0,j.gX)(r);if(e===r)break;r=e}}return t},[e,D]),ea=(0,i.useCallback)((e,t)=>{k(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&&($(new Set(n.map(t=>(0,j.e_)(e,t)))),M(e=>e+1))},[e]),el=(0,i.useCallback)(async(t,n)=>{Y(null),V(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,j.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){V(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),$(new Set),Y(null),V(null),U(0),H("checking");try{let n=await fetch(`/api/files/${(0,j.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){V(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&&(k(new Set),$(new Set),J(null),Y(null),V(null),X(""),Q(null)),f(t),b(null);let n=!1;return S(e).then(e=>{n||g(e)}).catch(e=>{n||b(e instanceof Error?e.message:String(e))}).finally(()=>{n||f(!1)}),()=>{n=!0}},[e,n,w]),(0,i.useEffect)(()=>{let t=!1;return T(e).then(e=>{t||(B(e.isGitRepository?e.files:[]),F(e.isGitRepository?{additions:e.additions,deletions:e.deletions}:{additions:0,deletions:0}))}).catch(()=>{t||(B([]),F({additions:0,deletions:0}))}),()=>{t=!0}},[e,n,w]),(0,i.useEffect)(()=>{let t=G.trim();if(!t)return void Q(null);let n=!1,r=setTimeout(()=>{C(e,t).then(e=>{n||Q(e.matches)}).catch(()=>{n||Q([])})},200);return()=>{n=!0,clearTimeout(r)}},[e,G]),(0,i.useEffect)(()=>{d?.(D.length)},[D,d]);let eu=er||null!==K||null!==_||null!==q,ep=!l&&D.length>0,eh=(0,i.useCallback)(()=>{q&&0!==q.uploaded.length&&a?.(q.uploaded.map(t=>(0,j.qP)((0,j.e_)(e,t),e)))},[e,a,q]);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"===N?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"===N?(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"===N&&(0,r.jsxs)("span",{style:{fontSize:10},children:[O,"%"]})]}),"uploading"===N&&(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)(z,{onClick:()=>V(null),title:p("files.dismissError")})]}),q&&(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:[q.uploaded.length>0&&(0,r.jsxs)("span",{title:`${q.uploaded.length} uploaded`,"aria-label":`${q.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:q.uploaded.length})]}),q.skipped.length>0&&(0,r.jsxs)("span",{title:`${q.skipped.length} skipped`,"aria-label":`${q.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:q.skipped.length})]}),q.errors.length>0&&(0,r.jsxs)("span",{title:`${q.errors.length} failed`,"aria-label":`${q.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:q.errors.length})]})]}),q.uploaded.length>0&&a&&(0,r.jsxs)("button",{type:"button",onClick:eh,title:1===q.uploaded.length?p("files.addUploadedFile"):p("files.addAllUploadedFiles"),"aria-label":1===q.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)(L,{}),p("files.mention")]}),(0,r.jsx)(z,{onClick:()=>J(null),title:p("files.dismissUploadResults")})]}),q.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:D.length,additions:A.additions,deletions:A.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:D.length})}),(0,r.jsxs)("span",{style:{color:R.added,fontFamily:"var(--font-mono)"},children:["+",A.additions]}),(0,r.jsxs)("span",{style:{color:R.deleted,fontFamily:"var(--font-mono)"},children:["-",A.deletions]})]}),D.map(n=>(0,r.jsx)(W,{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)(P,{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)(E,{node:n,depth:0,cwd:e,onOpenFile:t,onAtMention:o,expandedPaths:y,onToggleExpanded:ea,refreshToken:en,highlightedPaths:I,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 D({active:e,onChange:t,runningCount:n=0}){let{t:o}=(0,v.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)})})}function B({activeBoardId:e,collapsed:t,onToggleCollapsed:n,onOpenBoard:o,onExitBoard:a,refreshKey:s}){let{t:l}=(0,v.s)(),[d,c]=(0,i.useState)([]),[,u]=(0,i.useState)(!0),[p,h]=(0,i.useState)(!1),[g,x]=(0,i.useState)(""),[f,m]=(0,i.useState)(null),[b,y]=(0,i.useState)(""),[k,w]=(0,i.useState)(null),[j,S]=(0,i.useState)(!1),[C,T]=(0,i.useState)(null),[M,R]=(0,i.useState)(null),I=(0,i.useRef)(null),L=(0,i.useRef)(null),z=(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 c(t.boards),t.boards}catch{return null}finally{u(!1)}},[]);(0,i.useEffect)(()=>{z()},[z,s]),(0,i.useEffect)(()=>{p&&I.current?.focus()},[p]),(0,i.useEffect)(()=>{f&&L.current?.focus()},[f]);let E=async()=>{let e=g.trim();if(e&&!j){S(!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();x(""),h(!1),await z(),o(e.board.id)}}finally{S(!1)}}},W=async e=>{if(j)return;let t=b.trim();if(!t)return void m(null);S(!0);try{(await fetch(`/api/boards/${encodeURIComponent(e)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t})})).ok&&(m(null),await z())}finally{S(!1)}},P=async t=>{if(!j){S(!0);try{if((await fetch(`/api/boards/${encodeURIComponent(t)}`,{method:"DELETE"})).ok){w(null);let n=await z();if(e===t){let e=(n??[]).find(e=>!e.isSystem&&null==e.taskId&&e.id!==t);e?o(e.id):a?.()}}}finally{S(!1)}}},$=(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",T({id:e}),R(null))},[]),D=(0,i.useCallback)(e=>t=>{if(!t.dataTransfer.types.includes("application/x-board-id")||!C||C.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})},[C]),F=(0,i.useCallback)(e=>t=>{t.preventDefault();let n=t.dataTransfer.getData("application/x-board-id")||C?.id;if(!n||!M||M.targetId!==e){T(null),R(null);return}let r=d.filter(e=>!e.isSystem&&null==e.taskId).map(e=>e.id),i=r.indexOf(n),o=r.indexOf(e);if(T(null),R(null),-1===i||-1===o)return;let a=[...r];a.splice(i,1);let s=a.indexOf(e)+ +!M.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 z()}).catch(()=>{})},[d,M,C,z]),N=d.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:()=>h(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:[p&&(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:I,value:g,onChange:e=>x(e.target.value),onKeyDown:e=>{"Enter"===e.key&&E(),"Escape"===e.key&&(h(!1),x(""))},onBlur:()=>{g.trim()&&E(),h(!1),x("")},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:!g.trim(),onMouseDown:e=>e.preventDefault(),onClick:()=>void E(),style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,background:"transparent",border:"none",borderRadius:5,color:g.trim()?"var(--accent)":"var(--text-dim)",cursor:g.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:()=>{h(!1),x("")},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===N.length&&(0,r.jsx)("div",{style:{padding:"6px 10px",color:"var(--text-muted)",fontSize:11.5,fontStyle:"italic"},children:l("boards.empty")}),N.map(t=>(0,r.jsx)(A,{board:t,isActive:e===t.id,isDragging:C?.id===t.id,dropBefore:M?.targetId===t.id&&M.before,dropAfter:M?.targetId===t.id&&!M.before,renaming:f===t.id,renameValue:b,renameInputRef:L,onRenameValueChange:y,onStartRename:()=>{m(t.id),y(t.name)},onCommitRename:()=>void W(t.id),onCancelRename:()=>m(null),onDelete:()=>w(t.id),onDragStart:$(t.id),onDragEnd:()=>{T(null),R(null)},onDragOver:D(t.id),onDrop:F(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:()=>w(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:()=>w(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 P(k),disabled:j,style:{display:"flex",alignItems:"center",gap:6,padding:"5px 12px",border:"none",borderRadius:6,background:"#dc2626",color:"#fff",cursor:j?"default":"pointer",fontSize:12,opacity:j?.7:1},children:[j&&(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(j?"boards.deleting":"boards.delete")]})]})]})})]})}function A({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:b,onOpenBoard:y}){let{t:k}=(0,v.s)(),[w,j]=(0,i.useState)(!1),S=(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"})]}),C={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:m,onDrop:b,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:y,"data-board-row":e.id,title:e.name,onMouseEnter:()=>j(!0),onMouseLeave:()=>j(!1),style:{display:"flex",alignItems:"center",gap:4,minHeight:38,padding:"0 8px 0 5px",borderRadius:6,background:t?"var(--side-active)":w?"var(--side-hover)":"transparent",cursor:s?"default":"pointer",transition:"background 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:S}),(0,r.jsx)("input",{ref:d,value:l,onChange:e=>c(e.target.value),onKeyDown:e=>{"Enter"===e.key&&p(),"Escape"===e.key&&h()},onBlur:p,autoFocus:!0,placeholder:k("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:S}),(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}),w&&(0,r.jsxs)("span",{style:{position:"relative",display:"flex",gap:3,flexShrink:0,alignItems:"center"},children:[(0,r.jsx)("button",{type:"button",title:k("boards.rename"),"aria-label":k("boards.rename"),onClick:e=>{e.stopPropagation(),u()},style:C,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:k("boards.delete"),"aria-label":k("boards.delete"),onClick:e=>{e.stopPropagation(),g()},style:C,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 F="text/session-id",N=(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"})}),H=(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"})]}),O=(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"})}),U=(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.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"})]}),V="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:k,onOpenBoard:j,onDragStartTask:S,onDragOverTask:C,onDropTask:T,onDragEndTask:M,isDragging:R,dropBefore:I,dropAfter:L}){let{t:z}=(0,v.s)(),[E,W]=(0,i.useState)(!0),P=null!=p&&e.sessionIds.includes(p);(0,i.useEffect)(()=>{P&&W(!1)},[P]);let[$,D]=(0,i.useState)(!1),[B,A]=(0,i.useState)(!1),[J,K]=(0,i.useState)(!1),[Y,G]=(0,i.useState)(""),[X,Z]=(0,i.useState)(!1),[Q,ee]=(0,i.useState)(!1),[et,en]=(0,i.useState)(!1),[er,ei]=(0,i.useState)(!1),eo=(0,i.useRef)(null),ea=(0,i.useRef)(null),es=(0,i.useRef)(null);(0,i.useEffect)(()=>{if(!et&&!X)return;let e=e=>{let t=e.target;ea.current?.contains(t)||es.current?.contains(t)||(en(!1),Z(!1))},t=e=>{"Escape"===e.key&&(en(!1),Z(!1))};return document.addEventListener("pointerdown",e,!0),document.addEventListener("keydown",t),()=>{document.removeEventListener("pointerdown",e,!0),document.removeEventListener("keydown",t)}},[et,X]);let el=(0,i.useCallback)(e=>{if(e.stopPropagation(),et)return void en(!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;ei(!(o>=114)&&(a>=114||a>o)),en(!0)},[et]);(0,i.useEffect)(()=>{if(J){let e=requestAnimationFrame(()=>eo.current?.select());return()=>cancelAnimationFrame(e)}},[J]);let ed=(0,i.useCallback)(()=>{let t=Y.trim();t&&x(e.id,t),K(!1)},[Y,x,e.id]),ec=(0,i.useCallback)(t=>{if(t.dataTransfer.types.includes(V)){let n=t.currentTarget.getBoundingClientRect(),r=t.clientY<n.top+n.height/2,i=C(e.id,r);D(!1),i&&(t.preventDefault(),t.dataTransfer.dropEffect="move");return}t.dataTransfer.types.includes(F)&&(t.preventDefault(),t.dataTransfer.dropEffect="move",D(!0))},[C,e.id]),eu=(0,i.useCallback)(t=>{t.preventDefault(),D(!1);let n=t.dataTransfer.getData(F);n?g(e.id,n):t.dataTransfer.types.includes(V)&&T(e.id)},[g,e.id,T]),ep=(0,i.useCallback)(t=>{t.target.closest("button, input, textarea, a, [role=menuitem]")?t.preventDefault():(t.dataTransfer.setData(V,e.id),t.dataTransfer.effectAllowed="move",S(e))},[e,S]),eh={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:ec,onDragLeave:()=>D(!1),onDrop:eu,style:{position:"relative",margin:"0 4px 2px",borderRadius:6,background:$?"color-mix(in srgb, var(--accent) 8%, transparent)":"transparent",border:"none",boxShadow:$?"inset 2px 0 0 var(--accent)":"none",borderTop:I?"2px solid var(--accent)":"none",borderBottom:L?"2px solid var(--accent)":"none",opacity:R?.4:1,transition:"background 0.12s, box-shadow 0.12s"},children:[(0,r.jsx)("div",{draggable:!0,onDragStart:ep,onDragEnd:M,onClick:()=>{e.sessionIds.length>0&&W(e=>!e)},onMouseEnter:()=>A(!0),onMouseLeave:()=>A(!1),style:{display:"flex",alignItems:"center",gap:4,minHeight:38,padding:"0 8px 0 5px",borderRadius:6,background:h?"var(--side-active)":B?"var(--side-hover)":"transparent",cursor:"pointer",transition:"background 0.12s"},children:J?(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)(w.sj,{size:13,open:!E})}),(0,r.jsx)("input",{ref:eo,value:Y,onChange:e=>G(e.target.value),onKeyDown:e=>{"Enter"===e.key&&ed(),"Escape"===e.key&&K(!1)},onBlur:ed,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)(w.sj,{size:13,open:!E})}),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&&!J&&!X&&(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"})]})}),(B||et||X)&&!J&&(0,r.jsxs)("span",{ref:ea,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(),j(e.id)},style:{...eh,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:U}),(0,r.jsx)("button",{type:"button",title:z("sidebar.newTaskSession"),onClick:t=>{t.stopPropagation(),m(e.id)},style:{...eh,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:O}),(0,r.jsx)("button",{type:"button",title:z("sidebar.rename"),onClick:t=>{t.stopPropagation(),G(e.name),K(!0),en(!1)},style:{...eh,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:N}),(0,r.jsx)("button",{type:"button",title:z("sidebar.moreActions"),"aria-expanded":et,"aria-haspopup":"menu",onClick:el,style:{...eh,width:28,height:28,background:et?"var(--side-active)":"transparent",color:et?"var(--accent)":"var(--text-muted)"},onMouseEnter:e=>{et||(e.currentTarget.style.background="var(--side-active)",e.currentTarget.style.color="var(--accent)")},onMouseLeave:e=>{et||(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)(b.f,{open:et,up:er,style:{position:"absolute",top:er?"auto":"calc(100% + 4px)",bottom:er?"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(),en(!1),k(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:_}),z(e.pinned?"sidebar.unpinTask":"sidebar.pinTask")]}),(0,r.jsxs)("button",{role:"menuitem",onClick:t=>{t.stopPropagation(),en(!1),G(e.name),K(!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:N}),z("sidebar.rename")]}),(0,r.jsxs)("button",{role:"menuitem",onClick:e=>{e.stopPropagation(),en(!1),ee(!!ea.current&&y(ea.current,96)),Z(!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:H}),z("sidebar.deleteTask")]})]})}),X&&(0,r.jsxs)("div",{ref:es,role:"alertdialog",style:{position:"absolute",...Q?{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),Z(!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(),Z(!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")})]})]})]})]})}),!E&&(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 J({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,v.s)(),[m,b]=(0,i.useState)(""),[y,k]=(0,i.useState)(!1),[j,S]=(0,i.useState)(!1),C=(0,i.useRef)(null),[T,M]=(0,i.useState)(null),[R,I]=(0,i.useState)(null),[L,z]=(0,i.useState)(null);(0,i.useEffect)(()=>{a&&C.current?.focus()},[a]);let E=(0,i.useCallback)(()=>{let e=m.trim();e&&(l(e),b(""),s(!1))},[m,l,s]),W=(0,i.useCallback)(e=>{I({id:e.id,pinned:!!e.pinned}),z(null)},[]),P=(0,i.useCallback)(()=>{I(null),z(null)},[]),$=(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&&(z({targetId:t,before:n}),!0)},[R,e]),D=(0,i.useCallback)(t=>{if(!R||!L||L.targetId!==t)return void P();let n=e.map(e=>e.task.id),r=n.indexOf(R.id),i=n.indexOf(t);if(-1===r||-1===i)return void P();let o=[...n];o.splice(r,1);let a=o.indexOf(t)+ +!L.before;o.splice(a,0,R.id),P(),x(o)},[R,e,P,x,L]);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)(w.sj,{size:13,open:!1})}),(0,r.jsx)("input",{ref:C,value:m,onChange:e=>b(e.target.value),onKeyDown:e=>{"Enter"===e.key&&E(),"Escape"===e.key&&(s(!1),b(""))},onBlur:()=>{let e=m.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:!m.trim(),onMouseDown:e=>e.preventDefault(),onClick:E,onMouseEnter:()=>k(!0),onMouseLeave:()=>k(!1),style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,background:y&&m.trim()?"var(--side-hover)":"transparent",border:"none",borderRadius:5,color:m.trim()?"var(--accent)":"var(--text-dim)",cursor:m.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:()=>S(!0),onMouseLeave:()=>S(!1),style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,background:j?"var(--side-hover)":"transparent",border:"none",borderRadius:5,color:j?"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()=>{M(a.id);try{await b()}finally{M(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:T===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:W,onDragOverTask:$,onDropTask:D,onDragEndTask:P,isDragging:R?.id===a.id,dropBefore:L?.targetId===a.id&&L.before,dropAfter:L?.targetId===a.id&&!L.before})]},a.id)})]})}function K({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 Y="pi-web:unread-session-ids";function G(e,t){return t&&e.startsWith(t)?"~"+e.slice(t.length):e}function X({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 Z(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 Q="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";function ee(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 et(){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:Q[Math.floor(Math.random()*Q.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.49p0.84.3":"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 en({selectedSessionId:e,onSelectSession:t,onNewSession:n,initialSessionId:o,skipInitialProjectSelection:a,onInitialRestoreDone:s,refreshKey:l,onSessionDeleted:d,selectedCwd:u,onCwdChange:p,onOpenFile:h,explorerRefreshKey:g,onExplorerRefresh:x,onRefresh:y,onSessionsLoaded:w,onAtMention:j,onAtMentions:S,onBackgroundTaskDone:C,onRunningSessionIdsChange:T,onNewSessionFromTask:M,onOpenBoard:R,onOpenTaskBoard:I,onExitBoard:L,activeBoardId:z,activeWorktreeProject:E}){let{t:W}=(0,v.s)(),[P,A]=(0,i.useState)([]),[F,N]=(0,i.useState)([]),[H,O]=(0,i.useState)(!1),U=(0,i.useRef)(null),[_,V]=(0,i.useState)(!0),[q,Q]=(0,i.useState)(null),[ei,eo]=(0,i.useState)(null),[ea,eh]=(0,i.useState)(""),[eg,ex]=(0,i.useState)(!1),[ef,em]=(0,i.useState)(!1),[ev,eb]=(0,i.useState)(""),[ey,ek]=(0,i.useState)(!1),[ew,ej]=(0,i.useState)(""),[eS,eC]=(0,i.useState)(null),[eT,eM]=(0,i.useState)(!1),[eR,eI]=(0,i.useState)(null),[eL,ez]=(0,i.useState)(null),eE=E??eL,eW=(0,i.useRef)(null),[eP,e$]=(0,i.useState)("sessions"),[eD,eB]=(0,i.useState)(!1),[eA,eF]=(0,i.useState)(!1),[eN,eH]=(0,i.useState)(!1),[eO,eU]=(0,i.useState)(!1),[e_,eV]=(0,i.useState)([]),[eq,eJ]=(0,i.useState)(!1),[eK,eY]=(0,i.useState)(0),[eG,eX]=(0,i.useState)(!1),[eZ,eQ]=(0,i.useState)(0),[e0,e1]=(0,i.useState)(!0),[e2,e4]=(0,i.useState)(!1),[e8,e5]=(0,i.useState)(!1),[e6,e3]=(0,i.useState)(()=>new Set),[e7,e9]=(0,i.useState)(()=>new Set),te=(0,i.useRef)(new Set);(0,i.useEffect)(()=>{e$(function(){try{return"files"===window.localStorage.getItem(es)?"files":"sessions"}catch{return"sessions"}}()),eB(eu(el)),eF(eu(ed)),eH(eu(ec)),e9(function(){try{let e=window.localStorage.getItem(Y);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 tt=(0,i.useRef)(!1),tn=(0,i.useRef)(null),tr=(0,i.useRef)(null),ti=(0,i.useRef)(null),to=(0,i.useRef)(null),ta=(0,i.useCallback)(async()=>{let e=U.current;if(!e)return;let t=to.current;if(t&&t.key===e)return t.promise;let n=(async()=>{O(!0);try{let t=await fetch(`/api/sessions?project=${encodeURIComponent(e)}`,{cache:"no-store"});if(!t.ok)return;let n=await t.json();U.current===e&&(N(n.sessions??[]),tt.current||e3(new Set(n.runningSessionIds??[])))}catch{}finally{O(!1)}})();to.current={key:e,promise:n};try{await n}finally{to.current?.key===e&&(to.current=null)}},[]),ts=(0,i.useCallback)(async(e=!1)=>{try{e&&V(!0),await ta();let t=await fetch("/api/sessions",{cache:"no-store"});if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();A(n.sessions),w?.(n.sessions),tt.current||e3(new Set(n.runningSessionIds??[]));let r=new Set(n.sessions.map(e=>e.id));e9(e=>{if(0===e.size)return e;let t=new Set([...e].filter(e=>r.has(e)));return t.size===e.size?e:t}),Q(null),e||(e4(!0),tn.current&&clearTimeout(tn.current),tn.current=setTimeout(()=>e4(!1),2e3))}catch(e){Q(String(e))}finally{e&&V(!1)}},[w,ta]);(0,i.useEffect)(()=>{try{0===e7.size?window.localStorage.removeItem(Y):window.localStorage.setItem(Y,JSON.stringify([...e7]))}catch{}},[e7]),(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;tt.current=!0,e3(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)(()=>{T?.(e6)},[T,e6]),(0,i.useEffect)(()=>{let t=te.current,n=[...t].filter(t=>!e6.has(t)&&t!==e),r=[...e6].filter(e=>!t.has(e));(n.length>0||r.length>0)&&e9(e=>{let t=new Set(e);return e6.forEach(e=>t.delete(e)),n.forEach(e=>t.add(e)),t});let i=r.some(e=>!P.some(t=>t.id===e));(n.length>0||i)&&ts(!1),n.length>0&&C?.(n),te.current=e6},[e6,e,P,ts,C]),(0,i.useEffect)(()=>{e&&e9(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[e]),(0,i.useEffect)(()=>{void 0!==g&&eY(e=>e+1)},[g]),(0,i.useEffect)(()=>{fetch("/api/home").then(e=>e.json()).then(e=>{e.home&&eh(e.home)}).catch(()=>{})},[]);let tl=(0,i.useRef)(!1),td=(0,i.useCallback)((e,t)=>({root:e,key:t}),[]),tc=(0,i.useCallback)(e=>{if(!e)return null;if(eR?.cwd===e)return td(eR.root,eR.key);if(eE&&(e===eE.projectRoot||eE.worktreePaths.includes(e)))return td(eE.projectRoot,eE.projectKey);let t=P.find(t=>t.cwd===e||(t.projectRoot??t.cwd)===e);return t?td(t.projectRoot??t.cwd,f(t)):td(e,e)},[eR,eE,P,td]),tu=(0,i.useRef)(null);(0,i.useEffect)(()=>{let e=tc(ei),t=tu.current;(t?.cwd!==ei||t.key!==(e?.key??null))&&(tu.current={cwd:ei,key:e?.key??null},p?.(ei,e?.root??null,e?.key??null))},[ei,p,tc]);let tp=(0,i.useRef)(null);(0,i.useEffect)(()=>{u&&u!==tp.current&&(tp.current=u,eo(u))},[u]),(0,i.useEffect)(()=>{if(0!==P.length&&!a&&null===ei){if(o&&!tl.current){tl.current=!0;let e=P.find(e=>e.id===o);if(e){eo(e.cwd),t(e,!0);return}s?.()}let e=m(P);e.length>0&&eo(e[0].root)}},[P,ei,o,a,t,s]);let th=(0,i.useCallback)(async e=>{let t=(e??ew).trim();if(t&&!eT){eM(!0),eC(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 eC(n.error??`HTTP ${e.status}`);eI({cwd:n.cwd,root:n.projectRoot,key:n.projectKey}),eo(n.cwd),ek(!1),ej(""),ex(!1)}catch(e){eC(e instanceof Error?e.message:String(e))}finally{eM(!1)}}},[ew,eT]),tg=(0,i.useCallback)(()=>{ek(!0),eC(null),ex(!1)},[]),tx=(0,i.useCallback)(async()=>{try{let e=await fetch("/api/default-cwd",{method:"POST"}),t=await e.json();t.cwd&&(eo(t.cwd),ek(!1),ej(""),eC(null),ex(!1))}catch{}},[]);(0,i.useEffect)(()=>{let e=e=>{eW.current&&!eW.current.contains(e.target)&&(ex(!1),eb(""))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let tf=(0,i.useCallback)(e=>{e.cwd&&eo(e.cwd),t(e)},[t]),tm=(0,i.useCallback)(()=>{if(!ei)return;let e="function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}-${Math.random().toString(36).slice(2)}`;n?.(e,ei)},[ei,n]),tv=m(P),tb=tv.length>8,ty=ev.trim()?tv.filter(e=>e.root.toLowerCase().includes(ev.trim().toLowerCase())):tv,tk=tc(ei);U.current=tk?.key??null;let tw=(0,i.useRef)(null);(0,i.useEffect)(()=>{let e=tk?.key??null;tw.current===e||(tw.current=e,e&&ta())},[tk?.key,ta]);let tj=(0,i.useMemo)(()=>(function(e,t,n){let r=new Map;for(let i of e){let e=f(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})(P,e6,e7),[P,e6,e7]),tS=(0,i.useMemo)(()=>[...tj.entries()].some(([e,{running:t,unread:n}])=>e!==tk?.key&&(t>0||n>0)),[tj,tk]),tC=(0,i.useRef)(0),tT=(0,i.useCallback)(()=>{let e=tk?.key,t=++tC.current;e?fetch(`/api/tasks?projectKey=${encodeURIComponent(e)}`,{cache:"no-store"}).then(e=>e.ok?e.json():null).then(e=>{t===tC.current&&eV(t=>ee(t,Array.isArray(e?.tasks)?e.tasks:[]))}).catch(()=>{}):eV([])},[tk?.key]);(0,i.useEffect)(()=>{tT()},[tT]);let tM=(0,i.useRef)(!1),tR=(0,i.useRef)(null),tI=(0,i.useRef)(!1);(0,i.useEffect)(()=>{let e=!tM.current;if(tM.current=!0,e)return void ts(!0);if(tI.current){tI.current=!1,ts(!1),tT();return}return tR.current&&clearTimeout(tR.current),tR.current=setTimeout(()=>{tR.current=null,ts(!1),tT()},300),()=>{tR.current&&clearTimeout(tR.current)}},[ts,tT,l]);let tL=(0,i.useCallback)(async()=>{let e=tk?.key;if(!e)return;let t=await fetch(`/api/tasks?projectKey=${encodeURIComponent(e)}`,{cache:"no-store"}),n=await t.json().catch(()=>({}));eV(e=>ee(e,Array.isArray(n.tasks)?n.tasks:[]))},[tk?.key]),tz=(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;eV(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{}},[]),tE=(0,i.useCallback)((e,t)=>{A(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;N(e=>e.map(n)),eV(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(()=>{tL(),ta()})},[tL,ta]),tW=(0,i.useCallback)(e=>{let t=e_.find(t=>t.id===e);if(!t)return;let n=!t.pinned;eV(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(()=>tL())},[e_,tL]),tP=(0,i.useCallback)(e=>{let t=tk?.key;if(!t)return;let n=new Map(e_.map(e=>[e.id,e])),r=[],i=[];for(let t of e){let e=n.get(t);e&&(e.pinned?r:i).push(t)}eV(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(()=>{})},[e_,tk?.key]),t$=(0,i.useCallback)((e,t)=>{let n=n=>n.id===e?{...n,name:t}:n;A(e=>e.map(n)),N(e=>e.map(n)),eV(e=>e.map(e=>({...e,sessions:(e.sessions??[]).map(n)})))},[]);(0,i.useEffect)(()=>{let e=e=>{let t=e.detail;t?.sessionId&&t?.name&&t$(t.sessionId,t.name)};return window.addEventListener("pi-web:board-session-renamed",e),()=>window.removeEventListener("pi-web:board-session-renamed",e)},[t$]),(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 tD=(0,i.useCallback)(async e=>{let t=tk?.key;t&&(await fetch("/api/tasks",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({projectKey:t,name:e})}),await tL())},[tk?.key,tL]),tB=(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 tL()},[tL]),tA=(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 tL()},[tL,d]),tF=(0,i.useCallback)(async(e,t)=>{let n=e_.find(t=>t.id===e);!n||n.sessionIds.includes(t)||(await fetch(`/api/tasks/${encodeURIComponent(e)}/assign-session`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:t})}),await tL())},[e_,tL]),tN=(0,i.useCallback)(async e=>{let t=e_.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 tL())},[e_,tL]);function tH(e){let t=(e,t)=>e.session.modified<t.session.modified?1:e.session.modified>t.session.modified?-1:0;return[...e.filter(e=>e.session.pinned).sort(t),...e.filter(e=>!e.session.pinned).sort(t)]}let tO=e=>e.reduce((e,t)=>e+1+tO(t.children),0),tU=(0,i.useMemo)(()=>e_.map(e=>{let t=tH(Z(e.sessions??[])),n=e.sessionTotal??tO(t);return{task:e,nodes:t,sessionTotal:n}}),[e_]),t_=(0,i.useMemo)(()=>tH(Z([...F.filter(e=>e6.has(e.id)),...F.filter(e=>!e6.has(e.id))])),[F,e6]);return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[ey&&(0,r.jsx)(k.K,{busy:eT,error:eS,onCancel:()=>{ek(!1),eC(null)},onSelect:e=>void th(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)(et,{}),(0,r.jsxs)("div",{style:{display:"flex",gap:2,alignItems:"center"},children:[(0,r.jsxs)("button",{onClick:tm,disabled:!ei,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,background:"transparent",border:"none",color:ei?"var(--text-muted)":"var(--text-dim)",cursor:ei?"pointer":"not-allowed",padding:"3px 6px",borderRadius:4,fontSize:12,fontWeight:500,letterSpacing:"-0.01em",flexShrink:0,textDecoration:"none",transition:"color 0.12s"},title:ei?W("sidebar.newSessionTitle",{path:ei}):W("sidebar.selectProject"),onMouseEnter:e=>{ei&&(e.currentTarget.style.color="var(--accent)",e.currentTarget.style.textDecoration="underline")},onMouseLeave:e=>{e.currentTarget.style.color=ei?"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"})}),W("sidebar.tempSessions")]}),(0,r.jsxs)("button",{onClick:()=>{y?(tI.current=!0,y()):(ts(!1),tT())},style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,background:e2?"rgba(74,222,128,0.12)":"transparent",border:"none",color:e2?"#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=>{e2||(e.currentTarget.style.color="var(--accent)",e.currentTarget.style.textDecoration="underline")},onMouseLeave:e=>{e2||(e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.textDecoration="none")},title:W("sidebar.refresh"),children:[e2?(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"})]}),W("sidebar.refresh")]})]})]}),(0,r.jsxs)("div",{ref:eW,style:{position:"relative",display:"flex",alignItems:"center",borderRadius:7,background:eg?"var(--side-active)":ef?"var(--side-hover)":ei?"color-mix(in srgb, var(--glass-bg-strong) 55%, transparent)":"color-mix(in srgb, var(--accent) 8%, transparent)",border:ei?"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:()=>em(!0),onMouseLeave:()=>em(!1),children:[(0,r.jsxs)("button",{onClick:()=>ex(e=>!e),title:tk?.root??ei??"",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:[ei?(0,r.jsx)(X,{text:G(tk?.root??ei,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&&!tl.current?"":W("sidebar.selectProject")}),tS&&(0,r.jsx)("span",{title:W("sidebar.newActivity"),"aria-label":W("sidebar.newActivity"),style:{width:8,height:8,borderRadius:"50%",flexShrink:0,marginLeft:6,background:"var(--accent)"}})]}),ei&&(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:ei,onSelect:(e,t)=>{t&&ez(t),eo(e),ex(!1)},onOpenChange:e=>{e&&ex(!1)},showMainLabel:!1,compact:!0,style:{height:"auto",background:"transparent",flexShrink:0,borderRadius:0,maxWidth:85}})]}),(0,r.jsxs)(b.f,{open:eg,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:[tb&&(0,r.jsx)("div",{style:{padding:"6px 8px",borderBottom:"1px solid var(--border)"},children:(0,r.jsx)("input",{value:ev,onChange:e=>eb(e.target.value),onKeyDown:e=>{"Escape"===e.key&&(eb(""),ex(!1))},placeholder:W("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:[ty.map(e=>{var t,n;return(0,r.jsxs)("button",{onClick:()=>{eo(e.root),eb(""),ek(!1),ej(""),eC(null),ex(!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===tk?.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===tk?.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!==tk?.key&&(0,r.jsx)("span",{style:{width:10,flexShrink:0}}),(0,r.jsx)(X,{text:G(e.root,ea),style:{flex:1}}),(t=tj.get(e.key),n=W,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===ty.length&&ev.trim()&&(0,r.jsx)("div",{style:{padding:"8px 10px",fontSize:11,color:"var(--text-dim)"},children:W("sidebar.noMatchingProjects")})]}),!ey&&(0,r.jsxs)("button",{onClick:e=>{e.stopPropagation(),tx()},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",borderTop:ty.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:W("sidebar.useDefaultDirectory")})]}),(0,r.jsxs)("button",{onClick:e=>{e.stopPropagation(),tg()},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:W("sidebar.customPath")})]})]})]})]}),(0,r.jsx)(D,{active:eP,runningCount:e6.size,onChange:e=>{e$(e),function(e){try{window.localStorage.setItem(es,e)}catch{}}(e)}}),(0,r.jsx)("div",{style:{flex:1,minHeight:0,display:"sessions"===eP?"flex":"none",flexDirection:"column",overflowY:"auto",overflowX:"hidden"},children:_?(0,r.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:W("sidebar.loading")}):q?(0,r.jsx)("div",{style:{padding:"12px 14px",color:"#f87171",fontSize:12},children:q}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(B,{activeBoardId:z??null,collapsed:eD,refreshKey:l,onToggleCollapsed:()=>{let e=!eD;eB(e),ep(el,e)},onOpenBoard:e=>R?.(e),onExitBoard:L}),(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=!eA;eF(e),ep(ed,e)},"aria-expanded":!eA,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:W("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:eA?"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:()=>eU(e=>!e),title:W("sidebar.newTask"),"aria-label":W("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"})]})})]}),!eA&&(0,r.jsx)("div",{style:{overflowX:"hidden"},children:(0,r.jsx)(J,{groups:tU.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:()=>tz(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)(er,{node:t,selectedSessionId:e,runningSessionIds:e6,unreadSessionIds:e7,onSelectSession:tf,onRenamed:(e,t)=>t$(e,t),onSessionDeleted:e=>{d?.(e)},onTogglePin:tE,depth:0},t.session.id))}),(0,r.jsx)("div",{style:{paddingLeft:14,paddingBottom:2},children:o})}}}),selectedSessionId:e,activeBoardId:z,runningSessionIds:e6,newTaskOpen:eO,onNewTaskOpenChange:eU,onNewTask:e=>void tD(e),onRenameTask:(e,t)=>void tB(e,t),onDeleteTask:e=>void tA(e),onNewSessionFromTask:e=>M?.(e,tk?.key??void 0),onToggleTaskPin:tW,onOpenTaskBoard:e=>I?.(e),onDropSessionToTask:(e,t)=>void tF(e,t),onReorderTasks:tP})})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",minHeight:0,flex:eN?"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=!eN;eH(e),ep(ec,e)},"aria-expanded":!eN,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:W("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:eN?"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"})})]})}),!eN&&(0,r.jsxs)("div",{onDragOver:e=>{e.dataTransfer.types.includes("text/session-id")&&(e.preventDefault(),e.dataTransfer.dropEffect="move",eJ(!0))},onDragLeave:()=>eJ(!1),onDrop:e=>{e.preventDefault(),eJ(!1);let t=e.dataTransfer.getData("text/session-id");t&&tN(t)},style:{flex:1,minHeight:0,overflowY:"auto",overflowX:"hidden",background:eq?"color-mix(in srgb, var(--accent) 8%, transparent)":"transparent"},children:[t_.map((t,n)=>{let i=!!t.session.pinned,o=n>0&&!!t_[n-1].session.pinned;return(0,r.jsxs)("div",{children:[o&&!i&&(0,r.jsx)("div",{style:{margin:"2px 6px 4px",height:1,background:"color-mix(in srgb, var(--border) 45%, transparent)"}}),(0,r.jsx)(er,{node:t,selectedSessionId:e,runningSessionIds:e6,unreadSessionIds:e7,onSelectSession:tf,onRenamed:(e,t)=>t$(e,t),onSessionDeleted:e=>{d?.(e)},onTogglePin:tE,depth:0})]},t.session.id)}),0===t_.length&&0===tU.length&&(0,r.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:W("sidebar.noSessions")}),t_.length>0&&(0,r.jsx)(r.Fragment,{children:H&&(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:W("sidebar.loading")})]})})]})]})]})}),(0,r.jsx)("div",{style:{flex:1,display:"files"===eP?"flex":"none",flexDirection:"column",minHeight:0,overflow:"hidden"},children:(u||ei)&&(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)($,{ref:ti,cwd:ei??u,onOpenFile:h??(()=>{}),refreshKey:eK,onAtMention:j,onAtMentions:S,onUploadBusyChange:eX,changesCollapsed:e0,onChangesCountChange:eQ,toolbar:(0,r.jsxs)(r.Fragment,{children:[eZ>0&&(0,r.jsx)(K,{onClick:()=>e1(e=>!e),title:W("sidebar.changedFiles",{count:eZ}),ariaPressed:!e0,color:e0?"var(--text-dim)":"var(--accent)",background:e0?"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)(K,{onClick:()=>ti.current?.openUploadPicker(),disabled:eG,title:W("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)(K,{onClick:()=>{x?x():eY(e=>e+1),e5(!0),tr.current&&clearTimeout(tr.current),tr.current=setTimeout(()=>e5(!1),2e3)},title:W("sidebar.refreshExplorer"),skipHover:e8,color:e8?"#4ade80":"var(--text-dim)",background:e8?"rgba(74,222,128,0.18)":"none",marginRight:0,children:e8?(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"})]})})]})})})})})]})}function er({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)(ea,{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)(er,{node:e,selectedSessionId:t,runningSessionIds:n,unreadSessionIds:o,onSelectSession:a,onRenamed:s,onSessionDeleted:l,onTogglePin:d,depth:c+1},e.session.id))})]})}function ei(){let{t:e}=(0,v.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 eo(){let{t:e}=(0,v.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 ea({session:e,isSelected:t,isRunning:n,isUnread:o,onClick:a,onRenamed:s,onDeleted:l,onTogglePin:d,depth:c=0,hasChildren:p=!1,collapsed:h=!1,onToggleCollapse:g}){let{t:x}=(0,v.s)(),[f,m]=(0,i.useState)(!1),[k,w]=(0,i.useState)(!1),[j,S]=(0,i.useState)(""),[C,T]=(0,i.useState)(!1),[M,R]=(0,i.useState)(!1),[I,L]=(0,i.useState)(!1),[z,E]=(0,i.useState)(!1),[W,P]=(0,i.useState)(!1),$=(0,i.useRef)(null),D=(0,i.useRef)(null);(0,i.useEffect)(()=>{if(!z&&!C)return;let e=e=>{D.current&&!D.current.contains(e.target)&&(E(!1),T(!1))},t=e=>{"Escape"===e.key&&(E(!1),T(!1))};return document.addEventListener("pointerdown",e,!0),document.addEventListener("keydown",t),()=>{document.removeEventListener("pointerdown",e,!0),document.removeEventListener("keydown",t)}},[z,C]);let B=(0,i.useCallback)(e=>{if(e.stopPropagation(),z)return void E(!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;P(!(o>=114)&&(a>=114||a>o)),E(!0)},[z]);(0,i.useEffect)(()=>{if(k){let e=requestAnimationFrame(()=>$.current?.select());return()=>cancelAnimationFrame(e)}},[k]);let A=(0,u.d)(e.firstMessage),F=A?.command??e.firstMessage,N=e.name||F.slice(0,50)||e.id.slice(0,12),H=(0,i.useCallback)(t=>{t.stopPropagation(),e.transient||(E(!1),S(e.name||F.slice(0,50)||e.id.slice(0,12)),w(!0))},[e.name,e.transient,F,e.id]),O=(0,i.useCallback)(async()=>{let t=j.trim();if(w(!1),j!==N&&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{}},[j,e.id,e.name,s,N]),U=(0,i.useCallback)(async()=>{if(!e.transient){T(!1),L(!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{L(!1)}}},[e.id,e.transient,l]),_=(0,i.useCallback)(e=>{e.stopPropagation(),E(!1),R(!!D.current&&y(D.current,96)),T(!0)},[]),V=(0,i.useCallback)(e=>{e.stopPropagation(),U()},[U]),q=(0,i.useCallback)(e=>{e.stopPropagation(),T(!1)},[]),J=(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:C||k?void 0:a,onContextMenu:C||k?void 0:J,onMouseEnter:()=>m(!0),onMouseLeave:()=>{m(!1)},draggable:!k&&!C,onDragStart:t=>{E(!1),t.dataTransfer.setData("text/session-id",e.id),t.dataTransfer.setData("text/session-title",N),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:C||k?"default":"pointer",background:C?"color-mix(in srgb, #ef4444 7%, transparent)":t?"color-mix(in srgb, var(--accent) 8%, transparent)":f?"var(--side-hover)":"transparent",borderLeft:"2px solid transparent",transition:"background 0.1s",opacity:I?.5:1,gap:6},children:k?(0,r.jsx)("input",{ref:$,value:j,onChange:e=>S(e.target.value),onBlur:O,onKeyDown:e=>{"Enter"===e.key&&O(),"Escape"===e.key&&w(!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)(ei,{}):o?(0,r.jsx)(eo,{}):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:N,style:{flex:1,minWidth:0,fontSize:12,fontWeight:t?500:400,lineHeight:1.4,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:N})]}),f&&p&&!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"})})}),(f||z||C)&&!e.transient&&(0,r.jsxs)("div",{ref:D,style:{position:"relative",display:"flex",gap:4,flexShrink:0,alignItems:"center"},children:[(0,r.jsx)("button",{onClick:H,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:B,"aria-expanded":z,"aria-haspopup":"menu",title:x("sidebar.moreActions"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:z?"var(--side-active)":"transparent",border:"1px solid transparent",borderRadius:7,color:z?"var(--accent)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{z||(e.currentTarget.style.background="var(--side-active)",e.currentTarget.style.color="var(--accent)")},onMouseLeave:e=>{z||(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)(b.f,{open:z,up:W,style:{position:"absolute",top:W?"auto":"calc(100% + 4px)",bottom:W?"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(),E(!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(),E(!1),H(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(),E(!1),_(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")]})]})}),C&&(0,r.jsxs)("div",{role:"alertdialog",style:{position:"absolute",...M?{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:N.slice(0,30)+(N.length>30?"…":"")})}),(0,r.jsxs)("div",{style:{display:"flex",gap:6,justifyContent:"flex-end"},children:[(0,r.jsx)("button",{onClick:V,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:q,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 es="pi-sidebar-tab",el="pi-sidebar-boards-collapsed",ed="pi-sidebar-tasks-collapsed",ec="pi-sidebar-chat-collapsed";function eu(e){try{return"1"===window.localStorage.getItem(e)}catch{return!1}}function ep(e,t){try{t?window.localStorage.setItem(e,"1"):window.localStorage.removeItem(e)}catch{}}var eh=n(71594),eg=n(84876),ex=n(50640),ef=n(65063),em=n(7644),ev=n(32316),eb=n(96793);let ey={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"},ek={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",webm:"audio/webm"};function ew(e){return(e.replace(/\\/g,"/").split("/").pop()??"").toLowerCase().split(".").pop()??""}var ej=n(19870),eS=n(73620);let eC=/^(?:\uFEFF)?---[ \t]*(?:\r\n|\n|\r)/;function eT(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 eM=n(68925),eR=n(40233);let eI=["tags","categories","keywords","tag","category"];function eL({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=eI.find(t=>Array.isArray(e[t])),a=o?e[o].map(eT).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=eT(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 ez=n(82490);let eE={source:"Source",preview:"Preview",diff:"Diff"},eW={fontFamily:"var(--font-mono)",fontSize:13,lineHeight:1.6},eP={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 e$(){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 eD(e){let t=e.nodeType===Node.ELEMENT_NODE?e:e.parentElement;return t?.closest(".file-source-line[data-line-number]")??null}function eB(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=eD(n.startContainer),i=eD(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 eA({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,ex.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,ex.Ay)({node:e,stylesheet:t,useInlineStyles:n,key:`source-token-${o}-${r}`}))})]},`source-line-${o}`)})}function eF(e,t,n,r={}){let i=(0,j.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 eN({filePath:e,sourceSessionId:t}){let{t:n}=(0,v.s)();return(0,r.jsx)("a",{href:eF(e,"download",t),download:(0,j.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 eH(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function eO({patch:e}){let t,{t:n}=(0,v.s)(),i=(t=(0,ez.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%",...eW},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:eP,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 eU({filePath:e,cwd:t,sourceSessionId:n,watchEnabled:o=!0}){let{t:a}=(0,v.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),b=(0,i.useRef)(0),y=(0,j.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(eF(e,"watch",n));m.current=r,r.addEventListener("connected",()=>{let r;l(!0),r=++b.current,fetch(eF(e,"meta",n)).then(e=>e.json()).then(e=>{if(t&&r===b.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===b.current&&f(String(e))})}),r.addEventListener("change",e=>{b.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 k=eF(e,"read",n,d?{v:d}:void 0),w=null!=u?eH(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,j.qP)(e,t)}),(0,r.jsx)("span",{style:{marginLeft:"auto"},children:y||"image"}),h&&(0,r.jsxs)("span",{children:[h.w," \xd7 ",h.h]}),w&&(0,r.jsx)("span",{children:w}),(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)(eN,{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:k,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 e_({filePath:e,cwd:t,sourceSessionId:n,watchEnabled:o=!0}){let{t:a}=(0,v.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),b=(0,i.useRef)(0),y=(0,j.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(eF(e,"watch",n));m.current=r,r.addEventListener("connected",()=>{let r;l(!0),r=++b.current,fetch(eF(e,"meta",n)).then(e=>e.json()).then(e=>{if(t&&r===b.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===b.current&&f(String(e))})}),r.addEventListener("change",e=>{b.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 k=eF(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,j.qP)(e,t)}),(0,r.jsx)("span",{style:{marginLeft:"auto"},children:y||"audio"}),null!=h&&(0,r.jsx)("span",{children:function(e){if(!Number.isFinite(e))return"";let t=Math.round(e),n=Math.floor(t/60);return`${n}:${String(t%60).padStart(2,"0")}`}(h)}),null!=u&&(0,r.jsx)("span",{children:eH(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)(eN,{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:k,onLoadedMetadata:e=>g(e.currentTarget.duration),onError:()=>f("Failed to load audio"),style:{width:"100%"}},k)]})})]})}function eV({filePath:e,cwd:t,sourceSessionId:n,watchEnabled:o=!0}){let{t:a}=(0,v.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=ew(e),b="pdf"===m,y=b?eF(e,"read",n,d?{v:d}:void 0):eF(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(eF(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),!b&&e.size>0xa00000&&g("DOCX too large for preview (>10MB)")))}).catch(e=>{t&&r===f.current&&g(String(e))}),()=>{t=!1}},[e,b,n]),(0,i.useEffect)(()=>{if(l(!1),x.current&&(x.current.close(),x.current=null),!o)return;let t=!0,r=new EventSource(eF(e,"watch",n));x.current=r,r.addEventListener("connected",()=>{let r;l(!0),r=++f.current,fetch(eF(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),!b&&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),!b&&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,b,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,j.qP)(e,t)}),(0,r.jsx)("span",{style:{marginLeft:"auto"},children:"docx"===m?"docx preview":"pdf"}),null!=u&&(0,r.jsx)("span",{children:eH(u)}),(0,r.jsx)(eN,{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:y,sandbox:b?void 0:"allow-same-origin",title:a("i18n.previewFile",{file:(0,j.WP)(e)}),style:{width:"100%",height:"100%",border:"none",background:b?"var(--bg)":"#eef1f5"}},y)})]})}function eq({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!==(ey[ew(e)]??null)?(0,r.jsx)(eU,{filePath:e,cwd:t,sourceSessionId:n,watchEnabled:u}):null!==(ek[ew(e)]??null)?(0,r.jsx)(e_,{filePath:e,cwd:t,sourceSessionId:n,watchEnabled:u}):null!==("pdf"===(p=ew(e))||"docx"===p?p:null)?(0,r.jsx)(eV,{filePath:e,cwd:t,sourceSessionId:n,watchEnabled:u}):(0,r.jsx)(eJ,{filePath:e,cwd:t,sourceSessionId:n,onOpenFile:i,onMentionLines:o,onAtMention:a,gitRefreshKey:s,initialDisplayMode:l,initialState:d,onStateChange:c,watchEnabled:u})}function eJ({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,eb.D)(),{t:g}=(0,v.s)(),[x,f]=(0,i.useState)(null),[m,b]=(0,i.useState)(null),[y,k]=(0,i.useState)(!1),[w,S]=(0,i.useState)(!1),[C,T]=(0,i.useState)(!0),[M,R]=(0,i.useState)(null),I=c?.displayMode??d??"source",L=c?.wrapLines??!1,z=c?.scrollTop??0,E=c?.scrollLeft??0,[W,P]=(0,i.useState)(I),[$,D]=(0,i.useState)(L),[B,A]=(0,i.useState)(!1),F=(0,i.useRef)(null),N=(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),V=(0,i.useRef)(!0),q=(0,i.useRef)({displayMode:I,wrapLines:L,scrollTop:z,scrollLeft:E}),J=(0,i.useRef)(u),[K,Y]=(0,i.useState)(null);J.current=u;let G=(0,i.useCallback)(e=>{q.current.displayMode=e,P(e)},[]),X=(0,i.useCallback)(()=>{D(e=>{let t=!e;return q.current.wrapLines=t,t})},[]);(0,i.useEffect)(()=>(q.current={displayMode:I,wrapLines:L,scrollTop:z,scrollLeft:E},V.current=!0,U.current=!1,P(I),D(L),()=>{J.current?.({...q.current})}),[e,n,I,L,z,E]);let Z=(0,i.useCallback)(e=>{let t=++N.current;return fetch(eF(e,"read",n)).then(e=>e.json()).then(e=>t!==N.current?null:e.error?(R(e.error),null):(R(null),f(e),e)).catch(e=>(t!==N.current||R(String(e)),null))},[n]),Q=(0,i.useCallback)(async e=>{let n=++H.current;if(k(!0),!t){b(null),k(!1),S(!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;b(i.ok&&o.supported&&"string"==typeof o.patch?o:null)}catch{n===H.current&&b(null)}finally{n===H.current&&(k(!1),S(!0))}},[t]);(0,i.useEffect)(()=>{let t=!0;return T(!0),R(null),f(null),b(null),S(!1),A(!1),Z(e).finally(()=>{t&&T(!1)}),()=>{t=!1}},[e,Z,n]),(0,i.useEffect)(()=>{if(A(!1),F.current&&(F.current.close(),F.current=null),!p)return;let t=()=>{Z(e),Q(e)},r=new EventSource(eF(e,"watch",n));F.current=r,r.addEventListener("connected",()=>{A(!0),t()}),r.addEventListener("change",t);let i=()=>{A(!1)};return r.addEventListener("error",i),r.onerror=i,()=>{r.close(),F.current===r&&(F.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)(()=>{w&&!ee&&"diff"===W&&G("source")},[W,w,ee,G]),(0,i.useEffect)(()=>{"diff"===I&&ee&&!U.current&&(U.current=!0,G("diff"))},[I,ee,G]);let en=(0,i.useMemo)(()=>x?.language==="markdown"?(0,eM.Ep)(x.content):"",[x]),er=(0,i.useMemo)(()=>x?.language==="markdown"?function(e){let t=function(e){let t=eC.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,eS.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?eB(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,j.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?eB(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(!V.current||C||M&&!et||"diff"===I&&!w||"diff"===I&&ee&&"diff"!==W)return;let e=O.current;e&&(e.scrollTop=q.current.scrollTop,e.scrollLeft=q.current.scrollLeft,V.current=!1)},[x?.content,W,M,w,ee,et,C,I]),C||"diff"===I&&y&&!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(M&&!et)return(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#f87171",fontSize:13},children:M});if(!x&&!et)return null;let eo=x?.language??"text",ea=x?.content??"",es="html"===eo,el="markdown"===eo,ed=(0,j.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 ${eH(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,j.qP)(e,t)}),(0,r.jsx)("span",{className:"file-viewer-meta",title:eh,children:eh}),!et&&(0,r.jsx)("span",{title:B?g("i18n.liveSync"):g("i18n.notWatching"),"aria-label":B?g("i18n.liveSync"):g("i18n.notWatching"),className:"file-viewer-live-indicator",style:{background:B?"#4ade80":"var(--border)",boxShadow:B?"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:eE[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,j.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)(e$,{})}),"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)(eN,{filePath:e,sourceSessionId:n})]})]}),(0,r.jsx)("div",{ref:O,className:"file-viewer-content",onScroll:e=>{q.current.scrollTop=e.currentTarget.scrollTop,q.current.scrollLeft=e.currentTarget.scrollLeft},style:{flex:1,overflow:"auto",background:"transparent"},children:"diff"===eu&&ee?(0,r.jsx)(eO,{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)(eL,{data:er.data}),(0,r.jsx)(ev.oz,{remarkPlugins:eM.iA,rehypePlugins:eM.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)(eR.t,{code:o.replace(/\n$/,""),defaultPreview:!0}):(0,r.jsx)(eR.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,ej.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,ej.V)(e,ed,t??ed):null,s=a?eF(a,"read",n):e;return(0,r.jsx)("img",{src:s,alt:i??"",loading:"lazy",...o})}},children:en})]}):(0,r.jsx)(ef.A,{className:$?"file-source-view is-wrapped":"file-source-view",language:"text"===eo?"plaintext":eo,style:h?em.xJ:em.vs,showLineNumbers:!0,lineNumberStyle:{...eP},customStyle:{margin:0,padding:0,border:0,background:"transparent",...eW,width:$?"100%":"max-content",minWidth:"100%",minHeight:"100%",overflow:"visible"},codeTagProps:{style:{fontFamily:"var(--font-mono)",overflowWrap:$?"anywhere":"normal"}},renderer:e=>(0,r.jsx)(eA,{...e,wrapLines:$}),wrapLongLines:$,children:ea})})]})}function eK({tabs:e,activeTabId:t,onSelectTab:n,onCloseTab:o}){let{t:a}=(0,v.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,w.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)})})}var eY=n(31590);let eG=["input","output","cacheRead","cacheWrite"];function eX(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 eZ(e){if(!eQ(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 eQ(e){return eG.some(t=>""!==e[t].trim())}function e0(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 e1=e=>(0,r.jsx)("svg",{...e0(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"})}),e2=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"})]}),e4=e=>(0,r.jsx)("svg",{...e0(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"})}),e8=e=>(0,r.jsx)("svg",{...e0(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"})}),e5=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"})]}),e6=e=>(0,r.jsx)("svg",{...e0(e),viewBox:"0 0 24 24",children:(0,r.jsx)("path",{d:"M16 6H8v12h8V6zm4 16H4V2h16v20z"})}),e3=e=>(0,r.jsx)("svg",{...e0(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"})}),e7=e=>(0,r.jsx)("svg",{...e0(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"})}),e9={anthropic:{Icon:e=>(0,r.jsx)("svg",{...e0(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:e1,hasColor:!1},"openai-codex":{Icon:e1,hasColor:!1},google:{Icon:e2,hasColor:!0},"google-vertex":{Icon:e2,hasColor:!0},"ant-ling":{Icon:e=>(0,r.jsxs)("svg",{...e0(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",{...e0(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:e4,hasColor:!1},"moonshotai-cn":{Icon:e4,hasColor:!1},moonshot:{Icon:e4,hasColor:!1},minimax:{Icon:e8,hasColor:!0},"minimax-cn":{Icon:e8,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",{...e0(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",{...e0(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",{...e0(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:e5,hasColor:!0},"cloudflare-workers-ai":{Icon:e5,hasColor:!0},"vercel-ai-gateway":{Icon:e=>(0,r.jsx)("svg",{...e0(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",{...e0(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",{...e0(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",{...e0(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:e6,hasColor:!1},"opencode-go":{Icon:e6,hasColor:!1},qwen:{Icon:e=>(0,r.jsx)("svg",{...e0(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:e3,hasColor:!1},"xiaomi-token-plan-ams":{Icon:e3,hasColor:!1},"xiaomi-token-plan-cn":{Icon:e3,hasColor:!1},"xiaomi-token-plan-sgp":{Icon:e3,hasColor:!1},zai:{Icon:e7,hasColor:!1},"zai-coding-cn":{Icon:e7,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",{...e0(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}},te=["openai-completions","openai-responses","anthropic-messages","google-generative-ai"];function tt({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 tn={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 tr({value:e,onChange:t,placeholder:n,mono:i}){return(0,r.jsx)("input",{value:e,onChange:e=>t(e.target.value),placeholder:n,style:{...tn,fontFamily:i?"var(--font-mono)":"inherit"}})}function ti({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,v.s)();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),onKeyDown:a,placeholder:n,style:{...tn,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 to({value:e,onChange:t,placeholder:n}){return(0,r.jsx)("input",{type:"number",value:e,onChange:e=>t(e.target.value),placeholder:n,style:tn})}function ta({value:e,onChange:t,options:n,required:i}){let{t:o}=(0,v.s)();return(0,r.jsxs)("select",{value:e,onChange:e=>t(e.target.value),style:{...tn,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 ts({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 tl({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 td({name:e,provider:t,onChange:n,onRename:o,onDelete:a,onAddModels:s}){let{t:l}=(0,v.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),b=(0,i.useRef)(null);(0,i.useEffect)(()=>c(e),[e]);let y=(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 k=(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]),w=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=>!w.has(e.id)).map(e=>e.id),R=x.filter(e=>!w.has(e)).length,I=M.length>0&&M.every(e=>x.includes(e)),L=!I&&M.some(e=>x.includes(e));return(0,i.useEffect)(()=>{b.current&&(b.current.indeterminate=L)},[L]),(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)(tl,{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)(tt,{label:l("i18n.providerName"),children:[(0,r.jsx)(tr,{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)(tt,{label:"Base URL",children:(0,r.jsx)(tr,{value:t.baseUrl??"",onChange:e=>y("baseUrl",e||void 0),placeholder:"https://api.example.com/v1",mono:!0})}),(0,r.jsxs)(tt,{label:"API Key",children:[(0,r.jsx)(ti,{value:t.apiKey??"",onChange:e=>y("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)(tt,{label:"API",children:(0,r.jsx)(ta,{value:t.api??"openai-completions",onChange:e=>y("api",e),options:te,required:!0})}),(0,r.jsxs)(tt,{label:"Headers",children:[(0,r.jsx)(tx,{headers:t.headers,onChange:e=>y("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:k,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:{...tn,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:b,type:"checkbox",checked:I,disabled:0===M.length,onChange:()=>{let e=new Set(M);f(t=>I?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=w.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)&&!w.has(t.id));0!==t.length&&(s(t),f([]))},disabled:0===R,style:{height:28,padding:"0 11px",border:"none",borderRadius:5,background:R?"var(--accent)":"var(--bg-panel)",color:R?"#fff":"var(--text-dim)",cursor:R?"pointer":"not-allowed",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:R?l("models.discoveryAddSelectedCount",{count:R}):l("models.discoveryAddSelected")})]})]})]})]})}let tc=["off","minimal","low","medium","high","xhigh","max"],tu={off:"var(--text-dim)",minimal:"#6b7280",low:"#60a5fa",medium:"#a78bfa",high:"#f472b6",xhigh:"#fb923c",max:"#ef4444"};function tp({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:tc.map(e=>{let t=n[e],o=e in n?null===t?"null":"string":"omit",a="string"==typeof t?t:"",s=tu[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 th={thinkingFormat:"deepseek",requiresReasoningContentOnAssistantMessages:!0};function tg(e){return e.compat?.thinkingFormat==="deepseek"}function tx({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:{...tn,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:{...tn,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 tf({providerName:e,provider:t,model:n,onChange:o,onDelete:a}){let[s,l]=(0,i.useState)({phase:"idle"}),{t:d}=(0,v.s)(),[c,u]=(0,i.useState)({phase:"idle"}),[p,h]=(0,i.useState)(!1),[g,x]=(0,i.useState)(()=>eX(n.cost)),f=(0,i.useRef)(g),[m,b]=(0,i.useState)(!1),y=(0,i.useRef)(0),k=(0,i.useRef)(null),w=(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)(()=>{y.current+=1,u({phase:"idle"}),k.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=++y.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!==y.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=eZ(eX(i));o>0&&a&&(n.cost={...i,...a},r+=o)}return{model:n,appliedCount:r}}(n,l.recommendation.preset);d.appliedCount>0&&(k.current=n,o(d.model)),h(!1),u({phase:"success",recommendation:l.recommendation,appliedCount:d.appliedCount})}catch(e){if(i!==y.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}`})(),R="error"===c.phase?c.message:M,I="error"===c.phase?"#ef4444":"success"===c.phase&&"unreliable"===c.recommendation.price.status?"#d97706":"var(--text-dim)",L=[{key:"input",label:d("models.costInput")},{key:"output",label:d("models.costOutput")},{key:"cacheRead",label:d("models.costCacheRead")},{key:"cacheWrite",label:d("models.costCacheWrite")}],z=new Set(Object.keys(n.compat??{})),E=0;tg(n)&&(E+=1,z.delete("thinkingFormat"),z.delete("requiresReasoningContentOnAssistantMessages")),Object.prototype.hasOwnProperty.call(n.compat??{},"supportsDeveloperRole")&&(E+=1,z.delete("supportsDeveloperRole")),E+=z.size;let W=[n.api?`API: ${n.api}`:null,Object.keys(n.headers??{}).length?d("models.headersSummary",{count:Object.keys(n.headers??{}).length}):null,E?d("models.compatSummary",{count:E}):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)(tl,{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)(tt,{label:"ID *",children:(0,r.jsx)(tr,{value:n.id,onChange:e=>j("id",e),placeholder:"model-id",mono:!0})}),(0,r.jsx)(tt,{label:"Name",children:(0,r.jsx)(tr,{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")})]}),R&&(0,r.jsxs)("div",{"aria-live":"polite",style:{marginTop:8,display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,color:I,fontSize:10},children:[(0,r.jsx)("span",{title:R,style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:R}),k.current&&(0,r.jsx)("button",{onClick:()=>{let e=k.current;e&&(k.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)(tl,{children:d("models.capabilities")}),(0,r.jsxs)("div",{style:{display:"flex",gap:20,flexWrap:"wrap",marginTop:8},children:[(0,r.jsx)(ts,{label:d("models.reasoning"),checked:n.reasoning??!1,onChange:e=>j("reasoning",e||void 0)}),(0,r.jsx)(ts,{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)(tl,{children:d("models.modelSpecs")}),(0,r.jsx)("button",{type:"button",onClick:()=>{if(p)return void h(!1);w.current=n.cost;let e=eX(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)(tt,{label:d("models.contextWindow"),children:(0,r.jsx)(to,{value:void 0!==n.contextWindow?String(n.contextWindow):"",onChange:e=>j("contextWindow",e?parseInt(e):void 0),placeholder:"128000"})}),(0,r.jsx)(tt,{label:d("models.maxOutputTokens"),children:(0,r.jsx)(to,{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:[L.map(({key:e,label:t})=>(0,r.jsx)(tt,{label:t,children:(0,r.jsx)(to,{value:g[e],onChange:t=>{let r,i,a;return i=eZ(r={...f.current,[e]:t}),a={...n},void(f.current=r,x(r),i?(a.cost={...w.current??{},...i},w.current=a.cost):delete a.cost,o(a))},placeholder:"0"})},e)),eQ(g)&&!eZ(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:L.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:()=>b(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)(tt,{label:d("models.apiOverride"),children:(0,r.jsx)(ta,{value:n.api??"",onChange:e=>j("api",e||void 0),options:te})}),(0,r.jsxs)(tt,{label:d("models.headers"),children:[(0,r.jsx)(tx,{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)(tl,{children:d("models.compatibility")}),(0,r.jsx)(ts,{label:d("models.deepSeekThinkingCompat"),checked:tg(n),onChange:e=>o(function(e,t){if(t)return{...e,compat:{...e.compat??{},...th}};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)(ts,{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)(tl,{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)(tp,{value:n.thinkingLevelMap,onChange:e=>j("thinkingLevelMap",e)})]})]})]})]})]})}function tm({provider:e,onRefresh:t}){let[n,o]=(0,i.useState)({phase:"idle"}),{t:a}=(0,v.s)(),[s,l]=(0,i.useState)(""),d=(0,i.useRef)(null),c=(0,i.useRef)(null);(0,i.useEffect)(()=>{("auth"===n.phase||"prompt"===n.phase)&&setTimeout(()=>c.current?.focus(),50)},[n.phase]),(0,i.useEffect)(()=>{o({phase:"idle"}),l(""),d.current?.close(),d.current=null},[e.id]),(0,i.useEffect)(()=>()=>{d.current?.close()},[]);let u=(0,i.useCallback)(()=>{d.current?.close(),o({phase:"connecting"}),l("");let n=new EventSource(`/api/auth/login/${encodeURIComponent(e.id)}`);d.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]),p=(0,i.useCallback)(async()=>{await fetch(`/api/auth/logout/${encodeURIComponent(e.id)}`,{method:"POST"}),o({phase:"idle"}),t()},[e.id,t]),h=(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]),g=(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]),x="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)(tl,{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:()=>g(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:c,value:s,onChange:e=>l(e.target.value),onKeyDown:e=>{"Enter"===e.key&&h(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:()=>h(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:x?(0,r.jsx)("button",{onClick:()=>{d.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:u,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:p,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 tv({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,v.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)(tl,{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)(tt,{label:"API Key",children:(0,r.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,r.jsx)(ti,{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 tb({id:e,size:t}){let n=e9[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 ty({oauthProviders:e,apiKeyProviders:t,onSelectOAuth:n,onSelectApiKey:o,onAddCustom:a,onClose:s}){let[l,d]=(0,i.useState)(""),{t:c}=(0,v.s)(),u=(0,i.useRef)(null);(0,i.useEffect)(()=>{setTimeout(()=>u.current?.focus(),30)},[]);let p=l.trim().toLowerCase(),h=e.filter(e=>!e.loggedIn&&(!p||e.name.toLowerCase().includes(p))),g=t.filter(e=>!e.configured&&(!p||e.displayName.toLowerCase().includes(p)||e.id.toLowerCase().includes(p))),x=!p||"custom".includes(p)||"openai-compatible".includes(p)||"anthropic-compatible".includes(p),f=h.length+g.length+ +!!x,m={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:u,value:l,onChange:e=>d(e.target.value),onKeyDown: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===f?(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:[x&&(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")}),x&&(0,r.jsxs)("button",{onClick:()=>{a(),s()},style:m,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"})]})})]}),h.length>0&&(0,r.jsx)("div",{style:{gridColumn:"1 / -1",paddingTop:6*!!x,fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:c("i18n.subscriptions")}),h.map(e=>(0,r.jsxs)("button",{onClick:()=>{n(e.id),s()},style:m,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)(tb,{id:e.id,size:28})]},e.id)),g.length>0&&(0,r.jsx)("div",{style:{gridColumn:"1 / -1",paddingTop:6*(h.length>0),fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"API Key"}),g.map(e=>(0,r.jsxs)("button",{onClick:()=>{o(e.id),s()},style:m,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)(tb,{id:e.id,size:28})]},e.id))]})})]})})}function tk({onClose:e,cwd:t}){let n=(0,eY.a)(),{t:o}=(0,v.s)(),[a,s]=(0,i.useState)({providers:{}}),[l,d]=(0,i.useState)(!0),[c,u]=(0,i.useState)(!1),[p,h]=(0,i.useState)(null),[g,x]=(0,i.useState)(!1),[f,m]=(0,i.useState)(null),[b,y]=(0,i.useState)([]),[k,w]=(0,i.useState)([]),[j,S]=(0,i.useState)(!1),C=(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]),T=(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)&&w(e.providers)}).catch(()=>{})},[t]),M=(0,i.useCallback)(()=>{C(),T()},[C,T]);(0,i.useEffect)(()=>{fetch("/api/models-config").then(e=>e.json()).then(e=>{let t=e.providers?e:{...e,providers:{}};s(t);let n=Object.keys(t.providers??{});n.length>0&&m({type:"provider",name:n[0]})}).catch(()=>s({providers:{}})).finally(()=>d(!1)),M()},[M]);let R=(0,i.useCallback)(()=>{let e="new-provider",t=1;for(;a.providers?.[e];)e=`new-provider-${t++}`;s(t=>({...t,providers:{...t.providers??{},[e]:{api:"openai-completions"}}})),m({type:"provider",name:e})},[a.providers]),I=(0,i.useCallback)((e,t)=>{s(n=>({...n,providers:{...n.providers??{},[e]:t}}))},[]),L=(0,i.useCallback)((e,t)=>{s(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)})}),m(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=>{s(t=>{let n={...t.providers??{}};return delete n[e],{...t,providers:n}}),s(e=>{let t=Object.keys(e.providers??{});return m(t.length>0?{type:"provider",name:t[0]}:null),e})},[]),E=(0,i.useCallback)(e=>{s(t=>{let n=t.providers?.[e]??{},r=[...n.models??[],{id:""}];return{...t,providers:{...t.providers??{},[e]:{...n,models:r}}}}),s(t=>{let n=(t.providers?.[e]?.models?.length??1)-1;return m({type:"model",providerName:e,index:n}),t})},[]),W=(0,i.useCallback)((e,t)=>{s(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}}}})},[]),P=(0,i.useCallback)((e,t,n)=>{s(r=>{let i=r.providers?.[e]??{},o=[...i.models??[]];return o[t]=n,{...r,providers:{...r.providers??{},[e]:{...i,models:o}}}})},[]),$=(0,i.useCallback)((e,t)=>{s(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}}}}),m({type:"provider",name:e})},[]),D=(0,i.useCallback)(async()=>{u(!0),h(null),x(!1);try{let e=await fetch("/api/models-config",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)}),t=await e.json();!e.ok||t.error?h(t.error??`HTTP ${e.status}`):(x(!0),setTimeout(()=>x(!1),2e3))}catch(e){h(String(e))}finally{u(!1)}},[a]),B=Object.entries(a.providers??{}),A=b.filter(e=>e.loggedIn),F=k.filter(e=>e.configured),N=(()=>{if(!f)return null;if("oauth"===f.type){let e=b.find(e=>e.id===f.providerId);return e?(0,r.jsx)(tm,{provider:e,onRefresh:M},e.id):null}if("apikey"===f.type){let e=k.find(e=>e.id===f.providerId);return e?(0,r.jsx)(tv,{provider:e,onRefresh:M},e.id):null}if("provider"===f.type){let e=a.providers?.[f.name];return e?(0,r.jsx)(td,{name:f.name,provider:e,onChange:e=>I(f.name,e),onRename:e=>L(f.name,e),onDelete:()=>z(f.name),onAddModels:e=>W(f.name,e)},f.name):null}let e=a.providers?.[f.providerName],t=e?.models?.[f.index];return t?(0,r.jsx)(tf,{providerName:f.providerName,provider:e,model:t,onChange:e=>P(f.providerName,f.index,e),onDelete:()=>$(f.providerName,f.index)},`${f.providerName}-${f.index}`):null})();return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:t=>{t.target===t.currentTarget&&e()},children:(0,r.jsxs)("div",{style:{width:n?"calc(100vw - 16px)":860,maxWidth:"calc(100vw - 16px)",height:n?"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:[(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:o("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:n?"column":"row",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{width:n?"100%":210,maxHeight:n?"40vh":void 0,borderRight:n?"none":"1px solid var(--border)",borderBottom:n?"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=f?.type==="oauth"&&f.providerId===e.id;return(0,r.jsxs)("div",{onClick:()=>m({type:"oauth",providerId:e.id}),style:{display:"flex",alignItems:"center",gap:7,padding:"5px 8px",borderRadius:5,cursor:"pointer",background:t?"var(--bg-selected)":"none"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,r.jsx)(tb,{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=f?.type==="apikey"&&f.providerId===e.id;return(0,r.jsxs)("div",{onClick:()=>m({type:"apikey",providerId:e.id}),style:{display:"flex",alignItems:"center",gap:7,padding:"5px 8px",borderRadius:5,cursor:"pointer",background:t?"var(--bg-selected)":"none"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,r.jsx)(tb,{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)"}}),l?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:o("i18n.loading")}):B.map(([e,t])=>{let n=f?.type==="provider"&&f.name===e,i=t.models??[];return(0,r.jsxs)("div",{style:{marginBottom:2},children:[(0,r.jsxs)("div",{onClick:()=>m({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=f?.type==="model"&&f.providerName===e&&f.index===n;return(0,r.jsxs)("div",{onClick:()=>m({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||o("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(),E(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:["+ ",o("i18n.model")]})})]},e)})]}),(0,r.jsx)("div",{style:{borderTop:"1px solid var(--border)",padding:"8px 6px"},children:(0,r.jsxs)("button",{onClick:()=>S(!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:["+ ",o("i18n.addProvider")]})})]}),(0,r.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:l?null:N??(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:o("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:[p&&(0,r.jsx)("span",{style:{fontSize:12,color:"#f87171",flex:1},children:p}),(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:o("i18n.cancel")}),(0,r.jsxs)("button",{onClick:D,disabled:c||g,style:{position:"relative",padding:"6px 16px",minWidth:92,background:g?"#16a34a":c?"var(--bg-panel)":"var(--accent)",border:"none",borderRadius:6,color:g?"#fff":c?"var(--text-muted)":"#fff",cursor:c||g?"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:g?"saved-pop 0.45s ease":void 0},children:[g&&(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:g?o("i18n.saved"):c?o("i18n.saving"):o("i18n.save")})]})]})]})}),j&&(0,r.jsx)(ty,{oauthProviders:b,apiKeyProviders:k,onSelectOAuth:e=>m({type:"oauth",providerId:e}),onSelectApiKey:e=>m({type:"apikey",providerId:e}),onAddCustom:R,onClose:()=>S(!1)})]})}function tw(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function tj(e){let t=e.sourceInfo?.source,n=e.sourceInfo?.scope;return"user"===n||"user"===t?"global":"project"===n||"project"===t?"project":"path"}function tS(e){let t=tj(e);return"path"===t?t:e.install?.skillsShUrl?`${t} / skills.sh`:t}function tC(e){return e.install?`${e.install.scope}\0${e.install.package}`:null}function tT(e){return e?e.slice(0,8):"unknown"}function tM({enabled:e,loading:t,onToggle:n}){let{t:i}=(0,v.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 tR({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,v.s)(),h=tj(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 tw(e)}(e.filePath)}),(0,r.jsx)(tM,{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:tT(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:tT(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 tI({cwd:e,installedPackages:t,projectResourcesLoaded:n,onInstalled:o}){let{t:a}=(0,v.s)(),[s,l]=(0,i.useState)(""),[d,c]=(0,i.useState)([]),[u,p]=(0,i.useState)(!1),[h,g]=(0,i.useState)(null),[x,f]=(0,i.useState)(null),[m,b]=(0,i.useState)(null),[y,k]=(0,i.useState)(new Set),[w,j]=(0,i.useState)("global"),S=(0,i.useRef)(null);(0,i.useEffect)(()=>{S.current?.focus()},[]);let C=(0,i.useCallback)(async e=>{if(e.trim()){p(!0),g(null),c([]);try{let t=await fetch("/api/skills/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:e.trim()})}),n=await t.json();if(n.error)return void g(n.error);c(n.results??[]),0===(n.results??[]).length&&g("No skills found")}catch(e){g(String(e))}finally{p(!1)}}},[]),T=(0,i.useCallback)(async t=>{f(t),b(null);try{let n=await fetch("/api/skills/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({package:t,scope:w,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(`${w}:${t}`)),o()}catch(e){b(String(e))}finally{f(null)}},[o,w,e]),M="global"===w?"~/.pi/agent/skills/":`${tw(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:S,value:s,onChange:e=>l(e.target.value),onKeyDown:e=>{"Enter"===e.key&&C(s)},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:()=>C(s),disabled:u||!s.trim(),style:{padding:"7px 16px",fontSize:13,borderRadius:6,border:"none",background:"var(--accent)",color:"#fff",cursor:u||!s.trim()?"not-allowed":"pointer",opacity:u||!s.trim()?.5:1,flexShrink:0},children:u?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)&&j(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:w===e?"var(--bg-selected)":"none",color:w===e?"var(--text)":"var(--text-dim)",fontWeight:w===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:["→ ",M]})]}),h&&(0,r.jsx)("div",{style:{fontSize:12,color:"#f87171"},children:h}),m&&(0,r.jsx)("div",{style:{fontSize:12,color:"#f87171",wordBreak:"break-word"},children:m})]}),d.length>0?(0,r.jsx)("div",{style:{flex:1,overflowY:"auto"},children:d.map(e=>{let n=t[w].has(e.package)||y.has(`${w}:${e.package}`),i=x===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&&T(e.package),disabled:n||i||null!==x,style:{flexShrink:0,padding:"5px 14px",fontSize:12,fontWeight:500,borderRadius:5,border:"1px solid var(--border)",cursor:n||i||null!==x?"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)})}):!h&&!u&&(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 tL({cwd:e,onClose:t}){let n=(0,eY.a)(),{t:o}=(0,v.s)(),[a,s]=(0,i.useState)([]),[l,d]=(0,i.useState)(!0),[c,u]=(0,i.useState)(null),[p,h]=(0,i.useState)(null),[g,x]=(0,i.useState)(new Set),[f,m]=(0,i.useState)(null),[b,y]=(0,i.useState)(!1),[k,w]=(0,i.useState)({}),[j,S]=(0,i.useState)(new Set),[C,T]=(0,i.useState)(!1),[M,R]=(0,i.useState)(null),[I,L]=(0,i.useState)(null),[z,E]=(0,i.useState)(!0),[W,P]=(0,i.useState)({}),$=(0,i.useCallback)(async()=>{d(!0),u(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(s(r),E(n.projectResourcesLoaded??!0),r.length>0&&!p){let e=r.find(e=>!e.disableModelInvocation)??r[0];h(e.filePath),e.disableModelInvocation&&P(t=>({...t,[tS(e)]:!0}))}return r}catch(e){return u(String(e)),[]}finally{d(!1)}},[e,p]);(0,i.useEffect)(()=>{w({}),L(null),$()},[e]);let D=(0,i.useCallback)(async t=>{let n=(t?[t]:a.filter(e=>!!e.install)).map(tC).filter(e=>!!e);if(0!==n.length){L(null),S(e=>new Set([...e,...n])),t||T(!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}`);w(e=>{let t={...e};for(let e of r.updates??[])t[`${e.scope}\0${e.package}`]=e;return t})}catch(e){L(e instanceof Error?e.message:String(e))}finally{S(e=>{let t=new Set(e);for(let e of n)t.delete(e);return t}),t||T(!1)}}},[e,a]),B=(0,i.useCallback)(async t=>{if(!t.install)return;let n=tC(t);R(n),L(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 $();let o=i.skill?.install?.versionHash;w(e=>({...e,[n]:{package:t.install.package,scope:t.install.scope,state:"up-to-date",currentVersion:o,latestVersion:o}}))}catch(e){L(e instanceof Error?e.message:String(e))}finally{R(null)}},[e,$]),A=(0,i.useCallback)(async e=>{let t=!e.disableModelInvocation;x(t=>new Set(t).add(e.filePath)),m(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 m(r.error??`HTTP ${n.status}`);s(n=>n.map(n=>n.filePath===e.filePath?{...n,disableModelInvocation:t}:n)),t&&P(t=>({...t,[tS(e)]:!0}))}catch(e){m(String(e))}finally{x(t=>{let n=new Set(t);return n.delete(e.filePath),n})}},[]),F=a.find(e=>e.filePath===p)??null;return(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:e=>{e.target===e.currentTarget&&t()},children:(0,r.jsxs)("div",{style:{width:n?"calc(100vw - 16px)":860,maxWidth:"calc(100vw - 16px)",height:n?"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:[(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:o("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:tw(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:o("trust.skillsNotLoaded")}),(0,r.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:n?"column":"row",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{width:n?"100%":210,maxHeight:n?"40vh":void 0,borderRight:n?"none":"1px solid var(--border)",borderBottom:n?"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:l?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:o("i18n.loading")}):c?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"#f87171"},children:c}):0===a.length?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"var(--text-dim)"},children:o("i18n.noSkills")}):(()=>{let e=[];for(let{label:t,matches:n}of[{label:"project / skills.sh",matches:e=>"project"===tj(e)&&!!e.install?.skillsShUrl},{label:"project",matches:e=>"project"===tj(e)&&!e.install?.skillsShUrl},{label:"global / skills.sh",matches:e=>"global"===tj(e)&&!!e.install?.skillsShUrl},{label:"global",matches:e=>"global"===tj(e)&&!e.install?.skillsShUrl},{label:"path",matches:e=>"path"===tj(e)}]){let r=a.filter(n);r.length>0&&e.push({label:t,skills:r})}let t=e=>{let t,n,i=!b&&p===e.filePath,a=e.disableModelInvocation;return(0,r.jsxs)("div",{onClick:()=>{h(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:a?"var(--border)":"var(--accent)",boxShadow:a?"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:a?"var(--text-dim)":"var(--text)",fontFamily:"var(--font-mono)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),(n=(t=tC(e))?k[t]:void 0,n?.state!=="update-available"?null:(0,r.jsx)("span",{title:o("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),a=n.filter(e=>e.disableModelInvocation),s=W[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),a.length>0&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{onClick:()=>P(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?"▾":"▸"}),o("i18n.dormant")," (",a.length,")"]}),s&&a.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"})]}),o("i18n.addSkill")]})})]}),(0,r.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:b?(0,r.jsx)(tI,{cwd:e,projectResourcesLoaded:z,installedPackages:{global:new Set(a.filter(e=>e.install?.scope==="global").map(e=>e.install.package)),project:new Set(a.filter(e=>e.install?.scope==="project").map(e=>e.install.package))},onInstalled:()=>{$()}}):l?null:F?(0,r.jsx)(tR,{skill:F,cwd:e,onToggle:A,toggling:g.has(F.filePath),saveError:f,updateStatus:tC(F)?k[tC(F)]:void 0,checkingUpdate:!!tC(F)&&j.has(tC(F)),updating:M===tC(F),updateError:I,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:o("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:[a.some(e=>!!e.install)&&(0,r.jsx)("button",{onClick:()=>void D(),disabled:C||null!==M,style:{padding:"6px 12px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:C||null!==M?"not-allowed":"pointer",opacity:C||null!==M?.5:1,fontSize:12},children:C?o("i18n.checking"):o("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?o("i18n.update"):o("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:o("i18n.close")})]})]})})}var tz=n(32383),tE=n(22271);function tW(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function tP(e){let t=e.trim().match(/^\$?\s*pi\s+install\s+(\S+)\s*$/);return t?.[1]??e}function t$(e){return`${e.scope}\0${e.source}`}function tD(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 tB(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 tA(e){return"loaded"===e?"var(--accent)":"installed"===e?"#f59e0b":"disabled"===e?"var(--text-dim)":"#ef4444"}function tF({pkg:e}){let{t}=(0,v.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 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-dim)"},children:e})}function tH(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 tO({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 tU({value:e,projectResourcesLoaded:t,onChange:n}){let{t:i}=(0,v.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 t_({cwd:e,source:t,scope:n,projectResourcesLoaded:o,busy:a,actionError:s,onSourceChange:l,onScopeChange:d,onInstall:c}){let{t:u}=(0,v.s)(),p=(0,i.useRef)(null);return(0,i.useEffect)(()=>{p.current?.focus()},[]),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:18,maxWidth:660,minHeight:"100%"},children:[(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,flexWrap:"wrap"},children:[(0,r.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)"},children: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?`${tW(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:p,value:t,onChange:e=>l(e.target.value),onPaste:e=>{let t=(0,tE.Gm)(e.clipboardData),n=t.length>0?t[0]:e.clipboardData.getData("text"),r=tP(n);(r!==n||0!==t.length)&&(e.preventDefault(),l(r))},onBlur:e=>l(tP(e.currentTarget.value)),placeholder:"npm:@scope/package",style:{width:"100%",height:36,padding:"0 11px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:13,outline:"none"},onKeyDown:e=>{"Enter"===e.key&&t.trim()&&!a&&c()}})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,r.jsx)(tU,{value:n,projectResourcesLoaded:o,onChange:d}),(0,r.jsx)("button",{type:"button",onClick:c,disabled:a||!t.trim(),style:{...tH(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 tV({pkg:e,cwd:t,busyKey:n,actionError:i,actionMessage:o,sessionId:a,onAction:s,onReloadSession:l}){let{t:d}=(0,v.s)(),c=t$(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)(tO,{enabled:h,loading:u||p,onToggle:()=>s(e.disabled?"enable":"disable",e),label:d(e.disabled?"i18n.enablePackage":"i18n.disablePackage")}),(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-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:tH(u||p),children:d(n===`update:${c}`?"i18n.updating":"i18n.update")}),(0,r.jsx)("button",{onClick:l,disabled:!a||p||u,style:tH(!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:tH(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:tA(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:tB(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:tD(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?tW(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:tW(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)(tF,{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 tq({cwd:e,sessionId:t,onClose:n,onReloaded:o}){let a=(0,eY.a)(),{t:s}=(0,v.s)(),[l,d]=(0,i.useState)(null),[c,u]=(0,i.useState)(!0),[p,h]=(0,i.useState)(null),[g,x]=(0,i.useState)(null),[f,m]=(0,i.useState)(!1),[b,y]=(0,i.useState)(""),[k,w]=(0,i.useState)("global"),[j,S]=(0,i.useState)(null),[C,T]=(0,i.useState)(null),[M,R]=(0,i.useState)(null),I=(0,i.useMemo)(()=>l?.packages??[],[l?.packages]),L=I.find(e=>t$(e)===g)??null,z=l?.projectResourcesLoaded??!0,E=(0,i.useMemo)(()=>["project","global"].map(e=>({scope:e,packages:I.filter(t=>t.scope===e)})).filter(e=>e.packages.length>0),[I]),W=(0,i.useCallback)(async()=>{u(!0),h(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}`);d(n),m(e=>0===n.packages.length||e),x(e=>e&&n.packages.some(t=>t$(t)===e)?e:n.packages[0]?t$(n.packages[0]):null)}catch(e){h(e instanceof Error?e.message:String(e))}finally{u(!1)}},[e]);(0,i.useEffect)(()=>{W()},[W]);let P=(0,i.useCallback)(async(t,n)=>{let r=t$(n);S(`${t}:${r}`),T(null),R(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}`);d(i),"remove"===t?(x(i.packages[0]?t$(i.packages[0]):null),0===i.packages.length&&m(!0),R("Package removed.")):R({install:"Package installed.",update:"Package updated.",disable:"Package disabled.",enable:"Package enabled."}[t])}catch(e){T(e instanceof Error?e.message:String(e))}finally{S(null)}},[e]),$=(0,i.useCallback)(async()=>{let t=tP(b).trim();if(!t)return;y(t);let n=`${k}\0${t}`;S(`install:${n}`),T(null),R(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}`);d(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)));x(l?t$(l):n),m(!1),y(""),R("Package installed.")}catch(e){T(e instanceof Error?e.message:String(e))}finally{S(null)}},[e,k,b]),D=(0,i.useCallback)(async()=>{if(t){S("reload"),T(null),R(null);try{await (0,tz.$J)(t,{type:"reload"}),o?.(),await W(),R("Session reloaded.")}catch(e){T(e instanceof Error?e.message:String(e))}finally{S(null)}}},[W,o,t]),B=j?.startsWith("install:")??!1;return(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:e=>{e.target===e.currentTarget&&n()},children:(0,r.jsxs)("div",{style:{width:a?"calc(100vw - 16px)":860,maxWidth:"calc(100vw - 16px)",height:a?"calc(100dvh - 16px)":"76vh",maxHeight:"calc(100dvh - 16px)",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.18)",overflow:"hidden"},children:[(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:s("common.plugins")}),(0,r.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:tW(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:s("trust.pluginsNotLoaded")}),(0,r.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:a?"column":"row",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{width:a?"100%":245,maxHeight:a?"40vh":void 0,borderRight:a?"none":"1px solid var(--border)",borderBottom:a?"1px solid var(--border)":"none",display:"flex",flexDirection:"column",flexShrink:0,background:"var(--bg-panel)"},children:[(0,r.jsx)("div",{style:{flex:1,overflowY:"auto",padding:"8px 6px"},children:c?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:"Loading..."}):p?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"#ef4444"},children:p}):0===I.length?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"var(--text-dim)"},children:"No plugins configured"}):E.map(e=>(0,r.jsxs)("div",{style:{marginBottom:6},children:[(0,r.jsx)("div",{style:{padding:"4px 8px 3px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase"},children:e.scope}),e.packages.map(e=>{let t=t$(e),n=!f&&g===t;return(0,r.jsxs)("div",{onClick:()=>{x(t),m(!1),T(null),R(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:tA(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:tD(e,s)}),(e.version||e.configuredVersion)&&(0,r.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:2},children:tB(e,s)})]})]},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:()=>{m(!0),T(null),R(null)},style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,border:"none",width:"100%",cursor:"pointer",background:f?"var(--bg-selected)":"none",color:f?"var(--accent)":"var(--text-dim)",fontSize:12},onMouseEnter:e=>{f||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{f||(e.currentTarget.style.background="none")},children:[(0,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"})]}),s("i18n.addPlugin")]})})]}),(0,r.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:f?(0,r.jsx)(t_,{cwd:e,source:b,scope:k,projectResourcesLoaded:z,busy:B,actionError:C,onSourceChange:y,onScopeChange:w,onInstall:$}):c?null:L?(0,r.jsx)(tV,{pkg:L,cwd:e,busyKey:j,actionError:C,actionMessage:M,sessionId:t,onAction:P,onReloadSession:D},t$(L)):(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:s("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:l?.diagnostics.length?(0,r.jsxs)("span",{title:l.diagnostics.map(e=>`${e.type}: ${e.source?`${e.source}: `:""}${e.message}`).join("\n"),style:{color:l.diagnostics.some(e=>"error"===e.type)?"#ef4444":"#d97706"},children:[l.diagnostics.length," diagnostic",1===l.diagnostics.length?"":"s"]}):(0,r.jsx)("span",{children:l?`${l.totals.extensions} ext \xb7 ${l.totals.skills} skills \xb7 ${l.totals.prompts} prompts \xb7 ${l.totals.themes} themes`:""})}),(0,r.jsx)("button",{onClick:()=>void W(),disabled:c||null!==j,style:tH(c||null!==j),children:s("i18n.refresh")}),(0,r.jsx)("button",{onClick:n,style:tH(!1),children:s("i18n.close")})]})]})})}function tJ(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function tK({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 tY(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 tG({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 tX({value:e,projectResourcesLoaded:t,onChange:n}){let{t:i}=(0,v.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 tZ({server:e,cwd:t,busy:n,actionError:i,actionMessage:o,onToggle:a,onRemove:s,onMove:l,onTest:d,onEdit:c}){let{t:u}=(0,v.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,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)(tG,{enabled:p,loading:n,onToggle:a,label:u(p?"mcp.disable":"mcp.enable")}),(0,r.jsx)(tK,{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:tY(n),children:u(n?"mcp.testing":"mcp.test")}),(0,r.jsx)("button",{onClick:c,disabled:n,style:tY(n),children:u("mcp.edit")}),(0,r.jsx)("button",{onClick:l,disabled:n,style:tY(n),children:u("project"===h?"mcp.moveToProject":"mcp.moveToGlobal")}),(0,r.jsx)("button",{onClick:s,disabled:n,style:tY(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:tJ(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:tJ(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 tQ({cwd:e,scope:t,projectResourcesLoaded:n,busy:o,actionError:a,initial:s,onScopeChange:l,onSave:d,onFetchDef:c,onCancel:u}){let{t:p}=(0,v.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??"":""),[b,y]=(0,i.useState)(""),[k,w]=(0,i.useState)("basic"),[j,S]=(0,i.useState)(null),[C,T]=(0,i.useState)(null),[M,R]=(0,i.useState)(!1),I={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"},L={fontSize:12,fontWeight:600,color:"var(--text-muted)"},z=/^https?:\/\//.test(f.trim()),E=()=>{let e=f.trim();if(/^https?:\/\//.test(e))return{url:e};let t=e.split(/\s+/),n=t[0]??"",r=b.trim()?b.trim().split(/\s+/):[];return{command:n,args:[...t.slice(1),...r]}},W=async()=>{if(T(null),null!==j)return void w("json");if(h&&s){w("json"),R(!0);try{let e=await c(s.name,s.scope);S(JSON.stringify(e??E(),null,2))}finally{R(!1)}}else S(JSON.stringify(E(),null,2)),w("json")},P=g.trim()&&("json"===k?(j??"").trim().length>0:f.trim().length>0);return(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.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?`${tJ(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():w("basic"),style:{padding:"6px 14px",borderRadius:6,border:"1px solid var(--border)",cursor:"pointer",fontSize:12,background:k===e?"var(--accent)":"none",color:k===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:L,children:p("mcp.nameLabel")}),(0,r.jsx)("input",{value:g,onChange:e=>x(e.target.value),placeholder:p("mcp.namePlaceholder"),style:I})]}),"json"===k?(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:7},children:[(0,r.jsx)("label",{style:L,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:L,children:p("mcp.specLabel")}),(0,r.jsx)("input",{value:f,onChange:e=>m(e.target.value),placeholder:p("mcp.specPlaceholder"),style:I})]}),!z&&(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:7},children:[(0,r.jsx)("label",{style:L,children:p("mcp.argsLabel")}),(0,r.jsx)("input",{value:b,onChange:e=>y(e.target.value),style:I})]})]}),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)(tX,{value:t,projectResourcesLoaded:n,onChange:l}),(0,r.jsx)("button",{type:"button",onClick:()=>{if(T(null),"json"===k){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,E())},disabled:o||!P,style:{...tY(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:tY(!1),children:p("mcp.cancel")})]}),a&&(0,r.jsx)("div",{style:{fontSize:12,color:"#ef4444",whiteSpace:"pre-wrap"},children:a})]})}function t0({anchorRect:e,cwd:t,hidden:n,onClose:a}){let{t:s}=(0,v.s)(),[l,d]=(0,i.useState)(null),[c,u]=(0,i.useState)(!0),[p,h]=(0,i.useState)(null),[g,x]=(0,i.useState)(!1),[f,m]=(0,i.useState)("global"),[b,y]=(0,i.useState)(null),[k,w]=(0,i.useState)(null),[j,S]=(0,i.useState)(null),[C,T]=(0,i.useState)(null),[M,R]=(0,i.useState)(null),I=(0,i.useRef)(null),L=l?.projectResourcesLoaded??!0,z=(0,i.useMemo)(()=>l?.servers.find(e=>e.name===p)??null,[l,p]),E=(0,i.useMemo)(()=>["project","global"].map(e=>({scope:e,servers:(l?.servers??[]).filter(t=>t.scope===e)})).filter(e=>e.servers.length>0),[l]),W=t??"",P=(0,i.useCallback)(async()=>{if(W){u(!0),w(null);try{let e=await fetch(`/api/mcp?cwd=${encodeURIComponent(W)}`),t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);d(t),h(e=>e&&t.servers.some(t=>t.name===e)?e:t.servers[0]?.name??null)}catch(e){w(e instanceof Error?e.message:String(e))}finally{u(!1)}}},[W]);(0,i.useEffect)(()=>{n||P()},[n,P]),(0,i.useEffect)(()=>{if(n)return;let e=e=>{let t=e.target;I.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 $=(0,i.useCallback)(async(e,t)=>{if(!W)return null;R(`mcp:${e}`),w(null),S(null);try{let n=await fetch("/api/mcp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:W,action:e,...t})}),r=await n.json();if(!n.ok||r.error)throw Error(r.error??`HTTP ${n.status}`);return d(r),r}catch(e){return w(e instanceof Error?e.message:String(e)),null}finally{R(null)}},[W]),D=(0,i.useCallback)(async e=>{await $(e.disabled?"enable":"disable",{name:e.name,scope:e.scope})&&S(e.disabled?s("mcp.msgEnabled",{name:e.name}):s("mcp.msgDisabled",{name:e.name}))},[$,s]),B=(0,i.useCallback)(async e=>{let t=await $("remove",{name:e.name,scope:e.scope});t&&(h(t.servers[0]?.name??null),S(s("mcp.msgDeleted",{name:e.name})),0===t.servers.length&&x(!0))},[$,s]),A=(0,i.useCallback)(async e=>{let t="project"===e.scope?"global":"project";await $("move",{name:e.name,fromScope:e.scope,toScope:t})&&S(s("mcp.msgMoved",{name:e.name,scope:t}))},[$,s]),F=(0,i.useCallback)(async(e,t)=>{let n=!!b,r=n&&b?b.name:e.trim();await $(n?"update":"add",{name:r,scope:f,def:t})&&(h(r),x(!1),y(null),S(n?s("mcp.msgUpdated",{name:r}):s("mcp.msgAdded",{name:r})))},[f,b,$,s]),N=(0,i.useCallback)(async(e,t)=>{if(!W)return null;try{let n=await fetch("/api/mcp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:W,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}},[W]),H=(0,i.useCallback)(async e=>{T(e.name),w(null),S(null);try{let t=await fetch("/api/mcp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:W,action:"test",name:e.name,scope:e.scope})}),n=await t.json();if(!t.ok||n.error)throw Error(n.error??`HTTP ${t.status}`);S(s("mcp.msgTestResult",{name:e.name,result:n.message??""}))}catch(t){w(s("mcp.msgTestError",{name:e.name,error:t instanceof Error?t.message:String(t)}))}finally{T(null)}},[W,s]),O=null!==M,U=document.documentElement.clientWidth,_=Math.min(780,U-48),V=e?Math.max(24,Math.min(e.left,U-_-24)):U-_-24,q=(0,r.jsxs)("div",{ref:I,role:"dialog","aria-label":s("mcp.sectionTitle"),style:{position:"fixed",zIndex:130,top:e?.bottom??e?.top??46,left:V,width:_,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"})]}),s("mcp.sectionTitle")]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,r.jsx)("button",{onClick:()=>void P(),disabled:c||O,style:tY(c||O),children:s("i18n.refresh")}),(0,r.jsx)("button",{onClick:a,style:tY(!1),children:s("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",width:168,flexShrink:0,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:s("mcp.sectionTitle")}),c?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:"Loading..."}):!l&&k?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"#ef4444"},children:k}):(l?.servers.length??0)===0?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"var(--text-meta)"},children:s("mcp.emptyList")}):E.map(e=>(0,r.jsxs)("div",{style:{marginBottom:6},children:[(0,r.jsx)("div",{style:{padding:"4px 8px 3px",fontSize:10,fontWeight:600,color:"var(--text-meta)",textTransform:"uppercase"},children:e.scope}),e.servers.map(e=>{let t=!g&&p===e.name;return(0,r.jsxs)("div",{onClick:()=>{h(e.name),x(!1),y(null),w(null),S(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?s("mcp.itemDisabled"):s("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:()=>{x(!0),y(null),m("global"),w(null),S(null)},style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,border:"none",width:"100%",cursor:"pointer",background:g?"var(--bg-selected)":"none",color:g?"var(--accent)":"var(--text-meta)",fontSize:12},onMouseEnter:e=>{g||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{g||(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"})]}),s("mcp.addButton")]})})]}),(0,r.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:g?(0,r.jsx)(tQ,{cwd:W,scope:f,projectResourcesLoaded:L,busy:O,actionError:k,initial:b,onScopeChange:m,onSave:(e,t)=>void F(e,t),onFetchDef:N,onCancel:()=>{x(!1),y(null)}}):z?(0,r.jsx)(tZ,{server:z,cwd:W,busy:O||C===z.name,actionError:k,actionMessage:j,onToggle:()=>void D(z),onRemove:()=>void B(z),onMove:()=>void A(z),onTest:()=>void H(z),onEdit:()=>{y(z),x(!0),w(null),S(null)}},z.name):(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-meta)",fontSize:13},children:s("mcp.emptyDetail")})})]})]});return n?null:(0,o.createPortal)(q,document.body)}function t1({cwd:e,busy:t,error:n,onCancel:i,onConfirm:o}){let{t:a}=(0,v.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 t2(e){return"message"===e.type&&"message"in e}function t4(e){let t=e,n=t.branchPreview,r=t2(t.entry)?t.entry:null,i=t.compressedEntryIds?.length??0;for(;1===t.children.length;)t=t.children[0],n??=t.branchPreview,!r&&t2(t.entry)&&(r=t.entry),i+=1+(t.compressedEntryIds?.length??0);return{node:t,skipped:i,branchPreview:n,labelEntry:r??t.entry}}function t8({node:e,activePathIds:t,depth:n,isLast:i,parentLines:o,onSelect:a}){let{node:s,skipped:l,branchPreview:d,labelEntry:c}=t4(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:t2(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)(t8,{node:e,activePathIds:t,depth:n+1,isLast:l===s.children.length-1,parentLines:[...o,!i],onSelect:a},e.entry.id))]})}function t5({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,v.s)(),[f,m]=(0,i.useState)(!1),b=void 0!==l?l:f,y=(0,i.useRef)(null),[k,w]=(0,i.useState)(null);(0,i.useEffect)(()=>{if(!b||!a)return;let e=s?.current??y.current;if(!e)return;let t=()=>{let t=e.getBoundingClientRect(),n=e.closest?.("[data-session-titlebar]"),r=n?.getBoundingClientRect();w({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()},[b,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=t4(e[0]).node;return t.children.length>1?t.children:[]}(e),M=!C&&T.length>0,R=(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"})]}),I=(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:b?"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=b&&k?(0,r.jsx)("div",{style:{position:"fixed",top:k.top,left:k.left,width:k.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)(t8,{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:y,"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:b?"color-mix(in srgb, var(--glass-bg-strong) 60%, transparent)":"transparent",border:"none",borderRadius:6,cursor:"pointer",color:b?"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=b?"var(--accent)":"var(--text-muted)",e.currentTarget.style.background=b?"color-mix(in srgb, var(--glass-bg-strong) 60%, transparent)":"transparent"},title:x("i18n.branches"),"aria-label":x("i18n.branches"),"aria-pressed":b,children:[R,!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:[R,(0,r.jsx)("span",{style:{color:"var(--text)"},children:x("i18n.branches")}),I]}),b&&(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)(t8,{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 t6({onSelectSession:e,onOpenBoard:t}){let{t:n}=(0,v.s)(),s=(0,eY.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),[b,y]=(0,i.useState)(null),k=(0,i.useRef)(null),w=(0,i.useRef)(null),j=(0,i.useRef)(null),S=(0,i.useRef)(null);(0,i.useEffect)(()=>{if(!g||!k.current||s)return;let e=()=>{let e=k.current?.getBoundingClientRect();e&&y({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;w.current?.contains(t)||k.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]),R=(e,t)=>(0,r.jsx)("div",{ref:w,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()&&R(c,p)]}),document.body)]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{ref:k,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&&b&&(0,o.createPortal)((0,r.jsx)("div",{style:{position:"fixed",top:b.top,left:b.left,width:b.width,zIndex:520},children:R(c,p)}),document.body)]})}function t3(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 t7(e,t){try{window.localStorage.setItem(e,String(t))}catch{}}function t9(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=>t3(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)&&t7(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]),R=(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]),I=(0,i.useCallback)(e=>{T(e.pointerId)},[T]),L=(0,i.useCallback)(e=>{T(e.pointerId)},[T]),z=(0,i.useCallback)(e=>{T(e.pointerId)},[T]),E=(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(),E())},[S,k,s,d,E,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&&t7(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:E,separatorProps:{"aria-label":t,"aria-orientation":"vertical","aria-valuemax":b?k():l,"aria-valuemin":d,"aria-valuenow":x,"aria-valuetext":`${x} px`,onDoubleClick:E,onKeyDown:P,onLostPointerCapture:z,onPointerCancel:L,onPointerDown:M,onPointerMove:R,onPointerUp:I,role:"separator",tabIndex:0},width:x}}var ne=n(32782);let nt="bg-image",nn="wallpaper";function nr(){return new Promise((e,t)=>{let n=indexedDB.open("pi-web",1);n.onupgradeneeded=()=>{n.result.objectStoreNames.contains(nt)||n.result.createObjectStore(nt)},n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)})}let ni=null,no=null;async function na(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 ns(e){ni&&URL.revokeObjectURL(ni),no=e&&e.type.startsWith("image/")?"image":null,ni=e?URL.createObjectURL(e):null;let t=document.documentElement.style;return"image"===no&&ni?t.setProperty("--app-bg-image",`url("${ni}")`):t.setProperty("--app-bg-image","none"),{url:ni,kind:no}}async function nl(){try{let e=await nr(),t=await new Promise((t,n)=>{let r=e.transaction(nt,"readonly").objectStore(nt).get(nn);r.onsuccess=()=>t(r.result??null),r.onerror=()=>n(r.error)});if(!t)return{loaded:!1,...ns(null)};return{loaded:!0,...ns(t)}}catch{return{loaded:!1,...ns(null)}}}async function nd(e){let t=await nr();await new Promise((n,r)=>{let i=t.transaction(nt,"readwrite"),o=i.objectStore(nt);e?o.put(e,nn):o.delete(nn),i.oncomplete=()=>n(),i.onerror=()=>r(i.error)})}let nc={repeat:!1,offsetX:0,fill:!1,fillColorLeft:"#000000",fillColorRight:"#000000",bubbleOpacity:44,bubbleBlur:8,scrimAlpha:0,scrimBlur:0},nu="wallpaper-settings";async function np(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 nh=n(7834),ng=n(3099),nx=n(4325);let nf=(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}),nm=(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)(eg.N,{label:"正在加载画布…"})});function nv(){return new URLSearchParams(window.location.search).get("board")}function nb({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 ny(e){document.documentElement.style.setProperty("--bubble-alpha",String(e/100))}function nk(){let e,t,n,s,c,u,m,b,y,k,w,S,C,T=(0,a.useRouter)(),M=(0,a.useSearchParams)(),[R]=(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:I,toggleTheme:L}=(0,eb.D)(),{hasBg:z,ready:E,pick:W,remove:P,kind:$,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 nl().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 na(e);if(!n)return;await nd(n);let r=ns(n);l(r.url),a(r.kind),t(!0)},[]),remove:(0,i.useCallback)(async()=>{await nd(null),ns(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(nu);if(!e)return{...nc};return{...nc,...JSON.parse(e)}}catch{return{...nc}}})());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(nu,JSON.stringify(n))}catch{}return n}),[])}}(z&&"image"===$),F=(0,d.qE)(z&&"image"===$);(0,d.mf)(D,"image"===$,{offsetX:B.offsetX,repeat:B.repeat,fill:B.fill,bubbleBlur:B.bubbleBlur,scrimBlur:B.scrimBlur},F);let[N,H]=(0,i.useState)(!1);(0,i.useEffect)(()=>{if(!N)return;let e=document.body.style.userSelect;document.body.style.userSelect="none";let t=e=>{"Escape"===e.key&&H(!1)};return window.addEventListener("keydown",t),()=>{document.body.style.userSelect=e,window.removeEventListener("keydown",t)}},[N]);let O="light"===I?"theme.light":"theme.dark",{locale:U,setLocale:_,t:V,supportedLocales:q}=(0,v.s)(),J=(0,eY.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:K,onSoundToggle:Y,playDoneSound:G,unlockAudio:X,soundEnabledRef:Z}=(0,ne.G)(),Q=(0,i.useRef)(new Set),ee=(0,i.useRef)(new Set),et=(0,i.useCallback)(e=>{if(e&&e.length>0){let t=ee.current,n=e.every(e=>t.has(e));for(let n of e)t.delete(n);if(n)return}Z.current&&G()},[G,Z]),[er,ei]=(0,i.useState)(null),[eo,ea]=(0,i.useState)(()=>new Set),[es,el]=(0,i.useState)(()=>R.boardId),[ed,ec]=(0,i.useState)(null),eu=(0,i.useCallback)(e=>{ea(t=>t.size===e.size&&[...e].every(e=>t.has(e))?t:e)},[]),ep=(0,i.useCallback)(e=>{el(e),ec(null),ei(null),tV(null),tG([]),nj(null),nT(null),T.replace(`?board=${encodeURIComponent(e)}`,{scroll:!1})},[T]),[eg,ex]=(0,i.useState)(null),[ef,em]=(0,i.useState)("initial"),ev=(0,i.useRef)(null),[ey,ek]=(0,i.useState)(()=>R.requestedCwd?"validating":"idle"),[ew,ej]=(0,i.useState)(null),[eS,eC]=(0,i.useState)(0),[eT,eM]=(0,i.useState)(0),[eR,eI]=(0,i.useState)(0),[eL,ez]=(0,i.useState)(!1),[eE,eW]=(0,i.useState)(0),[eP,e$]=(0,i.useState)(!1),[eD,eB]=(0,i.useState)(!1),[eA,eF]=(0,i.useState)(null),[eN,eH]=(0,i.useState)(!1),[eO,eU]=(0,i.useState)(!1),[e_,eV]=(0,i.useState)(null),[eJ,eG]=(0,i.useState)(!0),[eX,eZ]=(0,i.useState)(!1),[eQ,e0]=(0,i.useState)("top"),[e1,e2]=(0,i.useState)(null),e4=(0,i.useRef)(null),[e8,e5]=(0,i.useState)(!1),e6=(0,i.useRef)(null),[e3,e7]=(0,i.useState)(!1),[e9,te]=(0,i.useState)(!1),[tt,tn]=(0,i.useState)(!1),tr=(0,i.useRef)(null),ti=(0,i.useRef)(null),to=(0,i.useRef)(null),[ta,ts]=(0,i.useState)(null),[tl,td]=(0,i.useState)(!1),tc=(0,i.useRef)(260),tu=(0,i.useRef)(560),tp=(0,i.useCallback)(()=>t3(.42*window.innerWidth,360,640),[]),th=(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:e3,rightPanelWidth:tu.current}),[e3]),tg=(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:eJ,sidebarWidth:tc.current}),[eJ]),tx=t9({ariaLabel:V("layout.resizeSidebar"),cssVariable:"--sidebar-width",defaultWidth:260,getMaxWidth:th,growthDirection:"right",maxWidth:480,minWidth:180,storageKey:"pi-sidebar-width",widthRef:tc}),tf=t9({ariaLabel:V("layout.resizeFilePanel"),cssVariable:"--right-panel-width",defaultWidth:560,getDefaultWidth:tp,getMaxWidth:tg,growthDirection:"left",maxWidth:1200,minWidth:300,storageKey:"pi-right-panel-width",widthRef:tu}),tm=tx.reclampWidth,tv=tf.reclampWidth;(0,i.useEffect)(()=>{J&&eG(!1)},[J]);let tb=(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)),ts({left:n,top:t.bottom}),tn(e=>!e)},[]);(0,i.useEffect)(()=>{if(!tt)return;let e=e=>{tr.current&&!tr.current.contains(e.target)&&to.current&&!to.current.contains(e.target)&&tn(!1)},t=e=>{"Escape"===e.key&&tn(!1)};return document.addEventListener("mousedown",e,!0),document.addEventListener("keydown",t,!0),()=>{document.removeEventListener("mousedown",e,!0),document.removeEventListener("keydown",t,!0)}},[tt]),(0,i.useEffect)(()=>{td(!0)},[]),(0,i.useEffect)(()=>{e3&&(tm(),tv())},[tv,tm,e3]);let ty=(0,i.useRef)(null),tw=(0,i.useRef)(null),tj=(0,i.useRef)(null),tS=(0,i.useRef)(null),[tC,tT]=(0,i.useState)([]),[tM,tR]=(0,i.useState)(null),tI=(0,i.useRef)(null),tz=(0,i.useRef)(null),tE=(0,i.useRef)(!1),tW=(0,i.useCallback)((e,t,n)=>{tT(e),tR(t),tI.current=n},[]),tP=(0,i.useCallback)(e=>{tI.current?.(e)},[]),[t$,tD]=(0,i.useState)(null),[tB,tA]=(0,i.useState)(!1),tF=(0,i.useRef)(null),tN=(0,i.useRef)(0),tH=(0,i.useRef)(null),tO=(0,i.useCallback)(e=>{tD(e),tA(!1)},[]),tU=(0,i.useCallback)(e=>{tN.current+=1,tF.current=e,tA(!1)},[]),[t_,tV]=(0,i.useState)(null),[tJ,tK]=(0,i.useState)(null),[tY,tG]=(0,i.useState)([]),[tX,tZ]=(0,i.useState)(!1),[tQ,t2]=(0,i.useState)(null),t4=(0,i.useRef)(null),t8=(0,i.useRef)(null),t7=(0,i.useCallback)(e=>{tV(e)},[]),nt=(0,i.useCallback)(e=>{tG(e)},[]),nn=(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)&&tG(n.todos)}catch{}},[]),[nr,ni]=(0,i.useState)(null),no=(0,i.useRef)(null),nk=(0,i.useCallback)((e,t)=>{(0,nh.D)(t).then(()=>{no.current&&clearTimeout(no.current),ni(e),no.current=setTimeout(()=>ni(null),1400)})},[]);(0,i.useEffect)(()=>()=>{no.current&&clearTimeout(no.current)},[]);let[nw,nj]=(0,i.useState)(null),nS=(0,i.useCallback)(e=>{nj(e)},[]),[nC,nT]=(0,i.useState)(null),[nM,nR]=(0,i.useState)(null),nI=(0,i.useRef)(null);(0,i.useEffect)(()=>{if("session"!==nC||!er?.id)return void tK(null);let e=!1;return tK(null),fetch(`/api/sessions/${encodeURIComponent(er.id)}`,{cache:"no-store"}).then(e=>e.ok?e.json():null).then(t=>{e||tK(t?.info?.taskName??null)}).catch(()=>{}),()=>{e=!0}},[nC,er?.id]);let nL=(0,i.useCallback)((e,t=!1)=>{J&&eG(!1),tZ(!1),nT(t=>t===e?null:e),J&&t&&te(!0)},[J]),nz=(0,i.useCallback)((e=!1)=>{let t="system"!==nC;if(nL("system",e),!t||tB)return;let n=tF.current;if(!n)return;let r=++tN.current;tA(!0),n().catch(e=>{console.error("Failed to load system prompt:",e)}).finally(()=>{tN.current===r&&tA(!1)})},[nC,tB,nL]),nE=(0,i.useCallback)(()=>{J&&eG(!1),te(!1),tZ(!1),nT("session")},[J]),nW=(0,i.useCallback)(()=>{J&&eG(!1),te(!1),nT(null),!tX&&er?.id&&nn(er.id),tZ(e=>!e)},[J,tX,er?.id,nn]);(0,i.useEffect)(()=>{if(!tX||!t4.current)return;let e=()=>{let e=t4.current;if(!e)return;let t=e.getBoundingClientRect();t2({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=t4.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)}},[tX]),(0,i.useEffect)(()=>{if(!tX)return;let e=e=>{let t=e.target;t4.current?.contains(t)||t8.current?.contains(t)||tZ(!1)},t=e=>{"Escape"===e.key&&tZ(!1)};return document.addEventListener("pointerdown",e,!0),document.addEventListener("keydown",t,!0),()=>{document.removeEventListener("pointerdown",e,!0),document.removeEventListener("keydown",t,!0)}},[tX]),(0,i.useEffect)(()=>{if(!eX)return;let e=()=>{let e="top"===eQ?e4.current:document.getElementById("terminal-bottombar-btn");if(!e)return;let t=e.getBoundingClientRect();e2({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)}},[eX,eQ]);let nP=(0,i.useCallback)(e=>{e0(e),eZ(t=>e!==eQ||!t)},[eQ]);(0,i.useEffect)(()=>{if(!nC)return;let e=e=>{let t=e.target;nI.current?.contains(t)||t.closest?.("button[data-top-panel-trigger]")||nT(null)},t=e=>{"Escape"===e.key&&nT(null)};return document.addEventListener("pointerdown",e,!0),document.addEventListener("keydown",t,!0),()=>{document.removeEventListener("pointerdown",e,!0),document.removeEventListener("keydown",t,!0)}},[nC]);let n$=(0,i.useCallback)(()=>{J&&(nT(null),tZ(!1),te(!1)),eG(e=>!e)},[J]),nD=(0,i.useCallback)(()=>{eG(!1),nT(null),tZ(!1),te(e=>!e)},[]),nB=(0,i.useCallback)(()=>{J&&(eG(!1),nT(null),te(!1)),e7(e=>!e)},[J]);(0,i.useEffect)(()=>{if(!e9)return;let e=e=>{let t=tj.current;t&&e.composedPath().includes(t)||te(!1)},t=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),te(!1))};return document.addEventListener("pointerdown",e,!0),document.addEventListener("keydown",t,!0),()=>{document.removeEventListener("pointerdown",e,!0),document.removeEventListener("keydown",t,!0)}},[e9]),(0,i.useEffect)(()=>{te(!1)},[J,er?.id,ef]),(0,i.useEffect)(()=>{if(!nC||!tw.current)return;let e=()=>{let e=tw.current.getBoundingClientRect();if("language"===nC&&!J&&tS.current){let t=tS.current.getBoundingClientRect(),n=Math.min(176,e.width),r=Math.min(t.left-1,Math.max(e.left,e.right-n));nR({top:e.bottom,left:r,width:n});return}nR({top:e.bottom,left:e.left,width:e.width})};e();let t=new ResizeObserver(e);return t.observe(tw.current),tS.current&&t.observe(tS.current),()=>t.disconnect()},[nC,J]);let[nA,nF]=(0,i.useState)([]),[nN,nH]=(0,i.useState)(null),nO=(0,i.useCallback)((e,t,n)=>{nF(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))},[]),nU=(0,i.useCallback)((e,t)=>{ty.current?.insertText((0,ng.$C)(e,t)),J&&(e7(!1),eG(!1))},[J]),n_=(0,i.useCallback)(e=>{let t=(0,ng.SO)(e);t&&ty.current?.insertText(t),J&&(e7(!1),eG(!1))},[J]),nV=(0,i.useCallback)((e,t,n)=>{ty.current?.insertText((0,ng.sn)(e,t,n)),J&&(e7(!1),eG(!1))},[J]),nq=R.sessionId,[nJ,nK]=(0,i.useState)(null),[nY,nG]=(0,i.useState)(null),nX=(0,i.useRef)(null),[nZ,nQ]=(0,i.useState)(()=>!nq),n0=(0,i.useRef)(!1),n1=(0,i.useRef)(0),n2=(0,i.useCallback)(()=>{n1.current+=1},[]);(0,i.useEffect)(()=>{er&&function(e,t,n=h()){if(n)try{let r=g(n);r[e]=t,n.setItem(p,JSON.stringify(r))}catch{}}(er.projectKey??nX.current??f(er),er.id)},[er]),(0,i.useEffect)(()=>{let e=R.requestedCwd;if(!e)return;let t=new AbortController;return ek("validating"),ej(null),fetch("/api/cwd/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e}),signal:t.signal}).then(async t=>{let n=await t.json().catch(()=>({}));if(!t.ok||!n.cwd)throw Error(n.error??`HTTP ${t.status}`);n0.current=!0;let r=`initial:${e}`;em(r),ev.current=`new:${r}:${n.cwd}`,ex(n.cwd),ek("ready")}).catch(e=>{t.signal.aborted||(ej(e instanceof Error?e.message:String(e)),ek("error"))}),()=>t.abort()},[R]);let n4=(0,i.useCallback)(e=>{if(nv())return;let t=++n1.current,n=function(e,t=h()){if(!t)return null;try{let n=g(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===n1.current&&x(e),null):n.ok?n.json():null).then(n=>{if(t!==n1.current||!n)return;let r=n.info;if(r&&r.id){if(f(r)!==e)return void x(e);ei(r),eM(e=>e+1),new URLSearchParams(window.location.search).get("session")!==r.id&&T.replace(`?session=${encodeURIComponent(r.id)}`,{scroll:!1})}}).catch(()=>{})},[T]),n8=(0,i.useCallback)((e,t,n)=>{n2();let r=eg??nJ;if(nK(e),!e)return;let i=n??t??e,o=nX.current??(er?f(er):null);if(nX.current=i,n0.current){n0.current=!1;return}if(r===e&&o!==i||o===i&&(null!==er||r===e))return;let a="function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;em(a),ev.current=`new:${a}:${e}`,ei(null),ex(t=>t&&t!==e?null:t),eM(e=>e+1),tT([]),tR(null),tD(null),tA(!1),nT(null),o!==i&&(nF([]),nH(null),e7(!1),tE.current?tE.current=!1:n4(i)),T.replace(function(){let e=nv();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})},[nJ,n2,eg,T,er,n4]),n5=(0,i.useCallback)((e,t=!1)=>{if(n2(),ev.current=null,!t&&er){let t=f(er)===f(e);if(er.id===e.id&&t){J&&eG(!1);return}}ex(null),ei(e),el(null),eM(e=>e+1),tD(null),tA(!1),nQ(!0),J&&!t&&eG(!1),t&&(n0.current=!0),t||T.replace(`?session=${encodeURIComponent(e.id)}`,{scroll:!1})},[n2,T,J,er]),n6=(0,i.useCallback)(e=>{tE.current=!0,n5(e)},[n5]),n3=(0,i.useCallback)((e,t)=>{n2(),ev.current=e,em(e),ei(null),ex(t),eM(e=>e+1),tT([]),tR(null),tD(null),tA(!1),nT(null),el(null),J&&eG(!1),T.replace("/",{scroll:!1})},[n2,T,J]),n7=(0,i.useCallback)((e,t)=>{let n=er?.cwd??eg??nJ;n&&(tz.current={taskId:e,projectKey:t},n3(crypto.randomUUID(),n))},[er?.cwd,eg,nJ,n3]),n9=(0,i.useCallback)((e,t)=>{ex(e),nK(e),t&&nG(t)},[]),re=(0,i.useRef)(n9);re.current=n9;let rt=(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&&(ep(t.board.id),ec(e))}).catch(()=>{})},[ep]);(0,l.n)({onNewSession:e=>n3(`kb-${Date.now()}`,e),activeCwd:nJ});let rn=(0,i.useRef)([]),rr=(0,i.useRef)(null),ri=(0,i.useCallback)(e=>{let t=rn.current.find(t=>t.id===e);t?ei(n=>n?.id===e?{...n,...t,transient:t.transient??!1}:n):rr.current=e},[]),ro=(0,i.useCallback)(e=>{rn.current=e;let t=rr.current;if(!t)return;let n=e.find(e=>e.id===t);n&&(rr.current=null,ei(e=>e?.id===t?{...e,...n,transient:n.transient??!1}:e))},[]),ra=(0,i.useCallback)((e,t)=>{eC(e=>e+1),ev.current===t&&(n2(),ev.current=null,ex(null),ei(e),ri(e.id),T.replace(`?session=${encodeURIComponent(e.id)}`,{scroll:!1}),tz.current=null)},[n2,T,ri]),rs=(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,nx.dL)({title:t,body:n,sessionUrl:i,tag:r,onClick:()=>{window.focus(),e&&n5(e)}})};"granted"===Notification.permission?i():"default"===Notification.permission&&Notification.requestPermission().then(e=>{"granted"===e&&i()})},[n5]),rl=(0,i.useCallback)(()=>{eC(e=>e+1),eI(e=>e+1),er&&ri(er.id),(0,nx.SH)()&&rs({targetSession:er,title:er?.name??V("i18n.sessionComplete"),body:V("i18n.taskFinished")})},[rs,ri,er,V]),rd=(0,i.useCallback)(e=>{!(0,nx.SH)()||(0,nx.$N)(e,Q.current)&&rs({targetSession:er,title:V("i18n.attentionNeeded"),body:"custom"===e.method?V("i18n.extensionInputNeeded"):e.title,tag:`pi-extension-ui:${e.id}`})},[rs,er,V]);(0,i.useEffect)(()=>{tZ(!1);let e=er?.id;e&&nn(e)},[er?.id,nn]);let rc=!!(er?.id&&eo.has(er.id));(0,i.useEffect)(()=>{let e,t=er?.id;if(!t||!rc)return;let n=!1,r=async()=>{await nn(t),n||(e=setTimeout(r,6e3))};return r(),()=>{n=!0,e&&clearTimeout(e)}},[er?.id,rc,nn]);let ru=(0,i.useCallback)(()=>{eI(e=>e+1)},[]),rp=(0,i.useCallback)(e=>{n2(),ev.current=null,eC(e=>e+1),eM(e=>e+1),ex(null),ei(t=>({...t??{path:"",cwd:"",created:"",modified:"",messageCount:0,firstMessage:""},id:e,transient:!1})),ri(e),T.replace(`?session=${encodeURIComponent(e)}`,{scroll:!1})},[n2,T,ri]),rh=(0,i.useCallback)(()=>{nQ(!0)},[]),rg=(0,i.useCallback)(e=>{if(n2(),eC(e=>e+1),er?.id===e){let e=er.cwd,t="function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;em(t),ev.current=e?`new:${t}:${e}`:null,ei(null),ex(e??null),eM(e=>e+1),tT([]),tR(null),tD(null),tA(!1),nT(null),T.replace("/",{scroll:!1})}},[n2,er,T]),rx=(0,i.useCallback)((e,t,n)=>{let r=n?.sourceSessionId,i=n?.modeHint,o=`file:${e}`;nF(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})),nH(o),e7(!0),J&&eG(!1)},[J]),rf=(0,i.useCallback)(e=>{rx(e,(0,j.WP)(e),{sourceSessionId:er?.id??null})},[rx,er?.id]);(0,i.useEffect)(()=>{let e=e=>{let t=e.detail;t?.filePath&&rx(t.filePath,(0,j.WP)(t.filePath),{sourceSessionId:t.sessionId})},t=e=>{let t=e.detail;t?.newSessionId&&(eC(e=>e+1),eI(e=>e+1))},n=e=>{let t=e.detail;t?.sessionId&&(eC(e=>e+1),eI(e=>e+1))},r=()=>{eC(e=>e+1)},i=e=>{let t=e.detail;t?.sessionId&&eC(e=>e+1)},o=e=>{let t=e.detail;if(!t?.sessionId)return;let n=ee.current;if(n.add(t.sessionId),n.size>100)for(let e of[...n].slice(0,n.size-100))n.delete(e);eC(e=>e+1),eI(e=>e+1),(0,nx.SH)()&&rs({targetSession:null,title:t.sessionName??V("i18n.sessionComplete"),body:V("i18n.taskFinished")})},a=e=>{let t=e.detail;!t?.sessionId||(0,nx.SH)()&&rs({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&&re.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)}},[rs,rx,V]);let rm=(0,i.useCallback)(e=>{nF(t=>{let n=t.filter(t=>t.id!==e);return 0===n.length&&e7(!1),n}),nH(t=>{if(t!==e)return t;let n=nA.filter(t=>t.id!==e);return n.length>0?n[n.length-1].id:null})},[nA]),rv=(0,i.useCallback)(()=>{er&&window.open(`/api/sessions/${encodeURIComponent(er.id)}/export?inline=1`,"_blank","noopener,noreferrer")},[er]),rb=eg??(null===er&&nJ?nJ:null),ry=null===er&&rb?ef:null;(0,i.useLayoutEffect)(()=>{ev.current=ry},[ry]);let rk=null!==er||null!==rb,rw=er?.cwd??rb,rj=nZ&&!rk;(0,i.useEffect)(()=>{if(eF(null),eH(!1),eV(null),!rw)return;let e=new AbortController;return fetch(`/api/project-trust?cwd=${encodeURIComponent(rw)}`,{signal:e.signal}).then(async e=>{let t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);eF(t)}).catch(e=>{e instanceof DOMException&&"AbortError"===e.name||console.error("Failed to load project trust:",e)}),()=>e.abort()},[rw]);let rS=(0,i.useCallback)(async()=>{if(rw&&!eO){eU(!0),eV(null);try{let e=await fetch("/api/project-trust",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:rw})}),t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);eF(t),eH(!1),eW(e=>e+1),eM(e=>e+1)}catch(e){eV(e instanceof Error?e.message:String(e))}finally{eU(!1)}}},[eO,rw]),rC=nA.find(e=>e.id===nN)??null,rT="Pi Web";(0,i.useEffect)(()=>{let e=()=>{document.title!==rT&&(document.title=rT)};e();let t=new MutationObserver(e);return t.observe(document.head,{childList:!0,subtree:!0,characterData:!0}),()=>t.disconnect()},[rT]);let rM=(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(en,{selectedSessionId:er?.id??null,onSelectSession:n5,onNewSession:n3,initialSessionId:nq,skipInitialProjectSelection:null!==R.requestedCwd,onInitialRestoreDone:rh,refreshKey:eS,onSessionDeleted:rg,selectedCwd:er?.cwd??eg??null,activeWorktreeProject:nY,onCwdChange:n8,onOpenFile:rx,explorerRefreshKey:eR,onExplorerRefresh:ru,onRefresh:()=>eC(e=>e+1),onSessionsLoaded:ro,onAtMention:nU,onAtMentions:n_,onBackgroundTaskDone:et,onRunningSessionIdsChange:eu,onNewSessionFromTask:n7,onOpenBoard:ep,onOpenTaskBoard:rt,onExitBoard:()=>el(null),activeBoardId:es}),(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:()=>ez(!0),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:()=>e$(!0),disabled:!nJ&&!er?.cwd&&!eg,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.plugins"),onClick:()=>eB(!0),disabled:!nJ&&!er?.cwd&&!eg,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:"M9 7V2"}),(0,r.jsx)("path",{d:"M15 7V2"}),(0,r.jsx)("path",{d:"M6 13V8a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v5a6 6 0 0 1-12 0Z"}),(0,r.jsx)("path",{d:"M12 19v3"})]})}].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))})]}),rR=e=>(0,r.jsx)("button",{type:"button",onClick:t=>{let n=t.currentTarget.getBoundingClientRect();L({x:n.left+n.width/2,y:n.top+n.height/2}),e&&te(!0)},title:V(O),"aria-label":V(O),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"===I?(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"===I?(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"})]})}),rI=e=>(0,r.jsx)("button",{ref:to,type:"button",onClick:t=>{tb(t),e&&te(!0)},title:V("bg.title"),"aria-label":V("bg.title"),"aria-haspopup":"menu","aria-expanded":tt,style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:tt?"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)"}})]})}),rL=e=>(0,r.jsx)("button",{ref:tS,type:"button","data-top-panel-trigger":!0,onClick:()=>nL("language",e),title:V("common.language"),"aria-label":V("common.language"),"aria-haspopup":"menu","aria-expanded":"language"===nC,"aria-pressed":"language"===nC,style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"language"===nC?"var(--bg-selected)":"none",border:"none",borderRight:"1px solid var(--border)",color:"language"===nC?"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"===nC?"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"})]})}),rz=e=>rk&&eA?.requiresTrust&&!eA.trusted?(0,r.jsxs)("button",{type:"button",onClick:()=>{eV(null),eH(!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,rE=e=>e||rk?!e&&es?(0,r.jsxs)("div",{style:{display:"flex",alignItems:"stretch",height:"100%"},children:[r$(),rD()]}):(0,r.jsxs)("div",{style:{display:"flex",alignItems:"stretch",height:"100%"},children:[(0,r.jsxs)("button",{type:"button",onClick:()=>{rv(),e&&te(!0)},disabled:!er,title:er?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:er?"var(--text-muted)":"var(--text-dim)",cursor:er?"pointer":"not-allowed",opacity:er?1:.45,flexShrink:0,fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s, opacity 0.1s"},onMouseEnter:e=>{er&&(e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{e.currentTarget.style.color=er?"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:er?"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:()=>nL("branches",!0),title:V("i18n.branches"),"aria-label":V("i18n.branches"),"aria-pressed":"branches"===nC,style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:"100%",padding:0,background:"branches"===nC?"var(--bg-selected)":"none",border:"none",borderTop:"branches"===nC?"2px solid var(--accent)":"2px solid transparent",borderRight:"1px solid var(--border)",color:"branches"===nC?"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:tC.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)(t5,{tree:tC,activeLeafId:tM,onLeafChange:tP,inline:!0,containerRef:tw,open:"branches"===nC,onToggle:()=>nL("branches"),hasSession:!0}),(0,r.jsxs)("button",{ref:tH,type:"button","data-top-panel-trigger":!0,onClick:()=>nz(e),disabled:e&&!rk,title:V("system.prompt"),"aria-label":V("system.prompt"),"aria-pressed":"system"===nC,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,width:e?36:void 0,height:"100%",padding:e?0:"0 12px",background:"system"===nC?"var(--bg-selected)":"none",border:"none",borderTop:"system"===nC?"2px solid var(--accent)":"2px solid transparent",borderRight:"1px solid var(--border)",cursor:e&&!rk?"not-allowed":"pointer",color:"system"===nC?"var(--text)":"var(--text-muted)",opacity:e&&!rk?.45:1,fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s"},onMouseEnter:t=>{(!e||rk)&&(t.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.color="system"===nC?"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:t$?"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&&r$(),!e&&rD(),e&&rR(!0),e&&rL(!0),e&&rI(!0)]}):null,rW=e=>{if(!e&&(!rk||!t_&&!nw))return null;let t=t_?.tokens,n=t_?.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(nw?.contextWindow){let e=nw.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(nw.contextWindow)}`:`? / ${i(nw.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(" | ")}(t_,nw,U),c=e&&e9,u=!!(t&&(t.input>0||t.output>0)||o||l);return(0,r.jsx)("button",{type:"button","data-top-panel-trigger":!0,onClick:()=>nL("session"),disabled:!rk||c,tabIndex:c?-1:void 0,title:d||V("session.title"),"aria-label":V("session.title"),"aria-pressed":"session"===nC,"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"===nC?"var(--bg-selected)":"none",border:"none",borderTop:"session"===nC?"2px solid var(--accent)":"2px solid transparent",fontSize:11,color:"var(--text-muted)",whiteSpace:"nowrap",cursor:rk?"pointer":"default",fontVariantNumeric:"tabular-nums",transition:"color 0.1s, background 0.1s"},onMouseEnter:e=>{rk&&!c&&(e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.color="session"===nC?"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&&rk&&(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]})]})})},rP=e=>{if(0===tY.length)return null;let t=tY.filter(e=>"completed"!==e.status).length,n=tX&&!e;return(0,r.jsxs)("button",{type:"button",ref:t4,onClick:nW,title:V("todo.title"),"aria-label":V("todo.title"),"aria-expanded":tX,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,height:"100%",padding:e?"0 8px":"0 12px",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",fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color=n?"var(--text)":"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)("rect",{x:"3",y:"4",width:"18",height:"16",rx:"3"}),(0,r.jsx)("path",{d:"M8 9h8M8 13h5"})]}),(0,r.jsx)("span",{children:t>0?t:"✓"})]})},r$=()=>{let e=eX&&"top"===eQ;return(0,r.jsxs)("button",{type:"button",id:"terminal-topbar-btn",ref:e4,onClick:()=>nP("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")})]})},rD=()=>(0,r.jsxs)("button",{type:"button",id:"mcp-topbar-btn",ref:e6,onClick:()=>e5(e=>!e),title:"MCP","aria-label":"MCP","aria-expanded":e8,style:{display:"flex",alignItems:"center",justifyContent:"center",width:"auto",height:"100%",padding:"0 10px",gap:5,background:e8?"var(--bg-selected)":"none",border:"none",borderTop:e8?"2px solid var(--accent)":"2px solid transparent",borderRight:"1px solid var(--border)",color:e8?"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:e=>{e.currentTarget.style.color=e8?"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"})]}),rB=e=>{let t=e&&e9;return(0,r.jsx)("button",{type:"button",onClick:nB,disabled:t,tabIndex:t?-1:void 0,"aria-controls":"file-panel","aria-expanded":e3,"aria-hidden":!!t||void 0,title:e3?V("files.hidePanel"):V("files.showPanel"),"aria-label":e3?V("files.hidePanel"):V("files.showPanel"),"data-mobile-toolbar-file":e?"true":void 0,style:{marginLeft:e||t_||nw?0:"auto",display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,visibility:t?"hidden":"visible",pointerEvents:t?"none":"auto",background:e3?"var(--bg-selected)":"none",border:"none",borderLeft:"1px solid var(--border)",color:e3?"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=e3?"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"})]})})},rA=(0,i.useMemo)(()=>{if(er){let e=er.projectRoot??er.cwd,t=e.split(/[\\/]/).filter(Boolean).pop()??e;return er.isWorktree&&er.branch?`${t}\xb7${er.branch}`:t}return rb?rb.split(/[\\/]/).filter(Boolean).pop()??rb:null},[er,rb]);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("style",{children:`
2
2
  @keyframes session-info-pop {
3
3
  0% {
4
4
  opacity: 0;