@surething/cockpit 1.0.178 → 1.0.180

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 (37) hide show
  1. package/.next-prod/BUILD_ID +1 -1
  2. package/.next-prod/app-path-routes-manifest.json +6 -6
  3. package/.next-prod/build-manifest.json +2 -2
  4. package/.next-prod/prerender-manifest.json +3 -3
  5. package/.next-prod/server/app/_global-error.html +2 -2
  6. package/.next-prod/server/app/_global-error.rsc +1 -1
  7. package/.next-prod/server/app/_global-error.segments/_full.segment.rsc +1 -1
  8. package/.next-prod/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  9. package/.next-prod/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  10. package/.next-prod/server/app/_global-error.segments/_head.segment.rsc +1 -1
  11. package/.next-prod/server/app/_global-error.segments/_index.segment.rsc +1 -1
  12. package/.next-prod/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  13. package/.next-prod/server/app/_not-found.html +2 -2
  14. package/.next-prod/server/app/_not-found.rsc +1 -1
  15. package/.next-prod/server/app/_not-found.segments/_full.segment.rsc +1 -1
  16. package/.next-prod/server/app/_not-found.segments/_head.segment.rsc +1 -1
  17. package/.next-prod/server/app/_not-found.segments/_index.segment.rsc +1 -1
  18. package/.next-prod/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  19. package/.next-prod/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  20. package/.next-prod/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  21. package/.next-prod/server/app/api/files/index/route.js +1 -1
  22. package/.next-prod/server/app/api/files/search/route.js +1 -1
  23. package/.next-prod/server/app/project/page.js +1 -1
  24. package/.next-prod/server/app/project/page_client-reference-manifest.js +1 -1
  25. package/.next-prod/server/app-paths-manifest.json +6 -6
  26. package/.next-prod/server/pages/404.html +2 -2
  27. package/.next-prod/server/pages/500.html +2 -2
  28. package/.next-prod/server/server-reference-manifest.json +1 -1
  29. package/.next-prod/static/chunks/app/project/{page-fb1ff1d5d382977d.js → page-5f44bd5f9edf4fdc.js} +1 -1
  30. package/.next-prod/trace +12 -12
  31. package/.next-prod/trace-build +1 -1
  32. package/README.md +8 -0
  33. package/README.zh.md +8 -0
  34. package/package.json +1 -1
  35. package/server.mjs +3 -1
  36. /package/.next-prod/static/{7AsMj_iNkeEBoqPIBmtH6 → Ufk-9jPJfLQ4WiU-nzAhp}/_buildManifest.js +0 -0
  37. /package/.next-prod/static/{7AsMj_iNkeEBoqPIBmtH6 → Ufk-9jPJfLQ4WiU-nzAhp}/_ssgManifest.js +0 -0
@@ -20,6 +20,6 @@ Error: ${e}`,exitCode:1,isRunning:!1,pid:void 0}:r))}})}catch(t){let e=W(d);A(d)
20
20
  Error: ${t.message}`,exitCode:1,isRunning:!1,pid:void 0}:r))}},[k,u,w,r,e,O,W,A,z,n,_]),V=(0,s.useCallback)(e=>{let t=o.find(t=>t.id===e);t?.isRunning&&t.pid&&tO(t.pid)},[o]),K=(0,s.useCallback)(async t=>{let n=o.find(e=>e.id===t);if(!n)return;n.isRunning&&n.pid&&(tO(n.pid),await new Promise(e=>setTimeout(e,200)));let s=n.command.trim().split(/\s+/),a=s[0],i=n.command;k[a]&&(i=k[a]+(s.length>1?" "+s.slice(1).join(" "):"")),A(t);let c=i!==n.command?`→ ${i}
21
21
  `:"";M.current.set(t,c),l(e=>e.map(e=>e.id===t?{...e,output:c,exitCode:void 0,isRunning:!0,pid:void 0}:e));let d=n.usePty||!1,h=R.current.get(t);try{await tI({cwd:n.cwd||u,command:i,commandId:t,tabId:r||"",projectCwd:e,env:w,usePty:d,...d&&h?{cols:h.cols,rows:h.rows}:{},onData:(e,r)=>{if("pid"===e)l(e=>e.map(e=>e.id===t?{...e,pid:r.pid}:e));else if("stdout"===e||"stderr"===e)O(t,r.data);else if("exit"===e){let e=W(t);A(t),l(n=>n.map(n=>n.id===t?{...n,output:e,exitCode:r.code,isRunning:!1,pid:void 0}:n))}},onError:e=>{let r=W(t);A(t),l(n=>n.map(n=>n.id===t?{...n,output:r+`
22
22
  Error: ${e}`,exitCode:1,isRunning:!1,pid:void 0}:n))}})}catch(r){let e=W(t);A(t),l(n=>n.map(n=>n.id===t?{...n,output:e+`
23
- Error: ${r.message}`,exitCode:1,isRunning:!1,pid:void 0}:n))}},[o,k,u,w,r,e,O,W,A]),J=(0,s.useCallback)(async t=>{if(l(e=>e.filter(e=>e.id!==t)),A(t),r)try{await fetch(`/api/terminal/history?cwd=${encodeURIComponent(e)}&tabId=${encodeURIComponent(r)}&commandId=${encodeURIComponent(t)}`,{method:"DELETE"})}catch(e){console.error("Failed to delete command:",e)}},[e,r,A]),X=(0,s.useCallback)((t,n,s)=>{var o;let l=t_(t);if(!l)return;let a=l.parse(n);"cwd"in a&&!a.cwd&&(a.cwd=u);let c={id:(o=l.idPrefix,`${o}-${Date.now()}-${Math.random().toString(36).slice(2,8)}`),_type:t,timestamp:new Date().toISOString(),...a};if(i(e=>[...e,c]),j(c.id),setTimeout(z,100),s){let t=C&&C.length>0?[...C]:D.current.map(e=>e.data.id),n=t.indexOf(s);-1!==n?t.splice(n+1,0,c.id):t.push(c.id),S(t),r&&fetch("/api/terminal/bubble-order",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,tabId:r,order:t})}).catch(()=>{})}if(r){let n=l.toHistory(c);fetch("/api/terminal/history",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,tabId:r,entry:{type:t,id:c.id,timestamp:c.timestamp,...n}})}).catch(e=>console.error(`Failed to save ${t} item:`,e))}},[z,e,r,C]),Y=(0,s.useCallback)(async t=>{let n=a.find(e=>e.id===t);if(i(e=>e.filter(e=>e.id!==t)),j(e=>e===t?null:e),d(e=>{let r=new Set(e);return r.delete(t),r}),n){let e=t_(n._type);e?.onClose?.(n)}r&&fetch(`/api/terminal/history?cwd=${encodeURIComponent(e)}&tabId=${encodeURIComponent(r)}&commandId=${encodeURIComponent(t)}`,{method:"DELETE"}).catch(e=>console.error("Failed to delete plugin item:",e))},[a,e,r]);I.current=X,P.current=q;let Q=(0,s.useCallback)((t,n)=>{r&&fetch("/api/terminal/history",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,tabId:r,id:t,fields:{sleeping:n}})}).catch(()=>{})},[e,r]),G=(0,s.useCallback)(e=>{d(t=>new Set(t).add(e)),Q(e,!0)},[Q]),Z=(0,s.useCallback)(e=>{d(t=>{let r=new Set(t);return r.delete(e),r}),Q(e,!1)},[Q]),ee=(0,s.useCallback)(async t=>{if(S(t),r)try{await fetch("/api/terminal/bubble-order",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,tabId:r,order:t})})}catch{}},[e,r]),et=(0,s.useMemo)(()=>{let e=[...o.map(e=>({type:"command",data:e})),...a.map(e=>({type:e._type,data:e}))];if(!C||0===C.length)return e.sort((e,t)=>new Date(e.data.timestamp).getTime()-new Date(t.data.timestamp).getTime());let t=new Map(C.map((e,t)=>[e,t])),r=[],n=[];for(let s of e)t.has(s.data.id)?r.push(s):n.push(s);return r.sort((e,r)=>t.get(e.data.id)-t.get(r.data.id)),n.sort((e,t)=>new Date(e.data.timestamp).getTime()-new Date(t.data.timestamp).getTime()),[...r,...n]},[o,a,C]);D.current=et,(0,s.useEffect)(()=>{$.current=o.filter(e=>!e.isRunning&&e.command.trim()).map(e=>e.command)},[o]);let er=async()=>{try{let t=new URLSearchParams({cwd:e});r&&t.set("tabId",r);let n=await fetch(`/api/terminal/env?${t}`);if(n.ok){let e=await n.json();y(e.env||{})}}catch(e){console.error("Failed to load env:",e)}},en=async()=>{try{let e=await fetch("/api/terminal/aliases");if(e.ok){let t=await e.json();N(t.aliases||{})}}catch(e){console.error("Failed to load aliases:",e)}},es=async()=>{if(r)try{let t=await fetch(`/api/terminal/bubble-order?cwd=${encodeURIComponent(e)}&tabId=${encodeURIComponent(r)}`);if(t.ok){let e=await t.json();e.order&&e.order.length>0&&S(e.order)}}catch{}};return(0,s.useEffect)(()=>{let e={current:!1};return(async()=>{await H(0),e.current||await U(e)})(),er(),en(),es(),()=>{e.current=!0}},[H,U]),(0,s.useEffect)(()=>()=>{null!==L.current&&cancelAnimationFrame(L.current)},[]),(0,s.useEffect)(()=>()=>{tW()},[]),{commands:o,pluginItems:a,sleepingBubbles:c,consoleItems:et,currentCwd:u,selectedCommandId:v,setSelectedCommandId:j,customEnv:w,setCustomEnv:y,aliases:k,setAliases:N,isLoadingHistory:m,hasMoreHistory:f,currentPage:g,scrollRef:B,commandHistoryRef:$,ptySizeRef:R,executeCommandRef:P,executeCommand:q,interruptCommand:V,rerunCommand:K,deleteCommand:J,addPluginItem:X,closePluginItem:Y,handleBubbleSleep:G,handleBubbleWake:Z,loadHistory:H,scrollToBottom:z,saveBubbleOrder:ee,sendStdin:tB,resizePty:tF}}({cwd:e,initialShellCwd:t,tabId:r,onCwdChange:l}),[D,B]=(0,s.useState)(null),[F,O]=(0,s.useState)(0),[A,W]=(0,s.useState)(0),[z,H]=(0,s.useState)(!0),[_,U]=(0,s.useState)(!1),[q,V]=(0,s.useState)(!1),[K,J]=(0,s.useState)(!1),[X,Y]=(0,s.useState)(!1),Q=(0,s.useRef)(null),G=(0,s.useRef)(null),Z=(0,s.useRef)(null),ee=(0,s.useRef)(!1),et=(0,s.useRef)(null),er=(0,s.useRef)(null),en=(0,s.useRef)([]);(0,s.useEffect)(()=>{en.current=c},[c]);let es=(0,s.useCallback)(()=>{let e=d.current;return!e||e.scrollHeight-e.scrollTop-e.clientHeight<50},[d]),eo=(0,s.useCallback)(()=>{let e=d.current;return!e||e.scrollTop<50},[d]),el=(0,s.useCallback)(()=>{J(!eo()),Y(!es())},[es,eo]),ea=(0,s.useCallback)(()=>{G.current?.scrollIntoView({behavior:"smooth"})},[]),ei=async()=>{try{let t=await fetch(`/api/project-settings?cwd=${encodeURIComponent(e)}`);if(t.ok){let e=await t.json();e.settings?.gridLayout!==void 0&&H(e.settings.gridLayout)}}catch(e){console.error("Failed to load project settings:",e)}},ec=async t=>{try{await fetch("/api/project-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,settings:t})})}catch(e){console.error("Failed to save project settings:",e)}};(0,s.useEffect)(()=>{queueMicrotask(()=>ei())},[]);let ed=(0,s.useCallback)(()=>{ee.current=!0},[]),eu=(0,s.useCallback)((e,t)=>{if(!ee.current)return void e.preventDefault();ee.current=!1,et.current=t,e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",t),e.currentTarget.style.opacity="0.4";let r=e.currentTarget.querySelector("[data-drag-handle]");if(r){let t=r.cloneNode(!0);t.style.cssText="position:fixed;top:-9999px;left:-9999px;width:"+r.offsetWidth+"px;background:var(--card);border-radius:8px;padding:4px 12px;opacity:0.9;",document.body.appendChild(t),e.dataTransfer.setDragImage(t,20,16),requestAnimationFrame(()=>document.body.removeChild(t))}},[]),eh=(0,s.useCallback)((e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect="move",er.current=t},[]),em=(0,s.useCallback)(e=>{e.preventDefault(),e.currentTarget.classList.add("ring-2","ring-brand")},[]),ex=(0,s.useCallback)(e=>{e.currentTarget.classList.remove("ring-2","ring-brand")},[]),ef=(0,s.useCallback)(e=>{e.preventDefault(),e.currentTarget.classList.remove("ring-2","ring-brand")},[]),ep=(0,s.useCallback)(e=>{e.currentTarget.style.opacity="1";let t=et.current,r=er.current;if(et.current=null,er.current=null,!t||!r||t===r)return;let n=en.current.map(e=>e.data.id),s=n.indexOf(t),o=n.indexOf(r);if(-1===s||-1===o)return;let l=[...n];l[s]=r,l[o]=t,T(l)},[T]),eg=(0,s.useCallback)(e=>{B(t=>t===e?null:e)},[]);(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"m"===e.key&&!e.shiftKey&&!e.altKey&&(e.preventDefault(),u&&eg(u))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[u,eg]),(0,s.useEffect)(()=>{let e=d.current;if(!e)return;let t=new ResizeObserver(([e])=>{W(e.contentRect.height)});return t.observe(e),W(e.clientHeight),()=>t.disconnect()},[d]),(0,s.useEffect)(()=>{let e=d.current;if(e)return D?O(e.clientHeight):(e.style.overflow="",O(0)),()=>{e&&(e.style.overflow="")}},[D,d]),(0,s.useEffect)(()=>{let e=d.current;if(!e||!D||!F)return;let t=requestAnimationFrame(()=>{let t=e.querySelector(`[data-bubble-id="${D}"]`);t&&t.scrollIntoView({block:"start"}),e.style.overflow="hidden"});return()=>cancelAnimationFrame(t)},[D,F,d]),(0,s.useEffect)(()=>{let e=e=>{let t=e.detail?.command;t&&v(t)};return window.addEventListener("execute-terminal-command",e),()=>window.removeEventListener("execute-terminal-command",e)},[v]);let eb=A>0?Math.floor((A-32-12)/2-41):void 0;return(0,n.jsxs)("div",{ref:Q,className:"h-full flex flex-col bg-background relative",children:[(0,n.jsx)("div",{ref:d,onScroll:el,className:`flex-1 overflow-y-auto ${D?"":"py-4 px-4"}`,children:0===c.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:i("console.enterCommandOrUrl")}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{ref:G}),$&&(0,n.jsx)("div",{className:"flex justify-center mb-4",children:(0,n.jsx)("button",{onClick:()=>R(P+1),disabled:I,className:"px-4 py-2 text-sm text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors disabled:opacity-50",children:i(I?"console.loadingMore":"console.loadMoreHistory")})}),(0,n.jsx)("div",{className:D?"flex flex-col gap-3":z?"grid grid-cols-2 gap-3":"flex flex-col gap-3",children:c.map(t=>{let s={draggable:!0,onDragStart:e=>eu(e,t.data.id),onDragOver:e=>eh(e,t.data.id),onDragEnter:em,onDragLeave:ex,onDrop:ef,onDragEnd:ep};if("command"===t.type){let o=t.data;return(0,n.jsx)("div",{"data-bubble-id":o.id,className:"group/cmd rounded-lg transition-shadow",...s,children:(0,n.jsx)(td,{commandId:o.id,tabId:r,projectCwd:e,command:o.command,output:o.output,exitCode:o.exitCode,isRunning:o.isRunning,selected:u===o.id,onSelect:()=>{h(o.id)},onInterrupt:o.isRunning?()=>m(o.id):void 0,onStdin:o.isRunning?e=>x(o.id,e):void 0,onDelete:()=>{o.isRunning&&o.pid&&tO(o.pid),f(o.id)},onRerun:()=>p(o.id),timestamp:o.timestamp,usePty:o.usePty,onPtyResize:(e,t)=>{g.current.set(o.id,{cols:e,rows:t}),b(o.id,e,t)},onToggleMaximize:()=>eg(o.id),maximized:D===o.id,expandedHeight:F,bubbleContentHeight:eb,onTitleMouseDown:ed})},o.id)}let o=t_(t.type);if(!o)return null;let l=o.Component,a=t.data;return(0,n.jsx)("div",{"data-bubble-id":a.id,className:"rounded-lg transition-shadow",...s,children:(0,n.jsx)(l,{item:a,selected:u===a.id,maximized:D===a.id,expandedHeight:F,bubbleContentHeight:eb,timestamp:a.timestamp,onSelect:()=>{h(a.id)},onClose:()=>w(a.id),onToggleMaximize:()=>eg(a.id),onTitleMouseDown:ed,extra:{addBrowserItem:(e,t)=>j("browser",e,t),initialSleeping:y.has(a.id),onSleep:k,onWake:N}})},a.id)})}),(0,n.jsx)("div",{ref:Z})]})}),!D&&c.length>0&&(0,n.jsx)(rB,{showTop:K,showBottom:X,onScrollTop:ea,onScrollBottom:C}),(0,n.jsx)(rD,{cwd:e,currentCwd:S,commandHistoryRef:L,gridLayout:z,onGridLayoutChange:e=>{H(e),ec({gridLayout:e})},onExecute:v,onAddPluginItem:j,onShowEnvManager:()=>U(!0),onOpenZsh:()=>v("zsh"),onOpenNote:a}),_&&(0,n.jsx)(tm,{cwd:e,tabId:r,onClose:()=>U(!1),onSave:e=>E(e)}),q&&(0,n.jsx)(tf,{onClose:()=>V(!1),onSave:e=>M(e)})]})}var rO=r(24750);let rA="review-last-viewed";function rW(){try{return JSON.parse(localStorage.getItem(rA)||"{}")}catch{return{}}}function rz(e,t){if(!e.lastCommentAt)return!1;let r=t[e.id];return!r||e.lastCommentAt>r}function rH({cwd:e}){let{t}=(0,o.Bd)(),[r,l]=(0,s.useState)(!1),[a,i]=(0,s.useState)([]),[c,d]=(0,s.useState)(!1),[u,h]=(0,s.useState)(null),[m,x]=(0,s.useState)({}),[f,p]=(0,s.useState)({open:!1,comments:[],title:"",userNameMap:{}}),g=(0,s.useRef)(null),b=(0,s.useRef)(null),[v,j]=(0,s.useState)(null);(0,s.useEffect)(()=>{queueMicrotask(()=>x(rW()))},[]),(0,s.useEffect)(()=>{if(!r)return;let e=e=>{g.current&&!g.current.contains(e.target)&&l(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[r]);let w=(0,s.useCallback)(async()=>{d(!0);try{let e=await fetch("/api/review");if(e.ok){let t=await e.json();i(t.reviews||[])}}catch{}d(!1)},[]);(0,s.useEffect)(()=>{r&&queueMicrotask(()=>w())},[r,w]);let y=(0,s.useCallback)(e=>{let{data:t}=e;t?.some(e=>"review"===e.type)&&w()},[w]);(0,eH.h)({url:`/ws/watch?cwd=${encodeURIComponent(e||"/")}`,onMessage:y,enabled:!!e}),(0,s.useEffect)(()=>{queueMicrotask(()=>w())},[w]);let k=(0,s.useMemo)(()=>a.filter(e=>e.active),[a]),N=(0,s.useMemo)(()=>k.some(e=>rz(e,m)),[k,m]),C=(0,s.useCallback)(e=>{let t;(t=rW())[e]=Date.now(),localStorage.setItem(rA,JSON.stringify(t)),x(rW()),window.open(`${window.location.origin}/review/${e}`,"_blank")},[]),S=(0,s.useCallback)(async(e,t)=>{e.stopPropagation();try{let[e,r]=await Promise.all([fetch(`/api/review/${t}`),fetch("/api/review/users")]);if(!e.ok)return;let{review:n}=await e.json(),s={};if(r.ok){let{users:e}=await r.json();for(let[t,r]of Object.entries(e))s[t]=r.name}p({open:!0,comments:n.comments||[],title:n.title,userNameMap:s})}catch{}},[]),L=(0,s.useCallback)((e,t)=>{b.current=t,e.dataTransfer.effectAllowed="move";let r=e.currentTarget;requestAnimationFrame(()=>r.classList.add("opacity-30"))},[]),E=(0,s.useCallback)(e=>{b.current=null,j(null),e.currentTarget instanceof HTMLElement&&e.currentTarget.classList.remove("opacity-30")},[]),M=(0,s.useCallback)((e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect="move",b.current&&b.current!==t&&j(t)},[]),T=(0,s.useCallback)((e,t)=>{e.preventDefault(),j(null);let r=b.current;b.current=null,r&&r!==t&&i(e=>{let n=[...e],s=n.findIndex(e=>e.id===r),o=n.findIndex(e=>e.id===t);if(-1===s||-1===o)return e;let[l]=n.splice(s,1);return n.splice(o,0,l),fetch("/api/review/order",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({order:n.map(e=>e.id)})}).catch(()=>{}),n})},[]);return(0,n.jsxs)("div",{ref:g,className:"relative",children:[(0,n.jsxs)("button",{onClick:()=>l(e=>!e),className:`relative p-2 rounded-lg transition-colors ${r?"text-foreground bg-accent":"text-muted-foreground hover:text-foreground hover:bg-accent"}`,title:t("review.reviewManagement"),children:[(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"})}),N&&(0,n.jsx)("span",{className:"absolute top-1 right-1 w-2 h-2 bg-red-500 rounded-full"})]}),r&&(0,n.jsxs)("div",{className:"absolute right-0 top-full mt-1 w-64 bg-popover border border-border rounded-lg shadow-xl z-50 overflow-hidden",children:[(0,n.jsxs)("div",{className:"px-3 py-2 border-b border-border flex items-center justify-between",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("span",{className:"text-xs font-medium text-muted-foreground",children:t("review.allReviews")}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground/60 ml-1.5",children:k.length})]}),(0,n.jsx)("button",{onClick:w,className:"p-0.5 text-muted-foreground hover:text-foreground rounded transition-colors",title:t("common.refresh"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})})]}),(0,n.jsx)("div",{className:"max-h-80 overflow-y-auto",children:c&&0===a.length?(0,n.jsx)("div",{className:"px-3 py-4 text-xs text-muted-foreground/50 text-center",children:t("common.loading")}):0===k.length?(0,n.jsx)("div",{className:"px-3 py-4 text-xs text-muted-foreground/50 text-center",children:t("review.noOpenReviews")}):k.map(e=>{let r,s,o,l,a,i=rz(e,m);return(0,n.jsxs)("div",{draggable:!0,onDragStart:t=>L(t,e.id),onDragEnd:E,onDragOver:t=>M(t,e.id),onDrop:t=>T(t,e.id),onMouseEnter:t=>{let r=t.currentTarget.getBoundingClientRect();h({id:e.id,text:e.title,top:r.top+r.height/2,left:r.left})},onMouseLeave:()=>h(t=>t?.id===e.id?null:t),onClick:()=>C(e.id),className:`group px-3 py-2 cursor-pointer border-b transition-colors ${v===e.id?"border-b-brand border-t border-t-transparent":"border-b-border/50"} hover:bg-accent/30`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 min-w-0",children:[(0,n.jsx)("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${i?"bg-red-500":"bg-green-500"}`}),(0,n.jsx)("span",{className:`text-xs truncate flex-1 ${i?"font-medium text-foreground":""}`,children:e.title}),e.commentCount>0&&(0,n.jsx)("button",{onClick:t=>S(t,e.id),className:"flex-shrink-0 p-0.5 rounded text-muted-foreground/0 group-hover:text-muted-foreground/60 hover:!text-brand hover:!bg-brand/10 transition-colors",title:t("review.viewComments"),children:(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2 text-[10px] text-muted-foreground/50 mt-0.5 pl-3",children:[(0,n.jsx)("span",{children:(s=String((r=new Date(e.updatedAt||e.createdAt)).getMonth()+1).padStart(2,"0"),o=String(r.getDate()).padStart(2,"0"),l=String(r.getHours()).padStart(2,"0"),a=String(r.getMinutes()).padStart(2,"0"),`${s}-${o} ${l}:${a}`)}),e.commentCount>0&&(0,n.jsx)("span",{children:t("review.nComments",{count:e.commentCount})})]})]},e.id)})})]}),u&&r&&(0,n.jsx)("div",{className:"fixed z-[60] px-2 py-1 text-xs bg-popover text-popover-foreground border border-border rounded shadow-md whitespace-nowrap pointer-events-none",style:{top:u.top,left:u.left-8,transform:"translate(-100%, -50%)"},children:u.text}),(0,n.jsx)(rO._,{isOpen:f.open,onClose:()=>p(e=>({...e,open:!1})),comments:f.comments,reviewTitle:f.title,userNameMap:f.userNameMap})]})}function r_({cwd:e,currentBranch:t,onSwitched:r}){let{t:l}=(0,o.Bd)(),[a,i]=(0,s.useState)(!1),[c,d]=(0,s.useState)([]),[u,h]=(0,s.useState)(!1),[m,x]=(0,s.useState)(!1),[f,p]=(0,s.useState)(""),b=(0,s.useRef)(null),v=(0,s.useRef)(null),j=(0,s.useCallback)(async()=>{h(!0);try{let t=await fetch(`/api/git/branches?cwd=${encodeURIComponent(e)}`);if(t.ok){let e=await t.json(),r=[...e.local||[],...(e.remote||[]).filter(t=>!e.local.includes(t.replace(/^origin\//,"")))];d(r)}}catch{(0,g.oR)(l("toast.loadBranchFailed"),"error")}finally{h(!1)}},[e]),w=(0,s.useCallback)(()=>{i(!0),p(""),j()},[j]),y=(0,s.useCallback)(()=>{i(!1)},[]);(0,s.useEffect)(()=>{if(!a)return;let e=e=>{b.current&&!b.current.contains(e.target)&&y()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[a,y]),(0,s.useEffect)(()=>{a&&setTimeout(()=>v.current?.focus(),50)},[a]);let k=async t=>{x(!0);try{let n=await fetch("/api/git/worktree",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"checkout",cwd:e,path:e,branch:t})});if(n.ok){let e=t.replace(/^origin\//,"");(0,g.oR)(l("toast.switchedToBranch",{branch:e}),"success"),y(),r()}else{let e=await n.json();(0,g.oR)(e.error||l("toast.switchBranchFailed"),"error")}}catch{(0,g.oR)(l("toast.switchBranchFailed"),"error")}finally{x(!1)}},N=c.filter(e=>e!==t&&e.toLowerCase().includes(f.toLowerCase()));return(0,n.jsxs)("div",{className:"relative",ref:b,children:[(0,n.jsx)("button",{onClick:a?y:w,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:l("git.switchBranch"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 7h12m0 0l-4-4m4 4l-4 4m0 6H4m0 0l4 4m-4-4l4-4"})})}),a&&(0,n.jsxs)("div",{className:"absolute top-full left-0 mt-1 w-64 bg-popover border border-border rounded-lg shadow-lg z-50 overflow-hidden",children:[(0,n.jsx)("div",{className:"p-2 border-b border-border",children:(0,n.jsx)("input",{ref:v,type:"text",value:f,onChange:e=>p(e.target.value),placeholder:l("git.searchBranch"),className:"w-full px-2.5 py-1.5 text-sm bg-muted rounded border-none outline-none placeholder:text-muted-foreground",onKeyDown:e=>{"Escape"===e.key&&y()}})}),(0,n.jsx)("div",{className:"max-h-60 overflow-y-auto p-1",children:u?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:l("common.loading")}):0===N.length?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:f?l("git.noMatchingBranches"):l("git.noBranches")}):N.map(e=>(0,n.jsx)("button",{onClick:()=>k(e),disabled:m,className:"w-full text-left px-2.5 py-1.5 text-sm rounded hover:bg-accent transition-colors truncate disabled:opacity-50",children:(0,n.jsx)("span",{className:e.startsWith("origin/")?"text-muted-foreground":"text-foreground",children:e})},e))})]})]})}function rU({initialCwd:e,activeTab:t,isGitRepo:r,currentBranch:s,onOpenWorktree:l,onOpenProjectSessions:a,onOpenAliasManager:i,onBranchSwitched:c}){let{t:d}=(0,o.Bd)();return(0,n.jsx)("div",{className:"border-b border-border bg-card shrink-0",children:(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 relative",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("img",{src:"/icons/icon-72x72.png",alt:"Cockpit",className:"w-6 h-6 cursor-pointer",title:d("tabManagerTopBar.copyPageUrl"),onClick:()=>{navigator.clipboard.writeText(window.location.href).then(()=>{(0,g.oR)(d("toast.copiedPageUrl"),"success")})}}),e?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-sm text-foreground max-w-md truncate cursor-help",title:`CWD: ${e}`,children:e}),(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(e),(0,g.oR)(d("toast.copiedDirPath"))},className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:d("tabManagerTopBar.copyDirPath"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}):(0,n.jsx)("h1",{className:"text-lg font-semibold text-foreground",children:"Cockpit"})]}),r&&e&&(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsxs)("button",{onClick:l,className:"flex items-center gap-1.5 px-2 py-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"Git Worktrees",children:[(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 17h8m0 0l-4-4m4 4l-4 4M3 7v6a4 4 0 004 4h5"})}),(0,n.jsx)("span",{className:"text-sm",children:s||"main"})]}),(0,n.jsx)(r_,{cwd:e,currentBranch:s,onSwitched:()=>c?.()})]})]}),(0,n.jsx)("div",{className:"absolute left-1/2 -translate-x-1/2",children:(0,n.jsx)(e5,{})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(rH,{cwd:e}),(0,n.jsx)("button",{onClick:()=>window.location.reload(),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:d("tabManagerTopBar.refreshProject"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})}),e&&(0,n.jsx)("button",{onClick:a,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:d("sessions.projectSessions"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),(0,n.jsx)("button",{onClick:async()=>{if(t?.cwd)try{await fetch("/api/open-vscode",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t.cwd})})}catch{}},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:d("tabManagerTopBar.openInVSCode"),children:(0,n.jsx)("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M17.583 2.213L12 7.393 6.417 2.213 1 6.17v11.66l5.417 3.957L12 16.607l5.583 5.18L23 17.83V6.17l-5.417-3.957zM6.417 17.83L3 15.33V8.67l3.417-2.5v11.66zm11.166 0V6.17L21 8.67v6.66l-3.417 2.5z"})})}),(0,n.jsx)("button",{onClick:async()=>{if(t?.cwd)try{await fetch("/api/open-cursor",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t.cwd})})}catch{}},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:d("tabManagerTopBar.openInCursor"),children:(0,n.jsx)("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M4.5 2L20.5 12L4.5 22V2Z"})})}),t?.sessionId&&(0,n.jsx)("button",{onClick:()=>{let e=`claude -r ${t.sessionId}`;navigator.clipboard.writeText(e).then(()=>{(0,g.oR)(d("toast.copiedCommand",{command:e}),"success")})},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:d("chat.copyCommandTooltip",{sessionId:t.sessionId}),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:i,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:d("tabManagerTopBar.aliasesGlobal"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M16 12h-6m-4 0a8 8 0 1116 0 8 8 0 01-16 0zm4 0h.01"})})}),(0,n.jsx)("button",{onClick:()=>window.parent.postMessage({type:"OPEN_TOKEN_STATS"},"*"),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:d("tabManagerTopBar.tokenStats"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"})})}),(0,n.jsx)("button",{onClick:()=>window.open("https://surething.io?from=cockpit","_blank"),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:d("tabManagerTopBar.openSurething"),children:(0,n.jsx)("img",{src:"https://surething.io/logo.png?from=cockpit",alt:"Surething",className:"w-5 h-5 rounded-sm"})})]})]})})}function rq({number:e,isActive:t}){return(0,n.jsxs)("svg",{className:`w-5 h-5 flex-shrink-0 ${t?"text-brand":"text-muted-foreground"}`,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"currentColor",stroke:"none",fontSize:"12",fontWeight:"500",children:e})]})}function rV({tabs:e,activeTabId:t,unreadTabs:r,dragTabIndex:s,dragOverTabIndex:l,isPinned:a,onTogglePin:i,onSwitchTab:c,onCloseTab:d,onNewTab:u,onDragStart:h,onDragOver:m,onDrop:x,onDragEnd:f}){let{t:p}=(0,o.Bd)();return(0,n.jsx)("div",{className:"border-b border-border bg-card shrink-0",children:(0,n.jsxs)("div",{className:"flex items-center px-2 gap-1 overflow-x-auto",children:[e.map((o,u)=>(0,n.jsx)(tw.m,{content:o.title,delay:200,children:(0,n.jsxs)("div",{draggable:!0,onDragStart:()=>h(u),onDragOver:e=>m(e,u),onDrop:()=>x(u),onDragEnd:f,className:`group flex items-center gap-1 px-3 py-1.5 text-sm cursor-pointer rounded-t-lg transition-colors ${o.id===t?"bg-accent text-foreground":"text-muted-foreground hover:bg-secondary"} ${s===u?"opacity-50":""} ${l===u?"border-l-2 border-brand":""}`,onClick:()=>c(o.id),children:[(0,n.jsxs)("div",{className:"relative flex-shrink-0",children:[(0,n.jsx)(rq,{number:u+1,isActive:o.id===t}),o.isLoading&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-orange-9 animate-pulse"}),!o.isLoading&&r.has(o.id)&&o.id!==t&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-red-500"}),i&&a?.(o.id)&&!o.isLoading&&!(r.has(o.id)&&o.id!==t)&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),i(o.id)},className:"absolute -top-1 -right-1 w-3.5 h-3.5 flex items-center justify-center rounded-full bg-card text-amber-500 hover:text-destructive transition-colors",title:p("tabBar.unpin"),children:(0,n.jsx)("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M16 4h-2V2h-4v2H8c-.55 0-1 .45-1 1v4l-2 3v2h5.97v7l1 1 1-1v-7H19v-2l-2-3V5c0-.55-.45-1-1-1z"})})}),i&&!a?.(o.id)&&!o.isLoading&&!(r.has(o.id)&&o.id!==t)&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),i(o.id)},className:"absolute -top-1 -right-1 w-3.5 h-3.5 flex items-center justify-center rounded-full bg-card text-muted-foreground opacity-0 group-hover:opacity-60 hover:!opacity-100 hover:!text-brand transition-all",title:p("tabBar.pin"),children:(0,n.jsx)("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2.5,children:(0,n.jsx)("path",{d:"M16 4h-2V2h-4v2H8c-.55 0-1 .45-1 1v4l-2 3v2h5.97v7l1 1 1-1v-7H19v-2l-2-3V5c0-.55-.45-1-1-1z"})})})]}),(0,n.jsx)("span",{className:"max-w-32 truncate",children:o.title}),e.length>1&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),d(o.id)},className:"ml-1 p-0.5 rounded hover:bg-muted opacity-0 group-hover:opacity-100 transition-opacity",title:p("tabBar.closeTab"),children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})},o.id)),(0,n.jsx)("button",{onClick:u,className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:p("tabBar.newTab"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})})]})})}var rK=r(44810),rJ=r(12651),rX=r(81165),rY=r(16950),rQ=r(11019),rG=r(12612);function rZ({filePath:e}){let[t,r]=(0,s.useState)(null),[o,l]=(0,s.useState)(!0),[a,i]=(0,s.useState)(null),c=(0,s.useRef)(!1),d=ec(e),u=ei(e);if((0,s.useEffect)(()=>{u?l(!1):c.current||(c.current=!0,(async()=>{l(!0),i(null);try{let t=await fetch(`/api/file?path=${encodeURIComponent(e)}`);if(!t.ok)throw Error(`Failed to load file: ${t.statusText}`);let n=await t.json();r(n.content)}catch(e){i(e instanceof Error?e.message:"Unknown error")}finally{l(!1),c.current=!1}})())},[e,u]),a)return(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-red-11",children:a})});if(o)return(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("span",{className:"text-sm text-muted-foreground",children:"Loading..."})});if(ei(e)){let t=`/api/file?path=${encodeURIComponent(e)}&raw=true`;return(0,n.jsx)("div",{className:"flex items-center justify-center h-full overflow-auto",children:(0,n.jsx)("img",{src:t,alt:e.split("/").pop()||"image",className:"max-w-full max-h-full object-contain"})})}return t?d?(0,n.jsx)(r1,{content:t}):(0,n.jsx)(eR,{content:t,filePath:e,showLineNumbers:!0,showSearch:!0,className:"h-full"}):(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("span",{className:"text-sm text-muted-foreground",children:"No content"})})}let r0=[eI.W];function r1({content:e}){let t=(0,s.useRef)(null);return(0,n.jsxs)("div",{className:"h-full flex",children:[(0,n.jsx)(eD.l,{content:e,containerRef:t}),(0,n.jsx)("div",{ref:t,className:"flex-1 overflow-auto p-4",children:(0,n.jsx)(eP.T,{content:e,rehypePlugins:r0})})]})}function r2({title:e,content:t,toolName:r,onClose:l}){let{t:a}=(0,o.Bd)(),i=function(e){try{return JSON.parse(e),!0}catch{return!1}}(t),c=function(e){try{let t=JSON.parse(e);if(t&&"string"==typeof t.file_path&&"string"==typeof t.old_string&&"string"==typeof t.new_string)return t}catch{}return null}(t),d=function(e){try{let t=JSON.parse(e);if(t&&"string"==typeof t.file_path)return t.file_path}catch{let t=e.trim();if(t.startsWith("/")&&!t.includes("\n")&&t.length<500)return t}return null}(t),u=!!c,h=!!d,[m,x]=(0,s.useState)(("Read"===r||"Write"===r)&&h?"file":u?"diff-unified":i?"readable":"json"),f=(0,s.useRef)(null),p=eu(f);(0,s.useEffect)(()=>{let e=e=>{if((e.metaKey||e.ctrlKey)&&"f"===e.key&&"readable"===m&&i){e.preventDefault(),p.open();return}if("Escape"===e.key){if(p.isVisible)return void p.close();document.activeElement instanceof HTMLElement&&document.activeElement.blur(),l()}};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[l,m,i,p]);let b=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:l,children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-[90vh] flex flex-col transition-all",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground",children:e}),d&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(d),(0,g.oR)(a("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:a("common.copyAbsPath"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[i&&(0,n.jsxs)("div",{className:"flex items-center gap-1 bg-accent rounded p-0.5",children:[u&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:()=>x("diff-split"),className:`px-2 py-1 text-xs rounded transition-colors ${"diff-split"===m?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,title:a("diffViewer.sideBySide"),children:"Split"}),(0,n.jsx)("button",{onClick:()=>x("diff-unified"),className:`px-2 py-1 text-xs rounded transition-colors ${"diff-unified"===m?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,title:a("diffViewer.unified"),children:"Unified"})]}),h&&(0,n.jsx)("button",{onClick:()=>x("file"),className:`px-2 py-1 text-xs rounded transition-colors ${"file"===m?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,title:a("diffViewer.previewFile"),children:"File"}),(0,n.jsx)("button",{onClick:()=>x("readable"),className:`px-2 py-1 text-xs rounded transition-colors ${"readable"===m?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:a("common.readable")}),(0,n.jsx)("button",{onClick:()=>x("json"),className:`px-2 py-1 text-xs rounded transition-colors ${"json"===m?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:"JSON"})]}),(0,n.jsx)("button",{onClick:l,className:"p-1 text-slate-9 hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto p-4",children:"file"===m&&d?(0,n.jsx)(rZ,{filePath:d}):"diff-unified"===m&&c?(0,n.jsx)(_,{oldContent:c.old_string,newContent:c.new_string,filePath:c.file_path}):"diff-split"===m&&c?(0,n.jsx)(H,{oldContent:c.old_string,newContent:c.new_string,filePath:c.file_path}):"readable"===m&&i?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(eh,{search:p}),(0,n.jsx)("pre",{ref:f,className:"text-foreground whitespace-pre-wrap break-words",style:{fontSize:"0.8125rem"},children:Z(t)})]}):(0,n.jsx)("pre",{className:"text-foreground whitespace-pre-wrap break-words",style:{fontSize:"0.8125rem"},children:i?function(e){try{let t=JSON.parse(e);return JSON.stringify(t,null,2)}catch{return e}}(t):t})})]})});return(0,n.jsx)(rK.Z,{children:b})}let r5={Read:"\uD83D\uDCC4",Write:"✏️",Edit:"\uD83D\uDCDD",Bash:"\uD83D\uDCBB",Glob:"\uD83D\uDD0D",Grep:"\uD83D\uDD0E",WebFetch:"\uD83C\uDF10",WebSearch:"\uD83D\uDD0D"};function r4({toolCall:e,cwd:t}){let r,{t:l}=(0,o.Bd)(),[a,i]=(0,s.useState)(!1),[c,d]=(0,s.useState)(null),u=r5[e.name]||"\uD83D\uDD27",h=(r=e.input,"Bash"===e.name&&r.command&&"string"==typeof r.command?r.command:"Glob"===e.name&&r.pattern&&"string"==typeof r.pattern||"Grep"===e.name&&r.pattern&&"string"==typeof r.pattern?r.pattern:r.file_path&&"string"==typeof r.file_path?r.file_path:r.path&&"string"==typeof r.path?r.path:null),m="Glob"===e.name||"Grep"===e.name||"Bash"===e.name,x=h?m?h:(e=>{if(t&&e.startsWith(t)){let r=e.slice(t.length);return r.startsWith("/")?r.slice(1):r}let r=e.split("/");return r.length>2?".../"+r.slice(-2).join("/"):e})(h):null,f=t=>{let r="input"===t?l("toolCall.inputParams"):l("toolCall.resultLabel"),n="input"===t?JSON.stringify(e.input,null,2):"string"==typeof e.result?e.result:JSON.stringify(e.result,null,2);d({title:`${e.name}${x?` ${x}`:""} - ${r}`,content:n,toolName:e.name})};return(0,n.jsxs)("div",{className:"my-2 border border-border rounded-lg overflow-hidden bg-secondary",children:[(0,n.jsxs)("button",{onClick:()=>i(!a),className:"w-full px-3 py-2 flex items-center gap-2 text-left hover:bg-accent transition-colors",children:[(0,n.jsx)("span",{className:"text-base",children:u}),(0,n.jsx)("span",{className:"font-medium text-sm text-foreground flex-shrink-0",children:e.name}),x&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground truncate flex-1 min-w-0",title:h||"",children:x}),(0,n.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),h&&(navigator.clipboard.writeText(h),(0,g.oR)(l("common.copiedPath")))},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),h&&(navigator.clipboard.writeText(h),(0,g.oR)(l("common.copiedPath"))))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0 cursor-pointer",title:l("common.copyAbsPath"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}),(0,n.jsxs)("span",{className:"ml-auto flex items-center gap-2",children:[a&&!e.isLoading&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),f("input")},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),f("input"))},className:"text-xs text-brand hover:text-teal-10 cursor-pointer",title:l("toolCall.inputParamsTitle"),children:l("toolCall.input")}),e.result&&(0,n.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),f("result")},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),f("result"))},className:"text-xs text-brand hover:text-teal-10 cursor-pointer",title:l("toolCall.resultTitle"),children:l("toolCall.result")})]}),e.isLoading?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"}):(0,n.jsx)("span",{className:"text-slate-9 text-xs",children:a?"▲":"▼"})]})]}),a&&(0,n.jsxs)("div",{className:"border-t border-border",children:[(0,n.jsxs)("div",{className:"px-3 py-2",children:[(0,n.jsx)("div",{className:"mb-1",children:(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:[l("toolCall.inputParams"),":"]})}),(0,n.jsx)("pre",{className:"text-xs bg-secondary p-2 rounded overflow-x-auto max-h-24 overflow-y-auto text-foreground",children:JSON.stringify(e.input,null,2)})]}),e.result&&(0,n.jsxs)("div",{className:"px-3 py-2 border-t border-border",children:[(0,n.jsx)("div",{className:"mb-1",children:(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:[l("toolCall.resultLabel"),":"]})}),(0,n.jsx)("pre",{className:"text-xs bg-secondary p-2 rounded overflow-x-auto max-h-24 overflow-y-auto text-foreground",children:"string"==typeof e.result?e.result:JSON.stringify(e.result,null,2)})]})]}),c&&(0,n.jsx)(r2,{title:c.title,content:c.content,toolName:c.toolName,onClose:()=>d(null)})]})}var r3=r(48368),r6=r(21362);function r8(e,t){if(t&&e.startsWith(t)){let r=e.slice(t.length);return r.startsWith("/")?r.slice(1):r}return e}function r9({node:e,selectedUid:t,onSelect:r,depth:o=0}){let[l,a]=(0,s.useState)(!0);if(e.isFile&&e.change){let s=t===e.change.uid;return(0,n.jsxs)("button",{onClick:()=>r(e.change),className:`w-full flex items-center gap-1.5 px-2 py-1 text-xs text-left rounded transition-colors ${s?"bg-brand/15 text-brand":"text-foreground hover:bg-accent"}`,style:{paddingLeft:`${12*o+8}px`},"data-tooltip":e.fullPath,children:[(0,n.jsx)(r3.A,{className:"w-3.5 h-3.5 flex-shrink-0 opacity-60"}),(0,n.jsx)("span",{className:"truncate",children:e.name}),(0,n.jsx)("span",{className:`ml-auto text-[10px] flex-shrink-0 ${"write"===e.change.type?"text-green-500":"text-yellow-500"}`,children:"write"===e.change.type?"new":"edit"})]})}return(0,n.jsxs)("div",{children:[(0,n.jsxs)("button",{onClick:()=>a(!l),className:"w-full flex items-center gap-1 px-2 py-1 text-xs text-muted-foreground hover:text-foreground transition-colors",style:{paddingLeft:`${12*o+8}px`},children:[l?(0,n.jsx)(tt.A,{className:"w-3 h-3"}):(0,n.jsx)(r6.A,{className:"w-3 h-3"}),(0,n.jsx)("span",{className:"truncate",children:e.name})]}),l&&e.children.map((e,s)=>(0,n.jsx)(r9,{node:e,selectedUid:t,onSelect:r,depth:o+1},e.isFile&&e.change?e.change.uid:`${e.fullPath}-${s}`))]})}function r7({toolCalls:e,cwd:t,onClose:r}){let{t:l}=(0,o.Bd)(),a=(0,s.useMemo)(()=>(function(e,t){let r=[],n=0;for(let s of e)if("Edit"===s.name){let e=s.input;e.file_path&&"string"==typeof e.old_string&&"string"==typeof e.new_string&&r.push({filePath:r8(e.file_path,t),uid:`change-${n++}`,type:"edit",old_string:e.old_string,new_string:e.new_string})}else if("Write"===s.name){let e=s.input;e.file_path&&"string"==typeof e.content&&r.push({filePath:r8(e.file_path,t),uid:`change-${n++}`,type:"write",old_string:"",new_string:e.content})}return r})(e,t),[e,t]),i=(0,s.useMemo)(()=>(function e(t){return t.map(t=>{if(!t.isFile&&1===t.children.length&&!t.children[0].isFile){let r=t.children[0];return{...r,name:t.name+"/"+r.name,children:e(r.children)}}return{...t,children:e(t.children)}})})(function(e){let t=[];for(let r of e){let e=r.filePath.split("/").filter(Boolean),n=t;for(let t=0;t<e.length;t++){let s=e[t],o=t===e.length-1,l=e.slice(0,t+1).join("/");if(o){let e={name:s,fullPath:l,isFile:!0,children:[],change:r};n.push(e)}else{let e=n.find(e=>e.name===s&&!e.isFile);e||(e={name:s,fullPath:l,isFile:!1,children:[]},n.push(e)),n=e.children}}}return t}(a)),[a]),[c,d]=(0,s.useState)(a[0]||null),[u,h]=(0,s.useState)("unified"),[m,x]=(0,s.useState)(null),f=(0,s.useRef)(null);if((0,s.useEffect)(()=>{let e=f.current;if(!e)return;let t=t=>{let r=t;for(;r&&r!==e;){if(r.dataset.tooltip)return r.dataset.tooltip;r=r.parentElement}return null},r=e=>{let r=t(e.target);x(r?{text:r,x:e.clientX,y:e.clientY}:null)},n=e=>{x(r=>{if(!r)return null;let n=t(e.target);return n?{text:n,x:e.clientX,y:e.clientY}:null})},s=r=>{let n=r.relatedTarget;n&&e.contains(n)&&t(n)||x(null)};return e.addEventListener("mouseover",r),e.addEventListener("mousemove",n),e.addEventListener("mouseout",s),()=>{e.removeEventListener("mouseover",r),e.removeEventListener("mousemove",n),e.removeEventListener("mouseout",s)}},[]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&r()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[r]),0===a.length)return null;let p=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:r,children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-[90vh] flex flex-col transition-all",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsx)("div",{className:"flex items-center gap-2",children:(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground",children:l("diffViewer.fileChanges",{count:a.length})})}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1 bg-accent rounded p-0.5",children:[(0,n.jsx)("button",{onClick:()=>h("unified"),className:`px-2 py-1 text-xs rounded transition-colors ${"unified"===u?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:"Unified"}),(0,n.jsx)("button",{onClick:()=>h("split"),className:`px-2 py-1 text-xs rounded transition-colors ${"split"===u?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:"Split"})]}),(0,n.jsx)("button",{onClick:r,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)(eJ.A,{className:"w-5 h-5"})})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[(0,n.jsx)("div",{ref:f,className:"w-56 flex-shrink-0 border-r border-border overflow-y-auto py-2",children:i.map((e,t)=>(0,n.jsx)(r9,{node:e,selectedUid:c?.uid||"",onSelect:d},e.isFile&&e.change?e.change.uid:`${e.fullPath}-${t}`))}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:c?"unified"===u?(0,n.jsx)(_,{oldContent:c.old_string,newContent:c.new_string,filePath:c.filePath}):(0,n.jsx)(H,{oldContent:c.old_string,newContent:c.new_string,filePath:c.filePath,isNew:"write"===c.type}):(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:l("diffViewer.selectFileToView")})})]})]})});return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(rK.Z,{children:p}),m&&(0,n.jsx)(rK.Z,{children:(0,n.jsx)("div",{className:"fixed z-[9999] px-2 py-1 bg-popover text-popover-foreground text-xs font-mono rounded shadow-lg border border-brand whitespace-nowrap pointer-events-none",style:{left:m.x+12,top:m.y+16},children:m.text})})]})}var ne=r(58515),nt=r(36201),nr=r(55804),nn=r(37618);function ns(e){let t=e.input?.questions||[],r=e.input?.answers||{},n={};if(e.result)try{let t=JSON.parse(e.result);t?.answers&&(n=t.answers)}catch{}return{questions:t,answers:{...r,...n}}}function no(e,t){return`${e}-${t}`}function nl({toolCalls:e,onClose:t}){let{t:r}=(0,o.Bd)(),[l,a]=(0,s.useState)({}),[i,c]=(0,s.useState)({}),[d,u]=(0,s.useState)({}),[h,m]=(0,s.useState)({});(0,s.useEffect)(()=>{let t={};e.forEach((e,r)=>{let{questions:n,answers:s}=ns(e);n.forEach((e,n)=>{let o=s[e.question];if(o){let s=no(r,n);t[s]=o,e.options.some(e=>e.label===o)||(c(e=>({...e,[s]:!0})),u(e=>({...e,[s]:o})))}})}),queueMicrotask(()=>a(t))},[e]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&t()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[t]);let x=e.reduce((e,t)=>{let{questions:r}=ns(t);return e+r.length},0),f=Object.values(h).filter(Boolean).length,p=(0,s.useCallback)((e,t)=>{a(r=>({...r,[e]:t})),c(t=>({...t,[e]:!1}))},[]),b=(0,s.useCallback)(e=>{c(t=>{let r=!t[e];if(r){let t=d[e]||"";t&&a(r=>({...r,[e]:t}))}return{...t,[e]:r}})},[d]),v=(0,s.useCallback)((e,t)=>{u(r=>({...r,[e]:t})),t&&a(r=>({...r,[e]:t}))},[]),j=(0,s.useCallback)(e=>{m(t=>({...t,[e]:!t[e]}))},[]),w=(0,s.useCallback)(()=>{let t=f>0,n=[];e.forEach((e,s)=>{let{questions:o}=ns(e);o.forEach((e,o)=>{let a=no(s,o);if(t&&!h[a])return;let i=l[a];n.push(`Q: ${e.question}`),n.push(`A: ${i||r("askQuestion.notSelected")}`),n.push("")})}),navigator.clipboard.writeText(n.join("\n").trim()),(0,g.oR)(t?r("toast.copiedQA",{count:f}):r("toast.copiedAllQA"))},[e,l,h,f,r]),y=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:t,children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-6xl h-[90vh] flex flex-col overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground",children:r("askQuestion.title")}),(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:[r("askQuestion.nQuestions",{count:x}),f>0&&` \xb7 ${r("askQuestion.checkedN",{count:f})}`]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:w,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:f>0?r("askQuestion.copyChecked",{count:f}):r("askQuestion.copyAll"),children:(0,n.jsx)(e6.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)(eJ.A,{className:"w-5 h-5"})})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto px-6 py-4 space-y-6",children:e.map((t,s)=>{let{questions:o}=ns(t);return o.map((t,a)=>{let c=no(s,a),u=l[c],m=i[c]||!1,x=h[c]||!1;return(0,n.jsxs)("div",{className:"space-y-3",children:[(0,n.jsxs)("div",{className:"flex items-start gap-2",children:[(0,n.jsx)("button",{onClick:()=>j(c),className:"mt-0.5 flex-shrink-0 p-0.5 rounded hover:bg-accent transition-colors",title:r("askQuestion.checkToCopy"),children:x?(0,n.jsx)(ne.A,{className:"w-4 h-4 text-brand"}):(0,n.jsx)(nt.A,{className:"w-4 h-4 text-muted-foreground"})}),t.header&&(0,n.jsx)("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium bg-brand/10 text-brand flex-shrink-0 mt-0.5",children:t.header}),(0,n.jsx)("span",{className:"text-sm font-medium text-foreground",children:t.question})]}),(0,n.jsxs)("div",{className:"space-y-1 ml-7",children:[t.options.map((e,t)=>{let r=u===e.label&&!m;return(0,n.jsxs)("button",{onClick:()=>p(c,e.label),className:`flex items-start gap-2 px-2.5 py-1.5 rounded-md transition-colors w-full text-left cursor-pointer hover:bg-accent/50 ${r?"bg-brand/10 hover:bg-brand/15":""}`,children:[(0,n.jsx)("div",{className:"mt-0.5 flex-shrink-0",children:r?(0,n.jsx)(nr.A,{className:"w-3.5 h-3.5 text-brand"}):(0,n.jsx)("div",{className:"w-3.5 h-3.5 rounded-full border border-muted-foreground"})}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("div",{className:`text-sm ${r?"text-foreground font-medium":"text-foreground"}`,children:e.label}),e.description&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground mt-0.5",children:e.description})]})]},t)}),(0,n.jsxs)("button",{onClick:()=>b(c),className:`flex items-start gap-2 px-2.5 py-1.5 rounded-md transition-colors w-full text-left cursor-pointer hover:bg-accent/50 ${m?"bg-brand/10 hover:bg-brand/15":""}`,children:[(0,n.jsx)("div",{className:"mt-0.5 flex-shrink-0",children:m?(0,n.jsx)(nr.A,{className:"w-3.5 h-3.5 text-brand"}):(0,n.jsx)("div",{className:"w-3.5 h-3.5 rounded-full border border-muted-foreground"})}),(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)(nn.A,{className:"w-3.5 h-3.5 text-muted-foreground"}),(0,n.jsx)("span",{className:"text-sm text-muted-foreground",children:r("askQuestion.custom")})]})]}),m&&(0,n.jsx)("div",{className:"ml-6 mt-1",children:(0,n.jsx)("input",{type:"text",autoFocus:!0,value:d[c]||"",onChange:e=>v(c,e.target.value),placeholder:r("askQuestion.customPlaceholder"),className:"w-full px-3 py-1.5 text-sm bg-background border border-border rounded-md focus:outline-none focus:ring-1 focus:ring-brand text-foreground placeholder:text-muted-foreground"})})]}),(s!==e.length-1||a!==o.length-1)&&(0,n.jsx)("div",{className:"border-b border-border/50 mt-3"})]},c)})})})]})});return(0,n.jsx)(rK.Z,{children:y})}function na({image:e,onClose:t}){let{t:r}=(0,o.Bd)(),s=(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80",onClick:t,children:[(0,n.jsx)("button",{onClick:t,className:"absolute top-4 right-4 w-10 h-10 flex items-center justify-center text-white/80 hover:text-white bg-black/40 hover:bg-black/60 rounded-full transition-colors",children:(0,n.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),(0,n.jsx)("img",{src:`data:${e.media_type};base64,${e.data}`,alt:r("chat.imagePreview"),className:"max-w-[90vw] max-h-[90vh] object-contain",onClick:e=>e.stopPropagation()})]});return(0,n.jsx)(rK.Z,{children:s})}function ni({filePath:e,content:t,cwd:r,onClose:o}){let[l,a]=(0,s.useState)(null);return(0,n.jsx)(rK.Z,{children:(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:o,children:(0,n.jsx)("div",{ref:a,className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-[90vh] flex flex-col relative",onClick:e=>e.stopPropagation(),children:(0,n.jsx)(v,{container:l,children:(0,n.jsx)(eA,{content:t,filePath:e,cwd:r,onClose:o})})})})})}let nc=(0,s.memo)(function({message:e,cwd:t,sessionId:r,onFork:l}){let a,i,c,{t:d}=(0,o.Bd)(),[u,h]=(0,s.useState)(null),[m,x]=(0,s.useState)(!1),[f,p]=(0,s.useState)(!1),[b,v]=(0,s.useState)(!1),j="user"===e.role,w=e.images&&e.images.length>0,y=e.toolCalls?.length||0,k=y>1,N=!!r&&!!t&&!!l,C=(0,s.useMemo)(()=>e.toolCalls?.some(e=>"Edit"===e.name||"Write"===e.name)||!1,[e.toolCalls]),S=(0,s.useMemo)(()=>{if(!e.toolCalls)return null;for(let t=e.toolCalls.length-1;t>=0;t--)if("TodoWrite"===e.toolCalls[t].name)return e.toolCalls[t];return null},[e.toolCalls]),L=(0,s.useMemo)(()=>e.toolCalls?e.toolCalls.filter(e=>"AskUserQuestion"===e.name):[],[e.toolCalls]),E=(0,s.useMemo)(()=>{if(!e.toolCalls)return[];let t=new Set,r=[];for(let n of e.toolCalls)if("Read"===n.name||"Edit"===n.name||"Write"===n.name){let e=n.input.file_path;e&&e.toLowerCase().endsWith(".md")&&!t.has(e)&&(t.add(e),r.push(e))}return r},[e.toolCalls]),[M,T]=(0,s.useState)(null),[$,R]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!M)return void queueMicrotask(()=>R(null));let e=!1;return fetch(`/api/file?path=${encodeURIComponent(M)}`).then(e=>e.ok?e.json():Promise.reject()).then(t=>{e||R(t.content)}).catch(()=>{e||((0,g.oR)(d("toast.readFileFailed"),"error"),T(null))}),()=>{e=!0}},[M]);let P=()=>{e.content&&(navigator.clipboard.writeText(e.content),(0,g.oR)(d("toast.copiedMessage")))},I=()=>{N&&l(e.id)},D=(e=>{if(!e)return"";let t=new Date(e);if(isNaN(t.getTime()))return"";let r=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return`${r}-${n} ${s}:${o}`})(e.timestamp);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:`flex flex-col ${j?"items-end":"items-start"} mb-4 group`,"data-role":e.role,children:[D&&(0,n.jsx)("span",{className:"text-[11px] text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity mb-0.5 px-1",children:D}),(0,n.jsxs)("div",{className:`flex ${j?"justify-end":"justify-start"} w-full`,children:[j&&(0,n.jsxs)("div",{className:"self-start mt-2 mr-1 flex flex-col gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.content&&(0,n.jsx)("button",{onClick:P,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:d("chat.copyMessage"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),N&&(0,n.jsx)("button",{onClick:I,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:d("chat.forkSession"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"18",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("path",{d:"M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9"}),(0,n.jsx)("path",{d:"M12 12v3"})]})})]}),(0,n.jsxs)("div",{className:`max-w-[80%] ${j?"bg-accent text-foreground border border-brand rounded-2xl rounded-br-md":"bg-accent text-foreground dark:text-slate-11 rounded-2xl rounded-bl-md"} px-4 py-2`,children:[w&&(0,n.jsx)("div",{className:`flex flex-wrap gap-2 ${e.content?"mb-2":""}`,children:e.images.map((e,t)=>(0,n.jsx)("div",{className:"relative w-16 h-16 rounded-lg overflow-hidden border border-white/20 cursor-pointer hover:opacity-90 transition-opacity",onClick:()=>h(e),children:(0,n.jsx)("img",{src:`data:${e.media_type};base64,${e.data}`,alt:d("chat.imageN",{index:t+1}),className:"w-full h-full object-cover"})},t))}),e.content&&(0,n.jsxs)("div",{className:"break-words",children:[(0,n.jsx)(eP.T,{content:e.content,isUser:j,isStreaming:e.isStreaming}),e.isStreaming&&(0,n.jsx)("span",{className:"inline-block w-2 h-4 ml-1 bg-current animate-pulse"})]}),S&&(i=(a=S.input?.todos||[]).filter(e=>"completed"===e.status).length,c=a.length,(0,n.jsx)("div",{className:`${e.content||w?"mt-2":""}`,children:(0,n.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden bg-secondary/50 px-3 py-2 space-y-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-1.5",children:[(0,n.jsx)("div",{className:"flex-1 h-1 bg-secondary rounded-full overflow-hidden",children:(0,n.jsx)("div",{className:"h-full bg-green-500 rounded-full transition-all duration-300",style:{width:`${c>0?i/c*100:0}%`}})}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:[i,"/",c]})]}),a.map((e,t)=>(0,n.jsxs)("div",{className:`flex items-center gap-1.5 ${"completed"===e.status?"opacity-50":""}`,children:["completed"===e.status?(0,n.jsx)(rJ.A,{className:"w-3 h-3 text-green-500 flex-shrink-0"}):"in_progress"===e.status?(0,n.jsx)(rX.A,{className:"w-3 h-3 text-brand flex-shrink-0 animate-spin"}):(0,n.jsx)(rY.A,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"}),(0,n.jsx)("span",{className:`text-xs truncate ${"completed"===e.status?"text-muted-foreground":"text-foreground"}`,children:"in_progress"===e.status&&e.activeForm?e.activeForm:e.content})]},t))]})})),E.length>0&&(0,n.jsx)("div",{className:`${e.content||w||S?"mt-2":""}`,children:(0,n.jsx)("div",{className:"border border-border rounded-lg overflow-hidden bg-secondary/50 px-3 py-2 space-y-0.5",children:E.map(e=>(0,n.jsxs)("button",{onClick:()=>T(e),className:"flex items-center gap-1.5 w-full text-left hover:bg-accent rounded px-1 py-0.5 transition-colors group/md",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground group-hover/md:text-foreground truncate",children:e.split("/").pop()})]},e))})}),e.toolCalls&&e.toolCalls.length>0&&(0,n.jsx)("div",{className:`${e.content||w?"mt-2":""}`,children:k?(0,n.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden bg-secondary",children:[(0,n.jsxs)("div",{className:"flex items-center",children:[(0,n.jsxs)("button",{onClick:()=>x(!m),className:"flex-1 px-3 py-2 flex items-center gap-2 text-left hover:bg-accent transition-colors active:bg-muted",children:[(0,n.jsx)("span",{className:"text-lg",children:"\uD83D\uDD27"}),(0,n.jsx)("span",{className:"font-medium text-foreground",children:d("chat.toolCalls",{count:y})}),(0,n.jsx)("span",{className:"ml-auto text-muted-foreground text-sm",children:m?d("chat.collapse"):d("chat.expand")})]}),L.length>0&&(0,n.jsx)("button",{onClick:()=>v(!0),className:"px-3 py-2 text-muted-foreground hover:text-foreground hover:bg-accent transition-colors border-l border-border",title:d("chat.viewQuestions"),children:(0,n.jsx)(rQ.A,{className:"w-4 h-4"})}),C&&(0,n.jsx)("button",{onClick:()=>p(!0),className:"px-3 py-2 text-muted-foreground hover:text-foreground hover:bg-accent transition-colors border-l border-border",title:d("chat.viewAllFileChanges"),children:(0,n.jsx)(rG.A,{className:"w-4 h-4"})})]}),m&&(0,n.jsx)("div",{className:"border-t border-border p-2 space-y-1",children:e.toolCalls.map((e,r)=>(0,n.jsx)(r4,{toolCall:e,cwd:t},`${e.id}-${r}`))})]}):e.toolCalls.map((e,r)=>(0,n.jsx)(r4,{toolCall:e,cwd:t},`${e.id}-${r}`))})]}),!j&&(0,n.jsxs)("div",{className:"self-start mt-2 ml-1 flex flex-col gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.content&&(0,n.jsx)("button",{onClick:P,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:d("chat.copyMessage"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),N&&(0,n.jsx)("button",{onClick:I,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:d("chat.forkSession"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"18",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("path",{d:"M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9"}),(0,n.jsx)("path",{d:"M12 12v3"})]})})]})]})]}),u&&(0,n.jsx)(na,{image:u,onClose:()=>h(null)}),f&&e.toolCalls&&(0,n.jsx)(r7,{toolCalls:e.toolCalls,cwd:t,onClose:()=>p(!1)}),b&&L.length>0&&(0,n.jsx)(nl,{toolCalls:L,onClose:()=>v(!1)}),M&&null!==$&&(0,n.jsx)(ni,{filePath:M,content:$,cwd:t||"",onClose:()=>T(null)})]})}),nd=(0,s.forwardRef)(function({messages:e,isLoading:t,cwd:r,sessionId:l,hasMoreHistory:a,isLoadingMore:i,onLoadMore:c,onFork:d,isActive:u=!0,onContentSearch:g},b){let{t:v}=(0,o.Bd)(),j=(0,s.useRef)(null),w=(0,s.useRef)(null),y=(0,s.useRef)(null),k=(0,s.useRef)(null),[N,E]=(0,s.useState)(null),[M,T]=(0,s.useState)(!0),[$,R]=(0,s.useState)(!1),[P,I]=(0,s.useState)(!1);(0,s.useEffect)(()=>{E(k.current)},[]);let{isSearchVisible:D,searchQuery:B,setSearchQuery:F,matches:O,currentMatchIndex:W,goToNextMatch:z,goToPrevMatch:H,closeSearch:_,searchInputRef:U,handleSearchKeyDown:q}=function(e){let[t,r]=(0,s.useState)(!1),[n,o]=(0,s.useState)(""),[l,a]=(0,s.useState)([]),[i,c]=(0,s.useState)(0),d=(0,s.useRef)(null),u=(0,s.useRef)([]),h=(0,s.useCallback)(()=>{let t=e.current;t&&(t.querySelectorAll("mark.chat-search-match, mark.chat-search-current").forEach(e=>{let t=e.parentNode;t&&(t.replaceChild(document.createTextNode(e.textContent||""),e),t.normalize())}),u.current=[])},[e]),m=(0,s.useCallback)(t=>{if(h(),!t||!e.current){a([]),c(0);return}let r=[],n=[],s=t.toLowerCase();e.current.querySelectorAll("[data-message-id]").forEach(e=>{let o,l=e.getAttribute("data-message-id")||"",a=0,i=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,null),c=[];for(;o=i.nextNode();)c.push(o);for(let e of c){let o=(e.textContent||"").toLowerCase(),i=0,c=[];for(;;){let e=o.indexOf(s,i);if(-1===e)break;c.push({start:e,end:e+t.length}),i=e+1}if(0!==c.length)for(let t=c.length-1;t>=0;t--){let s=c[t];e.splitText(s.end);let o=e.splitText(s.start),i=document.createElement("mark");i.className="chat-search-match",i.textContent=o.textContent,o.parentNode.replaceChild(i,o),r.push({messageId:l,markIndex:a}),n.push(i),a++}}}),r.reverse(),n.reverse(),u.current=n,a(r),c(r.length>0?0:-1)},[e,h]);(0,s.useEffect)(()=>{queueMicrotask(()=>m(n))},[n,m]),(0,s.useEffect)(()=>{let e=u.current;e.forEach((e,t)=>{e.className=t===i?"chat-search-current":"chat-search-match"}),i>=0&&i<e.length&&e[i].scrollIntoView({behavior:"smooth",block:"center"})},[i,l]);let x=(0,s.useCallback)(()=>{0!==l.length&&c(e=>(e+1)%l.length)},[l.length]),f=(0,s.useCallback)(()=>{0!==l.length&&c(e=>(e-1+l.length)%l.length)},[l.length]),p=(0,s.useCallback)(()=>{r(!0),setTimeout(()=>d.current?.focus(),0)},[]),g=(0,s.useCallback)(()=>{r(!1),o(""),h(),a([]),c(0)},[h]),b=(0,s.useCallback)(e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?f():x()),"Escape"===e.key&&g()},[x,f,g]);return(0,s.useEffect)(()=>{let t=e.current;if(!t)return;let r=e=>{(e.metaKey||e.ctrlKey)&&"f"===e.key&&(e.preventDefault(),e.stopPropagation(),p())};return t.addEventListener("keydown",r),()=>t.removeEventListener("keydown",r)},[e,p]),{isSearchVisible:t,searchQuery:n,setSearchQuery:o,matches:l,currentMatchIndex:i,goToNextMatch:x,goToPrevMatch:f,openSearch:p,closeSearch:g,searchInputRef:d,handleSearchKeyDown:b}}(k),V=C(),K=(0,s.useRef)(null),J=(0,s.useRef)(()=>{}),{addComment:X,refresh:Y}=p({cwd:r||"",filePath:x}),[Q,G]=(0,s.useState)(null),[Z,ee]=(0,s.useState)(null),et=(0,s.useCallback)(e=>{if(Q||Z)return;let t=window.getSelection();if(!t||t.isCollapsed||!t.rangeCount){K.current=null,J.current();return}let r=t.toString().trim();if(!r){K.current=null,J.current();return}let n=t.anchorNode instanceof HTMLElement?t.anchorNode:t.anchorNode?.parentElement;if(n?.closest('[data-role="user"]')){K.current=null,J.current();return}K.current={x:e.clientX,y:e.clientY,range:{start:0,end:0},selectedText:r},J.current()},[Q,Z]),er=(0,s.useCallback)(e=>{let t=e.target;!(t.closest(".floating-toolbar")||t.closest('[class*="z-[200]"]'))&&K.current&&(K.current=null,J.current())},[]),en=(0,s.useCallback)(()=>{let e=K.current;e&&(G({x:e.x,y:e.y,text:e.selectedText}),K.current=null,J.current(),window.getSelection()?.removeAllRanges())},[]),es=(0,s.useCallback)(()=>{let e=K.current;e&&(ee({x:e.x,y:e.y,text:e.selectedText}),K.current=null,J.current(),window.getSelection()?.removeAllRanges())},[]),eo=(0,s.useCallback)(()=>{let e=K.current;if(!e||!g)return;let t=e.selectedText.trim();K.current=null,J.current(),window.getSelection()?.removeAllRanges(),t&&g(t)},[g]),el=(0,s.useCallback)(async e=>{Q&&(await X(0,0,e,Q.text),G(null))},[Q,X]),ea=(0,s.useCallback)(async e=>{if(Z&&V&&r)try{let t=(await h(r)).map(e=>({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0}));t.push({filePath:x,startLine:0,endLine:0,codeContent:Z.text});let n=f(t,e);V.sendMessage(n),await m(r),Y(),ee(null)}catch(e){console.error("Failed to send to AI:",e)}},[Z,V,r,Y]),ei=(0,s.useMemo)(()=>{let t=new Set;return e.filter(e=>!t.has(e.id)&&(t.add(e.id),!0))},[e]),ec=(0,s.useRef)(0),ed=(0,s.useRef)(!1),eu=(0,s.useCallback)(()=>{let e=y.current;return!e||e.scrollHeight-e.scrollTop-e.clientHeight<50},[]),eh=(0,s.useCallback)(()=>{let e=y.current;return!e||e.scrollTop<50},[]),em=(0,s.useCallback)(()=>{let e=eu(),t=eh();if(T(e),R(!t),I(!e),t&&a&&!i&&c){let e=y.current;e&&(ec.current=e.scrollHeight,ed.current=!0),c()}},[eu,eh,a,i,c]),ex=(0,s.useCallback)(()=>{w.current?.scrollIntoView({behavior:"smooth"})},[]),ef=(0,s.useCallback)(()=>{j.current?.scrollIntoView({behavior:"smooth"})},[]),ep=(0,s.useCallback)(e=>{let t=y.current;if(!t)return;let r=t.querySelector(`[data-message-id="${e}"]`);r&&(r.scrollIntoView({behavior:"smooth",block:"center"}),r.classList.add("ring-2","ring-brand","ring-offset-2"),setTimeout(()=>{r.classList.remove("ring-2","ring-brand","ring-offset-2")},2e3))},[]);(0,s.useImperativeHandle)(b,()=>({scrollToMessage:ep}),[ep]);let eg=(0,s.useRef)(0),eb=(0,s.useRef)(!0);(0,s.useEffect)(()=>{let t=eg.current,r=e.length;eg.current=r,!eb.current&&M&&r>t&&j.current?.scrollIntoView({behavior:"smooth"})},[e,M]),(0,s.useEffect)(()=>{M&&t&&j.current?.scrollIntoView({behavior:"smooth"})},[t,M]),(0,s.useEffect)(()=>{if(ed.current&&!i){let e=y.current;if(e){let t=e.scrollHeight-ec.current;e.scrollTop=t,ed.current=!1}}},[e,i]);let ev=(0,s.useRef)(!1);return(0,s.useEffect)(()=>{u&&ev.current&&e.length>0&&(ev.current=!1,j.current?.scrollIntoView({behavior:"instant"}))},[u,e.length]),(0,s.useEffect)(()=>{eb.current&&e.length>0&&(eb.current=!1,u?j.current?.scrollIntoView({behavior:"instant"}):ev.current=!0)},[e.length,u]),(0,n.jsxs)("div",{ref:k,className:"relative flex-1 min-h-0 overflow-hidden flex flex-col outline-none",tabIndex:-1,onMouseUp:et,onMouseDown:er,children:[D&&(0,n.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-2 px-3 py-2 bg-secondary border-b border-border",children:[(0,n.jsx)("input",{ref:U,type:"text",value:B,onChange:e=>F(e.target.value),onKeyDown:q,placeholder:v("codeViewer.searchChat"),className:"flex-1 max-w-xs px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:O.length>0?`${W+1}/${O.length}`:v("common.noMatch")}),(0,n.jsx)("button",{onClick:H,disabled:0===O.length,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:v("codeViewer.prevShiftEnter"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"})})}),(0,n.jsx)("button",{onClick:z,disabled:0===O.length,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:v("codeViewer.nextEnter"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})}),(0,n.jsx)("button",{onClick:_,className:"p-1 rounded hover:bg-accent",title:v("codeViewer.closeEsc"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{ref:y,onScroll:em,className:"relative flex-1 min-h-0 overflow-y-auto p-4",children:0!==e.length||t?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{ref:w}),a&&(0,n.jsx)("div",{className:"flex justify-center py-3",children:i?(0,n.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground text-sm",children:[(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"}),(0,n.jsx)("span",{children:v("chat.loadMoreHistory")})]}):(0,n.jsx)("button",{onClick:c,className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:v("chat.scrollUpForMore")})}),ei.map(e=>(0,n.jsx)("div",{"data-message-id":e.id,className:"transition-[box-shadow] duration-300",children:(0,n.jsx)(nc,{message:e,cwd:r,sessionId:l,onFork:d})},e.id)),t&&(0,n.jsx)("div",{className:"flex justify-start mb-4",children:(0,n.jsx)("div",{className:"bg-accent rounded-2xl rounded-bl-md px-4 py-3",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,n.jsx)("span",{className:"inline-block w-5 h-5 border-2 border-brand border-t-transparent rounded-full animate-spin"}),(0,n.jsx)("span",{className:"text-sm",children:v("chat.claudeThinking")})]})})}),(0,n.jsx)("div",{ref:j})]}):(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-slate-9",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("div",{className:"text-4xl mb-4",children:"\uD83D\uDCAC"}),(0,n.jsx)("div",{children:v("chat.startConversation")})]})})}),$&&e.length>0&&(0,n.jsx)("button",{onClick:ex,className:"absolute top-2 left-1/2 -translate-x-1/2 p-2 bg-card text-muted-foreground hover:text-foreground shadow-md rounded-full transition-all hover:shadow-lg active:scale-95",title:v("chat.jumpToStart"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"})})}),P&&e.length>0&&(0,n.jsx)("button",{onClick:ef,className:"absolute bottom-2 left-1/2 -translate-x-1/2 p-2 bg-card text-muted-foreground hover:text-foreground shadow-md rounded-full transition-all hover:shadow-lg active:scale-95",title:v("chat.jumpToLatest"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})}),N&&(0,n.jsx)(A,{floatingToolbarRef:K,bumpRef:J,container:N,onAddComment:en,onSendToAI:es,onSearch:g?eo:void 0,isChatLoading:V?.isLoading}),Q&&N&&(0,n.jsx)(S,{x:Q.x,y:Q.y,range:{start:0,end:0},codeContent:Q.text,container:N,onSubmit:el,onClose:()=>G(null)}),Z&&N&&(0,n.jsx)(L,{x:Z.x,y:Z.y,range:{start:0,end:0},codeContent:Z.text,container:N,onSubmit:ea,onClose:()=>ee(null),isChatLoading:V?.isLoading})]})});function nu({image:e,onClose:t}){let{t:r}=(0,o.Bd)(),s=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-4",onClick:t,children:(0,n.jsxs)("div",{className:"relative max-w-[90vw] max-h-[90vh]",children:[(0,n.jsx)("img",{src:e.preview,alt:r("imagePreview.previewImage"),className:"max-w-full max-h-[90vh] object-contain rounded-lg",onClick:e=>e.stopPropagation()}),(0,n.jsx)("button",{onClick:t,className:"absolute -top-3 -right-3 w-8 h-8 bg-card text-foreground hover:text-foreground rounded-full shadow-lg flex items-center justify-center transition-colors",title:r("common.close"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})});return(0,n.jsx)(rK.Z,{children:s})}function nh({images:e,onRemove:t,disabled:r}){let{t:l}=(0,o.Bd)(),[a,i]=(0,s.useState)(null);return 0===e.length?null:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"flex flex-wrap gap-2 p-2 bg-secondary border-b border-border",children:e.map(e=>(0,n.jsxs)("div",{className:"relative group w-16 h-16 rounded-lg overflow-hidden border border-border cursor-pointer",onClick:()=>i(e),children:[(0,n.jsx)("img",{src:e.preview,alt:l("imagePreview.previewImage"),className:"w-full h-full object-cover hover:opacity-90 transition-opacity"}),(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),t(e.id)},className:"absolute top-0 right-0 w-5 h-5 bg-black/60 hover:bg-black/80 text-white text-xs flex items-center justify-center rounded-bl-lg opacity-0 group-hover:opacity-100 transition-opacity",title:l("imagePreview.deleteImage"),children:"✕"})]},e.id))}),a&&(0,n.jsx)(nu,{image:a,onClose:()=>i(null)})]})}var nm=r(28147);let nx=(0,s.memo)(function({onSend:e,disabled:t,cwd:r,onShowGitStatus:l,onShowComments:a,onShowUserMessages:i,onOpenNote:c,onCreateScheduledTask:d}){let{t:u}=(0,o.Bd)(),[h,m]=(0,s.useState)(""),[x,f]=(0,s.useState)([]),[p,b]=(0,s.useState)([]),[v,j]=(0,s.useState)(!1),[w,y]=(0,s.useState)(0),[k,N]=(0,s.useState)(!1),C=(0,s.useRef)(null),S=(0,s.useRef)(null),L=(0,s.useCallback)(()=>{let e=C.current;if(!e)return;e.style.height="auto";let t=Math.max(38,Math.min(e.scrollHeight,200));e.style.height=`${t}px`},[]);(0,s.useLayoutEffect)(()=>{L()},[h,L]),(0,s.useEffect)(()=>{(async()=>{try{let e=r?`/api/commands?cwd=${encodeURIComponent(r)}`:"/api/commands",t=await fetch(e);if(t.ok){let e=await t.json();b(e)}}catch(e){console.error("Failed to load commands:",e)}})()},[r]);let E=(0,s.useMemo)(()=>{if(!h.startsWith("/"))return[];let e=h.toLowerCase();return p.filter(t=>t.name.toLowerCase().startsWith(e))},[h,p]),M=!k&&h.startsWith("/")&&E.length>0,T=(0,s.useRef)(h);(0,s.useLayoutEffect)(()=>{T.current!==h&&(queueMicrotask(()=>y(0)),k&&queueMicrotask(()=>N(!1)),T.current=h)},[h,k]),(0,s.useLayoutEffect)(()=>{if(M&&S.current){let e=S.current.children[w];e&&e.scrollIntoView({block:"nearest"})}},[w,M]);let $=(0,s.useCallback)(()=>{let r=h.trim();(r||x.length>0)&&!t&&(e(r,x.length>0?x:void 0),m(""),f([]),C.current&&(C.current.style.height="auto"))},[h,x,t,e]),R=(0,s.useCallback)(e=>{m(e.name+" "),C.current?.focus()},[]),P=(0,s.useCallback)(e=>{if(!e.nativeEvent.isComposing){if(M&&E.length>0){if("ArrowDown"===e.key){e.preventDefault(),y(e=>(e+1)%E.length);return}if("ArrowUp"===e.key){e.preventDefault(),y(e=>(e-1+E.length)%E.length);return}if("Enter"===e.key){e.preventDefault(),R(E[w]);return}if("Escape"===e.key){e.preventDefault(),N(!0);return}if("Tab"===e.key){e.preventDefault(),R(E[w]);return}}"Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),$())}},[M,E,w,R,$]),I=(0,s.useCallback)(e=>{let t=e.clipboardData?.items;if(!t)return;let r=["image/png","image/jpeg","image/webp","image/gif"];for(let n of Array.from(t)){let t=r.find(e=>n.type===e);if(t){e.preventDefault();let r=n.getAsFile();if(!r)continue;if(r.size>5242880){alert(u("chat.imageSizeLimit",{size:(r.size/1024/1024).toFixed(2)}));continue}let s=new FileReader;s.onload=e=>{let r=e.target?.result;if(!r)return;let n=r.replace(/^data:image\/\w+;base64,/,""),s={id:`img-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,data:n,preview:r,media_type:t};f(e=>[...e,s])},s.readAsDataURL(r)}}},[u]),D=(0,s.useCallback)(e=>{f(t=>t.filter(t=>t.id!==e))},[]);return(0,n.jsxs)("div",{className:"border-t border-border bg-card relative",children:[(0,n.jsx)(nh,{images:x,onRemove:D,disabled:t}),M&&E.length>0&&(0,n.jsx)("div",{ref:S,className:"absolute bottom-full left-0 right-0 mx-4 mb-2 max-h-64 overflow-y-auto bg-card border border-border rounded-lg shadow-lg",children:E.map((e,t)=>(0,n.jsxs)("div",{onClick:()=>R(e),className:`flex items-center gap-3 px-4 py-2 cursor-pointer ${t===w?"bg-brand/10":"hover:bg-accent"}`,children:[(0,n.jsx)("span",{className:"font-mono text-sm font-medium text-foreground",children:e.name}),(0,n.jsx)("span",{className:"flex-1 text-sm text-muted-foreground truncate",children:e.description}),(0,n.jsx)("span",{className:`text-xs px-1.5 py-0.5 rounded ${(e=>{switch(e){case"builtin":return"bg-brand/15 text-brand dark:bg-brand/25 dark:text-teal-11";case"global":return"bg-green-9/15 text-green-11 dark:bg-green-9/25 dark:text-green-11";case"project":return"bg-amber-9/15 text-amber-11 dark:bg-amber-9/25 dark:text-amber-11"}})(e.source)}`,children:(e=>{switch(e){case"builtin":return u("common.builtin");case"global":return u("common.global");case"project":return u("common.project")}})(e.source)})]},e.name))}),(0,n.jsxs)("div",{className:"flex gap-2 items-end p-4",children:[(0,n.jsx)("button",{onClick:async()=>{try{(await fetch("/api/git/stage",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:r,files:["."]})})).ok?((0,g.oR)(u("toast.stagedAllFiles"),"success"),window.dispatchEvent(new CustomEvent("git-status-changed"))):(0,g.oR)(u("toast.stageFailed"),"error")}catch(e){console.error("Error staging files:",e),(0,g.oR)(u("toast.stageFailed"),"error")}},className:"p-2 text-green-11 hover:text-green-10 hover:bg-green-9/10 active:bg-green-9/20 active:scale-95 rounded-lg transition-all",title:u("chat.stageAll"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})}),l&&(0,n.jsx)("button",{onClick:l,className:"p-2 text-brand hover:text-teal-10 hover:bg-brand/10 active:bg-brand/20 active:scale-95 rounded-lg transition-all",title:u("chat.viewGitChanges"),children:(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"6",cy:"6",r:"2",strokeWidth:2}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"2",strokeWidth:2}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"2",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 8v10M18 8v4c0 2-2 4-6 4"})]})}),a&&(0,n.jsx)("button",{onClick:a,className:"p-2 text-amber-11 hover:text-amber-10 hover:bg-amber-9/10 active:bg-amber-9/20 active:scale-95 rounded-lg transition-all",title:u("chat.viewAllComments"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})})}),i&&(0,n.jsx)("button",{onClick:i,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent active:bg-muted active:scale-95 rounded-lg transition-all",title:u("chat.userMessages"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16M4 18h16"})})}),c&&(0,n.jsx)("button",{onClick:c,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent active:bg-muted active:scale-95 rounded-lg transition-all",title:u("chat.projectNotes"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}),d&&(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("button",{onClick:()=>j(!v),className:`p-2 rounded-lg transition-all ${v?"text-brand bg-brand/10":"text-muted-foreground hover:text-foreground hover:bg-accent active:bg-muted active:scale-95"}`,title:u("chat.scheduledTasks"),children:(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6v6l4 2"})]})}),v&&(0,n.jsx)(nm.E,{onClose:()=>j(!1),onCreate:d})]}),(0,n.jsx)("textarea",{ref:C,value:h,onChange:e=>m(e.target.value),onKeyDown:P,onPaste:I,placeholder:t?u("chat.placeholderDisabled"):u("chat.placeholder"),rows:1,className:"flex-1 resize-none px-4 py-2 border border-border rounded-lg focus:outline-none focus:ring-2 focus:ring-ring bg-card text-foreground placeholder-slate-9"})]})]})});var nf=r(97440),np=r(31914);function ng(e){if(0===e.length)return"";let t=[c.A.t("comments.codeRef"),""],r=e.filter(e=>e.filePath===x),n=e.filter(e=>e.filePath!==x);for(let e of(n.length>0&&n.forEach((e,r)=>{t.push(`[${r+1}] ${e.filePath}:${e.startLine}-${e.endLine}`),t.push("```"),t.push(e.codeContent),t.push("```"),e.content&&t.push(c.A.t("comments.note",{content:e.content})),t.push("")}),r)){let r=e.codeContent.split("\n").map(e=>`> ${e}`).join("\n");t.push(r),e.content&&t.push(e.content),t.push("")}return t.join("\n").trim()}function nb({isOpen:e,onClose:t,cwd:r,onNavigateToComment:l}){let{t:a}=(0,o.Bd)(),[i,c]=(0,s.useState)([]),[d,f]=(0,s.useState)(!1),[p,b]=(0,s.useState)(null),[v,j]=(0,s.useState)(!1),w=(0,s.useCallback)(async()=>{if(r){f(!0);try{let e=await fetch(`/api/comments?cwd=${encodeURIComponent(r)}&all=true`);if(e.ok){let t=await e.json();c(t.comments||[])}}catch(e){console.error("Failed to load comments:",e)}finally{f(!1)}}},[r]);(0,s.useEffect)(()=>{e&&w()},[e,w]);let y=async e=>{try{(await fetch(`/api/comments?cwd=${encodeURIComponent(r)}&id=${encodeURIComponent(e)}`,{method:"DELETE"})).ok&&(c(t=>t.filter(t=>t.id!==e)),u())}catch(e){console.error("Failed to delete comment:",e)}},k=async e=>{b(e.id);try{let t="";if(e.selectedText)t=e.selectedText;else{let n=await fetch(`/api/files/read?cwd=${encodeURIComponent(r)}&path=${encodeURIComponent(e.filePath)}`);if(!n.ok)throw Error("Failed to read file");t=((await n.json()).content||"").split("\n").slice(e.startLine-1,e.endLine).join("\n")}let n={filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,content:e.content,codeContent:t},s=ng([n]);await navigator.clipboard.writeText(s),(0,g.oR)(a("toast.copiedComment"))}catch(e){console.error("Failed to copy comment:",e)}finally{b(null)}},N=async()=>{if(0!==i.length){j(!0);try{let e=await h(r),t=ng(e);await navigator.clipboard.writeText(t),(0,g.oR)(a("toast.copiedAllComments"))}catch(e){console.error("Failed to copy all comments:",e)}finally{j(!1)}}},C=i.reduce((e,t)=>(e[t.filePath]||(e[t.filePath]=[]),e[t.filePath].push(t),e),{});if(!e)return null;let S=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:t,children:(0,n.jsxs)("div",{className:"w-full max-w-2xl max-h-[80vh] bg-card border border-border rounded-lg shadow-xl flex flex-col overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border bg-secondary",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h2",{className:"text-lg font-semibold text-foreground",children:a("comments.allComments")}),i.length>0&&(0,n.jsx)("button",{onClick:N,disabled:v,className:"p-1 rounded hover:bg-accent text-muted-foreground disabled:opacity-50",title:a("comments.copyAllComments"),children:v?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 rounded hover:bg-accent text-muted-foreground",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:d?(0,n.jsx)("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:a("common.loading")}):0===i.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[(0,n.jsx)("svg",{className:"w-12 h-12 mb-3 opacity-50",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})}),(0,n.jsx)("span",{children:a("comments.noComments")})]}):(0,n.jsx)("div",{className:"space-y-4",children:Object.entries(C).map(([e,t])=>(0,n.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden",children:[(0,n.jsxs)("div",{className:"px-3 py-2 bg-secondary border-b border-border",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-foreground font-mono",children:e===x?a("comments.aiReply"):e}),(0,n.jsxs)("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",a("comments.nComments",{count:t.length}),")"]})]}),(0,n.jsx)("div",{className:"divide-y divide-border",children:t.map(e=>{var t;return(0,n.jsx)("div",{className:"px-3 py-2 hover:bg-accent/50 cursor-pointer group",onClick:()=>l?.(e),children:(0,n.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[e.startLine>0||e.endLine>0?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{className:"text-xs text-brand font-mono",children:[a("common.line")," ",e.startLine===e.endLine?e.startLine:`${e.startLine}-${e.endLine}`]}),(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:["(",a("comments.linesCount",{count:e.endLine-e.startLine+1}),")"]})]}):e.selectedText?(0,n.jsxs)("span",{className:"text-xs text-muted-foreground italic truncate max-w-[200px]",children:["“",e.selectedText.slice(0,50),e.selectedText.length>50?"...":"","”"]}):null,(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:(t=e.updatedAt||e.createdAt)?new Date(t).toLocaleString("zh-CN",{month:"numeric",day:"numeric",hour:"2-digit",minute:"2-digit"}):""})]}),(0,n.jsx)("p",{className:"text-sm text-foreground line-clamp-2",children:e.content||(0,n.jsx)("span",{className:"text-muted-foreground italic",children:a("comments.noContent")})})]}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),k(e)},disabled:p===e.id,className:"p-1 rounded opacity-0 group-hover:opacity-100 hover:bg-accent text-muted-foreground transition-opacity disabled:opacity-50",title:a("common.copy"),children:p===e.id?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),y(e.id)},className:"p-1 rounded opacity-0 group-hover:opacity-100 hover:bg-accent text-muted-foreground hover:text-red-9 transition-opacity",title:a("common.delete"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]})},e.id)})})]},e))})}),(0,n.jsxs)("div",{className:"px-4 py-3 border-t border-border bg-secondary flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground",children:a("comments.totalComments",{count:i.length})}),(0,n.jsx)("button",{onClick:async()=>{0===i.length||await m(r)&&c([])},disabled:0===i.length,className:"px-3 py-1.5 text-sm bg-red-9 text-white rounded hover:bg-red-10 disabled:opacity-50 disabled:cursor-not-allowed",children:a("comments.clearAll")})]})]})});return(0,n.jsx)(rK.Z,{children:S})}function nv({isOpen:e,onClose:t,messages:r,onSelectMessage:l}){let{t:a}=(0,o.Bd)();if((0,s.useEffect)(()=>{if(!e)return;let r=e=>{"Escape"===e.key&&t()};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[e,t]),!e)return null;let i=r.filter(e=>"user"===e.role),c=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:t,children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-lg max-h-[70vh] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border shrink-0",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground",children:a("userMessages.title")}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:0===i.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:a("userMessages.noMessages")}):(0,n.jsx)("div",{className:"divide-y divide-border",children:i.map((e,r)=>{let s,o,a,i=(s=e.id.match(/^user-(\d+)/))?parseInt(s[1],10):null,c=i?(o=new Date(i),a=new Date,o.toDateString()===a.toDateString()?o.toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"}):o.toLocaleDateString("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})):"";return(0,n.jsx)("button",{onClick:()=>{l(e.id),t()},className:"w-full px-4 py-3 text-left hover:bg-accent transition-colors",children:(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsxs)("span",{className:"text-xs text-muted-foreground font-mono w-6 shrink-0 pt-0.5",children:[r+1,"."]}),(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)("p",{className:"text-sm text-foreground break-words",children:function(e,t=50){let r=e.replace(/\s+/g," ").trim();return r.length<=t?r:r.slice(0,t)+"..."}(e.content)})}),c&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground shrink-0 pt-0.5",children:c})]})},e.id)})})})]})});return(0,n.jsx)(rK.Z,{children:c})}function nj({cwd:e,sessionId:t,onOpenProjectSessions:r,onOpenSessionBrowser:l,onOpenSettings:a}){let{t:i}=(0,o.Bd)(),[c,d]=(0,s.useState)(!1);return(0,n.jsx)("div",{className:"border-b border-border px-4 py-3 bg-card",children:(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("img",{src:"/icons/icon-72x72.png",alt:"Cockpit",className:"w-6 h-6"}),(0,n.jsxs)("div",{className:"flex items-baseline gap-2",children:[(0,n.jsx)("h1",{className:"text-lg font-semibold text-foreground",children:"Cockpit"}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:"One seat. One AI. Everything under control."})]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[e&&(0,n.jsx)("span",{className:"text-sm text-foreground max-w-md truncate cursor-help",title:`CWD: ${e}`,children:e}),!e&&t&&(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:["Session: ",t.slice(0,8),"..."]}),e&&(0,n.jsx)("button",{onClick:r,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:i("sessions.projectSessions"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),(0,n.jsx)("button",{onClick:l,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:i("sessions.browseAllSessions"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}),t&&(0,n.jsx)("button",{onClick:()=>{let e=`claude -r ${t}`;navigator.clipboard.writeText(e).then(()=>{d(!0),setTimeout(()=>d(!1),2e3)})},className:`p-2 rounded-lg transition-colors ${c?"text-green-500 bg-green-500/10":"text-muted-foreground hover:text-foreground hover:bg-accent"}`,title:c?i("chat.copiedCommandTooltip"):i("chat.copyCommandTooltip",{sessionId:t}),children:c?(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}):(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3m2 4H10m0 0l3-3m-3 3l3 3"})})}),(0,n.jsx)("button",{onClick:a,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:i("settings.title"),children:(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]})})]})]})})}function nw({tokenUsage:e}){let{t}=(0,o.Bd)();return(0,n.jsx)("div",{className:"px-4 py-1.5 border-t border-border bg-secondary",children:(0,n.jsxs)("div",{className:"flex items-center justify-end gap-4 text-xs text-muted-foreground",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})}),(0,n.jsxs)("span",{children:[t("chat.context"),": ",(0,n.jsx)("strong",{className:"text-foreground",children:(e.inputTokens+e.cacheReadInputTokens+e.cacheCreationInputTokens).toLocaleString()})]})]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z"})}),(0,n.jsxs)("span",{children:[t("chat.output"),": ",(0,n.jsx)("strong",{className:"text-foreground",children:e.outputTokens.toLocaleString()})]})]}),(e.cacheReadInputTokens>0||e.cacheCreationInputTokens>0)&&(0,n.jsxs)("span",{className:"flex items-center gap-1 text-brand",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 7v10c0 2.21 3.582 4 8 4s8-1.79 8-4V7M4 7c0 2.21 3.582 4 8 4s8-1.79 8-4M4 7c0-2.21 3.582-4 8-4s8 1.79 8 4"})}),(0,n.jsxs)("span",{children:["Cache: ",(e.cacheReadInputTokens/(e.inputTokens+e.cacheReadInputTokens+e.cacheCreationInputTokens)*100).toFixed(0),"%"]})]}),e.totalCostUsd>0&&(0,n.jsxs)("span",{className:"flex items-center gap-1 text-green-11",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,n.jsxs)("span",{children:["$",e.totalCostUsd.toFixed(4)]})]})]})})}function ny({tabId:e,initialCwd:t,initialSessionId:r,hideHeader:a,hideSidebar:i,isActive:d=!0,onLoadingChange:u,onSessionIdChange:h,onTitleChange:m,onShowGitStatus:x,onOpenNote:f,onCreateScheduledTask:p,onOpenSession:g,onContentSearch:b}){let{t:v}=(0,o.Bd)(),j=C(),[w,y]=(0,s.useState)([]),[k,N]=(0,s.useState)(null),[S,L]=(0,s.useState)(!1),[E,M]=(0,s.useState)(!1),[T,$]=(0,s.useState)(!1),[R,P]=(0,s.useState)(!1),[I,D]=(0,s.useState)(!1),[B,F]=(0,s.useState)(!1),[O,A]=(0,s.useState)(null),W=(0,s.useRef)(null),z=(0,s.useRef)(null),H=(0,s.useCallback)(async e=>{if(t)try{let r=await fetch("/api/session-by-path",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,sessionId:e})});if(r.ok){let e=await r.json();e.title&&m?.(e.title)}}catch(e){console.error("Failed to fetch session title:",e)}},[t,m]),{isLoading:_,tokenUsage:U,handleSend:q,handleStop:V}=function(e,t,{sessionId:r,cwd:n,onSessionId:o,onFetchTitle:l}){let[a,i]=(0,s.useState)(!1),[d,u]=(0,s.useState)(null),h=(0,s.useRef)(null),m=(0,s.useRef)(r);m.current=r;let x=(0,s.useRef)(null),f=(0,s.useRef)(null),p=(0,s.useCallback)(()=>{let e=x.current;if(e&&e.text){let{messageId:r,text:n}=e;t(e=>e.map(e=>e.id===r?{...e,content:(e.content||"")+n}:e)),x.current={messageId:r,text:""}}f.current=null},[t]),g=(0,s.useCallback)(()=>{h.current&&(h.current.abort(),h.current=null)},[]),b=(0,s.useCallback)((e,r)=>{let s=e.type;if("system"===s&&"init"===e.subtype){let t=e.session_id;o(t),m.current=t;return}if("stream_event"===s){let t=e.event;if(t?.type==="content_block_delta"&&t.delta?.type==="text_delta"){let e=t.delta.text||"";x.current&&x.current.messageId===r?x.current.text+=e:x.current={messageId:r,text:e},f.current||(f.current=setTimeout(p,50))}return}if("assistant"===s){let n=e.message;if(n?.content){for(let e of n.content)if("name"in e&&e.name){let n={id:e.id||`tool-${Date.now()}`,name:e.name,input:e.input||{},isLoading:!0};t(e=>e.map(e=>e.id!==r||e.toolCalls?.some(e=>e.id===n.id)?e:{...e,toolCalls:[...e.toolCalls||[],n]}))}}}if("user"===s){let n=e.message;if(n?.content){for(let e of n.content)if("tool_use_id"in e&&e.tool_use_id){let n=e.tool_use_id,s="string"==typeof e.content?e.content:JSON.stringify(e.content);t(e=>e.map(e=>e.id===r?{...e,toolCalls:e.toolCalls?.map(e=>e.id===n?{...e,result:s,isLoading:!1}:e)}:e))}}}if("result"===s){f.current&&(clearTimeout(f.current),f.current=null),p();let s=m.current;s&&n&&t(e=>(2===e.length&&l(s),e));let o=e.usage,a=e.total_cost_usd;o&&u({inputTokens:o.input_tokens||0,outputTokens:o.output_tokens||0,cacheCreationInputTokens:o.cache_creation_input_tokens||0,cacheReadInputTokens:o.cache_read_input_tokens||0,totalCostUsd:a||0}),t(e=>e.map(e=>e.id===r?{...e,isStreaming:!1,toolCalls:e.toolCalls?.map(e=>({...e,isLoading:!1}))}:e))}},[t,p,o,l,n]);return{isLoading:a,tokenUsage:d,handleSend:(0,s.useCallback)(async(e,r)=>{let s=r?.map(e=>({type:"base64",media_type:e.media_type,data:e.data})),o={id:`user-${Date.now()}`,role:"user",content:e,images:s};t(e=>[...e,o]),i(!0);let l=`assistant-${Date.now()}`,a={id:l,role:"assistant",content:"",toolCalls:[],isStreaming:!0};t(e=>[...e,a]),h.current=new AbortController;try{let t=await fetch("/api/chat",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:e,sessionId:m.current,images:s,cwd:n}),signal:h.current.signal});if(!t.ok)throw Error(c.A.t("chat.requestFailed"));let r=t.body?.getReader();if(!r)throw Error(c.A.t("chat.cannotReadStream"));let o=new TextDecoder,a="";for(;;){let{done:e,value:t}=await r.read();if(e)break;let n=(a+=o.decode(t,{stream:!0})).split("\n");for(let e of(a=n.pop()||"",n))if(e.startsWith("data: ")){let t=e.slice(6);if("[DONE]"===t)continue;try{let e=JSON.parse(t);b(e,l)}catch{}}}}catch(e){e instanceof Error&&"AbortError"===e.name||(console.error("Chat error:",e),t(e=>e.map(e=>e.id===l?{...e,content:c.A.t("chat.errorRetry"),isStreaming:!1}:e)))}finally{h.current=null,i(!1),t(e=>e.map(e=>e.id===l?{...e,isStreaming:!1}:e))}},[n,t,b]),handleStop:g,abortControllerRef:h}}(0,y,{sessionId:k,cwd:t,onSessionId:N,onFetchTitle:H}),K=(0,s.useCallback)(async(e,r)=>{let n=e.split("\n")[0];if(n.startsWith("!")&&n.length>1){let s=n.slice(1).trim();if(!s)return void q(e,r);let o=e.split("\n").slice(1).join("\n").trim();try{let e=await fetch("/api/bash",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({command:s,cwd:t})}),n=await e.json(),l=[n.stdout,n.stderr].filter(Boolean).join("\n")||"(no output)",a=n.exitCode?` (exit code: ${n.exitCode})`:"",i=v("chat.executedCommand",{command:s,exitInfo:a,output:l});o&&(i+=`
23
+ Error: ${r.message}`,exitCode:1,isRunning:!1,pid:void 0}:n))}},[o,k,u,w,r,e,O,W,A]),J=(0,s.useCallback)(async t=>{if(l(e=>e.filter(e=>e.id!==t)),A(t),r)try{await fetch(`/api/terminal/history?cwd=${encodeURIComponent(e)}&tabId=${encodeURIComponent(r)}&commandId=${encodeURIComponent(t)}`,{method:"DELETE"})}catch(e){console.error("Failed to delete command:",e)}},[e,r,A]),X=(0,s.useCallback)((t,n,s)=>{var o;let l=t_(t);if(!l)return;let a=l.parse(n);"cwd"in a&&!a.cwd&&(a.cwd=u);let c={id:(o=l.idPrefix,`${o}-${Date.now()}-${Math.random().toString(36).slice(2,8)}`),_type:t,timestamp:new Date().toISOString(),...a};if(i(e=>[...e,c]),j(c.id),setTimeout(z,100),s){let t=C&&C.length>0?[...C]:D.current.map(e=>e.data.id),n=t.indexOf(s);-1!==n?t.splice(n+1,0,c.id):t.push(c.id),S(t),r&&fetch("/api/terminal/bubble-order",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,tabId:r,order:t})}).catch(()=>{})}if(r){let n=l.toHistory(c);fetch("/api/terminal/history",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,tabId:r,entry:{type:t,id:c.id,timestamp:c.timestamp,...n}})}).catch(e=>console.error(`Failed to save ${t} item:`,e))}},[z,e,r,C]),Y=(0,s.useCallback)(async t=>{let n=a.find(e=>e.id===t);if(i(e=>e.filter(e=>e.id!==t)),j(e=>e===t?null:e),d(e=>{let r=new Set(e);return r.delete(t),r}),n){let e=t_(n._type);e?.onClose?.(n)}r&&fetch(`/api/terminal/history?cwd=${encodeURIComponent(e)}&tabId=${encodeURIComponent(r)}&commandId=${encodeURIComponent(t)}`,{method:"DELETE"}).catch(e=>console.error("Failed to delete plugin item:",e))},[a,e,r]);I.current=X,P.current=q;let Q=(0,s.useCallback)((t,n)=>{r&&fetch("/api/terminal/history",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,tabId:r,id:t,fields:{sleeping:n}})}).catch(()=>{})},[e,r]),G=(0,s.useCallback)(e=>{d(t=>new Set(t).add(e)),Q(e,!0)},[Q]),Z=(0,s.useCallback)(e=>{d(t=>{let r=new Set(t);return r.delete(e),r}),Q(e,!1)},[Q]),ee=(0,s.useCallback)(async t=>{if(S(t),r)try{await fetch("/api/terminal/bubble-order",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,tabId:r,order:t})})}catch{}},[e,r]),et=(0,s.useMemo)(()=>{let e=[...o.map(e=>({type:"command",data:e})),...a.map(e=>({type:e._type,data:e}))];if(!C||0===C.length)return e.sort((e,t)=>new Date(e.data.timestamp).getTime()-new Date(t.data.timestamp).getTime());let t=new Map(C.map((e,t)=>[e,t])),r=[],n=[];for(let s of e)t.has(s.data.id)?r.push(s):n.push(s);return r.sort((e,r)=>t.get(e.data.id)-t.get(r.data.id)),n.sort((e,t)=>new Date(e.data.timestamp).getTime()-new Date(t.data.timestamp).getTime()),[...r,...n]},[o,a,C]);D.current=et,(0,s.useEffect)(()=>{$.current=o.filter(e=>!e.isRunning&&e.command.trim()).map(e=>e.command)},[o]);let er=async()=>{try{let t=new URLSearchParams({cwd:e});r&&t.set("tabId",r);let n=await fetch(`/api/terminal/env?${t}`);if(n.ok){let e=await n.json();y(e.env||{})}}catch(e){console.error("Failed to load env:",e)}},en=async()=>{try{let e=await fetch("/api/terminal/aliases");if(e.ok){let t=await e.json();N(t.aliases||{})}}catch(e){console.error("Failed to load aliases:",e)}},es=async()=>{if(r)try{let t=await fetch(`/api/terminal/bubble-order?cwd=${encodeURIComponent(e)}&tabId=${encodeURIComponent(r)}`);if(t.ok){let e=await t.json();e.order&&e.order.length>0&&S(e.order)}}catch{}};return(0,s.useEffect)(()=>{let e={current:!1};return(async()=>{await H(0),e.current||await U(e)})(),er(),en(),es(),()=>{e.current=!0}},[H,U]),(0,s.useEffect)(()=>()=>{null!==L.current&&cancelAnimationFrame(L.current)},[]),(0,s.useEffect)(()=>()=>{tW()},[]),{commands:o,pluginItems:a,sleepingBubbles:c,consoleItems:et,currentCwd:u,selectedCommandId:v,setSelectedCommandId:j,customEnv:w,setCustomEnv:y,aliases:k,setAliases:N,isLoadingHistory:m,hasMoreHistory:f,currentPage:g,scrollRef:B,commandHistoryRef:$,ptySizeRef:R,executeCommandRef:P,executeCommand:q,interruptCommand:V,rerunCommand:K,deleteCommand:J,addPluginItem:X,closePluginItem:Y,handleBubbleSleep:G,handleBubbleWake:Z,loadHistory:H,scrollToBottom:z,saveBubbleOrder:ee,sendStdin:tB,resizePty:tF}}({cwd:e,initialShellCwd:t,tabId:r,onCwdChange:l}),[D,B]=(0,s.useState)(null),[F,O]=(0,s.useState)(0),[A,W]=(0,s.useState)(0),[z,H]=(0,s.useState)(!0),[_,U]=(0,s.useState)(!1),[q,V]=(0,s.useState)(!1),[K,J]=(0,s.useState)(!1),[X,Y]=(0,s.useState)(!1),Q=(0,s.useRef)(null),G=(0,s.useRef)(null),Z=(0,s.useRef)(null),ee=(0,s.useRef)(!1),et=(0,s.useRef)(null),er=(0,s.useRef)(null),en=(0,s.useRef)([]);(0,s.useEffect)(()=>{en.current=c},[c]);let es=(0,s.useCallback)(()=>{let e=d.current;return!e||e.scrollHeight-e.scrollTop-e.clientHeight<50},[d]),eo=(0,s.useCallback)(()=>{let e=d.current;return!e||e.scrollTop<50},[d]),el=(0,s.useCallback)(()=>{J(!eo()),Y(!es())},[es,eo]),ea=(0,s.useCallback)(()=>{G.current?.scrollIntoView({behavior:"smooth"})},[]),ei=async()=>{try{let t=await fetch(`/api/project-settings?cwd=${encodeURIComponent(e)}`);if(t.ok){let e=await t.json();e.settings?.gridLayout!==void 0&&H(e.settings.gridLayout)}}catch(e){console.error("Failed to load project settings:",e)}},ec=async t=>{try{await fetch("/api/project-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,settings:t})})}catch(e){console.error("Failed to save project settings:",e)}};(0,s.useEffect)(()=>{queueMicrotask(()=>ei())},[]);let ed=(0,s.useCallback)(()=>{ee.current=!0},[]),eu=(0,s.useCallback)((e,t)=>{if(!ee.current)return void e.preventDefault();ee.current=!1,et.current=t,e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",t),e.currentTarget.style.opacity="0.4";let r=e.currentTarget.querySelector("[data-drag-handle]");if(r){let t=r.cloneNode(!0);t.style.cssText="position:fixed;top:-9999px;left:-9999px;width:"+r.offsetWidth+"px;background:var(--card);border-radius:8px;padding:4px 12px;opacity:0.9;",document.body.appendChild(t),e.dataTransfer.setDragImage(t,20,16),requestAnimationFrame(()=>document.body.removeChild(t))}},[]),eh=(0,s.useCallback)((e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect="move",er.current=t},[]),em=(0,s.useCallback)(e=>{e.preventDefault(),e.currentTarget.classList.add("ring-2","ring-brand")},[]),ex=(0,s.useCallback)(e=>{e.currentTarget.classList.remove("ring-2","ring-brand")},[]),ef=(0,s.useCallback)(e=>{e.preventDefault(),e.currentTarget.classList.remove("ring-2","ring-brand")},[]),ep=(0,s.useCallback)(e=>{e.currentTarget.style.opacity="1";let t=et.current,r=er.current;if(et.current=null,er.current=null,!t||!r||t===r)return;let n=en.current.map(e=>e.data.id),s=n.indexOf(t),o=n.indexOf(r);if(-1===s||-1===o)return;let l=[...n];l[s]=r,l[o]=t,T(l)},[T]),eg=(0,s.useCallback)(e=>{B(t=>t===e?null:e)},[]);(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"m"===e.key&&!e.shiftKey&&!e.altKey&&(e.preventDefault(),u&&eg(u))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[u,eg]),(0,s.useEffect)(()=>{let e=d.current;if(!e)return;let t=new ResizeObserver(([e])=>{W(e.contentRect.height)});return t.observe(e),W(e.clientHeight),()=>t.disconnect()},[d]),(0,s.useEffect)(()=>{let e=d.current;if(e)return D?O(e.clientHeight):(e.style.overflow="",O(0)),()=>{e&&(e.style.overflow="")}},[D,d]),(0,s.useEffect)(()=>{let e=d.current;if(!e||!D||!F)return;let t=requestAnimationFrame(()=>{let t=e.querySelector(`[data-bubble-id="${D}"]`);t&&t.scrollIntoView({block:"start"}),e.style.overflow="hidden"});return()=>cancelAnimationFrame(t)},[D,F,d]),(0,s.useEffect)(()=>{let e=e=>{let t=e.detail?.command;t&&v(t)};return window.addEventListener("execute-terminal-command",e),()=>window.removeEventListener("execute-terminal-command",e)},[v]);let eb=A>0?Math.floor((A-32-12)/2-41):void 0;return(0,n.jsxs)("div",{ref:Q,className:"h-full flex flex-col bg-background relative",children:[(0,n.jsx)("div",{ref:d,onScroll:el,className:`flex-1 overflow-y-auto ${D?"":"py-4 px-4"}`,children:0===c.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:i("console.enterCommandOrUrl")}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{ref:G}),$&&(0,n.jsx)("div",{className:"flex justify-center mb-4",children:(0,n.jsx)("button",{onClick:()=>R(P+1),disabled:I,className:"px-4 py-2 text-sm text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors disabled:opacity-50",children:i(I?"console.loadingMore":"console.loadMoreHistory")})}),(0,n.jsx)("div",{className:D?"flex flex-col gap-3":z?"grid grid-cols-2 gap-3":"flex flex-col gap-3",children:c.map(t=>{let s={draggable:!0,onDragStart:e=>eu(e,t.data.id),onDragOver:e=>eh(e,t.data.id),onDragEnter:em,onDragLeave:ex,onDrop:ef,onDragEnd:ep};if("command"===t.type){let o=t.data;return(0,n.jsx)("div",{"data-bubble-id":o.id,className:"group/cmd rounded-lg transition-shadow",...s,children:(0,n.jsx)(td,{commandId:o.id,tabId:r,projectCwd:e,command:o.command,output:o.output,exitCode:o.exitCode,isRunning:o.isRunning,selected:u===o.id,onSelect:()=>{h(o.id)},onInterrupt:o.isRunning?()=>m(o.id):void 0,onStdin:o.isRunning?e=>x(o.id,e):void 0,onDelete:()=>{o.isRunning&&o.pid&&tO(o.pid),f(o.id)},onRerun:()=>p(o.id),timestamp:o.timestamp,usePty:o.usePty,onPtyResize:(e,t)=>{g.current.set(o.id,{cols:e,rows:t}),b(o.id,e,t)},onToggleMaximize:()=>eg(o.id),maximized:D===o.id,expandedHeight:F,bubbleContentHeight:eb,onTitleMouseDown:ed})},o.id)}let o=t_(t.type);if(!o)return null;let l=o.Component,a=t.data;return(0,n.jsx)("div",{"data-bubble-id":a.id,className:"rounded-lg transition-shadow",...s,children:(0,n.jsx)(l,{item:a,selected:u===a.id,maximized:D===a.id,expandedHeight:F,bubbleContentHeight:eb,timestamp:a.timestamp,onSelect:()=>{h(a.id)},onClose:()=>w(a.id),onToggleMaximize:()=>eg(a.id),onTitleMouseDown:ed,extra:{addBrowserItem:(e,t)=>j("browser",e,t),initialSleeping:y.has(a.id),onSleep:k,onWake:N}})},a.id)})}),(0,n.jsx)("div",{ref:Z})]})}),!D&&c.length>0&&(0,n.jsx)(rB,{showTop:K,showBottom:X,onScrollTop:ea,onScrollBottom:C}),(0,n.jsx)(rD,{cwd:e,currentCwd:S,commandHistoryRef:L,gridLayout:z,onGridLayoutChange:e=>{H(e),ec({gridLayout:e})},onExecute:v,onAddPluginItem:j,onShowEnvManager:()=>U(!0),onOpenZsh:()=>v("zsh"),onOpenNote:a}),_&&(0,n.jsx)(tm,{cwd:e,tabId:r,onClose:()=>U(!1),onSave:e=>E(e)}),q&&(0,n.jsx)(tf,{onClose:()=>V(!1),onSave:e=>M(e)})]})}var rO=r(24750);let rA="review-last-viewed";function rW(){try{return JSON.parse(localStorage.getItem(rA)||"{}")}catch{return{}}}function rz(e,t){if(!e.lastCommentAt)return!1;let r=t[e.id];return!r||e.lastCommentAt>r}function rH({cwd:e}){let{t}=(0,o.Bd)(),[r,l]=(0,s.useState)(!1),[a,i]=(0,s.useState)([]),[c,d]=(0,s.useState)(!1),[u,h]=(0,s.useState)(null),[m,x]=(0,s.useState)({}),[f,p]=(0,s.useState)({open:!1,comments:[],title:"",userNameMap:{}}),g=(0,s.useRef)(null),b=(0,s.useRef)(null),[v,j]=(0,s.useState)(null);(0,s.useEffect)(()=>{queueMicrotask(()=>x(rW()))},[]),(0,s.useEffect)(()=>{if(!r)return;let e=e=>{g.current&&!g.current.contains(e.target)&&l(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[r]);let w=(0,s.useCallback)(async()=>{d(!0);try{let e=await fetch("/api/review");if(e.ok){let t=await e.json();i(t.reviews||[])}}catch{}d(!1)},[]);(0,s.useEffect)(()=>{r&&queueMicrotask(()=>w())},[r,w]);let y=(0,s.useCallback)(e=>{let{data:t}=e;t?.some(e=>"review"===e.type)&&w()},[w]);(0,eH.h)({url:`/ws/watch?cwd=${encodeURIComponent(e||"/")}`,onMessage:y,enabled:!!e}),(0,s.useEffect)(()=>{queueMicrotask(()=>w())},[w]);let k=(0,s.useMemo)(()=>a.filter(e=>e.active),[a]),N=(0,s.useMemo)(()=>k.some(e=>rz(e,m)),[k,m]),C=(0,s.useCallback)(e=>{let t;(t=rW())[e]=Date.now(),localStorage.setItem(rA,JSON.stringify(t)),x(rW()),window.open(`${window.location.origin}/review/${e}`,"_blank")},[]),S=(0,s.useCallback)(async(e,t)=>{e.stopPropagation();try{let[e,r]=await Promise.all([fetch(`/api/review/${t}`),fetch("/api/review/users")]);if(!e.ok)return;let{review:n}=await e.json(),s={};if(r.ok){let{users:e}=await r.json();for(let[t,r]of Object.entries(e))s[t]=r.name}p({open:!0,comments:n.comments||[],title:n.title,userNameMap:s})}catch{}},[]),L=(0,s.useCallback)((e,t)=>{b.current=t,e.dataTransfer.effectAllowed="move";let r=e.currentTarget;requestAnimationFrame(()=>r.classList.add("opacity-30"))},[]),E=(0,s.useCallback)(e=>{b.current=null,j(null),e.currentTarget instanceof HTMLElement&&e.currentTarget.classList.remove("opacity-30")},[]),M=(0,s.useCallback)((e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect="move",b.current&&b.current!==t&&j(t)},[]),T=(0,s.useCallback)((e,t)=>{e.preventDefault(),j(null);let r=b.current;b.current=null,r&&r!==t&&i(e=>{let n=[...e],s=n.findIndex(e=>e.id===r),o=n.findIndex(e=>e.id===t);if(-1===s||-1===o)return e;let[l]=n.splice(s,1);return n.splice(o,0,l),fetch("/api/review/order",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({order:n.map(e=>e.id)})}).catch(()=>{}),n})},[]);return(0,n.jsxs)("div",{ref:g,className:"relative",children:[(0,n.jsxs)("button",{onClick:()=>l(e=>!e),className:`relative p-2 rounded-lg transition-colors ${r?"text-foreground bg-accent":"text-muted-foreground hover:text-foreground hover:bg-accent"}`,title:t("review.reviewManagement"),children:[(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"})}),N&&(0,n.jsx)("span",{className:"absolute top-1 right-1 w-2 h-2 bg-red-500 rounded-full"})]}),r&&(0,n.jsxs)("div",{className:"absolute right-0 top-full mt-1 w-64 bg-popover border border-border rounded-lg shadow-xl z-50 overflow-hidden",children:[(0,n.jsxs)("div",{className:"px-3 py-2 border-b border-border flex items-center justify-between",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("span",{className:"text-xs font-medium text-muted-foreground",children:t("review.allReviews")}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground/60 ml-1.5",children:k.length})]}),(0,n.jsx)("button",{onClick:w,className:"p-0.5 text-muted-foreground hover:text-foreground rounded transition-colors",title:t("common.refresh"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})})]}),(0,n.jsx)("div",{className:"max-h-80 overflow-y-auto",children:c&&0===a.length?(0,n.jsx)("div",{className:"px-3 py-4 text-xs text-muted-foreground/50 text-center",children:t("common.loading")}):0===k.length?(0,n.jsx)("div",{className:"px-3 py-4 text-xs text-muted-foreground/50 text-center",children:t("review.noOpenReviews")}):k.map(e=>{let r,s,o,l,a,i=rz(e,m);return(0,n.jsxs)("div",{draggable:!0,onDragStart:t=>L(t,e.id),onDragEnd:E,onDragOver:t=>M(t,e.id),onDrop:t=>T(t,e.id),onMouseEnter:t=>{let r=t.currentTarget.getBoundingClientRect();h({id:e.id,text:e.title,top:r.top+r.height/2,left:r.left})},onMouseLeave:()=>h(t=>t?.id===e.id?null:t),onClick:()=>C(e.id),className:`group px-3 py-2 cursor-pointer border-b transition-colors ${v===e.id?"border-b-brand border-t border-t-transparent":"border-b-border/50"} hover:bg-accent/30`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 min-w-0",children:[(0,n.jsx)("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${i?"bg-red-500":"bg-green-500"}`}),(0,n.jsx)("span",{className:`text-xs truncate flex-1 ${i?"font-medium text-foreground":""}`,children:e.title}),e.commentCount>0&&(0,n.jsx)("button",{onClick:t=>S(t,e.id),className:"flex-shrink-0 p-0.5 rounded text-muted-foreground/0 group-hover:text-muted-foreground/60 hover:!text-brand hover:!bg-brand/10 transition-colors",title:t("review.viewComments"),children:(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2 text-[10px] text-muted-foreground/50 mt-0.5 pl-3",children:[(0,n.jsx)("span",{children:(s=String((r=new Date(e.updatedAt||e.createdAt)).getMonth()+1).padStart(2,"0"),o=String(r.getDate()).padStart(2,"0"),l=String(r.getHours()).padStart(2,"0"),a=String(r.getMinutes()).padStart(2,"0"),`${s}-${o} ${l}:${a}`)}),e.commentCount>0&&(0,n.jsx)("span",{children:t("review.nComments",{count:e.commentCount})})]})]},e.id)})})]}),u&&r&&(0,n.jsx)("div",{className:"fixed z-[60] px-2 py-1 text-xs bg-popover text-popover-foreground border border-border rounded shadow-md whitespace-nowrap pointer-events-none",style:{top:u.top,left:u.left-8,transform:"translate(-100%, -50%)"},children:u.text}),(0,n.jsx)(rO._,{isOpen:f.open,onClose:()=>p(e=>({...e,open:!1})),comments:f.comments,reviewTitle:f.title,userNameMap:f.userNameMap})]})}function r_({cwd:e,currentBranch:t,onSwitched:r}){let{t:l}=(0,o.Bd)(),[a,i]=(0,s.useState)(!1),[c,d]=(0,s.useState)([]),[u,h]=(0,s.useState)(!1),[m,x]=(0,s.useState)(!1),[f,p]=(0,s.useState)(""),b=(0,s.useRef)(null),v=(0,s.useRef)(null),j=(0,s.useCallback)(async()=>{h(!0);try{let t=await fetch(`/api/git/branches?cwd=${encodeURIComponent(e)}`);if(t.ok){let e=await t.json(),r=[...e.local||[],...(e.remote||[]).filter(t=>!e.local.includes(t.replace(/^origin\//,"")))];d(r)}}catch{(0,g.oR)(l("toast.loadBranchFailed"),"error")}finally{h(!1)}},[e]),w=(0,s.useCallback)(()=>{i(!0),p(""),j()},[j]),y=(0,s.useCallback)(()=>{i(!1)},[]);(0,s.useEffect)(()=>{if(!a)return;let e=e=>{b.current&&!b.current.contains(e.target)&&y()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[a,y]),(0,s.useEffect)(()=>{a&&setTimeout(()=>v.current?.focus(),50)},[a]);let k=async t=>{x(!0);try{let n=await fetch("/api/git/worktree",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"checkout",cwd:e,path:e,branch:t})});if(n.ok){let e=t.replace(/^origin\//,"");(0,g.oR)(l("toast.switchedToBranch",{branch:e}),"success"),y(),r()}else{let e=await n.json();(0,g.oR)(e.error||l("toast.switchBranchFailed"),"error")}}catch{(0,g.oR)(l("toast.switchBranchFailed"),"error")}finally{x(!1)}},N=c.filter(e=>e!==t&&e.toLowerCase().includes(f.toLowerCase()));return(0,n.jsxs)("div",{className:"relative",ref:b,children:[(0,n.jsx)("button",{onClick:a?y:w,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:l("git.switchBranch"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 7h12m0 0l-4-4m4 4l-4 4m0 6H4m0 0l4 4m-4-4l4-4"})})}),a&&(0,n.jsxs)("div",{className:"absolute top-full left-0 mt-1 w-64 bg-popover border border-border rounded-lg shadow-lg z-50 overflow-hidden",children:[(0,n.jsx)("div",{className:"p-2 border-b border-border",children:(0,n.jsx)("input",{ref:v,type:"text",value:f,onChange:e=>p(e.target.value),placeholder:l("git.searchBranch"),className:"w-full px-2.5 py-1.5 text-sm bg-muted rounded border-none outline-none placeholder:text-muted-foreground",onKeyDown:e=>{"Escape"===e.key&&y()}})}),(0,n.jsx)("div",{className:"max-h-60 overflow-y-auto p-1",children:u?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:l("common.loading")}):0===N.length?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:f?l("git.noMatchingBranches"):l("git.noBranches")}):N.map(e=>(0,n.jsx)("button",{onClick:()=>k(e),disabled:m,className:"w-full text-left px-2.5 py-1.5 text-sm rounded hover:bg-accent transition-colors truncate disabled:opacity-50",children:(0,n.jsx)("span",{className:e.startsWith("origin/")?"text-muted-foreground":"text-foreground",children:e})},e))})]})]})}function rU({initialCwd:e,activeTab:t,isGitRepo:r,currentBranch:s,onOpenWorktree:l,onOpenProjectSessions:a,onOpenAliasManager:i,onBranchSwitched:c}){let{t:d}=(0,o.Bd)();return(0,n.jsx)("div",{className:"border-b border-border bg-card shrink-0",children:(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 relative",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("img",{src:"/icons/icon-72x72.png",alt:"Cockpit",className:"w-6 h-6 cursor-pointer",title:d("tabManagerTopBar.copyPageUrl"),onClick:()=>{navigator.clipboard.writeText(window.location.href).then(()=>{(0,g.oR)(d("toast.copiedPageUrl"),"success")})}}),e?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-sm text-foreground max-w-md truncate cursor-help",title:`CWD: ${e}`,children:e}),(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(e),(0,g.oR)(d("toast.copiedDirPath"))},className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:d("tabManagerTopBar.copyDirPath"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}):(0,n.jsx)("h1",{className:"text-lg font-semibold text-foreground",children:"Cockpit"})]}),r&&e&&(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsxs)("button",{onClick:l,className:"flex items-center gap-1.5 px-2 py-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"Git Worktrees",children:[(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 17h8m0 0l-4-4m4 4l-4 4M3 7v6a4 4 0 004 4h5"})}),(0,n.jsx)("span",{className:"text-sm",children:s||"main"})]}),(0,n.jsx)(r_,{cwd:e,currentBranch:s,onSwitched:()=>c?.()})]})]}),(0,n.jsx)("div",{className:"absolute left-1/2 -translate-x-1/2",children:(0,n.jsx)(e5,{})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(rH,{cwd:e}),(0,n.jsx)("button",{onClick:()=>window.location.reload(),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:d("tabManagerTopBar.refreshProject"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})}),e&&(0,n.jsx)("button",{onClick:a,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:d("sessions.projectSessions"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),(0,n.jsx)("button",{onClick:async()=>{if(t?.cwd)try{await fetch("/api/open-vscode",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t.cwd})})}catch{}},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:d("tabManagerTopBar.openInVSCode"),children:(0,n.jsx)("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M17.583 2.213L12 7.393 6.417 2.213 1 6.17v11.66l5.417 3.957L12 16.607l5.583 5.18L23 17.83V6.17l-5.417-3.957zM6.417 17.83L3 15.33V8.67l3.417-2.5v11.66zm11.166 0V6.17L21 8.67v6.66l-3.417 2.5z"})})}),(0,n.jsx)("button",{onClick:async()=>{if(t?.cwd)try{await fetch("/api/open-cursor",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t.cwd})})}catch{}},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:d("tabManagerTopBar.openInCursor"),children:(0,n.jsx)("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M4.5 2L20.5 12L4.5 22V2Z"})})}),t?.sessionId&&(0,n.jsx)("button",{onClick:()=>{let e=`claude -r ${t.sessionId}`;navigator.clipboard.writeText(e).then(()=>{(0,g.oR)(d("toast.copiedCommand",{command:e}),"success")})},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:d("chat.copyCommandTooltip",{sessionId:t.sessionId}),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:i,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:d("tabManagerTopBar.aliasesGlobal"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M16 12h-6m-4 0a8 8 0 1116 0 8 8 0 01-16 0zm4 0h.01"})})}),(0,n.jsx)("button",{onClick:()=>window.parent.postMessage({type:"OPEN_TOKEN_STATS"},"*"),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:d("tabManagerTopBar.tokenStats"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"})})}),(0,n.jsx)("button",{onClick:()=>window.open("https://surething.io?from=cockpit","_blank"),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:d("tabManagerTopBar.openSurething"),children:(0,n.jsx)("img",{src:"https://surething.io/logo.png?from=cockpit",alt:"Surething",className:"w-5 h-5 rounded-sm"})})]})]})})}function rq({number:e,isActive:t}){return(0,n.jsxs)("svg",{className:`w-5 h-5 flex-shrink-0 ${t?"text-brand":"text-muted-foreground"}`,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"currentColor",stroke:"none",fontSize:"12",fontWeight:"500",children:e})]})}function rV({tabs:e,activeTabId:t,unreadTabs:r,dragTabIndex:s,dragOverTabIndex:l,isPinned:a,onTogglePin:i,onSwitchTab:c,onCloseTab:d,onNewTab:u,onDragStart:h,onDragOver:m,onDrop:x,onDragEnd:f}){let{t:p}=(0,o.Bd)();return(0,n.jsx)("div",{className:"border-b border-border bg-card shrink-0",children:(0,n.jsxs)("div",{className:"flex items-center px-2 gap-1 overflow-x-auto",children:[e.map((o,u)=>(0,n.jsx)(tw.m,{content:o.title,delay:200,children:(0,n.jsxs)("div",{draggable:!0,onDragStart:()=>h(u),onDragOver:e=>m(e,u),onDrop:()=>x(u),onDragEnd:f,className:`group flex items-center gap-1 px-3 py-1.5 text-sm cursor-pointer rounded-t-lg transition-colors ${o.id===t?"bg-accent text-foreground":"text-muted-foreground hover:bg-secondary"} ${s===u?"opacity-50":""} ${l===u?"border-l-2 border-brand":""}`,onClick:()=>c(o.id),children:[(0,n.jsxs)("div",{className:"relative flex-shrink-0",children:[(0,n.jsx)(rq,{number:u+1,isActive:o.id===t}),o.isLoading&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-orange-9 animate-pulse"}),!o.isLoading&&r.has(o.id)&&o.id!==t&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-red-500"}),i&&a?.(o.id)&&!o.isLoading&&!(r.has(o.id)&&o.id!==t)&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),i(o.id)},className:"absolute -top-1 -right-1 w-3.5 h-3.5 flex items-center justify-center rounded-full bg-card text-amber-500 hover:text-destructive transition-colors",title:p("tabBar.unpin"),children:(0,n.jsx)("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M16 4h-2V2h-4v2H8c-.55 0-1 .45-1 1v4l-2 3v2h5.97v7l1 1 1-1v-7H19v-2l-2-3V5c0-.55-.45-1-1-1z"})})}),i&&!a?.(o.id)&&!o.isLoading&&!(r.has(o.id)&&o.id!==t)&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),i(o.id)},className:"absolute -top-1 -right-1 w-3.5 h-3.5 flex items-center justify-center rounded-full bg-card text-muted-foreground opacity-0 group-hover:opacity-60 hover:!opacity-100 hover:!text-brand transition-all",title:p("tabBar.pin"),children:(0,n.jsx)("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2.5,children:(0,n.jsx)("path",{d:"M16 4h-2V2h-4v2H8c-.55 0-1 .45-1 1v4l-2 3v2h5.97v7l1 1 1-1v-7H19v-2l-2-3V5c0-.55-.45-1-1-1z"})})})]}),(0,n.jsx)("span",{className:"max-w-32 truncate",children:o.title}),e.length>1&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),d(o.id)},className:"ml-1 p-0.5 rounded hover:bg-muted opacity-0 group-hover:opacity-100 transition-opacity",title:p("tabBar.closeTab"),children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})},o.id)),(0,n.jsx)("button",{onClick:u,className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:p("tabBar.newTab"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})})]})})}var rK=r(44810),rJ=r(12651),rX=r(81165),rY=r(16950),rQ=r(11019),rG=r(12612);function rZ({filePath:e}){let[t,r]=(0,s.useState)(null),[o,l]=(0,s.useState)(!0),[a,i]=(0,s.useState)(null),c=(0,s.useRef)(!1),d=ec(e),u=ei(e);if((0,s.useEffect)(()=>{u?l(!1):c.current||(c.current=!0,(async()=>{l(!0),i(null);try{let t=await fetch(`/api/file?path=${encodeURIComponent(e)}`);if(!t.ok)throw Error(`Failed to load file: ${t.statusText}`);let n=await t.json();r(n.content)}catch(e){i(e instanceof Error?e.message:"Unknown error")}finally{l(!1),c.current=!1}})())},[e,u]),a)return(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-red-11",children:a})});if(o)return(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("span",{className:"text-sm text-muted-foreground",children:"Loading..."})});if(ei(e)){let t=`/api/file?path=${encodeURIComponent(e)}&raw=true`;return(0,n.jsx)("div",{className:"flex items-center justify-center h-full overflow-auto",children:(0,n.jsx)("img",{src:t,alt:e.split("/").pop()||"image",className:"max-w-full max-h-full object-contain"})})}return t?d?(0,n.jsx)(r1,{content:t}):(0,n.jsx)(eR,{content:t,filePath:e,showLineNumbers:!0,showSearch:!0,className:"h-full"}):(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("span",{className:"text-sm text-muted-foreground",children:"No content"})})}let r0=[eI.W];function r1({content:e}){let t=(0,s.useRef)(null);return(0,n.jsxs)("div",{className:"h-full flex",children:[(0,n.jsx)(eD.l,{content:e,containerRef:t}),(0,n.jsx)("div",{ref:t,className:"flex-1 overflow-auto p-4",children:(0,n.jsx)(eP.T,{content:e,rehypePlugins:r0})})]})}function r2({title:e,content:t,toolName:r,onClose:l}){let{t:a}=(0,o.Bd)(),i=function(e){try{return JSON.parse(e),!0}catch{return!1}}(t),c=function(e){try{let t=JSON.parse(e);if(t&&"string"==typeof t.file_path&&"string"==typeof t.old_string&&"string"==typeof t.new_string)return t}catch{}return null}(t),d=function(e){try{let t=JSON.parse(e);if(t&&"string"==typeof t.file_path)return t.file_path}catch{let t=e.trim();if(t.startsWith("/")&&!t.includes("\n")&&t.length<500)return t}return null}(t),u=!!c,h=!!d,[m,x]=(0,s.useState)(("Read"===r||"Write"===r)&&h?"file":u?"diff-unified":i?"readable":"json"),f=(0,s.useRef)(null),p=eu(f);(0,s.useEffect)(()=>{let e=e=>{if((e.metaKey||e.ctrlKey)&&"f"===e.key&&"readable"===m&&i){e.preventDefault(),p.open();return}if("Escape"===e.key){if(p.isVisible)return void p.close();document.activeElement instanceof HTMLElement&&document.activeElement.blur(),l()}};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[l,m,i,p]);let b=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:l,children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-[90vh] flex flex-col transition-all",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground",children:e}),d&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(d),(0,g.oR)(a("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:a("common.copyAbsPath"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[i&&(0,n.jsxs)("div",{className:"flex items-center gap-1 bg-accent rounded p-0.5",children:[u&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:()=>x("diff-split"),className:`px-2 py-1 text-xs rounded transition-colors ${"diff-split"===m?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,title:a("diffViewer.sideBySide"),children:"Split"}),(0,n.jsx)("button",{onClick:()=>x("diff-unified"),className:`px-2 py-1 text-xs rounded transition-colors ${"diff-unified"===m?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,title:a("diffViewer.unified"),children:"Unified"})]}),h&&(0,n.jsx)("button",{onClick:()=>x("file"),className:`px-2 py-1 text-xs rounded transition-colors ${"file"===m?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,title:a("diffViewer.previewFile"),children:"File"}),(0,n.jsx)("button",{onClick:()=>x("readable"),className:`px-2 py-1 text-xs rounded transition-colors ${"readable"===m?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:a("common.readable")}),(0,n.jsx)("button",{onClick:()=>x("json"),className:`px-2 py-1 text-xs rounded transition-colors ${"json"===m?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:"JSON"})]}),(0,n.jsx)("button",{onClick:l,className:"p-1 text-slate-9 hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto p-4",children:"file"===m&&d?(0,n.jsx)(rZ,{filePath:d}):"diff-unified"===m&&c?(0,n.jsx)(_,{oldContent:c.old_string,newContent:c.new_string,filePath:c.file_path}):"diff-split"===m&&c?(0,n.jsx)(H,{oldContent:c.old_string,newContent:c.new_string,filePath:c.file_path}):"readable"===m&&i?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(eh,{search:p}),(0,n.jsx)("pre",{ref:f,className:"text-foreground whitespace-pre-wrap break-words",style:{fontSize:"0.8125rem"},children:Z(t)})]}):(0,n.jsx)("pre",{className:"text-foreground whitespace-pre-wrap break-words",style:{fontSize:"0.8125rem"},children:i?function(e){try{let t=JSON.parse(e);return JSON.stringify(t,null,2)}catch{return e}}(t):t})})]})});return(0,n.jsx)(rK.Z,{children:b})}let r5={Read:"\uD83D\uDCC4",Write:"✏️",Edit:"\uD83D\uDCDD",Bash:"\uD83D\uDCBB",Glob:"\uD83D\uDD0D",Grep:"\uD83D\uDD0E",WebFetch:"\uD83C\uDF10",WebSearch:"\uD83D\uDD0D"};function r4({toolCall:e,cwd:t}){let r,{t:l}=(0,o.Bd)(),[a,i]=(0,s.useState)(!1),[c,d]=(0,s.useState)(null),u=r5[e.name]||"\uD83D\uDD27",h=(r=e.input,"Bash"===e.name&&r.command&&"string"==typeof r.command?r.command:"Glob"===e.name&&r.pattern&&"string"==typeof r.pattern||"Grep"===e.name&&r.pattern&&"string"==typeof r.pattern?r.pattern:r.file_path&&"string"==typeof r.file_path?r.file_path:r.path&&"string"==typeof r.path?r.path:null),m="Glob"===e.name||"Grep"===e.name||"Bash"===e.name,x=h?m?h:(e=>{if(t&&e.startsWith(t)){let r=e.slice(t.length);return r.startsWith("/")?r.slice(1):r}let r=e.split("/");return r.length>2?".../"+r.slice(-2).join("/"):e})(h):null,f=t=>{let r="input"===t?l("toolCall.inputParams"):l("toolCall.resultLabel"),n="input"===t?JSON.stringify(e.input,null,2):"string"==typeof e.result?e.result:JSON.stringify(e.result,null,2);d({title:`${e.name}${x?` ${x}`:""} - ${r}`,content:n,toolName:e.name})};return(0,n.jsxs)("div",{className:"my-2 border border-border rounded-lg overflow-hidden bg-secondary",children:[(0,n.jsxs)("button",{onClick:()=>i(!a),className:"w-full px-3 py-2 flex items-center gap-2 text-left hover:bg-accent transition-colors",children:[(0,n.jsx)("span",{className:"text-base",children:u}),(0,n.jsx)("span",{className:"font-medium text-sm text-foreground flex-shrink-0",children:e.name}),x&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground truncate flex-1 min-w-0",title:h||"",children:x}),(0,n.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),h&&(navigator.clipboard.writeText(h),(0,g.oR)(l("common.copiedPath")))},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),h&&(navigator.clipboard.writeText(h),(0,g.oR)(l("common.copiedPath"))))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0 cursor-pointer",title:l("common.copyAbsPath"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}),(0,n.jsxs)("span",{className:"ml-auto flex items-center gap-2",children:[a&&!e.isLoading&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),f("input")},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),f("input"))},className:"text-xs text-brand hover:text-teal-10 cursor-pointer",title:l("toolCall.inputParamsTitle"),children:l("toolCall.input")}),e.result&&(0,n.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),f("result")},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),f("result"))},className:"text-xs text-brand hover:text-teal-10 cursor-pointer",title:l("toolCall.resultTitle"),children:l("toolCall.result")})]}),e.isLoading?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"}):(0,n.jsx)("span",{className:"text-slate-9 text-xs",children:a?"▲":"▼"})]})]}),a&&(0,n.jsxs)("div",{className:"border-t border-border",children:[(0,n.jsxs)("div",{className:"px-3 py-2",children:[(0,n.jsx)("div",{className:"mb-1",children:(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:[l("toolCall.inputParams"),":"]})}),(0,n.jsx)("pre",{className:"text-xs bg-secondary p-2 rounded overflow-x-auto max-h-24 overflow-y-auto text-foreground",children:JSON.stringify(e.input,null,2)})]}),e.result&&(0,n.jsxs)("div",{className:"px-3 py-2 border-t border-border",children:[(0,n.jsx)("div",{className:"mb-1",children:(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:[l("toolCall.resultLabel"),":"]})}),(0,n.jsx)("pre",{className:"text-xs bg-secondary p-2 rounded overflow-x-auto max-h-24 overflow-y-auto text-foreground",children:"string"==typeof e.result?e.result:JSON.stringify(e.result,null,2)})]})]}),c&&(0,n.jsx)(r2,{title:c.title,content:c.content,toolName:c.toolName,onClose:()=>d(null)})]})}var r3=r(48368),r6=r(21362);function r8(e,t){if(t&&e.startsWith(t)){let r=e.slice(t.length);return r.startsWith("/")?r.slice(1):r}return e}function r9({node:e,selectedUid:t,onSelect:r,depth:o=0}){let[l,a]=(0,s.useState)(!0);if(e.isFile&&e.change){let s=t===e.change.uid;return(0,n.jsxs)("button",{onClick:()=>r(e.change),className:`w-full flex items-center gap-1.5 px-2 py-1 text-xs text-left rounded transition-colors ${s?"bg-brand/15 text-brand":"text-foreground hover:bg-accent"}`,style:{paddingLeft:`${12*o+8}px`},"data-tooltip":e.fullPath,children:[(0,n.jsx)(r3.A,{className:"w-3.5 h-3.5 flex-shrink-0 opacity-60"}),(0,n.jsx)("span",{className:"truncate",children:e.name}),(0,n.jsx)("span",{className:`ml-auto text-[10px] flex-shrink-0 ${"write"===e.change.type?"text-green-500":"text-yellow-500"}`,children:"write"===e.change.type?"new":"edit"})]})}return(0,n.jsxs)("div",{children:[(0,n.jsxs)("button",{onClick:()=>a(!l),className:"w-full flex items-center gap-1 px-2 py-1 text-xs text-muted-foreground hover:text-foreground transition-colors",style:{paddingLeft:`${12*o+8}px`},children:[l?(0,n.jsx)(tt.A,{className:"w-3 h-3"}):(0,n.jsx)(r6.A,{className:"w-3 h-3"}),(0,n.jsx)("span",{className:"truncate",children:e.name})]}),l&&e.children.map((e,s)=>(0,n.jsx)(r9,{node:e,selectedUid:t,onSelect:r,depth:o+1},e.isFile&&e.change?e.change.uid:`${e.fullPath}-${s}`))]})}function r7({toolCalls:e,cwd:t,onClose:r}){let{t:l}=(0,o.Bd)(),a=(0,s.useMemo)(()=>(function(e,t){let r=[],n=0;for(let s of e)if("Edit"===s.name){let e=s.input;e.file_path&&"string"==typeof e.old_string&&"string"==typeof e.new_string&&r.push({filePath:r8(e.file_path,t),uid:`change-${n++}`,type:"edit",old_string:e.old_string,new_string:e.new_string})}else if("Write"===s.name){let e=s.input;e.file_path&&"string"==typeof e.content&&r.push({filePath:r8(e.file_path,t),uid:`change-${n++}`,type:"write",old_string:"",new_string:e.content})}return r})(e,t),[e,t]),i=(0,s.useMemo)(()=>(function e(t){return t.map(t=>{if(!t.isFile&&1===t.children.length&&!t.children[0].isFile){let r=t.children[0];return{...r,name:t.name+"/"+r.name,children:e(r.children)}}return{...t,children:e(t.children)}})})(function(e){let t=[];for(let r of e){let e=r.filePath.split("/").filter(Boolean),n=t;for(let t=0;t<e.length;t++){let s=e[t],o=t===e.length-1,l=e.slice(0,t+1).join("/");if(o){let e={name:s,fullPath:l,isFile:!0,children:[],change:r};n.push(e)}else{let e=n.find(e=>e.name===s&&!e.isFile);e||(e={name:s,fullPath:l,isFile:!1,children:[]},n.push(e)),n=e.children}}}return t}(a)),[a]),[c,d]=(0,s.useState)(a[0]||null),[u,h]=(0,s.useState)("unified"),[m,x]=(0,s.useState)(null),f=(0,s.useRef)(null);if((0,s.useEffect)(()=>{let e=f.current;if(!e)return;let t=t=>{let r=t;for(;r&&r!==e;){if(r.dataset.tooltip)return r.dataset.tooltip;r=r.parentElement}return null},r=e=>{let r=t(e.target);x(r?{text:r,x:e.clientX,y:e.clientY}:null)},n=e=>{x(r=>{if(!r)return null;let n=t(e.target);return n?{text:n,x:e.clientX,y:e.clientY}:null})},s=r=>{let n=r.relatedTarget;n&&e.contains(n)&&t(n)||x(null)};return e.addEventListener("mouseover",r),e.addEventListener("mousemove",n),e.addEventListener("mouseout",s),()=>{e.removeEventListener("mouseover",r),e.removeEventListener("mousemove",n),e.removeEventListener("mouseout",s)}},[]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&r()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[r]),0===a.length)return null;let p=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:r,children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-[90vh] flex flex-col transition-all",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsx)("div",{className:"flex items-center gap-2",children:(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground",children:l("diffViewer.fileChanges",{count:a.length})})}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1 bg-accent rounded p-0.5",children:[(0,n.jsx)("button",{onClick:()=>h("unified"),className:`px-2 py-1 text-xs rounded transition-colors ${"unified"===u?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:"Unified"}),(0,n.jsx)("button",{onClick:()=>h("split"),className:`px-2 py-1 text-xs rounded transition-colors ${"split"===u?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:"Split"})]}),(0,n.jsx)("button",{onClick:r,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)(eJ.A,{className:"w-5 h-5"})})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[(0,n.jsx)("div",{ref:f,className:"w-56 flex-shrink-0 border-r border-border overflow-y-auto py-2",children:i.map((e,t)=>(0,n.jsx)(r9,{node:e,selectedUid:c?.uid||"",onSelect:d},e.isFile&&e.change?e.change.uid:`${e.fullPath}-${t}`))}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:c?"unified"===u?(0,n.jsx)(_,{oldContent:c.old_string,newContent:c.new_string,filePath:c.filePath}):(0,n.jsx)(H,{oldContent:c.old_string,newContent:c.new_string,filePath:c.filePath,isNew:"write"===c.type}):(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:l("diffViewer.selectFileToView")})})]})]})});return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(rK.Z,{children:p}),m&&(0,n.jsx)(rK.Z,{children:(0,n.jsx)("div",{className:"fixed z-[9999] px-2 py-1 bg-popover text-popover-foreground text-xs font-mono rounded shadow-lg border border-brand whitespace-nowrap pointer-events-none",style:{left:m.x+12,top:m.y+16},children:m.text})})]})}var ne=r(58515),nt=r(36201),nr=r(55804),nn=r(37618);function ns(e){let t=e.input?.questions||[],r=e.input?.answers||{},n={};if(e.result)try{let t=JSON.parse(e.result);t?.answers&&(n=t.answers)}catch{}return{questions:t,answers:{...r,...n}}}function no(e,t){return`${e}-${t}`}function nl({toolCalls:e,onClose:t}){let{t:r}=(0,o.Bd)(),[l,a]=(0,s.useState)({}),[i,c]=(0,s.useState)({}),[d,u]=(0,s.useState)({}),[h,m]=(0,s.useState)({});(0,s.useEffect)(()=>{let t={};e.forEach((e,r)=>{let{questions:n,answers:s}=ns(e);n.forEach((e,n)=>{let o=s[e.question];if(o){let s=no(r,n);t[s]=o,e.options.some(e=>e.label===o)||(c(e=>({...e,[s]:!0})),u(e=>({...e,[s]:o})))}})}),queueMicrotask(()=>a(t))},[e]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&t()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[t]);let x=e.reduce((e,t)=>{let{questions:r}=ns(t);return e+r.length},0),f=Object.values(h).filter(Boolean).length,p=(0,s.useCallback)((e,t)=>{a(r=>({...r,[e]:t})),c(t=>({...t,[e]:!1}))},[]),b=(0,s.useCallback)(e=>{c(t=>{let r=!t[e];if(r){let t=d[e]||"";t&&a(r=>({...r,[e]:t}))}return{...t,[e]:r}})},[d]),v=(0,s.useCallback)((e,t)=>{u(r=>({...r,[e]:t})),t&&a(r=>({...r,[e]:t}))},[]),j=(0,s.useCallback)(e=>{m(t=>({...t,[e]:!t[e]}))},[]),w=(0,s.useCallback)(()=>{let t=f>0,n=[];e.forEach((e,s)=>{let{questions:o}=ns(e);o.forEach((e,o)=>{let a=no(s,o);if(t&&!h[a])return;let i=l[a];n.push(`Q: ${e.question}`),n.push(`A: ${i||r("askQuestion.notSelected")}`),n.push("")})}),navigator.clipboard.writeText(n.join("\n").trim()),(0,g.oR)(t?r("toast.copiedQA",{count:f}):r("toast.copiedAllQA"))},[e,l,h,f,r]),y=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:t,children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-6xl h-[90vh] flex flex-col overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground",children:r("askQuestion.title")}),(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:[r("askQuestion.nQuestions",{count:x}),f>0&&` \xb7 ${r("askQuestion.checkedN",{count:f})}`]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:w,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:f>0?r("askQuestion.copyChecked",{count:f}):r("askQuestion.copyAll"),children:(0,n.jsx)(e6.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)(eJ.A,{className:"w-5 h-5"})})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto px-6 py-4 space-y-6",children:e.map((t,s)=>{let{questions:o}=ns(t);return o.map((t,a)=>{let c=no(s,a),u=l[c],m=i[c]||!1,x=h[c]||!1;return(0,n.jsxs)("div",{className:"space-y-3",children:[(0,n.jsxs)("div",{className:"flex items-start gap-2",children:[(0,n.jsx)("button",{onClick:()=>j(c),className:"mt-0.5 flex-shrink-0 p-0.5 rounded hover:bg-accent transition-colors",title:r("askQuestion.checkToCopy"),children:x?(0,n.jsx)(ne.A,{className:"w-4 h-4 text-brand"}):(0,n.jsx)(nt.A,{className:"w-4 h-4 text-muted-foreground"})}),t.header&&(0,n.jsx)("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium bg-brand/10 text-brand flex-shrink-0 mt-0.5",children:t.header}),(0,n.jsx)("span",{className:"text-sm font-medium text-foreground",children:t.question})]}),(0,n.jsxs)("div",{className:"space-y-1 ml-7",children:[t.options.map((e,t)=>{let r=u===e.label&&!m;return(0,n.jsxs)("button",{onClick:()=>p(c,e.label),className:`flex items-start gap-2 px-2.5 py-1.5 rounded-md transition-colors w-full text-left cursor-pointer hover:bg-accent/50 ${r?"bg-brand/10 hover:bg-brand/15":""}`,children:[(0,n.jsx)("div",{className:"mt-0.5 flex-shrink-0",children:r?(0,n.jsx)(nr.A,{className:"w-3.5 h-3.5 text-brand"}):(0,n.jsx)("div",{className:"w-3.5 h-3.5 rounded-full border border-muted-foreground"})}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("div",{className:`text-sm ${r?"text-foreground font-medium":"text-foreground"}`,children:e.label}),e.description&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground mt-0.5",children:e.description})]})]},t)}),(0,n.jsxs)("button",{onClick:()=>b(c),className:`flex items-start gap-2 px-2.5 py-1.5 rounded-md transition-colors w-full text-left cursor-pointer hover:bg-accent/50 ${m?"bg-brand/10 hover:bg-brand/15":""}`,children:[(0,n.jsx)("div",{className:"mt-0.5 flex-shrink-0",children:m?(0,n.jsx)(nr.A,{className:"w-3.5 h-3.5 text-brand"}):(0,n.jsx)("div",{className:"w-3.5 h-3.5 rounded-full border border-muted-foreground"})}),(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)(nn.A,{className:"w-3.5 h-3.5 text-muted-foreground"}),(0,n.jsx)("span",{className:"text-sm text-muted-foreground",children:r("askQuestion.custom")})]})]}),m&&(0,n.jsx)("div",{className:"ml-6 mt-1",children:(0,n.jsx)("input",{type:"text",autoFocus:!0,value:d[c]||"",onChange:e=>v(c,e.target.value),placeholder:r("askQuestion.customPlaceholder"),className:"w-full px-3 py-1.5 text-sm bg-background border border-border rounded-md focus:outline-none focus:ring-1 focus:ring-brand text-foreground placeholder:text-muted-foreground"})})]}),(s!==e.length-1||a!==o.length-1)&&(0,n.jsx)("div",{className:"border-b border-border/50 mt-3"})]},c)})})})]})});return(0,n.jsx)(rK.Z,{children:y})}function na({image:e,onClose:t}){let{t:r}=(0,o.Bd)(),s=(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80",onClick:t,children:[(0,n.jsx)("button",{onClick:t,className:"absolute top-4 right-4 w-10 h-10 flex items-center justify-center text-white/80 hover:text-white bg-black/40 hover:bg-black/60 rounded-full transition-colors",children:(0,n.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),(0,n.jsx)("img",{src:`data:${e.media_type};base64,${e.data}`,alt:r("chat.imagePreview"),className:"max-w-[90vw] max-h-[90vh] object-contain",onClick:e=>e.stopPropagation()})]});return(0,n.jsx)(rK.Z,{children:s})}function ni({filePath:e,content:t,cwd:r,onClose:o}){let[l,a]=(0,s.useState)(null);return(0,n.jsx)(rK.Z,{children:(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:o,children:(0,n.jsx)("div",{ref:a,className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-[90vh] flex flex-col relative",onClick:e=>e.stopPropagation(),children:(0,n.jsx)(v,{container:l,children:(0,n.jsx)(eA,{content:t,filePath:e,cwd:r,onClose:o})})})})})}let nc=(0,s.memo)(function({message:e,cwd:t,sessionId:r,onFork:l}){let a,i,c,d,{t:u}=(0,o.Bd)(),[h,m]=(0,s.useState)(null),[x,f]=(0,s.useState)(!1),[p,b]=(0,s.useState)(!1),[v,j]=(0,s.useState)(!1),w="user"===e.role,y=e.images&&e.images.length>0,k=e.toolCalls?.length||0,N=k>1,C=!!r&&!!t&&!!l,S=(0,s.useMemo)(()=>e.toolCalls?.some(e=>"Edit"===e.name||"Write"===e.name)||!1,[e.toolCalls]),L=(0,s.useMemo)(()=>{if(!e.toolCalls)return null;for(let t=e.toolCalls.length-1;t>=0;t--)if("TodoWrite"===e.toolCalls[t].name)return e.toolCalls[t];return null},[e.toolCalls]),E=(0,s.useMemo)(()=>e.toolCalls?e.toolCalls.filter(e=>"AskUserQuestion"===e.name):[],[e.toolCalls]),M=(0,s.useMemo)(()=>{if(!e.toolCalls)return[];let t=new Set,r=[];for(let n of e.toolCalls)if("Read"===n.name||"Edit"===n.name||"Write"===n.name){let e=n.input.file_path;e&&e.toLowerCase().endsWith(".md")&&!t.has(e)&&(t.add(e),r.push(e))}return r},[e.toolCalls]),[T,$]=(0,s.useState)(null),[R,P]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!T)return void queueMicrotask(()=>P(null));let e=!1;return fetch(`/api/file?path=${encodeURIComponent(T)}`).then(e=>e.ok?e.json():Promise.reject()).then(t=>{e||P(t.content)}).catch(()=>{e||((0,g.oR)(u("toast.readFileFailed"),"error"),$(null))}),()=>{e=!0}},[T]);let I=()=>{e.content&&(navigator.clipboard.writeText(e.content),(0,g.oR)(u("toast.copiedMessage")))},D=()=>{C&&l(e.id)},B=(e=>{if(!e)return"";let t=new Date(e);if(isNaN(t.getTime()))return"";let r=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return`${r}-${n} ${s}:${o}`})(e.timestamp);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:`flex flex-col ${w?"items-end":"items-start"} mb-4 group`,"data-role":e.role,children:[B&&(0,n.jsx)("span",{className:"text-[11px] text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity mb-0.5 px-1",children:B}),(0,n.jsxs)("div",{className:`flex ${w?"justify-end":"justify-start"} w-full`,children:[w&&(0,n.jsxs)("div",{className:"self-start mt-2 mr-1 flex flex-col gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.content&&(0,n.jsx)("button",{onClick:I,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:u("chat.copyMessage"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),C&&(0,n.jsx)("button",{onClick:D,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:u("chat.forkSession"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"18",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("path",{d:"M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9"}),(0,n.jsx)("path",{d:"M12 12v3"})]})})]}),(0,n.jsxs)("div",{className:`max-w-[80%] ${w?"bg-accent text-foreground border border-brand rounded-2xl rounded-br-md":"bg-accent text-foreground dark:text-slate-11 rounded-2xl rounded-bl-md"} px-4 py-2`,children:[y&&(0,n.jsx)("div",{className:`flex flex-wrap gap-2 ${e.content?"mb-2":""}`,children:e.images.map((e,t)=>(0,n.jsx)("div",{className:"relative w-16 h-16 rounded-lg overflow-hidden border border-white/20 cursor-pointer hover:opacity-90 transition-opacity",onClick:()=>m(e),children:(0,n.jsx)("img",{src:`data:${e.media_type};base64,${e.data}`,alt:u("chat.imageN",{index:t+1}),className:"w-full h-full object-cover"})},t))}),e.content&&(0,n.jsxs)("div",{className:"break-words",children:[(0,n.jsx)(eP.T,{content:e.content,isUser:w,isStreaming:e.isStreaming}),e.isStreaming&&(0,n.jsx)("span",{className:"inline-block w-2 h-4 ml-1 bg-current animate-pulse"})]}),L&&(c=(i=Array.isArray(a=L.input?.todos)?a:[]).filter(e=>"completed"===e.status).length,d=i.length,(0,n.jsx)("div",{className:`${e.content||y?"mt-2":""}`,children:(0,n.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden bg-secondary/50 px-3 py-2 space-y-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-1.5",children:[(0,n.jsx)("div",{className:"flex-1 h-1 bg-secondary rounded-full overflow-hidden",children:(0,n.jsx)("div",{className:"h-full bg-green-500 rounded-full transition-all duration-300",style:{width:`${d>0?c/d*100:0}%`}})}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:[c,"/",d]})]}),i.map((e,t)=>(0,n.jsxs)("div",{className:`flex items-center gap-1.5 ${"completed"===e.status?"opacity-50":""}`,children:["completed"===e.status?(0,n.jsx)(rJ.A,{className:"w-3 h-3 text-green-500 flex-shrink-0"}):"in_progress"===e.status?(0,n.jsx)(rX.A,{className:"w-3 h-3 text-brand flex-shrink-0 animate-spin"}):(0,n.jsx)(rY.A,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"}),(0,n.jsx)("span",{className:`text-xs truncate ${"completed"===e.status?"text-muted-foreground":"text-foreground"}`,children:"in_progress"===e.status&&e.activeForm?e.activeForm:e.content})]},t))]})})),M.length>0&&(0,n.jsx)("div",{className:`${e.content||y||L?"mt-2":""}`,children:(0,n.jsx)("div",{className:"border border-border rounded-lg overflow-hidden bg-secondary/50 px-3 py-2 space-y-0.5",children:M.map(e=>(0,n.jsxs)("button",{onClick:()=>$(e),className:"flex items-center gap-1.5 w-full text-left hover:bg-accent rounded px-1 py-0.5 transition-colors group/md",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground group-hover/md:text-foreground truncate",children:e.split("/").pop()})]},e))})}),e.toolCalls&&e.toolCalls.length>0&&(0,n.jsx)("div",{className:`${e.content||y?"mt-2":""}`,children:N?(0,n.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden bg-secondary",children:[(0,n.jsxs)("div",{className:"flex items-center",children:[(0,n.jsxs)("button",{onClick:()=>f(!x),className:"flex-1 px-3 py-2 flex items-center gap-2 text-left hover:bg-accent transition-colors active:bg-muted",children:[(0,n.jsx)("span",{className:"text-lg",children:"\uD83D\uDD27"}),(0,n.jsx)("span",{className:"font-medium text-foreground",children:u("chat.toolCalls",{count:k})}),(0,n.jsx)("span",{className:"ml-auto text-muted-foreground text-sm",children:x?u("chat.collapse"):u("chat.expand")})]}),E.length>0&&(0,n.jsx)("button",{onClick:()=>j(!0),className:"px-3 py-2 text-muted-foreground hover:text-foreground hover:bg-accent transition-colors border-l border-border",title:u("chat.viewQuestions"),children:(0,n.jsx)(rQ.A,{className:"w-4 h-4"})}),S&&(0,n.jsx)("button",{onClick:()=>b(!0),className:"px-3 py-2 text-muted-foreground hover:text-foreground hover:bg-accent transition-colors border-l border-border",title:u("chat.viewAllFileChanges"),children:(0,n.jsx)(rG.A,{className:"w-4 h-4"})})]}),x&&(0,n.jsx)("div",{className:"border-t border-border p-2 space-y-1",children:e.toolCalls.map((e,r)=>(0,n.jsx)(r4,{toolCall:e,cwd:t},`${e.id}-${r}`))})]}):e.toolCalls.map((e,r)=>(0,n.jsx)(r4,{toolCall:e,cwd:t},`${e.id}-${r}`))})]}),!w&&(0,n.jsxs)("div",{className:"self-start mt-2 ml-1 flex flex-col gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.content&&(0,n.jsx)("button",{onClick:I,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:u("chat.copyMessage"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),C&&(0,n.jsx)("button",{onClick:D,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:u("chat.forkSession"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"18",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("path",{d:"M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9"}),(0,n.jsx)("path",{d:"M12 12v3"})]})})]})]})]}),h&&(0,n.jsx)(na,{image:h,onClose:()=>m(null)}),p&&e.toolCalls&&(0,n.jsx)(r7,{toolCalls:e.toolCalls,cwd:t,onClose:()=>b(!1)}),v&&E.length>0&&(0,n.jsx)(nl,{toolCalls:E,onClose:()=>j(!1)}),T&&null!==R&&(0,n.jsx)(ni,{filePath:T,content:R,cwd:t||"",onClose:()=>$(null)})]})}),nd=(0,s.forwardRef)(function({messages:e,isLoading:t,cwd:r,sessionId:l,hasMoreHistory:a,isLoadingMore:i,onLoadMore:c,onFork:d,isActive:u=!0,onContentSearch:g},b){let{t:v}=(0,o.Bd)(),j=(0,s.useRef)(null),w=(0,s.useRef)(null),y=(0,s.useRef)(null),k=(0,s.useRef)(null),[N,E]=(0,s.useState)(null),[M,T]=(0,s.useState)(!0),[$,R]=(0,s.useState)(!1),[P,I]=(0,s.useState)(!1);(0,s.useEffect)(()=>{E(k.current)},[]);let{isSearchVisible:D,searchQuery:B,setSearchQuery:F,matches:O,currentMatchIndex:W,goToNextMatch:z,goToPrevMatch:H,closeSearch:_,searchInputRef:U,handleSearchKeyDown:q}=function(e){let[t,r]=(0,s.useState)(!1),[n,o]=(0,s.useState)(""),[l,a]=(0,s.useState)([]),[i,c]=(0,s.useState)(0),d=(0,s.useRef)(null),u=(0,s.useRef)([]),h=(0,s.useCallback)(()=>{let t=e.current;t&&(t.querySelectorAll("mark.chat-search-match, mark.chat-search-current").forEach(e=>{let t=e.parentNode;t&&(t.replaceChild(document.createTextNode(e.textContent||""),e),t.normalize())}),u.current=[])},[e]),m=(0,s.useCallback)(t=>{if(h(),!t||!e.current){a([]),c(0);return}let r=[],n=[],s=t.toLowerCase();e.current.querySelectorAll("[data-message-id]").forEach(e=>{let o,l=e.getAttribute("data-message-id")||"",a=0,i=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,null),c=[];for(;o=i.nextNode();)c.push(o);for(let e of c){let o=(e.textContent||"").toLowerCase(),i=0,c=[];for(;;){let e=o.indexOf(s,i);if(-1===e)break;c.push({start:e,end:e+t.length}),i=e+1}if(0!==c.length)for(let t=c.length-1;t>=0;t--){let s=c[t];e.splitText(s.end);let o=e.splitText(s.start),i=document.createElement("mark");i.className="chat-search-match",i.textContent=o.textContent,o.parentNode.replaceChild(i,o),r.push({messageId:l,markIndex:a}),n.push(i),a++}}}),r.reverse(),n.reverse(),u.current=n,a(r),c(r.length>0?0:-1)},[e,h]);(0,s.useEffect)(()=>{queueMicrotask(()=>m(n))},[n,m]),(0,s.useEffect)(()=>{let e=u.current;e.forEach((e,t)=>{e.className=t===i?"chat-search-current":"chat-search-match"}),i>=0&&i<e.length&&e[i].scrollIntoView({behavior:"smooth",block:"center"})},[i,l]);let x=(0,s.useCallback)(()=>{0!==l.length&&c(e=>(e+1)%l.length)},[l.length]),f=(0,s.useCallback)(()=>{0!==l.length&&c(e=>(e-1+l.length)%l.length)},[l.length]),p=(0,s.useCallback)(()=>{r(!0),setTimeout(()=>d.current?.focus(),0)},[]),g=(0,s.useCallback)(()=>{r(!1),o(""),h(),a([]),c(0)},[h]),b=(0,s.useCallback)(e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?f():x()),"Escape"===e.key&&g()},[x,f,g]);return(0,s.useEffect)(()=>{let t=e.current;if(!t)return;let r=e=>{(e.metaKey||e.ctrlKey)&&"f"===e.key&&(e.preventDefault(),e.stopPropagation(),p())};return t.addEventListener("keydown",r),()=>t.removeEventListener("keydown",r)},[e,p]),{isSearchVisible:t,searchQuery:n,setSearchQuery:o,matches:l,currentMatchIndex:i,goToNextMatch:x,goToPrevMatch:f,openSearch:p,closeSearch:g,searchInputRef:d,handleSearchKeyDown:b}}(k),V=C(),K=(0,s.useRef)(null),J=(0,s.useRef)(()=>{}),{addComment:X,refresh:Y}=p({cwd:r||"",filePath:x}),[Q,G]=(0,s.useState)(null),[Z,ee]=(0,s.useState)(null),et=(0,s.useCallback)(e=>{if(Q||Z)return;let t=window.getSelection();if(!t||t.isCollapsed||!t.rangeCount){K.current=null,J.current();return}let r=t.toString().trim();if(!r){K.current=null,J.current();return}let n=t.anchorNode instanceof HTMLElement?t.anchorNode:t.anchorNode?.parentElement;if(n?.closest('[data-role="user"]')){K.current=null,J.current();return}K.current={x:e.clientX,y:e.clientY,range:{start:0,end:0},selectedText:r},J.current()},[Q,Z]),er=(0,s.useCallback)(e=>{let t=e.target;!(t.closest(".floating-toolbar")||t.closest('[class*="z-[200]"]'))&&K.current&&(K.current=null,J.current())},[]),en=(0,s.useCallback)(()=>{let e=K.current;e&&(G({x:e.x,y:e.y,text:e.selectedText}),K.current=null,J.current(),window.getSelection()?.removeAllRanges())},[]),es=(0,s.useCallback)(()=>{let e=K.current;e&&(ee({x:e.x,y:e.y,text:e.selectedText}),K.current=null,J.current(),window.getSelection()?.removeAllRanges())},[]),eo=(0,s.useCallback)(()=>{let e=K.current;if(!e||!g)return;let t=e.selectedText.trim();K.current=null,J.current(),window.getSelection()?.removeAllRanges(),t&&g(t)},[g]),el=(0,s.useCallback)(async e=>{Q&&(await X(0,0,e,Q.text),G(null))},[Q,X]),ea=(0,s.useCallback)(async e=>{if(Z&&V&&r)try{let t=(await h(r)).map(e=>({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0}));t.push({filePath:x,startLine:0,endLine:0,codeContent:Z.text});let n=f(t,e);V.sendMessage(n),await m(r),Y(),ee(null)}catch(e){console.error("Failed to send to AI:",e)}},[Z,V,r,Y]),ei=(0,s.useMemo)(()=>{let t=new Set;return e.filter(e=>!t.has(e.id)&&(t.add(e.id),!0))},[e]),ec=(0,s.useRef)(0),ed=(0,s.useRef)(!1),eu=(0,s.useCallback)(()=>{let e=y.current;return!e||e.scrollHeight-e.scrollTop-e.clientHeight<50},[]),eh=(0,s.useCallback)(()=>{let e=y.current;return!e||e.scrollTop<50},[]),em=(0,s.useCallback)(()=>{let e=eu(),t=eh();if(T(e),R(!t),I(!e),t&&a&&!i&&c){let e=y.current;e&&(ec.current=e.scrollHeight,ed.current=!0),c()}},[eu,eh,a,i,c]),ex=(0,s.useCallback)(()=>{w.current?.scrollIntoView({behavior:"smooth"})},[]),ef=(0,s.useCallback)(()=>{j.current?.scrollIntoView({behavior:"smooth"})},[]),ep=(0,s.useCallback)(e=>{let t=y.current;if(!t)return;let r=t.querySelector(`[data-message-id="${e}"]`);r&&(r.scrollIntoView({behavior:"smooth",block:"center"}),r.classList.add("ring-2","ring-brand","ring-offset-2"),setTimeout(()=>{r.classList.remove("ring-2","ring-brand","ring-offset-2")},2e3))},[]);(0,s.useImperativeHandle)(b,()=>({scrollToMessage:ep}),[ep]);let eg=(0,s.useRef)(0),eb=(0,s.useRef)(!0);(0,s.useEffect)(()=>{let t=eg.current,r=e.length;eg.current=r,!eb.current&&M&&r>t&&j.current?.scrollIntoView({behavior:"smooth"})},[e,M]),(0,s.useEffect)(()=>{M&&t&&j.current?.scrollIntoView({behavior:"smooth"})},[t,M]),(0,s.useEffect)(()=>{if(ed.current&&!i){let e=y.current;if(e){let t=e.scrollHeight-ec.current;e.scrollTop=t,ed.current=!1}}},[e,i]);let ev=(0,s.useRef)(!1);return(0,s.useEffect)(()=>{u&&ev.current&&e.length>0&&(ev.current=!1,j.current?.scrollIntoView({behavior:"instant"}))},[u,e.length]),(0,s.useEffect)(()=>{eb.current&&e.length>0&&(eb.current=!1,u?j.current?.scrollIntoView({behavior:"instant"}):ev.current=!0)},[e.length,u]),(0,n.jsxs)("div",{ref:k,className:"relative flex-1 min-h-0 overflow-hidden flex flex-col outline-none",tabIndex:-1,onMouseUp:et,onMouseDown:er,children:[D&&(0,n.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-2 px-3 py-2 bg-secondary border-b border-border",children:[(0,n.jsx)("input",{ref:U,type:"text",value:B,onChange:e=>F(e.target.value),onKeyDown:q,placeholder:v("codeViewer.searchChat"),className:"flex-1 max-w-xs px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:O.length>0?`${W+1}/${O.length}`:v("common.noMatch")}),(0,n.jsx)("button",{onClick:H,disabled:0===O.length,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:v("codeViewer.prevShiftEnter"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"})})}),(0,n.jsx)("button",{onClick:z,disabled:0===O.length,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:v("codeViewer.nextEnter"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})}),(0,n.jsx)("button",{onClick:_,className:"p-1 rounded hover:bg-accent",title:v("codeViewer.closeEsc"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{ref:y,onScroll:em,className:"relative flex-1 min-h-0 overflow-y-auto p-4",children:0!==e.length||t?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{ref:w}),a&&(0,n.jsx)("div",{className:"flex justify-center py-3",children:i?(0,n.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground text-sm",children:[(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"}),(0,n.jsx)("span",{children:v("chat.loadMoreHistory")})]}):(0,n.jsx)("button",{onClick:c,className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:v("chat.scrollUpForMore")})}),ei.map(e=>(0,n.jsx)("div",{"data-message-id":e.id,className:"transition-[box-shadow] duration-300",children:(0,n.jsx)(nc,{message:e,cwd:r,sessionId:l,onFork:d})},e.id)),t&&(0,n.jsx)("div",{className:"flex justify-start mb-4",children:(0,n.jsx)("div",{className:"bg-accent rounded-2xl rounded-bl-md px-4 py-3",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,n.jsx)("span",{className:"inline-block w-5 h-5 border-2 border-brand border-t-transparent rounded-full animate-spin"}),(0,n.jsx)("span",{className:"text-sm",children:v("chat.claudeThinking")})]})})}),(0,n.jsx)("div",{ref:j})]}):(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-slate-9",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("div",{className:"text-4xl mb-4",children:"\uD83D\uDCAC"}),(0,n.jsx)("div",{children:v("chat.startConversation")})]})})}),$&&e.length>0&&(0,n.jsx)("button",{onClick:ex,className:"absolute top-2 left-1/2 -translate-x-1/2 p-2 bg-card text-muted-foreground hover:text-foreground shadow-md rounded-full transition-all hover:shadow-lg active:scale-95",title:v("chat.jumpToStart"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"})})}),P&&e.length>0&&(0,n.jsx)("button",{onClick:ef,className:"absolute bottom-2 left-1/2 -translate-x-1/2 p-2 bg-card text-muted-foreground hover:text-foreground shadow-md rounded-full transition-all hover:shadow-lg active:scale-95",title:v("chat.jumpToLatest"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})}),N&&(0,n.jsx)(A,{floatingToolbarRef:K,bumpRef:J,container:N,onAddComment:en,onSendToAI:es,onSearch:g?eo:void 0,isChatLoading:V?.isLoading}),Q&&N&&(0,n.jsx)(S,{x:Q.x,y:Q.y,range:{start:0,end:0},codeContent:Q.text,container:N,onSubmit:el,onClose:()=>G(null)}),Z&&N&&(0,n.jsx)(L,{x:Z.x,y:Z.y,range:{start:0,end:0},codeContent:Z.text,container:N,onSubmit:ea,onClose:()=>ee(null),isChatLoading:V?.isLoading})]})});function nu({image:e,onClose:t}){let{t:r}=(0,o.Bd)(),s=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-4",onClick:t,children:(0,n.jsxs)("div",{className:"relative max-w-[90vw] max-h-[90vh]",children:[(0,n.jsx)("img",{src:e.preview,alt:r("imagePreview.previewImage"),className:"max-w-full max-h-[90vh] object-contain rounded-lg",onClick:e=>e.stopPropagation()}),(0,n.jsx)("button",{onClick:t,className:"absolute -top-3 -right-3 w-8 h-8 bg-card text-foreground hover:text-foreground rounded-full shadow-lg flex items-center justify-center transition-colors",title:r("common.close"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})});return(0,n.jsx)(rK.Z,{children:s})}function nh({images:e,onRemove:t,disabled:r}){let{t:l}=(0,o.Bd)(),[a,i]=(0,s.useState)(null);return 0===e.length?null:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"flex flex-wrap gap-2 p-2 bg-secondary border-b border-border",children:e.map(e=>(0,n.jsxs)("div",{className:"relative group w-16 h-16 rounded-lg overflow-hidden border border-border cursor-pointer",onClick:()=>i(e),children:[(0,n.jsx)("img",{src:e.preview,alt:l("imagePreview.previewImage"),className:"w-full h-full object-cover hover:opacity-90 transition-opacity"}),(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),t(e.id)},className:"absolute top-0 right-0 w-5 h-5 bg-black/60 hover:bg-black/80 text-white text-xs flex items-center justify-center rounded-bl-lg opacity-0 group-hover:opacity-100 transition-opacity",title:l("imagePreview.deleteImage"),children:"✕"})]},e.id))}),a&&(0,n.jsx)(nu,{image:a,onClose:()=>i(null)})]})}var nm=r(28147);let nx=(0,s.memo)(function({onSend:e,disabled:t,cwd:r,onShowGitStatus:l,onShowComments:a,onShowUserMessages:i,onOpenNote:c,onCreateScheduledTask:d}){let{t:u}=(0,o.Bd)(),[h,m]=(0,s.useState)(""),[x,f]=(0,s.useState)([]),[p,b]=(0,s.useState)([]),[v,j]=(0,s.useState)(!1),[w,y]=(0,s.useState)(0),[k,N]=(0,s.useState)(!1),C=(0,s.useRef)(null),S=(0,s.useRef)(null),L=(0,s.useCallback)(()=>{let e=C.current;if(!e)return;e.style.height="auto";let t=Math.max(38,Math.min(e.scrollHeight,200));e.style.height=`${t}px`},[]);(0,s.useLayoutEffect)(()=>{L()},[h,L]),(0,s.useEffect)(()=>{(async()=>{try{let e=r?`/api/commands?cwd=${encodeURIComponent(r)}`:"/api/commands",t=await fetch(e);if(t.ok){let e=await t.json();b(e)}}catch(e){console.error("Failed to load commands:",e)}})()},[r]);let E=(0,s.useMemo)(()=>{if(!h.startsWith("/"))return[];let e=h.toLowerCase();return p.filter(t=>t.name.toLowerCase().startsWith(e))},[h,p]),M=!k&&h.startsWith("/")&&E.length>0,T=(0,s.useRef)(h);(0,s.useLayoutEffect)(()=>{T.current!==h&&(queueMicrotask(()=>y(0)),k&&queueMicrotask(()=>N(!1)),T.current=h)},[h,k]),(0,s.useLayoutEffect)(()=>{if(M&&S.current){let e=S.current.children[w];e&&e.scrollIntoView({block:"nearest"})}},[w,M]);let $=(0,s.useCallback)(()=>{let r=h.trim();(r||x.length>0)&&!t&&(e(r,x.length>0?x:void 0),m(""),f([]),C.current&&(C.current.style.height="auto"))},[h,x,t,e]),R=(0,s.useCallback)(e=>{m(e.name+" "),C.current?.focus()},[]),P=(0,s.useCallback)(e=>{if(!e.nativeEvent.isComposing){if(M&&E.length>0){if("ArrowDown"===e.key){e.preventDefault(),y(e=>(e+1)%E.length);return}if("ArrowUp"===e.key){e.preventDefault(),y(e=>(e-1+E.length)%E.length);return}if("Enter"===e.key){e.preventDefault(),R(E[w]);return}if("Escape"===e.key){e.preventDefault(),N(!0);return}if("Tab"===e.key){e.preventDefault(),R(E[w]);return}}"Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),$())}},[M,E,w,R,$]),I=(0,s.useCallback)(e=>{let t=e.clipboardData?.items;if(!t)return;let r=["image/png","image/jpeg","image/webp","image/gif"];for(let n of Array.from(t)){let t=r.find(e=>n.type===e);if(t){e.preventDefault();let r=n.getAsFile();if(!r)continue;if(r.size>5242880){alert(u("chat.imageSizeLimit",{size:(r.size/1024/1024).toFixed(2)}));continue}let s=new FileReader;s.onload=e=>{let r=e.target?.result;if(!r)return;let n=r.replace(/^data:image\/\w+;base64,/,""),s={id:`img-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,data:n,preview:r,media_type:t};f(e=>[...e,s])},s.readAsDataURL(r)}}},[u]),D=(0,s.useCallback)(e=>{f(t=>t.filter(t=>t.id!==e))},[]);return(0,n.jsxs)("div",{className:"border-t border-border bg-card relative",children:[(0,n.jsx)(nh,{images:x,onRemove:D,disabled:t}),M&&E.length>0&&(0,n.jsx)("div",{ref:S,className:"absolute bottom-full left-0 right-0 mx-4 mb-2 max-h-64 overflow-y-auto bg-card border border-border rounded-lg shadow-lg",children:E.map((e,t)=>(0,n.jsxs)("div",{onClick:()=>R(e),className:`flex items-center gap-3 px-4 py-2 cursor-pointer ${t===w?"bg-brand/10":"hover:bg-accent"}`,children:[(0,n.jsx)("span",{className:"font-mono text-sm font-medium text-foreground",children:e.name}),(0,n.jsx)("span",{className:"flex-1 text-sm text-muted-foreground truncate",children:e.description}),(0,n.jsx)("span",{className:`text-xs px-1.5 py-0.5 rounded ${(e=>{switch(e){case"builtin":return"bg-brand/15 text-brand dark:bg-brand/25 dark:text-teal-11";case"global":return"bg-green-9/15 text-green-11 dark:bg-green-9/25 dark:text-green-11";case"project":return"bg-amber-9/15 text-amber-11 dark:bg-amber-9/25 dark:text-amber-11"}})(e.source)}`,children:(e=>{switch(e){case"builtin":return u("common.builtin");case"global":return u("common.global");case"project":return u("common.project")}})(e.source)})]},e.name))}),(0,n.jsxs)("div",{className:"flex gap-2 items-end p-4",children:[(0,n.jsx)("button",{onClick:async()=>{try{(await fetch("/api/git/stage",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:r,files:["."]})})).ok?((0,g.oR)(u("toast.stagedAllFiles"),"success"),window.dispatchEvent(new CustomEvent("git-status-changed"))):(0,g.oR)(u("toast.stageFailed"),"error")}catch(e){console.error("Error staging files:",e),(0,g.oR)(u("toast.stageFailed"),"error")}},className:"p-2 text-green-11 hover:text-green-10 hover:bg-green-9/10 active:bg-green-9/20 active:scale-95 rounded-lg transition-all",title:u("chat.stageAll"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})}),l&&(0,n.jsx)("button",{onClick:l,className:"p-2 text-brand hover:text-teal-10 hover:bg-brand/10 active:bg-brand/20 active:scale-95 rounded-lg transition-all",title:u("chat.viewGitChanges"),children:(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"6",cy:"6",r:"2",strokeWidth:2}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"2",strokeWidth:2}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"2",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 8v10M18 8v4c0 2-2 4-6 4"})]})}),a&&(0,n.jsx)("button",{onClick:a,className:"p-2 text-amber-11 hover:text-amber-10 hover:bg-amber-9/10 active:bg-amber-9/20 active:scale-95 rounded-lg transition-all",title:u("chat.viewAllComments"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})})}),i&&(0,n.jsx)("button",{onClick:i,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent active:bg-muted active:scale-95 rounded-lg transition-all",title:u("chat.userMessages"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16M4 18h16"})})}),c&&(0,n.jsx)("button",{onClick:c,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent active:bg-muted active:scale-95 rounded-lg transition-all",title:u("chat.projectNotes"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}),d&&(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("button",{onClick:()=>j(!v),className:`p-2 rounded-lg transition-all ${v?"text-brand bg-brand/10":"text-muted-foreground hover:text-foreground hover:bg-accent active:bg-muted active:scale-95"}`,title:u("chat.scheduledTasks"),children:(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6v6l4 2"})]})}),v&&(0,n.jsx)(nm.E,{onClose:()=>j(!1),onCreate:d})]}),(0,n.jsx)("textarea",{ref:C,value:h,onChange:e=>m(e.target.value),onKeyDown:P,onPaste:I,placeholder:t?u("chat.placeholderDisabled"):u("chat.placeholder"),rows:1,className:"flex-1 resize-none px-4 py-2 border border-border rounded-lg focus:outline-none focus:ring-2 focus:ring-ring bg-card text-foreground placeholder-slate-9"})]})]})});var nf=r(97440),np=r(31914);function ng(e){if(0===e.length)return"";let t=[c.A.t("comments.codeRef"),""],r=e.filter(e=>e.filePath===x),n=e.filter(e=>e.filePath!==x);for(let e of(n.length>0&&n.forEach((e,r)=>{t.push(`[${r+1}] ${e.filePath}:${e.startLine}-${e.endLine}`),t.push("```"),t.push(e.codeContent),t.push("```"),e.content&&t.push(c.A.t("comments.note",{content:e.content})),t.push("")}),r)){let r=e.codeContent.split("\n").map(e=>`> ${e}`).join("\n");t.push(r),e.content&&t.push(e.content),t.push("")}return t.join("\n").trim()}function nb({isOpen:e,onClose:t,cwd:r,onNavigateToComment:l}){let{t:a}=(0,o.Bd)(),[i,c]=(0,s.useState)([]),[d,f]=(0,s.useState)(!1),[p,b]=(0,s.useState)(null),[v,j]=(0,s.useState)(!1),w=(0,s.useCallback)(async()=>{if(r){f(!0);try{let e=await fetch(`/api/comments?cwd=${encodeURIComponent(r)}&all=true`);if(e.ok){let t=await e.json();c(t.comments||[])}}catch(e){console.error("Failed to load comments:",e)}finally{f(!1)}}},[r]);(0,s.useEffect)(()=>{e&&w()},[e,w]);let y=async e=>{try{(await fetch(`/api/comments?cwd=${encodeURIComponent(r)}&id=${encodeURIComponent(e)}`,{method:"DELETE"})).ok&&(c(t=>t.filter(t=>t.id!==e)),u())}catch(e){console.error("Failed to delete comment:",e)}},k=async e=>{b(e.id);try{let t="";if(e.selectedText)t=e.selectedText;else{let n=await fetch(`/api/files/read?cwd=${encodeURIComponent(r)}&path=${encodeURIComponent(e.filePath)}`);if(!n.ok)throw Error("Failed to read file");t=((await n.json()).content||"").split("\n").slice(e.startLine-1,e.endLine).join("\n")}let n={filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,content:e.content,codeContent:t},s=ng([n]);await navigator.clipboard.writeText(s),(0,g.oR)(a("toast.copiedComment"))}catch(e){console.error("Failed to copy comment:",e)}finally{b(null)}},N=async()=>{if(0!==i.length){j(!0);try{let e=await h(r),t=ng(e);await navigator.clipboard.writeText(t),(0,g.oR)(a("toast.copiedAllComments"))}catch(e){console.error("Failed to copy all comments:",e)}finally{j(!1)}}},C=i.reduce((e,t)=>(e[t.filePath]||(e[t.filePath]=[]),e[t.filePath].push(t),e),{});if(!e)return null;let S=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:t,children:(0,n.jsxs)("div",{className:"w-full max-w-2xl max-h-[80vh] bg-card border border-border rounded-lg shadow-xl flex flex-col overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border bg-secondary",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h2",{className:"text-lg font-semibold text-foreground",children:a("comments.allComments")}),i.length>0&&(0,n.jsx)("button",{onClick:N,disabled:v,className:"p-1 rounded hover:bg-accent text-muted-foreground disabled:opacity-50",title:a("comments.copyAllComments"),children:v?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 rounded hover:bg-accent text-muted-foreground",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:d?(0,n.jsx)("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:a("common.loading")}):0===i.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[(0,n.jsx)("svg",{className:"w-12 h-12 mb-3 opacity-50",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})}),(0,n.jsx)("span",{children:a("comments.noComments")})]}):(0,n.jsx)("div",{className:"space-y-4",children:Object.entries(C).map(([e,t])=>(0,n.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden",children:[(0,n.jsxs)("div",{className:"px-3 py-2 bg-secondary border-b border-border",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-foreground font-mono",children:e===x?a("comments.aiReply"):e}),(0,n.jsxs)("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",a("comments.nComments",{count:t.length}),")"]})]}),(0,n.jsx)("div",{className:"divide-y divide-border",children:t.map(e=>{var t;return(0,n.jsx)("div",{className:"px-3 py-2 hover:bg-accent/50 cursor-pointer group",onClick:()=>l?.(e),children:(0,n.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[e.startLine>0||e.endLine>0?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{className:"text-xs text-brand font-mono",children:[a("common.line")," ",e.startLine===e.endLine?e.startLine:`${e.startLine}-${e.endLine}`]}),(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:["(",a("comments.linesCount",{count:e.endLine-e.startLine+1}),")"]})]}):e.selectedText?(0,n.jsxs)("span",{className:"text-xs text-muted-foreground italic truncate max-w-[200px]",children:["“",e.selectedText.slice(0,50),e.selectedText.length>50?"...":"","”"]}):null,(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:(t=e.updatedAt||e.createdAt)?new Date(t).toLocaleString("zh-CN",{month:"numeric",day:"numeric",hour:"2-digit",minute:"2-digit"}):""})]}),(0,n.jsx)("p",{className:"text-sm text-foreground line-clamp-2",children:e.content||(0,n.jsx)("span",{className:"text-muted-foreground italic",children:a("comments.noContent")})})]}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),k(e)},disabled:p===e.id,className:"p-1 rounded opacity-0 group-hover:opacity-100 hover:bg-accent text-muted-foreground transition-opacity disabled:opacity-50",title:a("common.copy"),children:p===e.id?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),y(e.id)},className:"p-1 rounded opacity-0 group-hover:opacity-100 hover:bg-accent text-muted-foreground hover:text-red-9 transition-opacity",title:a("common.delete"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]})},e.id)})})]},e))})}),(0,n.jsxs)("div",{className:"px-4 py-3 border-t border-border bg-secondary flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground",children:a("comments.totalComments",{count:i.length})}),(0,n.jsx)("button",{onClick:async()=>{0===i.length||await m(r)&&c([])},disabled:0===i.length,className:"px-3 py-1.5 text-sm bg-red-9 text-white rounded hover:bg-red-10 disabled:opacity-50 disabled:cursor-not-allowed",children:a("comments.clearAll")})]})]})});return(0,n.jsx)(rK.Z,{children:S})}function nv({isOpen:e,onClose:t,messages:r,onSelectMessage:l}){let{t:a}=(0,o.Bd)();if((0,s.useEffect)(()=>{if(!e)return;let r=e=>{"Escape"===e.key&&t()};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[e,t]),!e)return null;let i=r.filter(e=>"user"===e.role),c=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:t,children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-lg max-h-[70vh] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border shrink-0",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground",children:a("userMessages.title")}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:0===i.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:a("userMessages.noMessages")}):(0,n.jsx)("div",{className:"divide-y divide-border",children:i.map((e,r)=>{let s,o,a,i=(s=e.id.match(/^user-(\d+)/))?parseInt(s[1],10):null,c=i?(o=new Date(i),a=new Date,o.toDateString()===a.toDateString()?o.toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"}):o.toLocaleDateString("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})):"";return(0,n.jsx)("button",{onClick:()=>{l(e.id),t()},className:"w-full px-4 py-3 text-left hover:bg-accent transition-colors",children:(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsxs)("span",{className:"text-xs text-muted-foreground font-mono w-6 shrink-0 pt-0.5",children:[r+1,"."]}),(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)("p",{className:"text-sm text-foreground break-words",children:function(e,t=50){let r=e.replace(/\s+/g," ").trim();return r.length<=t?r:r.slice(0,t)+"..."}(e.content)})}),c&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground shrink-0 pt-0.5",children:c})]})},e.id)})})})]})});return(0,n.jsx)(rK.Z,{children:c})}function nj({cwd:e,sessionId:t,onOpenProjectSessions:r,onOpenSessionBrowser:l,onOpenSettings:a}){let{t:i}=(0,o.Bd)(),[c,d]=(0,s.useState)(!1);return(0,n.jsx)("div",{className:"border-b border-border px-4 py-3 bg-card",children:(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("img",{src:"/icons/icon-72x72.png",alt:"Cockpit",className:"w-6 h-6"}),(0,n.jsxs)("div",{className:"flex items-baseline gap-2",children:[(0,n.jsx)("h1",{className:"text-lg font-semibold text-foreground",children:"Cockpit"}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:"One seat. One AI. Everything under control."})]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[e&&(0,n.jsx)("span",{className:"text-sm text-foreground max-w-md truncate cursor-help",title:`CWD: ${e}`,children:e}),!e&&t&&(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:["Session: ",t.slice(0,8),"..."]}),e&&(0,n.jsx)("button",{onClick:r,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:i("sessions.projectSessions"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),(0,n.jsx)("button",{onClick:l,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:i("sessions.browseAllSessions"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}),t&&(0,n.jsx)("button",{onClick:()=>{let e=`claude -r ${t}`;navigator.clipboard.writeText(e).then(()=>{d(!0),setTimeout(()=>d(!1),2e3)})},className:`p-2 rounded-lg transition-colors ${c?"text-green-500 bg-green-500/10":"text-muted-foreground hover:text-foreground hover:bg-accent"}`,title:c?i("chat.copiedCommandTooltip"):i("chat.copyCommandTooltip",{sessionId:t}),children:c?(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}):(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3m2 4H10m0 0l3-3m-3 3l3 3"})})}),(0,n.jsx)("button",{onClick:a,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:i("settings.title"),children:(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]})})]})]})})}function nw({tokenUsage:e}){let{t}=(0,o.Bd)();return(0,n.jsx)("div",{className:"px-4 py-1.5 border-t border-border bg-secondary",children:(0,n.jsxs)("div",{className:"flex items-center justify-end gap-4 text-xs text-muted-foreground",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})}),(0,n.jsxs)("span",{children:[t("chat.context"),": ",(0,n.jsx)("strong",{className:"text-foreground",children:(e.inputTokens+e.cacheReadInputTokens+e.cacheCreationInputTokens).toLocaleString()})]})]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z"})}),(0,n.jsxs)("span",{children:[t("chat.output"),": ",(0,n.jsx)("strong",{className:"text-foreground",children:e.outputTokens.toLocaleString()})]})]}),(e.cacheReadInputTokens>0||e.cacheCreationInputTokens>0)&&(0,n.jsxs)("span",{className:"flex items-center gap-1 text-brand",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 7v10c0 2.21 3.582 4 8 4s8-1.79 8-4V7M4 7c0 2.21 3.582 4 8 4s8-1.79 8-4M4 7c0-2.21 3.582-4 8-4s8 1.79 8 4"})}),(0,n.jsxs)("span",{children:["Cache: ",(e.cacheReadInputTokens/(e.inputTokens+e.cacheReadInputTokens+e.cacheCreationInputTokens)*100).toFixed(0),"%"]})]}),e.totalCostUsd>0&&(0,n.jsxs)("span",{className:"flex items-center gap-1 text-green-11",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,n.jsxs)("span",{children:["$",e.totalCostUsd.toFixed(4)]})]})]})})}function ny({tabId:e,initialCwd:t,initialSessionId:r,hideHeader:a,hideSidebar:i,isActive:d=!0,onLoadingChange:u,onSessionIdChange:h,onTitleChange:m,onShowGitStatus:x,onOpenNote:f,onCreateScheduledTask:p,onOpenSession:g,onContentSearch:b}){let{t:v}=(0,o.Bd)(),j=C(),[w,y]=(0,s.useState)([]),[k,N]=(0,s.useState)(null),[S,L]=(0,s.useState)(!1),[E,M]=(0,s.useState)(!1),[T,$]=(0,s.useState)(!1),[R,P]=(0,s.useState)(!1),[I,D]=(0,s.useState)(!1),[B,F]=(0,s.useState)(!1),[O,A]=(0,s.useState)(null),W=(0,s.useRef)(null),z=(0,s.useRef)(null),H=(0,s.useCallback)(async e=>{if(t)try{let r=await fetch("/api/session-by-path",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,sessionId:e})});if(r.ok){let e=await r.json();e.title&&m?.(e.title)}}catch(e){console.error("Failed to fetch session title:",e)}},[t,m]),{isLoading:_,tokenUsage:U,handleSend:q,handleStop:V}=function(e,t,{sessionId:r,cwd:n,onSessionId:o,onFetchTitle:l}){let[a,i]=(0,s.useState)(!1),[d,u]=(0,s.useState)(null),h=(0,s.useRef)(null),m=(0,s.useRef)(r);m.current=r;let x=(0,s.useRef)(null),f=(0,s.useRef)(null),p=(0,s.useCallback)(()=>{let e=x.current;if(e&&e.text){let{messageId:r,text:n}=e;t(e=>e.map(e=>e.id===r?{...e,content:(e.content||"")+n}:e)),x.current={messageId:r,text:""}}f.current=null},[t]),g=(0,s.useCallback)(()=>{h.current&&(h.current.abort(),h.current=null)},[]),b=(0,s.useCallback)((e,r)=>{let s=e.type;if("system"===s&&"init"===e.subtype){let t=e.session_id;o(t),m.current=t;return}if("stream_event"===s){let t=e.event;if(t?.type==="content_block_delta"&&t.delta?.type==="text_delta"){let e=t.delta.text||"";x.current&&x.current.messageId===r?x.current.text+=e:x.current={messageId:r,text:e},f.current||(f.current=setTimeout(p,50))}return}if("assistant"===s){let n=e.message;if(n?.content){for(let e of n.content)if("name"in e&&e.name){let n={id:e.id||`tool-${Date.now()}`,name:e.name,input:e.input||{},isLoading:!0};t(e=>e.map(e=>e.id!==r||e.toolCalls?.some(e=>e.id===n.id)?e:{...e,toolCalls:[...e.toolCalls||[],n]}))}}}if("user"===s){let n=e.message;if(n?.content){for(let e of n.content)if("tool_use_id"in e&&e.tool_use_id){let n=e.tool_use_id,s="string"==typeof e.content?e.content:JSON.stringify(e.content);t(e=>e.map(e=>e.id===r?{...e,toolCalls:e.toolCalls?.map(e=>e.id===n?{...e,result:s,isLoading:!1}:e)}:e))}}}if("result"===s){f.current&&(clearTimeout(f.current),f.current=null),p();let s=m.current;s&&n&&t(e=>(2===e.length&&l(s),e));let o=e.usage,a=e.total_cost_usd;o&&u({inputTokens:o.input_tokens||0,outputTokens:o.output_tokens||0,cacheCreationInputTokens:o.cache_creation_input_tokens||0,cacheReadInputTokens:o.cache_read_input_tokens||0,totalCostUsd:a||0}),t(e=>e.map(e=>e.id===r?{...e,isStreaming:!1,toolCalls:e.toolCalls?.map(e=>({...e,isLoading:!1}))}:e))}},[t,p,o,l,n]);return{isLoading:a,tokenUsage:d,handleSend:(0,s.useCallback)(async(e,r)=>{let s=r?.map(e=>({type:"base64",media_type:e.media_type,data:e.data})),o={id:`user-${Date.now()}`,role:"user",content:e,images:s};t(e=>[...e,o]),i(!0);let l=`assistant-${Date.now()}`,a={id:l,role:"assistant",content:"",toolCalls:[],isStreaming:!0};t(e=>[...e,a]),h.current=new AbortController;try{let t=await fetch("/api/chat",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:e,sessionId:m.current,images:s,cwd:n}),signal:h.current.signal});if(!t.ok)throw Error(c.A.t("chat.requestFailed"));let r=t.body?.getReader();if(!r)throw Error(c.A.t("chat.cannotReadStream"));let o=new TextDecoder,a="";for(;;){let{done:e,value:t}=await r.read();if(e)break;let n=(a+=o.decode(t,{stream:!0})).split("\n");for(let e of(a=n.pop()||"",n))if(e.startsWith("data: ")){let t=e.slice(6);if("[DONE]"===t)continue;try{let e=JSON.parse(t);b(e,l)}catch{}}}}catch(e){e instanceof Error&&"AbortError"===e.name||(console.error("Chat error:",e),t(e=>e.map(e=>e.id===l?{...e,content:c.A.t("chat.errorRetry"),isStreaming:!1}:e)))}finally{h.current=null,i(!1),t(e=>e.map(e=>e.id===l?{...e,isStreaming:!1}:e))}},[n,t,b]),handleStop:g,abortControllerRef:h}}(0,y,{sessionId:k,cwd:t,onSessionId:N,onFetchTitle:H}),K=(0,s.useCallback)(async(e,r)=>{let n=e.split("\n")[0];if(n.startsWith("!")&&n.length>1){let s=n.slice(1).trim();if(!s)return void q(e,r);let o=e.split("\n").slice(1).join("\n").trim();try{let e=await fetch("/api/bash",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({command:s,cwd:t})}),n=await e.json(),l=[n.stdout,n.stderr].filter(Boolean).join("\n")||"(no output)",a=n.exitCode?` (exit code: ${n.exitCode})`:"",i=v("chat.executedCommand",{command:s,exitInfo:a,output:l});o&&(i+=`
24
24
 
25
25
  ${o}`),q(i,r)}catch(e){q(v("chat.executedCommandFailed",{command:s,error:e}),r)}return}q(e,r)},[q,t,v]),{isLoadingHistory:J,isLoadingMore:X,hasMoreHistory:Y,loadMoreHistory:Q,loadHistoryByCwdAndSessionId:G}=function(e,t,r,{cwd:n,initialSessionId:o,onSessionId:l,onTitleChange:a,onTokenUsage:i}){let[c,d]=(0,s.useState)(!1),[u,h]=(0,s.useState)(!1),[m,x]=(0,s.useState)(!1),[f,p]=(0,s.useState)(void 0),[g,b]=(0,s.useState)(0),v=(0,s.useRef)(a);v.current=a;let j=(0,s.useRef)(i);j.current=i;let w=(0,s.useRef)(void 0),y=(0,s.useRef)(0),k=(0,s.useCallback)(async(e,r,n=!1,s,o)=>{if(n){let e=Date.now();if(e-y.current<5e3)return;y.current=e}n||d(!0);try{let a={cwd:e,sessionId:r,limit:s,beforeTurnIndex:o};n&&w.current&&(a.ifFingerprint=w.current);let i=await fetch("/api/session-by-path",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(i.ok){let e=await i.json();if(e.notModified)return;e.fingerprint&&(w.current=e.fingerprint),void 0!==e.totalTurns&&b(e.totalTurns),void 0!==e.hasMore&&x(e.hasMore),e.messages&&e.messages.length>0&&(n?t(t=>{let r=e.messages;if(t.length===r.length&&t.length>0&&t[t.length-1].content===r[r.length-1].content)return t;let n=0;for(let e=0;e<Math.min(t.length,r.length)&&t[e].id===r[e].id&&t[e].content===r[e].content;e++)n=e+1;return n===t.length&&n<r.length?[...t,...r.slice(n)]:r}):t(e.messages)),e.sessionId&&l(e.sessionId),e.title&&v.current?.(e.title),e.usage&&j.current?.({inputTokens:e.usage.input_tokens||0,outputTokens:e.usage.output_tokens||0,cacheCreationInputTokens:e.usage.cache_creation_input_tokens||0,cacheReadInputTokens:e.usage.cache_read_input_tokens||0,totalCostUsd:0})}}catch(e){console.error("Failed to load history by cwd and sessionId:",e)}finally{n||d(!1)}},[t,l]),N=(0,s.useCallback)(async()=>{if(n&&r&&!u&&m){h(!0);try{let s=void 0!==f?f:g-Math.ceil(e.filter(e=>"user"===e.role).length),o=await fetch("/api/session-by-path",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:n,sessionId:r,limit:10,beforeTurnIndex:s>0?s:void 0})});if(o.ok){let e=await o.json();if(e.messages&&e.messages.length>0){t(t=>[...e.messages,...t]);let r=e.messages.filter(e=>"user"===e.role).length;p(s-r)}void 0!==e.hasMore&&x(e.hasMore),e.fingerprint&&(w.current=e.fingerprint)}}catch(e){console.error("Failed to load more history:",e)}finally{h(!1)}}},[n,r,u,m,f,g,e,t]),C=(0,s.useCallback)(async e=>{d(!0);try{let r=await fetch(`/api/session/${e}/history`);if(r.ok){let e=await r.json();e.messages&&e.messages.length>0&&t(e.messages)}}catch(e){console.error("Failed to load history:",e)}finally{d(!1)}},[t]);return(0,s.useEffect)(()=>{n&&o&&k(n,o,!1,10)},[]),{isLoadingHistory:c,isLoadingMore:u,hasMoreHistory:m,loadMoreHistory:N,loadHistory:C,loadHistoryByCwdAndSessionId:k}}(w,y,k,{cwd:t,initialSessionId:r,onSessionId:N,onTitleChange:m,onTokenUsage:A}),Z=(0,s.useRef)(d);(0,s.useEffect)(()=>{d&&!Z.current&&k&&t&&!_&&G(t,k,!0,10),Z.current=d},[d,k,t,_,G]);let ee=U||O;(0,s.useEffect)(()=>{k&&h?.(k)},[k,h]);let et=(0,s.useRef)(!1);(0,s.useEffect)(()=>{if(u?.(_),et.current&&!_&&t&&k){let e;for(let t=w.length-1;t>=0;t--)if("user"===w[t].role&&w[t].content){e=w[t].content.slice(0,100);break}window.parent.postMessage({type:"SESSION_COMPLETE",cwd:t,sessionId:k,lastUserMessage:e},"*")}et.current=_},[_,u,t]),(0,s.useEffect)(()=>{d&&j?.setIsLoading(_)},[_,d,j]),(0,s.useEffect)(()=>{if(e&&j)return j.registerChat(e=>{z.current?.(e)},e),()=>{j.unregisterChat(e)}},[e,j]),(0,s.useEffect)(()=>{e&&d&&j&&j.setActiveTab(e)},[e,d,j]),(0,s.useEffect)(()=>{z.current=K},[K]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&S&&_&&V()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[S,_,V]);let er=(0,s.useCallback)(async e=>{if(t&&k)try{let r=await fetch(`/api/session/${k}/fork`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,fromMessageUuid:e})});if(r.ok){let e=await r.json();g?g(e.newSessionId,"Fork"):window.parent.postMessage({type:"OPEN_PROJECT",cwd:t,sessionId:e.newSessionId},"*")}else console.error("Fork failed:",await r.text())}catch(e){console.error("Fork error:",e)}},[t,k,g]),en=(0,s.useCallback)(()=>{D(!0)},[]),es=(0,s.useCallback)(()=>{F(!0)},[]),eo=(0,s.useMemo)(()=>{if(p&&t&&e&&k)return r=>{p({...r,cwd:t,tabId:e,sessionId:k})}},[p,t,e,k]);return(0,n.jsxs)("div",{className:`flex ${a&&i?"h-full":"h-screen"} bg-card`,children:[(0,n.jsxs)("div",{id:"chat-screen",className:"flex-1 flex flex-col min-w-0 relative",onMouseEnter:()=>L(!0),onMouseLeave:()=>L(!1),children:[!a&&(0,n.jsx)(nj,{cwd:t,sessionId:k,onOpenProjectSessions:()=>$(!0),onOpenSessionBrowser:()=>M(!0),onOpenSettings:()=>P(!0)}),J?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("span",{className:"text-muted-foreground",children:v("sessions.loadingHistory")})}):(0,n.jsx)(nd,{ref:W,messages:w,isLoading:_,cwd:t,sessionId:k,hasMoreHistory:Y,isLoadingMore:X,onLoadMore:Q,onFork:er,isActive:d,onContentSearch:b}),ee&&(0,n.jsx)(nw,{tokenUsage:ee}),(0,n.jsx)(nx,{onSend:K,disabled:_,cwd:t,onShowGitStatus:x,onShowComments:t?en:void 0,onShowUserMessages:es,onOpenNote:f,onCreateScheduledTask:eo})]}),!a&&(0,n.jsx)(nf.r,{isOpen:E,onClose:()=>M(!1)}),!a&&t&&(0,n.jsx)(l,{isOpen:T,onClose:()=>$(!1),cwd:t}),!a&&(0,n.jsx)(np.b,{isOpen:R,onClose:()=>P(!1)}),t&&(0,n.jsx)(nb,{isOpen:I,onClose:()=>D(!1),cwd:t}),(0,n.jsx)(nv,{isOpen:B,onClose:()=>F(!1),messages:w,onSelectMessage:e=>{W.current?.scrollToMessage(e)}})]})}function nk({tabId:e,cwd:t,sessionId:r,isActive:o,onStateChange:l,onShowGitStatus:a,onOpenNote:i,onCreateScheduledTask:c,onOpenSession:d,onContentSearch:u}){let h=(0,s.useCallback)(t=>{l(e,{isLoading:t})},[e,l]),m=(0,s.useCallback)(t=>{l(e,{sessionId:t})},[e,l]),x=(0,s.useCallback)(t=>{l(e,{title:t})},[e,l]);return(0,n.jsx)(ny,{tabId:e,initialCwd:t,initialSessionId:r,hideHeader:!0,hideSidebar:!0,isActive:o,onLoadingChange:h,onSessionIdChange:m,onTitleChange:x,onShowGitStatus:a,onOpenNote:i,onCreateScheduledTask:c,onOpenSession:d,onContentSearch:u})}var nN=r(36998),nC=r(18658);function nS({initialCwd:e,initialSessionId:t}){let{t:r}=(0,o.Bd)(),[a,i]=(0,s.useState)("agent"),{tabs:c,activeTabId:d,activeTab:u,unreadTabs:h,dragTabIndex:m,dragOverTabIndex:x,closeTab:f,switchTab:p,handleSelectSession:g,handleNewTab:b,handleOpenSession:v,updateTabState:j,handleTabDragStart:w,handleTabDragOver:y,handleTabDrop:k,handleTabDragEnd:C}=function({initialCwd:e,initialSessionId:t,activeView:r}){let n=(0,s.useRef)(!1),o=(0,s.useRef)(!0),l=(0,s.useRef)(r);(0,s.useEffect)(()=>{l.current=r},[r]);let a=e_(),i=(0,s.useRef)(a);(0,s.useEffect)(()=>{i.current=a},[a]);let[c,d]=(0,s.useState)(()=>[{id:`tab-${Date.now()}`,cwd:e,title:"New Chat"}]),[u,h]=(0,s.useState)(c[0].id),[m,x]=(0,s.useState)(new Set),f=(0,s.useRef)(c);(0,s.useEffect)(()=>{f.current=c},[c]);let p=(0,s.useCallback)((t,r)=>{e&&t&&fetch("/api/global-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,sessionId:t,status:r})}).catch(()=>{})},[e]),[g,b]=(0,s.useState)(null),[v,j]=(0,s.useState)(null);(0,s.useEffect)(()=>{!e||n.current||(n.current=!0,(async()=>{try{let r=await fetch(`/api/project-state?cwd=${encodeURIComponent(e)}`);if(r.ok){let n=await r.json(),s=n.sessions||[],l=n.activeSessionId,a=[...s];if(t&&!a.includes(t)&&(a=[t,...a]),a.length>0){let r=a.map((t,r)=>({id:`tab-${Date.now()}-${r}`,cwd:e,sessionId:t,title:`Session ${t.slice(0,6)}...`})),n=t||l,s=n?a.indexOf(n):-1;s<0&&(s=0);let i=r[s].id;d(r),h(i),setTimeout(()=>{o.current=!1},0)}else o.current=!1}}catch(e){console.error("Failed to load sessions:",e),o.current=!1}})())},[e,t]),(0,s.useEffect)(()=>{if(o.current||!e)return;let t=c.map(e=>e.sessionId).filter(e=>!!e),r=c.find(e=>e.id===u);fetch("/api/project-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,sessions:t,activeSessionId:r?.sessionId})}).catch(e=>{console.error("Failed to save sessions:",e)})},[c,u,e]),(0,s.useEffect)(()=>{if(o.current||!e)return;let t=c.find(e=>e.id===u);t?.sessionId&&window.parent.postMessage({type:"SESSION_CHANGE",cwd:e,sessionId:t.sessionId},"*")},[u,c,e]);let w=(0,s.useCallback)((e,t,r)=>{let n={id:`tab-${Date.now()}`,cwd:e,sessionId:t,title:r||(t?`Session ${t.slice(0,6)}...`:"New Chat")};d(e=>{let t=e.findIndex(e=>e.id===u);if(-1===t)return[...e,n];let r=[...e];return r.splice(t+1,0,n),r}),h(n.id)},[u]),y=(0,s.useCallback)(t=>{d(r=>{let n=r.filter(e=>e.id!==t);if(t===u&&n.length>0&&h(n[n.length-1].id),0===n.length){let t={id:`tab-${Date.now()}`,cwd:e,title:"New Chat"};return h(t.id),[t]}return n})},[u,e]),k=(0,s.useCallback)((t,r)=>{let n=c.find(e=>e.sessionId===t);n?h(n.id):w(e,t,r)},[c,e,w]),N=(0,s.useCallback)(()=>{w(e)},[e,w]),C=(0,s.useCallback)((t,r)=>{w(e,t,r)},[e,w]),S=(0,s.useCallback)((e,t)=>{d(r=>{let n=r.find(t=>t.id===e);if(n?.isLoading&&!1===t.isLoading){let r=!l.current||"agent"===l.current;if(e===u&&r&&i.current){let e=n.sessionId||t.sessionId;e&&p(e,"normal")}else x(t=>new Set(t).add(e))}return r.map(r=>r.id===e?{...r,...t}:r)})},[u,p]);(0,s.useEffect)(()=>{(!r||"agent"===r)&&a&&x(e=>{if(!e.has(u))return e;let t=new Set(e);t.delete(u);let r=f.current.find(e=>e.id===u);return r?.sessionId&&p(r.sessionId,"normal"),t})},[r,u,a,p]);let L=(0,s.useCallback)(e=>{h(e),x(t=>{if(!t.has(e))return t;let r=new Set(t);r.delete(e);let n=f.current.find(t=>t.id===e);return n?.sessionId&&p(n.sessionId,"normal"),r})},[p]),E=(0,s.useCallback)(e=>{b(e)},[]),M=(0,s.useCallback)((e,t)=>{e.preventDefault(),null!==g&&g!==t&&j(t)},[g]),T=(0,s.useCallback)(e=>{null!==g&&g!==e&&d(t=>{let r=[...t],[n]=r.splice(g,1);return r.splice(e,0,n),r}),b(null),j(null)},[g]),$=(0,s.useCallback)(()=>{b(null),j(null)},[]),R=c.find(e=>e.id===u);return{tabs:c,activeTabId:u,activeTab:R,unreadTabs:m,dragTabIndex:g,dragOverTabIndex:v,addTab:w,closeTab:y,switchTab:L,handleSelectSession:k,handleNewTab:N,handleOpenSession:C,updateTabState:S,handleTabDragStart:E,handleTabDragOver:M,handleTabDrop:T,handleTabDragEnd:$}}({initialCwd:e,initialSessionId:t,activeView:a}),{isPinned:S,pinSession:L,unpinSession:E}=(0,nN.P)(),{createTask:M}=(0,nC.n)(),T=(0,s.useCallback)(e=>{let t=c.find(t=>t.id===e);return!!t?.sessionId&&S(t.sessionId)},[c,S]),$=(0,s.useCallback)(t=>{let r=c.find(e=>e.id===t);r?.sessionId&&(S(r.sessionId)?E(r.sessionId):L(r.sessionId,r.cwd||e||"",r.title))},[c,S,L,E,e]),[R,P]=(0,s.useState)(!1),[I,D]=(0,s.useState)(!1),[B,F]=(0,s.useState)(!1),[O,A]=(0,s.useState)(null),[W,z]=(0,s.useState)(!1),[H,_]=(0,s.useState)("tree"),[U,q]=(0,s.useState)(0),[V,K]=(0,s.useState)(null),[J,X]=(0,s.useState)(0);(0,s.useEffect)(()=>{e&&fetch(`/api/project-settings?cwd=${encodeURIComponent(e)}`).then(e=>e.ok?e.json():null).then(e=>{e?.settings?.activeView&&i(e.settings.activeView)}).catch(()=>{})},[e]);let[Y,Q]=(0,s.useState)(!1),G=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=e=>{let{active:t}=e.detail;t?(G.current=a,i("console"),Q(!0)):(Q(!1),G.current&&"console"!==G.current&&i(G.current),G.current=null)};return window.addEventListener("cockpit-screenshot-state",e),()=>window.removeEventListener("cockpit-screenshot-state",e)},[a]);let Z=(0,s.useCallback)(t=>{i(t),e&&(fetch("/api/project-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,settings:{activeView:t}})}).catch(()=>{}),window.parent.postMessage({type:"VIEW_CHANGE",cwd:e,view:t},"*"))},[e]),ee=(0,s.useCallback)(async()=>{if(e)try{let t=await fetch(`/api/git/worktree?cwd=${encodeURIComponent(e)}`);if(t.ok){let r=await t.json();if(z(r.isGitRepo),r.isGitRepo&&r.worktrees.length>0){let t=r.worktrees.find(t=>t.path===e);t&&A(t.branch)}}}catch(e){console.error("Failed to load git info:",e)}},[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>ee())},[ee]);let et=(0,s.useCallback)(e=>{let{data:t}=e;t?.some(e=>"git"===e.type)&&ee()},[ee]);(0,eH.h)({url:`/ws/watch?cwd=${encodeURIComponent(e||"")}`,onMessage:et,enabled:!!e}),(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&("1"===e.key?(e.preventDefault(),Z("agent")):"2"===e.key?(e.preventDefault(),Z("explorer")):"3"===e.key&&(e.preventDefault(),Z("console")))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]),(0,s.useEffect)(()=>{let t=t=>{if(t.data?.type==="SWITCH_SESSION"){let{sessionId:r,switchToAgent:n}=t.data;if(r){g(r),n&&Z("agent");let t=c.find(e=>e.sessionId===r);e&&!t?.isLoading&&fetch("/api/global-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,sessionId:r,status:"normal"})}).catch(()=>{})}}};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[g,Z,e,c]);let er=(0,s.useCallback)(()=>{_("status"),q(e=>e+1),Z("explorer")},[Z]),en=(0,s.useCallback)(e=>{K(e),X(e=>e+1),Z("explorer")},[Z]),es=(0,s.useCallback)(()=>{e&&window.parent.postMessage({type:"OPEN_NOTE",cwd:e},"*")},[e]);return(0,n.jsx)(N,{children:(0,n.jsx)(e1,{activeView:a,onViewChange:Z,children:(0,n.jsxs)("div",{className:"flex h-screen bg-card",children:[(0,n.jsxs)("div",{className:"flex-1 flex flex-col min-w-0",children:[(0,n.jsx)(rU,{initialCwd:e,activeTab:u,isGitRepo:W,currentBranch:O,onOpenWorktree:()=>D(!0),onOpenProjectSessions:()=>P(!0),onOpenAliasManager:()=>F(!0),onBranchSwitched:ee}),Y&&(0,n.jsxs)("div",{className:"flex items-center justify-center gap-2 py-1 bg-brand/15 text-brand text-xs font-medium border-b border-brand/20",children:[(0,n.jsx)("span",{className:"animate-pulse",children:"●"}),r("console.screenshotting")]}),e?(0,n.jsxs)(e2,{children:[(0,n.jsxs)("div",{className:"w-1/3 h-full flex flex-col overflow-hidden",children:[(0,n.jsx)(rV,{tabs:c,activeTabId:d,unreadTabs:h,dragTabIndex:m,dragOverTabIndex:x,isPinned:T,onTogglePin:$,onSwitchTab:p,onCloseTab:f,onNewTab:b,onDragStart:w,onDragOver:y,onDrop:k,onDragEnd:C}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden relative",children:c.map(e=>(0,n.jsx)("div",{className:`h-full ${e.id===d?"block":"hidden"}`,children:(0,n.jsx)(nk,{tabId:e.id,cwd:e.cwd,sessionId:e.sessionId,isActive:e.id===d&&"agent"===a,onStateChange:j,onShowGitStatus:er,onContentSearch:en,onOpenNote:es,onCreateScheduledTask:M,onOpenSession:v})},e.id))})]}),(0,n.jsx)("div",{className:"w-1/3 h-full overflow-hidden",children:(0,n.jsx)(e4,{onClose:()=>Z("agent"),cwd:e,initialTab:H,tabSwitchTrigger:U,initialSearchQuery:V,searchQueryTrigger:J})}),(0,n.jsx)("div",{className:"w-1/3 h-full overflow-hidden",children:(0,n.jsx)(rF,{cwd:e,tabId:"default",onOpenNote:es})})]}):(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,n.jsx)(rV,{tabs:c,activeTabId:d,unreadTabs:h,dragTabIndex:m,dragOverTabIndex:x,isPinned:T,onTogglePin:$,onSwitchTab:p,onCloseTab:f,onNewTab:b,onDragStart:w,onDragOver:y,onDrop:k,onDragEnd:C}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden relative",children:c.map(e=>(0,n.jsx)("div",{className:`h-full ${e.id===d?"block":"hidden"}`,children:(0,n.jsx)(nk,{tabId:e.id,cwd:e.cwd,sessionId:e.sessionId,isActive:e.id===d,onStateChange:j,onCreateScheduledTask:M,onOpenSession:v})},e.id))})]})]}),e&&(0,n.jsx)(l,{isOpen:R,onClose:()=>P(!1),cwd:e,onSelectSession:g}),e&&W&&(0,n.jsx)(e3,{isOpen:I,onClose:()=>D(!1),cwd:e}),B&&(0,n.jsx)(tf,{onClose:()=>F(!1),onSave:()=>F(!1)})]})})})}}},e=>{e.O(0,[8653,7330,9114,305,2072,3530,5493,1593,8441,3794,7358],()=>e(e.s=60499)),_N_E=e.O()}]);