@surething/cockpit 1.0.239 → 1.0.240
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.next-prod/BUILD_ID +1 -1
- package/.next-prod/app-path-routes-manifest.json +4 -4
- package/.next-prod/build-manifest.json +2 -2
- package/.next-prod/prerender-manifest.json +3 -3
- package/.next-prod/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/_global-error.html +1 -1
- package/.next-prod/server/app/_global-error.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next-prod/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/_not-found.html +2 -2
- package/.next-prod/server/app/_not-found.rsc +2 -2
- package/.next-prod/server/app/_not-found.segments/_full.segment.rsc +2 -2
- package/.next-prod/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/.next-prod/server/app/_not-found.segments/_index.segment.rsc +2 -2
- package/.next-prod/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/.next-prod/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/.next-prod/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/.next-prod/server/app/api/session-by-path/route.js +1 -1
- package/.next-prod/server/app/api/sessions/projects/[encodedPath]/route.js +1 -1
- package/.next-prod/server/app/api/sessions/route.js +1 -1
- package/.next-prod/server/app/m/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/project/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/review/[id]/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app-paths-manifest.json +4 -4
- package/.next-prod/server/chunks/9658.js +5 -5
- package/.next-prod/server/chunks/9830.js +1 -1
- package/.next-prod/server/middleware-build-manifest.js +1 -1
- package/.next-prod/server/pages/404.html +2 -2
- package/.next-prod/server/pages/500.html +1 -1
- package/.next-prod/server/server-reference-manifest.json +1 -1
- package/.next-prod/static/chunks/{5408-f7b9470b57c6690e.js → 5408-b31a0bb83ee220ad.js} +3 -3
- package/.next-prod/static/chunks/9530-aac4bba2518aa113.js +15 -0
- package/.next-prod/static/chunks/app/{layout-b8d5256d3bf96b1e.js → layout-95cb81ab4128b70e.js} +1 -1
- package/.next-prod/static/chunks/app/m/{page-149145e4714873de.js → page-54053828af79704f.js} +1 -1
- package/.next-prod/static/chunks/app/{page-497c9c5c75bf40f2.js → page-5969e7f2f5788be2.js} +1 -1
- package/.next-prod/static/chunks/app/project/{page-497c9c5c75bf40f2.js → page-5969e7f2f5788be2.js} +1 -1
- package/.next-prod/trace +13 -13
- package/.next-prod/trace-build +1 -1
- package/dist/{chunk-MNMFPTV4.mjs → chunk-JDX7Z54G.mjs} +58 -30
- package/dist/scheduledTasks.mjs +1 -1
- package/dist/wsServer.mjs +1 -1
- package/package.json +1 -1
- package/.next-prod/static/chunks/543-9c1455693df33cd1.js +0 -15
- /package/.next-prod/static/{c1JrZ4eVs2JR2ujEC_UrJ → ArsrRKOrvluh7oFS0G-Fg}/_buildManifest.js +0 -0
- /package/.next-prod/static/{c1JrZ4eVs2JR2ujEC_UrJ → ArsrRKOrvluh7oFS0G-Fg}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[9530],{1058:(e,t,n)=>{n.d(t,{_:()=>o});var r=n(12115),s=n(90717),l=n(86957),a=n(46456);function o({cwd:e,filePath:t}){let[n,i]=(0,r.useState)([]),[c,d]=(0,r.useState)(!1),[u,h]=(0,r.useState)(null),m=(0,r.useCallback)(async()=>{if(!e||!t)return;d(!0),h(null);let n=await l.t4.runPromiseExit((0,a.lb)(e,t));if("Success"===n._tag)i(n.value.comments??[]);else{let e="Fail"===n.cause._tag?n.cause.error:null,t=e?.cause;h(t instanceof Error?t.message:"Failed to load comments")}d(!1)},[e,t]);(0,r.useEffect)(()=>{m()},[m]),(0,r.useEffect)(()=>(0,s.zL)(()=>{m()}),[m]);let f=(0,r.useCallback)(async(n,r,s,o)=>{let c=await l.t4.runPromiseExit((0,a.BC)({cwd:e,filePath:t,startLine:n,endLine:r,content:s,...o?{selectedText:o}:{}}));if("Success"===c._tag&&c.value.comment){let e=c.value.comment;return i(t=>[...t,e]),e}return"Failure"===c._tag&&console.error("Failed to add comment:",c.cause),null},[e,t]),x=(0,r.useCallback)(async(t,n)=>{let r=await l.t4.runPromiseExit((0,a.vv)(e,t,n));if("Success"===r._tag&&r.value.comment){let e=r.value.comment;return i(n=>n.map(n=>n.id===t?e:n)),!0}return"Failure"===r._tag&&console.error("Failed to update comment:",r.cause),!1},[e]),p=(0,r.useCallback)(async t=>{let n=await l.t4.runPromiseExit((0,a.Tu)(e,t));return"Success"===n._tag?(i(e=>e.filter(e=>e.id!==t)),!0):(console.error("Failed to delete comment:",n.cause),!1)},[e]),g=(0,r.useCallback)(e=>n.filter(t=>e>=t.startLine&&e<=t.endLine),[n]);return{comments:n,isLoading:c,error:u,addComment:f,updateComment:x,deleteComment:p,refresh:m,getCommentsForLine:g}}},3292:(e,t,n)=>{n.d(t,{P:()=>c});var r=n(12115),s=n(95045),l=n(75346),a=n(49433),o=n(86957),i=n(82680);function c(){let[e,t]=(0,r.useState)([]),n=(0,r.useCallback)(()=>{let e=a.tryPromise({try:async()=>{let e=await fetch("/api/pinned-sessions");return await e.json()},catch:e=>new i.uV({message:"loadPinnedSessions failed",cause:e})});o.t4.runPromise(e.pipe(a.match({onSuccess:e=>t(e.sessions||[]),onFailure:()=>{}})))},[]);(0,r.useEffect)(()=>{n()},[n]),(0,r.useEffect)(()=>{let e=e=>{e.data?.type==="PINNED_SESSIONS_CHANGED"&&n()};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[n]);let c=(0,r.useCallback)(e=>{t(e);let n=a.tryPromise({try:async()=>{await fetch("/api/pinned-sessions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessions:e})})},catch:e=>new i.uV({message:"savePinnedSessions failed",cause:e})});o.t4.runFork(n.pipe(a.orElse(()=>a.void))),(0,s.F)(l.n.PinnedSessionsChanged,{})},[]),d=(0,r.useCallback)(t=>e.some(e=>e.sessionId===t),[e]),u=(0,r.useCallback)((t,n,r)=>{e.some(e=>e.sessionId===t)||c([...e,{sessionId:t,cwd:n,customTitle:r}])},[e,c]),h=(0,r.useCallback)(t=>{c(e.filter(e=>e.sessionId!==t))},[e,c]),m=(0,r.useCallback)((t,n)=>{c(e.map(e=>e.sessionId===t?{...e,customTitle:n}:e))},[e,c]);return{pinnedSessions:e,isPinned:d,pinSession:u,unpinSession:h,updateTitle:m,reorder:(0,r.useCallback)(e=>{c(e)},[c]),reload:n}}},5135:(e,t,n)=>{n.d(t,{M:()=>j});var r=n(95155),s=n(12115),l=n(79114),a=n(47650),o=n(70188),i=n(34075),c=n(89109),d=n(7320),u=n(37614),h=n(1058),m=n(48347),f=n(90717),x=n(13219),p=n(97251),g=n(11890),b=n(47215),v=n(47176),y=n(79968),w=n(27570);let k=[p.W];function j({content:e,filePath:t,cwd:n,onClose:p,sourceFile:C,embedded:N=!1,onLocalMdLink:S,scrollToAnchor:L}){let E=C||(n&&t.startsWith(n)?t.slice(n.endsWith("/")?n.length:n.length+1):t),{t:M}=(0,l.Bd)(),R=(0,o.iN)(),T=(0,m.r)(),{comments:$,addComment:I,updateComment:P,deleteComment:A,refresh:_}=(0,h._)({cwd:n,filePath:t}),[D,F]=(0,s.useState)(!1),[W,B]=(0,s.useState)(null),[V,O]=(0,s.useState)(null),[z,H]=(0,s.useState)(null),K=(0,s.useMemo)(()=>e.split("\n"),[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>F(!0))},[]);let[U,q]=(0,s.useState)(null),X=(0,s.useRef)(null);(0,s.useEffect)(()=>{X.current!==U&&q(X.current)});let Z=(0,s.useCallback)(e=>{if(!S||/^[a-z][a-z0-9+.-]*:/i.test(e))return!1;let t=e.indexOf("#"),n=t>=0?e.slice(0,t):e,r=t>=0?e.slice(t+1):null;if(!n)return!1;let s=n;try{s=decodeURIComponent(n)}catch{}return!!(0,b.e$)(s)&&(S((0,b.WU)(E,s),r),!0)},[S,E]);(0,s.useEffect)(()=>{if(!L)return;let e=setTimeout(()=>{(0,g.O)(X.current,L)},80);return()=>clearTimeout(e)},[L,e]);let{toolbarRef:G,bumpRef:J,clearToolbar:Y}=(0,w.L)({enabled:!0,container:U,resolveLineRange:e=>{let t=function(e){let t=e.nodeType===Node.TEXT_NODE?e.parentElement:e;if(!t||!("closest"in t))return null;let n=t.closest("[data-source-start]");if(!n)return null;let r=n.getAttribute("data-source-start"),s=n.getAttribute("data-source-end");return r&&s?{start:parseInt(r,10),end:parseInt(s,10)}:null}(e);return t?{start:t.start,end:t.end}:null},buildLineSnapshot:({start:e,end:t})=>{let n=Math.max(0,e-1),r=Math.min(K.length,t);return K.slice(n,r).join("\n")}}),Q=(0,s.useCallback)(()=>{let e=G.current;e&&(B({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),Y())},[Y,G]),ee=(0,s.useCallback)(()=>{let e=G.current;e&&(O({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),Y())},[Y,G]),et=(0,s.useCallback)(async e=>{W&&(await I(W.range.start,W.range.end,e,W.selectedText),B(null))},[W,I]),en=(0,s.useCallback)(async(e,r)=>{if(T)try{let s=await (0,f.$3)(n),l=[];for(let e of s)l.push({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0});l.push({filePath:t,startLine:e.range.start,endLine:e.range.end,codeContent:e.lineSnapshot});let a=(0,f.Gw)(l,r);T.sendMessage(a),await (0,f.RP)(n),_()}catch(e){console.error("Failed to send to AI:",e)}},[T,t,n,_]),er=(0,s.useCallback)(e=>{V&&en(V,e)},[V,en]),es=(0,s.useCallback)(e=>{W&&en(W,e)},[W,en]),el=(0,s.useMemo)(()=>{if(0===$.length)return[];let e=new Map;for(let t of $){let n=`${t.startLine}-${t.endLine}`;e.has(n)||e.set(n,[]),e.get(n).push(t)}return Array.from(e.entries()).map(([e,t])=>({key:e,startLine:t[0].startLine,endLine:t[0].endLine,comments:t}))},[$]),[ea,eo]=(0,s.useState)([]);return(0,s.useEffect)(()=>{if(0===el.length||!X.current)return void queueMicrotask(()=>eo([]));let e=setTimeout(()=>{let e=X.current;if(!e)return;let t=[],n=e.querySelectorAll("[data-source-start]");for(let r of el){let s=null,l=1/0;for(let e of n){let t=parseInt(e.getAttribute("data-source-start"),10),n=parseInt(e.getAttribute("data-source-end"),10);if(t<=r.startLine&&n>=r.endLine){let r=n-t;r<l&&(l=r,s=e)}}if(s){let n=e.getBoundingClientRect(),l=s.getBoundingClientRect();t.push({key:r.key,top:l.top-n.top+e.scrollTop,comments:r.comments})}}eo(t)},100);return()=>clearTimeout(e)},[el,e]),(0,s.useEffect)(()=>{let e=e=>{if("Escape"===e.key){if(V){O(null),e.stopPropagation();return}if(W){B(null),e.stopPropagation();return}if(G.current){G.current=null,J.current(),e.stopPropagation();return}if(z){H(null),e.stopPropagation();return}p?.()}};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[V,W,z,p]),(0,r.jsxs)(r.Fragment,{children:[!N&&(0,r.jsxs)("div",{className:"px-4 py-3 border-b border-border flex items-center justify-between gap-3 flex-shrink-0",children:[(0,r.jsxs)("span",{className:"text-sm font-medium text-foreground truncate min-w-0 flex-1 cursor-pointer hover:text-brand transition-colors",style:{direction:"rtl",textAlign:"left"},title:t,onClick:()=>{navigator.clipboard.writeText(t),(0,i.oR)(M("common.copiedPath"))},children:["",t]}),(0,r.jsxs)("div",{className:"flex items-center gap-3",children:[(0,r.jsx)(y.ShareReviewToggle,{content:e,sourceFile:E}),(0,r.jsx)("button",{onClick:p,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:M("common.close"),children:(0,r.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,r.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[(0,r.jsx)(v.l,{content:e,containerRef:X}),(0,r.jsxs)("div",{className:"flex-1 overflow-auto relative",ref:X,children:[(0,r.jsx)("div",{className:"p-6",children:(0,r.jsx)(x.T,{content:e,rehypePlugins:k,onLinkClick:Z})}),ea.map(({key:e,top:t,comments:n})=>(0,r.jsx)("div",{className:"absolute right-3 cursor-pointer z-10",style:{top:t},onClick:e=>{e.stopPropagation(),H({comment:n[0],x:e.clientX,y:e.clientY})},children:(0,r.jsx)("div",{className:"w-5 h-5 rounded-full bg-amber-500/80 text-white text-xs flex items-center justify-center shadow-sm hover:bg-amber-500 transition-colors",children:n.length})},e))]})]}),D&&R&&(0,a.createPortal)((0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(c.f,{floatingToolbarRef:G,bumpRef:J,container:R,onAddComment:Q,onSendToAI:ee,isChatLoading:T?.isLoading}),W&&(0,r.jsx)(d.t,{x:W.x,y:W.y,range:W.range,filePath:t,lineSnapshot:W.lineSnapshot,container:R,onSubmit:et,onSendToAI:T?es:void 0,onClose:()=>B(null),isChatLoading:T?.isLoading}),V&&(0,r.jsx)(d.G,{x:V.x,y:V.y,range:V.range,filePath:t,lineSnapshot:V.lineSnapshot,container:R,onSubmit:er,onClose:()=>O(null),isChatLoading:T?.isLoading}),z&&(0,r.jsx)(u.t,{x:z.x,y:z.y,comment:z.comment,container:R,onClose:()=>H(null),onUpdateComment:P,onDeleteComment:A})]}),R)]})}},7320:(e,t,n)=>{n.d(t,{G:()=>o,t:()=>a});var r=n(95155),s=n(12115),l=n(79114);function a({x:e,y:t,range:n,filePath:o,lineSnapshot:i,container:c,onSubmit:d,onSendToAI:u,onClose:h,isChatLoading:m}){let{t:f}=(0,l.Bd)(),[x,p]=(0,s.useState)(""),[g,b]=(0,s.useState)(!1),v=(0,s.useRef)(null),y=(0,s.useRef)(null),[w,k]=(0,s.useState)({x:0,y:0}),j=i?.split("\n").slice(0,5).join("\n"),C=!!i&&i.split("\n").length>5;(0,s.useEffect)(()=>{if(v.current&&c){let n=c.getBoundingClientRect(),r=v.current.getBoundingClientRect(),s=e-n.left,l=t-n.top;s+r.width>n.width-16&&(s=n.width-r.width-16),s<16&&(s=16),l+r.height>n.height-16&&(l=l-r.height-8),l<16&&(l=16),queueMicrotask(()=>k({x:s,y:l}))}},[e,t,c]),(0,s.useEffect)(()=>{y.current?.focus()},[]),(0,s.useEffect)(()=>{let e=e=>{g||!v.current||v.current.contains(e.target)||h()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[h,g]);let N=()=>{!g&&x.trim()&&(b(!0),d(x.trim()))};return(0,r.jsxs)("div",{ref:v,className:"absolute z-[200] w-[640px] bg-card border border-border rounded-lg shadow-lg overflow-hidden",style:{left:w.x,top:w.y},children:[(0,r.jsxs)("div",{className:"px-3 py-2 bg-amber-9/10 border-b border-border",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsx)("span",{className:"text-xs font-medium text-amber-11",children:f("comments.addComment")}),(n.start>0||n.end>0)&&(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:f("comments.lineRange",{start:n.start,end:n.end})})]}),o&&(0,r.jsx)("div",{className:"mt-1 text-xs text-muted-foreground truncate",children:o})]}),i&&(0,r.jsx)("div",{className:"px-3 py-2 bg-secondary/50 border-b border-border max-h-24 overflow-hidden",children:(0,r.jsxs)("pre",{className:"text-xs font-mono text-muted-foreground whitespace-pre-wrap break-all",children:[j,C&&(0,r.jsx)("span",{className:"text-muted-foreground/50",children:"..."})]})}),(0,r.jsxs)("div",{className:"p-2",children:[(0,r.jsx)("textarea",{ref:y,value:x,onChange:e=>p(e.target.value),placeholder:f("comments.inputPlaceholder"),className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card resize-none focus:outline-none focus:ring-1 focus:ring-ring disabled:opacity-50 disabled:cursor-not-allowed",rows:2,disabled:g,onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),N()),"Escape"!==e.key||g||h()}}),(0,r.jsxs)("div",{className:"mt-1 flex items-center justify-between gap-2",children:[(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:f(g?"comments.submitting":"comments.enterSubmit")}),(0,r.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,r.jsx)("button",{className:"px-3 py-1 text-xs font-medium border border-amber-11 text-amber-11 rounded-md hover:bg-amber-9/10 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",onClick:N,disabled:g||!x.trim(),children:f("comments.submitComment")}),u&&(0,r.jsx)("button",{className:"px-3 py-1 text-xs font-medium border border-brand text-brand rounded-md hover:bg-brand/10 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",onClick:()=>{!g&&!m&&u&&x.trim()&&(b(!0),u(x.trim()),h())},disabled:g||m||!x.trim(),title:f(m?"comments.aiResponding":"comments.sendToAI"),children:f("comments.sendToAI")})]})]})]})]})}function o({x:e,y:t,range:n,filePath:a,lineSnapshot:i,container:c,onSubmit:d,onClose:u,isChatLoading:h}){let{t:m}=(0,l.Bd)(),[f,x]=(0,s.useState)(""),p=(0,s.useRef)(null),g=(0,s.useRef)(null),[b,v]=(0,s.useState)({x:0,y:0});(0,s.useEffect)(()=>{if(p.current&&c){let n=c.getBoundingClientRect(),r=p.current.getBoundingClientRect(),s=e-n.left,l=t-n.top;s+r.width>n.width-16&&(s=n.width-r.width-16),s<16&&(s=16),l+r.height>n.height-16&&(l=l-r.height-8),l<16&&(l=16),queueMicrotask(()=>v({x:s,y:l}))}},[e,t,c]),(0,s.useEffect)(()=>{g.current?.focus()},[]),(0,s.useEffect)(()=>{let e=e=>{p.current&&!p.current.contains(e.target)&&u()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[u]);let y=i?.split("\n").slice(0,5).join("\n"),w=!!i&&i.split("\n").length>5;return(0,r.jsxs)("div",{ref:p,className:"absolute z-[200] w-[640px] bg-card border border-border rounded-lg shadow-lg overflow-hidden",style:{left:b.x,top:b.y},children:[(0,r.jsxs)("div",{className:"px-3 py-2 bg-brand/10 border-b border-border",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsx)("span",{className:"text-xs font-medium text-brand",children:m("comments.askAI")}),(n.start>0||n.end>0)&&(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:m("comments.lineRange",{start:n.start,end:n.end})})]}),a&&(0,r.jsx)("div",{className:"mt-1 text-xs text-muted-foreground truncate",children:a})]}),i&&(0,r.jsx)("div",{className:"px-3 py-2 bg-secondary/50 border-b border-border max-h-24 overflow-hidden",children:(0,r.jsxs)("pre",{className:"text-xs font-mono text-muted-foreground whitespace-pre-wrap break-all",children:[y,w&&(0,r.jsx)("span",{className:"text-muted-foreground/50",children:"..."})]})}),(0,r.jsxs)("div",{className:"p-2",children:[(0,r.jsx)("textarea",{ref:g,value:f,onChange:e=>x(e.target.value),placeholder:m("comments.inputQuestion"),className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card resize-none focus:outline-none focus:ring-1 focus:ring-ring disabled:opacity-50 disabled:cursor-not-allowed",rows:2,disabled:h,onKeyDown:e=>{"Enter"===e.key&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),!h&&f.trim()&&(d(f.trim()),u())),"Escape"===e.key&&u()}}),(0,r.jsx)("div",{className:"mt-1 text-xs text-muted-foreground",children:m(h?"comments.aiGenerating":"comments.enterSend")})]})]})}},9573:(e,t,n)=>{n.d(t,{se:()=>o,xK:()=>a});var r=n(49433),s=n(82680);let l=e=>r.tryPromise({try:async()=>{let t=await fetch(e);if(!t.ok)throw Error(`HTTP ${t.status}`);return await t.json()},catch:t=>new s.uV({message:`GET ${e} failed`,cause:t})}),a=(e,t)=>l(`/api/snapshots?cwd=${encodeURIComponent(e)}&toolIds=${encodeURIComponent(t.join(","))}`).pipe(r.map(e=>e.commits??[])),o=(e,t)=>a(e,t).pipe(r.flatMap(t=>r.all(t.map(t=>{let n;return n=t.hash,l(`/api/snapshots/diff?cwd=${encodeURIComponent(e)}&commit=${encodeURIComponent(n)}`)}),{concurrency:4})))},14575:(e,t,n)=>{n.d(t,{o:()=>a});var r=n(95155);n(12115);let s={ts:"#3178c6",tsx:"#3178c6",js:"#f1e05a",jsx:"#61dafb",mjs:"#f1e05a",cjs:"#f1e05a",html:"#e44d26",css:"#563d7c",scss:"#cd6799",sass:"#cd6799",less:"#1d365d",vue:"#41b883",svelte:"#ff3e00",json:"#cbcb41",yaml:"#cb171e",yml:"#cb171e",toml:"#9c4121",xml:"#e37933",env:"#ecd53f",md:"#519aba",mdx:"#519aba",txt:"#89898a",py:"#3572a5",go:"#00add8",rs:"#dea584",java:"#b07219",kt:"#a97bff",kts:"#a97bff",c:"#555555",h:"#555555",cpp:"#f34b7d",hpp:"#f34b7d",rb:"#701516",php:"#4f5d95",sh:"#89e051",bash:"#89e051",zsh:"#89e051",png:"#a074c4",jpg:"#a074c4",jpeg:"#a074c4",gif:"#a074c4",svg:"#ffb13b",webp:"#a074c4",ico:"#a074c4",lock:"#89898a",gitignore:"#f14e32",dockerfile:"#2496ed",sql:"#e38c00",graphql:"#e535ab",gql:"#e535ab",default:"#8a8a8a"},l={"package.json":"#cb3837","package-lock.json":"#cb3837","tsconfig.json":"#3178c6","jsconfig.json":"#f1e05a",".gitignore":"#f14e32",".eslintrc":"#4b32c3",".eslintrc.js":"#4b32c3",".eslintrc.json":"#4b32c3",".prettierrc":"#56b3b4",dockerfile:"#2496ed",".env":"#ecd53f",".env.local":"#ecd53f",".env.development":"#ecd53f",".env.production":"#ecd53f","readme.md":"#519aba",license:"#d4af37",makefile:"#6d8086","cargo.toml":"#dea584","go.mod":"#00add8","go.sum":"#00add8","requirements.txt":"#3572a5","yarn.lock":"#2c8ebb","pnpm-lock.yaml":"#f9ad00","vite.config.ts":"#646cff","vite.config.js":"#646cff","next.config.js":"#000000","next.config.mjs":"#000000","tailwind.config.js":"#38bdf8","tailwind.config.ts":"#38bdf8"};function a({name:e,className:t="",size:n=16}){let o,i=l[o=e.toLowerCase()]?l[o]:s[e.split(".").pop()?.toLowerCase()||""]||s.default,c=e.split(".").pop()?.toLowerCase()||"";return["ts","tsx"].includes(c)?(0,r.jsxs)("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,r.jsx)("rect",{x:"2",y:"2",width:"20",height:"20",rx:"2",fill:i}),(0,r.jsx)("path",{d:"M7 10h10M12 10v8",stroke:"white",strokeWidth:"2",strokeLinecap:"round"})]}):["js","jsx","mjs","cjs"].includes(c)?(0,r.jsxs)("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,r.jsx)("rect",{x:"2",y:"2",width:"20",height:"20",rx:"2",fill:i}),(0,r.jsx)("path",{d:"M10 10v6c0 1-1 2-2 2M14 10v4c0 2 4 2 4 0v-4",stroke:"#323330",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}):"jsx"===c||"tsx"===c&&e.includes("component")?(0,r.jsxs)("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,r.jsx)("ellipse",{cx:"12",cy:"12",rx:"10",ry:"4",stroke:"#61dafb",strokeWidth:"1.5",fill:"none"}),(0,r.jsx)("ellipse",{cx:"12",cy:"12",rx:"10",ry:"4",stroke:"#61dafb",strokeWidth:"1.5",fill:"none",transform:"rotate(60 12 12)"}),(0,r.jsx)("ellipse",{cx:"12",cy:"12",rx:"10",ry:"4",stroke:"#61dafb",strokeWidth:"1.5",fill:"none",transform:"rotate(120 12 12)"}),(0,r.jsx)("circle",{cx:"12",cy:"12",r:"2",fill:"#61dafb"})]}):"json"===c?(0,r.jsxs)("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,r.jsx)("path",{d:"M6 4C4 4 4 6 4 8v2c0 1-1 2-2 2 1 0 2 1 2 2v2c0 2 0 4 2 4",stroke:i,strokeWidth:"2",fill:"none",strokeLinecap:"round"}),(0,r.jsx)("path",{d:"M18 4c2 0 2 2 2 4v2c0 1 1 2 2 2-1 0-2 1-2 2v2c0 2 0 4-2 4",stroke:i,strokeWidth:"2",fill:"none",strokeLinecap:"round"}),(0,r.jsx)("circle",{cx:"12",cy:"12",r:"1.5",fill:i})]}):["md","mdx"].includes(c)?(0,r.jsxs)("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,r.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",stroke:i,strokeWidth:"1.5",fill:"none"}),(0,r.jsx)("path",{d:"M5 15V9l3 4 3-4v6M17 12l-2-3v6M17 12l2-3v6",stroke:i,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):["py","pyi","pyx"].includes(c)?(0,r.jsxs)("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,r.jsx)("path",{d:"M12 4c-4 0-4 2-4 3v2h5v1H6c-2 0-3 2-3 4s1 4 3 4h2v-2c0-2 1-3 3-3h4c1 0 2-1 2-2V7c0-2-2-3-5-3z",fill:"#3572a5"}),(0,r.jsx)("path",{d:"M12 20c4 0 4-2 4-3v-2h-5v-1h7c2 0 3-2 3-4s-1-4-3-4h-2v2c0 2-1 3-3 3h-4c-1 0-2 1-2 2v4c0 2 2 3 5 3z",fill:"#ffd43b"}),(0,r.jsx)("circle",{cx:"9",cy:"7",r:"1",fill:"white"}),(0,r.jsx)("circle",{cx:"15",cy:"17",r:"1",fill:"white"})]}):"go"===c?(0,r.jsxs)("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,r.jsx)("ellipse",{cx:"12",cy:"12",rx:"8",ry:"6",fill:i}),(0,r.jsx)("circle",{cx:"9",cy:"11",r:"1.5",fill:"white"}),(0,r.jsx)("circle",{cx:"15",cy:"11",r:"1.5",fill:"white"}),(0,r.jsx)("circle",{cx:"9",cy:"11",r:"0.7",fill:"#333"}),(0,r.jsx)("circle",{cx:"15",cy:"11",r:"0.7",fill:"#333"})]}):"rs"===c?(0,r.jsxs)("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:i,strokeWidth:"2",fill:"none"}),(0,r.jsx)("circle",{cx:"12",cy:"12",r:"3",fill:i}),(0,r.jsx)("path",{d:"M12 3v3M12 18v3M3 12h3M18 12h3",stroke:i,strokeWidth:"2",strokeLinecap:"round"})]}):["png","jpg","jpeg","gif","webp","ico","bmp"].includes(c)?(0,r.jsxs)("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,r.jsx)("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2",stroke:i,strokeWidth:"1.5",fill:"none"}),(0,r.jsx)("circle",{cx:"8",cy:"9",r:"2",fill:i}),(0,r.jsx)("path",{d:"M3 16l5-5 3 3 4-4 6 6",stroke:i,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):"svg"===c?(0,r.jsxs)("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,r.jsx)("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2",stroke:i,strokeWidth:"1.5",fill:"none"}),(0,r.jsx)("path",{d:"M7 12 Q12 6 17 12 Q12 18 7 12",stroke:i,strokeWidth:"1.5",fill:"none"})]}):"html"===c?(0,r.jsxs)("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,r.jsx)("path",{d:"M4 3l1.5 17L12 22l6.5-2L20 3H4z",fill:i}),(0,r.jsx)("path",{d:"M8 7h8l-.5 6-3.5 1-3.5-1-.2-2",stroke:"white",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]}):["css","scss","sass","less"].includes(c)?(0,r.jsxs)("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,r.jsx)("path",{d:"M4 3l1.5 17L12 22l6.5-2L20 3H4z",fill:i}),(0,r.jsx)("path",{d:"M15 8H9l.3 3h5.2l-.4 4-2.1.7-2.1-.7-.1-2",stroke:"white",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]}):["yaml","yml"].includes(c)?(0,r.jsxs)("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,r.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",stroke:i,strokeWidth:"1.5",fill:"none"}),(0,r.jsx)("path",{d:"M7 8l3 4v5M17 8l-3 4v5",stroke:i,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):["sh","bash","zsh","fish"].includes(c)?(0,r.jsxs)("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,r.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",fill:"#1e1e1e",stroke:"#555",strokeWidth:"1"}),(0,r.jsx)("path",{d:"M6 9l3 3-3 3M12 15h5",stroke:i,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):"gitignore"===c||".gitignore"===e.toLowerCase()?(0,r.jsxs)("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"9",fill:i}),(0,r.jsx)("circle",{cx:"12",cy:"12",r:"3",fill:"white"}),(0,r.jsx)("path",{d:"M12 6v3M12 15v3M6 12h3M15 12h3",stroke:"white",strokeWidth:"2",strokeLinecap:"round"})]}):"dockerfile"===c||"dockerfile"===e.toLowerCase()||e.toLowerCase().startsWith("dockerfile")?(0,r.jsxs)("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,r.jsx)("path",{d:"M3 12h3v3H3zM7 12h3v3H7zM11 12h3v3h-3zM7 8h3v3H7zM11 8h3v3h-3zM11 4h3v3h-3zM15 12h3v3h-3z",fill:i}),(0,r.jsx)("path",{d:"M21 13c-1-2-3-2-4-2h-1c0-1 0-2-2-3h-1v1c0 1-1 2-2 2H3c-1 3 0 6 2 8s5 3 9 3c5 0 8-2 10-6",stroke:i,strokeWidth:"1.5",fill:"none"})]}):"env"===c||e.startsWith(".env")?(0,r.jsxs)("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,r.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",stroke:i,strokeWidth:"1.5",fill:"none"}),(0,r.jsx)("circle",{cx:"8",cy:"8",r:"2",fill:i}),(0,r.jsx)("path",{d:"M12 8h6M8 12h8M8 16h5",stroke:i,strokeWidth:"1.5",strokeLinecap:"round"})]}):"sql"===c?(0,r.jsxs)("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,r.jsx)("ellipse",{cx:"12",cy:"7",rx:"8",ry:"3",stroke:i,strokeWidth:"1.5",fill:"none"}),(0,r.jsx)("path",{d:"M4 7v10c0 1.7 3.6 3 8 3s8-1.3 8-3V7",stroke:i,strokeWidth:"1.5",fill:"none"}),(0,r.jsx)("path",{d:"M4 12c0 1.7 3.6 3 8 3s8-1.3 8-3",stroke:i,strokeWidth:"1.5",fill:"none"})]}):"vue"===c?(0,r.jsxs)("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,r.jsx)("path",{d:"M2 4h4l6 10 6-10h4L12 22 2 4z",fill:i}),(0,r.jsx)("path",{d:"M6 4h4l2 4 2-4h4l-6 10L6 4z",fill:"#35495e"})]}):(0,r.jsxs)("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,r.jsx)("path",{d:"M6 3h8l5 5v13H6V3z",stroke:i,strokeWidth:"1.5",fill:"none"}),(0,r.jsx)("path",{d:"M14 3v5h5",stroke:i,strokeWidth:"1.5",fill:"none"})]})}},17196:(e,t,n)=>{n.d(t,{Np:()=>c,ZD:()=>o,b8:()=>i,kS:()=>l,sQ:()=>a});let r=null,s=["typescript","tsx","javascript","jsx","html","css","scss","json","yaml","python","go","rust","java","ruby","php","bash","shell","markdown","sql","c","cpp","swift","kotlin","dart","lua","graphql","xml"];function l(){return r||(r=Promise.all([n.e(9304),n.e(4523)]).then(n.bind(n,64523)).then(({createHighlighter:e})=>e({themes:["github-dark","github-light"],langs:[...s]}))),r}function a(e){let t=e.split("/").pop()?.toLowerCase()||"",n=t.split(".").pop()?.toLowerCase();if(".env"===t||t.startsWith(".env.")||"dockerfile"===t||t.startsWith("dockerfile.")||"makefile"===t)return"bash";let r={ts:"typescript",tsx:"tsx",js:"javascript",jsx:"jsx",mjs:"javascript",cjs:"javascript",html:"html",htm:"html",css:"css",scss:"scss",json:"json",yaml:"yaml",yml:"yaml",xml:"xml",py:"python",go:"go",rs:"rust",java:"java",kt:"kotlin",rb:"ruby",php:"php",cs:"cpp",cpp:"cpp",c:"c",h:"c",sh:"bash",bash:"bash",zsh:"bash",md:"markdown",mdx:"markdown",sql:"sql",swift:"swift",dart:"dart",lua:"lua",graphql:"graphql",gql:"graphql",toml:"yaml",sass:"scss",less:"css",scala:"java",r:"python",vim:"bash",env:"bash"}[n||""]||"text";return s.includes(r)?r:"text"}function o(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function i(e){return e.map(e=>e.color?`<span style="color:${e.color}">${o(e.content)}</span>`:o(e.content)).join("")}function c(e,t,n,r){if(!t)return[];let s=[],l=n?t:t.toLowerCase();for(let t=0;t<e.length;t++){let a=n?e[t]:e[t].toLowerCase(),o=0;for(;;){let e=a.indexOf(l,o);if(-1===e)break;let n=e+l.length;if(r){let r=e>0?a[e-1]:" ",l=n<a.length?a[n]:" ",o=!/\w/.test(r),i=!/\w/.test(l);o&&i&&s.push({lineIndex:t,startCol:e,endCol:n})}else s.push({lineIndex:t,startCol:e,endCol:n});o=e+1}}return s}},20917:(e,t,n)=>{n.d(t,{e:()=>i});var r=n(12115),s=n(48948),l=n(69809),a=n(2111),o=n(95942);function i(e,t,{sessionId:n,cwd:c,engine:d,chatMode:u,planMode:h,ollamaModel:m,deepseekModel:f,onSessionId:x,onFetchTitle:p,onPtyOutput:g,onRunComplete:b}){let[v,y]=(0,r.useState)(!1),[w,k]=(0,r.useState)(null),[j,C]=(0,r.useState)(null),[N,S]=(0,r.useState)(null),[L,E]=(0,r.useState)(null),M=(0,r.useRef)(null),[R,T]=(0,r.useState)(null),$=(0,r.useRef)(R);$.current=R;let I=(0,r.useRef)(b);I.current=b;let P=(0,r.useRef)(!1),A=(0,r.useRef)(null),_=(0,r.useRef)(n);_.current=n;let D=(0,r.useRef)(null),F=(0,r.useRef)(null),W=(0,r.useRef)(null),B=(0,r.useRef)(!1),V=(0,r.useRef)(!1),O=(0,r.useRef)(0),z=(0,r.useCallback)(()=>{let e=D.current;if(e&&e.text){let{messageId:n,text:r}=e;t(e=>(0,s.F)(e,{type:"stream_event",event:{type:"content_block_delta",delta:{type:"text_delta",text:r}}},{engine:d,assistantId:n})),D.current={messageId:n,text:""}}F.current=null},[t,d]),H=(0,r.useCallback)(()=>{F.current&&(clearTimeout(F.current),F.current=null),A.current&&(clearTimeout(A.current),A.current=null),z(),y(!1);let e=$.current,n=W.current;e&&t(t=>t.map(t=>t.id===e.assistantId||t.id===n?{...t,isStreaming:!1}:t)),T(null),I.current?.()},[z,t]),K=(0,r.useCallback)(()=>{let e=$.current;fetch("/api/chat/stop",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:_.current,runId:e?.runKey})}).catch(()=>{}),H()},[H]),U=(0,r.useCallback)((e,n)=>{let r=e.type;if("pty_output"===r)return void g?.(e.data);if("pty_notice"===r){let r=e.messageKey?l.A.t(e.messageKey,e.params||{}):e.message;if(!r)return;e.terminal?t(e=>e.map(e=>e.id===n?{...e,content:r,isStreaming:!1}:e)):E(r);return}if("system"===r&&"init"===e.subtype){let n=e.session_id;if(x(n),_.current=n,S(null),B.current){let e=`auto-asst-${++O.current}`;W.current=e,t(t=>[...t,{id:e,role:"assistant",content:"",toolCalls:[],isStreaming:!0,runKey:$.current?.runKey}])}V.current=!0;return}if("system"===r&&"task_notification"===e.subtype){if(!V.current){let n=e.status,r=e.summary||"",s=e.task_id,l=`<task-notification>
|
|
2
|
+
`+(s?`<task-id>${s}</task-id>
|
|
3
|
+
`:"")+(n?`<status>${n}</status>
|
|
4
|
+
`:"")+(r?`<summary>${r}</summary>
|
|
5
|
+
`:"")+(e.output_file?`<output-file>${e.output_file}</output-file>
|
|
6
|
+
`:"")+"</task-notification>",a=`auto-tasknotif-${s||++O.current}`;t(e=>[...e,{id:a,role:"system",content:r,systemEvent:{kind:"task-notification",...n?{status:n}:{},detail:l},runKey:$.current?.runKey}])}return}if("system"===r&&"api_retry"===e.subtype)return void S({attempt:e.attempt??0,maxRetries:e.max_retries??0,delayMs:e.retry_delay_ms??0,errorStatus:e.error_status,error:e.error});if("rate_limit_event"===r){let t=e.rate_limit_info;t&&C({status:t.status||"allowed",resetsAt:t.resetsAt,rateLimitType:t.rateLimitType,utilization:t.utilization,overageStatus:t.overageStatus,overageDisabledReason:t.overageDisabledReason,isUsingOverage:t.isUsingOverage,surpassedThreshold:t.surpassedThreshold});return}if("error"===r){let r=e.error||l.A.t("chat.errorRetry",{defaultValue:"An error occurred. Please try again."});S(null),F.current&&(clearTimeout(F.current),F.current=null),z(),t(e=>e.map(e=>e.id===n?{...e,content:e.content?`${e.content}
|
|
7
|
+
|
|
8
|
+
⚠️ ${r}`:`⚠️ ${r}`,isStreaming:!1}:e));return}if("stream_event"===r){S(e=>e?null:e),E(e=>e?null:e);let t=e.event;if(t?.type==="content_block_delta"&&t.delta?.type==="text_delta"){let e=t.delta.text||"";D.current&&D.current.messageId===n?D.current.text+=e:D.current={messageId:n,text:e},F.current||(F.current=setTimeout(z,50))}return}if("assistant"===r&&t(t=>(0,s.F)(t,e,{engine:d,assistantId:n})),"user"===r&&t(t=>(0,s.F)(t,e,{engine:d,assistantId:n})),"result"===r){V.current=!1,B.current=!0,S(null),F.current&&(clearTimeout(F.current),F.current=null),z();let r=_.current;r&&c&&t(e=>(2===e.length&&p(r),e));let l=e.usage,a=e.total_cost_usd;l&&k({inputTokens:l.input_tokens||0,outputTokens:l.output_tokens||0,cacheCreationInputTokens:l.cache_creation_input_tokens||0,cacheReadInputTokens:l.cache_read_input_tokens||0,totalCostUsd:a||0}),t(t=>(0,s.F)(t,e,{engine:d,assistantId:n}))}},[t,z,x,p,c,d,g]);return(0,a.h)({url:R?`/ws/session-stream?sessionId=${encodeURIComponent(R.runKey)}`:"/ws/session-stream",enabled:!!R,onMessage:e=>{P.current=!0,A.current&&(clearTimeout(A.current),A.current=null);let n=$.current;if(n)if("run-snapshot"===e.type&&Array.isArray(e.events)){for(let r of(F.current&&(clearTimeout(F.current),F.current=null),D.current=null,W.current=n.assistantId,B.current=!1,V.current=!1,t(e=>e.filter(e=>!("string"==typeof e.id&&e.id.startsWith("auto-")&&e.runKey===n.runKey)).map(e=>e.id===n.assistantId?{...e,content:"",toolCalls:[]}:e)),e.events))U(r,W.current??n.assistantId);e.status&&"running"!==e.status&&H()}else if("run-event"===e.type&&e.message){if("run-ended"===e.message.type)return void H();U(e.message,W.current??n.assistantId)}else"run-idle"===e.type&&H()}}),{isLoading:v,tokenUsage:w,rateLimitInfo:j,apiRetryInfo:N,ptyNotice:L,handleSend:(0,r.useCallback)(async(e,n,r)=>{let s=r&&"permissionMode"in r?"plan"===r.permissionMode:h,a=n?.map(e=>({type:"base64",media_type:e.media_type,data:e.data})),i={id:`user-${Date.now()}`,role:"user",content:e,images:a};t(e=>[...e,i]),y(!0),S(null),E(null);let x=`assistant-${Date.now()}`,p={id:x,role:"assistant",content:"",toolCalls:[],isStreaming:!0};t(e=>[...e,p]),W.current=x,B.current=!1,V.current=!1;let g=!d||"claude"===d||"claude2"===d,b="pty"===u&&g,v=function(){try{return crypto.randomUUID()}catch{return`run-${Date.now()}-${Math.floor(1e9*Math.random())}`}}();try{if("ollama"===d&&!m)throw Error("Please select an Ollama model first (click the model picker above)");let n="codex"===d?"/api/chat/codex":"kimi"===d?"/api/chat/kimi":"ollama"===d?"/api/chat/ollama":"deepseek"===d?"/api/chat/deepseek":"/api/chat",r=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:e,sessionId:_.current,runId:v,images:a,cwd:c,language:l.A.language,..."ollama"===d&&m&&{model:m},..."deepseek"===d&&f&&{model:f},..."claude2"===d&&{engine:"claude2"},...b&&{mode:"pty",ptyCols:o.EE,ptyRows:o.K2},...s&&!b&&g&&{permissionMode:"plan"}})});if(400===r.status&&"deepseek"===d){let e=await r.json().catch(()=>null);throw Error(e?.error||"DeepSeek request failed")}if(!r.ok)throw Error(l.A.t("chat.requestFailed",{defaultValue:"Request failed"}));let i=await r.json().catch(()=>({}));T({runKey:i.runKey||v,assistantId:x}),P.current=!1,A.current&&clearTimeout(A.current),A.current=setTimeout(()=>{$.current&&!P.current&&(t(e=>e.map(e=>e.id!==x||e.content?e:{...e,content:l.A.t("chat.errorRetry",{defaultValue:"An error occurred. Please try again."})})),H())},15e3)}catch(n){console.error("Chat error:",n);let e=n instanceof Error?n.message:l.A.t("chat.errorRetry",{defaultValue:"An error occurred. Please try again."});t(t=>t.map(t=>t.id===x?{...t,content:e,isStreaming:!1}:t)),y(!1),T(null)}},[c,d,u,h,m,f,t,H]),handleStop:K,abortControllerRef:M}}},22576:(e,t,n)=>{n.d(t,{X:()=>r});function r(e,t){let n=e.split("\n"),r=t.split("\n"),s=[],l=n.length,a=r.length,o=Array(l+1).fill(null).map(()=>Array(a+1).fill(0));for(let e=1;e<=l;e++)for(let t=1;t<=a;t++)n[e-1]===r[t-1]?o[e][t]=o[e-1][t-1]+1:o[e][t]=Math.max(o[e-1][t],o[e][t-1]);let i=l,c=a,d=[];for(;i>0||c>0;)i>0&&c>0&&n[i-1]===r[c-1]?(d.push({type:"unchanged",content:n[i-1],oldLineNum:i,newLineNum:c}),i--,c--):c>0&&(0===i||o[i][c-1]>=o[i-1][c])?(d.push({type:"added",content:r[c-1],newLineNum:c}),c--):(d.push({type:"removed",content:n[i-1],oldLineNum:i}),i--);for(;d.length>0;)s.push(d.pop());return s}},27570:(e,t,n)=>{n.d(t,{L:()=>s});var r=n(12115);function s({enabled:e,container:t,resolveLineRange:n,buildLineSnapshot:l,dragThresholdPx:a=5}){let o=(0,r.useRef)(null),i=(0,r.useRef)(()=>{}),c=(0,r.useRef)(n),d=(0,r.useRef)(l),u=(0,r.useRef)(a);return c.current=n,d.current=l,u.current=a,(0,r.useEffect)(()=>{if(!e||!t)return;let n=!1,r=0,s=0,l=()=>{o.current&&(o.current=null,i.current())},a=e=>{n=!0,r=e.clientX,s=e.clientY;let t=e.target;t?.closest?.(".floating-toolbar")||l()},h=e=>{n=!1;let a=e.target;if(a?.closest?.(".floating-toolbar"))return;let h=u.current,m=Math.abs(e.clientX-r)>h||Math.abs(e.clientY-s)>h,f=window.getSelection();if(!f||f.isCollapsed||!f.toString().trim()||!m)return void l();let x=f.getRangeAt(0);if(!t.contains(x.commonAncestorContainer))return void l();let p=c.current(x.startContainer),g=c.current(x.endContainer);if(!p||!g)return void l();let b=Math.min(p.start,g.start),v=Math.max(p.end,g.end),y=f.toString(),w=d.current({start:b,end:v});o.current={x:e.clientX,y:e.clientY,range:{start:b,end:v},selectedText:y,lineSnapshot:w},i.current()},m=()=>{if(n||!o.current)return;let e=window.getSelection();e&&!e.isCollapsed&&e.toString().trim()||l()};return t.addEventListener("mousedown",a),document.addEventListener("mouseup",h),document.addEventListener("selectionchange",m),()=>{t.removeEventListener("mousedown",a),document.removeEventListener("mouseup",h),document.removeEventListener("selectionchange",m)}},[e,t]),{toolbarRef:o,bumpRef:i,clearToolbar:()=>{o.current&&(o.current=null,i.current())}}}},30133:(e,t,n)=>{n.d(t,{y:()=>l});var r=n(95155),s=n(79114);function l({value:e,onChange:t,className:n}){let{t:a}=(0,s.Bd)();return(0,r.jsx)("div",{className:`flex items-center gap-0.5 rounded border border-border overflow-hidden ${n??""}`,children:["compact","full"].map(n=>(0,r.jsx)("button",{onClick:e=>{e.stopPropagation(),t(n)},className:`px-2 py-0.5 text-xs transition-colors ${e===n?"bg-brand text-white":"text-muted-foreground hover:bg-accent"}`,children:a("compact"===n?"diffViewer.compact":"diffViewer.full")},n))})}},37614:(e,t,n)=>{n.d(t,{t:()=>a});var r=n(95155),s=n(12115),l=n(79114);function a({x:e,y:t,comment:n,container:o,onClose:i,onUpdateComment:c,onDeleteComment:d}){let{t:u}=(0,l.Bd)(),[h,m]=(0,s.useState)(!1),[f,x]=(0,s.useState)(n.content),p=(0,s.useRef)(null),[g,b]=(0,s.useState)({x:0,y:0});(0,s.useEffect)(()=>{if(p.current&&o){let n=o.getBoundingClientRect(),r=p.current.getBoundingClientRect(),s=e-n.left,l=t-n.top;s+r.width>n.width-16&&(s=n.width-r.width-16),s<16&&(s=16),l+r.height>n.height-16&&(l=l-r.height-8),l<16&&(l=16),queueMicrotask(()=>b({x:s,y:l}))}},[e,t,o]),(0,s.useEffect)(()=>{let e=e=>{p.current&&!p.current.contains(e.target)&&i()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[i]);let v=async()=>{f.trim()&&(await c(n.id,f.trim()),m(!1))},y=async()=>{await d(n.id),i()};return(0,r.jsx)("div",{ref:p,className:"absolute z-[200] w-96 bg-card border border-border rounded-lg shadow-lg overflow-hidden",style:{left:g.x,top:g.y},children:(0,r.jsx)("div",{className:"p-3",children:h?(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)("textarea",{value:f,onChange:e=>x(e.target.value),className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card resize-none focus:outline-none focus:ring-1 focus:ring-ring",rows:3,autoFocus:!0,onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),v()),"Escape"===e.key&&(m(!1),x(n.content))}}),(0,r.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,r.jsx)("button",{onClick:()=>{m(!1),x(n.content)},className:"px-2 py-1 text-xs text-muted-foreground hover:text-foreground",children:u("common.cancel")}),(0,r.jsx)("button",{onClick:v,className:"px-2 py-1 text-xs bg-brand text-white rounded hover:bg-brand/90",children:u("common.save")})]})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("p",{className:"text-sm text-foreground whitespace-pre-wrap",children:n.content}),(0,r.jsxs)("div",{className:"mt-2 flex items-center justify-between",children:[(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:u("comments.lineRange",{start:n.startLine,end:n.endLine})}),(0,r.jsxs)("div",{className:"flex gap-1",children:[(0,r.jsx)("button",{onClick:()=>m(!0),className:"p-1 rounded hover:bg-accent text-muted-foreground",title:u("common.edit"),children:(0,r.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.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"})})}),(0,r.jsx)("button",{onClick:y,className:"p-1 rounded hover:bg-accent text-muted-foreground hover:text-red-9",title:u("common.delete"),children:(0,r.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.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"})})})]})]})]})})})}},38175:(e,t,n)=>{n.d(t,{E:()=>d});var r=n(95155),s=n(12115),l=n(48347),a=n(89109),o=n(7320),i=n(1058),c=n(90717);function d({content:e,filePath:t,cwd:n,onContentSearch:u}){let h=(0,l.r)(),m=!!n,{addComment:f,refresh:x}=(0,i._)({cwd:n||"",filePath:t}),[p,g]=(0,s.useState)(null),b=(0,s.useRef)(null),v=(0,s.useRef)(null),y=(0,s.useRef)(()=>{}),[w,k]=(0,s.useState)(null),[j,C]=(0,s.useState)(null),N=(0,s.useRef)(!1);(0,s.useEffect)(()=>{N.current=!!(w||j)},[w,j]);let S=(0,s.useCallback)(()=>{v.current&&(v.current=null,y.current())},[]),L=(0,s.useCallback)(()=>{if(!m)return;let e=b.current,t=e?.contentDocument;e&&t&&(t.addEventListener("mouseup",t=>{if(N.current)return;let n=e.contentWindow?.getSelection(),r=n&&!n.isCollapsed?n.toString().trim():"";if(!r)return void S();let s=e.getBoundingClientRect();v.current={x:s.left+t.clientX,y:s.top+t.clientY,range:{start:0,end:0},selectedText:r,lineSnapshot:r},y.current()}),t.addEventListener("mousedown",()=>{S(),k(null),C(null)}),t.addEventListener("scroll",()=>S(),{capture:!0,passive:!0}))},[m,S]),E=(0,s.useCallback)(()=>{let e=v.current;e&&(k({x:e.x,y:e.y,text:e.selectedText}),S(),b.current?.contentWindow?.getSelection()?.removeAllRanges())},[S]),M=(0,s.useCallback)(()=>{let e=v.current;e&&(C({x:e.x,y:e.y,text:e.selectedText}),S(),b.current?.contentWindow?.getSelection()?.removeAllRanges())},[S]),R=(0,s.useCallback)(()=>{let e=v.current;if(!e||!u)return;let t=e.selectedText.trim();S(),b.current?.contentWindow?.getSelection()?.removeAllRanges(),t&&u(t)},[u,S]),T=(0,s.useCallback)(async e=>{w&&(await f(0,0,e,w.text),k(null))},[w,f]),$=(0,s.useCallback)(async(e,r)=>{if(h&&n)try{let s=(await (0,c.$3)(n)).map(e=>({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0}));s.push({filePath:t,startLine:0,endLine:0,codeContent:e});let l=(0,c.Gw)(s,r);h.sendMessage(l),await (0,c.RP)(n),x()}catch(e){console.error("[HtmlPreview] send to AI failed:",e)}},[h,n,t,x]),I=(0,s.useCallback)(e=>{j&&$(j.text,e)},[j,$]),P=(0,s.useCallback)(e=>{w&&$(w.text,e)},[w,$]);return(0,r.jsxs)("div",{ref:g,className:"relative h-full w-full bg-white",children:[(0,r.jsx)("iframe",{ref:b,srcDoc:e,title:t,sandbox:"allow-scripts allow-same-origin",className:"h-full w-full border-0",onLoad:L},t),m&&p&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(a.f,{floatingToolbarRef:v,bumpRef:y,container:p,onAddComment:E,onSendToAI:M,onSearch:u?R:void 0,isChatLoading:h?.isLoading}),w&&(0,r.jsx)(o.t,{x:w.x,y:w.y,range:{start:0,end:0},filePath:t,lineSnapshot:w.text,container:p,onSubmit:T,onSendToAI:h?P:void 0,onClose:()=>k(null),isChatLoading:h?.isLoading}),j&&(0,r.jsx)(o.G,{x:j.x,y:j.y,range:{start:0,end:0},filePath:t,lineSnapshot:j.text,container:p,onSubmit:I,onClose:()=>C(null),isChatLoading:h?.isLoading})]})]})}},38408:(e,t,n)=>{n.d(t,{Cv:()=>P,XO:()=>A});var r=n(95155),s=n(12115),l=n(79114),a=n(47650),o=n(86957),i=n(60938),c=n(70188),d=n(7320),u=n(56978),h=n(17196),m=n(89109),f=n(37614),x=n(69809),p=n(64428);function g({blame:e,onClick:t}){let{t:n}=(0,l.Bd)(),a=(0,s.useRef)(null),o=(0,s.useRef)(null),i=(0,p.F2)(),c=(0,s.useRef)(!1),d=(0,s.useRef)(!1),u=(0,s.useRef)(null),h=(0,s.useRef)(null),m=(0,s.useRef)(null),f=(0,s.useRef)(e);(0,s.useEffect)(()=>{f.current=e},[e]);let b=(0,s.useRef)(t);(0,s.useEffect)(()=>{b.current=t},[t]);let v=(0,s.useCallback)(()=>{let e,t=o.current,n=a.current;if(!t||!n)return;let r=n.getBoundingClientRect(),s=t.getBoundingClientRect(),l=i?.getBoundingClientRect(),c=l?.left??0,d=l?.top??0,u=l?.width??window.innerWidth,h=l?.height??window.innerHeight,m=r.left-c;m+s.width>u-8&&(m=u-s.width-8),m<8&&(m=8);let f=r.top-d,x=r.bottom-d;(e=f-s.height-4<0?x+4:f-s.height-4)+s.height>h-8&&(e=h-s.height-8),t.style.left=`${m}px`,t.style.top=`${e}px`},[i]),y=(0,s.useCallback)(()=>{u.current&&(clearTimeout(u.current),u.current=null),h.current&&(clearTimeout(h.current),h.current=null),c.current=!1,d.current=!1,o.current&&(o.current.style.display="none"),m.current&&(document.removeEventListener("mousedown",m.current.down),document.removeEventListener("mouseup",m.current.up),m.current=null)},[]),w=(0,s.useCallback)(()=>{let e=o.current;if(!e||c.current)return;c.current=!0,e.style.left="-9999px",e.style.top="-9999px",e.style.display="block",requestAnimationFrame(()=>requestAnimationFrame(v));let t=0,n=0,r=e=>{t=e.clientX,n=e.clientY},s=e=>{if(!(Math.abs(e.clientX-t)>5||Math.abs(e.clientY-n)>5)){let t;t=e.target,o.current?.contains(t)||a.current?.contains(t)||y()}};document.addEventListener("mousedown",r),document.addEventListener("mouseup",s),m.current={down:r,up:s}},[v,y]),k=(0,s.useCallback)(()=>{if(u.current&&clearTimeout(u.current),h.current&&(clearTimeout(h.current),h.current=null),c.current)return;let e=window.getSelection();(!e||e.isCollapsed)&&(u.current=setTimeout(w,500))},[w]),j=(0,s.useCallback)(()=>{u.current&&(clearTimeout(u.current),u.current=null),c.current&&(h.current=setTimeout(()=>{d.current||y()},200))},[y]),C=(0,s.useCallback)(()=>{d.current=!0,h.current&&(clearTimeout(h.current),h.current=null)},[]),N=(0,s.useCallback)(()=>{d.current=!1,y()},[y]),S=(0,s.useCallback)(e=>{e.stopPropagation();let t=window.getSelection();t&&t.toString().length>0&&o.current?.contains(t.anchorNode)||(b.current?.(f.current),y())},[y]);(0,s.useEffect)(()=>()=>y(),[y]);let L=e.message.split("\n")[0]||"",E=e.message.split("\n").slice(1).join("\n").trim();return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("span",{ref:a,className:"select-none text-xs text-muted-foreground/50 ml-6 cursor-default hover:text-muted-foreground/80",onMouseEnter:k,onMouseLeave:j,children:[e.author.split(" ")[0],", ",function(e){let t=x.A.t,n=Math.floor((Date.now()-1e3*e)/1e3);if(n<60)return t("common.justNow");let r=Math.floor(n/60);if(r<60)return t("common.minutesAgo",{count:r});let s=Math.floor(r/60);if(s<24)return t("common.hoursAgo",{count:s});let l=Math.floor(s/24);if(l<30)return t("common.daysAgo",{count:l});let a=Math.floor(l/30);return a<12?t("common.monthsAgo",{count:a}):t("common.yearsAgo",{count:Math.floor(a/12)})}(e.time)," \xb7 ",L]}),(0,r.jsx)(p.ZL,{children:(0,r.jsxs)("div",{ref:o,className:"fixed z-[9999] bg-card border border-border rounded-lg shadow-xl p-3 text-xs text-foreground whitespace-pre-wrap max-w-md select-text",style:{display:"none",minWidth:280,cursor:"text"},"data-inline-blame-tip":"",onMouseEnter:C,onMouseLeave:N,children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 mb-1.5",children:[(0,r.jsx)("span",{className:"font-mono text-brand",children:e.hash}),(0,r.jsx)("span",{className:"text-muted-foreground",children:e.author}),(0,r.jsx)("span",{className:"text-muted-foreground/60",children:new Date(1e3*e.time).toLocaleString()})]}),(0,r.jsx)("div",{className:"font-medium",children:L}),E&&(0,r.jsx)("div",{className:"mt-1 text-muted-foreground",children:E}),(0,r.jsx)("div",{className:"mt-2 text-[11px] text-brand border-t border-border pt-2 cursor-pointer hover:underline",onClick:S,children:n("codeViewer.clickToViewDetails")})]})})]})}let b=[{bg:"rgba(59, 130, 246, 0.15)",border:"rgb(59, 130, 246)"},{bg:"rgba(16, 185, 129, 0.15)",border:"rgb(16, 185, 129)"},{bg:"rgba(245, 158, 11, 0.15)",border:"rgb(245, 158, 11)"},{bg:"rgba(239, 68, 68, 0.15)",border:"rgb(239, 68, 68)"},{bg:"rgba(168, 85, 247, 0.15)",border:"rgb(168, 85, 247)"},{bg:"rgba(236, 72, 153, 0.15)",border:"rgb(236, 72, 153)"},{bg:"rgba(20, 184, 166, 0.15)",border:"rgb(20, 184, 166)"},{bg:"rgba(249, 115, 22, 0.15)",border:"rgb(249, 115, 22)"}];function v(e,t){let n,r=document.caretRangeFromPoint(e.clientX,e.clientY);if(!r||!t.contains(r.startContainer))return 1;let s=r.startContainer,l=r.startOffset,a=document.createTreeWalker(t,NodeFilter.SHOW_TEXT),o=1;for(;n=a.nextNode();){if(n===s){o+=l;break}o+=n.textContent?.length||0}return o}let y=(0,s.memo)(function({virtualKey:e,lineNum:t,highlightedHtml:n,hasComments:a,firstComment:o,lineCommentsCount:i,isInRange:c,showLineNumbers:d,lineNumChars:u,commentsEnabled:h,virtualItemSize:m,virtualItemStart:f,onCommentBubbleClick:x,onCmdClick:p,onTokenHover:b,onTokenHoverLeave:y,flashLine:w,blameLine:k,showBlameInfo:j,blameAuthorColor:C,isBlameHovered:N,onBlameClick:S,onBlameMouseEnter:L,onBlameMouseLeave:E,inlineBlameData:M,onInlineBlameClick:R,isCursorLine:T,cursorCol:$}){let{t:I}=(0,l.Bd)(),P=(0,s.useMemo)(()=>T&&null!=$?function(e,t){let n=0,r=0;for(;r<e.length;){if("<"===e[r]){let t=e.indexOf(">",r);if(-1!==t){r=t+1;continue}}if(n===t){let t;if("&"===e[r]){let n=e.indexOf(";",r);t=-1!==n&&n-r<10?n+1:r+1}else t=r+1;let n=e.substring(r,t);return e.substring(0,r)+'<span class="vi-char-cursor">'+n+"</span>"+e.substring(t)}if("&"===e[r]){let t=e.indexOf(";",r);r=-1!==t&&t-r<10?t+1:r+1}else r++;n++}return e+'<span class="vi-char-cursor"> </span>'}(n,$):n,[n,T,$]),A=(0,s.useCallback)(e=>{if(!e.metaKey||!p)return;e.preventDefault(),e.stopPropagation();let n=e.currentTarget,r=v(e,n);window.getSelection()?.removeAllRanges(),p(t,r)},[t,p]),_=(0,s.useCallback)(e=>{if(!b||0!==e.buttons)return;let n=window.getSelection();if(n&&!n.isCollapsed)return;let r=e.target;if("SPAN"!==r.tagName||!r.style.color)return;let s=e.currentTarget,l=v(e,s),a=r.getBoundingClientRect();b(t,l,{x:a.left,y:a.bottom+4})},[t,b]),D=(0,s.useCallback)(()=>{k&&S&&S(k)},[k,S]),F=(0,s.useCallback)(e=>{k&&L&&L(k,e)},[k,L]);return(0,r.jsxs)("div",{"data-line":t,style:{position:"absolute",top:0,left:0,width:"100%",height:`${m}px`,transform:`translateY(${f}px)`,backgroundColor:N&&C?C.bg:void 0},className:`flex ${w===t?"flash-line":""} ${T?"vi-cursor-line":""} ${c?"bg-blue-9/20":a?"bg-amber-9/10":"hover:bg-accent/50"}`,children:[(0,r.jsxs)("div",{className:"flex shrink-0 sticky left-0 z-[2] bg-secondary",style:{backgroundColor:N&&C?C.bg:void 0},children:[k&&C&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"w-1 flex-shrink-0",style:{backgroundColor:C.border}}),(0,r.jsx)("div",{className:"w-48 flex-shrink-0 px-2 flex items-center gap-2 border-r border-border text-muted-foreground cursor-pointer hover:bg-accent/50",onMouseEnter:F,onMouseLeave:E,onClick:D,title:I("codeViewer.clickToViewCommit"),children:j?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"font-medium",style:{color:C.border},children:k.hash}),(0,r.jsx)("span",{className:"truncate flex-1",children:k.author.split(" ")[0]})]}):null})]}),d&&(0,r.jsxs)("span",{className:`flex-shrink-0 flex items-center justify-end gap-0.5 pr-2 select-none border-r border-border font-variant-tabular ${c?"bg-blue-9/30 text-blue-11":"bg-card/50 text-slate-9"}`,children:[h&&a&&o&&(0,r.jsx)("button",{onClick:e=>x(o,e),className:"w-4 h-4 flex items-center justify-center rounded hover:bg-accent text-amber-9",title:I("codeViewer.nComments",{count:i}),children:(0,r.jsx)("svg",{className:"w-3 h-3",fill:"currentColor",viewBox:"0 0 20 20",children:(0,r.jsx)("path",{fillRule:"evenodd",d:"M18 10c0 3.866-3.582 7-8 7a8.841 8.841 0 01-4.083-.98L2 17l1.338-3.123C2.493 12.767 2 11.434 2 10c0-3.866 3.582-7 8-7s8 3.134 8 7zM7 9H5v2h2V9zm8 0h-2v2h2V9zM9 9h2v2H9V9z",clipRule:"evenodd"})})}),h&&!a&&(0,r.jsx)("span",{className:"w-4"}),(0,r.jsx)("span",{className:"text-right",style:{minWidth:`${u}ch`},children:t})]})]}),(0,r.jsxs)("span",{className:"flex-1 px-3 whitespace-pre select-text",onClick:A,onMouseOver:_,onMouseLeave:y,"data-code-content":!0,children:[(0,r.jsx)("span",{dangerouslySetInnerHTML:{__html:P}}),M&&(0,r.jsx)(g,{blame:M,onClick:R})]})]},e)});var w=n(64702),k=n(1058),j=n(90717),C=n(48347),N=n(27570);function S(e,t,n){let r,s=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),l=0;for(;(r=s.nextNode())&&r!==t;)l+=r.textContent.length;return l+n}function L(e,t){let n,r=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),s=t,l=null;for(;n=r.nextNode();){l=n;let e=n.textContent.length;if(s<=e)return{node:n,offset:s};s-=e}return l?{node:l,offset:l.textContent.length}:null}var E=n(82292),M=n(34075);let R="white-space:pre;padding:0 12px;min-height:20px;line-height:20px";function T(e){let t=window.getSelection();if(!t?.rangeCount)return null;let n=t.getRangeAt(0),r=n.startContainer;for(;r&&r.parentElement!==e;)r=r.parentElement;if(!r)return null;let s=Array.from(e.children).indexOf(r);if(s<0)return null;let l=document.createRange();return l.selectNodeContents(r),l.setEnd(n.startContainer,n.startOffset),{line:s,offset:l.toString().length}}function $(e,t){let n,r=e.children[t.line];if(!r)return;let s=document.createTreeWalker(r,NodeFilter.SHOW_TEXT),l=t.offset;for(;n=s.nextNode();){let e=n.textContent?.length||0;if(l<=e){let e=window.getSelection(),t=document.createRange();t.setStart(n,l),t.collapse(!0),e?.removeAllRanges(),e?.addRange(t);return}l-=e}let a=window.getSelection(),o=document.createRange();o.selectNodeContents(r),o.collapse(!1),a?.removeAllRanges(),a?.addRange(o)}function I(e){return e.map(e=>`<div style="${R}">${e}</div>`).join("")}let P=(0,s.forwardRef)(function({content:e,filePath:t,showLineNumbers:n=!0,showSearch:x=!0,className:p="",cwd:g,enableComments:v=!1,scrollToLine:P=null,scrollToLineAlign:A="center",onScrollToLineComplete:_,highlightKeyword:D=null,visibleLineRef:F,onCmdClick:W,onTokenHover:B,onTokenHoverLeave:V,onTokenHoverCancel:O,blameLines:z,inlineBlameLines:H,onSelectCommit:K,editable:U=!1,initialMtime:q,onEditorClose:X,onSaved:Z,onEditorStateChange:G,viMode:J=!1,onContentMutate:Y,onEnterInsertMode:Q,onViSave:ee,viStateRef:et,initialCursorLine:en,initialCursorCol:er,onInitialCursorSet:es,onContentSearch:el},ea){let{t:eo}=(0,l.Bd)(),ei=(0,s.useRef)(e),ec=(0,s.useRef)(!1),[ed,eu]=(0,s.useState)(!1),[eh,em]=(0,s.useState)(!1),[ef,ex]=(0,s.useState)(()=>e.split("\n").length),ep=(0,s.useRef)(e.split("\n").length),[eg,eb]=(0,s.useState)({show:!1}),ev=(0,s.useRef)(null),ey=(0,s.useRef)(null),ew=(0,s.useRef)(q),ek=(0,s.useRef)(null),ej=(0,s.useRef)(!1),eC=(0,s.useRef)(!1),{parentRef:eN,containerRef:eS,searchInputRef:eL,floatingToolbarRef:eE,suppressHoverRef:eM,bumpToolbarRef:eR,savedSelectionRef:eT,highlightedLines:e$,isMounted:eI,cmdHeld:eP,flashLine:eA,isSearchVisible:e_,searchQuery:eD,caseSensitive:eF,wholeWord:eW,currentMatchIndex:eB,viewingComment:eV,addCommentInput:eO,sendToAIInput:ez,aiBridge:eH,commentsEnabled:eK,updateComment:eU,deleteComment:eq,lines:eX,matches:eZ,rowData:eG,virtualizer:eJ,commentsByEndLine:eY,linesWithComments:eQ,setIsSearchVisible:e0,setSearchQuery:e1,setCaseSensitive:e2,setWholeWord:e5,setViewingComment:e4,setAddCommentInput:e3,setSendToAIInput:e8,goToNextMatch:e6,goToPrevMatch:e9,handleSearchKeyDown:e7,handleCommentBubbleClick:te,handleToolbarAddComment:tt,handleToolbarSendToAI:tn,handleToolbarSearch:tr,handleCommentSubmit:ts,handleSendToAISubmit:tl,handleCommentSendToAI:ta,getHighlightedLineHtml:to,suppressMatchScrollRef:ti,inlineBlameLineRef:tc,inlineBlameVersion:td}=function({content:e,filePath:t,showSearch:n=!0,cwd:r,enableComments:l=!1,scrollToLine:a=null,scrollToLineAlign:o="center",onScrollToLineComplete:i,visibleLineRef:c,onContentSearch:d}){let[m,f]=(0,s.useState)(!1),x=(0,s.useRef)(null),p=(0,s.useRef)(null),g=(0,s.useRef)(null),b=(0,C.r)();(0,s.useEffect)(()=>{f(!0)},[]);let[v,y]=(0,s.useState)(!1),[L,E]=(0,s.useState)(null),M=(0,s.useRef)(null),[R,T]=(0,s.useState)(!1),[$,I]=(0,s.useState)(""),[P,A]=(0,s.useState)(!1),[_,D]=(0,s.useState)(!1),[F,W]=(0,s.useState)(0),[B,V]=(0,s.useState)(0),O=(0,s.useRef)(!1),[z,H]=(0,s.useState)(null),K=(0,s.useRef)(!1),U=(0,s.useRef)(null),[q,X]=(0,s.useState)(null),[Z,G]=(0,s.useState)(null),J=(0,s.useMemo)(()=>e.split("\n"),[e]),[Y,Q]=(0,s.useState)(null);(0,s.useEffect)(()=>{x.current!==Y&&Q(x.current)});let ee=l&&!!r,{toolbarRef:et,bumpRef:en,clearToolbar:er}=(0,N.L)({enabled:ee,container:Y,resolveLineRange:e=>{if(!document.contains(e))return null;let t=e.nodeType===Node.TEXT_NODE?e.parentElement:e,n=t?.closest("[data-line]");if(!n)return null;let r=parseInt(n.getAttribute("data-line")||"0",10);return!Number.isFinite(r)||r<=0?null:{start:r,end:r}},buildLineSnapshot:({start:e,end:t})=>J.slice(e-1,t).join("\n")}),es=(0,s.useRef)(null),[el,ea]=(0,s.useState)(0),{comments:eo,addComment:ei,updateComment:ec,deleteComment:ed,refresh:eu}=(0,k._)({cwd:r||"",filePath:t}),eh=(0,u.C)(J,t),em=(0,s.useMemo)(()=>{let e=new Map;for(let t of eo){let n=t.endLine;e.has(n)||e.set(n,[]),e.get(n).push(t)}return e},[eo]),ef=(0,s.useMemo)(()=>{let e=new Set;for(let t of eo)for(let n=t.startLine;n<=t.endLine;n++)e.add(n);return e},[eo]),ex=(0,s.useMemo)(()=>(0,h.Np)(J,$,P,_),[J,$,P,_]);(0,s.useEffect)(()=>{ex.length>0&&W(0)},[ex.length,$,P,_]);let ep=(0,s.useMemo)(()=>{let e=[];for(let t=0;t<J.length;t++)e.push({type:"code",lineIndex:t});return e},[J.length]),eg=(0,w.Te)({count:ep.length,getScrollElement:()=>x.current,estimateSize:()=>20,overscan:10});(0,s.useEffect)(()=>{if(!c)return;let e=x.current;if(!e)return;let t=()=>{if(!eg.range)return;let t=e.scrollTop;for(let e of eg.getVirtualItems())if(e.start>=t){let t=ep[e.index];t?.type==="code"&&(c.current=t.lineIndex+1);return}};return e.addEventListener("scroll",t,{passive:!0}),t(),()=>e.removeEventListener("scroll",t)},[c,ep]),(0,s.useEffect)(()=>{let e=e=>{"Meta"===e.key&&y(!0)},t=e=>{"Meta"===e.key&&y(!1)},n=()=>y(!1);return window.addEventListener("keydown",e),window.addEventListener("keyup",t),window.addEventListener("blur",n),()=>{window.removeEventListener("keydown",e),window.removeEventListener("keyup",t),window.removeEventListener("blur",n)}},[]),(0,s.useEffect)(()=>{if(!n)return;let e=e=>{(e.metaKey||e.ctrlKey)&&"f"===e.key&&(e.preventDefault(),T(!0),setTimeout(()=>g.current?.focus(),0)),"Escape"===e.key&&(R?(T(!1),I("")):Z?G(null):q?X(null):et.current?er():z&&H(null))},t=p.current;if(t)return t.addEventListener("keydown",e),()=>t.removeEventListener("keydown",e)},[n,R,Z,q,z]),(0,s.useEffect)(()=>{if(O.current){O.current=!1;return}if(ex.length>0&&F>=0&&F<ex.length){let e=ex[F],t=ep.findIndex(t=>"code"===t.type&&t.lineIndex===e.lineIndex);t>=0&&eg.scrollToIndex(t,{align:"center"})}},[F,ex,eg,ep,B]);let eb=(0,s.useCallback)(()=>{0!==ex.length&&(W(e=>(e+1)%ex.length),V(e=>e+1))},[ex.length]),ev=(0,s.useCallback)(()=>{0!==ex.length&&(W(e=>(e-1+ex.length)%ex.length),V(e=>e+1))},[ex.length]),ey=(0,s.useRef)(a);ey.current=a,(0,s.useEffect)(()=>{if(null!==ey.current&&ey.current>0&&ep.length>0){let e=ey.current,t=e-1,n=ep.findIndex(e=>"code"===e.type&&e.lineIndex===t);if(n>=0){let t=()=>{eg.scrollToIndex(n,{align:o}),"center"===o&&(M.current&&clearTimeout(M.current),E(e),M.current=setTimeout(()=>E(null),500)),i?.()};"start"===o?requestAnimationFrame(t):setTimeout(t,150)}}},[a,o,ep.length,eg,i]);let ew=(0,s.useCallback)(e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?ev():eb()),"Escape"===e.key&&(T(!1),I(""))},[eb,ev]),ek=(0,s.useCallback)((e,t)=>{ee&&(t.stopPropagation(),H({comment:e,x:t.clientX,y:t.clientY}),er(),X(null),G(null))},[ee,er]);(0,s.useEffect)(()=>{if(!ee)return;let e=x.current,t=!1,n=()=>{t=!0,U.current=null,K.current=!0},r=()=>{t=!1;let e=window.getSelection();if(!e||e.isCollapsed||!e.toString().trim()){K.current=!1;return}let n=e.getRangeAt(0),r=x.current;if(!r||!r.contains(n.commonAncestorContainer))return;let s=n.startContainer,l=n.endContainer,a=(s.nodeType===Node.TEXT_NODE?s.parentElement:s)?.closest("[data-line]"),o=(l.nodeType===Node.TEXT_NODE?l.parentElement:l)?.closest("[data-line]");if(!a||!o)return;let i=parseInt(a.getAttribute("data-line")||"0",10),c=parseInt(o.getAttribute("data-line")||"0",10);i&&c&&(K.current=!0,U.current={startLine:i,startOffset:S(a,n.startContainer,n.startOffset),endLine:c,endOffset:S(o,n.endContainer,n.endOffset)})},s=()=>{if(t)return;let e=window.getSelection();e&&!e.isCollapsed&&e.toString().trim()||(U.current=null,K.current=!1)};return e?.addEventListener("mousedown",n),document.addEventListener("mouseup",r),document.addEventListener("selectionchange",s),()=>{e?.removeEventListener("mousedown",n),document.removeEventListener("mouseup",r),document.removeEventListener("selectionchange",s)}},[ee]),(0,s.useEffect)(()=>{let e=x.current;if(!e)return;let t=t=>{let n,r;if(!e.contains(t.target)){if(t.target.closest?.("[data-inline-blame-tip]"))return;null!==es.current&&(es.current=null,ea(e=>e+1));return}let s=window.getSelection();if(s&&!s.isCollapsed&&s.toString().trim())return;let l=(n=t.target,(r=n.closest?.("[data-line]"))?parseInt(r.getAttribute("data-line")||"0",10):null);l!==es.current&&(es.current=l,requestAnimationFrame(()=>ea(e=>e+1)))};return document.addEventListener("mouseup",t),()=>document.removeEventListener("mouseup",t)},[]);let ej=(0,s.useCallback)(()=>{let e=et.current;e&&(X({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),er())},[er,et]),eC=(0,s.useCallback)(()=>{let e=et.current;e&&(G({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),er())},[er,et]),eN=(0,s.useCallback)(()=>{let e=et.current;if(!e||!d)return;let t=e.selectedText.trim();er(),t&&d(t)},[d,er,et]),eS=(0,s.useCallback)(async e=>{q&&(await ei(q.range.start,q.range.end,e,q.selectedText),X(null))},[q,ei]),eL=(0,s.useCallback)(async(e,n)=>{if(b&&r)try{let s=await (0,j.$3)(r),l=[];for(let e of s)l.push({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0});l.push({filePath:t,startLine:e.range.start,endLine:e.range.end,codeContent:e.lineSnapshot});let a=(0,j.Gw)(l,n);b.sendMessage(a),await (0,j.RP)(r),eu()}catch(e){console.error("Failed to send to AI:",e)}},[b,t,r,eu]),eE=(0,s.useCallback)(e=>{Z&&eL(Z,e)},[Z,eL]),eM=(0,s.useCallback)(e=>{q&&eL(q,e)},[q,eL]),eR=(0,s.useCallback)((e,t,n)=>{let r=J[e];if(!r)return t;let s=[];if($&&ex.length>0)for(let t of ex.filter(t=>t.lineIndex===e)){let n=ex[F]?.lineIndex===e&&ex[F]?.startCol===t.startCol;s.push({start:t.startCol,end:t.endCol,cls:n?"hl-cur":"hl-m"})}if(n&&!$&&n.length>=1){let e=n.toLowerCase(),t=r.toLowerCase(),l=0;for(;-1!==(l=t.indexOf(e,l));)s.push({start:l,end:l+n.length,cls:"hl-kw"}),l+=1}if(0===s.length)return t;s.sort((e,t)=>e.start-t.start||e.end-t.end);let l=[],a=0;for(let e of s){if(e.start<a)continue;e.start>a&&l.push((0,h.ZD)(r.substring(a,e.start)));let t=(0,h.ZD)(r.substring(e.start,e.end));l.push(`<span class="${e.cls}">${t}</span>`),a=e.end}if(a<r.length&&l.push((0,h.ZD)(r.substring(a))),t!==(0,h.ZD)(r)){let e=t;for(let t of s){let n=r.substring(t.start,t.end),s=(0,h.ZD)(n),l=s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),a=RegExp(`(?<=>)([^<]*?)(${l})`,""),o=`$1<span class="${t.cls}">${s}</span>`,i=e.replace(a,o);i.length>e.length+200||(e=i)}return e}return l.join("")},[$,ex,F,J]);return{parentRef:x,containerRef:p,searchInputRef:g,floatingToolbarRef:et,suppressHoverRef:K,savedSelectionRef:U,highlightedLines:eh,isMounted:m,cmdHeld:v,flashLine:L,isSearchVisible:R,searchQuery:$,caseSensitive:P,wholeWord:_,currentMatchIndex:F,viewingComment:z,bumpToolbarRef:en,addCommentInput:q,sendToAIInput:Z,aiBridge:b,commentsEnabled:ee,comments:eo,updateComment:ec,deleteComment:ed,lines:J,matches:ex,rowData:ep,virtualizer:eg,commentsByEndLine:em,linesWithComments:ef,setIsSearchVisible:T,setSearchQuery:I,suppressMatchScrollRef:O,setCaseSensitive:A,setWholeWord:D,setViewingComment:H,setAddCommentInput:X,setSendToAIInput:G,goToNextMatch:eb,goToPrevMatch:ev,handleSearchKeyDown:ew,handleCommentBubbleClick:ek,handleToolbarAddComment:ej,handleToolbarSendToAI:eC,handleToolbarSearch:eN,handleCommentSubmit:eS,handleSendToAISubmit:eE,handleCommentSendToAI:eM,getHighlightedLineHtml:eR,inlineBlameLineRef:es,inlineBlameVersion:el}}({content:e,filePath:t,showSearch:x,cwd:g,enableComments:!U&&v,scrollToLine:U?null:P,scrollToLineAlign:U?"center":A,onScrollToLineComplete:U?void 0:_,visibleLineRef:U?void 0:F,onContentSearch:el}),tu=(0,c.iN)(),th=(0,s.useRef)(null),tm=(0,s.useRef)(null),tf=(0,s.useRef)({line:0,col:0}),tx=(0,s.useRef)({line:0,col:0}),tp=function({lines:e,enabled:t,onContentChange:n,onEnterInsert:r,onSave:l,getVisibleLineCount:a,scrollToLine:o,onSearchExecute:i,onSearchNext:c,onSearchPrev:d,onSearchClear:u}){let[h,m]=(0,s.useState)("normal"),[f,x]=(0,s.useState)(-1),[p,g]=(0,s.useState)(0),[b,v]=(0,s.useState)(!1),[y,w]=(0,s.useState)(""),[k,j]=(0,s.useState)(""),[C,N]=(0,s.useState)(""),[S,L]=(0,s.useState)(""),E=(0,s.useRef)([]),M=(0,s.useRef)([]),R=(0,s.useRef)([]),T=(0,s.useRef)(null),$=(0,s.useRef)(e);(0,s.useEffect)(()=>{$.current=e}),(0,s.useEffect)(()=>{0!==e.length&&queueMicrotask(()=>x(t=>Math.min(t,e.length-1)))},[e.length]);let I=(0,s.useCallback)((e,t)=>Math.max(0,Math.min(t,Math.max(0,($.current[e]??"").length-1))),[]),P=(0,s.useRef)(e.length);(0,s.useEffect)(()=>{let t=Math.abs(e.length-P.current);P.current=e.length,t>10&&(queueMicrotask(()=>{x(-1),g(0),v(!1)}),E.current=[],M.current=[],R.current=[])},[e]);let A=(0,s.useCallback)(()=>{T.current&&(clearTimeout(T.current),T.current=null),w("")},[]),_=(0,s.useCallback)(()=>{T.current&&clearTimeout(T.current),T.current=setTimeout(()=>{w(""),T.current=null},500)},[]),D=(0,s.useCallback)((e,t)=>{E.current.push(t),M.current=[],v(!0),n(e.join("\n"))},[n]),F=(0,s.useCallback)((e,t)=>{let n=Math.max(0,Math.min(e,$.current.length-1));x(n),g(I(n,t??0)),o(n,"auto")},[o,I]),W=(0,s.useCallback)(e=>{x(t=>{let n=Math.max(0,Math.min(t+e,$.current.length-1));return o(n,"auto"),g(e=>Math.max(0,Math.min(e,Math.max(0,($.current[n]??"").length-1)))),n})},[o]),B=(0,s.useCallback)(()=>{let e=$.current,t=Math.min(f,e.length-1);if(0===e.length)return;let n=e[t];R.current=[n];let r=[...e];r.splice(t,1),0===r.length&&r.push("");let s=Math.min(t,r.length-1);D(r,{lineIndex:t,oldLines:[n],newLines:[],cursorLine:t}),x(s),g(0)},[f,D]),V=(0,s.useCallback)(()=>{let e=$.current,t=Math.min(f,e.length-1);e.length>0&&(R.current=[e[t]])},[f]),O=(0,s.useCallback)(()=>{let e=R.current;if(0===e.length)return;let t=$.current,n=Math.min(f,t.length-1)+1,r=[...t];r.splice(n,0,...e),D(r,{lineIndex:n,oldLines:[],newLines:[...e],cursorLine:f}),x(n),g(0),o(n,"auto")},[f,D,o]),z=(0,s.useCallback)(()=>{let e=$.current,t=Math.min(f,e.length-1),n=e[t];if(!n||0===n.length)return;let r=n.substring(1),s=[...e];s[t]=r,D(s,{lineIndex:t,oldLines:[n],newLines:[r],cursorLine:f})},[f,D]),H=(0,s.useCallback)(()=>{let e=E.current;if(0===e.length)return;let t=e.pop(),r=[...$.current];0===t.newLines.length&&t.oldLines.length>0?r.splice(t.lineIndex,0,...t.oldLines):0===t.oldLines.length&&t.newLines.length>0?(r.splice(t.lineIndex,t.newLines.length),0===r.length&&r.push("")):r.splice(t.lineIndex,t.newLines.length,...t.oldLines),M.current.push(t),n(r.join("\n")),x(Math.min(t.cursorLine,r.length-1)),o(Math.min(t.cursorLine,r.length-1),"auto"),0===e.length&&v(!1)},[n,o]),K=(0,s.useCallback)(()=>{let e=M.current;if(0===e.length)return;let t=e.pop(),r=[...$.current];0===t.newLines.length&&t.oldLines.length>0?(r.splice(t.lineIndex,t.oldLines.length),0===r.length&&r.push("")):0===t.oldLines.length&&t.newLines.length>0?r.splice(t.lineIndex,0,...t.newLines):r.splice(t.lineIndex,t.oldLines.length,...t.newLines),E.current.push(t),v(!0),n(r.join("\n"));let s=t.lineIndex+Math.max(0,t.newLines.length-1);x(Math.min(s,r.length-1)),o(Math.min(s,r.length-1),"auto")},[n,o]),U=(0,s.useCallback)(e=>{let t=$.current,n=Math.min(f,t.length-1);if("o"===e||"O"===e){let r="o"===e?n+1:n,s=[...t];s.splice(r,0,""),D(s,{lineIndex:r,oldLines:[],newLines:[""],cursorLine:f}),n=r,x(r)}m("insert"),r(n,p,e)},[f,p,D,r]),q=(0,s.useCallback)(()=>{m("normal"),A()},[A]),X=(0,s.useCallback)(()=>{m("command"),j("")},[]),Z=(0,s.useCallback)(()=>{m("normal"),j("")},[]),G=(0,s.useCallback)(()=>{m("search"),N("")},[]),J=(0,s.useCallback)(()=>{m("normal"),N("")},[]),Y=(0,s.useCallback)(e=>{let t=e.trim();if("w"===t){l?.(),m("normal"),j("");return}if("q"===t){m("normal"),j("");return}if("wq"===t){l?.(),m("normal"),j("");return}if("noh"===t||"nohlsearch"===t){u?.(),m("normal"),j("");return}let n=parseInt(t,10);if(!isNaN(n)&&n>0){let e=Math.min(n-1,$.current.length-1);x(e),o(e,"center"),m("normal"),j("");return}m("normal"),j("")},[l,u,o]),Q=(0,s.useCallback)(e=>{if(!e){m("normal"),N("");return}L(e),i?.(e),m("normal"),N("")},[i]),ee=(0,s.useCallback)(e=>{if(!t)return!1;let n=e.ctrlKey&&"c"===e.key&&!e.metaKey&&!e.shiftKey;if("insert"===h)return("Escape"===e.key||!!n)&&(q(),!0);if("command"===h)return!e.isComposing&&("Escape"===e.key||n?Z():"Enter"===e.key?Y(k):"Backspace"===e.key?0===k.length?Z():j(e=>e.slice(0,-1)):1!==e.key.length||e.metaKey||e.ctrlKey||j(t=>t+e.key),!0);if("search"===h)return!e.isComposing&&("Escape"===e.key||n?J():"Enter"===e.key?Q(C):"Backspace"===e.key?0===C.length?J():N(e=>e.slice(0,-1)):1!==e.key.length||e.metaKey||e.ctrlKey||N(t=>t+e.key),!0);if(f<0&&(x(0),g(0)),e.metaKey)return!1;if(e.ctrlKey)return"d"===e.key?(W(Math.max(1,Math.floor(a()/2))),A(),!0):"u"===e.key?(W(-Math.max(1,Math.floor(a()/2))),A(),!0):"r"===e.key&&(K(),A(),!0);let r=e.key,s=y+r;if("g"===s)return w("g"),_(),!0;if("gg"===s)return F(0),A(),!0;if("d"===s)return w("d"),_(),!0;if("dd"===s)return B(),A(),!0;if("y"===s)return w("y"),_(),!0;if("yy"===s)return V(),A(),!0;if(y&&s!==r&&A(),"j"===r||"ArrowDown"===r)return W(1),!0;if("k"===r||"ArrowUp"===r)return W(-1),!0;if("h"===r||"ArrowLeft"===r)return g(e=>Math.max(0,e-1)),!0;if("l"===r||"ArrowRight"===r){let e=Math.max(0,($.current[f]??"").length-1);return g(t=>Math.min(e,t+1)),!0}if("0"===r)return g(0),!0;if("$"===r)return g(Math.max(0,($.current[f]??"").length-1)),!0;if("^"===r){let e=($.current[f]??"").search(/\S/);return g(e>=0?e:0),!0}return"G"===r?(F($.current.length-1),!0):"x"===r?(z(),!0):"p"===r?(O(),!0):"u"===r?(H(),!0):"i"===r||"a"===r||"I"===r||"A"===r||"o"===r||"O"===r?(U(r),!0):"/"===r?(G(),!0):"n"===r?(c?.(),!0):"N"===r?(d?.(),!0):":"===r?(X(),!0):"Escape"!==r&&1===r.length},[t,h,y,k,C,f,q,U,X,Z,G,J,Y,Q,W,F,a,B,V,O,z,H,K,A,_,c,d]);return{state:{mode:h,cursorLine:f,cursorCol:p,isDirty:b,keyBuffer:y,commandInput:k,searchInput:C,lastSearch:S},handleKeyDown:ee,enterNormal:q,enterInsert:U,setCursorLine:x,setCursorCol:g,setCommandInput:j,setSearchInput:N,setIsDirty:v,clearUndoHistory:(0,s.useCallback)(()=>{E.current=[],M.current=[]},[])}}({lines:eX,enabled:J&&!U,onContentChange:e=>{tf.current={line:tx.current.line,col:tx.current.col},Y?.(e)},onEnterInsert:(e,t,n)=>{let r=t;if("a"===n)r=t+1;else if("A"===n)r=(eX[e]??"").length;else if("I"===n){let t=(eX[e]??"").search(/\S/);r=t>=0?t:0}else("o"===n||"O"===n)&&(r=0);tf.current={line:e,col:r},Q?.(e)},onSave:ee,getVisibleLineCount:()=>{let e=eN.current;return e?Math.floor(e.clientHeight/20):20},scrollToLine:(e,t)=>{let n=eG.findIndex(t=>"code"===t.type&&t.lineIndex===e);n>=0&&eJ.scrollToIndex(n,{align:t||"auto"})},onSearchExecute:e=>{e1(e),e0(!1)},onSearchNext:e6,onSearchPrev:e9,onSearchClear:()=>{e1("")}});(0,s.useEffect)(()=>{et&&(et.current={cursorLine:tp.state.cursorLine,cursorCol:tp.state.cursorCol}),tx.current={line:tp.state.cursorLine,col:tp.state.cursorCol}},[et,tp.state.cursorLine,tp.state.cursorCol]);let tg=(0,s.useRef)(null);(0,s.useEffect)(()=>{J&&!U&&null!=en&&t&&tg.current!==t&&(tg.current=t,tp.setCursorLine(en-1),null!=er&&tp.setCursorCol(er-1),es?.())},[J,U,en,er,t]),(0,s.useEffect)(()=>{if(!J||U)return;let e=eS.current;if(!e)return;let t=e=>{let t=e.target;"TEXTAREA"===t.tagName||"INPUT"===t.tagName||t.isContentEditable||tp.handleKeyDown(e)&&(e.preventDefault(),e.stopPropagation())};return e.addEventListener("keydown",t,!0),()=>e.removeEventListener("keydown",t,!0)},[J,U,tp.handleKeyDown]),(0,s.useEffect)(()=>{if(!J||U)return;let e=eS.current;e&&"normal"===tp.state.mode&&requestAnimationFrame(()=>{let t=document.activeElement;t&&("TEXTAREA"===t.tagName||"INPUT"===t.tagName||t.isContentEditable)||e.focus()})},[J,U,tp.state.mode,e]);let tb=(0,s.useCallback)(e=>{if(!J||U)return;let t=e.target.closest("[data-line]");if(t){let n=parseInt(t.getAttribute("data-line"),10);if(!isNaN(n)){tp.setCursorLine(n-1);let r=t.querySelector("[data-code-content]");if(r){let t=document.caretRangeFromPoint(e.clientX,e.clientY);if(t&&r.contains(t.startContainer)){let e,s=document.createTreeWalker(r,NodeFilter.SHOW_TEXT),l=0;for(;e=s.nextNode();){if(e===t.startContainer){l+=t.startOffset;break}l+=e.textContent?.length||0}let a=eX[n-1]??"";tp.setCursorCol(Math.max(0,Math.min(l,Math.max(0,a.length-1))))}}}}let n=e.target;if("TEXTAREA"===n.tagName||"INPUT"===n.tagName||n.isContentEditable)return;let r=eS.current;r&&r.focus()},[J,U,tp.setCursorLine,tp.setCursorCol,eX]),tv=(0,s.useCallback)(e=>{J&&!U&&requestAnimationFrame(()=>{let e=window.getSelection(),t=e?.toString().trim();t&&/^\S+$/.test(t)&&(ti.current=!0,e1(t))})},[J,U,e1,ti]);(0,s.useEffect)(()=>{"command"===tp.state.mode?setTimeout(()=>th.current?.focus(),0):"search"===tp.state.mode&&setTimeout(()=>tm.current?.focus(),0)},[tp.state.mode]),(0,s.useEffect)(()=>{let e=eN.current;if(!e)return;let t=()=>{(O??V)?.()};return e.addEventListener("mousedown",t),()=>e.removeEventListener("mousedown",t)},[O,V]),(0,s.useEffect)(()=>{eO||ez?(eM.current=!0,V?.()):eE.current||(eM.current=!1)},[eO,ez,V]),(0,s.useLayoutEffect)(()=>{let e=eT.current;if(!e)return;let t=window.getSelection();if(t&&!t.isCollapsed)return;let n=eN.current;if(!n)return;let r=n.querySelector(`[data-line="${e.startLine}"]`),s=n.querySelector(`[data-line="${e.endLine}"]`);if(!r||!s)return;let l=L(r,e.startOffset),a=L(s,e.endOffset);if(l&&a)try{let e=document.createRange();e.setStart(l.node,l.offset),e.setEnd(a.node,a.offset),t?.removeAllRanges(),t?.addRange(e)}catch{}});let ty=(0,s.useCallback)((e,t,n)=>{eM.current||B?.(e,t,n)},[B]),tw=(0,s.useCallback)((e,t)=>{eM.current||W?.(e,t)},[W]),tk=Math.max(4,String(U?ef:eX.length).length),tj=(0,s.useMemo)(()=>{let e=0;for(let t of eX){let n=0;for(let e=0;e<t.length;e++)" "===t[e]?n+=2-n%2:n+=1;n>e&&(e=n)}return e},[eX]);(0,s.useEffect)(()=>{if(U){ei.current=e;let t=e.split("\n").length;ep.current=t,ex(t),ec.current=!1,eu(!1),eb({show:!1}),ew.current=q}},[U,e,q]),(0,s.useEffect)(()=>{if(!U)return;let t=ev.current;if(!t)return;let n=e.split("\n");t.innerHTML=I(n.map((e,t)=>e$[t]||(0,h.ZD)(e||" "))),requestAnimationFrame(()=>{let e,r;J?(e=Math.max(0,Math.min(tf.current.line,n.length-1)),r=tf.current.col):(e=Math.max(0,Math.min((F?.current??1)-1,n.length-1)),r=0),t.focus(),$(t,{line:e,offset:r});let s=F?.current??1;ey.current&&(ey.current.scrollTop=(s-1)*20)})},[U]),(0,s.useEffect)(()=>{U&&G?.({isDirty:ed,isSaving:eh})},[U,ed,eh,G]);let tC=(0,s.useCallback)(()=>{let e=ev.current;if(!e)return ei.current;let t=[];for(let n of e.childNodes){let e=n.textContent||"";t.push(" "===e?"":e)}return t.join("\n")},[]),tN=(0,s.useCallback)(()=>{ek.current&&clearTimeout(ek.current),ek.current=setTimeout(async()=>{let e=ev.current;if(e&&!eC.current){ei.current=tC();try{let n=await (0,h.kS)(),r=(0,h.sQ)(t),s=document.documentElement.classList.contains("dark"),l=ei.current.split("\n"),a=n.codeToTokens(l.join("\n"),{lang:r,theme:s?"github-dark":"github-light"}).tokens.map(e=>(0,h.b8)(e)),o=T(e);ej.current=!0,e.innerHTML=I(a),ej.current=!1,o&&$(e,o)}catch{}}},300)},[t,tC]);(0,s.useEffect)(()=>{if(U)return()=>{ek.current&&clearTimeout(ek.current)}},[U]);let tS=(0,s.useCallback)(()=>{let e=ev.current;if(!e)return;ec.current||(ec.current=!0,eu(!0));let t=e.children.length;t!==ep.current&&(ep.current=t,ex(t))},[]),tL=(0,s.useCallback)(()=>{ej.current||eC.current||(tS(),tN())},[tS,tN]),tE=(0,s.useCallback)(e=>{if(!e.nativeEvent.isComposing&&("Tab"===e.key&&(e.preventDefault(),document.execCommand("insertText",!1," ")),"Enter"===e.key)){e.preventDefault();let t=ev.current;if(!t)return;let n=window.getSelection();if(!n?.rangeCount)return;let r=n.getRangeAt(0);r.deleteContents();let s=r.startContainer;for(;s&&s.parentElement!==t;)s=s.parentElement;if(!s||!(s instanceof HTMLElement))return;let l=T(t),a=Array.from(t.children).indexOf(s),o=s.textContent||"",i=l?.offset??o.length,c=o.substring(0,i),d=o.substring(i);s.innerHTML=(0,h.ZD)(c||" ");let u=document.createElement("div");u.setAttribute("style",R),u.innerHTML=(0,h.ZD)(d||" "),s.after(u),$(t,{line:a+1,offset:0}),tS(),tN()}},[tS,tN]),tM=(0,s.useCallback)(e=>{e.preventDefault();let t=e.clipboardData.getData("text/plain");document.execCommand("insertText",!1,t)},[]),tR=(0,s.useCallback)(async(e=!1)=>{if(!g)return;ei.current=tC(),em(!0);let n=await o.t4.runPromiseExit((0,i.OJ)({cwd:g,path:t,content:ei.current,expectedMtime:e?void 0:ew.current}));if("Failure"===n._tag){console.error("Error saving file:",n.cause),(0,M.oR)(eo("toast.saveFailed"),"error"),em(!1);return}let r=n.value,s=r.data;if(409===r.status&&s?.conflict){let e=await o.t4.runPromiseExit((0,i.K9)(g,t));"Success"===e._tag&&e.value.ok&&"string"==typeof e.value.data?.content?eb({show:!0,diskContent:e.value.data.content}):eb({show:!0}),em(!1);return}if(!r.ok){console.error("Error saving file: status",r.status),(0,M.oR)(eo("toast.saveFailed"),"error"),em(!1);return}let l=s?.mtime;l&&(ew.current=l),ec.current=!1,eu(!1),eb({show:!1}),(0,M.oR)(eo("toast.savedSuccess"),"success"),Z?.(),em(!1)},[g,t,tC,Z,eo]),tT=(0,s.useCallback)(async()=>{ed&&!eh&&await tR(!1)},[ed,eh,tR]),t$=(0,s.useCallback)(async()=>{eb({show:!1}),await tR(!0)},[tR]),tI=(0,s.useCallback)(()=>{if(void 0!==eg.diskContent){ei.current=eg.diskContent;let t=eg.diskContent.split("\n").length;ep.current=t,ex(t);let n=eg.diskContent!==e;ec.current=n,eu(n);let r=ev.current;r&&(r.innerHTML=I(eg.diskContent.split("\n").map(e=>(0,h.ZD)(e||" "))),tN())}eb({show:!1}),Z?.()},[eg.diskContent,e,Z,tN]),tP=(0,s.useCallback)(()=>{let e=ey.current;return e?Math.floor(e.scrollTop/20)+1:F?.current??1},[F]),tA=(0,s.useCallback)(async()=>{(!ed||await (0,M.lJ)(eo("codeViewer.unsavedConfirm"),{danger:!0,confirmText:eo("codeViewer.discardChanges"),cancelText:eo("codeViewer.continueEditing")}))&&X?.(tP())},[ed,X,tP]);(0,s.useEffect)(()=>{if(!U)return;let e=e=>{(e.metaKey||e.ctrlKey)&&"s"===e.key&&(e.preventDefault(),tT())};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[U,tT]);let t_=(0,s.useCallback)(()=>{let e=tC();Y?.(e);let t=ev.current,n=t?T(t):null,r=tP();if(tp.enterNormal(),n){tp.setCursorLine(n.line);let t=e.split("\n")[n.line]??"";tp.setCursorCol(Math.max(0,Math.min(n.offset,Math.max(0,t.length-1))))}else tp.setCursorLine(Math.max(0,r-1));X?.(r)},[tC,Y,tP,X,tp]);(0,s.useEffect)(()=>{if(!U)return;let e=e=>{let t="Escape"===e.key,n=e.ctrlKey&&"c"===e.key&&!e.metaKey&&!e.shiftKey;(t||J&&n)&&(e.preventDefault(),e.stopPropagation(),J?ec.current?(0,M.lJ)(eo("codeViewer.unsavedExitConfirm"),{danger:!0,confirmText:eo("codeViewer.discardChanges"),cancelText:eo("codeViewer.continueEditing")}).then(e=>{e&&t_()}):t_():tA())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[U,J,tA,t_]);let tD=(0,s.useCallback)(()=>{ec.current||(ec.current=!0,eu(!0))},[]);(0,s.useImperativeHandle)(ea,()=>({save:tT,close:tA,markDirty:tD,get isDirty(){return ec.current},get isSaving(){return eh}}),[tT,tA,tD,eh]);let tF=!!(z&&z.length>0),tW=(0,s.useMemo)(()=>{if(!z)return new Map;let e=[...new Set(z.map(e=>e.author))],t=new Map;return e.forEach((e,n)=>{t.set(e,b[n%b.length])}),t},[z]),[tB,tV]=(0,s.useState)(null),[tO,tz]=(0,s.useState)(null);(0,s.useEffect)(()=>{tV(null),tz(null)},[z]);let tH=(0,s.useCallback)((e,t)=>{tV(e.author);let n=t.currentTarget.getBoundingClientRect();tz({line:e,x:n.right+8,y:n.top})},[]),tK=(0,s.useCallback)(()=>{tV(null),tz(null)},[]),tU=(0,s.useCallback)(e=>{K&&(K({hash:e.hashFull,shortHash:e.hash,author:e.author,authorEmail:e.authorEmail,date:new Date(1e3*e.time).toISOString(),subject:e.message.split("\n")[0]||"",body:e.message.split("\n").slice(1).join("\n").trim(),time:e.time}),tz(null))},[K]),tq=`${tk+2}ch`;return(0,r.jsxs)("div",{ref:eS,className:`h-full flex flex-col outline-none ${p}`,tabIndex:0,onClick:tb,onDoubleClick:tv,children:[U&&eg.show&&(0,r.jsxs)("div",{className:"px-4 py-2 bg-amber-500/15 border-b border-amber-500/30 flex items-center gap-3 flex-shrink-0",children:[(0,r.jsx)("svg",{className:"w-5 h-5 text-amber-500 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L4.082 16.5c-.77.833.192 2.5 1.732 2.5z"})}),(0,r.jsx)("span",{className:"text-sm text-foreground flex-1",children:eo("codeViewer.fileModifiedExternally")}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("button",{onClick:tI,className:"px-3 py-1 text-sm rounded border border-border hover:bg-accent transition-colors",children:eo("codeViewer.useDiskVersion")}),(0,r.jsx)("button",{onClick:t$,className:"px-3 py-1 text-sm rounded bg-amber-500 text-white hover:bg-amber-600 transition-colors",children:eo("codeViewer.forceOverwrite")})]})]}),!U&&x&&e_&&(0,r.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-2 px-3 py-2 bg-secondary border-b border-border",children:[(0,r.jsx)("input",{ref:eL,type:"text",value:eD,onChange:e=>e1(e.target.value),onKeyDown:e7,placeholder:eo("codeViewer.searchPlaceholder"),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,r.jsx)("button",{onClick:()=>e2(!eF),className:`px-2 py-1 text-xs font-mono rounded border transition-colors ${eF?"bg-brand text-white border-brand":"border-border text-muted-foreground hover:bg-accent"}`,title:eo("codeViewer.caseSensitive"),children:"Aa"}),(0,r.jsx)("button",{onClick:()=>e5(!eW),className:`px-2 py-1 text-xs font-mono rounded border transition-colors ${eW?"bg-brand text-white border-brand":"border-border text-muted-foreground hover:bg-accent"}`,title:eo("codeViewer.wholeWordMatch"),children:"[ab]"}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:eZ.length>0?`${eB+1}/${eZ.length}`:eo("common.noMatch")}),(0,r.jsx)("button",{onClick:e9,disabled:0===eZ.length,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:eo("common.previous"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"})})}),(0,r.jsx)("button",{onClick:e6,disabled:0===eZ.length,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:eo("common.next"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})}),(0,r.jsx)("button",{onClick:()=>{e0(!1),e1("")},className:"p-1 rounded hover:bg-accent",title:eo("common.close"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),U?(0,r.jsx)("div",{ref:ey,className:"flex-1 overflow-auto bg-secondary",children:(0,r.jsxs)("div",{className:"flex",style:{minHeight:"100%"},children:[(0,r.jsx)("div",{className:"flex-shrink-0 font-mono text-sm select-none sticky left-0 z-[2] bg-secondary",style:{width:tq},children:Array.from({length:ef},(e,t)=>(0,r.jsx)("div",{className:"text-right text-muted-foreground/50 pr-3",style:{height:20,lineHeight:"20px"},children:t+1},t))}),(0,r.jsx)("div",{ref:ev,contentEditable:!0,suppressContentEditableWarning:!0,onInput:tL,onKeyDown:tE,onPaste:tM,onCompositionStart:()=>{eC.current=!0},onCompositionEnd:()=>{eC.current=!1,tL()},spellCheck:!1,autoCorrect:"off",autoCapitalize:"off",className:"flex-1 font-mono text-sm outline-none",style:{caretColor:"var(--foreground)",tabSize:2}})]})}):(0,r.jsx)("div",{ref:eN,className:`flex-1 overflow-auto font-mono text-sm bg-secondary${eP?" cmd-held-container":""}`,children:(0,r.jsx)("div",{style:{height:`${eJ.getTotalSize()}px`,minWidth:"100%",width:tF?`calc(${tk+tj+10}ch + 13rem)`:`${tk+tj+10}ch`,position:"relative"},children:eJ.getVirtualItems().map(e=>{let t=eG[e.index];if("code"!==t.type)return null;let s=t.lineIndex,l=s+1,a=e$[s]||(0,h.ZD)(eX[s]||""),o=to(s,a,D),i=eQ.has(l),c=eY.get(l),d=c?.[0],u=!!(eO&&l>=eO.range.start&&l<=eO.range.end),m=td>=0?tc.current:null,f=!U&&H&&m===l?H[s]??null:null,x=tF?z[s]:void 0,p=tF&&s>0?z[s-1]:void 0,g=!!x&&(!p||p.hash!==x.hash),b=x?tW.get(x.author):void 0;return(0,r.jsx)(y,{virtualKey:e.key,lineNum:l,highlightedHtml:o,hasComments:i,firstComment:d,lineCommentsCount:c?.length,isInRange:u,showLineNumbers:n,lineNumChars:tk,commentsEnabled:eK,virtualItemSize:e.size,virtualItemStart:e.start,onCommentBubbleClick:te,onCmdClick:tw,onTokenHover:ty,onTokenHoverLeave:V,flashLine:eA,blameLine:x,showBlameInfo:g,blameAuthorColor:b,isBlameHovered:!!(x&&tB===x.author),onBlameClick:tU,onBlameMouseEnter:tH,onBlameMouseLeave:tK,inlineBlameData:f,onInlineBlameClick:tU,isCursorLine:J&&!U&&tp.state.cursorLine===s,cursorCol:J&&!U&&tp.state.cursorLine===s?tp.state.cursorCol:void 0},e.key)})})}),J&&(0,r.jsxs)("div",{className:"vi-status-bar flex-shrink-0 h-6 bg-card border-t border-border flex items-center px-3 text-xs font-mono select-none",children:["normal"===tp.state.mode&&(0,r.jsx)("span",{className:"text-green-11 font-medium",children:"NORMAL"}),"insert"===tp.state.mode&&(0,r.jsx)("span",{className:"text-blue-11 font-medium",children:"INSERT"}),"command"===tp.state.mode&&(0,r.jsxs)("div",{className:"flex items-center flex-1",children:[(0,r.jsx)("span",{className:"text-foreground",children:":"}),(0,r.jsx)("input",{ref:th,value:tp.state.commandInput,onChange:e=>tp.setCommandInput(e.target.value),onKeyDown:e=>{if(e.nativeEvent.isComposing)return;let t=e.ctrlKey&&"c"===e.key&&!e.metaKey&&!e.shiftKey;("Enter"===e.key||"Escape"===e.key||t)&&(e.preventDefault(),e.stopPropagation(),tp.handleKeyDown(e.nativeEvent))},className:"flex-1 bg-transparent outline-none text-foreground ml-0.5",spellCheck:!1,autoComplete:"off"})]}),"search"===tp.state.mode&&(0,r.jsxs)("div",{className:"flex items-center flex-1",children:[(0,r.jsx)("span",{className:"text-foreground",children:"/"}),(0,r.jsx)("input",{ref:tm,value:tp.state.searchInput,onChange:e=>tp.setSearchInput(e.target.value),onKeyDown:e=>{if(e.nativeEvent.isComposing)return;let t=e.ctrlKey&&"c"===e.key&&!e.metaKey&&!e.shiftKey;("Enter"===e.key||"Escape"===e.key||t)&&(e.preventDefault(),e.stopPropagation(),tp.handleKeyDown(e.nativeEvent))},className:"flex-1 bg-transparent outline-none text-foreground ml-0.5",spellCheck:!1,autoComplete:"off"})]}),tp.state.keyBuffer&&"normal"===tp.state.mode&&(0,r.jsx)("span",{className:"ml-2 text-muted-foreground",children:tp.state.keyBuffer}),tp.state.isDirty&&("normal"===tp.state.mode||"command"===tp.state.mode)&&(0,r.jsx)("span",{className:"ml-2 text-amber-11",children:"[+]"}),(0,r.jsxs)("span",{className:"ml-auto text-muted-foreground",children:[tp.state.cursorLine+1,":",tp.state.cursorCol+1]})]}),eI&&tu&&(0,a.createPortal)((0,r.jsxs)(r.Fragment,{children:[!U&&(0,r.jsx)(m.f,{floatingToolbarRef:eE,bumpRef:eR,container:tu,onAddComment:tt,onSendToAI:tn,onSearch:el?tr:void 0,isChatLoading:eH?.isLoading}),!U&&eO&&(0,r.jsx)(d.t,{x:eO.x,y:eO.y,range:eO.range,filePath:t,lineSnapshot:eO.lineSnapshot,container:tu,onSubmit:ts,onSendToAI:eH?ta:void 0,onClose:()=>e3(null),isChatLoading:eH?.isLoading}),!U&&ez&&(0,r.jsx)(d.G,{x:ez.x,y:ez.y,range:ez.range,filePath:t,lineSnapshot:ez.lineSnapshot,container:tu,onSubmit:tl,onClose:()=>e8(null),isChatLoading:eH?.isLoading}),!U&&eV&&(0,r.jsx)(f.t,{x:eV.x,y:eV.y,comment:eV.comment,container:tu,onClose:()=>e4(null),onUpdateComment:eU,onDeleteComment:eq}),tO&&(0,r.jsxs)("div",{className:"fixed z-50 bg-card border border-border rounded-lg shadow-lg p-3 max-w-lg",style:{left:Math.min(tO.x,window.innerWidth-450),top:Math.max(8,Math.min(tO.y,window.innerHeight-200))},children:[(0,r.jsxs)("div",{className:"flex items-start gap-3",children:[(0,r.jsx)("div",{className:"px-2 py-0.5 rounded text-xs font-mono font-medium text-white flex-shrink-0",style:{backgroundColor:tW.get(tO.line.author)?.border||"#666"},children:tO.line.hash}),(0,r.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,r.jsx)("div",{className:"text-sm font-medium text-foreground",children:tO.line.author}),(0,r.jsx)("div",{className:"text-xs text-muted-foreground",children:tO.line.authorEmail})]})]}),(0,r.jsx)("div",{className:"mt-2 text-sm text-foreground whitespace-pre-wrap max-h-48 overflow-y-auto",children:tO.line.message}),(0,r.jsxs)("div",{className:"mt-2 text-xs text-muted-foreground border-t border-border pt-2",children:[(0,E.fw)(tO.line.time)," \xb7 ",new Date(1e3*tO.line.time).toLocaleString(),(0,r.jsx)("span",{className:"ml-2 text-brand",children:eo("codeViewer.clickToViewDetails")})]})]})]}),tu)]})});function A({content:e,filePath:t,className:n=""}){let l=(0,s.useMemo)(()=>e.split("\n"),[e]),a=(0,u.C)(l,t),o=Math.max(4,String(l.length).length);return(0,r.jsx)("pre",{className:`overflow-auto text-sm font-mono bg-secondary p-2 ${n}`,children:l.map((e,t)=>(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"text-slate-9 select-none pr-4 text-right",style:{minWidth:`${o+2}ch`},children:t+1}),(0,r.jsx)("span",{className:"flex-1",dangerouslySetInnerHTML:{__html:a[t]||(0,h.ZD)(e||" ")}})]},t))})}},46456:(e,t,n)=>{n.d(t,{$:()=>i,BC:()=>c,Tu:()=>u,lb:()=>o,tj:()=>h,vv:()=>d});var r=n(49433),s=n(82680);let l=(e,t)=>r.tryPromise({try:async()=>{let n=await fetch(e,t);if(!n.ok)throw Error(`HTTP ${n.status}`);return await n.json()},catch:n=>new s.uV({message:`${t?.method??"GET"} ${e} failed`,cause:n})}),a=(e,t)=>r.tryPromise({try:async()=>{let n=await fetch(e,t);if(!n.ok)throw Error(`HTTP ${n.status}`)},catch:n=>new s.uV({message:`${t.method} ${e} failed`,cause:n})}),o=(e,t)=>l(`/api/comments?cwd=${encodeURIComponent(e)}${t?`&filePath=${encodeURIComponent(t)}`:""}`),i=e=>l(`/api/comments?cwd=${encodeURIComponent(e)}&all=true`),c=e=>l("/api/comments",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),d=(e,t,n)=>l("/api/comments",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,id:t,content:n})}),u=(e,t)=>a(`/api/comments?cwd=${encodeURIComponent(e)}&id=${encodeURIComponent(t)}`,{method:"DELETE"}),h=e=>a(`/api/comments?cwd=${encodeURIComponent(e)}&all=true`,{method:"DELETE"})},47215:(e,t,n)=>{n.d(t,{C6:()=>a,Hz:()=>b,WU:()=>v,aR:()=>g,cG:()=>i,e$:()=>p,jU:()=>l,oK:()=>y,u:()=>x,xb:()=>c,zs:()=>m});var r=n(12115),s=n(69809);function l(e){try{return JSON.parse(e),!0}catch{return!1}}function a(e){try{let t=JSON.parse(e);return JSON.stringify(t,null,2)}catch{return e}}let o={key:"#79c0ff",str:"#a5d6ff",num:"#79c0ff",bool:"#ff7b72",punct:"#8b949e",fold:"#6e7681"},i={key:"hsl(var(--blue-11))",str:"hsl(var(--green-11))",num:"hsl(var(--violet-11))",bool:"hsl(var(--red-11))",punct:"hsl(var(--slate-11))",fold:"hsl(var(--slate-11))"};function c(e,t=o){try{let n=JSON.parse(e);return h(n,0,t)}catch{return e}}let d=(e,t)=>r.createElement("span",{style:{color:e}},t);function u({label:e,labelColor:t,value:n,indent:l,colors:a}){let[o,i]=r.useState(!1),[c,m]=r.useState({x:0,y:0}),f="string"==typeof n&&n.replace(/\\n/g,"\n").split("\n").length>3,x={onMouseDown:e=>{m({x:e.clientX,y:e.clientY})},onClick:e=>{let t=e.clientX-c.x,n=e.clientY-c.y;t*t+n*n>25||(e.stopPropagation(),i(e=>!e))},style:{cursor:"pointer"}};if(f&&o&&"string"==typeof n){let l=n.replace(/\\n/g,"\n").split("\n")[0],o=n.replace(/\\n/g,"\n").split("\n").length;return r.createElement("span",x,d(t,e),d(a.punct,": "),d(a.str,l),d(a.fold,` ${s.A.t("toolCall.foldedLines",{count:o})}`))}let p=r.createElement(r.Fragment,null,d(t,e),d(a.punct,": "),h(n,l,a));return f?r.createElement("span",x,p):p}function h(e,t,n){let s=" ".repeat(t);if(null===e)return d(n.bool,"null");if(void 0===e)return d(n.bool,"undefined");if("string"==typeof e){let t=e.replace(/\\n/g,"\n").replace(/\n/g,"\n"+s);return d(n.str,t)}if("number"==typeof e)return d(n.num,String(e));if("boolean"==typeof e)return d(n.bool,String(e));if(Array.isArray(e))return 0===e.length?d(n.punct,"[]"):r.createElement(r.Fragment,null,d(n.punct,"["),"\n",...e.map((l,a)=>r.createElement("span",{key:a},s+" ",r.createElement(u,{label:`[${a}]`,labelColor:n.key,value:l,indent:t+1,colors:n}),a<e.length-1?r.createElement(r.Fragment,null,d(n.punct,","),"\n"):"\n")),s,d(n.punct,"]"));if("object"==typeof e){let l=Object.entries(e);return 0===l.length?d(n.punct,"{}"):r.createElement(r.Fragment,null,d(n.punct,"{"),"\n",...l.map(([e,a],o)=>r.createElement("span",{key:e},s+" ",r.createElement(u,{label:e,labelColor:n.key,value:a,indent:t+1,colors:n}),o<l.length-1?r.createElement(r.Fragment,null,d(n.punct,","),"\n"):"\n")),s,d(n.punct,"}"))}return String(e)}function m(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}let f=new Set([".png",".jpg",".jpeg",".gif",".webp",".svg",".bmp",".ico",".avif"]);function x(e){let t=e.slice(e.lastIndexOf(".")).toLowerCase();return f.has(t)}function p(e){return e.toLowerCase().endsWith(".md")}function g(e){let t=e.toLowerCase();return t.endsWith(".html")||t.endsWith(".htm")}function b(e){return e.toLowerCase().endsWith(".json")}function v(e,t){let n=t.startsWith("/")?[]:e.split("/").slice(0,-1);for(let e of t.replace(/^\//,"").split("/"))""!==e&&"."!==e&&(".."===e?n.pop():n.push(e));return n.join("/")}function y(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}},48347:(e,t,n)=>{n.d(t,{H:()=>a,r:()=>o});var r=n(95155),s=n(12115);let l=(0,s.createContext)(null);function a({value:e,children:t}){return(0,r.jsx)(l.Provider,{value:e,children:t})}function o(){return(0,s.useContext)(l)}},48948:(e,t,n)=>{n.d(t,{F:()=>r});function r(e,t,n){let{engine:r,assistantId:s}=n;if("stream_event"===t.type){let n=t.event;if(n?.type==="content_block_delta"&&n.delta?.type==="text_delta"&&n.delta.text){let t=n.delta.text;return e.map(e=>e.id===s?{...e,content:(e.content||"")+t}:e)}return e}if("assistant"===t.type){let n=t.message?.content;if(!Array.isArray(n))return e;let l=e,a=t.message?.model==="<synthetic>";if("codex"===r||"kimi"===r||"ollama"===r||a){let e=n.filter(e=>"text"===e.type&&e.text).map(e=>e.text).join("");e&&(l=l.map(t=>t.id===s?{...t,content:(t.content||"")+e}:t))}for(let e of n)if(e.name){let t={id:e.id||`tool-${s}-${e.name}`,name:e.name,input:e.input||{},isLoading:!0};l=l.map(e=>e.id!==s||e.toolCalls?.some(e=>e.id===t.id)?e:{...e,toolCalls:[...e.toolCalls||[],t]})}return l}if("user"===t.type){let n=t.message?.content;if(!Array.isArray(n))return e;let r=e;for(let e of n)if(e.tool_use_id){let t=e.tool_use_id,n="string"==typeof e.content?e.content:JSON.stringify(e.content);r=r.map(e=>e.id===s?{...e,toolCalls:e.toolCalls?.map(e=>e.id===t?{...e,result:n,isLoading:!1}:e)}:e)}return r}if("error"===t.type){let n=t.error||"An error occurred. Please try again.";return e.map(e=>e.id===s?{...e,content:e.content?`${e.content}
|
|
9
|
+
|
|
10
|
+
⚠️ ${n}`:`⚠️ ${n}`,isStreaming:!1}:e)}if("result"===t.type){let n="string"==typeof t.result?t.result.trim():"";return e.map(e=>e.id===s?{...e,content:!e.content&&n?n:e.content,isStreaming:!1,toolCalls:e.toolCalls?.map(e=>({...e,isLoading:!1}))}:e)}return e}},50860:(e,t,n)=>{n.d(t,{I:()=>o});var r=n(95155),s=n(12115),l=n(86957),a=n(60938);function o(e){let{refreshKey:t,className:n="h-full flex items-center justify-center p-4 bg-secondary",imgClassName:o="max-w-full max-h-full object-contain",alt:i}=e,c="absPath"in e&&"string"==typeof e.absPath,d=c?void 0:e.cwd,u=c?void 0:e.path,h=c?e.absPath:void 0,[m,f]=(0,s.useState)({kind:"loading"}),x=(0,s.useRef)(0);if((0,s.useEffect)(()=>{let e=++x.current;return f({kind:"loading"}),(async()=>{if(c){if(e!==x.current)return;f({kind:"ready",etag:null,size:0});return}let t=await l.t4.runPromiseExit((0,a.r6)(d,u));if(e!==x.current)return;if("Failure"===t._tag){let e="Fail"===t.cause._tag?t.cause.error:null,n=e?.cause;f({kind:"error",message:n instanceof Error?n.message:"Unknown error"});return}let n=t.value;if(!n.ok)return f({kind:"error",message:`stat failed (${n.status})`});let r=n.data;r&&r.exists?"too-large"===r.category?f({kind:"too-large",size:r.size??0}):"image"!==r.category?f({kind:"error",message:`Not an image (${r.category})`}):f({kind:"ready",etag:r.etag||`t-${r.mtimeMs??Date.now()}`,size:r.size??0}):f({kind:"missing"})})(),()=>{x.current++}},[c,d,u,h,t]),"loading"===m.kind)return(0,r.jsx)("div",{className:n,children:(0,r.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})});if("missing"===m.kind)return(0,r.jsx)("div",{className:n,children:(0,r.jsx)("div",{className:"text-sm text-muted-foreground",children:"File not found"})});if("too-large"===m.kind)return(0,r.jsx)("div",{className:n,children:(0,r.jsxs)("div",{className:"text-sm text-muted-foreground",children:["Image too large to preview (",Math.round(m.size/1024/1024)," MB)"]})});if("error"===m.kind)return(0,r.jsx)("div",{className:n,children:(0,r.jsx)("div",{className:"text-sm text-red-11",children:m.message})});let p=c?`/api/file?path=${encodeURIComponent(h)}&raw=true`:`/api/files/read?cwd=${encodeURIComponent(d)}&path=${encodeURIComponent(u)}&v=${encodeURIComponent(m.etag)}`;return(0,r.jsx)("div",{className:n,children:(0,r.jsx)("img",{src:p,alt:i??(u||h),className:o})})}},56045:(e,t,n)=>{n.d(t,{_:()=>o,o:()=>a});var r=n(12115),s=n(69809);let l="json-search-highlight-style";function a(e){let[t,n]=(0,r.useState)(!1),[s,a]=(0,r.useState)(""),[o,i]=(0,r.useState)(!1),[c,d]=(0,r.useState)(0),[u,h]=(0,r.useState)(0),m=(0,r.useRef)(null),f=(0,r.useRef)([]),x=(0,r.useCallback)(()=>{let t;CSS.highlights?.delete("json-search"),CSS.highlights?.delete("json-search-current"),f.current=[];let n=e.current;if(!n||!s){d(0),h(0);return}!function(){if(document.getElementById(l))return;let e=document.createElement("style");e.id=l,e.textContent="::highlight(json-search){background:rgba(217,119,6,.3)}::highlight(json-search-current){background:rgba(217,119,6,.5)}",document.head.appendChild(e)}();let r=n.textContent||"",a=o?s:s.toLowerCase(),i=o?r:r.toLowerCase(),c=[],u=0;for(;u<i.length;){let e=i.indexOf(a,u);if(-1===e)break;c.push([e,e+a.length]),u=e+1}if(0===c.length){d(0),h(0);return}let m=document.createTreeWalker(n,NodeFilter.SHOW_TEXT),x=0,p=0,g=[],b=null,v=0;for(;(t=m.nextNode())&&p<c.length;){let e=t.textContent?.length||0,n=x,r=x+e;for(;p<c.length;){let[e,s]=c[p];if(e>=r)break;if(!b)if(e>=n)(b=document.createRange()).setStart(t,e-n),v=s;else break;if(v<=r)b.setEnd(t,v-n),g.push(b),b=null,p++;else break}x=r}f.current=g,d(g.length),h(e=>g.length>0?Math.min(e,g.length-1):0),CSS.highlights&&g.length>0&&CSS.highlights.set("json-search",new Highlight(...g))},[e,s,o]),p=(0,r.useCallback)((e,t)=>{let n=e.getBoundingClientRect();(t.top<n.top||t.bottom>n.bottom)&&(e.scrollTop+=t.top-n.top-n.height/2+t.height/2)},[]),g=(0,r.useCallback)(t=>{CSS.highlights?.delete("json-search-current");let n=f.current[t];if(!n||!CSS.highlights)return;CSS.highlights.set("json-search-current",new Highlight(n));let r=n.getBoundingClientRect(),s=e.current?.parentElement;s&&p(s,r)},[e,p]);(0,r.useEffect)(()=>{queueMicrotask(()=>x())},[x]),(0,r.useEffect)(()=>{g(u)},[u,c,g]),(0,r.useEffect)(()=>{let t=e.current;if(!t||!s)return;let n=new MutationObserver(()=>x());return n.observe(t,{childList:!0,subtree:!0,characterData:!0}),()=>n.disconnect()},[e,s,x]),(0,r.useEffect)(()=>{t||(CSS.highlights?.delete("json-search"),CSS.highlights?.delete("json-search-current"),f.current=[])},[t]),(0,r.useEffect)(()=>()=>{CSS.highlights?.delete("json-search"),CSS.highlights?.delete("json-search-current")},[]);let b=(0,r.useCallback)(()=>{0!==c&&h(e=>(e+1)%c)},[c]),v=(0,r.useCallback)(()=>{0!==c&&h(e=>(e-1+c)%c)},[c]),y=(0,r.useCallback)(()=>{n(!0),setTimeout(()=>m.current?.focus(),0)},[]),w=(0,r.useCallback)(()=>{n(!1),a(""),h(0)},[]),k=(0,r.useCallback)(e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?v():b()),"Escape"===e.key&&(e.preventDefault(),w())},[b,v,w]);return{isVisible:t,query:s,setQuery:a,caseSensitive:o,setCaseSensitive:i,matchCount:c,currentIndex:u,searchInputRef:m,open:y,close:w,goToNext:b,goToPrev:v,handleKeyDown:k}}function o({search:e}){return e.isVisible?r.createElement("div",{className:"flex-shrink-0 flex items-center gap-2 px-3 py-2 bg-secondary border-b border-border"},r.createElement("input",{ref:e.searchInputRef,type:"text",value:e.query,onChange:t=>e.setQuery(t.target.value),onKeyDown:e.handleKeyDown,placeholder:s.A.t("codeViewer.searchPlaceholder"),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"}),r.createElement("button",{onClick:()=>e.setCaseSensitive(e=>!e),className:`px-2 py-1 text-xs font-mono rounded border transition-colors ${e.caseSensitive?"bg-brand text-white border-brand":"border-border text-muted-foreground hover:bg-accent"}`,title:s.A.t("codeViewer.caseSensitive")},"Aa"),r.createElement("span",{className:"text-xs text-muted-foreground"},e.matchCount>0?`${e.currentIndex+1}/${e.matchCount}`:s.A.t("common.noMatch")),r.createElement("button",{onClick:e.goToPrev,disabled:0===e.matchCount,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:s.A.t("common.previous")},r.createElement("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},r.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"}))),r.createElement("button",{onClick:e.goToNext,disabled:0===e.matchCount,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:s.A.t("common.next")},r.createElement("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},r.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"}))),r.createElement("button",{onClick:e.close,className:"p-1 rounded hover:bg-accent",title:s.A.t("common.close")},r.createElement("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},r.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})))):null}},56978:(e,t,n)=>{n.d(t,{C:()=>l});var r=n(12115),s=n(17196);function l(e,t){let[n,l]=(0,r.useState)(null),[a,o]=(0,r.useState)(!1);(0,r.useEffect)(()=>{let e=()=>{o(document.documentElement.classList.contains("dark"))};e();let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>t.disconnect()},[]);let i=(0,r.useMemo)(()=>e.join("\n"),[e]),c=`${i}:${t}:${a}`,d=(0,r.useMemo)(()=>n&&n.key===c?n.html:e.map(e=>(0,s.ZD)(e||" ")),[e,c,n]);return(0,r.useEffect)(()=>{if(0===e.length)return;let n=!1;return(async()=>{try{let r=await (0,s.kS)();if(n)return;let o=(0,s.sQ)(t),i=e.join("\n"),d=r.codeToTokens(i,{lang:o,theme:a?"github-dark":"github-light"}),u=[];for(let e=0;e<d.tokens.length;e++)if(u[e]=(0,s.b8)(d.tokens[e]),e%500==0&&e>0&&(await new Promise(e=>setTimeout(e,0)),n))return;l({key:c,html:u})}catch(e){console.error("Line highlight error:",e)}})(),()=>{n=!0}},[i,t,a]),d}},60938:(e,t,n)=>{n.d(t,{DZ:()=>c,Ft:()=>m,K9:()=>p,Nn:()=>w,OJ:()=>b,VK:()=>k,YW:()=>h,__:()=>y,dt:()=>v,eA:()=>g,eE:()=>f,gZ:()=>d,mP:()=>i,nM:()=>j,r6:()=>x,r9:()=>u});var r=n(49433),s=n(82680);let l=(e,t={})=>r.tryPromise({try:async()=>{let n=await fetch(e,t.init);if(t.passThroughStatuses&&t.passThroughStatuses.includes(n.status))return await n.json().catch(()=>({}));if(!n.ok){let e;try{e=(await n.json()).error}catch{}throw Error(e||`HTTP ${n.status}`)}return await n.json()},catch:t=>new s.uV({message:`GET ${e} failed`,cause:t})}),a=(e,t)=>r.tryPromise({try:async()=>{let n=await fetch(e,t),r=null;try{r=await n.json()}catch{}return{status:n.status,ok:n.ok,data:r}},catch:t=>new s.uV({message:`GET ${e} failed`,cause:t})}),o=(e,t)=>r.tryPromise({try:async()=>{let n=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!n.ok)throw Error(`HTTP ${n.status}`)},catch:t=>new s.uV({message:`POST ${e} failed`,cause:t})}),i=e=>l(`/api/files/init?cwd=${encodeURIComponent(e)}`),c=e=>l(`/api/files/index?cwd=${encodeURIComponent(e)}`),d=(e,t)=>l(`/api/files/readdir?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`),u=e=>l(`/api/files/recent?cwd=${encodeURIComponent(e)}`),h=(e,t,n)=>o("/api/files/recent",{cwd:e,file:t,...n??{}}),m=(e,t)=>o("/api/files/expanded",{cwd:e,paths:t}),f=(e,t)=>l(`/api/files/blame?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`).pipe(r.catchAll(e=>r.succeed({error:e.message}))),x=(e,t)=>a(`/api/files/stat?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`,{cache:"no-store"}),p=(e,t)=>a(`/api/files/text?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`,{cache:"no-store"}),g=e=>l(`/api/files/text?${e.toString()}`),b=e=>r.tryPromise({try:async()=>{let t=await fetch("/api/files/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),n=null;try{n=await t.json()}catch{}return{status:t.status,ok:t.ok,data:n}},catch:e=>new s.uV({message:"POST /api/files/save failed",cause:e})}),v=()=>l("/api/files/clipboard"),y=e=>r.tryPromise({try:async()=>{let t=await fetch("/api/files/clipboard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw Error(`HTTP ${t.status}`)},catch:e=>new s.uV({message:"POST /api/files/clipboard failed",cause:e})}),w=e=>r.tryPromise({try:async()=>{let t=await fetch("/api/files/paste",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),n=await t.json().catch(()=>null);if(!t.ok)throw Error(n?.error||`HTTP ${t.status}`);return n},catch:e=>new s.uV({message:"POST /api/files/paste failed",cause:e})}),k=e=>r.tryPromise({try:async()=>{let t=await fetch("/api/files/delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),n=await t.json().catch(()=>null);if(!t.ok)throw Error(n?.error||`HTTP ${t.status}`);return n},catch:e=>new s.uV({message:"POST /api/files/delete failed",cause:e})}),j=e=>l(`/api/file?path=${encodeURIComponent(e)}`)},65153:(e,t,n)=>{n.d(t,{u:()=>a});var r=n(12115),s=n(2111),l=n(48948);function a(e,t,n,a,o){let i=(0,r.useRef)(null),c=(0,r.useRef)(0),d=(0,r.useRef)(!1),u=()=>{let e=`live-asst-${++c.current}`;return i.current=e,t(t=>[...t,{id:e,role:"assistant",content:"",isStreaming:!0}]),e},h=e=>{if("system"===e.type&&"init"===e.subtype){d.current=!0,u();return}if("system"===e.type&&"task_notification"===e.subtype){if(!d.current){let n=`live-tasknotif-${e.task_id||++c.current}`,r=`<task-notification>
|
|
11
|
+
`+(e.task_id?`<task-id>${e.task_id}</task-id>
|
|
12
|
+
`:"")+(e.status?`<status>${e.status}</status>
|
|
13
|
+
`:"")+(e.summary?`<summary>${e.summary}</summary>
|
|
14
|
+
`:"")+(e.output_file?`<output-file>${e.output_file}</output-file>
|
|
15
|
+
`:"")+"</task-notification>";t(t=>[...t,{id:n,role:"system",content:e.summary||"",systemEvent:{kind:"task-notification",...e.status?{status:e.status}:{},detail:r}}])}return}if("user"===e.type&&e._human){let n=e.message?.content,r="string"==typeof n?n:Array.isArray(n)?n.map(e=>e?.text||"").join(""):"",s="string"==typeof e._turnId?e._turnId:null,l="number"==typeof e._ts?e._ts:null,a=s?`live-user-${s}`:`live-user-${++c.current}`;t(e=>{if(s&&e.some(e=>e.id===a))return e;for(let t=e.length-1;t>=0;t--){if("user"!==e[t].role)continue;let n=e[t].timestamp?Date.parse(e[t].timestamp):NaN;if(null===l||Number.isNaN(n)){if(e[t].content===r)return e}else if(n>=l)return e;break}return[...e,{id:a,role:"user",content:r}]});return}"result"===e.type&&(d.current=!1);let n=i.current??u();t(t=>(0,l.F)(t,e,{engine:a,assistantId:n}))};(0,s.h)({url:e?`/ws/session-stream?sessionId=${encodeURIComponent(e)}`:"/ws/session-stream",enabled:n&&!!e,onMessage:e=>{if("run-snapshot"===e.type&&Array.isArray(e.events)){if("running"!==e.status)return void o?.onRunningChange?.(!1);let n=e.events.find(e=>e?.type==="user"&&e?._human),r=n?.message?.content,s="string"==typeof r?r:"",l=new Set,a=new Set;for(let t of e.events){let e=t?.uuid;if("string"==typeof e&&l.add(e),t?.type==="assistant"&&Array.isArray(t.message?.content))for(let e of t.message.content)e?.name&&"string"==typeof e.id&&a.add(e.id)}let u="number"==typeof e.startedAt?e.startedAt:null;for(let n of(t(e=>{let t=e.filter(e=>!("string"==typeof e.id&&e.id.startsWith("live-"))),n=t[t.length-1],r=n?.timestamp?Date.parse(n.timestamp):NaN;if(null!==u&&!Number.isNaN(r)){let e=t.length;for(;e>0;){let n=t[e-1],r=n.timestamp?Date.parse(n.timestamp):NaN;if(!Number.isNaN(r)&&r>=u)e--;else break}return e<t.length?t.slice(0,e):t}if(!s)return t;let o=-1;for(let e=t.length-1;e>=0;e--)if("user"===t[e].role){t[e].content===s&&(o=e);break}return -1===o?t:t.slice(o+1).every(e=>"assistant"===e.role&&("string"==typeof e.id&&l.has(e.id)||!!e.toolCalls?.length&&e.toolCalls.every(e=>a.has(e.id))))?t.slice(0,o):t}),i.current=null,c.current=0,d.current=!1,e.events))h(n);o?.onRunningChange?.(!0)}else if("run-event"===e.type&&e.message){if("run-ended"===e.message.type){o?.onRunningChange?.(!1),o?.onComplete?.();return}h(e.message),o?.onRunningChange?.(!0)}else"run-idle"===e.type&&o?.onRunningChange?.(!1)}})}},65992:(e,t,n)=>{n.d(t,{zB:()=>M,e$:()=>E,vP:()=>C});var r=n(95155),s=n(12115),l=n(79114),a=n(49433),o=n(77725),i=n(64428),c=n(12710),d=n(33210),u=n(32967),h=n(88780),m=n(30133);function f({value:e,onChange:t,className:n}){let{t:s}=(0,l.Bd)();return(0,r.jsx)("div",{className:`flex items-center gap-0.5 rounded border border-border overflow-hidden ${n??""}`,children:["split","unified"].map(n=>(0,r.jsx)("button",{onClick:e=>{e.stopPropagation(),t(n)},className:`px-2 py-0.5 text-xs transition-colors ${e===n?"bg-brand text-white":"text-muted-foreground hover:bg-accent"}`,children:s("split"===n?"diffViewer.viewSplit":"diffViewer.viewUnified")},n))})}var x=n(67362),p=n(47215),g=n(5135),b=n(9573);let v=[/(^|\/)__tests__\//,/(^|\/)tests?\//,/\.(test|spec)\.[^/]+$/],y=[/\.(md|mdx)$/i,/(^|\/)docs\//,/(^|\/)README[^/]*$/i,/(^|\/)LICENSE[^/]*$/i,/(^|\/)CHANGELOG[^/]*$/i];function w(e){return v.some(t=>t.test(e))?"test":y.some(t=>t.test(e))?"docs":null}function k(e,t){if(t&&e.startsWith(t)){let n=e.slice(t.length);return n.startsWith("/")?n.slice(1):n}return e}function j(e,t){let n=[];for(let r of e)if("Edit"===r.name){let e=r.input;if(e.file_path&&"string"==typeof e.old_string&&"string"==typeof e.new_string){let s=k(e.file_path,t);n.push({key:r.id,toolName:"Edit",subject:`[Edit] ${s}`,legacy:!0,changeClass:w(s),files:[{path:s,status:"modified",old_string:e.old_string,new_string:e.new_string,fileClass:w(s)}]})}}else if("Write"===r.name){let e=r.input;if(e.file_path&&"string"==typeof e.content){let s=k(e.file_path,t);n.push({key:r.id,toolName:"Write",subject:`[Write] ${s}`,legacy:!0,changeClass:w(s),files:[{path:s,status:"added",old_string:"",new_string:e.content,fileClass:w(s)}]})}}return n}function C(e,t,n){let r=e.map(e=>{let t=new Set(e.commit.toolFiles);return{key:e.commit.toolId??e.commit.hash,shortHash:e.commit.hash.slice(0,7),toolName:e.commit.toolName??"tool",subject:e.commit.subject,timestamp:e.commit.timestamp,truncated:!0===e.truncated,changeClass:function(e){if(0===e.length)return null;let t=w(e[0]);return null===t?null:e.every(e=>w(e)===t)?t:null}(e.files.map(e=>e.path)),files:e.files.map(e=>({path:e.path,status:e.status,additions:e.additions,deletions:e.deletions,old_string:e.oldContent??"",new_string:e.newContent??"",unviewable:e.binary||null===e.oldContent&&null===e.newContent,external:t.size>0&&!t.has(e.path),fileClass:w(e.path)}))}});return r.length>0?r:j(t,n)}function N({additions:e,deletions:t}){return(0,r.jsxs)("span",{className:"flex items-center gap-1 font-mono",children:[(0,r.jsxs)("span",{className:"text-green-11",children:["+",e]}),(0,r.jsxs)("span",{className:"text-red-11",children:["-",t]})]})}function S({cls:e}){return(0,r.jsx)("span",{className:`text-[10px] px-1 py-px rounded flex-shrink-0 ${"test"===e?"bg-emerald-500/15 text-emerald-600 dark:text-emerald-400/80":"bg-sky-500/15 text-sky-600 dark:text-sky-400/80"}`,children:e})}function L(e){let t=new Date(1e3*e),n=new Date,r=String(t.getMonth()+1).padStart(2,"0"),s=String(t.getDate()).padStart(2,"0"),l=String(t.getHours()).padStart(2,"0"),a=String(t.getMinutes()).padStart(2,"0"),o=`${r}-${s} ${l}:${a}`;return t.getFullYear()===n.getFullYear()?o:`${t.getFullYear()}-${o}`}function E({toolCalls:e,cwd:t,onClose:n}){let{t:i}=(0,l.Bd)(),v=(0,s.useMemo)(()=>e.map(e=>e.id).filter(Boolean),[e]),y=v.join(","),[w,k]=(0,s.useState)(0),M=(0,o.Z)(t&&v.length>0?(0,b.se)(t,v):a.succeed([]),[t,y,w]),R=(0,s.useMemo)(()=>e.filter(e=>["Edit","Write","MultiEdit","NotebookEdit"].includes(e.name)).map(e=>e.id),[e]);(0,s.useEffect)(()=>{if("success"!==M.status||w>=2)return;let e=new Set(M.data.map(e=>e.commit.toolId));if(R.some(t=>!e.has(t))){let e=setTimeout(()=>k(e=>e+1),2e3);return()=>clearTimeout(e)}},[M,w,R]);let T=(0,s.useRef)([]),$="loading"===M.status&&0===T.current.length,I=(0,s.useMemo)(()=>{if("success"===M.status){let n=C(M.data,e,t);return n.length>0&&(T.current=n),n}return"loading"===M.status&&T.current.length>0?T.current:"loading"===M.status?[]:j(e,t)},[M,e,t]),[P,A]=(0,s.useState)(null),[_,D]=(0,s.useState)(null),[F,W]=(0,s.useState)(new Set),[B,V]=(0,s.useState)(()=>window.innerWidth>=768),[O,z]=(0,s.useState)("compact"),[H,K]=(0,s.useState)("split"),[U,q]=(0,s.useState)(!1),[X,Z]=(0,s.useState)(null),G=(0,s.useMemo)(()=>I.find(e=>e.key===P)??null,[I,P]),J=(0,s.useRef)(null);(0,s.useEffect)(()=>{G&&(J.current=G)},[G]);let Y=G??J.current,Q=(0,s.useMemo)(()=>Y?(0,h.Do)(Y.files):[],[Y]),ee=(0,s.useMemo)(()=>Y?.files.find(e=>e.path===_)??null,[Y,_]),et=(0,s.useCallback)(e=>{A(e.key),D(e.files[0]?.path??null),W(new Set((0,h.Sz)((0,h.Do)(e.files))))},[]);(0,s.useEffect)(()=>{I.length>0&&null==P&&et(I[0])},[I,P,et]),(0,s.useEffect)(()=>{let e=e=>{if("Escape"===e.key){if(U)return void q(!1);if(X)return void Z(null);n()}};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[n,U,X]);let en=(0,s.useMemo)(()=>I.reduce((e,t)=>e+t.files.length,0),[I]),er=e=>(0,r.jsx)("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:e});return(0,r.jsxs)("div",{className:"relative bg-card shadow-xl w-full h-full flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("button",{onClick:()=>V(e=>!e),"aria-label":i("diffViewer.toggleFileTree"),className:`p-1 rounded transition-colors ${B?"text-foreground bg-accent":"text-muted-foreground hover:text-foreground hover:bg-accent"}`,children:(0,r.jsx)(c.A,{className:"w-4 h-4"})}),(0,r.jsx)("h3",{className:"text-sm font-medium text-foreground",children:i("diffViewer.fileChanges",{count:en})})]}),(0,r.jsx)("button",{onClick:n,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,r.jsx)(d.A,{className:"w-5 h-5"})})]}),(0,r.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[B&&(0,r.jsx)("div",{className:"w-60 flex-shrink-0 border-r border-border overflow-y-auto",children:I.map(e=>{let t;return(0,r.jsxs)("div",{onClick:()=>et(e),className:`px-3 py-2 border-b border-border cursor-pointer hover:bg-accent ${P===e.key?"bg-brand/10":""}`,children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[e.shortHash&&(0,r.jsx)("span",{className:"font-mono text-xs text-brand",children:e.shortHash}),void 0!==e.timestamp&&(0,r.jsx)("span",{className:"text-xs text-slate-9",children:L(e.timestamp)}),e.changeClass&&(0,r.jsx)("span",{className:"ml-auto",children:(0,r.jsx)(S,{cls:e.changeClass})})]}),(0,r.jsx)("div",{className:"text-sm text-foreground truncate mt-0.5","data-tooltip":e.subject,children:e.subject}),(0,r.jsxs)("div",{className:"flex items-center gap-2 mt-0.5 text-xs text-muted-foreground",children:[(0,r.jsx)("span",{children:i("commitDetail.nChanges",{count:e.files.length})}),(t=function(e){let t=!1,n=0,r=0;for(let s of e.files)(void 0!==s.additions||void 0!==s.deletions)&&(t=!0),n+=s.additions??0,r+=s.deletions??0;return t?{additions:n,deletions:r}:null}(e))&&(t.additions>0||t.deletions>0)?(0,r.jsx)(N,{additions:t.additions,deletions:t.deletions}):null]})]},e.key)})}),(0,r.jsx)("div",{className:"flex-1 flex flex-col overflow-hidden",children:$?er(i("diffViewer.loadingSnapshots")):0===I.length?er(i("diffViewer.noChanges")):Y?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"flex items-center gap-3 px-4 py-2 border-b border-border text-xs text-muted-foreground",children:[(0,r.jsxs)("span",{className:"flex items-center gap-1 text-foreground",children:[(0,r.jsx)(u.A,{className:"w-3.5 h-3.5"}),Y.toolName]}),Y.shortHash&&(0,r.jsx)("span",{className:"font-mono text-brand",children:Y.shortHash}),void 0!==Y.timestamp&&(0,r.jsx)("span",{children:L(Y.timestamp)}),(0,r.jsx)("span",{className:"flex-1 min-w-0 truncate","data-tooltip":Y.subject,children:Y.subject}),Y.truncated&&(0,r.jsx)("span",{className:"text-amber-500",children:i("diffViewer.truncated")}),Y.legacy&&(0,r.jsx)("span",{className:"px-1.5 py-0.5 rounded bg-amber-500/15 text-amber-600 dark:text-amber-400","data-tooltip":i("diffViewer.reconstructedHint"),children:i("diffViewer.reconstructed")}),(0,r.jsxs)("div",{className:"ml-auto flex items-center gap-2",children:[(0,r.jsx)(m.y,{value:O,onChange:z}),(0,r.jsx)(f,{value:H,onChange:K})]})]}),(0,r.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[B&&(0,r.jsx)("div",{className:"w-72 flex-shrink-0 border-r border-border overflow-y-auto overflow-x-hidden",children:(0,r.jsx)(h.VO,{files:Q,selectedPath:_,expandedPaths:F,onToggle:e=>W(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),onSelect:e=>{!e.isDirectory&&e.file&&(D(e.file.path),window.innerWidth<768&&V(!1))},cwd:t||"",showChanges:!0,renderActions:e=>{if(e.isDirectory)return null;let t=e.file;return t?(0,r.jsxs)(r.Fragment,{children:[t.fileClass&&(0,r.jsx)(S,{cls:t.fileClass}),t.external&&(0,r.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-purple-400 flex-shrink-0","data-tooltip":i("diffViewer.externalChange")})]}):null}})}),(0,r.jsx)("div",{className:"flex-1 overflow-hidden",children:ee?ee.unviewable?(0,r.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground text-sm",children:i("diffViewer.notViewable")}):"unified"===H?(0,r.jsx)(x.xU,{oldContent:ee.old_string,newContent:ee.new_string,filePath:ee.path,compact:"compact"===O}):(0,r.jsx)(x.xZ,{oldContent:ee.old_string,newContent:ee.new_string,filePath:ee.path,isNew:"added"===ee.status,isDeleted:"deleted"===ee.status,cwd:t,compact:"compact"===O,onPreview:"deleted"===ee.status?void 0:(0,p.e$)(ee.path)?()=>q(!0):ee.path.endsWith(".json")?()=>Z({content:ee.new_string,filePath:ee.path}):void 0,previewLabel:ee.path.endsWith(".json")?i("common.readable"):i("common.preview")}):(0,r.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground text-sm",children:i("diffViewer.selectFileToView")})})]})]}):er(i("diffViewer.selectFileToView"))})]}),U&&ee&&(0,r.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50 p-2 md:p-4",onClick:()=>q(!1),children:(0,r.jsx)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[95%] h-full flex flex-col",onClick:e=>e.stopPropagation(),children:(0,r.jsx)(g.M,{content:ee.new_string,filePath:ee.path,cwd:t||"",onClose:()=>q(!1)})})}),X&&(0,r.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50 p-2 md:p-4",onClick:()=>Z(null),children:(0,r.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[95%] h-full flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border flex-shrink-0",children:[(0,r.jsx)("span",{className:"text-sm text-muted-foreground font-mono truncate",children:X.filePath}),(0,r.jsx)("button",{onClick:()=>Z(null),className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,r.jsx)(d.A,{className:"w-4 h-4"})})]}),(0,r.jsx)("div",{className:"flex-1 overflow-auto px-6 py-4 bg-[#0d1117]",children:(0,r.jsx)("pre",{className:"whitespace-pre-wrap break-words font-mono",style:{fontSize:"0.8125rem",lineHeight:"1.5"},children:(0,p.xb)(X.content)})})]})})]})}function M({toolCalls:e,cwd:t,onClose:n}){return(0,r.jsx)(i.ZL,{children:(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:n,children:(0,r.jsx)(E,{toolCalls:e,cwd:t,onClose:n})})})}},67362:(e,t,n)=>{n.d(t,{xU:()=>j,xZ:()=>k});var r=n(95155),s=n(12115),l=n(47650),a=n(79114),o=n(64702),i=n(1058),c=n(90717),d=n(70188),u=n(48347),h=n(89109),m=n(7320),f=n(22576),x=n(34075),p=n(56978),g=n(17196);function b({lines:e,containerRef:t}){let n=(0,s.useRef)(null),[l,a]=(0,s.useState)({top:0,height:0});if((0,s.useEffect)(()=>{let e=t.current;if(!e)return;let r=()=>{let{scrollTop:t,scrollHeight:r,clientHeight:s}=e,l=n.current?.clientHeight||0;if(r<=s)a({top:0,height:l});else{let e=l/r;a({top:t*e,height:s*e})}};return r(),e.addEventListener("scroll",r),window.addEventListener("resize",r),()=>{e.removeEventListener("scroll",r),window.removeEventListener("resize",r)}},[t]),0===e.length)return null;let o=100/e.length;return(0,r.jsxs)("div",{ref:n,className:"w-4 flex-shrink-0 bg-secondary border-l border-border relative cursor-pointer",onClick:e=>{let r=t.current,s=n.current;if(!r||!s)return;let l=s.getBoundingClientRect(),a=(e.clientY-l.top)/l.height*r.scrollHeight-r.clientHeight/2;r.scrollTo({top:Math.max(0,a),behavior:"smooth"})},children:[e.map((e,t)=>"unchanged"!==e.type&&(0,r.jsx)("div",{className:`absolute left-0 right-0 ${"removed"===e.type?"bg-red-9":"bg-green-9"}`,style:{top:`${t*o}%`,height:`${Math.max(o,.5)}%`,minHeight:"2px"}},t)),(0,r.jsx)("div",{className:"absolute left-0 right-0 bg-muted/60 border-y border-border",style:{top:`${l.top}px`,height:`${Math.max(l.height,10)}px`}})]})}var v=n(37614),y=n(27570);function w(e){return e.params?`${e.name}(${e.params.join(", ")})`:e.name}function k({oldContent:e,newContent:t,filePath:n,isNew:j=!1,isDeleted:C=!1,cwd:N,enableComments:S=!1,onPreview:L,previewLabel:E,onContentSearch:M,targetLine:R,compact:T=!1,symbols:$}){let{t:I}=(0,a.Bd)(),P=E??I("common.preview"),A=(0,s.useMemo)(()=>(0,f.X)(e,t),[e,t]),_=(0,s.useRef)(null),D=(0,s.useRef)(null),F=(0,s.useRef)(null),W=(0,s.useRef)(!1),[B,V]=(0,s.useState)(!1),O=(0,d.iN)(),z=(0,u.r)(),H=S&&!!N,{comments:K,addComment:U,updateComment:q,deleteComment:X,refresh:Z}=(0,i._)({cwd:N||"",filePath:n}),[G,J]=(0,s.useState)(null),[Y,Q]=(0,s.useState)(null);(0,s.useEffect)(()=>{F.current!==Y&&Q(F.current)});let{toolbarRef:ee,bumpRef:et,clearToolbar:en}=(0,y.L)({enabled:H,container:Y,resolveLineRange:e=>{if(!document.contains(e))return null;let t=e.nodeType===Node.TEXT_NODE?e.parentElement:e,n=t?.closest("[data-new-line]");if(!n)return null;let r=parseInt(n.getAttribute("data-new-line")||"0",10);return!Number.isFinite(r)||r<=0?null:{start:r,end:r}},buildLineSnapshot:({start:e,end:t})=>{let n=[],r=0;for(let s of A)("unchanged"===s.type||"added"===s.type)&&++r>=e&&r<=t&&n.push(s.content);return n.join("\n")}}),[er,es]=(0,s.useState)(null),[el,ea]=(0,s.useState)(null);(0,s.useEffect)(()=>{V(!0)},[]);let eo=(0,s.useMemo)(()=>{let e=new Set;for(let t of K)for(let n=t.startLine;n<=t.endLine;n++)e.add(n);return e},[K]),ei=(0,s.useMemo)(()=>{let e=new Map;for(let t of K){let n=t.endLine;e.has(n)||e.set(n,[]),e.get(n).push(t)}return e},[K]),ec=(0,s.useCallback)((e,t)=>{t.stopPropagation(),J({comment:e,x:t.clientX,y:t.clientY}),en(),es(null),ea(null)},[en]),ed=(0,s.useCallback)(()=>{let e=ee.current;e&&(es({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),en())},[en,ee]),eu=(0,s.useCallback)(()=>{let e=ee.current;e&&(ea({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),en())},[en,ee]),eh=(0,s.useCallback)(()=>{let e=ee.current;if(!e||!M)return;let t=e.selectedText.trim();en(),t&&M(t)},[M,en,ee]),em=(0,s.useCallback)(async(e,t)=>{if(z&&N)try{let r=await (0,c.$3)(N),s=[];for(let e of r)s.push({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0});s.push({filePath:n,startLine:e.range.start,endLine:e.range.end,codeContent:e.lineSnapshot});let l=(0,c.Gw)(s,t);z.sendMessage(l),await (0,c.RP)(N),Z()}catch(e){console.error("Failed to send to AI:",e)}},[z,n,N,Z]),ef=(0,s.useCallback)(e=>{el&&em(el,e)},[el,em]),ex=(0,s.useCallback)(e=>{er&&em(er,e)},[er,em]),ep=(0,s.useCallback)(async e=>{er&&(await U(er.range.start,er.range.end,e,er.selectedText),es(null))},[er,U]);(0,s.useEffect)(()=>{let e=D.current,t=F.current;if(!e||!t)return;let n=(e,t)=>{W.current||(W.current=!0,t.scrollLeft=e.scrollLeft,requestAnimationFrame(()=>{W.current=!1}))},r=()=>n(e,t),s=()=>n(t,e);return e.addEventListener("scroll",r),t.addEventListener("scroll",s),()=>{e.removeEventListener("scroll",r),t.removeEventListener("scroll",s)}},[]);let{leftLines:eg,rightLines:eb}=(0,s.useMemo)(()=>{let e=[],t=[],n=0,r=0;for(let s=0;s<A.length;s++){let l=A[s];if("unchanged"===l.type){for(;e.length<t.length;)e.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});for(;t.length<e.length;)t.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});n++,r++,e.push({lineNum:n,content:l.content,type:"unchanged",originalIdx:s}),t.push({lineNum:r,content:l.content,type:"unchanged",originalIdx:s})}else"removed"===l.type?(n++,e.push({lineNum:n,content:l.content,type:"removed",originalIdx:s})):"added"===l.type&&(r++,t.push({lineNum:r,content:l.content,type:"added",originalIdx:s}))}for(;e.length<t.length;)e.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});for(;t.length<e.length;)t.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});return{leftLines:e,rightLines:t}},[A]),ev=(0,s.useMemo)(()=>A.map(e=>e.content),[A]),ey=(0,p.C)(ev,n),[ew,ek]=(0,s.useState)(()=>new Map);(0,s.useLayoutEffect)(()=>{ek(new Map),eR.measure()},[eg,eb]);let ej=(0,s.useMemo)(()=>$??[],[$]),{rows:eC,gaps:eN}=(0,s.useMemo)(()=>T?function(e,t,n,r=[]){let s=e.length,l=n=>"unchanged"!==e[n].type||"unchanged"!==t[n].type,a=new Set;for(let e=0;e<s;e++){if(!l(e))continue;let t=Math.max(0,e-3),n=Math.min(s-1,e+3);for(let e=t;e<=n;e++)a.add(e)}let o=[];for(let e=0;e<s;e++){if(a.has(e))continue;let t=e;for(;e<s&&!a.has(e);)e++;o.push({id:o.length,startIdx:t,endIdx:e-1}),e--}for(let e of o){let t=n.get(e.id)??{topRevealed:0,bottomRevealed:0},r=e.endIdx-e.startIdx+1,s=Math.max(0,Math.min(t.topRevealed,r)),l=Math.max(0,Math.min(t.bottomRevealed,r-s));for(let t=e.startIdx;t<e.startIdx+s;t++)a.add(t);for(let t=e.endIdx-l+1;t<=e.endIdx;t++)a.add(t)}let i=[];for(let e=0;e<s;e++){let n;if(a.has(e)){i.push({kind:"diff",idx:e});continue}let l=e;for(;e<s&&!a.has(e);)e++;let c=e-1;e--;let d=o.find(e=>e.startIdx<=l&&c<=e.endIdx);if(!d)continue;let u=c-l+1,h=Math.min(20,u);if(r.length>0&&c+1<s)for(let e=c+1;e<s;e++){let s=t[e].lineNum;if(!(s<=0)){n=function(e,t){let n=null;for(let r of e)r.startLine<=t&&t<=r.endLine&&(!n||r.endLine-r.startLine<n.endLine-n.startLine)&&(n=r);return n}(r,s)??void 0;break}}i.push({kind:"gap-expand",gapId:d.id,direction:"up",revealCount:h}),i.push({kind:"gap-label",gapId:d.id,hiddenCount:u,enclosingFn:n}),i.push({kind:"gap-expand",gapId:d.id,direction:"down",revealCount:h})}return{rows:i,gaps:o}}(eg,eb,ew,ej):{rows:eg.map((e,t)=>({kind:"diff",idx:t})),gaps:[]},[T,eg,eg,eb,ew,ej]),eS=(0,s.useCallback)((e,t)=>{let n=eN.find(t=>t.id===e);n&&ek(r=>{let s=r.get(e)??{topRevealed:0,bottomRevealed:0},l=n.endIdx-n.startIdx+1-s.topRevealed-s.bottomRevealed;if(l<=0)return r;let a=Math.min(20,l),o="up"===t?{...s,topRevealed:s.topRevealed+a}:{...s,bottomRevealed:s.bottomRevealed+a};return new Map(r).set(e,o)})},[eN]),eL=(0,s.useCallback)(e=>{for(let t of eN)if(e>=t.startIdx&&e<=t.endIdx)return t.id;return null},[eN]),eE=(0,s.useCallback)(e=>eC[e]?.kind==="gap-label"?28:20,[eC]),eM=(0,s.useCallback)(e=>{let t=eC[e];if(!t)return e;if("gap-label"===t.kind)return`gl:${t.gapId}`;if("gap-expand"===t.kind)return`ge:${t.gapId}:${t.direction}`;let n=eg[t.idx],r=eb[t.idx];return`d:${n?.lineNum??"x"}:${n?.type??"x"}:${r?.lineNum??"x"}:${r?.type??"x"}`},[eC,eg,eb]),eR=(0,o.Te)({count:eC.length,getScrollElement:()=>_.current,estimateSize:eE,getItemKey:eM,overscan:20}),eT=j?"w-1/4":C?"w-3/4":"w-1/2",e$=j?"w-3/4":C?"w-1/4":"w-1/2",eI=(0,s.useMemo)(()=>eC.map(e=>{if("diff"!==e.kind)return{type:"unchanged"};let t=eg[e.idx],n=eb[e.idx];return"removed"===t.type?{type:"removed"}:n?.type==="added"?{type:"added"}:{type:"unchanged"}}),[eC,eg,eb]),eP=eR.getTotalSize(),eA=eR.getVirtualItems();return(0,s.useEffect)(()=>{if(!R)return;let e=("after"===R.side?eb:eg).findIndex(e=>e.lineNum===R.line);if(-1===e)return;let t=eC.findIndex(t=>"diff"===t.kind&&t.idx===e);if(-1===t){let t=eL(e);if(null!==t){let e=eN.find(e=>e.id===t);if(!e)return;let n=e.endIdx-e.startIdx+1;ek(e=>{let r=e.get(t)??{topRevealed:0,bottomRevealed:0};if(r.topRevealed+r.bottomRevealed>=n)return e;let s=new Map(e);return s.set(t,{topRevealed:n,bottomRevealed:0}),s})}return}let n=requestAnimationFrame(()=>{eR.scrollToIndex(t,{align:"start"})});return()=>cancelAnimationFrame(n)},[R,eg,eb,eC]),(0,r.jsxs)("div",{className:"font-mono flex flex-col h-full text-sm",children:[(0,r.jsxs)("div",{className:"flex flex-shrink-0 border-b border-border",children:[(0,r.jsx)("div",{className:`${eT} min-w-0 px-2 py-1 bg-accent text-muted-foreground text-center text-xs font-medium border-r border-border`,children:j?"(New File)":C?"Deleted":"Old"}),(0,r.jsxs)("div",{className:`${e$} min-w-0 px-2 py-1 bg-accent text-muted-foreground text-xs font-medium relative`,children:[(0,r.jsx)("span",{className:"block text-center",children:C?"(Deleted)":"New"}),(0,r.jsxs)("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center gap-2",children:[L&&(0,r.jsx)("button",{onClick:L,className:"text-muted-foreground hover:text-foreground transition-colors",children:P}),!C&&t&&(0,r.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(t),(0,x.oR)(I("diffViewer.copiedAll"))},className:"text-muted-foreground hover:text-foreground transition-colors",children:I("common.copy")})]})]}),(0,r.jsx)("div",{className:"w-4 flex-shrink-0 bg-accent"})]}),(0,r.jsxs)("div",{className:"flex-1 min-h-0 flex",children:[(0,r.jsx)("div",{ref:_,className:"flex-1 overflow-y-auto overflow-x-hidden",children:(0,r.jsxs)("div",{className:"flex",style:{height:`${eP}px`},children:[(0,r.jsx)("div",{ref:D,className:`${eT} overflow-x-auto border-r border-border`,children:(0,r.jsx)("div",{className:"min-w-max h-full",style:{position:"relative"},children:eA.map(e=>{let t=eC[e.index];if("gap-expand"===t.kind||"gap-label"===t.kind){let n="gap-label"===t.kind;return(0,r.jsx)("div",{ref:eR.measureElement,"data-index":e.index,style:{position:"absolute",top:0,left:0,width:"100%",height:`${Math.max(e.size,eE(e.index))}px`,transform:`translateY(${e.start}px)`},className:n?"bg-accent border-y border-border":""},e.key)}let n=eg[t.idx];return(0,r.jsxs)("div",{ref:eR.measureElement,"data-index":e.index,"data-row-idx":t.idx,style:{position:"absolute",top:0,left:0,minWidth:"100%",width:"max-content",height:`${Math.max(e.size,eE(e.index))}px`,transform:`translateY(${e.start}px)`},className:`flex ${"removed"===n.type?"bg-red-9/15 dark:bg-red-9/25":""}`,children:[(0,r.jsx)("span",{className:"w-10 flex-shrink-0 text-right pr-2 text-slate-9 select-none border-r border-border",children:n.lineNum||""}),(0,r.jsx)("span",{className:"whitespace-pre pl-2",dangerouslySetInnerHTML:{__html:n.originalIdx>=0&&ey[n.originalIdx]||(0,g.ZD)(n.content||" ")}})]},e.key)})})}),(0,r.jsx)("div",{ref:F,className:`${e$} overflow-x-auto`,children:(0,r.jsx)("div",{className:"min-w-max h-full",style:{position:"relative"},children:eA.map(e=>{let t=eC[e.index];if("gap-expand"===t.kind)return(0,r.jsx)("button",{ref:eR.measureElement,"data-index":e.index,type:"button",onClick:()=>eS(t.gapId,t.direction),style:{position:"absolute",top:0,left:0,width:"100%",height:`${Math.max(e.size,eE(e.index))}px`,transform:`translateY(${e.start}px)`},className:"flex items-center justify-center text-[11px] text-foreground/50 hover:bg-accent hover:text-brand active:bg-brand/15 transition-colors duration-100 cursor-pointer focus:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-brand/60",title:I("up"===t.direction?"diffViewer.gap.expandUp":"diffViewer.gap.expandDown",{count:t.revealCount}),"aria-label":I("up"===t.direction?"diffViewer.gap.expandUp":"diffViewer.gap.expandDown",{count:t.revealCount}),children:(0,r.jsx)("span",{className:"select-none",children:I("diffViewer.gap.more",{count:t.revealCount})})},e.key);if("gap-label"===t.kind)return(0,r.jsxs)("div",{ref:eR.measureElement,"data-index":e.index,"data-gap-id":t.gapId,style:{position:"absolute",top:0,left:0,width:"100%",height:`${Math.max(e.size,eE(e.index))}px`,transform:`translateY(${e.start}px)`},className:"flex items-center justify-center gap-2 px-3 text-[11px] text-foreground/80 bg-accent border-y border-border min-w-0 select-none",children:[(0,r.jsx)("span",{className:"flex-shrink-0",children:I("diffViewer.gap.hidden",{count:t.hiddenCount})}),t.enclosingFn&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"opacity-50 flex-shrink-0",children:"\xb7"}),(0,r.jsx)("span",{className:"truncate min-w-0 font-medium",title:w(t.enclosingFn),children:w(t.enclosingFn)})]})]},e.key);let n=eb[t.idx],s=n?.lineNum||0,l=s>0&&eo.has(s),a=ei.get(s),o=a?.[0],i=er&&s>=er.range.start&&s<=er.range.end,c=el&&s>=el.range.start&&s<=el.range.end,d=i||c;return(0,r.jsxs)("div",{ref:eR.measureElement,"data-index":e.index,"data-new-line":s||void 0,"data-row-idx":t.idx,style:{position:"absolute",top:0,left:0,minWidth:"100%",width:"max-content",height:`${Math.max(e.size,eE(e.index))}px`,transform:`translateY(${e.start}px)`},className:`flex ${d?"bg-blue-9/20":l?"bg-amber-9/10":n?.type==="added"?"bg-green-9/15 dark:bg-green-9/25":""}`,children:[(0,r.jsxs)("span",{className:`flex-shrink-0 flex items-center gap-0.5 pr-1 text-slate-9 select-none border-r border-border ${d?"bg-blue-9/30":""}`,style:{width:H?"52px":"40px"},children:[H&&s>0&&l&&o&&(0,r.jsx)("button",{onClick:e=>ec(o,e),className:"w-4 h-4 flex items-center justify-center rounded hover:bg-accent text-amber-9",title:I("codeViewer.nComments",{count:a?.length}),children:(0,r.jsx)("svg",{className:"w-3 h-3",fill:"currentColor",viewBox:"0 0 20 20",children:(0,r.jsx)("path",{fillRule:"evenodd",d:"M18 10c0 3.866-3.582 7-8 7a8.841 8.841 0 01-4.083-.98L2 17l1.338-3.123C2.493 12.767 2 11.434 2 10c0-3.866 3.582-7 8-7s8 3.134 8 7zM7 9H5v2h2V9zm8 0h-2v2h2V9zM9 9h2v2H9V9z",clipRule:"evenodd"})})}),H&&s>0&&!l&&(0,r.jsx)("span",{className:"w-4"}),(0,r.jsx)("span",{className:"flex-1 text-right pr-1",children:s||""})]}),(0,r.jsx)("span",{className:"whitespace-pre pl-2",dangerouslySetInnerHTML:{__html:n?.originalIdx>=0&&ey[n.originalIdx]||(0,g.ZD)(n?.content||" ")}})]},e.key)})})})]})}),(0,r.jsx)(b,{lines:eI,containerRef:_})]}),B&&O&&(0,l.createPortal)((0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(h.f,{floatingToolbarRef:ee,bumpRef:et,container:O,onAddComment:ed,onSendToAI:eu,onSearch:M?eh:void 0,isChatLoading:z?.isLoading??!1}),er&&(0,r.jsx)(m.t,{x:er.x,y:er.y,range:er.range,filePath:n,lineSnapshot:er.lineSnapshot,container:O,onSubmit:ep,onSendToAI:z?ex:void 0,onClose:()=>es(null),isChatLoading:z?.isLoading}),el&&(0,r.jsx)(m.G,{x:el.x,y:el.y,range:el.range,filePath:n,lineSnapshot:el.lineSnapshot,container:O,onSubmit:ef,onClose:()=>ea(null),isChatLoading:z?.isLoading}),G&&(0,r.jsx)(v.t,{x:G.x,y:G.y,comment:G.comment,container:O,onClose:()=>J(null),onUpdateComment:q,onDeleteComment:X})]}),O)]})}function j({oldContent:e,newContent:t,filePath:n,compact:l=!1}){let{t:i}=(0,a.Bd)(),c=(0,s.useMemo)(()=>(0,f.X)(e,t),[e,t]),d=(0,s.useRef)(null),u=(0,s.useMemo)(()=>c.map(e=>e.content),[c]),h=(0,p.C)(u,n),[m,x]=(0,s.useState)(()=>new Set);(0,s.useEffect)(()=>{x(new Set)},[e,t,n]);let b=(0,s.useMemo)(()=>l?function(e,t){let n=e.length,r=Array(n).fill(!1);for(let t=0;t<n;t++){if("unchanged"===e[t].type)continue;let s=Math.max(0,t-3),l=Math.min(n-1,t+3);for(let e=s;e<=l;e++)r[e]=!0}let s=[],l=0,a=0;for(;a<n;){if(r[a]){s.push({kind:"line",line:e[a],index:a}),a++;continue}let o=a;for(;o<n&&!r[o];)o++;let i=l++;if(t.has(i))for(let t=a;t<o;t++)s.push({kind:"line",line:e[t],index:t});else s.push({kind:"gap",id:i,count:o-a});a=o}return s}(c,m):c.map((e,t)=>({kind:"line",line:e,index:t})),[l,c,m]),v=(0,s.useCallback)(e=>{let t=b[e];if(!t)return e;if("gap"===t.kind)return`gap:${t.id}`;let n=t.line;return`${n.type}:${n.oldLineNum??"x"}:${n.newLineNum??"x"}`},[b]),y=(0,o.Te)({count:b.length,getScrollElement:()=>d.current,estimateSize:()=>20,getItemKey:v,overscan:20});return(0,r.jsx)("div",{ref:d,className:"font-mono text-sm overflow-auto h-full",children:(0,r.jsx)("div",{style:{height:`${y.getTotalSize()}px`,position:"relative"},children:y.getVirtualItems().map(e=>{let t=b[e.index];if(!t)return null;let n={position:"absolute",top:0,left:0,minWidth:"100%",width:"max-content",height:`${e.size}px`,transform:`translateY(${e.start}px)`};if("gap"===t.kind){let s=i("diffViewer.gap.hidden",{count:t.count});return(0,r.jsx)("div",{style:n,onClick:()=>x(e=>new Set(e).add(t.id)),className:"flex items-center cursor-pointer bg-slate-2 hover:bg-accent border-y border-border text-xs text-slate-9 select-none",title:s,children:(0,r.jsx)("span",{className:"w-full text-center",children:s})},e.key)}let s=t.line;return(0,r.jsxs)("div",{style:n,className:`flex ${"removed"===s.type?"bg-red-9/15 dark:bg-red-9/25":"added"===s.type?"bg-green-9/15 dark:bg-green-9/25":""}`,children:[(0,r.jsx)("span",{className:"w-10 flex-shrink-0 text-right pr-2 text-slate-9 select-none border-r border-border",children:"added"!==s.type?s.oldLineNum:""}),(0,r.jsx)("span",{className:"w-10 flex-shrink-0 text-right pr-2 text-slate-9 select-none border-r border-border",children:"removed"!==s.type?s.newLineNum:""}),(0,r.jsx)("span",{className:`w-6 flex-shrink-0 text-center select-none ${"removed"===s.type?"text-red-11":"added"===s.type?"text-green-11":"text-slate-9"}`,children:"removed"===s.type?"-":"added"===s.type?"+":" "}),(0,r.jsx)("span",{className:"flex-1 whitespace-pre pl-1",dangerouslySetInnerHTML:{__html:h[t.index]||(0,g.ZD)(s.content||" ")}})]},e.key)})})})}},67589:(e,t,n)=>{n.d(t,{z:()=>o,m:()=>c});var r=n(12115),s=n(49433),l=n(86957),a=n(82680);let o=e=>s.tryPromise({try:async()=>{let t=await fetch("/api/session-by-path",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});return t.ok?await t.json():null},catch:e=>new a.uV({message:"session-by-path failed",cause:e})}),i=new Map;function c(e,t,n,{cwd:d,initialSessionId:u,onSessionId:h,onTitleChange:m,onTokenUsage:f,liveRunningRef:x}){let[p,g]=(0,r.useState)(!1),[b,v]=(0,r.useState)(!1),[y,w]=(0,r.useState)(!1),[k,j]=(0,r.useState)(void 0),[C,N]=(0,r.useState)(0),[S,L]=(0,r.useState)(null),[E,M]=(0,r.useState)(null),R=(0,r.useRef)(m);R.current=m;let T=(0,r.useRef)(f);T.current=f;let $=(0,r.useRef)(void 0),I=(0,r.useRef)(0),P=(0,r.useCallback)(async(e,n,r=!1,s,a,c=!1)=>{if(r){let e=Date.now();if(!c&&e-I.current<5e3)return;I.current=e}let d=(e,r)=>{e.fingerprint&&($.current=e.fingerprint),void 0!==e.totalTurns&&N(e.totalTurns),void 0!==e.hasMore&&w(e.hasMore),e.messages&&e.messages.length>0&&(r?t(t=>(function(e,t){if(0===t.length)return e;let n=0;if(e.length>0&&e[0].id!==t[0].id){n=-1;for(let r=e.length-1;r>=0;r--)if(e[r].id===t[0].id){n=r;break}}if(n<0)return t;let r=e.slice(n),s=0;for(let e=0;e<Math.min(r.length,t.length)&&r[e].id===t[e].id&&r[e].content===t[e].content;e++)s=e+1;return s===r.length&&s===t.length?e:s===r.length&&s<t.length?[...e,...t.slice(s)]:[...e.slice(0,n),...r.slice(0,s),...t.slice(s)]})(t,e.messages)):x?.current||t(e.messages),L(n)),e.sessionId&&h(e.sessionId),e.engine&&M(e.engine),e.title&&R.current?.(e.title),e.usage&&T.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})},u=`${e}::${n}`,m=!r&&void 0===a,f=m?i.get(u):void 0;r||(f?d(f.data,!1):g(!0));try{let t={cwd:e,sessionId:n,limit:s,beforeTurnIndex:a};r&&$.current?t.ifFingerprint=$.current:f&&(t.ifFingerprint=f.fingerprint);let c=await l.t4.runPromiseExit(o(t));if("Success"===c._tag&&c.value){let e=c.value;if(e.notModified)return;if(d(e,r),m&&e.fingerprint&&e.messages&&e.messages.length>0&&(i.delete(u),i.set(u,{data:e,fingerprint:e.fingerprint}),i.size>20)){let e=i.keys().next().value;void 0!==e&&i.delete(e)}}}catch(e){console.error("Failed to load history by cwd and sessionId:",e)}finally{r||g(!1)}},[t,h]),A=(0,r.useCallback)(async()=>{if(d&&n&&!b&&y){v(!0);try{let r=void 0!==k?k:C-Math.ceil(e.filter(e=>"user"===e.role).length),s=await l.t4.runPromiseExit(o({cwd:d,sessionId:n,limit:10,beforeTurnIndex:r>0?r:void 0}));if("Success"===s._tag&&s.value){let e=s.value;if(e.messages&&e.messages.length>0){t(t=>[...e.messages,...t]);let s=e.messages.filter(e=>"user"===e.role).length;j(r-s),L(n)}void 0!==e.hasMore&&w(e.hasMore),e.fingerprint&&($.current=e.fingerprint)}else"Failure"===s._tag&&console.error("Failed to load more history:",s.cause)}finally{v(!1)}}},[d,n,b,y,k,C,e,t]),_=(0,r.useCallback)(async e=>{g(!0);let n=s.tryPromise({try:async()=>{let t=await fetch(`/api/session/${e}/history`);return t.ok?await t.json():null},catch:e=>new a.uV({message:"load session history failed",cause:e})}),r=await l.t4.runPromiseExit(n);"Success"===r._tag&&r.value?.messages&&r.value.messages.length>0?(t(r.value.messages),L(e)):"Failure"===r._tag&&console.error("Failed to load history:",r.cause),g(!1)},[t]);return(0,r.useEffect)(()=>{d&&u&&P(d,u,!1,10)},[]),{isLoadingHistory:p,isLoadingMore:b,hasMoreHistory:y,loadMoreHistory:A,loadHistory:_,loadHistoryByCwdAndSessionId:P,loadedSessionId:S,loadedEngine:E}}},70188:(e,t,n)=>{n.d(t,{Ee:()=>h,SU:()=>c,ft:()=>u,iN:()=>d});var r=n(95155),s=n(12115),l=n(79114),a=n(47650),o=n(34075);let i=(0,s.createContext)(null);function c({container:e,children:t}){return(0,r.jsx)(i.Provider,{value:e,children:t})}function d(){return(0,s.useContext)(i)}function u({x:e,y:t,path:n,cwd:c,isDirectory:d,onClose:h,onCreateFile:m,onDelete:f,onRefresh:x,onCopyFile:p,onPaste:g}){let{t:b}=(0,l.Bd)(),v=(0,s.useRef)(null),y=(0,s.useContext)(i),w=n.split("/").pop()||n,k=`${c}/${n}`,j=n.includes("/")?n.substring(0,n.lastIndexOf("/")):"",C=j?`${c}/${j}`:c,N=d?n:j,S=d?k:C;(0,s.useEffect)(()=>{let e=e=>{v.current&&!v.current.contains(e.target)&&h()},t=e=>{"Escape"===e.key&&h()};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[h]);let[L,E]=(0,s.useState)({x:0,y:0});(0,s.useEffect)(()=>{if(v.current&&y){let n=y.getBoundingClientRect(),r=v.current.getBoundingClientRect(),s=e-n.left,l=t-n.top;s=Math.min(s,n.width-r.width-8),l=Math.min(l,n.height-r.height-8),E({x:s=Math.max(8,s),y:l=Math.max(8,l)})}else if(v.current){let n=v.current.getBoundingClientRect();E({x:Math.max(8,Math.min(e,window.innerWidth-n.width-8)),y:Math.max(8,Math.min(t,window.innerHeight-n.height-8))})}},[e,t,y]);let M=(0,s.useCallback)(async(e,t)=>{try{await navigator.clipboard.writeText(e),(0,o.oR)(b("toast.copiedName",{name:t}),"success")}catch{(0,o.oR)(b("toast.copyFailed"),"error")}h()},[h,b]),R=d?n:j,T=[{label:b("fileContextMenu.copyRelativePath"),value:n},{label:b("fileContextMenu.copyAbsolutePath"),value:k},{label:b("fileContextMenu.copyRelativeDirPath"),value:N||"."},{label:b("fileContextMenu.copyAbsoluteDirPath"),value:S},{label:d?b("fileContextMenu.copyFolderName"):b("fileContextMenu.copyFileName"),value:w}],$=(0,r.jsxs)("div",{ref:v,className:"absolute z-[200] bg-card border border-border rounded-lg shadow-lg py-1 w-fit whitespace-nowrap",style:{left:L.x,top:L.y},children:[m&&(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>{h(),m(R)},children:b("fileContextMenu.createFile")}),p&&(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>{h(),p(n)},children:d?b("fileContextMenu.copyFolder"):b("fileContextMenu.copyFile")}),g&&(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>{h(),g(R)},children:b("fileContextMenu.pasteHere")}),f&&(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-destructive hover:bg-accent transition-colors",onClick:()=>{h(),f(n,d,w)},children:d?b("fileContextMenu.deleteFolder"):b("fileContextMenu.deleteFile")}),(m||f||p||g)&&(0,r.jsx)("div",{className:"my-1 border-t border-border"}),T.map((e,t)=>(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>M(e.value,e.label),children:e.label},t))]});return y?(0,a.createPortal)($,y):$}function h(){let[e,t]=(0,s.useState)(null);return{contextMenu:e,showContextMenu:(0,s.useCallback)((e,n,r)=>{e.preventDefault(),e.stopPropagation(),t({x:e.clientX,y:e.clientY,path:n,isDirectory:r})},[]),hideContextMenu:(0,s.useCallback)(()=>{t(null)},[])}}},73395:(e,t,n)=>{n.d(t,{M:()=>ei});var r=n(95155),s=n(12115),l=n(83897),a=n(64428),o=n(34075),i=n(12651),c=n(81165),d=n(16950),u=n(11019),h=n(12612),m=n(79114),f=n(86957),x=n(67589);function p({cwd:e,sessionId:t,toolCall:n,workflowRef:l,onClose:o}){let{t:i}=(0,m.Bd)(),[c,d]=(0,s.useState)(null),[u,h]=(0,s.useState)(null),[g,b]=(0,s.useState)(!1),v=(0,s.useRef)(void 0),y=l?!!l.running:!n?.result,w=(0,s.useCallback)(async()=>{let r=await f.t4.runPromiseExit((0,x.z)({cwd:e,sessionId:t,...l?{workflowId:l.runId,workflowAgentId:l.agentId}:{toolUseId:n?.id},ifFingerprint:v.current}));if(b(!0),"Success"!==r._tag||!r.value)return;let s=r.value;s.fingerprint&&(v.current=s.fingerprint),!s.notModified&&(s.messages&&d(s.messages),s.subagent&&h(s.subagent))},[e,t,n?.id,l?.runId,l?.agentId]);(0,s.useEffect)(()=>{if(w(),!y)return;let e=setInterval(w,5e3);return()=>clearInterval(e)},[y,w]);let k=(0,s.useRef)(null),j=(0,s.useRef)(!0);(0,s.useEffect)(()=>{let e=k.current;e&&j.current&&(e.scrollTop=e.scrollHeight)},[c]);let C="string"==typeof n?.input?.description?n.input.description:"",N=l?l.label||"":[u?.agentType,C].filter(Boolean).join(" \xb7 ");return(0,r.jsx)(a.ZL,{children:(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:o,children:(0,r.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-[90vh] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 px-4 py-3 border-b border-border flex-shrink-0",children:[(0,r.jsx)("span",{className:"text-base",children:"\uD83E\uDD16"}),(0,r.jsx)("span",{className:"font-medium text-sm text-foreground flex-shrink-0",children:i("chat.subagent")}),N&&(0,r.jsx)("span",{className:"text-xs text-muted-foreground truncate flex-1 min-w-0",title:N,children:N}),(0,r.jsxs)("span",{className:"ml-auto flex items-center gap-2 flex-shrink-0",children:[y&&(0,r.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"}),(0,r.jsx)("button",{onClick:o,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:i("common.close"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,r.jsx)("div",{ref:k,onScroll:()=>{let e=k.current;e&&(j.current=e.scrollTop+e.clientHeight>=e.scrollHeight-40)},className:"flex-1 overflow-y-auto px-4 py-3",children:null===c?(0,r.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:i(g?"chat.subagentEmpty":"common.loading")}):c.map(t=>(0,r.jsx)(er,{message:t,cwd:e},t.id))})]})})})}function g(e){return e?e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e):"0"}function b(e){if(!e)return"–";let t=Math.round(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);return`${n}m${t%60}s`}let v={done:"text-green-9",running:"text-brand",queued:"text-muted-foreground",error:"text-red-9",failed:"text-red-9"};function y({cwd:e,sessionId:t,runId:n,isRunning:l,onClose:o}){let{t:i}=(0,m.Bd)(),[c,d]=(0,s.useState)(null),[u,h]=(0,s.useState)(!1),[v,k]=(0,s.useState)(null),j=(0,s.useRef)(void 0),C=l||null!=c&&"completed"!==c.status&&"failed"!==c.status,N=(0,s.useCallback)(async()=>{let r=await f.t4.runPromiseExit((0,x.z)({cwd:e,sessionId:t,workflowId:n,ifFingerprint:j.current}));if(h(!0),"Success"!==r._tag||!r.value)return;let s=r.value;s.fingerprint&&(j.current=s.fingerprint),!s.notModified&&s.workflow&&d(s.workflow)},[e,t,n]);(0,s.useEffect)(()=>{if(N(),!C)return;let e=setInterval(N,5e3);return()=>clearInterval(e)},[C,N]);let S=[];if(c?.agents){let e=new Map;for(let t of c.agents){let n=t.phaseTitle||i("chat.workflowUngrouped");e.has(n)||e.set(n,[]),e.get(n).push(t)}for(let[t,n]of e)S.push({title:t,agents:n})}let L=c?[c.workflowName,c.status,`${c.agentCount??c.agents?.length??0} ${i("chat.workflowAgents")}`,`${g(c.totalTokens)} tok`,b(c.durationMs)].filter(Boolean).join(" \xb7 "):"";return(0,r.jsxs)(a.ZL,{children:[(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:o,children:(0,r.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-[90vh] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 px-4 py-3 border-b border-border flex-shrink-0",children:[(0,r.jsx)("span",{className:"text-base",children:"\uD83E\uDDE9"}),(0,r.jsx)("span",{className:"font-medium text-sm text-foreground flex-shrink-0",children:i("chat.workflowRun")}),L&&(0,r.jsx)("span",{className:"text-xs text-muted-foreground truncate flex-1 min-w-0",title:L,children:L}),(0,r.jsxs)("span",{className:"ml-auto flex items-center gap-2 flex-shrink-0",children:[C&&(0,r.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"}),(0,r.jsx)("button",{onClick:o,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:i("common.close"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,r.jsx)("div",{className:"flex-1 overflow-y-auto px-4 py-3",children:null===c?(0,r.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:i(u?"chat.workflowEmpty":"common.loading")}):(0,r.jsxs)(r.Fragment,{children:[c.summary&&(0,r.jsx)("div",{className:"mb-3 text-xs text-muted-foreground whitespace-pre-wrap",children:c.summary}),S.map(e=>(0,r.jsxs)(s.Fragment,{children:[(0,r.jsx)("div",{className:"text-xs font-semibold text-foreground/80 mt-3 mb-1 sticky top-0 bg-card py-1",children:e.title}),e.agents.map(e=>(0,r.jsx)(w,{agent:e,onOpen:()=>e.agentId&&k({runId:n,agentId:e.agentId,label:e.label,running:"done"!==e.state&&C})},`${e.index}-${e.agentId}`))]},e.title))]})})]})}),v&&(0,r.jsx)(p,{cwd:e,sessionId:t,workflowRef:v,onClose:()=>k(null)})]})}function w({agent:e,onOpen:t}){let{t:n}=(0,m.Bd)(),[l,a]=(0,s.useState)(!1),o=e.state&&v[e.state]||"text-muted-foreground",i=e.resultPreview||e.promptPreview||"";return(0,r.jsxs)("div",{className:"border border-border rounded-md mb-1 bg-secondary/50",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 px-2 py-1.5",children:[(0,r.jsx)("button",{onClick:()=>a(e=>!e),className:"text-slate-9 text-xs flex-shrink-0",title:n(l?"chat.collapse":"chat.expand"),children:l?"▲":"▼"}),(0,r.jsx)("span",{className:"text-xs text-foreground truncate flex-1 min-w-0",title:e.label||"",children:e.label||e.agentId}),(0,r.jsx)("span",{className:`text-[10px] flex-shrink-0 ${o}`,children:e.state}),(0,r.jsxs)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:[g(e.tokens)," tok \xb7 ",b(e.durationMs)]}),e.agentId&&(0,r.jsx)("span",{role:"button",tabIndex:0,onClick:t,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&t()},className:"text-xs text-brand hover:text-teal-10 cursor-pointer flex-shrink-0",title:n("chat.subagentViewTitle"),children:n("chat.workflowViewAgent")})]}),l&&i&&(0,r.jsx)("pre",{className:"text-[11px] bg-secondary px-2 py-1.5 rounded-b overflow-x-auto max-h-32 overflow-y-auto text-muted-foreground whitespace-pre-wrap border-t border-border",children:i})]})}var k=n(60938),j=n(67362),C=n(38408),N=n(13219),S=n(47176),L=n(97251),E=n(56045),M=n(50860),R=n(47215);function T({filePath:e}){let[t,n]=(0,s.useState)(null),[l,a]=(0,s.useState)(!0),[o,i]=(0,s.useState)(null),c=(0,s.useRef)(!1),d=(0,R.e$)(e),u=(0,R.u)(e);return((0,s.useEffect)(()=>{u?a(!1):c.current||(c.current=!0,(async()=>{a(!0),i(null);let t=await f.t4.runPromiseExit((0,k.nM)(e));if("Success"===t._tag)n(t.value.content??null);else{let e="Fail"===t.cause._tag?t.cause.error:null,n=e?.cause;i(n instanceof Error?n.message:"Failed to load file")}a(!1),c.current=!1})())},[e,u]),o)?(0,r.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,r.jsx)("div",{className:"text-xs text-red-11",children:o})}):l?(0,r.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,r.jsx)("span",{className:"text-sm text-muted-foreground",children:"Loading..."})}):(0,R.u)(e)?(0,r.jsx)(M.I,{absPath:e,className:"flex items-center justify-center h-full overflow-auto",imgClassName:"max-w-full max-h-full object-contain",alt:e.split("/").pop()||"image"}):t?d?(0,r.jsx)(I,{content:t}):(0,r.jsx)(C.Cv,{content:t,filePath:e,showLineNumbers:!0,showSearch:!0,className:"h-full"}):(0,r.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,r.jsx)("span",{className:"text-sm text-muted-foreground",children:"No content"})})}let $=[L.W];function I({content:e}){let t=(0,s.useRef)(null);return(0,r.jsxs)("div",{className:"h-full flex",children:[(0,r.jsx)(S.l,{content:e,containerRef:t}),(0,r.jsx)("div",{ref:t,className:"flex-1 overflow-auto p-4",children:(0,r.jsx)(N.T,{content:e,rehypePlugins:$})})]})}function P({title:e,content:t,toolName:n,onClose:l}){let{t:i}=(0,m.Bd)(),c=(0,R.jU)(t),d=(0,R.zs)(t),u=(0,R.oK)(t),h=!!d,f=!!u,[x,p]=(0,s.useState)(("Read"===n||"Write"===n)&&f?"file":h?"diff-unified":c?"readable":"json"),g=(0,s.useRef)(null),b=(0,E.o)(g);(0,s.useEffect)(()=>{let e=e=>{if((e.metaKey||e.ctrlKey)&&"f"===e.key&&"readable"===x&&c){e.preventDefault(),b.open();return}if("Escape"===e.key){if(b.isVisible)return void b.close();document.activeElement instanceof HTMLElement&&document.activeElement.blur(),l()}};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[l,x,c,b]);let v=(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-0 md:p-4",onClick:l,children:(0,r.jsxs)("div",{className:"bg-card shadow-xl w-full max-w-[90%] h-full md:h-[90vh] rounded-none md:rounded-lg flex flex-col transition-all",onClick:e=>e.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("h3",{className:"text-sm font-medium text-foreground",children:e}),u&&(0,r.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(u),(0,o.oR)(i("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:i("common.copyAbsPath"),children:(0,r.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.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,r.jsxs)("div",{className:"flex items-center gap-3",children:[c&&(0,r.jsxs)("div",{className:"flex items-center gap-1 bg-accent rounded p-0.5",children:[h&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{onClick:()=>p("diff-split"),className:`px-2 py-1 text-xs rounded transition-colors ${"diff-split"===x?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,title:i("diffViewer.sideBySide"),children:"Split"}),(0,r.jsx)("button",{onClick:()=>p("diff-unified"),className:`px-2 py-1 text-xs rounded transition-colors ${"diff-unified"===x?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,title:i("diffViewer.unified"),children:"Unified"})]}),f&&(0,r.jsx)("button",{onClick:()=>p("file"),className:`px-2 py-1 text-xs rounded transition-colors ${"file"===x?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,title:i("diffViewer.previewFile"),children:"File"}),(0,r.jsx)("button",{onClick:()=>p("readable"),className:`px-2 py-1 text-xs rounded transition-colors ${"readable"===x?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:i("common.readable")}),(0,r.jsx)("button",{onClick:()=>p("json"),className:`px-2 py-1 text-xs rounded transition-colors ${"json"===x?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:"JSON"})]}),(0,r.jsx)("button",{onClick:l,className:"p-1 text-slate-9 hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,r.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,r.jsx)("div",{className:"flex-1 overflow-auto p-4",children:"file"===x&&u?(0,r.jsx)(T,{filePath:u}):"diff-unified"===x&&d?(0,r.jsx)(j.xU,{oldContent:d.old_string,newContent:d.new_string,filePath:d.file_path}):"diff-split"===x&&d?(0,r.jsx)(j.xZ,{oldContent:d.old_string,newContent:d.new_string,filePath:d.file_path}):"readable"===x&&c?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(E._,{search:b}),(0,r.jsx)("pre",{ref:g,className:"text-foreground whitespace-pre-wrap break-words",style:{fontSize:"0.8125rem"},children:(0,R.xb)(t)})]}):(0,r.jsx)("pre",{className:"text-foreground whitespace-pre-wrap break-words",style:{fontSize:"0.8125rem"},children:c?(0,R.C6)(t):t})})]})});return(0,r.jsx)(a.ZL,{children:v})}let A={Read:"\uD83D\uDCC4",Write:"✏️",Edit:"\uD83D\uDCDD",Bash:"\uD83D\uDCBB",Glob:"\uD83D\uDD0D",Grep:"\uD83D\uDD0E",WebFetch:"\uD83C\uDF10",WebSearch:"\uD83D\uDD0D",Workflow:"\uD83E\uDDE9",Skill:"\uD83D\uDEE0️"};function _({toolCall:e,cwd:t,sessionId:n}){var l;let{t:a}=(0,m.Bd)(),[i,c]=(0,s.useState)(!1),[d,u]=(0,s.useState)(null),[h,f]=(0,s.useState)(!1),[x,g]=(0,s.useState)(!1),b=A[e.name]||"\uD83D\uDD27",v="Agent"===e.name||"Task"===e.name,w=v&&!!t&&!!n,k="Workflow"===e.name,j=k&&(l=e.result)?l.match(/subagents\/workflows\/(wf_[A-Za-z0-9_-]+)/)?.[1]??null:null,C=k&&!!j&&!!t&&!!n,N="Skill"===e.name,S=v||k||N,L=(()=>{let t=e.input;if("Bash"===e.name&&t.command&&"string"==typeof t.command)return t.command;if(v&&t.description&&"string"==typeof t.description)return t.description;if(k){let e=["string"==typeof t.name?t.name:"","string"==typeof t.args?t.args:"string"==typeof t.resumeFromRunId?t.resumeFromRunId:""].filter(Boolean).join(" \xb7 ");if(e)return e}if(N&&"string"==typeof t.skill){let e="string"==typeof t.args?t.args:"";return[t.skill,e].filter(Boolean).join(" \xb7 ")}return"Glob"===e.name&&t.pattern&&"string"==typeof t.pattern||"Grep"===e.name&&t.pattern&&"string"==typeof t.pattern?t.pattern:"ToolSearch"===e.name&&t.query&&"string"==typeof t.query?t.query:"TaskCreate"===e.name&&t.subject&&"string"==typeof t.subject?t.subject:t.file_path&&"string"==typeof t.file_path?t.file_path:t.path&&"string"==typeof t.path?t.path:null})(),E="Glob"===e.name||"Grep"===e.name||"Bash"===e.name||v||k||N,M=L?E?L:(e=>{if(t&&e.startsWith(t)){let n=e.slice(t.length);return n.startsWith("/")?n.slice(1):n}let n=e.split("/");return n.length>2?".../"+n.slice(-2).join("/"):e})(L):null,R=t=>{let n="input"===t?a("toolCall.inputParams"):a("toolCall.resultLabel"),r="input"===t?JSON.stringify(e.input,null,2):"string"==typeof e.result?e.result:JSON.stringify(e.result,null,2);u({title:`${e.name}${M?` ${M}`:""} - ${n}`,content:r,toolName:e.name})};return(0,r.jsxs)("div",{className:"my-1 border border-border rounded-lg overflow-hidden bg-secondary",children:[(0,r.jsxs)("button",{onClick:()=>c(!i),className:"w-full px-3 py-1.5 flex items-center gap-2 text-left hover:bg-accent transition-colors",children:[(0,r.jsx)("span",{className:"text-sm",children:b}),(0,r.jsx)("span",{className:"font-medium text-sm text-foreground flex-shrink-0",children:e.name}),M&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"text-xs text-muted-foreground truncate flex-1 min-w-0",title:L||"",children:M}),!S&&(0,r.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),L&&(navigator.clipboard.writeText(L),(0,o.oR)(a("common.copiedPath")))},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),L&&(navigator.clipboard.writeText(L),(0,o.oR)(a("common.copiedPath"))))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0 cursor-pointer",title:a("common.copyAbsPath"),children:(0,r.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.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,r.jsxs)("span",{className:"ml-auto flex items-center gap-2",children:[w&&(0,r.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),f(!0)},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),f(!0))},className:"text-xs text-brand hover:text-teal-10 cursor-pointer",title:a("chat.subagentViewTitle"),children:a("chat.subagent")}),C&&(0,r.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),g(!0)},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),g(!0))},className:"text-xs text-brand hover:text-teal-10 cursor-pointer",title:a("chat.workflowViewTitle"),children:a("chat.workflowRun")}),i&&!e.isLoading&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),R("input")},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),R("input"))},className:"text-xs text-brand hover:text-teal-10 cursor-pointer",title:a("toolCall.inputParamsTitle"),children:a("toolCall.input")}),e.result&&(0,r.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),R("result")},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),R("result"))},className:"text-xs text-brand hover:text-teal-10 cursor-pointer",title:a("toolCall.resultTitle"),children:a("toolCall.result")})]}),e.isLoading?(0,r.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"}):(0,r.jsx)("span",{className:"text-slate-9 text-xs",children:i?"▲":"▼"})]})]}),i&&(0,r.jsxs)("div",{className:"border-t border-border",children:[(0,r.jsxs)("div",{className:"px-3 py-2",children:[(0,r.jsx)("div",{className:"mb-1",children:(0,r.jsxs)("span",{className:"text-xs text-muted-foreground",children:[a("toolCall.inputParams"),":"]})}),(0,r.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,r.jsxs)("div",{className:"px-3 py-2 border-t border-border",children:[(0,r.jsx)("div",{className:"mb-1",children:(0,r.jsxs)("span",{className:"text-xs text-muted-foreground",children:[a("toolCall.resultLabel"),":"]})}),(0,r.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)})]}),e.skillContent&&(0,r.jsxs)("div",{className:"px-3 py-2 border-t border-border",children:[(0,r.jsx)("div",{className:"mb-1",children:(0,r.jsxs)("span",{className:"text-xs text-muted-foreground",children:[a("toolCall.skillContent",{defaultValue:"Skill content"}),":"]})}),(0,r.jsx)("pre",{className:"text-xs bg-secondary p-2 rounded overflow-x-auto max-h-60 overflow-y-auto text-foreground whitespace-pre-wrap",children:e.skillContent})]})]}),d&&(0,r.jsx)(P,{title:d.title,content:d.content,toolName:d.toolName,onClose:()=>u(null)}),h&&t&&n&&(0,r.jsx)(p,{cwd:t,sessionId:n,toolCall:e,onClose:()=>f(!1)}),x&&t&&n&&j&&(0,r.jsx)(y,{cwd:t,sessionId:n,runId:j,isRunning:!!e.isLoading,onClose:()=>g(!1)})]})}var D=n(56204),F=n(67635),W=n(33210),B=n(58515),V=n(36201),O=n(55804),z=n(37618);function H(e){let t=e.input?.questions||[],n=e.input?.answers||{},r={};if(e.result)try{let t=JSON.parse(e.result);t?.answers&&(r=t.answers)}catch{}return{questions:t,answers:{...n,...r}}}function K(e,t){return`${e}-${t}`}function U({toolCalls:e,onClose:t}){let{t:n}=(0,m.Bd)(),i=(0,l.nH)(),[c,d]=(0,s.useState)({}),[u,h]=(0,s.useState)({}),[f,x]=(0,s.useState)({}),[p,g]=(0,s.useState)({});(0,s.useEffect)(()=>{let t={};e.forEach((e,n)=>{let{questions:r,answers:s}=H(e);r.forEach((e,r)=>{let l=s[e.question];if(l){let s=K(n,r);t[s]=l,e.options.some(e=>e.label===l)||(h(e=>({...e,[s]:!0})),x(e=>({...e,[s]:l})))}})}),queueMicrotask(()=>d(t))},[e]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&t()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[t]);let b=e.reduce((e,t)=>{let{questions:n}=H(t);return e+n.length},0),v=Object.values(p).filter(Boolean).length,y=(0,s.useCallback)((e,t)=>{d(n=>({...n,[e]:t})),h(t=>({...t,[e]:!1}))},[]),w=(0,s.useCallback)(e=>{h(t=>{let n=!t[e];if(n){let t=f[e]||"";t&&d(n=>({...n,[e]:t}))}return{...t,[e]:n}})},[f]),k=(0,s.useCallback)((e,t)=>{x(n=>({...n,[e]:t})),t&&d(n=>({...n,[e]:t}))},[]),j=(0,s.useCallback)(e=>{g(t=>({...t,[e]:!t[e]}))},[]),C=(0,s.useCallback)(()=>{let t=v>0,r=[];return e.forEach((e,s)=>{let{questions:l}=H(e);l.forEach((e,l)=>{let a=K(s,l);if(t&&!p[a])return;let o=c[a];r.push(`Q: ${e.question}`),r.push(`A: ${o||n("askQuestion.notSelected")}`),r.push("")})}),r.join("\n").trim()},[e,c,p,v,n]),N=(0,s.useCallback)(()=>{navigator.clipboard.writeText(C()),(0,o.oR)(v>0?n("toast.copiedQA",{count:v}):n("toast.copiedAllQA"))},[C,v,n]),S=(0,s.useCallback)(()=>{i?(i.sendMessage(C()),(0,o.oR)(n("toast.sentQA")),t()):(0,o.oR)(n("askQuestion.sendNoChat"))},[i,C,t,n]),L=(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:t,children:(0,r.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,r.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border flex-shrink-0",children:[(0,r.jsxs)("div",{className:"flex items-center gap-3",children:[(0,r.jsx)("h3",{className:"text-sm font-medium text-foreground",children:n("askQuestion.title")}),(0,r.jsxs)("span",{className:"text-xs text-muted-foreground",children:[n("askQuestion.nQuestions",{count:b}),v>0&&` \xb7 ${n("askQuestion.checkedN",{count:v})}`]})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("button",{onClick:S,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:v>0?n("askQuestion.sendChecked",{count:v}):n("askQuestion.sendAll"),children:(0,r.jsx)(D.A,{className:"w-4 h-4"})}),(0,r.jsx)("button",{onClick:N,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:v>0?n("askQuestion.copyChecked",{count:v}):n("askQuestion.copyAll"),children:(0,r.jsx)(F.A,{className:"w-4 h-4"})}),(0,r.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,r.jsx)(W.A,{className:"w-5 h-5"})})]})]}),(0,r.jsx)("div",{className:"flex-1 overflow-y-auto px-6 py-4 space-y-6",children:e.map((t,s)=>{let{questions:l}=H(t);return l.map((t,a)=>{let o=K(s,a),i=c[o],d=u[o]||!1,h=p[o]||!1;return(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsxs)("div",{className:"flex items-start gap-2",children:[(0,r.jsx)("button",{onClick:()=>j(o),className:"mt-0.5 flex-shrink-0 p-0.5 rounded hover:bg-accent transition-colors",title:n("askQuestion.checkToCopy"),children:h?(0,r.jsx)(B.A,{className:"w-4 h-4 text-brand"}):(0,r.jsx)(V.A,{className:"w-4 h-4 text-muted-foreground"})}),t.header&&(0,r.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,r.jsx)("span",{className:"text-sm font-medium text-foreground",children:t.question})]}),(0,r.jsxs)("div",{className:"space-y-1 ml-7",children:[t.options.map((e,t)=>{let n=i===e.label&&!d;return(0,r.jsxs)("button",{onClick:()=>y(o,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 ${n?"bg-brand/10 hover:bg-brand/15":""}`,children:[(0,r.jsx)("div",{className:"mt-0.5 flex-shrink-0",children:n?(0,r.jsx)(O.A,{className:"w-3.5 h-3.5 text-brand"}):(0,r.jsx)("div",{className:"w-3.5 h-3.5 rounded-full border border-muted-foreground"})}),(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsx)("div",{className:`text-sm ${n?"text-foreground font-medium":"text-foreground"}`,children:e.label}),e.description&&(0,r.jsx)("div",{className:"text-xs text-muted-foreground mt-0.5",children:e.description})]})]},t)}),(0,r.jsxs)("button",{onClick:()=>w(o),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 ${d?"bg-brand/10 hover:bg-brand/15":""}`,children:[(0,r.jsx)("div",{className:"mt-0.5 flex-shrink-0",children:d?(0,r.jsx)(O.A,{className:"w-3.5 h-3.5 text-brand"}):(0,r.jsx)("div",{className:"w-3.5 h-3.5 rounded-full border border-muted-foreground"})}),(0,r.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,r.jsx)(z.A,{className:"w-3.5 h-3.5 text-muted-foreground"}),(0,r.jsx)("span",{className:"text-sm text-muted-foreground",children:n("askQuestion.custom")})]})]}),d&&(0,r.jsx)("div",{className:"ml-6 mt-1",children:(0,r.jsx)("input",{type:"text",autoFocus:!0,value:f[o]||"",onChange:e=>k(o,e.target.value),placeholder:n("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!==l.length-1)&&(0,r.jsx)("div",{className:"border-b border-border/50 mt-3"})]},o)})})})]})});return(0,r.jsx)(a.ZL,{children:L})}var q=n(65992),X=n(9573);let Z=new Set(["Read","Grep","Glob","LS","WebSearch","WebFetch","NotebookRead","TodoRead","AskUserQuestion","ExitPlanMode","TodoWrite","Skill"]);var G=n(5135),J=n(38175),Y=n(70188),Q=n(83448);function ee({image:e,onClose:t}){let{t:n}=(0,m.Bd)(),s=(0,r.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80",onClick:t,children:[(0,r.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,r.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),(0,r.jsx)("img",{src:`data:${e.media_type};base64,${e.data}`,alt:n("chat.imagePreview"),className:"max-w-[90vw] max-h-[90vh] object-contain",onClick:e=>e.stopPropagation()})]});return(0,r.jsx)(a.ZL,{children:s})}function et({filePath:e,content:t,cwd:n,onClose:l}){let[o,i]=(0,s.useState)(null);return(0,r.jsx)(a.ZL,{children:(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-0 md:p-4",onClick:l,children:(0,r.jsx)("div",{ref:i,className:"bg-card shadow-xl w-full h-full rounded-none md:max-w-[90%] md:h-[90vh] md:rounded-lg flex flex-col relative",onClick:e=>e.stopPropagation(),children:(0,r.jsx)(Y.SU,{container:o,children:(0,r.jsx)(G.M,{content:t,filePath:e,cwd:n,onClose:l})})})})})}function en({filePath:e,content:t,cwd:n,onClose:s,onContentSearch:l}){let{t:i}=(0,m.Bd)();return(0,r.jsx)(a.ZL,{children:(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-0 md:p-4",onClick:s,children:(0,r.jsxs)("div",{className:"bg-card shadow-xl w-full h-full rounded-none md:max-w-[90%] md:h-[90vh] md:rounded-lg flex flex-col relative overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center justify-between gap-3 px-4 py-2 border-b border-border flex-shrink-0",children:[(0,r.jsxs)("span",{className:"text-sm text-muted-foreground truncate min-w-0 flex-1 cursor-pointer hover:text-foreground transition-colors",style:{direction:"rtl",textAlign:"left"},title:e,onClick:()=>{navigator.clipboard.writeText(e),(0,o.oR)(i("common.copiedPath"))},children:["",e]}),(0,r.jsx)("button",{onClick:s,className:"text-muted-foreground hover:text-foreground px-1.5 py-0.5 rounded hover:bg-accent transition-colors flex-shrink-0",children:"✕"})]}),(0,r.jsx)("div",{className:"flex-1 overflow-hidden",children:(0,r.jsx)(J.E,{content:t,filePath:e,cwd:n,onContentSearch:l?e=>{l(e),s()}:void 0})})]})})})}let er=(0,s.memo)(function({message:e,cwd:t,sessionId:n,onFork:l,onApprovePlan:x,isLoading:p,onContentSearch:g,onShowFileDiff:b}){let v,y,w,k,{t:j}=(0,m.Bd)(),[C,S]=(0,s.useState)(null),[L,E]=(0,s.useState)(()=>1===(e.toolCalls?.length||0)),[M,T]=(0,s.useState)(!1),[$,I]=(0,s.useState)(!1),[P,A]=(0,s.useState)(!1),D="user"===e.role,F=e.images&&e.images.length>0,W=e.toolCalls?.length||0,B=!!n&&!!t&&!!l,V=(0,s.useMemo)(()=>e.toolCalls?.some(e=>{let t;return t=e.name,!Z.has(t)})||!1,[e.toolCalls]),O=(0,s.useMemo)(()=>(0,q.vP)([],e.toolCalls??[],t).length>0,[e.toolCalls,t]),[z,H]=(0,s.useState)(!1),K=O||z;(0,s.useEffect)(()=>{if(!V||O||!t)return;let n=(e.toolCalls??[]).map(e=>e.id).filter(Boolean);if(0===n.length)return;let r=(e.toolCalls??[]).filter(e=>["Edit","Write","MultiEdit","NotebookEdit"].includes(e.name)).map(e=>e.id),s=!1,l=null,a=0,o=()=>{f.t4.runPromiseExit((0,X.xK)(t,n)).then(e=>{if(s)return;let t="Success"===e._tag?e.value:[];if(t.length>0)return void H(!0);let n=new Set(t.map(e=>e.toolId));r.some(e=>!n.has(e))&&a<2&&(a+=1,l=setTimeout(o,2e3))})};return o(),()=>{s=!0,l&&clearTimeout(l)}},[V,O,t,e.toolCalls]);let G=(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]),J=(0,s.useMemo)(()=>e.toolCalls?e.toolCalls.filter(e=>"AskUserQuestion"===e.name):[],[e.toolCalls]),Y=(0,s.useMemo)(()=>{if(!e.toolCalls)return null;for(let t=e.toolCalls.length-1;t>=0;t--)if("ExitPlanMode"===e.toolCalls[t].name){let n=e.toolCalls[t].input?.plan;return"string"==typeof n&&n?n:null}return null},[e.toolCalls]),er=(0,s.useMemo)(()=>e.toolCalls?.filter(e=>"ExitPlanMode"!==e.name)??[],[e.toolCalls]),es=(0,s.useMemo)(()=>{if(!e.toolCalls)return[];let t=new Set,n=[];for(let r of e.toolCalls)if("Read"===r.name||"Edit"===r.name||"Write"===r.name){let e=r.input.file_path;e&&((0,R.e$)(e)||(0,R.aR)(e))&&!t.has(e)&&(t.add(e),n.push(e))}return n},[e.toolCalls]),el=(0,s.useMemo)(()=>{if(!e.toolCalls)return[];let t=[];for(let n of e.toolCalls){let e=n.input?.thought;if(e&&"string"==typeof e){let r=e.match(/PREVIOUS:\s*(.*?)\s*→\s*THIS:\s*(.*?)\s*→\s*EXPECT:\s*(.*)/i);r?t.push({previous:r[1].trim(),current:r[2].trim(),expect:r[3].trim(),raw:e,toolName:n.name}):t.push({previous:"",current:e,expect:"",raw:e,toolName:n.name})}}return t},[e.toolCalls]),[ea,eo]=(0,s.useState)(null),[ei,ec]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!ea)return void queueMicrotask(()=>ec(null));let e=!1;return f.t4.runPromiseExit((0,Q.an)(ea)).then(t=>{e||("Success"===t._tag&&void 0!==t.value.content?ec(t.value.content):((0,o.oR)(j("toast.readFileFailed"),"error"),eo(null)))}),()=>{e=!0}},[ea,j]);let ed=()=>{e.content&&(navigator.clipboard.writeText(e.content),(0,o.oR)(j("toast.copiedMessage")))},eu=()=>{B&&l(e.id)},eh=(e=>{if(!e)return"";let t=new Date(e);if(isNaN(t.getTime()))return"";let n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),l=String(t.getMinutes()).padStart(2,"0");return`${n}-${r} ${s}:${l}`})(e.timestamp);if("system"===e.role){let t=e.systemEvent,n=t?.kind==="task-notification"?"failed"===t.status?"⚠️":"stopped"===t.status?"⏹️":"\uD83D\uDD14":"ℹ️",s=t?.detail||e.content;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"flex justify-center my-2 px-2","data-role":"system",children:(0,r.jsxs)("button",{type:"button",onClick:()=>A(!0),className:"flex items-center gap-1.5 max-w-[85%] text-[11px] text-muted-foreground bg-secondary/40 border border-border/50 rounded-full px-3 py-1 hover:bg-secondary hover:text-foreground transition-colors cursor-pointer",title:j("chat.viewDetails",{defaultValue:"Click for details"}),children:[(0,r.jsx)("span",{className:"flex-shrink-0",children:n}),(0,r.jsx)("span",{className:"truncate",children:e.content})]})}),P&&(0,r.jsx)(a.ZL,{children:(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:()=>A(!1),children:(0,r.jsxs)("div",{className:"bg-card shadow-xl w-full max-w-4xl max-h-[80vh] rounded-lg flex flex-col overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border flex-shrink-0",children:[(0,r.jsxs)("span",{className:"text-sm text-foreground flex items-center gap-1.5",children:[(0,r.jsx)("span",{children:n}),t?.kind==="task-notification"?j("chat.taskNotification",{defaultValue:"Task notification"}):j("chat.systemNotice",{defaultValue:"Notice"})]}),(0,r.jsx)("button",{onClick:()=>A(!1),className:"text-muted-foreground hover:text-foreground px-1.5 py-0.5 rounded hover:bg-accent transition-colors",children:"✕"})]}),(0,r.jsx)("pre",{className:"flex-1 overflow-auto px-4 py-3 text-xs text-foreground whitespace-pre-wrap break-words",children:s})]})})})]})}return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:`flex flex-col ${D?"items-end":"items-start"} mb-4 group`,"data-role":e.role,children:[eh&&(0,r.jsx)("span",{className:"text-[11px] text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity mb-0.5 px-1",children:eh}),(0,r.jsxs)("div",{className:`flex ${D?"justify-end":"justify-start"} w-full`,children:[D&&(0,r.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,r.jsx)("button",{onClick:ed,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:j("chat.copyMessage"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.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"})})}),B&&(0,r.jsx)("button",{onClick:eu,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:j("chat.forkSession"),children:(0,r.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("circle",{cx:"12",cy:"18",r:"3"}),(0,r.jsx)("circle",{cx:"6",cy:"6",r:"3"}),(0,r.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,r.jsx)("path",{d:"M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9"}),(0,r.jsx)("path",{d:"M12 12v3"})]})})]}),(0,r.jsxs)("div",{className:`max-w-[80%] ${D?"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:[F&&(0,r.jsx)("div",{className:`flex flex-wrap gap-2 ${e.content?"mb-2":""}`,children:e.images.map((e,t)=>(0,r.jsx)("div",{className:"relative w-16 h-16 rounded-lg overflow-hidden border border-white/20 cursor-pointer hover:opacity-90 transition-opacity",onClick:()=>S(e),children:(0,r.jsx)("img",{src:`data:${e.media_type};base64,${e.data}`,alt:j("chat.imageN",{index:t+1}),className:"w-full h-full object-cover"})},t))}),e.content&&(0,r.jsxs)("div",{className:"break-words",children:[(0,r.jsx)(N.T,{content:e.content,isUser:D,isStreaming:e.isStreaming,enableMath:!1}),e.isStreaming&&(0,r.jsx)("span",{className:"inline-block w-2 h-4 ml-1 bg-current animate-pulse"})]}),G&&(w=(y=Array.isArray(v=G.input?.todos)?v:[]).filter(e=>"completed"===e.status).length,k=y.length,(0,r.jsx)("div",{className:`${e.content||F?"mt-2":""}`,children:(0,r.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden bg-secondary/50 px-3 py-2 space-y-1",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 mb-1.5",children:[(0,r.jsx)("div",{className:"flex-1 h-1 bg-secondary rounded-full overflow-hidden",children:(0,r.jsx)("div",{className:"h-full bg-green-500 rounded-full transition-all duration-300",style:{width:`${k>0?w/k*100:0}%`}})}),(0,r.jsxs)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:[w,"/",k]})]}),y.map((e,t)=>(0,r.jsxs)("div",{className:`flex items-center gap-1.5 ${"completed"===e.status?"opacity-50":""}`,children:["completed"===e.status?(0,r.jsx)(i.A,{className:"w-3 h-3 text-green-500 flex-shrink-0"}):"in_progress"===e.status?(0,r.jsx)(c.A,{className:"w-3 h-3 text-brand flex-shrink-0 animate-spin"}):(0,r.jsx)(d.A,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"}),(0,r.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))]})})),Y&&(0,r.jsx)("div",{className:`${e.content||F||G?"mt-2":""}`,children:(0,r.jsxs)("div",{className:"border border-brand/40 rounded-lg overflow-hidden bg-secondary/50",children:[(0,r.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-1.5 border-b border-border bg-brand/10",children:[(0,r.jsx)("span",{className:"text-sm",children:"\uD83D\uDCCB"}),(0,r.jsx)("span",{className:"text-xs font-medium text-foreground",children:j("chat.planTitle",{defaultValue:"Plan (awaiting your review)"})})]}),(0,r.jsx)("div",{className:"px-3 py-2",children:(0,r.jsx)(N.T,{content:Y,isUser:!1,enableMath:!1})}),x&&(0,r.jsxs)("div",{className:"px-3 py-2 border-t border-border flex items-center justify-between gap-2",children:[(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:j("chat.planApproveHint",{defaultValue:"本环境无审批弹窗,点此退出 Plan 并执行"})}),(0,r.jsxs)("button",{onClick:()=>x(),disabled:p,className:"flex items-center gap-1.5 px-3 py-1 rounded-md bg-brand text-white text-xs font-medium hover:bg-brand/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors flex-shrink-0",children:[(0,r.jsx)("span",{children:"✓"}),(0,r.jsx)("span",{children:j("chat.approvePlan",{defaultValue:"批准并执行"})})]})]})]})}),es.length>0&&(0,r.jsx)("div",{className:`${e.content||F||G?"mt-2":""}`,children:(0,r.jsx)("div",{className:"border border-border rounded-lg overflow-hidden bg-secondary/50 px-3 py-2 space-y-0.5",children:es.map(e=>(0,r.jsxs)("button",{onClick:()=>eo(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,R.aR)(e)?(0,r.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,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4"})}):(0,r.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,r.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,r.jsx)("span",{className:"text-xs text-muted-foreground group-hover/md:text-foreground truncate",children:e.split("/").pop()})]},e))})}),el.length>0&&(0,r.jsx)("div",{className:`${e.content||F||G||es.length>0?"mt-2":""}`,children:(0,r.jsx)("div",{className:"border border-border rounded-lg overflow-hidden bg-secondary/50",children:(0,r.jsxs)("table",{className:"w-full text-xs",children:[(0,r.jsx)("thead",{children:(0,r.jsxs)("tr",{className:"border-b border-border text-muted-foreground",children:[(0,r.jsx)("th",{className:"px-2 py-1.5 text-left font-medium w-[60px]",children:"Tool"}),(0,r.jsx)("th",{className:"px-2 py-1.5 text-left font-medium",children:"Previous"}),(0,r.jsx)("th",{className:"px-2 py-1.5 text-left font-medium",children:"Action"}),(0,r.jsx)("th",{className:"px-2 py-1.5 text-left font-medium",children:"Expect"})]})}),(0,r.jsx)("tbody",{children:el.map((e,t)=>(0,r.jsxs)("tr",{className:t<el.length-1?"border-b border-border/50":"",children:[(0,r.jsx)("td",{className:"px-2 py-1 text-muted-foreground font-mono",children:e.toolName}),(0,r.jsx)("td",{className:"px-2 py-1 text-muted-foreground",children:e.previous||"—"}),(0,r.jsx)("td",{className:"px-2 py-1 text-foreground",children:e.current}),(0,r.jsx)("td",{className:"px-2 py-1 text-muted-foreground",children:e.expect||"—"})]},t))})]})})}),er.length>0&&(0,r.jsx)("div",{className:`${e.content||F?"mt-2":""}`,children:W>0?(0,r.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden bg-secondary",children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsxs)("button",{onClick:()=>E(!L),className:"flex-1 px-3 py-1.5 flex items-center gap-2 text-left hover:bg-accent transition-colors active:bg-muted",children:[(0,r.jsx)("span",{className:"text-sm",children:"\uD83D\uDD27"}),(0,r.jsx)("span",{className:"font-medium text-foreground",children:j("chat.toolCalls",{count:er.length})}),(0,r.jsx)("span",{className:"ml-auto text-muted-foreground text-sm",children:L?j("chat.collapse"):j("chat.expand")})]}),J.length>0&&(0,r.jsx)("button",{onClick:()=>I(!0),className:"px-3 py-1.5 text-muted-foreground hover:text-foreground hover:bg-accent transition-colors border-l border-border",title:j("chat.viewQuestions"),children:(0,r.jsx)(u.A,{className:"w-4 h-4"})}),K&&(0,r.jsx)("button",{onClick:()=>{b&&e.toolCalls?b(e.toolCalls,t):T(!0)},className:"px-3 py-1.5 text-muted-foreground hover:text-foreground hover:bg-accent transition-colors border-l border-border",title:j("chat.viewAllFileChanges"),children:(0,r.jsx)(h.A,{className:"w-4 h-4"})})]}),L&&(0,r.jsx)("div",{className:"border-t border-border p-2 space-y-1",children:er.map((e,s)=>(0,r.jsx)(_,{toolCall:e,cwd:t,sessionId:n},`${e.id}-${s}`))})]}):er.map((e,s)=>(0,r.jsx)(_,{toolCall:e,cwd:t,sessionId:n},`${e.id}-${s}`))})]}),!D&&(0,r.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,r.jsx)("button",{onClick:ed,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:j("chat.copyMessage"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.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"})})}),B&&(0,r.jsx)("button",{onClick:eu,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:j("chat.forkSession"),children:(0,r.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("circle",{cx:"12",cy:"18",r:"3"}),(0,r.jsx)("circle",{cx:"6",cy:"6",r:"3"}),(0,r.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,r.jsx)("path",{d:"M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9"}),(0,r.jsx)("path",{d:"M12 12v3"})]})})]})]})]}),C&&(0,r.jsx)(ee,{image:C,onClose:()=>S(null)}),M&&e.toolCalls&&(0,r.jsx)(q.zB,{toolCalls:e.toolCalls,cwd:t,onClose:()=>T(!1)}),$&&J.length>0&&(0,r.jsx)(U,{toolCalls:J,onClose:()=>I(!1)}),ea&&null!==ei&&((0,R.aR)(ea)?(0,r.jsx)(en,{filePath:ea,content:ei,cwd:t,onClose:()=>eo(null),onContentSearch:g}):(0,r.jsx)(et,{filePath:ea,content:ei,cwd:t||"",onClose:()=>eo(null)}))]})});var es=n(1058),el=n(90717),ea=n(89109),eo=n(7320);let ei=(0,s.forwardRef)(function({messages:e,isLoading:t,cwd:n,sessionId:a,engine:o,apiRetryInfo:i,ptyNotice:c,hasMoreHistory:d,isLoadingMore:u,onLoadMore:h,onFork:f,isActive:x=!0,onContentSearch:p,onShowFileDiff:g,onApprovePlan:b},v){let{t:y}=(0,m.Bd)(),w=(0,s.useRef)(null),k=(0,s.useRef)(null),j=(0,s.useRef)(null),C=(0,s.useRef)(null),[N,S]=(0,s.useState)(null),[L,E]=(0,s.useState)(!0),[M,R]=(0,s.useState)(!1),[T,$]=(0,s.useState)(!1);(0,s.useEffect)(()=>{S(C.current)},[]);let{isSearchVisible:I,searchQuery:P,setSearchQuery:A,matches:_,currentMatchIndex:D,goToNextMatch:F,goToPrevMatch:W,closeSearch:B,searchInputRef:V,handleSearchKeyDown:O}=function(e){let[t,n]=(0,s.useState)(!1),[r,l]=(0,s.useState)(""),[a,o]=(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){o([]),c(0);return}let n=[],r=[],s=t.toLowerCase();e.current.querySelectorAll("[data-message-id]").forEach(e=>{let l,a=e.getAttribute("data-message-id")||"",o=0,i=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,null),c=[];for(;l=i.nextNode();)c.push(l);for(let e of c){let l=(e.textContent||"").toLowerCase(),i=0,c=[];for(;;){let e=l.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 l=e.splitText(s.start),i=document.createElement("mark");i.className="chat-search-match",i.textContent=l.textContent,l.parentNode.replaceChild(i,l),n.push({messageId:a,markIndex:o}),r.push(i),o++}}}),n.reverse(),r.reverse(),u.current=r,o(n),c(n.length>0?0:-1)},[e,h]);(0,s.useEffect)(()=>{queueMicrotask(()=>m(r))},[r,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,a]);let f=(0,s.useCallback)(()=>{0!==a.length&&c(e=>(e+1)%a.length)},[a.length]),x=(0,s.useCallback)(()=>{0!==a.length&&c(e=>(e-1+a.length)%a.length)},[a.length]),p=(0,s.useCallback)(()=>{n(!0),setTimeout(()=>d.current?.focus(),0)},[]),g=(0,s.useCallback)(()=>{n(!1),l(""),h(),o([]),c(0)},[h]),b=(0,s.useCallback)(e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?x():f()),"Escape"===e.key&&g()},[f,x,g]);return(0,s.useEffect)(()=>{let t=e.current;if(!t)return;let n=e=>{(e.metaKey||e.ctrlKey)&&"f"===e.key&&(e.preventDefault(),e.stopPropagation(),p())};return t.addEventListener("keydown",n),()=>t.removeEventListener("keydown",n)},[e,p]),{isSearchVisible:t,searchQuery:r,setSearchQuery:l,matches:a,currentMatchIndex:i,goToNextMatch:f,goToPrevMatch:x,openSearch:p,closeSearch:g,searchInputRef:d,handleSearchKeyDown:b}}(C),z=(0,l.nH)(),H=(0,s.useRef)(null),K=(0,s.useRef)(()=>{}),{addComment:U,refresh:q}=(0,es._)({cwd:n||"",filePath:el.Un}),[X,Z]=(0,s.useState)(null),[G,J]=(0,s.useState)(null),Y=(0,s.useCallback)(e=>{if(X||G)return;let t=window.getSelection();if(!t||t.isCollapsed||!t.rangeCount){H.current=null,K.current();return}let n=t.toString().trim();if(!n){H.current=null,K.current();return}let r=t.anchorNode instanceof HTMLElement?t.anchorNode:t.anchorNode?.parentElement;if(r?.closest('[data-role="user"]')){H.current=null,K.current();return}H.current={x:e.clientX,y:e.clientY,range:{start:0,end:0},selectedText:n,lineSnapshot:n},K.current()},[X,G]),Q=(0,s.useCallback)(e=>{let t=e.target;!(t.closest(".floating-toolbar")||t.closest('[class*="z-[200]"]'))&&H.current&&(H.current=null,K.current())},[]),ee=(0,s.useCallback)(()=>{let e=H.current;e&&(Z({x:e.x,y:e.y,text:e.selectedText}),H.current=null,K.current(),window.getSelection()?.removeAllRanges())},[]),et=(0,s.useCallback)(()=>{let e=H.current;e&&(J({x:e.x,y:e.y,text:e.selectedText}),H.current=null,K.current(),window.getSelection()?.removeAllRanges())},[]),en=(0,s.useCallback)(()=>{let e=H.current;if(!e||!p)return;let t=e.selectedText.trim();H.current=null,K.current(),window.getSelection()?.removeAllRanges(),t&&p(t)},[p]),ei=(0,s.useCallback)(async e=>{X&&(await U(0,0,e,X.text),Z(null))},[X,U]),ec=(0,s.useCallback)(async(e,t)=>{if(z&&n)try{let r=(await (0,el.$3)(n)).map(e=>({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0}));r.push({filePath:el.Un,startLine:0,endLine:0,codeContent:e});let s=(0,el.Gw)(r,t);z.sendMessage(s),await (0,el.RP)(n),q()}catch(e){console.error("Failed to send to AI:",e)}},[z,n,q]),ed=(0,s.useCallback)(e=>{G&&ec(G.text,e)},[G,ec]),eu=(0,s.useCallback)(e=>{X&&ec(X.text,e)},[X,ec]),eh=(0,s.useMemo)(()=>{let t=new Set;return e.filter(e=>!t.has(e.id)&&(t.add(e.id),!0))},[e]),em=(0,s.useRef)(0),ef=(0,s.useRef)(!1),ex=(0,s.useCallback)(()=>{let e=j.current;return!e||e.scrollHeight-e.scrollTop-e.clientHeight<50},[]),ep=(0,s.useCallback)(()=>{let e=j.current;return!e||e.scrollTop<50},[]),eg=(0,s.useCallback)(()=>{let e=ex(),t=ep();if(E(e),R(!t),$(!e),t&&d&&!u&&h){let e=j.current;e&&(em.current=e.scrollHeight,ef.current=!0),h()}},[ex,ep,d,u,h]),eb=(0,s.useCallback)(()=>{k.current?.scrollIntoView({behavior:"smooth"})},[]),ev=(0,s.useCallback)(()=>{w.current?.scrollIntoView({behavior:"smooth"})},[]),ey=(0,s.useCallback)(e=>{let t=j.current;if(!t)return;let n=t.querySelector(`[data-message-id="${e}"]`);n&&(n.scrollIntoView({behavior:"smooth",block:"center"}),n.classList.add("ring-2","ring-brand","ring-offset-2"),setTimeout(()=>{n.classList.remove("ring-2","ring-brand","ring-offset-2")},2e3))},[]);(0,s.useImperativeHandle)(v,()=>({scrollToMessage:ey}),[ey]);let ew=(0,s.useRef)(0),ek=(0,s.useRef)(!0);(0,s.useEffect)(()=>{let t=ew.current,n=e.length;ew.current=n,!ek.current&&L&&n>t&&w.current?.scrollIntoView({behavior:"smooth"})},[e,L]),(0,s.useEffect)(()=>{L&&t&&w.current?.scrollIntoView({behavior:"smooth"})},[t,L]),(0,s.useEffect)(()=>{if(ef.current&&!u){let e=j.current;if(e){let t=e.scrollHeight-em.current;e.scrollTop=t,ef.current=!1}}},[e,u]);let ej=(0,s.useRef)(!1);return(0,s.useEffect)(()=>{x&&ej.current&&e.length>0&&(ej.current=!1,w.current?.scrollIntoView({behavior:"instant"}))},[x,e.length]),(0,s.useEffect)(()=>{ek.current&&e.length>0&&(ek.current=!1,x?w.current?.scrollIntoView({behavior:"instant"}):ej.current=!0)},[e.length,x]),(0,r.jsxs)("div",{ref:C,className:"relative flex-1 min-h-0 overflow-hidden flex flex-col outline-none",tabIndex:-1,onMouseUp:Y,onMouseDown:Q,children:[I&&(0,r.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-2 px-3 py-2 bg-secondary border-b border-border",children:[(0,r.jsx)("input",{ref:V,type:"text",value:P,onChange:e=>A(e.target.value),onKeyDown:O,placeholder:y("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,r.jsx)("span",{className:"text-xs text-muted-foreground",children:_.length>0?`${D+1}/${_.length}`:y("common.noMatch")}),(0,r.jsx)("button",{onClick:W,disabled:0===_.length,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:y("codeViewer.prevShiftEnter"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"})})}),(0,r.jsx)("button",{onClick:F,disabled:0===_.length,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:y("codeViewer.nextEnter"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})}),(0,r.jsx)("button",{onClick:B,className:"p-1 rounded hover:bg-accent",title:y("codeViewer.closeEsc"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,r.jsx)("div",{ref:j,onScroll:eg,className:"relative flex-1 min-h-0 overflow-y-auto p-4",children:0!==e.length||t?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{ref:k}),d&&(0,r.jsx)("div",{className:"flex justify-center py-3",children:u?(0,r.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground text-sm",children:[(0,r.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"}),(0,r.jsx)("span",{children:y("chat.loadMoreHistory")})]}):(0,r.jsx)("button",{onClick:h,className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:y("chat.scrollUpForMore")})}),eh.map(e=>(0,r.jsx)("div",{"data-message-id":e.id,className:"transition-[box-shadow] duration-300",children:(0,r.jsx)(er,{message:e,cwd:n,sessionId:a,onFork:f,onApprovePlan:b,isLoading:t,onContentSearch:p,onShowFileDiff:g})},e.id)),t&&(0,r.jsx)("div",{className:"flex justify-start mb-4",children:(0,r.jsxs)("div",{className:"bg-accent rounded-2xl rounded-bl-md px-4 py-3 max-w-[90%]",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,r.jsx)("span",{className:"inline-block w-5 h-5 border-2 border-brand border-t-transparent rounded-full animate-spin"}),(0,r.jsx)("span",{className:"text-sm",children:"claude2"===o?"Claude 2 is thinking...":"codex"===o?"Codex is thinking...":"kimi"===o?"Kimi is thinking...":"ollama"===o?"Ollama is thinking...":"deepseek"===o?"DeepSeek is thinking...":y("chat.claudeThinking")})]}),i&&(0,r.jsxs)("div",{className:"mt-2 flex items-start gap-2 text-xs text-amber-400 border-t border-border/50 pt-2",children:[(0,r.jsx)("svg",{className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0 animate-spin",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.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,r.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,r.jsxs)("div",{children:["Retrying API call (attempt ",i.attempt,i.maxRetries>0?`/${i.maxRetries}`:"",i.delayMs>0?`, delay ${(i.delayMs/1e3).toFixed(1)}s`:"",")"]}),(i.errorStatus||i.error)&&(0,r.jsxs)("div",{className:"text-muted-foreground/80 break-words",children:[i.errorStatus?`${i.errorStatus}`:"",i.errorStatus&&i.error?" \xb7 ":"",i.error||""]})]})]}),c&&(0,r.jsxs)("div",{className:"mt-2 flex items-start gap-2 text-xs text-amber-400 border-t border-border/50 pt-2",children:[(0,r.jsx)("svg",{className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01M5.07 19h13.86c1.54 0 2.5-1.67 1.73-3L13.73 4a2 2 0 00-3.46 0L3.34 16c-.77 1.33.19 3 1.73 3z"})}),(0,r.jsx)("div",{className:"flex-1 min-w-0 break-words",children:c})]})]})}),(0,r.jsx)("div",{ref:w})]}):(0,r.jsx)("div",{className:"flex items-center justify-center h-full text-slate-9",children:(0,r.jsxs)("div",{className:"text-center",children:[(0,r.jsx)("div",{className:"text-4xl mb-4",children:"\uD83D\uDCAC"}),(0,r.jsx)("div",{children:y("chat.startConversation")})]})})}),M&&e.length>0&&(0,r.jsx)("button",{onClick:eb,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:y("chat.jumpToStart"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"})})}),T&&e.length>0&&(0,r.jsx)("button",{onClick:ev,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:y("chat.jumpToLatest"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})}),N&&(0,r.jsx)(ea.f,{floatingToolbarRef:H,bumpRef:K,container:N,onAddComment:ee,onSendToAI:et,onSearch:p?en:void 0,isChatLoading:z?.isLoading}),X&&N&&(0,r.jsx)(eo.t,{x:X.x,y:X.y,range:{start:0,end:0},lineSnapshot:X.text,container:N,onSubmit:ei,onSendToAI:z?eu:void 0,onClose:()=>Z(null),isChatLoading:z?.isLoading}),G&&N&&(0,r.jsx)(eo.G,{x:G.x,y:G.y,range:{start:0,end:0},lineSnapshot:G.text,container:N,onSubmit:ed,onClose:()=>J(null),isChatLoading:z?.isLoading})]})})},75346:(e,t,n)=>{n.d(t,{n:()=>s});var r=n(88292);let s={SessionChange:(0,r.R)("session-change"),ViewChange:(0,r.R)("view-change"),OpenNote:(0,r.R)("open-note"),LangChange:(0,r.R)("lang-change"),TabAdd:(0,r.R)("tab-add"),TabClose:(0,r.R)("tab-close"),SwitchSession:(0,r.R)("switch-session"),ProjectChange:(0,r.R)("project-change"),OpenProject:(0,r.R)("open-project"),SessionComplete:(0,r.R)("session-complete"),OpenTokenStats:(0,r.R)("open-token-stats"),PinnedSessionsChanged:(0,r.R)("pinned-sessions-changed"),ScheduledTasksChanged:(0,r.R)("scheduled-tasks-changed"),ScreenshotPrepare:(0,r.R)("screenshot-prepare"),ScreenshotDone:(0,r.R)("screenshot-done")}},77725:(e,t,n)=>{n.d(t,{Z:()=>d});var r=n(12115),s=n(10592),l=n(86359),a=n(80905),o=n(49433),i=n(80286),c=n(86957);function d(e,t){let[n,d]=(0,r.useState)({status:"loading"});return(0,r.useEffect)(()=>{d({status:"loading"});let t=c.t4.runFork(e);return t.addObserver(e=>{s.YW(e,{onSuccess:e=>d({status:"success",data:e}),onFailure:e=>{let t=l.od(e);d({status:"error",error:a.Ru(t)?t.value:e})}})}),()=>{o.runFork(i.G(t))}},t),n}},82292:(e,t,n)=>{function r(e,t){for(let n of e){if(n.path===t)return n;if(n.children){let e=r(n.children,t);if(e)return e}}return null}function s(e,t){if(!e)return"";let n=r(t,e);if(n?.isDirectory)return e;let s=e.split("/");return s.pop(),s.join("/")}function l(e){let t=[];for(let n of e){let e=n.split("/"),r=t;for(let t=0;t<e.length;t++){let n=e[t],s=t===e.length-1,l=e.slice(0,t+1).join("/"),a=r.find(e=>e.name===n);a||(a={name:n,path:l,isDirectory:!s,children:s?void 0:[]},r.push(a)),!s&&a.children&&(r=a.children)}}let n=e=>{e.sort((e,t)=>e.isDirectory&&!t.isDirectory?-1:!e.isDirectory&&t.isDirectory?1:e.name.localeCompare(t.name)),e.forEach(e=>{e.children&&n(e.children)})};return n(t),t}function a(e){let t=[],n=e=>{for(let r of e)r.isDirectory&&(t.push(r.path),r.children&&n(r.children))};return n(e),t}n.d(t,{B_:()=>f,HR:()=>function e(t,n){if(0===n.length)return t;let r=new Map(n.map(e=>[e.path,e]));return t.map(t=>{let n=r.get(t.path);return n&&t.isDirectory?void 0===t.children&&void 0!==n.children?{...t,children:n.children}:void 0!==t.children&&void 0!==n.children?{...t,children:e(t.children,n.children)}:t:t})},KH:()=>d,MB:()=>r,S7:()=>s,fw:()=>u,q3:()=>c,r6:()=>h,tE:()=>m,tW:()=>a,u:()=>i,v3:()=>l});let o=new Set(["png","jpg","jpeg","gif","svg","webp","ico","bmp"]);function i(e){let t=e.split(".").pop()?.toLowerCase();return o.has(t||"")}function c(e,t,n=!1){let r=new Set;if(!t)return r;let s=t.toLowerCase(),l=e=>{if(r.add(e.path),e.children)for(let t of e.children)l(t)},a=(e,t)=>{let o=e.name.toLowerCase(),i=n?o===s:o.includes(s);if(i&&e.children)return l(e),t.forEach(e=>r.add(e)),!0;let c=!1;if(e.children)for(let n of e.children)a(n,[...t,e.path])&&(c=!0);return(!!i||!!c)&&(r.add(e.path),t.forEach(e=>r.add(e)),!0)};for(let t of e)a(t,[]);return r}function d(e,t,n=!1){let r=new Set;if(!t)return r;let s=t.toLowerCase();for(let t of e){let e=t.split("/");for(let t=0;t<e.length;t++){let l=e[t].toLowerCase();if(n?l===s:l.includes(s)){for(let t=0;t<=e.length-1;t++)r.add(e.slice(0,t+1).join("/"));break}}}return r}function u(e){let t=Math.floor(Math.floor((Date.now()-1e3*e)/1e3)/60),n=Math.floor(t/60),r=Math.floor(n/24),s=Math.floor(r/30),l=Math.floor(r/365);return l>0?`${l}y ago`:s>0?`${s}mo ago`:r>0?`${r}d ago`:n>0?`${n}h ago`:t>0?`${t}m ago`:"just now"}function h(e){let t=new Date(e),n=new Date,r=t.getFullYear()===n.getFullYear(),s=String(t.getMonth()+1).padStart(2,"0"),l=String(t.getDate()).padStart(2,"0"),a=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return r?`${s}-${l} ${a}:${o}`:`${t.getFullYear()}-${s}-${l} ${a}:${o}`}let m=()=>{},f=50},83448:(e,t,n)=>{n.d(t,{Cr:()=>v,JC:()=>u,M5:()=>c,QW:()=>f,Zr:()=>m,an:()=>b,em:()=>i,l1:()=>d,n_:()=>h,qD:()=>g,td:()=>o,z2:()=>x});var r=n(49433),s=n(82680);let l=(e,t)=>r.tryPromise({try:async()=>{let n=await fetch(e,t);if(!n.ok)throw Error(`HTTP ${n.status}`);return await n.json()},catch:n=>new s.uV({message:`${t?.method??"GET"} ${e} failed`,cause:n})}),a=(e,t)=>l(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),o=()=>l("/api/settings"),i=e=>l("/api/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),c=()=>l("/api/commands"),d=()=>l("/api/skills"),u=e=>a("/api/bash",e),h=e=>r.tryPromise({try:async()=>{let t=await fetch("/api/session-by-path",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});return t.ok?await t.json():null},catch:e=>new s.uV({message:"POST /api/session-by-path failed",cause:e})}),m=(e,t)=>a(`/api/session/${encodeURIComponent(e)}/fork`,t),f=e=>l(`/api/sessions/projects/${encodeURIComponent(e)}`),x=()=>l("/api/global-state").pipe(r.map(e=>e.sessions??[])),p=()=>r.tryPromise({try:async()=>{let e=await fetch("/api/ollama/models");return 503===e.status?{_tag:"not-running"}:e.ok?{_tag:"ok",models:(await e.json()).models??[]}:{_tag:"error",message:"Failed to fetch models"}},catch:e=>new s.uV({message:"fetch ollama models failed",cause:e})}),g=e=>r.gen(function*(){let t=yield*p();if("not-running"!==t._tag)return t;e&&(yield*r.sync(e));let n=yield*r.tryPromise({try:async()=>{let e=await fetch("/api/ollama/start",{method:"POST"}),t=await e.json().catch(()=>({}));return 404===e.status?{_tag:"not-installed",message:t.message||"Ollama is not installed"}:e.ok?{_tag:"started"}:{_tag:"error",message:"Failed to start Ollama"}},catch:e=>new s.uV({message:"start ollama failed",cause:e})});if("not-installed"===n._tag)return{_tag:"not-installed",message:n.message};if("error"===n._tag)return{_tag:"error",message:n.message};let l=yield*p();return"not-running"===l._tag?{_tag:"error",message:"Ollama started but cannot fetch models"}:l}),b=e=>l(`/api/file?path=${encodeURIComponent(e)}`),v=e=>l(`/api/claude-stats?engine=${encodeURIComponent(e)}`)},83897:(e,t,n)=>{n.d(t,{k_:()=>o,nH:()=>i});var r=n(95155),s=n(12115),l=n(48347);let a=(0,s.createContext)(null);function o({children:e}){let t=(0,s.useRef)(new Map),n=(0,s.useRef)(null),[i,c]=(0,s.useState)(!1),d=(0,s.useCallback)((e,n)=>{t.current.set(n,e)},[]),u=(0,s.useCallback)(e=>{t.current.delete(e)},[]),h=(0,s.useCallback)(e=>{n.current=e},[]),m=(0,s.useCallback)(e=>{let r=n.current;if(!r)return void console.warn("No active tab to send message");let s=t.current.get(r);s?s(e):console.warn(`No chat sender registered for tab ${r}`)},[]),f=(0,s.useMemo)(()=>({sendMessage:m,isLoading:i,registerChat:d,unregisterChat:u,setActiveTab:h,setIsLoading:c}),[m,i,d,u,h]),x=(0,s.useMemo)(()=>({sendMessage:m,isLoading:i}),[m,i]);return(0,r.jsx)(a.Provider,{value:f,children:(0,r.jsx)(l.H,{value:x,children:e})})}function i(){return(0,s.useContext)(a)}},88780:(e,t,n)=>{n.d(t,{Do:()=>u,Sz:()=>h,VO:()=>d,wI:()=>m});var r=n(95155),s=n(12115),l=n(79114),a=n(70188),o=n(14575);function i({status:e}){let{label:t,className:n}={added:{label:"A",className:"text-green-11"},untracked:{label:"A",className:"text-green-11"},modified:{label:"M",className:"text-amber-11"},deleted:{label:"D",className:"text-red-11"},renamed:{label:"R",className:"text-brand"}}[e]||{label:"?",className:"text-muted-foreground"};return(0,r.jsx)("span",{className:`text-xs font-bold ${n}`,children:t})}let c=s.memo(function e({node:t,level:n,selectedPath:l,expandedPaths:a,onSelect:c,onToggle:d,onContextMenu:u,showChanges:h=!1,renderActions:m}){let f=l===t.path,x=a.has(t.path),p=(0,s.useCallback)(()=>{t.isDirectory?d(t.path):c(t)},[t,c,d]),g=(0,s.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),u(e,t.path,t.isDirectory)},[t.path,t.isDirectory,u]);return t.isDirectory?(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center gap-1 py-0.5 px-2 pr-3 hover:bg-accent cursor-pointer whitespace-nowrap group",style:{paddingLeft:`${12*n+8}px`},onClick:p,onContextMenu:g,children:[(0,r.jsx)("span",{className:"text-slate-9 text-xs",children:x?"▼":"▶"}),(0,r.jsx)("span",{className:"text-sm text-foreground flex-1 truncate","data-tooltip":t.path,children:t.name}),m&&m(t)]}),x&&t.children.map(t=>(0,r.jsx)(e,{node:t,level:n+1,selectedPath:l,expandedPaths:a,onSelect:c,onToggle:d,onContextMenu:u,showChanges:h,renderActions:m},t.path))]}):(0,r.jsxs)("div",{className:`flex items-center gap-1.5 py-0.5 px-2 pr-3 cursor-pointer whitespace-nowrap group ${f?"bg-brand/10":"hover:bg-accent"}`,style:{paddingLeft:`${12*n+8}px`},onClick:p,onContextMenu:g,children:[(0,r.jsx)(o.o,{name:t.name,size:16,className:"flex-shrink-0"}),(0,r.jsx)("span",{className:`text-sm flex-1 truncate ${f?"text-brand":"text-foreground"}`,"data-tooltip":t.path,children:t.name}),t.status&&(0,r.jsx)(i,{status:t.status}),h&&void 0!==t.additions&&void 0!==t.deletions&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("span",{className:"text-xs text-green-11",children:["+",t.additions]}),(0,r.jsxs)("span",{className:"text-xs text-red-11",children:["-",t.deletions]})]}),m&&m(t)]})});function d({files:e,selectedPath:t,expandedPaths:n,onSelect:s,onToggle:o,cwd:i,showChanges:u=!1,renderActions:h,emptyMessage:m,className:f}){let{t:x}=(0,l.Bd)(),p=m??x("gitFileTree.noFiles"),{contextMenu:g,showContextMenu:b,hideContextMenu:v}=(0,a.Ee)();return 0===e.length?(0,r.jsx)("div",{className:"px-3 py-2 text-xs text-slate-9",children:p}):(0,r.jsxs)("div",{className:f||"py-1",children:[e.map(e=>(0,r.jsx)(c,{node:e,level:0,selectedPath:t,expandedPaths:n,onSelect:s,onToggle:o,onContextMenu:b,showChanges:u,renderActions:h},e.path)),g&&(0,r.jsx)(a.ft,{x:g.x,y:g.y,path:g.path,cwd:i,isDirectory:g.isDirectory,onClose:v})]})}function u(e){let t=[];for(let n of e){let e=n.path.split("/"),r=t;for(let t=0;t<e.length;t++){let s=e[t],l=t===e.length-1,a=e.slice(0,t+1).join("/"),o=r.find(e=>e.name===s);o||(o={name:s,path:a,isDirectory:!l,children:[],...l&&{status:n.status,additions:n.additions,deletions:n.deletions,oldPath:n.oldPath,file:n}},r.push(o)),l||(r=o.children)}}let n=e=>{e.sort((e,t)=>e.isDirectory&&!t.isDirectory?-1:!e.isDirectory&&t.isDirectory?1:e.name.localeCompare(t.name)),e.forEach(e=>n(e.children))};return n(t),t}function h(e){let t=[],n=e=>{for(let r of e)r.isDirectory&&(t.push(r.path),n(r.children))};return n(e),t}function m(e){let t=[],n=e=>{if(e.isDirectory)for(let t of e.children)n(t);else t.push(e)};return n(e),t}},89109:(e,t,n)=>{n.d(t,{f:()=>o});var r=n(95155),s=n(12115),l=n(79114);function a({x:e,y:t,visible:n,container:s,onAddComment:o,onSendToAI:i,onSearch:c,isChatLoading:d}){let{t:u}=(0,l.Bd)(),h=s.getBoundingClientRect(),m=e-h.left,f=Math.max(0,t-h.top-40);return(0,r.jsxs)("div",{className:"floating-toolbar absolute z-[200] flex items-center gap-1.5 bg-card border border-border rounded-lg shadow-xl p-1.5",style:{left:m+8,top:f,visibility:n?"visible":"hidden",pointerEvents:n?"auto":"none"},children:[(0,r.jsx)("button",{className:"px-3 py-1.5 text-xs font-medium border border-brand text-brand rounded-md hover:bg-brand/10 transition-colors",onClick:o,children:u("floatingToolbar.addComment")}),(0,r.jsx)("button",{className:"px-3 py-1.5 text-xs font-medium border border-brand text-brand rounded-md hover:bg-brand/10 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",onClick:i,disabled:d,title:u(d?"comments.aiResponding":"floatingToolbar.sendToAI"),children:u("floatingToolbar.sendToAI")}),c&&(0,r.jsx)("button",{className:"px-3 py-1.5 text-xs font-medium border border-brand text-brand rounded-md hover:bg-brand/10 transition-colors",onClick:c,children:u("floatingToolbar.search")})]})}let o=(0,s.memo)(function({floatingToolbarRef:e,bumpRef:t,container:n,onAddComment:l,onSendToAI:o,onSearch:i,isChatLoading:c}){let[d,u]=(0,s.useState)(0);(0,s.useEffect)(()=>{t.current=()=>u(e=>e+1)},[t]);let h=(0,s.useMemo)(()=>e.current,[d]);return(0,r.jsx)(a,{x:h?.x??0,y:h?.y??0,visible:!!h,container:n,onAddComment:l,onSendToAI:o,onSearch:i,isChatLoading:c})})},90717:(e,t,n)=>{n.d(t,{$3:()=>u,Cm:()=>d,Gw:()=>f,RP:()=>h,Un:()=>m,zL:()=>c});var r=n(69809),s=n(49433),l=n(86957),a=n(82680),o=n(46456);let i=new Set;function c(e){return i.add(e),()=>i.delete(e)}function d(){i.forEach(e=>e())}async function u(e){let t=await l.t4.runPromiseExit((0,o.lb)(e));if("Success"!==t._tag)throw Error("Failed to fetch comments");let n=t.value.comments??[];if(0===n.length)return[];let r=new Map;for(let e of n)e.selectedText||(r.has(e.filePath)||r.set(e.filePath,[]),r.get(e.filePath).push(e));let i=new Map;await Promise.all(Array.from(r.keys()).map(async t=>{let n=await l.t4.runPromiseExit(s.tryPromise({try:async()=>{let n=await fetch(`/api/files/text?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`);return n.ok?await n.json():null},catch:e=>new a.uV({message:`read file text ${t} failed`,cause:e})}));"Success"===n._tag&&n.value&&"string"==typeof n.value.content?i.set(t,n.value.content.split("\n")):"Failure"===n._tag&&console.error(`Failed to read file ${t}:`,n.cause)}));let c=[];for(let e of n){if(e.selectedText){c.push({...e,codeContent:e.selectedText});continue}let t=i.get(e.filePath),n="";if(t){let r=Math.max(0,e.startLine-1),s=Math.min(t.length,e.endLine);n=t.slice(r,s).join("\n")}c.push({...e,codeContent:n})}return c}async function h(e){let t=await l.t4.runPromiseExit((0,o.tj)(e));return"Success"===t._tag?(d(),!0):(console.error("Failed to clear comments:",t.cause),!1)}let m="__chat__";function f(e,t){let n=e.filter(e=>e.filePath===m),s=e.filter(e=>e.filePath!==m),l=[];for(let e of(s.length>0&&(l.push(`${r.A.t("comments.codeRef")}`,""),s.forEach((e,t)=>{let n=e.startLine>0||e.endLine>0?`:${e.startLine}-${e.endLine}`:"";l.push(`[${t+1}] ${e.filePath}${n}`),l.push("```"),l.push(e.codeContent),l.push("```"),e.note&&l.push(r.A.t("comments.note",{content:e.note})),l.push("")})),n)){let t=e.codeContent.split("\n").map(e=>`> ${e}`).join("\n");l.push(t),e.note&&l.push(e.note),l.push("")}if(t.trim()){for(;l.length>0&&""===l[l.length-1];)l.pop();l.push(t.trim())}return l.join("\n").trim()}},95045:(e,t,n)=>{n.d(t,{F:()=>a});var r=n(49433),s=n(88292),l=n(86957);let a=(e,t)=>{l.t4.runFork(r.flatMap(s.d,n=>n.publish(e,t)))}},95942:(e,t,n)=>{n.d(t,{EE:()=>o,K2:()=>i,ri:()=>c});var r=n(95155),s=n(12115),l=n(79114),a=n(8422);let o=80,i=24,c=(0,s.forwardRef)(function({visible:e,running:t,onInput:n},c){let{t:d}=(0,l.Bd)(),u=(0,s.useRef)(n);(0,s.useEffect)(()=>{u.current=n},[n]);let[h,m]=(0,s.useState)(!1),f=(0,s.useRef)(!1);(0,s.useEffect)(()=>{t&&!f.current?m(!0):!t&&f.current&&m(!1),f.current=t},[t]);let x=(0,s.useRef)(null),p=(0,s.useRef)(null),g=(0,s.useRef)(""),b=(0,s.useCallback)(()=>{if(p.current||!x.current)return;let e=new a.B({cols:o,rows:i,fontSize:11,fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, "Courier New", monospace',convertEol:!1,scrollback:2e3,theme:{background:"#0a0a0a",foreground:"#d4d4d8"},disableStdin:!1,allowProposedApi:!0});e.open(x.current),e.onData(e=>u.current?.(e)),g.current&&e.write(g.current),p.current=e},[]);return((0,s.useEffect)(()=>{h&&e?b():(p.current?.dispose(),p.current=null)},[h,e,b]),(0,s.useImperativeHandle)(c,()=>({write:e=>{g.current+=e,g.current.length>2e5&&(g.current=g.current.slice(-15e4)),p.current?.write(e)},clear:()=>{g.current="",p.current?.clear()}}),[]),e)?(0,r.jsxs)("div",{className:"absolute top-12 right-3 z-30 rounded-lg border border-border bg-card shadow-lg overflow-hidden",style:{width:h?"auto":180},"data-testid":"pty-floating-window",children:[(0,r.jsxs)("button",{type:"button",onClick:()=>m(e=>!e),"data-testid":"pty-floating-toggle",className:"w-full flex items-center justify-between gap-3 px-2.5 py-1.5 text-xs bg-accent/60 hover:bg-accent",children:[(0,r.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,r.jsx)("span",{className:`inline-block w-2 h-2 rounded-full ${t?"bg-green-500 animate-pulse":"bg-muted-foreground"}`}),(0,r.jsxs)("span",{className:"text-muted-foreground",children:[d("chat.ptyTerminal"),t?` \xb7 ${d("chat.ptyRunning")}`:""]})]}),(0,r.jsx)("span",{className:"text-muted-foreground",children:h?`${d("chat.ptyCollapse")} ▾`:`${d("chat.ptyExpand")} ▸`})]}),(0,r.jsx)("div",{ref:x,"data-testid":"pty-floating-term",style:{display:h?"block":"none",padding:4},className:"bg-[#0a0a0a]"})]}):null})}}]);
|