@surething/cockpit 1.0.283 → 1.0.285
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 +3 -3
- package/.next-prod/build-manifest.json +2 -2
- package/.next-prod/cockpit-build.json +1 -1
- 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/_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/_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/_tree.segment.rsc +1 -1
- package/.next-prod/server/app/api/chat/route.js +1 -1
- package/.next-prod/server/app/api/scheduled-tasks/route.js +1 -1
- package/.next-prod/server/app/api/session/[sessionId]/fork/route.js +1 -1
- package/.next-prod/server/app/api/session/[sessionId]/history/route.js +1 -1
- package/.next-prod/server/app/api/session/[sessionId]/turn/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-paths-manifest.json +3 -3
- package/.next-prod/server/chunks/2493.js +4 -4
- package/.next-prod/server/chunks/6495.js +1 -1
- package/.next-prod/server/chunks/7438.js +10 -10
- 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/{2550-eb5beeffe90c8632.js → 2550-8c7decb785b92fbf.js} +4 -4
- package/.next-prod/static/chunks/{5313-da9f9a2ce9c5ba34.js → 5313-8a3e790e11b63d64.js} +5 -5
- package/.next-prod/trace +14 -14
- package/.next-prod/trace-build +1 -1
- package/bin/instanceLock.mjs +23 -1
- package/dist/auth.mjs +7 -2
- package/dist/{chunk-BE235BMW.mjs → chunk-7YQK3TY5.mjs} +157 -37
- package/dist/{chunk-TOVSUPTJ.mjs → chunk-EMTH733G.mjs} +1 -1
- package/dist/httpApi.mjs +2 -2
- package/dist/scheduledTasks.mjs +3 -1
- package/dist/wsServer.mjs +2 -2
- package/package.json +3 -3
- /package/.next-prod/static/{UM1QtmCsp6wKOKw_z_UEq → SHzF6HEOUD5ikVkZI6v3E}/_buildManifest.js +0 -0
- /package/.next-prod/static/{UM1QtmCsp6wKOKw_z_UEq → SHzF6HEOUD5ikVkZI6v3E}/_ssgManifest.js +0 -0
|
@@ -29,8 +29,8 @@ Error: ${e}`,exitCode:1,isRunning:!1,pid:void 0}:r))}})}catch(t){let e=J(c);q(c)
|
|
|
29
29
|
Error: ${t.message}`,exitCode:1,isRunning:!1,pid:void 0}:r))}},[C,m,k,r,e,_,J,q,Y,n,X]),ea=(0,s.useCallback)(e=>{let t=o.find(t=>t.id===e);t?.isRunning&&t.pid&&r6(t.pid)},[o]),el=(0,s.useCallback)(async t=>{let n=o.find(e=>e.id===t);if(!n)return;n.isRunning&&n.pid&&(r6(n.pid),await new Promise(e=>setTimeout(e,200)));let s=n.command.trim().split(/\s+/),l=s[0],i=n.usePty&&n.command===nv,d=i?nb:n.command;!i&&C[l]&&(d=C[l]+(s.length>1?" "+s.slice(1).join(" "):""));let c=n.usePty||!1;if(c){let e=U.current.get(t);if(e)for(let t of e)t()}q(t,c);let u=d!==n.command?`→ ${d}
|
|
30
30
|
`:"";c||$.current.set(t,u),c&&T.current.add(t),a(e=>e.map(e=>e.id===t?{...e,output:c?"":u,exitCode:void 0,isRunning:!0,pid:void 0}:e));let x=I.current.get(t);try{await r2({cwd:n.cwd||m,command:d,commandId:t,tabId:r||"",projectCwd:e,env:k,usePty:c,sourceId:z.current,...c&&x?{cols:x.cols,rows:x.rows}:{},onData:(e,r)=>{if("pid"===e)a(e=>e.map(e=>e.id===t?{...e,pid:r.pid,..."string"==typeof r.command?{command:r.command}:{}}:e));else if("stdout"===e||"stderr"===e)_(t,r.data);else if("exit"===e){let e=J(t);q(t),a(n=>n.map(n=>n.id===t?{...n,output:e,exitCode:r.code,isRunning:!1,pid:void 0}:n))}},onError:e=>{let r=J(t);q(t),a(n=>n.map(n=>n.id===t?{...n,output:r+`
|
|
31
31
|
Error: ${e}`,exitCode:1,isRunning:!1,pid:void 0}:n))}})}catch(r){let e=J(t);q(t),a(n=>n.map(n=>n.id===t?{...n,output:e+`
|
|
32
|
-
Error: ${r.message}`,exitCode:1,isRunning:!1,pid:void 0}:n))}},[o,C,m,k,r,e,_,J,q]),ei=(0,s.useCallback)(async t=>{a(e=>e.filter(e=>e.id!==t)),q(t),r&&await u.t4.runPromise((0,tU.SN)(e,r,t,z.current).pipe(eb.sFT(e=>eb.OH5(()=>console.error("Failed to delete command:",e))),eb.NWQ(()=>eb.rIH)))},[e,r,q]),ed=(0,s.useCallback)((t,n,s)=>{var o;let a=t2(t);if(!a)return;let l=a.parse(n);"cwd"in l&&!l.cwd&&(l.cwd=m);let d={id:(o=a.idPrefix,`${o}-${Date.now()}-${Math.random().toString(36).slice(2,8)}`),_type:t,timestamp:new Date().toISOString(),...l};if(i(e=>[...e,d]),w(d.id),setTimeout(Y,100),s){let t=M&&M.length>0?[...M]:H.current.map(e=>e.data.id),n=t.indexOf(s);-1!==n?t.splice(n+1,0,d.id):t.push(d.id),L(t),r&&u.t4.runFork((0,tU.cm)(e,r,t,z.current).pipe(eb.NWQ(()=>eb.rIH)))}if(r){let n=a.toHistory(d);u.t4.runFork((0,tU.AJ)(e,r,{type:t,id:d.id,timestamp:d.timestamp,...n},z.current).pipe(eb.sFT(e=>eb.OH5(()=>console.error(`Failed to save ${t} item:`,e))),eb.NWQ(()=>eb.rIH)))}},[Y,e,r,M]),ec=(0,s.useCallback)(async t=>{let n=l.find(e=>e.id===t);if(i(e=>e.filter(e=>e.id!==t)),w(e=>e===t?null:e),c(e=>{let r=new Set(e);return r.delete(t),r}),n){let e=t2(n._type);e?.onClose?.(n)}r&&u.t4.runFork((0,tU.SN)(e,r,t,z.current).pipe(eb.sFT(e=>eb.OH5(()=>console.error("Failed to delete plugin item:",e))),eb.NWQ(()=>eb.rIH)))},[l,e,r]);A.current=ed,D.current=es;let eu=(0,s.useCallback)((t,n)=>{r&&u.t4.runFork((0,tU.bv)(e,r,t,{sleeping:n},z.current).pipe(eb.NWQ(()=>eb.rIH)))},[e,r]),em=(0,s.useCallback)(e=>{c(t=>new Set(t).add(e)),eu(e,!0)},[eu]),ex=(0,s.useCallback)(e=>{c(t=>{let r=new Set(t);return r.delete(e),r}),eu(e,!1)},[eu]),eh=(0,s.useCallback)(async t=>{L(t),r&&await u.t4.runPromise((0,tU.cm)(e,r,t,z.current).pipe(eb.NWQ(()=>eb.rIH)))},[e,r]),ef=(0,s.useMemo)(()=>{let e=[...o.map(e=>({type:"command",data:e})),...l.map(e=>({type:e._type,data:e}))];if(!M||0===M.length)return e.sort((e,t)=>new Date(e.data.timestamp).getTime()-new Date(t.data.timestamp).getTime());let t=new Map(M.map((e,t)=>[e,t])),r=[],n=[];for(let s of e)t.has(s.data.id)?r.push(s):n.push(s);return r.sort((e,r)=>t.get(e.data.id)-t.get(r.data.id)),n.sort((e,t)=>new Date(e.data.timestamp).getTime()-new Date(t.data.timestamp).getTime()),[...r,...n]},[o,l,M]);H.current=ef,(0,s.useEffect)(()=>{R.current=o.filter(e=>!e.isRunning&&e.command.trim()).map(e=>e.command)},[o]);let ep=async()=>{let t=await u.t4.runPromise((0,tU.QF)(e,r).pipe(eb.sFT(e=>eb.OH5(()=>console.error("Failed to load env:",e))),eb.DM4(()=>({env:{},home:""}))));y(t.env),N.current=t.home},eg=async()=>{S(await u.t4.runPromise((0,tU.Jn)().pipe(eb.sFT(e=>eb.OH5(()=>console.error("Failed to load aliases:",e))),eb.DM4(()=>({})))))},ev=async()=>{if(!r)return;let t=await u.t4.runPromise((0,tU.DN)(e,r).pipe(eb.DM4(()=>[])));t.length>0&&L(t)};return(0,s.useEffect)(()=>{let e={current:!1};return(async()=>{await Z(0),e.current||await ee(e)})(),ep(),eg(),ev(),()=>{e.current=!0}},[Z,ee]),(0,s.useEffect)(()=>()=>{null!==E.current&&cancelAnimationFrame(E.current)},[]),(0,s.useEffect)(()=>()=>{r9()},[]),{commands:o,pluginItems:l,sleepingBubbles:d,consoleItems:ef,currentCwd:m,selectedCommandId:j,setSelectedCommandId:w,customEnv:k,setCustomEnv:y,aliases:C,setAliases:S,isLoadingHistory:h,hasMoreHistory:p,currentPage:b,scrollRef:W,commandHistoryRef:R,ptySizeRef:I,executeCommandRef:D,executeCommand:es,interruptCommand:ea,rerunCommand:el,deleteCommand:ei,addPluginItem:ed,closePluginItem:ec,handleBubbleSleep:em,handleBubbleWake:ex,loadHistory:Z,scrollToBottom:Y,saveBubbleOrder:eh,sendStdin:r4,resizePty:r3,subscribePtyOutput:V,subscribePtyReset:K,subscribePtyRefresh:G}}({cwd:e,initialShellCwd:t,tabId:r,onCwdChange:a}),[W,O]=(0,s.useState)(null),[_,q]=(0,s.useState)(0),[V,U]=(0,s.useState)(0),[K,Q]=(0,s.useState)(!0),[G,J]=(0,s.useState)(!1),[Y,Z]=(0,s.useState)(!1),[X,ee]=(0,s.useState)(!1),[et,er]=(0,s.useState)(!1),en=(0,s.useRef)(null),es=(0,s.useRef)(null),ea=(0,s.useRef)(null),el=(0,s.useRef)(!1),ei=(0,s.useRef)(null),ed=(0,s.useRef)(null),ec=(0,s.useRef)([]);(0,s.useEffect)(()=>{ec.current=c},[c]);let eu=(0,s.useCallback)(()=>{let e=m.current;return!e||e.scrollHeight-e.scrollTop-e.clientHeight<50},[m]),em=(0,s.useCallback)(()=>{let e=m.current;return!e||e.scrollTop<50},[m]),ex=(0,s.useCallback)(()=>{ee(!em()),er(!eu())},[eu,em]),eh=(0,s.useCallback)(()=>{es.current?.scrollIntoView({behavior:"smooth"})},[]),ef=async()=>{let t=await u.t4.runPromiseExit((0,tU.D0)(e));if("Success"===t._tag){let e=t.value.settings;e?.gridLayout!==void 0&&Q(e.gridLayout)}else console.error("Failed to load project settings:",t.cause)};(0,s.useEffect)(()=>{queueMicrotask(()=>ef())},[]);let ep=(0,s.useCallback)(()=>{el.current=!0},[]),eg=(0,s.useCallback)((e,t)=>{if(!el.current)return void e.preventDefault();el.current=!1,ei.current=t,e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",t),e.currentTarget.style.opacity="0.4";let r=e.currentTarget.querySelector("[data-drag-handle]");if(r){let t=r.cloneNode(!0);t.style.cssText="position:fixed;top:-9999px;left:-9999px;width:"+r.offsetWidth+"px;background:hsl(var(--card));color:hsl(var(--foreground));box-shadow:var(--elevation-2);border-radius:8px;padding:4px 12px;opacity:0.9;",document.body.appendChild(t),e.dataTransfer.setDragImage(t,20,16),requestAnimationFrame(()=>document.body.removeChild(t))}},[]),ev=(0,s.useCallback)((e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect="move",ed.current=t},[]),ej=(0,s.useCallback)(e=>{e.preventDefault(),e.currentTarget.classList.add("ring-2","ring-brand")},[]),ew=(0,s.useCallback)(e=>{e.currentTarget.classList.remove("ring-2","ring-brand")},[]),ek=(0,s.useCallback)(e=>{e.preventDefault(),e.currentTarget.classList.remove("ring-2","ring-brand")},[]),ey=(0,s.useCallback)(e=>{e.currentTarget.style.opacity="1";let t=ei.current,r=ed.current;if(ei.current=null,ed.current=null,!t||!r||t===r)return;let n=ec.current.map(e=>e.data.id),s=n.indexOf(t),o=n.indexOf(r);if(-1===s||-1===o)return;let a=[...n];a[s]=r,a[o]=t,R(a)},[R]),eN=(0,s.useCallback)(e=>{O(t=>t===e?null:e)},[]),eC=(0,s.useCallback)((e,t)=>k("browser",e,t),[k]);(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"m"===e.key&&!e.shiftKey&&!e.altKey&&(e.preventDefault(),x&&eN(x))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[x,eN]),(0,s.useEffect)(()=>{let e=m.current;if(!e)return;let t=new ResizeObserver(([e])=>{U(e.contentRect.height)});return t.observe(e),U(e.clientHeight),()=>t.disconnect()},[m]),(0,s.useEffect)(()=>{let e=m.current;if(e)return W?q(e.clientHeight):(e.style.overflow="",q(0)),()=>{e&&(e.style.overflow="")}},[W,m]),(0,s.useEffect)(()=>{let e=m.current;if(!e||!W||!_)return;let t=requestAnimationFrame(()=>{let t=e.querySelector(`[data-bubble-id="${W}"]`);t&&t.scrollIntoView({block:"start"}),e.style.overflow="hidden"});return()=>cancelAnimationFrame(t)},[W,_,m]);let[eS,eM]=(0,s.useState)(null);(0,s.useEffect)(()=>{i&&(O(null),eM(i.commandId))},[i]),(0,s.useEffect)(()=>{if(!eS||!c.some(e=>e.data.id===eS))return;let e=requestAnimationFrame(()=>{let e=m.current,t=e?.querySelector(`[data-bubble-id="${CSS.escape(eS)}"]`);if(!e||!t)return;eM(null),h(eS);let r=t.getBoundingClientRect(),n=e.getBoundingClientRect(),s=r.top-n.top-Math.max(0,(n.height-r.height)/2);e.scrollTo({top:e.scrollTop+s,behavior:"smooth"})});return()=>cancelAnimationFrame(e)},[eS,c,m,h]),(0,s.useEffect)(()=>{if(!eS)return;let e=setTimeout(()=>{eM(null),(0,T.oR)(d("runningTerminals.notFound"),"error")},3e3);return()=>clearTimeout(e)},[eS,d]),(0,s.useEffect)(()=>{let e=e=>{let t=e.detail?.command;t&&w(t)};return window.addEventListener("execute-terminal-command",e),()=>window.removeEventListener("execute-terminal-command",e)},[w]),(0,s.useEffect)(()=>{let e=e=>{let t=e.detail?.url;t&&k("browser",t)};return window.addEventListener("console-open-browser",e),()=>window.removeEventListener("console-open-browser",e)},[k]);let eL=V>0?Math.floor((V-32-12)/2-41):void 0;return(0,n.jsxs)("div",{ref:en,className:"h-full flex flex-col bg-background relative",children:[(0,n.jsx)("div",{ref:m,onScroll:ex,className:`console-scroll-root flex-1 overflow-y-auto ${W?"":"py-4 px-4"}`,children:0===c.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsxs)("div",{className:"w-full max-w-md flex flex-col gap-4 text-sm",children:[(0,n.jsx)("p",{className:"text-muted-foreground",children:d("console.emptyIntro")}),(0,n.jsx)("ul",{className:"flex flex-col gap-2",children:nw.map(e=>(0,n.jsxs)("li",{className:"flex items-start gap-3",children:[(0,n.jsx)("span",{className:"w-16 flex-shrink-0 text-foreground font-medium",children:d(e.label)}),(0,n.jsxs)("span",{className:"flex-1 flex flex-col gap-1",children:[(0,n.jsx)("span",{className:"flex flex-wrap gap-1",children:e.triggers.map(e=>(0,n.jsx)("code",{className:"px-1.5 py-0.5 rounded bg-muted text-xs font-mono text-muted-foreground",children:e},e))}),e.notes?.map(e=>(0,n.jsx)("span",{className:"text-xs leading-snug text-muted-foreground/70",children:d(e)},e))]})]},e.key))}),(0,n.jsxs)("button",{type:"button",onClick:()=>w(nb),title:d("console.launchShell"),className:"self-start flex items-center gap-2 px-4 py-2 rounded-lg border border-input bg-background text-sm text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95 transition-all",children:[(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,n.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]}),"New PTY"]})]})}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{ref:es}),I&&(0,n.jsx)("div",{className:"flex justify-center mb-4",children:(0,n.jsx)("button",{onClick:()=>F(B+1),disabled:D,className:"px-4 py-2 text-sm text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors disabled:opacity-50",children:D?d("console.loadingMore"):d("console.loadMoreHistory")})}),(0,n.jsx)("div",{className:W?"flex flex-col gap-3":K?"grid grid-cols-2 gap-3":"flex flex-col gap-3",children:c.map(t=>(0,n.jsx)(r7,{item:t,selected:x===t.data.id,maximized:W===t.data.id,initialSleeping:N.has(t.data.id),tabId:r,projectCwd:e,expandedHeight:_,bubbleContentHeight:eL,onDragStart:eg,onDragOver:ev,onDragEnter:ej,onDragLeave:ew,onDrop:ek,onDragEnd:ey,onSelectId:h,onInterruptId:f,onStdin:p,onDeleteCommand:g,onRerun:b,subscribePtyOutput:A,subscribePtyReset:H,subscribePtyRefresh:z,ptySizeRef:v,resizePty:j,onToggleMaximizeId:eN,onTitleMouseDown:ep,onClosePlugin:y,addBrowserItem:eC,onSleep:C,onWake:S},t.data.id))}),(0,n.jsx)("div",{ref:ea})]})}),!W&&c.length>0&&(0,n.jsx)(nf,{showTop:X,showBottom:et,onScrollTop:eh,onScrollBottom:M}),(0,n.jsx)(nh,{cwd:e,currentCwd:L,commandHistoryRef:E,gridLayout:K,onGridLayoutChange:t=>{Q(t),u.t4.runFork((0,tU.Yn)({cwd:e,settings:{gridLayout:t}}).pipe(eb.sFT(e=>eb.OH5(()=>console.error("Failed to save project settings:",e))),eb.NWQ(()=>eb.rIH)))},onExecute:w,onAddPluginItem:k,onShowEnvManager:()=>J(!0),onOpenShell:()=>w(nb),onOpenNote:l}),G&&(0,n.jsx)(nr,{cwd:e,tabId:r,onClose:()=>J(!1),onSave:e=>P(e)}),Y&&(0,n.jsx)(ns,{onClose:()=>Z(!1),onSave:e=>$(e)})]})});var ny=r(83897),nN=r(54271);function nC(e,t,r,n){return n&&r&&t.includes(e)}var nS=r(54356),nM=r(76412),nL=r(24058),nE=r(56058),nP=r(32880),n$=r(29899),nT=r(98307),nR=r(65153),nI=r(45720);function nF({cwd:e,sessionId:t,engine:r,onOpenProjectSessions:a,onOpenSessionBrowser:l,onOpenSettings:i}){let{t:d}=(0,o.Bd)(),[c,u]=(0,s.useState)(!1),m=t?(0,nI.X)(r,t):null;return(0,n.jsx)("div",{className:"border-b border-border px-4 py-3 bg-card",children:(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("img",{src:"/icons/icon-72x72.png",alt:"Cockpit",className:"w-6 h-6"}),(0,n.jsxs)("div",{className:"flex items-baseline gap-2",children:[(0,n.jsx)("h1",{className:"text-lg font-semibold text-foreground",children:"Cockpit"}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:"One seat. One AI. Everything under control."})]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[e&&(0,n.jsx)("span",{className:"text-sm text-foreground max-w-md truncate cursor-help","data-tooltip":`CWD: ${e}`,children:e}),!e&&t&&(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:["Session: ",t.slice(0,8),"..."]}),e&&(0,n.jsx)("button",{onClick:a,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:d("sessions.projectSessions"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),(0,n.jsx)("button",{onClick:l,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:d("sessions.browseAllSessions"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}),m&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(m).then(()=>{u(!0),setTimeout(()=>u(!1),2e3)})},className:`p-2 rounded-lg transition-colors ${c?"text-green-11 bg-green-500/10":"text-muted-foreground hover:text-foreground hover:bg-hover"}`,title:c?d("chat.copiedCommandTooltip"):d("chat.copyCommandTooltip",{command:m}),children:c?(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}):(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3m2 4H10m0 0l3-3m-3 3l3 3"})})}),(0,n.jsx)("button",{onClick:i,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:d("settings.title"),children:(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]})})]})]})})}function nB({tokenUsage:e,rateLimitInfo:t}){let{t:r}=(0,o.Bd)(),[a,l]=(0,s.useState)(()=>Date.now());(0,s.useEffect)(()=>{if(!t?.resetsAt)return;let e=setInterval(()=>l(Date.now()),3e4);return()=>clearInterval(e)},[t?.resetsAt]);let i=t?.status==="rejected"?"text-red-11":t?.status==="allowed_warning"?"text-amber-11":"text-muted-foreground",d=t?.status==="rejected"?r("chat.rateLimitRejected","Rate Limited"):t?.status==="allowed_warning"?r("chat.rateLimitWarning","Approaching Limit"):null,c=e=>{if(!e)return"";let t=(e<1e12?1e3*e:e)-a;if(t<=0)return"";let r=Math.ceil(t/6e4);if(r<60)return`${r}m`;let n=Math.floor(r/60),s=r%60;return s>0?`${n}h${s}m`:`${n}h`},u=e=>e?e.replace(/_/g," "):"";return(0,n.jsx)("div",{className:"px-4 py-1.5 border-t border-border ",children:(0,n.jsxs)("div",{className:"flex items-center justify-end gap-4 text-xs text-muted-foreground",children:[t&&d&&(0,n.jsxs)("span",{className:`flex items-center gap-1 ${i}`,"data-tooltip":[t.rateLimitType&&`Type: ${u(t.rateLimitType)}`,null!=t.utilization&&`Usage: ${(100*t.utilization).toFixed(0)}%`,t.resetsAt&&`Resets in: ${c(t.resetsAt)}`,t.isUsingOverage&&"Using overage"].filter(Boolean).join(" \xb7 "),children:["rejected"===t.status?(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}):(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,n.jsxs)("span",{children:[(0,n.jsx)("strong",{children:d}),null!=t.utilization&&` ${(100*t.utilization).toFixed(0)}%`,t.resetsAt&&` \xb7 ${c(t.resetsAt)}`]})]}),t&&!d&&t.resetsAt&&(0,n.jsxs)("span",{className:"flex items-center gap-1.5","data-tooltip":[t.rateLimitType&&u(t.rateLimitType),null!=t.utilization&&`Usage: ${(100*t.utilization).toFixed(0)}%`,`Resets in: ${c(t.resetsAt)}`].filter(Boolean).join(" \xb7 "),children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),null!=t.utilization?(0,n.jsxs)("span",{children:[(100*t.utilization).toFixed(0),"%"]}):(0,n.jsx)("span",{children:c(t.resetsAt)})]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})}),(0,n.jsxs)("span",{children:[r("chat.context"),": ",(0,n.jsx)("strong",{className:"text-foreground",children:(e.inputTokens+e.cacheReadInputTokens+e.cacheCreationInputTokens).toLocaleString()})]})]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z"})}),(0,n.jsxs)("span",{children:[r("chat.output"),": ",(0,n.jsx)("strong",{className:"text-foreground",children:e.outputTokens.toLocaleString()})]})]}),(e.cacheReadInputTokens>0||e.cacheCreationInputTokens>0)&&(0,n.jsxs)("span",{className:"flex items-center gap-1 text-brand",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 7v10c0 2.21 3.582 4 8 4s8-1.79 8-4V7M4 7c0 2.21 3.582 4 8 4s8-1.79 8-4M4 7c0-2.21 3.582-4 8-4s8 1.79 8 4"})}),(0,n.jsxs)("span",{children:["Cache: ",(e.cacheReadInputTokens/(e.inputTokens+e.cacheReadInputTokens+e.cacheCreationInputTokens)*100).toFixed(0),"%"]})]}),e.totalCostUsd>0&&(0,n.jsxs)("span",{className:"flex items-center gap-1 text-green-11",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,n.jsxs)("span",{children:["$",e.totalCostUsd.toFixed(4)]})]})]})})}function nD({isOpen:e,onClose:t,cwd:r,sessionId:a,onSelectMessage:l}){let{t:d}=(0,o.Bd)(),[c,x]=(0,s.useState)(null),[h,f]=(0,s.useState)(!1),[p,g]=(0,s.useState)(""),[v,j]=(0,s.useState)(null),w=(0,s.useRef)(null),k=(0,s.useRef)(null);(0,H.E)(t,e),(0,s.useEffect)(()=>{if(!e){x(null),f(!1),g(""),j(null);return}if(!r||!a)return void x([]);let t=!1;return u.t4.runPromiseExit((0,m.nM)(r,a)).then(e=>{t||("Success"===e._tag?x(e.value.messages):(console.error("Failed to load user message index:",e.cause),f(!0),x([])))}),()=>{t=!0}},[e,r,a]);let y=(0,s.useMemo)(()=>{if(!c)return[];let e=c.map((e,t)=>({entry:e,ordinal:t+1})),t=p.trim().toLowerCase();return t?e.filter(e=>e.entry.content.toLowerCase().includes(t)):e},[c,p]),N=p.trim().length>0;(0,s.useEffect)(()=>{if(!e||N||!c)return;let t=w.current;t&&(t.scrollTop=t.scrollHeight)},[e,N,c]);let C=(0,s.useCallback)(async e=>{j(e.id);try{await l(e)}finally{j(null)}t()},[l,t]);if(!e)return null;let S=null===c,M=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-scrim",onClick:t,children:(0,n.jsxs)("div",{className:i.iG,onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border shrink-0",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground",children:d("userMessages.title")}),c&&c.length>0&&(0,n.jsx)("p",{className:"text-xs text-muted-foreground truncate",children:d("userMessages.count",{shown:y.length,total:c.length})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-3 ml-4",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{ref:k,type:"text",autoFocus:!0,placeholder:d("userMessages.searchPlaceholder"),value:p,onChange:e=>g(e.target.value),className:"px-2 py-1 pr-6 text-xs border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),p&&(0,n.jsx)("button",{onClick:()=>{g(""),k.current?.focus()},className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-foreground-subtle hover:text-foreground rounded-sm transition-colors",title:d("fileBrowser.clear"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-foreground-subtle hover:text-foreground hover:bg-hover rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,n.jsx)("div",{ref:w,className:"flex-1 overflow-y-auto",children:S?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:d("common.loading")}):h?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:d("userMessages.loadFailed")}):0===c.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:d("userMessages.noMessages")}):0===y.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:d("userMessages.noResults")}):(0,n.jsx)("div",{className:"divide-y divide-border",children:y.map(({entry:e,ordinal:t})=>{let r,s=e.timestamp?function(e){let t=new Date(e);if(Number.isNaN(t.getTime()))return"";let r=new Date;return t.toDateString()===r.toDateString()?t.toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"}):t.toLocaleDateString("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}(e.timestamp):"";return(0,n.jsx)("button",{onClick:()=>{C(e)},className:"w-full px-4 py-3 text-left hover:bg-hover transition-colors","data-tooltip":(r=e.content.trim()).length>500?`${r.slice(0,500)}…`:r,children:(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsxs)("span",{className:"text-xs text-muted-foreground font-mono w-6 shrink-0 pt-0.5",children:[t,"."]}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("p",{className:"text-sm text-foreground truncate",children:e.content.replace(/\s+/g," ").trim()}),v===e.id&&(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:d("userMessages.jumping")})]}),s&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground shrink-0 pt-0.5",children:s})]})},e.id)})})})]})});return(0,n.jsx)(b.ZL,{children:M})}var nA=r(67589),nH=r(20917),nz=r(74086),nW=r(201),nO=r(94290),n_=r(80860),nq=r(36351);function nV({image:e,onClose:t}){let{t:r}=(0,o.Bd)(),s=async t=>{t.stopPropagation();try{var n;if(!navigator.clipboard?.write||"u"<typeof ClipboardItem)throw Error("Clipboard image write is unavailable");let t=await (n=e.preview,new Promise((e,t)=>{let r=new Image;r.onload=()=>{let n=document.createElement("canvas");n.width=r.naturalWidth,n.height=r.naturalHeight;let s=n.getContext("2d");s?(s.drawImage(r,0,0),n.toBlob(r=>{r?e(r):t(Error("Could not encode image"))},"image/png")):t(Error("Canvas is unavailable"))},r.onerror=()=>t(Error("Could not load image")),r.src=n}));await navigator.clipboard.write([new ClipboardItem({"image/png":t})]),(0,T.oR)(r("imagePreview.copiedImage"),"success")}catch{(0,T.oR)(r("common.copyFailed"),"error")}},a=(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80",onClick:t,children:[(0,n.jsxs)("div",{className:"absolute top-4 right-4 flex items-center gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:s,className:"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",title:r("imagePreview.copyImage"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 7V5a2 2 0 0 1 2-2h7a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2h-2M7 7h6a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2Z"})})}),(0,n.jsx)("button",{type:"button",onClick:t,className:"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",title:r("common.close"),children:(0,n.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("img",{src:e.preview,alt:r("imagePreview.previewImage"),className:"max-w-[90vw] max-h-[90vh] object-contain",onClick:e=>e.stopPropagation()})]});return(0,n.jsx)(b.ZL,{children:a})}function nU({images:e,onRemove:t,disabled:r}){let{t:a}=(0,o.Bd)(),[l,i]=(0,s.useState)(null);return 0===e.length?null:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"flex flex-wrap gap-2 p-2 border-b border-border",children:e.map(e=>(0,n.jsxs)("div",{className:"relative group w-16 h-16 rounded-lg overflow-hidden border border-border cursor-pointer",onClick:()=>i(e),children:[(0,n.jsx)("img",{src:e.preview,alt:a("imagePreview.previewImage"),className:"w-full h-full object-cover hover:opacity-90 transition-opacity"}),(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),t(e.id)},className:"absolute top-0 right-0 w-5 h-5 bg-black/60 hover:bg-black/80 text-white text-xs flex items-center justify-center rounded-bl-lg opacity-0 group-hover:opacity-100 transition-opacity",title:a("imagePreview.deleteImage"),children:"✕"})]},e.id))}),l&&(0,n.jsx)(nV,{image:l,onClose:()=>i(null)})]})}var nK=r(93777),nQ=r(38798),nG=r(94514),nJ=r(59883),nY=r(56204),nZ=r(49387),nX=r(21362),n0=r(63393);let n1=()=>Math.random().toString(36).slice(2,10),n2=e=>e.replace(/\\n/g,"\n");function n5(e){let t=[],r=null;for(let[n,s]of e.split(/\r?\n/).entries()){if(!s.trim())continue;let e=s.match(/^\s*-(?:\s+(.*))?$/);if(e){let t=(e[1]??"").trim();if(!r)return{ok:!1,line:n+1};r.isGroup=!0,t&&r.children.push(n2(t));continue}if(/^\s/.test(s))return{ok:!1,line:n+1};let o=s.trim();o&&(r={text:n2(o),children:[],isGroup:!1},t.push(r))}return{ok:!0,nodes:t.map(e=>e.isGroup?{id:n1(),name:e.text,items:e.children.map(e=>({id:n1(),text:e}))}:{id:n1(),text:e.text})}}function n4({title:e,nodes:t,onSave:r,onClose:a}){let{t:l}=(0,o.Bd)(),[i,d]=(0,s.useState)(()=>t.flatMap(e=>(0,m._9)(e)?[e.name.replace(/\n/g,"\\n"),...e.items.length>0?e.items.map(e=>`- ${e.text.replace(/\n/g,"\\n")}`):["- "]]:[e.text.replace(/\n/g,"\\n")]).join("\n")),[c,u]=(0,s.useState)(!1),[x,h]=(0,s.useState)(!1),f=n5(i);(0,H.E)(a);let p=(0,s.useCallback)(async()=>{let e=n5(i);!e.ok||c||((u(!0),h(!1),await r(e.nodes))?a():(u(!1),h(!0)))},[a,r,c,i]);return(0,n.jsx)(b.ZL,{children:(0,n.jsx)("div",{"data-quick-instruction-layer":"",className:"fixed inset-0 z-[300] flex items-center justify-center bg-scrim p-4",onMouseDown:e=>{e.target===e.currentTarget&&a()},children:(0,n.jsxs)("div",{role:"dialog","aria-modal":"true","aria-label":e,className:"w-full max-w-4xl max-h-[90vh] bg-card border border-border rounded-xl shadow-lv3 flex flex-col",children:[(0,n.jsxs)("header",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:e}),(0,n.jsx)("p",{className:"mt-0.5 text-xs text-muted-foreground",children:l("chat.quickInstructionsMarkdownHint")})]}),(0,n.jsx)("button",{type:"button",onClick:a,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded","aria-label":l("common.cancel"),children:(0,n.jsx)(ei.A,{className:"w-4 h-4"})})]}),(0,n.jsx)("div",{className:"min-h-0 flex-1 px-4 py-3",children:(0,n.jsx)("textarea",{autoFocus:!0,wrap:"off",value:i,onChange:e=>d(e.target.value),placeholder:l("chat.quickInstructionsMarkdownPlaceholder"),rows:24,spellCheck:!1,className:"w-full h-[60vh] min-h-80 max-h-[70vh] resize-y overflow-x-auto whitespace-pre px-3 py-2 text-sm font-mono leading-6 bg-background border border-border rounded-lg text-foreground focus:outline-none focus:border-brand"})}),(0,n.jsxs)("footer",{className:"flex items-center justify-between gap-3 px-4 py-3 border-t border-border",children:[(0,n.jsx)("span",{className:"text-xs text-destructive",children:f.ok?x?l("chat.saveQuickInstructionsFailed"):"":l("chat.quickInstructionsMarkdownError",{line:f.line})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:a,className:"px-3 py-1.5 text-xs text-muted-foreground hover:text-foreground rounded hover:bg-hover",children:l("common.cancel")}),(0,n.jsx)("button",{type:"button",disabled:!f.ok||c,onClick:p,className:"px-3 py-1.5 text-xs rounded border border-brand text-brand hover:bg-brand/10 disabled:opacity-40",children:l(c?"chat.savingQuickInstructions":"common.save")})]})]})]})})})}let n3="data-quick-instruction-layer",n6=()=>Math.random().toString(36).slice(2,10);function n8({groups:e,value:t,onChange:r,onSubmit:a,onCancel:l}){let{t:i}=(0,o.Bd)(),[d,c]=(0,s.useState)(!1),[u,m]=(0,s.useState)(null),[x,h]=(0,s.useState)(0),f=(0,s.useRef)(null),g=(0,s.useRef)(null),b=[null,...e.map(e=>e.id)],v=null===t?i("chat.instructionGroupNone"):e.find(e=>e.id===t)?.name??i("chat.instructionGroupNone"),j=(0,s.useCallback)(()=>{let r=f.current?.getBoundingClientRect();r&&(m(((e,t,r)=>{let n=Math.min(e.width,r.width-16),s=Math.min(Math.max(8,e.left),Math.max(8,r.width-n-8)),o=r.height-e.bottom-2-8,a=e.top-2-8,l=28*t+8;if(o>=Math.min(l,96)||o>=a)return{left:s,top:e.bottom+2,width:n,maxHeight:Math.max(28,Math.min(l,o))};let i=Math.max(28,Math.min(l,a));return{left:s,top:e.top-2-i,width:n,maxHeight:i}})(r,e.length+1,{width:window.innerWidth,height:window.innerHeight})),h(Math.max(0,b.indexOf(t))),c(!0))},[e.length,b,t]),w=(0,s.useCallback)(()=>{c(!1),m(null),f.current?.focus()},[]),k=(0,s.useCallback)(e=>{r(e),w()},[r,w]);(0,s.useEffect)(()=>{if(!d)return;let e=e=>{let t=e.target;g.current?.contains(t)||f.current?.contains(t)||(c(!1),m(null))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[d]),(0,s.useEffect)(()=>{if(!d)return;let e=()=>{c(!1),m(null)};return window.addEventListener("resize",e),window.addEventListener("scroll",e,!0),()=>{window.removeEventListener("resize",e),window.removeEventListener("scroll",e,!0)}},[d]);let y=(0,s.useCallback)(e=>{d?"Escape"===e.key?(e.preventDefault(),e.stopPropagation(),w()):"ArrowDown"===e.key?(e.preventDefault(),e.stopPropagation(),h(e=>Math.min(b.length-1,e+1))):"ArrowUp"===e.key?(e.preventDefault(),e.stopPropagation(),h(e=>Math.max(0,e-1))):"Enter"===e.key&&(e.preventDefault(),e.stopPropagation(),k(b[x]??null)):"ArrowDown"===e.key||" "===e.key?(e.preventDefault(),e.stopPropagation(),j()):"Enter"===e.key?(e.preventDefault(),e.stopPropagation(),a()):"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),l())},[d,j,w,k,b,x,a,l]);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{ref:f,type:"button",onClick:()=>d?w():j(),onKeyDown:y,className:"w-[140px] min-w-0 flex-shrink-0 px-2 py-1 flex items-center gap-1 text-xs rounded border border-input bg-background hover:bg-hover focus:outline-none focus:ring-1 focus:ring-ring transition-colors",title:i("chat.instructionGroupLabel"),children:[(0,n.jsx)(nQ.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground"}),(0,n.jsx)("span",{className:`flex-1 min-w-0 truncate text-left ${null===t?"text-muted-foreground":""}`,children:v}),(0,n.jsx)(tO.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground"})]}),d&&u&&(0,p.createPortal)((0,n.jsx)("div",{ref:g,[n3]:"",role:"listbox",style:{left:u.left,top:u.top,width:u.width,maxHeight:u.maxHeight},className:"fixed z-[60] py-1 bg-popover border border-border rounded-lg shadow-lv2 overflow-y-auto",children:b.map((r,s)=>{let o=r===t;return(0,n.jsxs)("button",{type:"button",role:"option","aria-selected":o,onClick:()=>k(r),onMouseEnter:()=>h(s),className:`w-full min-w-0 px-2 py-1 flex items-center gap-1.5 text-xs text-left transition-colors ${s===x?"bg-hover":""}`,children:[(0,n.jsx)(nG.A,{className:`w-3 h-3 flex-shrink-0 ${o?"text-brand":"opacity-0"}`}),(0,n.jsx)("span",{className:`flex-1 min-w-0 truncate ${null===r?"text-muted-foreground":""}`,children:null===r?i("chat.instructionGroupNone"):e.find(e=>e.id===r)?.name})]},r??"__none__")})}),document.body)]})}function n9({initialValue:e,placeholder:t,groupChoices:r,initialGroupId:o,onCommit:a,onCancel:l}){let[i,d]=(0,s.useState)(e),[c,u]=(0,s.useState)(o??null),m=(0,s.useCallback)(()=>{let e=i.trim();e&&a(e,c)},[i,c,a]),x=(0,s.useCallback)(e=>{"Enter"!==e.key||e.nativeEvent.isComposing?"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),l()):(e.preventDefault(),e.stopPropagation(),m())},[m,l]);return(0,n.jsxs)("div",{className:"mb-1 flex items-center gap-1",children:[(0,n.jsx)("input",{type:"text",value:i,onChange:e=>d(e.target.value),onKeyDown:x,placeholder:t,autoFocus:!0,className:"flex-1 min-w-0 px-2 py-1 text-xs rounded border border-input bg-background focus:outline-none focus:ring-1 focus:ring-ring"}),r&&r.length>0&&(0,n.jsx)(n8,{groups:r,value:c,onChange:u,onSubmit:m,onCancel:l})]})}let n7=(e,t)=>`flex items-center group min-w-0 rounded transition-opacity ${e?"opacity-50":""} ${t?"border-t-2 border-brand":""}`,se="p-1 text-muted-foreground hover:text-foreground rounded opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0",st=(0,s.memo)(function({item:e,isDragging:t,isDragOver:r,onSelect:s,onInsert:a,onEdit:l,onDelete:i,onDragStart:d,onDragOver:c,onDrop:u,onDragEnd:m,management:x=!0}){let{t:h}=(0,o.Bd)();return(0,n.jsxs)("div",{draggable:x,onDragStart:x?()=>d(e.id):void 0,onDragOver:x?t=>c(t,e.id):void 0,onDrop:x?()=>u(e.id):void 0,onDragEnd:x?m:void 0,className:n7(t,r),children:[x&&(0,n.jsx)(nJ.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity cursor-grab"}),(0,n.jsx)($.m,{content:e.text,children:(0,n.jsxs)("button",{type:"button",onClick:()=>s(e.text),className:"flex-1 min-w-0 flex items-center gap-2 px-2 py-1.5 text-left text-sm rounded hover:bg-hover transition-colors",children:[(0,n.jsx)(nY.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground"}),(0,n.jsx)("span",{className:"truncate",children:e.text})]})}),(0,n.jsx)("button",{type:"button",onClick:()=>a(e.text),className:se,title:h("chat.insertQuickInstruction"),children:(0,n.jsx)(nq.A,{className:"w-3 h-3"})}),x&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:()=>l(e.id),className:se,title:h("common.edit"),children:(0,n.jsx)(nZ.A,{className:"w-3 h-3"})}),(0,n.jsx)("button",{type:"button",onClick:()=>i(e.id),className:`${se} hover:text-destructive`,title:h("common.delete"),children:(0,n.jsx)(ei.A,{className:"w-3 h-3"})})]})]})}),sr=(0,s.memo)(function({group:e,isOpen:t,isDragging:r,isDragOver:a,isDragActive:l,onHoverOpen:i,onHoverClose:d,onToggle:c,onRename:u,onDelete:m,onDragStart:x,onDragOver:h,onDrop:f,onDragEnd:p,management:g=!0}){let{t:b}=(0,o.Bd)(),v=(0,s.useRef)(null),j=(0,s.useCallback)(()=>v.current?.getBoundingClientRect(),[]);return(0,n.jsxs)("div",{ref:v,draggable:g,onDragStart:g?()=>x(e.id):void 0,onDragOver:g?t=>h(t,e.id):void 0,onDrop:g?()=>f(e.id):void 0,onDragEnd:g?p:void 0,onMouseEnter:()=>{if(l)return;let t=j();t&&i(e.id,t)},onMouseLeave:()=>{l||d()},className:`${n7(r,a)} ${t?"bg-hover":""}`,children:[g&&(0,n.jsx)(nJ.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity cursor-grab"}),(0,n.jsxs)("button",{type:"button",onClick:()=>{let t=j();t&&c(e.id,t)},className:"flex-1 min-w-0 flex items-center gap-2 px-2 py-1.5 text-left text-sm rounded hover:bg-hover transition-colors",title:e.name,children:[(0,n.jsx)(nQ.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground"}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:e.name}),(0,n.jsxs)("span",{className:"ml-auto flex items-center gap-1 flex-shrink-0 text-[10px] text-muted-foreground",children:[e.items.length>0&&e.items.length,(0,n.jsx)(nX.A,{className:"w-3 h-3"})]})]}),g&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:()=>u(e.id),className:se,title:b("common.edit"),children:(0,n.jsx)(nZ.A,{className:"w-3 h-3"})}),(0,n.jsx)("button",{type:"button",onClick:()=>m(e.id),className:`${se} hover:text-destructive`,title:b("common.delete"),children:(0,n.jsx)(ei.A,{className:"w-3 h-3"})})]})]})});function sn({group:e,position:t,groupChoices:r,editId:s,isAdding:a,isDragActive:l,dragId:i,dragOverId:d,onMouseEnter:c,onMouseLeave:u,onSelect:m,onInsert:x,onStartEdit:h,onCommitEdit:f,onCancelEdit:g,onDelete:b,onStartAdd:v,onCommitAdd:j,onCancelAdd:w,onDragStart:k,onDragOver:y,onDrop:N,onDragEnd:C,management:S=!0}){let{t:M}=(0,o.Bd)();return(0,p.createPortal)((0,n.jsxs)("div",{[n3]:"",onMouseEnter:c,onMouseLeave:()=>{l||u()},style:{left:t.left,top:t.top,width:t.width,maxHeight:t.maxHeight},className:"fixed z-50 p-2 bg-popover border border-border rounded-lg shadow-lv2 overflow-y-auto",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-muted-foreground px-1 truncate",children:e.name}),S&&(0,n.jsx)("button",{type:"button",onClick:v,className:"p-0.5 text-muted-foreground hover:text-foreground rounded flex-shrink-0",title:M("chat.addQuickInstruction"),children:(0,n.jsx)(nt.A,{className:"w-3.5 h-3.5"})})]}),S&&a&&(0,n.jsx)(n9,{initialValue:"",placeholder:M("chat.quickInstructionPlaceholder"),onCommit:e=>j(e),onCancel:w}),0===e.items.length&&!a&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground px-1 py-1",children:M("chat.noQuickInstructions")}),e.items.map(t=>s===t.id?(0,n.jsx)(n9,{initialValue:t.text,placeholder:M("chat.quickInstructionPlaceholder"),groupChoices:r,initialGroupId:e.id,onCommit:(e,r)=>f(t.id,e,r),onCancel:g},`edit-${t.id}`):(0,n.jsx)(st,{item:t,isDragging:i===t.id,isDragOver:d===t.id&&i!==t.id,onSelect:m,onInsert:x,onEdit:h,onDelete:b,onDragStart:k,onDragOver:y,onDrop:N,onDragEnd:C,management:S},t.id))]}),document.body)}function ss({label:e,nodes:t,scope:r,openGroupId:a,flyoutPosition:l,onOpenFlyout:i,onCloseFlyout:d,onKeepFlyout:c,onSave:u,onSelect:x,onInsert:h,management:f=!0,onManage:p}){let{t:g}=(0,o.Bd)(),[b,v]=(0,s.useState)(null),[j,w]=(0,s.useState)(!1),[k,y]=(0,s.useState)(null),[N,C]=(0,s.useState)(null),[S,M]=(0,s.useState)(null),L=t.filter(m._9),E=a?L.find(e=>e.id===a)??null:null,P=(0,s.useRef)(t);P.current=t;let $=(0,s.useRef)(a);$.current=a;let R=(0,s.useRef)(null);(0,s.useEffect)(()=>{w(!1)},[a]);let I=(0,s.useCallback)(e=>{y(null),u(r,e)},[u,r]),F=(0,s.useCallback)(e=>{v(null),I([...P.current,{id:n6(),text:e}])},[I]),B=(0,s.useCallback)(e=>{v(null),I([...P.current,{id:n6(),name:e,items:[]}])},[I]),D=(0,s.useCallback)((e,t,r,n)=>{let s=P.current,o={id:e,text:t};if(r===n)return void I(s.map(t=>(0,m._9)(t)?t.id===n?{...t,items:t.items.map(t=>t.id===e?o:t)}:t:null===n&&t.id===e?o:t));let a=null===r?s.filter(t=>(0,m._9)(t)||t.id!==e):s.map(t=>(0,m._9)(t)&&t.id===r?{...t,items:t.items.filter(t=>t.id!==e)}:t);I(null===n?[...a,o]:a.map(e=>(0,m._9)(e)&&e.id===n?{...e,items:[...e.items,o]}:e))},[I]),A=(0,s.useCallback)((e,t)=>{I(P.current.map(r=>(0,m._9)(r)&&r.id===e?{...r,name:t}:r))},[I]),H=(0,s.useCallback)(async e=>{let t=P.current.find(t=>t.id===e);if(t&&(0,m._9)(t)&&t.items.length>0){if(!await (0,T.lJ)(g("chat.deleteInstructionGroupConfirm",{name:t.name,count:t.items.length}),{danger:!0,confirmText:g("common.delete")}))return;d()}y(null),I(P.current.filter(t=>t.id!==e))},[I,g,d]),z=(0,s.useCallback)(e=>{let t=$.current;t&&I(P.current.map(r=>(0,m._9)(r)&&r.id===t?e(r):r))},[I]),W=(0,s.useCallback)(e=>{w(!1),z(t=>({...t,items:[...t.items,{id:n6(),text:e}]}))},[z]),O=(0,s.useCallback)(e=>{y(null),z(t=>({...t,items:t.items.filter(t=>t.id!==e)}))},[z]),_=(0,s.useCallback)((e,t,r)=>{D(e,t,$.current,r)},[D]),q=(0,s.useCallback)(e=>{R.current=e,C(e)},[]),V=(0,s.useCallback)(()=>{q(null),M(null)},[q]),U=(0,s.useCallback)(e=>{q(e),d()},[q,d]),K=(0,s.useCallback)((e,t)=>{e.preventDefault(),M(t)},[]),Q=(e,t,r)=>{let n=e.findIndex(e=>e.id===t),s=e.findIndex(e=>e.id===r);if(n<0||s<0)return e;let o=[...e],[a]=o.splice(n,1);return o.splice(s,0,a),o},G=(0,s.useCallback)(e=>{let t=R.current;V(),t&&t!==e&&I(Q(P.current,t,e))},[I,V]),J=(0,s.useCallback)(e=>{let t=R.current;V(),t&&t!==e&&z(r=>({...r,items:Q(r.items,t,e)}))},[z,V]),Y=e=>{let t=P.current.find(t=>(0,m._9)(t)&&t.id===e);return t&&(0,m._9)(t)?t.items.length:0},Z=(0,s.useCallback)((e,t)=>{i(r,e,t,Y(e),!1)},[i,r]),X=(0,s.useCallback)((e,t)=>{$.current===e?d():i(r,e,t,Y(e),!0)},[i,d,r]);return(0,n.jsxs)("div",{className:"p-2",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-muted-foreground px-1",children:e}),f?(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{type:"button",onClick:()=>{y(null),v("group")},className:"p-0.5 text-muted-foreground hover:text-foreground rounded",title:g("chat.addInstructionGroup"),children:(0,n.jsx)(n0.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("button",{type:"button",onClick:()=>{y(null),v("instruction")},className:"p-0.5 text-muted-foreground hover:text-foreground rounded",title:g("chat.addQuickInstruction"),children:(0,n.jsx)(nt.A,{className:"w-3.5 h-3.5"})})]}):p?(0,n.jsx)("button",{type:"button",onClick:p,className:"p-1 text-muted-foreground hover:text-brand rounded hover:bg-hover transition-colors",title:g("common.edit"),"aria-label":g("common.edit"),children:(0,n.jsx)(nZ.A,{className:"w-3.5 h-3.5"})}):null]}),"instruction"===b&&(0,n.jsx)(n9,{initialValue:"",placeholder:g("chat.quickInstructionPlaceholder"),onCommit:e=>F(e),onCancel:()=>v(null)}),"group"===b&&(0,n.jsx)(n9,{initialValue:"",placeholder:g("chat.instructionGroupNamePlaceholder"),onCommit:e=>B(e),onCancel:()=>v(null)}),0===t.length&&!b&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground px-1 py-1",children:g("chat.noQuickInstructions")}),t.map(e=>k===e.id?(0,m._9)(e)?(0,n.jsx)(n9,{initialValue:e.name,placeholder:g("chat.instructionGroupNamePlaceholder"),onCommit:t=>A(e.id,t),onCancel:()=>y(null)},`edit-${e.id}`):(0,n.jsx)(n9,{initialValue:e.text,placeholder:g("chat.quickInstructionPlaceholder"),groupChoices:L,initialGroupId:null,onCommit:(t,r)=>D(e.id,t,null,r),onCancel:()=>y(null)},`edit-${e.id}`):(0,m._9)(e)?(0,n.jsx)(sr,{group:e,isOpen:a===e.id,isDragging:N===e.id,isDragOver:S===e.id&&N!==e.id,isDragActive:null!==N,onHoverOpen:Z,onHoverClose:d,onToggle:X,onRename:y,onDelete:H,onDragStart:U,onDragOver:K,onDrop:G,onDragEnd:V,management:f},e.id):(0,n.jsx)(st,{item:e,isDragging:N===e.id,isDragOver:S===e.id&&N!==e.id,onSelect:x,onInsert:h,onEdit:y,onDelete:H,onDragStart:U,onDragOver:K,onDrop:G,onDragEnd:V,management:f},e.id)),E&&l&&(0,n.jsx)(sn,{group:E,position:l,groupChoices:L,editId:k,isAdding:j,isDragActive:null!==N,dragId:N,dragOverId:S,onMouseEnter:c,onMouseLeave:d,onSelect:x,onInsert:h,onStartEdit:y,onCommitEdit:_,onCancelEdit:()=>y(null),onDelete:O,onStartAdd:()=>{y(null),w(!0)},onCommitAdd:W,onCancelAdd:()=>w(!1),onDragStart:q,onDragOver:K,onDrop:J,onDragEnd:V,management:f})]})}function so({cwd:e,anchorRef:t,onClose:r,onSelect:a,onInsert:l}){let{t:i}=(0,o.Bd)(),[d,c]=(0,s.useState)([]),[x,h]=(0,s.useState)([]),[f,p]=(0,s.useState)(null),[g,b]=(0,s.useState)(null),v=(0,s.useRef)(null),j=(0,s.useRef)(null),w=(0,s.useCallback)(()=>{v.current&&(clearTimeout(v.current),v.current=null),j.current&&(clearTimeout(j.current),j.current=null)},[]);(0,s.useEffect)(()=>w,[w]),(0,s.useEffect)(()=>{let t=!1;return(async()=>{let[r,n]=await Promise.all([u.t4.runPromiseExit((0,m.ZQ)()),e?u.t4.runPromiseExit((0,m.$x)(e)):null]);!t&&("Success"===r._tag?c(r.value.instructions??[]):console.error("Failed to load global instructions:",r.cause),n&&"Success"===n._tag?h(n.value.instructions??[]):n&&console.error("Failed to load project instructions:",n.cause))})(),()=>{t=!0}},[e]),(0,s.useEffect)(()=>{let e=e=>{let n;if((n=e.target)instanceof Element&&null!==n.closest(`[${n3}]`))return;let s=t.current;s&&!s.contains(e.target)&&r()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[t,r]),(0,s.useEffect)(()=>{if(!f)return;let e=()=>{w(),p(null)};return window.addEventListener("resize",e),window.addEventListener("scroll",e,!0),()=>{window.removeEventListener("resize",e),window.removeEventListener("scroll",e,!0)}},[f,w]);let k=(0,s.useCallback)((e,t,r,n,s)=>{w();let o=()=>{var s;let o,a,l,i,d,c,u;return p({scope:e,groupId:t,position:(a=(s={width:window.innerWidth,height:window.innerHeight}).width-r.right-4-8,l=r.left-4-8,i=288,a>=288?o=r.right+4:l>=288?o=r.left-4-288:a>=l?(i=Math.max(180,a),o=r.right+4):(i=Math.max(180,l),o=r.left-4-i),o=Math.min(Math.max(8,o),Math.max(8,s.width-i-8)),c=Math.min(d=Math.max(90,.6*s.height),30*n+40),(u=r.top-4)+c>s.height-8&&(u=s.height-8-c),{left:o,top:u=Math.max(8,u),width:i,maxHeight:d})})};s?o():v.current=setTimeout(o,150)},[w]),y=(0,s.useCallback)(()=>{w(),j.current=setTimeout(()=>p(null),300)},[w]),N=(0,s.useCallback)(()=>w(),[w]),C=(0,s.useCallback)(async(t,r)=>{let n="global"===t?c:h;n(r);let s=await u.t4.runPromiseExit((0,m.hZ)("global"===t?{scope:"global",instructions:r}:{cwd:e,instructions:r}));return"Failure"===s._tag?(console.error(`Failed to save ${t} instructions:`,s.cause),!1):(s.value?.instructions&&n(s.value.instructions),!0)},[e]),S=(0,s.useCallback)(e=>{r(),a(e)},[r,a]),M=(0,s.useCallback)(e=>{r(),l(e)},[r,l]),L=(0,s.useCallback)(async e=>!!g&&C(g,e),[g,C]);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"absolute bottom-full left-0 mb-2 w-80 max-w-[calc(100vw-1.5rem)] bg-popover border border-border rounded-lg shadow-lv2 z-50 max-h-[70vh] overflow-y-auto",children:[(0,n.jsx)(ss,{label:i("chat.globalInstructions"),nodes:d,scope:"global",openGroupId:f?.scope==="global"?f.groupId:null,flyoutPosition:f?.scope==="global"?f.position:null,onOpenFlyout:k,onCloseFlyout:y,onKeepFlyout:N,onSave:C,onSelect:S,onInsert:M,management:!1,onManage:()=>{w(),p(null),b("global")}}),e&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsx)(ss,{label:i("chat.projectInstructions"),nodes:x,scope:"project",openGroupId:f?.scope==="project"?f.groupId:null,flyoutPosition:f?.scope==="project"?f.position:null,onOpenFlyout:k,onCloseFlyout:y,onKeepFlyout:N,onSave:C,onSelect:S,onInsert:M,management:!1,onManage:()=>{w(),p(null),b("project")}})]})]}),g&&(0,n.jsx)(n4,{title:i("global"===g?"chat.editGlobalInstructions":"chat.editProjectInstructions"),nodes:"global"===g?d:x,onSave:L,onClose:()=>b(null)})]})}var sa=r(96625);let sl=(0,s.memo)(function({onSend:e,disabled:t,cwd:r,engine:a,onShowGitStatus:l,onShowComments:i,hasComments:d,onOpenNote:c,isFavorite:u,onToggleFavorite:m,onCreateScheduledTask:x,draft:h,setDraft:f,draftImages:p,setDraftImages:g}){let{t:b}=(0,o.Bd)(),v=(0,s.useState)(""),j=(0,s.useState)([]),[w,k]=void 0!==h&&f?[h,f]:v,[y,N]=void 0!==p&&g?[p,g]:j,[C,S]=(0,s.useState)(!1),[M,L]=(0,s.useState)(!1),E=(0,s.useRef)(null),P=(0,s.useRef)(null),$=(0,s.useCallback)(()=>{let e=E.current;if(!e)return;e.style.height="auto";let t=Math.max(38,Math.min(e.scrollHeight,200));e.style.height=`${t}px`},[]);(0,s.useLayoutEffect)(()=>{$()},[w,$]);let T=(0,s.useMemo)(()=>a&&"claude"!==a?[]:[{name:"/plan",description:"Enable plan mode (read-only). /plan <task> to plan a task; /plan off to disable.",source:"builtin",argumentHint:"[task|off]"}],[a]),R=(0,sa.n)({value:w,onChange:k,textareaRef:E,extraCommands:T}),I=(0,s.useCallback)(()=>{let r=w.trim();(r||y.length>0)&&!t&&(e(r,y.length>0?y:void 0),k(""),N([]),E.current&&(E.current.style.height="auto"))},[w,y,t,e]),F=(0,s.useCallback)(r=>{t||e(r)},[t,e]),B=(0,s.useCallback)(e=>{k(t=>{let r=t.replace(/\s+$/,"");return r?`${r}
|
|
33
|
-
${e}`:e}),requestAnimationFrame(()=>{let e=E.current;e&&(e.focus(),e.setSelectionRange(e.value.length,e.value.length))})},[]),D=(0,s.useCallback)(e=>{e.nativeEvent.isComposing||!R.handleKeyDown(e)&&("Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),I()))},[R,I]),A=(0,s.useCallback)(e=>{let t=e.clipboardData?.items;if(!t)return;let r=["image/png","image/jpeg","image/webp","image/gif"];for(let n of Array.from(t)){let t=r.find(e=>n.type===e);if(t){e.preventDefault();let r=n.getAsFile();if(!r)continue;if(r.size>5242880){alert(b("chat.imageSizeLimit",{size:(r.size/1024/1024).toFixed(2)}));continue}let s=new FileReader;s.onload=e=>{let r=e.target?.result;if(!r)return;let n=r.replace(/^data:image\/\w+;base64,/,""),s={id:`img-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,data:n,preview:r,media_type:t};N(e=>[...e,s])},s.readAsDataURL(r)}}},[b]),H=(0,s.useCallback)(e=>{N(t=>t.filter(t=>t.id!==e))},[]);return(0,n.jsxs)("div",{className:"border-t border-border bg-card relative",children:[(0,n.jsx)(nU,{images:y,onRemove:H,disabled:t}),(0,n.jsx)(sa.V,{ac:R,className:"absolute bottom-full left-0 right-0 mx-4 mb-2 max-h-64"}),(0,n.jsxs)("div",{className:"flex gap-2 items-end p-4",children:[l&&(0,n.jsx)("button",{onClick:l,className:"p-2 text-brand hover:text-teal-10 hover:bg-brand/10 active:bg-brand/20 active:scale-95 rounded-lg transition-all",title:b("chat.viewGitChanges"),children:(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"6",cy:"6",r:"2",strokeWidth:2}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"2",strokeWidth:2}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"2",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 8v10M18 8v4c0 2-2 4-6 4"})]})}),i&&(0,n.jsx)("button",{onClick:i,className:`p-2 rounded-lg transition-all active:scale-95 ${d?"text-amber-11 hover:text-amber-10 hover:bg-amber-9/10 active:bg-amber-9/20":"text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted"}`,title:b("chat.viewAllComments"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})})}),c&&(0,n.jsx)("button",{onClick:c,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95 rounded-lg transition-all",title:b("chat.projectNotes"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}),m&&(0,n.jsx)("button",{onClick:m,className:`p-2 rounded-lg transition-all ${u?"text-amber-9 hover:text-amber-10 hover:bg-amber-9/10 active:bg-amber-9/20 active:scale-95":"text-muted-foreground hover:text-amber-9 hover:bg-amber-9/10 active:bg-amber-9/20 active:scale-95"}`,title:b(u?"sessions.removeFavorite":"sessions.addFavorite"),"aria-label":b(u?"sessions.removeFavorite":"sessions.addFavorite"),"aria-pressed":u,children:(0,n.jsx)(nO.A,{className:"w-5 h-5",fill:u?"currentColor":"none"})}),x&&(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("button",{onClick:()=>S(!C),className:`p-2 rounded-lg transition-all ${C?"text-brand bg-brand/10":"text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95"}`,title:b("chat.scheduledTasks"),children:(0,n.jsx)(n_.A,{className:"w-5 h-5"})}),C&&(0,n.jsx)(nK.E,{onClose:()=>S(!1),onCreate:x})]}),(0,n.jsxs)("div",{className:"relative",ref:P,children:[(0,n.jsx)("button",{onClick:()=>L(!M),className:`p-2 rounded-lg transition-all ${M?"text-brand bg-brand/10":"text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95"}`,title:b("chat.quickInstructions"),children:(0,n.jsx)(nq.A,{className:"w-5 h-5"})}),M&&(0,n.jsx)(so,{cwd:r,anchorRef:P,onClose:()=>L(!1),onSelect:F,onInsert:B})]}),(0,n.jsx)("textarea",{ref:E,value:w,onChange:e=>{k(e.target.value),R.trackCaret(e.target)},onSelect:e=>R.trackCaret(e.currentTarget),onKeyDown:D,onPaste:A,placeholder:t?b("chat.placeholderDisabled"):b("chat.placeholder"),rows:1,className:"flex-1 resize-none px-4 py-2 border border-border rounded-lg focus:outline-none focus:ring-2 focus:ring-ring bg-card text-foreground"})]})]})});var si=r(57125);function sd(e){return"env"===e?"from env var":"default"===e?"default":null}function sc({currentModel:e,onModelChange:t}){let[r,o]=(0,s.useState)(!1),[a,l]=(0,s.useState)([]),[i,d]=(0,s.useState)(!1),[c,x]=(0,s.useState)(null),[h,f]=(0,s.useState)(!1),[p,g]=(0,s.useState)(!1),[v,j]=(0,s.useState)(!1),[w,k]=(0,s.useState)(null),[y,N]=(0,s.useState)(""),[C,S]=(0,s.useState)("default"),[M,L]=(0,s.useState)(!1),[E,P]=(0,s.useState)(""),[$,T]=(0,s.useState)("default"),[R,I]=(0,s.useState)(""),[F,B]=(0,s.useState)(!1),D=(0,s.useRef)(null),A=(0,s.useRef)(null),H=(0,s.useRef)(null),[z,W]=(0,s.useState)({top:0,left:0}),O=(0,b.F2)();(0,s.useEffect)(()=>{if(!r)return;let e=e=>{A.current&&!A.current.contains(e.target)&&D.current&&!D.current.contains(e.target)&&o(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[r]);let _=(0,s.useCallback)(async()=>{d(!0),x(null);let e=await u.t4.runPromiseExit((0,m.qD)(()=>f(!0)));if(f(!1),"Failure"===e._tag)x("Connection error");else{let t=e.value;switch(t._tag){case"ok":l(t.models);break;case"not-installed":case"error":x(t.message);break;case"not-running":x("Ollama is not running")}}d(!1)},[]),q=(0,s.useCallback)(e=>{N(e.baseUrl),S(e.baseUrlSource),L(e.hasKey),P(e.maskedKey),T(e.keySource),I(""),B(!1)},[]),V=(0,s.useCallback)(async()=>{g(!0),k(null);let e=await u.t4.runPromiseExit((0,m.F4)());"Failure"===e._tag?k("Failed to load config"):q(e.value),g(!1)},[q]),U=async()=>{j(!0),k(null);let e=await u.t4.runPromiseExit((0,m.yS)({baseUrl:y}));"Failure"===e._tag?k("Save failed"):(q(e.value),await _()),j(!1)},K=async()=>{let e=R.trim();if(!e)return;j(!0),k(null);let t=await u.t4.runPromiseExit((0,m.yS)({apiKey:e}));"Failure"===t._tag?k("Save failed"):q(t.value),j(!1)},Q=async()=>{j(!0),k(null);let e=await u.t4.runPromiseExit((0,m.yS)({apiKey:""}));"Failure"===e._tag?k("Clear failed"):q(e.value),j(!1)},G=e?e.replace(/:latest$/,""):"Select model",J=sd(C),Y=sd($),Z=r?(0,n.jsx)(b.ZL,{children:(0,n.jsxs)("div",{ref:A,className:`${si.ys} min-w-[300px]`,style:{top:z.top,left:z.left},children:[(0,n.jsxs)("div",{className:"px-3 py-1.5",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1.5",children:[(0,n.jsx)("span",{className:"text-[11px] font-medium text-muted-foreground",children:"Server URL"}),J&&!p&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground/70",children:J})]}),p?(0,n.jsxs)("div",{className:"flex items-center gap-2 py-1 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:"w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),"Loading..."]}):(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{type:"text",value:y,onChange:e=>N(e.target.value),onKeyDown:e=>{"Enter"===e.key&&U()},placeholder:"http://127.0.0.1:11434",spellCheck:!1,className:`flex-1 min-w-0 text-xs px-2 py-1 rounded bg-secondary text-foreground border border-border focus:outline-none font-mono ${si.Fx}`}),(0,n.jsx)("button",{onClick:U,disabled:v,className:`text-[11px] px-2 py-1 rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${si.$T}`,children:v?"...":"Save"})]})]}),(0,n.jsxs)("div",{className:"px-3 py-1.5",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1.5",children:[(0,n.jsx)("span",{className:"text-[11px] font-medium text-muted-foreground",children:"API Key"}),Y&&M&&!p&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground/70",children:Y})]}),p?null:M&&!F?(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("code",{className:"flex-1 min-w-0 truncate text-xs px-2 py-1 rounded bg-secondary text-foreground font-mono",children:E}),(0,n.jsx)("button",{onClick:()=>{B(!0),I(""),setTimeout(()=>H.current?.focus(),0)},className:"text-[11px] px-2 py-1 rounded bg-secondary hover:bg-hover text-foreground transition-colors",disabled:v,children:"Edit"}),(0,n.jsx)("button",{onClick:Q,className:"text-[11px] px-2 py-1 rounded text-red-11 hover:bg-red-500/10 transition-colors",disabled:v,children:"Clear"})]}):(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{ref:H,type:"password",value:R,onChange:e=>I(e.target.value),onKeyDown:e=>{"Enter"===e.key&&K()},placeholder:"optional — for authenticated servers",spellCheck:!1,className:`flex-1 min-w-0 text-xs px-2 py-1 rounded bg-secondary text-foreground border border-border focus:outline-none font-mono ${si.Fx}`}),(0,n.jsx)("button",{onClick:K,disabled:v||!R.trim(),className:`text-[11px] px-2 py-1 rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${si.$T}`,children:v?"...":"Save"}),M&&(0,n.jsx)("button",{onClick:()=>{B(!1),I("")},className:"text-[11px] px-2 py-1 rounded text-muted-foreground hover:text-foreground transition-colors",children:"Cancel"})]}),w&&(0,n.jsx)("div",{className:"mt-1 text-[11px] text-red-11",children:w})]}),(0,n.jsx)("div",{className:"my-1 border-t border-border"}),(0,n.jsx)("div",{className:"px-3 pt-1 pb-0.5",children:(0,n.jsx)("span",{className:"text-[11px] font-medium text-muted-foreground",children:"Model"})}),(0,n.jsx)("div",{className:"max-h-[240px] overflow-y-auto",children:i||h?(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:"w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),h?"Starting Ollama...":"Loading models..."]}):c?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-red-11",children:c}):0===a.length?(0,n.jsxs)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:["No models found. Run ",(0,n.jsx)("code",{className:"bg-secondary px-1 rounded",children:"ollama pull <model>"})]}):a.map(r=>{var s;let a=r.name===e;return(0,n.jsxs)("button",{onClick:()=>{t(r.name),o(!1)},className:`w-full flex items-center gap-2 px-3 py-1.5 text-xs transition-colors ${a?si.yI:"text-foreground hover:bg-hover"}`,children:[(0,n.jsx)(si.hG,{selected:a}),(0,n.jsx)("span",{className:"truncate",children:r.name.replace(/:latest$/,"")}),(0,n.jsx)("span",{className:"ml-auto pl-2 text-muted-foreground flex-shrink-0",children:r.parameter_size||((s=r.size)<1e9?`${(s/1e6).toFixed(0)}M`:`${(s/1e9).toFixed(1)}G`)})]},r.name)})})]})}):null;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(si.XY,{buttonRef:D,label:G,title:"Configure Ollama",onClick:()=>{if(!r){if(D.current){let e=D.current.getBoundingClientRect(),t=O?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0;W({top:e.bottom+4-n,left:e.left-r})}V(),_()}o(e=>!e)},icon:(0,n.jsx)(si.eV,{engine:"ollama"}),testId:"ollama-config-picker"}),Z]})}let su={deepseek:{label:"DeepSeek",apiKeysUrl:"https://platform.deepseek.com/api_keys",modelsEndpoint:"/v1/models"},kimi:{label:"Kimi",apiKeysUrl:"https://www.kimi.com/code/console",modelsEndpoint:"/coding/v1/models"},glm:{label:"GLM",apiKeysUrl:"https://bigmodel.cn/apikey/platform",modelsEndpoint:"/coding/paas/v4/models",regions:[{id:"cn",label:"中国大陆",hint:"open.bigmodel.cn"},{id:"global",label:"International",hint:"api.z.ai"}]}};function sm({engine:e,currentModel:t,onModelChange:r,onHasKeyChange:o}){let a=su[e],[l,i]=(0,s.useState)(!1),[d,c]=(0,s.useState)(!1),[x,h]=(0,s.useState)(""),[f,p]=(0,s.useState)(""),[g,v]=(0,s.useState)(!1),[j,w]=(0,s.useState)(!1),[k,y]=(0,s.useState)(!1),[N,C]=(0,s.useState)(null),[S,M]=(0,s.useState)(!1),[L,E]=(0,s.useState)([]),[P,$]=(0,s.useState)(null),[T,R]=(0,s.useState)(null),I=(0,s.useRef)(null),F=(0,s.useRef)(null),B=(0,s.useRef)(null),D=(0,s.useRef)(null);(0,s.useEffect)(()=>()=>{D.current&&clearTimeout(D.current)},[]);let A=(0,s.useRef)(t),H=(0,s.useRef)(r),z=(0,s.useRef)(o);(0,s.useEffect)(()=>{A.current=t,H.current=r,z.current=o}),(0,s.useEffect)(()=>{z.current?.(d)},[d]);let[W,O]=(0,s.useState)({top:0,left:0}),_=(0,b.F2)();(0,s.useEffect)(()=>{let t=!1;return(async()=>{let[r,n]=await Promise.all([u.t4.runPromiseExit((0,m.Hw)(e)),u.t4.runPromiseExit((0,m.td)())]);if(t||"Failure"===r._tag)return;c(r.value.hasKey),h(r.value.maskedKey);let s="Success"===n._tag?n.value?.engines?.[e]:void 0,o=s?.builtinModel;!A.current&&o&&H.current(o)})(),()=>{t=!0}},[e]),(0,s.useEffect)(()=>{if(!l)return;let e=e=>{F.current&&!F.current.contains(e.target)&&I.current&&!I.current.contains(e.target)&&i(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[l]);let q=(0,s.useCallback)(async()=>{w(!0),C(null),$(null);let[n,s]=await Promise.all([u.t4.runPromiseExit((0,m.Hw)(e)),u.t4.runPromiseExit((0,m.td)())]);if("Failure"===n._tag){C("Failed to load settings"),w(!1);return}c(n.value.hasKey),h(n.value.maskedKey),p(""),v(!1);let o="Success"===s._tag?s.value:void 0,l=o?.engines?.[e],i=l?.builtinModel;a.regions&&R(l?.region??("en"===o?.language?"global":"cn"));let d=[];if(n.value.hasKey){let t=await u.t4.runPromiseExit((0,m.Fi)(e));"Success"===t._tag?d=t.value.models:$("Failed to load models — check the API key")}E(d);let x=d.map(e=>e.id),f=i&&x.includes(i)?i:x[0];!f||t&&x.includes(t)||r(f),w(!1)},[e,t,r,a.regions]),V=(0,s.useCallback)(async t=>{let r=await u.t4.runPromiseExit((0,m.td)()),n=("Success"===r._tag?r.value:{}).engines||{},s={...n,[e]:{...n[e]||{},builtinModel:t}};if("Failure"===(await u.t4.runPromiseExit((0,m.em)({engines:s})))._tag)throw Error("Failed to save settings")},[e]),U=(0,s.useCallback)(async t=>{R(t);let r=await u.t4.runPromiseExit((0,m.td)()),n=("Success"===r._tag?r.value:{}).engines||{};"Failure"===(await u.t4.runPromiseExit((0,m.em)({engines:{...n,[e]:{...n[e]||{},region:t}}})))._tag?C("Failed to save region"):q()},[e,q]),K=async()=>{let t=f.trim();if(!t)return;y(!0),C(null);let r=await u.t4.runPromiseExit((0,m.dQ)(e,t));"Failure"===r._tag?C("Save failed"):(c(r.value.hasKey),h(r.value.maskedKey),p(""),v(!1),q()),y(!1)},Q=async()=>{y(!0),C(null);let t=await u.t4.runPromiseExit((0,m.dQ)(e,""));"Failure"===t._tag?C("Clear failed"):(c(t.value.hasKey),h(t.value.maskedKey),p(""),v(!1),E([])),y(!1)},G=async()=>{let t=await u.t4.runPromiseExit((0,m.Ny)(e));if("Failure"===t._tag||!t.value.apiKey)return void C("Copy failed");try{await navigator.clipboard.writeText(t.value.apiKey)}catch{C("Clipboard unavailable");return}C(null),M(!0),D.current&&clearTimeout(D.current),D.current=setTimeout(()=>M(!1),1500)},J=async e=>{r(e);try{await V(e)}catch{}},Y=d?t||"Select model":"Set API key",Z=d?void 0:si.Aw,X=t||"",ee=l?(0,n.jsx)(b.ZL,{children:(0,n.jsx)("div",{ref:F,className:`${si.ys} min-w-[280px]`,style:{top:W.top,left:W.left},children:j?(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:"w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),"Loading..."]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-3 py-1.5",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1 mb-1.5",children:[(0,n.jsx)("span",{className:"text-[11px] font-medium text-muted-foreground",children:"API Key"}),(0,n.jsx)("a",{href:a.apiKeysUrl,target:"_blank",rel:"noopener","data-testid":`${e}-api-keys-link`,title:`Open ${a.label} API keys page`,"aria-label":`Open ${a.label} API keys page`,className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})})]}),d&&!g?(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("code",{className:"flex-1 min-w-0 truncate text-xs px-2 py-1 rounded bg-secondary text-foreground font-mono",children:x}),(0,n.jsx)("button",{onClick:G,"data-testid":`${e}-copy-api-key`,title:S?"Copied":"Copy API key","aria-label":"Copy API key",className:`p-1 rounded transition-colors ${S?"text-green-11":"text-muted-foreground hover:text-foreground hover:bg-hover"}`,disabled:k,children:S?(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}):(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:()=>{v(!0),p(""),setTimeout(()=>B.current?.focus(),0)},className:"text-[11px] px-2 py-1 rounded bg-secondary hover:bg-hover text-foreground transition-colors",disabled:k,children:"Edit"}),(0,n.jsx)("button",{onClick:Q,className:"text-[11px] px-2 py-1 rounded text-red-11 hover:bg-red-500/10 transition-colors",disabled:k,children:"Clear"})]}):(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{ref:B,type:"password",value:f,onChange:e=>p(e.target.value),onKeyDown:e=>{"Enter"===e.key&&K()},placeholder:"sk-...",className:`flex-1 min-w-0 text-xs px-2 py-1 rounded bg-secondary text-foreground border border-border focus:outline-none font-mono ${si.Fx}`,autoFocus:!0}),(0,n.jsx)("button",{onClick:K,disabled:k||!f.trim(),className:`text-[11px] px-2 py-1 rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${si.$T}`,children:k?"Saving...":"Save"}),d&&(0,n.jsx)("button",{onClick:()=>{v(!1),p("")},className:"text-[11px] px-2 py-1 rounded text-muted-foreground hover:text-foreground transition-colors",children:"Cancel"})]}),N&&(0,n.jsx)("div",{className:"mt-1 text-[11px] text-red-11",children:N})]}),(0,n.jsx)("div",{className:"my-1 border-t border-border"}),a.regions&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-3 py-1.5",children:[(0,n.jsx)("div",{className:"text-[11px] font-medium text-muted-foreground mb-1.5",children:"Region"}),(0,n.jsx)("div",{className:"inline-flex rounded-md border border-border overflow-hidden text-xs",role:"group","data-testid":`${e}-region-toggle`,children:a.regions.map(t=>(0,n.jsx)("button",{type:"button","data-testid":`${e}-region-${t.id}`,onClick:()=>U(t.id),title:t.hint,className:`px-2 py-0.5 ${T===t.id?"bg-brand text-white":"bg-transparent text-muted-foreground hover:bg-hover"}`,children:t.label},t.id))})]}),(0,n.jsx)("div",{className:"my-1 border-t border-border"})]}),(0,n.jsxs)("div",{className:"px-3 py-1.5",children:[(0,n.jsx)("div",{className:"text-[11px] font-medium text-muted-foreground mb-1.5",children:"Model"}),P&&(0,n.jsx)("div",{className:"mb-1 text-[11px] text-red-11",children:P}),!P&&0===L.length&&(0,n.jsx)("div",{className:"mb-1 text-[11px] text-muted-foreground",children:d?`No models returned by ${a.modelsEndpoint}`:"Save an API key to list models"}),(0,n.jsx)("div",{className:"flex flex-col gap-0.5",children:L.map(e=>{var t;let r=X===e.id,s=(t=e.contextTokens)&&!(t<=0)?t>=1048576?`${Math.round(t/1048576)}M`:`${Math.round(t/1024)}K`:null;return(0,n.jsxs)("button",{onClick:()=>J(e.id),className:`flex items-center gap-2 px-2 py-1 text-xs rounded transition-colors ${r?si.yI:"text-foreground hover:bg-hover"}`,children:[(0,n.jsx)(si.hG,{selected:r}),(0,n.jsx)("span",{className:"truncate",children:e.id}),e.label&&e.label!==e.id&&(0,n.jsx)("span",{className:"truncate text-[10px] text-muted-foreground",children:e.label}),s&&(0,n.jsx)("span",{className:"ml-auto pl-2 text-[10px] text-muted-foreground flex-shrink-0",children:s})]},e.id)})})]})]})})}):null;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(si.XY,{buttonRef:I,label:Y,labelClassName:Z,title:`Configure ${a.label}`,onClick:()=>{if(!l){if(I.current){let e=I.current.getBoundingClientRect(),t=_?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0;O({top:e.bottom+4-n,left:e.left-r})}q()}i(e=>!e)},icon:(0,n.jsx)(si.eV,{engine:e}),testId:`${e}-config-picker`}),ee]})}var sx=r(53317);let sh="claude-opus-5-5",sf="gpt-6.1-sol",sp=[{id:"low",label:"Low"},{id:"medium",label:"Medium"},{id:"high",label:"High"},{id:"xhigh",label:"Extra High"},{id:"max",label:"Max"},{id:"ultracode",label:"Ultracode"},{id:"ultrathink",label:"Ultrathink"}],sg=[{id:"claude-sonnet-5-5",label:"Claude Sonnet 5.5",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"medium"},{id:"claude-sonnet-5",label:"Claude Sonnet 5",effort:["low","medium","high","xhigh","max","ultrathink"],defaultEffort:"high"},{id:"claude-opus-5-5",label:"Claude Opus 5.5",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"medium",fast:!0},{id:"claude-opus-5",label:"Claude Opus 5",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"high",fast:!0},{id:"claude-fable-5-1",label:"Claude Fable 5.1",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"high"},{id:"claude-haiku-5-5",label:"Claude Haiku 5.5",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"medium"},{id:"claude-haiku-4-5",label:"Claude Haiku 4.5",thinking:!0}],sb=[{id:"low",label:"Low"},{id:"medium",label:"Medium"},{id:"high",label:"High"},{id:"xhigh",label:"Extra High"},{id:"max",label:"Max"},{id:"ultra",label:"Ultra"}],sv=[{id:"gpt-6-astra",label:"GPT-6-Astra",reasoning:["low","medium","high","xhigh","max","ultra"],defaultReasoning:"low"},{id:"gpt-6.1-sol",label:"GPT-6.1-Sol",reasoning:["low","medium","high","xhigh","max","ultra"],defaultReasoning:"low"},{id:"gpt-6-sol",label:"GPT-6-Sol",reasoning:["low","medium","high","xhigh","max","ultra"],defaultReasoning:"medium"},{id:"gpt-6-luna",label:"GPT-6-Luna",reasoning:["low","medium","high","xhigh","max"],defaultReasoning:"medium"},{id:"gpt-5.6-sol",label:"GPT-5.6-Sol",reasoning:["low","medium","high","xhigh","max","ultra"],defaultReasoning:"low"}];function sj(e){return sv.find(t=>t.id===e)?.defaultReasoning??"low"}function sw(e,t){let r=sv.find(t=>t.id===e)?.reasoning;return t&&(!r||r.includes(t))?t:sj(e)}function sk(e,t){return e.find(e=>e.id===t)?.label??t}function sy(e){return sg.find(t=>t.id===e)?.fast===!0}function sN(e){return sg.find(t=>t.id===e)?.thinking===!0}function sC(e){let t=sg.find(t=>t.id===e);return t?t.defaultEffort:"high"}function sS(e,t){let r=sg.find(t=>t.id===e),n=r?.effort;return t&&(!r||n?.includes(t))?t:sC(e)}function sM({value:e,selected:t,label:r,defaultValue:s,onSelect:o}){return(0,n.jsxs)("button",{type:"button",onClick:()=>o(e),className:`flex w-full items-start gap-2 px-3 py-2 text-left text-xs transition-colors ${t?si.yI:"text-muted-foreground hover:bg-hover hover:text-foreground"}`,children:[(0,n.jsx)("span",{className:"mt-0.5",children:(0,n.jsx)(si.hG,{selected:t})}),(0,n.jsx)("span",{className:"min-w-0 flex-1 truncate",children:r}),(0,n.jsx)("span",{className:"shrink-0",children:s&&(0,n.jsx)("span",{className:"rounded bg-muted px-1.5 text-[10px] font-medium text-muted-foreground",children:"Default"})})]})}function sL({title:e,selected:t,value:r,items:o,onSelect:a,icon:l,testId:i}){let d=(0,s.useRef)(null),c=(0,s.useRef)(null),[u,m]=(0,s.useState)(!1),[x,h]=(0,s.useState)({top:0,left:0}),f=(0,b.F2)(),p=()=>{let e=d.current?.getBoundingClientRect();if(!e)return;let t=f?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0;h({top:e.bottom+4-n,left:e.left-r})};return(0,s.useEffect)(()=>{if(!u)return;let e=e=>{let t=e.target;c.current?.contains(t)||d.current?.contains(t)||m(!1)},t=()=>p();return document.addEventListener("mousedown",e),window.addEventListener("resize",t),window.addEventListener("scroll",t,!0),()=>{document.removeEventListener("mousedown",e),window.removeEventListener("resize",t),window.removeEventListener("scroll",t,!0)}},[u]),(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)(si.XY,{buttonRef:d,label:r,labelMaxWidth:"max-w-[180px]",title:`${e}: ${r}`,onClick:()=>{u||p(),m(e=>!e)},icon:l,testId:i}),u&&(0,n.jsx)(b.ZL,{children:(0,n.jsxs)("div",{ref:c,className:`${si.ys} min-w-[190px]`,style:{top:x.top,left:x.left},children:[(0,n.jsx)("div",{className:"px-3 pb-1 text-[11px] font-medium text-muted-foreground",children:e}),(0,n.jsx)("div",{className:"flex flex-col",children:o.map(e=>(0,n.jsx)(sM,{value:e.id,selected:t===e.id,label:e.label,defaultValue:e.defaultValue,onSelect:e=>{a(e),m(!1)}},e.id))})]})})]})}function sE(e){let t,r,s,o=e.engine??"claude",a=e.claudeModel??sh,l=sC(a),i=(t=sg.find(e=>e.id===a)?.effort)?t.map(e=>sp.find(t=>t.id===e)??{id:e,label:e}):[],d=sS(a,e.claudeEffort),c=e.claudeFastMode??!1,u=e.claudeThinking??!1,m=e.codexModel??sf,x=sj(m),h=(r=sv.find(e=>e.id===m)?.reasoning)?r.map(e=>sb.find(t=>t.id===e)??{id:e,label:e}):sb,f=sw(m,e.codexReasoningEffort);return"claude"!==o?(0,n.jsxs)("div",{className:"flex min-w-0 items-center gap-1","data-agent-model-traits":!0,children:[(0,n.jsx)(sL,{title:"Model",selected:m,value:sv.find(e=>e.id===m)?.label??(0,sx.U)(m),items:sv.map(e=>({id:e.id,label:e.label,defaultValue:e.id===sf})),onSelect:t=>{e.onCodexModelChange?.(t),e.onCodexReasoningEffortChange?.(sj(t))},icon:(0,n.jsx)(si.eV,{engine:"codex"}),testId:"codex-model-picker"}),(0,n.jsx)(sL,{title:"Reasoning",selected:f,value:sk(sb,f),items:h.map(e=>({...e,defaultValue:e.id===x})),onSelect:t=>e.onCodexReasoningEffortChange?.(t),testId:"codex-reasoning-picker"})]}):(0,n.jsxs)("div",{className:"flex min-w-0 items-center gap-1","data-agent-model-traits":!0,children:[(0,n.jsx)(sL,{title:"Model",selected:a,value:(s=sg.find(e=>e.id===a))?s.label:a.startsWith("claude-")?`Claude ${(0,sx.J)(a)}`:a,items:sg.map(e=>({id:e.id,label:e.label,defaultValue:e.id===sh})),onSelect:t=>{e.onClaudeModelChange?.(t);let r=sC(t);r&&e.onClaudeEffortChange?.(r),sy(t)||e.onClaudeFastModeChange?.(!1),sN(t)||e.onClaudeThinkingChange?.(!1)},icon:(0,n.jsx)(si.eV,{engine:"claude"}),testId:"claude-model-picker"}),d&&i.length>0&&(0,n.jsx)(sL,{title:"Reasoning",selected:d,value:sk(sp,d),items:i.map(e=>({...e,defaultValue:e.id===l})),onSelect:t=>e.onClaudeEffortChange?.(t),testId:"claude-reasoning-picker"}),sy(a)&&(0,n.jsx)(sL,{title:"Fast Mode",selected:c?"on":"off",value:c?"Fast On":"Fast Off",items:[{id:"on",label:"On"},{id:"off",label:"Off",defaultValue:!0}],onSelect:t=>e.onClaudeFastModeChange?.("on"===t),testId:"claude-fast-mode-picker"}),sN(a)&&(0,n.jsx)(sL,{title:"Thinking",selected:u?"on":"off",value:u?"Thinking On":"Thinking Off",items:[{id:"on",label:"On"},{id:"off",label:"Off",defaultValue:!0}],onSelect:t=>e.onClaudeThinkingChange?.("on"===t),testId:"claude-thinking-picker"})]})}var sP=r(6489);let s$=/^#\s+(.*)$/;function sT(e,t=[]){let r=new Map(t.map(e=>[e.name,e.id])),n=[];for(let[t,r]of e.split(/\r?\n/).entries()){let e=r.match(s$);if(e){n.push({name:e[1].trim(),line:t+1,body:[]});continue}let s=n[n.length-1];if(!s){if(r.trim())return{ok:!1,line:t+1,reason:"content-before-heading"};continue}s.body.push(r)}let s=new Set,o=[];for(let e of n){let t=e.body.join("\n").trim();if(!e.name||!t)return{ok:!1,line:e.line,reason:"empty-style"};if(s.has(e.name))return{ok:!1,line:e.line,reason:"duplicate-name"};s.add(e.name),o.push({id:r.get(e.name)??"",name:e.name,content:t})}return{ok:!0,styles:o}}function sR({styles:e,onSave:t,onClose:r}){let{t:a}=(0,o.Bd)(),[l,i]=(0,s.useState)(()=>e.map(e=>`# ${e.name}
|
|
34
|
-
${e.content}`).join("\n\n")),[d,c]=(0,s.useState)(!1),[u,m]=(0,s.useState)(!1),x=sT(l,e);(0,H.E)(r);let h=(0,s.useCallback)(async()=>{let n=sT(l,e);if(n.ok&&!d){if(c(!0),m(!1),await t(n.styles))return void r();c(!1),m(!0)}},[r,t,d,e,l]),f=a("chat.editOutputStyles");return(0,n.jsx)(b.ZL,{children:(0,n.jsx)("div",{className:"fixed inset-0 z-[300] flex items-center justify-center bg-scrim p-4",onMouseDown:e=>{e.target===e.currentTarget&&r()},children:(0,n.jsxs)("div",{role:"dialog","aria-modal":"true","aria-label":f,className:"w-full max-w-4xl max-h-[90vh] bg-card border border-border rounded-xl shadow-lv3 flex flex-col",children:[(0,n.jsxs)("header",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:f}),(0,n.jsx)("p",{className:"mt-0.5 text-xs text-muted-foreground",children:a("chat.outputStylesMarkdownHint")})]}),(0,n.jsx)("button",{type:"button",onClick:r,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded","aria-label":a("common.cancel"),children:(0,n.jsx)(ei.A,{className:"w-4 h-4"})})]}),(0,n.jsx)("div",{className:"min-h-0 flex-1 px-4 py-3",children:(0,n.jsx)("textarea",{autoFocus:!0,value:l,onChange:e=>i(e.target.value),placeholder:a("chat.outputStylesMarkdownPlaceholder"),rows:24,spellCheck:!1,"data-testid":"output-styles-editor",className:"w-full h-[60vh] min-h-80 max-h-[70vh] resize-y px-3 py-2 text-sm font-mono leading-6 bg-background border border-border rounded-lg text-foreground focus:outline-none focus:border-brand"})}),(0,n.jsxs)("footer",{className:"flex items-center justify-between gap-3 px-4 py-3 border-t border-border",children:[(0,n.jsx)("span",{className:"text-xs text-destructive",children:x.ok?u?a("chat.saveQuickInstructionsFailed"):"":a(`chat.outputStylesError.${x.reason}`,{line:x.line})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:r,className:"px-3 py-1.5 text-xs text-muted-foreground hover:text-foreground rounded hover:bg-hover",children:a("common.cancel")}),(0,n.jsx)("button",{type:"button",disabled:!x.ok||d,onClick:h,"data-testid":"output-styles-save",className:"px-3 py-1.5 text-xs rounded border border-brand text-brand hover:bg-brand/10 disabled:opacity-40",children:a(d?"chat.savingQuickInstructions":"common.save")})]})]})]})})})}let sI=[],sF=sI,sB=!1,sD=null,sA=new Set,sH=e=>{sF=e,sA.forEach(e=>e())};function sz(e=!1){return sB&&!e?Promise.resolve():sD||(sD=(async()=>{let e=await u.t4.runPromiseExit((0,m.K4)());(sD=null,"Failure"===e._tag)?console.error("Failed to load output styles:",e.cause):(sB=!0,sH(e.value.styles??sI))})())}async function sW(e){let t=await u.t4.runPromiseExit((0,m.DF)(e));return"Failure"===t._tag?(console.error("Failed to save output styles:",t.cause),!1):(sB=!0,sH(t.value.styles??sI),!0)}let sO=e=>(sA.add(e),()=>{sA.delete(e)}),s_=()=>sF;function sq({value:e,onChange:t}){let{t:r}=(0,o.Bd)(),a=((0,s.useEffect)(()=>{sz()},[]),(0,s.useSyncExternalStore)(sO,s_,()=>sI)),l=(0,s.useRef)(null),i=(0,s.useRef)(null),[d,c]=(0,s.useState)(!1),[u,m]=(0,s.useState)(!1),[x,h]=(0,s.useState)({top:0,left:0}),f=(0,b.F2)(),p=a.find(t=>t.id===e),g=r("chat.outputStyleNone"),v=p?.name??g,j=(0,s.useCallback)(()=>{let e=l.current?.getBoundingClientRect();if(!e)return;let t=f?.getBoundingClientRect();h({top:e.bottom+4-(t?.top??0),left:e.left-(t?.left??0)})},[f]);(0,s.useEffect)(()=>{if(!d)return;let e=e=>{let t=e.target;i.current?.contains(t)||l.current?.contains(t)||c(!1)};return document.addEventListener("mousedown",e),window.addEventListener("resize",j),window.addEventListener("scroll",j,!0),()=>{document.removeEventListener("mousedown",e),window.removeEventListener("resize",j),window.removeEventListener("scroll",j,!0)}},[d,j]);let w=e=>{t(e),c(!1)},k=e=>`flex w-full items-start gap-2 px-3 py-2 text-left text-xs transition-colors ${e?si.yI:"text-muted-foreground hover:bg-hover hover:text-foreground"}`;return(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)(si.XY,{buttonRef:l,label:v,labelMaxWidth:"max-w-[140px]",title:`${r("chat.outputStyle")}: ${v}`,onClick:()=>{d||(j(),sz(!0)),c(e=>!e)},icon:(0,n.jsx)(sP.A,{className:`h-3.5 w-3.5 flex-shrink-0 ${p?"text-brand":""}`}),testId:"output-style-picker"}),d&&(0,n.jsx)(b.ZL,{children:(0,n.jsxs)("div",{ref:i,className:`${si.ys} min-w-[200px] max-w-[320px]`,style:{top:x.top,left:x.left},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between gap-2 px-3 pb-1",children:[(0,n.jsx)("span",{className:"text-[11px] font-medium text-muted-foreground",children:r("chat.outputStyle")}),(0,n.jsx)("button",{type:"button",onClick:()=>{c(!1),m(!0)},className:"p-1 text-muted-foreground hover:text-foreground rounded hover:bg-hover",title:r("chat.editOutputStyles"),"data-testid":"output-style-edit",children:(0,n.jsx)(nZ.A,{className:"w-3 h-3"})})]}),(0,n.jsxs)("div",{className:"flex flex-col",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>w(""),className:k(!p),children:[(0,n.jsx)("span",{className:"mt-0.5",children:(0,n.jsx)(si.hG,{selected:!p})}),(0,n.jsx)("span",{className:"min-w-0 flex-1 truncate",children:g})]}),a.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>w(e.id),className:k(p?.id===e.id),title:e.content,children:[(0,n.jsx)("span",{className:"mt-0.5",children:(0,n.jsx)(si.hG,{selected:p?.id===e.id})}),(0,n.jsx)("span",{className:"min-w-0 flex-1 truncate",children:e.name})]},e.id)),0===a.length&&(0,n.jsx)("div",{className:"px-3 py-2 text-[11px] text-muted-foreground",children:r("chat.noOutputStyles")})]})]})}),u&&(0,n.jsx)(sR,{styles:a,onSave:sW,onClose:()=>m(!1)})]})}let sV={CNY:"\xa5",USD:"$"};function sU({hasKey:e}){let{t}=(0,o.Bd)(),[r,a]=(0,s.useState)(!1),[l,i]=(0,s.useState)(null),[d,c]=(0,s.useState)(null),x=(0,s.useCallback)(async()=>{a(!0),c(null);let e=await u.t4.runPromiseExit((0,m.he)());"Failure"===e._tag?(i(null),c(t("chat.balanceFailed",{defaultValue:"Query failed — check the API key"}))):i(e.value),a(!1)},[t]),h=l?l.balances.map(e=>`${sV[e.currency]??(e.currency?`${e.currency} `:"")}${e.totalBalance}`).join(" / "):"",f=!!(l&&!l.isAvailable);return(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-2",children:[r&&(0,n.jsx)("span",{className:"w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),!r&&d&&(0,n.jsx)("span",{className:"text-xs text-red-11",children:d}),!r&&!d&&l&&(0,n.jsx)("span",{className:`text-xs font-mono ${f?"text-red-11":si.pe.deepseek}`,"data-tooltip":f?t("chat.balanceUnavailable",{defaultValue:"Account is not available for requests"}):void 0,"data-testid":"deepseek-balance-value",children:h||t("chat.balanceEmpty",{defaultValue:"No balance returned"})}),(0,n.jsx)("button",{type:"button","data-testid":"deepseek-balance-button",disabled:!e||r,onClick:x,"data-tooltip":e?void 0:t("chat.balanceNeedsKey",{defaultValue:"Set a DeepSeek API key first"}),className:"px-2 py-0.5 text-xs rounded border border-border text-muted-foreground hover:bg-hover hover:text-foreground transition-colors disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent",children:t("chat.checkBalance",{defaultValue:"Check balance"})}),(0,n.jsx)("a",{href:"https://platform.deepseek.com/usage",target:"_blank",rel:"noopener","data-testid":"deepseek-usage-link",title:t("chat.openUsagePage",{defaultValue:"Open DeepSeek usage console"}),"aria-label":t("chat.openUsagePage",{defaultValue:"Open DeepSeek usage console"}),className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})})]})}let sK={kimi:"https://www.kimi.com/code/console",glm:"https://bigmodel.cn/coding-plan/personal/usage"};function sQ(e){let t=e.remaining??"?",r=e.limit??"?";return`${e.label} ${t}/${r}`}function sG({engine:e,hasKey:t}){let{t:r}=(0,o.Bd)(),[a,l]=(0,s.useState)(!1),[i,d]=(0,s.useState)(null),[c,x]=(0,s.useState)(null),h=(0,s.useCallback)(async()=>{l(!0),x(null);let t=await u.t4.runPromiseExit((0,m.dM)(e));"Failure"===t._tag?(d(null),x(r("chat.quotaFailed",{defaultValue:"Quota unavailable — check the API key"}))):d(t.value),l(!1)},[r,e]),f=i?.windows??[],p=[i?.tier,...f.map(sQ)].filter(Boolean).join(" \xb7 "),g=function(e){if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:`${t.getMonth()+1}/${t.getDate()} ${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}(f.reduce((e,t)=>t.resetTime&&(!e||t.resetTime>e)?t.resetTime:e,null)),b=f.some(e=>0===e.remaining);return(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-2",children:[a&&(0,n.jsx)("span",{className:"w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),!a&&c&&(0,n.jsx)("span",{className:"text-xs text-red-11",children:c}),!a&&!c&&i&&(0,n.jsx)("span",{className:`text-xs font-mono ${b?"text-red-11":si.pe[e]}`,"data-tooltip":g?r("chat.quotaResetAt",{defaultValue:"Resets {{time}}",time:g}):void 0,"data-testid":`${e}-quota-value`,children:p||r("chat.quotaEmpty",{defaultValue:"No quota returned"})}),(0,n.jsx)("button",{type:"button","data-testid":`${e}-quota-button`,disabled:!t||a,onClick:h,"data-tooltip":t?void 0:r("chat.quotaNeedsKey",{defaultValue:"Set an API key first"}),className:"px-2 py-0.5 text-xs rounded border border-border text-muted-foreground hover:bg-hover hover:text-foreground transition-colors disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent",children:r("chat.checkQuota",{defaultValue:"Check quota"})}),(0,n.jsx)("a",{href:sK[e],target:"_blank",rel:"noopener","data-testid":`${e}-console-link`,title:r("chat.openProviderConsole",{defaultValue:"Open the provider console"}),"aria-label":r("chat.openProviderConsole",{defaultValue:"Open the provider console"}),className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})})]})}var sJ=r(67889),sY=r(46456);function sZ(e){if(0===e.length)return"";let t=[tS.A.t("comments.codeRef"),""],r=e.filter(e=>e.filePath===eM.Un),n=e.filter(e=>e.filePath!==eM.Un);for(let e of(n.length>0&&n.forEach((e,r)=>{let n=e.startLine>0||e.endLine>0?`:${e.startLine}-${e.endLine}`:"";t.push(`[${r+1}] ${e.filePath}${n}`),t.push("```"),t.push(e.codeContent),t.push("```"),e.content&&t.push(tS.A.t("comments.note",{content:e.content})),t.push("")}),r)){let r=e.codeContent.split("\n").map(e=>`> ${e}`).join("\n");t.push(r),e.content&&t.push(e.content),t.push("")}return t.join("\n").trim()}function sX({isOpen:e,onClose:t,cwd:r,onNavigateToComment:a}){let{t:l}=(0,o.Bd)(),i=(0,A.r)(),[d,c]=(0,s.useState)([]),[m,x]=(0,s.useState)(!1),[h,f]=(0,s.useState)(null),[p,g]=(0,s.useState)(!1),[v,w]=(0,s.useState)(!1),k=(0,s.useCallback)(async()=>{if(!r)return;x(!0);let e=await u.t4.runPromiseExit((0,sY.$)(r));"Success"===e._tag?c(e.value.comments??[]):console.error("Failed to load comments:",e.cause),x(!1)},[r]);(0,s.useEffect)(()=>{e&&k()},[e,k]);let y=async e=>{let t=await u.t4.runPromiseExit((0,sY.Tu)(r,e));"Success"===t._tag?(c(t=>t.filter(t=>t.id!==e)),(0,eM.Cm)()):console.error("Failed to delete comment:",t.cause)},N=async e=>{f(e.id);try{let t="";if(e.selectedText)t=e.selectedText;else{let n=await u.t4.runPromiseExit((0,j.K)(r,e.filePath));if("Success"!==n._tag||!n.value.ok)throw Error("Failed to read file");t=(n.value.data?.content||"").split("\n").slice(e.startLine-1,e.endLine).join("\n")}let n={filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,content:e.content,codeContent:t},s=sZ([n]);await navigator.clipboard.writeText(s),(0,T.oR)(l("toast.copiedComment"))}catch(e){console.error("Failed to copy comment:",e)}finally{f(null)}},C=async()=>{if(0!==d.length){g(!0);try{let e=await (0,eM.$3)(r),t=sZ(e);await navigator.clipboard.writeText(t),(0,T.oR)(l("toast.copiedAllComments"))}catch(e){console.error("Failed to copy all comments:",e)}finally{g(!1)}}},S=async()=>{if(0!==d.length&&i&&!i.isLoading&&!v){w(!0);try{let e=(await (0,eM.$3)(r)).map(e=>({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0})),n=(0,eM.Gw)(e,"");i.sendMessage(n),await (0,eM.RP)(r),c([]),t()}catch(e){console.error("Failed to send comments to AI:",e)}finally{w(!1)}}},M=d.reduce((e,t)=>(e[t.filePath]||(e[t.filePath]=[]),e[t.filePath].push(t),e),{});if(!e)return null;let L=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-scrim p-4",onClick:t,children:(0,n.jsxs)("div",{className:"w-full max-w-2xl max-h-[80vh] bg-card border border-border rounded-lg shadow-lv3 flex flex-col overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border ",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h2",{className:"text-lg font-semibold text-foreground",children:l("comments.allComments")}),d.length>0&&(0,n.jsx)("button",{onClick:C,disabled:p,className:"p-1 rounded hover:bg-hover text-muted-foreground disabled:opacity-50",title:l("comments.copyAllComments"),children:p?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 rounded hover:bg-hover text-muted-foreground",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:m?(0,n.jsx)("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:l("common.loading")}):0===d.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[(0,n.jsx)("svg",{className:"w-12 h-12 mb-3 opacity-50",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})}),(0,n.jsx)("span",{children:l("comments.noComments")})]}):(0,n.jsx)("div",{className:"space-y-4",children:Object.entries(M).map(([e,t])=>(0,n.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden",children:[(0,n.jsxs)("div",{className:"px-3 py-2 border-b border-border",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-foreground font-mono",children:e===eM.Un?l("comments.aiReply"):e}),(0,n.jsxs)("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",l("comments.nComments",{count:t.length}),")"]})]}),(0,n.jsx)("div",{className:"divide-y divide-border",children:t.map(e=>{var t;return(0,n.jsx)("div",{className:"px-3 py-2 hover:bg-hover cursor-pointer group",onClick:()=>a?.(e),children:(0,n.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[e.startLine>0||e.endLine>0?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{className:"text-xs text-brand font-mono",children:[l("common.line")," ",e.startLine===e.endLine?e.startLine:`${e.startLine}-${e.endLine}`]}),(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:["(",l("comments.linesCount",{count:e.endLine-e.startLine+1}),")"]})]}):e.selectedText?(0,n.jsxs)("span",{className:"text-xs text-muted-foreground italic truncate max-w-[200px]",children:["“",e.selectedText.slice(0,50),e.selectedText.length>50?"...":"","”"]}):null,(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:(t=e.updatedAt||e.createdAt)?new Date(t).toLocaleString("zh-CN",{month:"numeric",day:"numeric",hour:"2-digit",minute:"2-digit"}):""})]}),(0,n.jsx)("p",{className:"text-sm text-foreground line-clamp-2",children:e.content||(0,n.jsx)("span",{className:"text-muted-foreground italic",children:l("comments.noContent")})})]}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),N(e)},disabled:h===e.id,className:"p-1 rounded opacity-0 group-hover:opacity-100 hover:bg-hover text-muted-foreground transition-opacity disabled:opacity-50",title:l("common.copy"),children:h===e.id?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),y(e.id)},className:"p-1 rounded opacity-0 group-hover:opacity-100 hover:bg-hover text-muted-foreground hover:text-red-9 transition-opacity",title:l("common.delete"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]})},e.id)})})]},e))})}),(0,n.jsxs)("div",{className:"px-4 py-3 border-t border-border flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground",children:l("comments.totalComments",{count:d.length})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[i&&(0,n.jsx)("button",{onClick:S,disabled:0===d.length||i.isLoading||v,className:"px-3 py-1.5 text-sm bg-brand text-white rounded hover:bg-brand/90 disabled:opacity-50 disabled:cursor-not-allowed",title:i.isLoading?l("comments.aiResponding"):void 0,children:v?l("comments.submitting"):l("comments.sendToAI")}),(0,n.jsx)("button",{onClick:async()=>{0===d.length||await (0,eM.RP)(r)&&c([])},disabled:0===d.length,className:"px-3 py-1.5 text-sm bg-red-9 text-white rounded hover:bg-red-10 disabled:opacity-50 disabled:cursor-not-allowed",children:l("comments.clearAll")})]})]})]})});return(0,n.jsx)(b.ZL,{children:L})}let s0=`${sJ.o} pl-3 pr-14 bg-card/50`;function s1({tabId:e,initialCwd:t,initialSessionId:r,engine:l,onEngineChange:i,ollamaModel:x,onOllamaModelChange:h,deepseekModel:g,onDeepseekModelChange:b,kimiModel:v,onKimiModelChange:j,glmModel:w,onGlmModelChange:k,claudeModel:y,onClaudeModelChange:N,claudeEffort:C,onClaudeEffortChange:S,claudeFastMode:M,onClaudeFastModeChange:L,claudeThinking:E,onClaudeThinkingChange:P,codexModel:$,onCodexModelChange:R,codexReasoningEffort:I,onCodexReasoningEffortChange:F,planMode:B,onPlanModeChange:D,noHistory:A,onNoHistoryChange:H,outputStyle:z,onOutputStyleChange:W,hideHeader:O,hideSidebar:_,isActive:q=!0,isFocused:V=q,peerTabId:U,peerSide:K,refreshSignal:Q,onLoadingChange:G,onSessionIdChange:J,onTitleChange:Y,onBotChange:Z,onShowGitStatus:X,onOpenNote:ee,isFavorite:et,onToggleFavorite:er,onCreateScheduledTask:en,onOpenSession:es,onContentSearch:eo,onShowFileDiff:ea,onOpenFileLink:el,onOpenSessionBrowser:ei,onOpenSettings:ed}){let ec,{t:eu}=(0,o.Bd)(),em=(0,s.useContext)(a),[ex,eh]=(0,s.useState)(""),[ef,ep]=(0,s.useState)([]),eg=(0,ny.nH)(),[eb,ev]=(0,s.useState)([]),[ej,ew]=(0,s.useState)(null),[ek,ey]=(0,s.useState)(!1),[eN,eC]=(0,s.useState)(!1),[eS,eL]=(0,s.useState)(!1),eE=function(e){let[t,r]=(0,s.useState)(!1);return(0,s.useEffect)(()=>{if(!e)return void r(!1);let t=!1,n=async()=>{let n=await u.t4.runPromiseExit((0,sY.lb)(e));t||"Success"!==n._tag||r((n.value.comments?.length??0)>0)};n();let s=(0,eM.zL)(n);return()=>{t=!0,s()}},[e]),t}(t),[eP,e$]=(0,s.useState)(!1),[eT,eR]=(0,s.useState)(null),[eI,eF]=(0,s.useState)(!1),eB=B??eI,eD=(0,s.useCallback)(e=>{eF(e),D?.(e)},[D]),[eA,eH]=(0,s.useState)(!1),ez=A??eA,eW=(0,s.useCallback)(e=>{eH(e),H?.(e)},[H]),[eO,e_]=(0,s.useState)(""),eq=z??eO,eV=(0,s.useCallback)(e=>{e_(e),W?.(e)},[W]),[eU,eK]=(0,s.useState)(!1),eQ=(0,s.useRef)(null),eG=(0,s.useRef)(null),eJ=(0,s.useCallback)(async e=>{if(!t)return;let r=await u.t4.runPromiseExit((0,m.n_)({cwd:t,sessionId:e}));"Success"===r._tag&&r.value&&"string"==typeof r.value.title?Y?.(r.value.title):"Failure"===r._tag&&console.error("Failed to fetch session title:",r.cause)},[t,Y]),eY=(0,s.useRef)(null),[eZ,eX]=(0,s.useState)(!1),[e0,e1]=(0,s.useState)(null),[e2,e5]=(0,s.useState)(null),[e4,e3]=(0,s.useState)(nH.R),e6=(0,s.useMemo)(()=>(0,nz.hC)(),[]),e8=(0,s.useRef)(!1);(0,s.useEffect)(()=>{e8.current=eZ},[eZ]);let{isLoadingHistory:e9,isLoadingMore:e7,hasMoreHistory:te,loadMoreHistory:tt,ensureTurnLoaded:tr,loadHistoryByCwdAndSessionId:tn,loadedSessionId:ts,loadedEngine:to,loadedBot:ta}=(0,nA.m)(eb,ev,ej,{cwd:t,initialSessionId:r,onSessionId:ew,onTitleChange:Y,onTokenUsage:eR,liveRunningRef:e8}),tl=to??l??void 0;(0,s.useEffect)(()=>{Z?.(ta)},[ta,Z]);let ti=!tl||"claude"===tl,td="codex"===tl,tc=y??sh,tu=sS(tc,C),tm=$??sf,tx=sw(tm,I),th="deepseek"===tl||"kimi"===tl||"glm"===tl?tl:null,tf="kimi"===th?v:"glm"===th?w:g,tp="kimi"===th?j:"glm"===th?k:b,tg="ollama"===tl||null!==th||ti||td;(0,s.useEffect)(()=>{to&&l!==to&&i?.(to)},[l,to,i]);let{isLoading:tb,tokenUsage:tv,liveOutputTokens:tj,runningStartedAt:tw,rateLimitInfo:tk,apiRetryInfo:ty,backgroundTasks:tN,handleSend:tC,handleStop:tS}=(0,nH.e)(eb,ev,{sessionId:ej,cwd:t,engine:tl,planMode:eB,noHistory:ez,outputStyleId:eq,ollamaModel:x,engineModel:tf,claudeModel:tc,claudeEffort:tu,claudeFastMode:M,claudeThinking:E,codexModel:tm,codexReasoningEffort:tx,onSessionId:ew,onFetchTitle:eJ,onRunComplete:()=>eY.current?.(),taskStore:e6}),tM=(0,s.useCallback)((...e)=>(eQ.current?.pinNextUserMessage(),tC(...e)),[tC]),tL=(0,s.useCallback)(async(e,r)=>{let n=e.split("\n")[0];if(ti){let t=/^\/plan(?:\s+([\s\S]*))?$/.exec(e.trim());if(t){let e=(t[1]??"").trim();"off"===e.toLowerCase()?(eD(!1),(0,T.oR)(eu("chat.planModeOff",{defaultValue:"Plan mode off"}),"info")):""===e?(eD(!0),(0,T.oR)(eu("chat.planModeOn",{defaultValue:"Plan mode on"}),"success")):(eD(!0),tM(e,r,{permissionMode:"plan"}));return}}if(n.startsWith("!")&&n.length>1){let s=n.slice(1).trim();if(!s)return void tM(e,r);let o=e.split("\n").slice(1).join("\n").trim(),a=await u.t4.runPromiseExit((0,m.JC)({command:s,cwd:t}));if("Success"===a._tag){let e=a.value,t=[e.stdout,e.stderr].filter(Boolean).join("\n")||"(no output)",n=eu("chat.executedCommand",{command:s,exitInfo:e.exitCode?` (exit code: ${e.exitCode})`:"",output:t});o&&(n+=`
|
|
32
|
+
Error: ${r.message}`,exitCode:1,isRunning:!1,pid:void 0}:n))}},[o,C,m,k,r,e,_,J,q]),ei=(0,s.useCallback)(async t=>{a(e=>e.filter(e=>e.id!==t)),q(t),r&&await u.t4.runPromise((0,tU.SN)(e,r,t,z.current).pipe(eb.sFT(e=>eb.OH5(()=>console.error("Failed to delete command:",e))),eb.NWQ(()=>eb.rIH)))},[e,r,q]),ed=(0,s.useCallback)((t,n,s)=>{var o;let a=t2(t);if(!a)return;let l=a.parse(n);"cwd"in l&&!l.cwd&&(l.cwd=m);let d={id:(o=a.idPrefix,`${o}-${Date.now()}-${Math.random().toString(36).slice(2,8)}`),_type:t,timestamp:new Date().toISOString(),...l};if(i(e=>[...e,d]),w(d.id),setTimeout(Y,100),s){let t=M&&M.length>0?[...M]:H.current.map(e=>e.data.id),n=t.indexOf(s);-1!==n?t.splice(n+1,0,d.id):t.push(d.id),L(t),r&&u.t4.runFork((0,tU.cm)(e,r,t,z.current).pipe(eb.NWQ(()=>eb.rIH)))}if(r){let n=a.toHistory(d);u.t4.runFork((0,tU.AJ)(e,r,{type:t,id:d.id,timestamp:d.timestamp,...n},z.current).pipe(eb.sFT(e=>eb.OH5(()=>console.error(`Failed to save ${t} item:`,e))),eb.NWQ(()=>eb.rIH)))}},[Y,e,r,M]),ec=(0,s.useCallback)(async t=>{let n=l.find(e=>e.id===t);if(i(e=>e.filter(e=>e.id!==t)),w(e=>e===t?null:e),c(e=>{let r=new Set(e);return r.delete(t),r}),n){let e=t2(n._type);e?.onClose?.(n)}r&&u.t4.runFork((0,tU.SN)(e,r,t,z.current).pipe(eb.sFT(e=>eb.OH5(()=>console.error("Failed to delete plugin item:",e))),eb.NWQ(()=>eb.rIH)))},[l,e,r]);A.current=ed,D.current=es;let eu=(0,s.useCallback)((t,n)=>{r&&u.t4.runFork((0,tU.bv)(e,r,t,{sleeping:n},z.current).pipe(eb.NWQ(()=>eb.rIH)))},[e,r]),em=(0,s.useCallback)(e=>{c(t=>new Set(t).add(e)),eu(e,!0)},[eu]),ex=(0,s.useCallback)(e=>{c(t=>{let r=new Set(t);return r.delete(e),r}),eu(e,!1)},[eu]),eh=(0,s.useCallback)(async t=>{L(t),r&&await u.t4.runPromise((0,tU.cm)(e,r,t,z.current).pipe(eb.NWQ(()=>eb.rIH)))},[e,r]),ef=(0,s.useMemo)(()=>{let e=[...o.map(e=>({type:"command",data:e})),...l.map(e=>({type:e._type,data:e}))];if(!M||0===M.length)return e.sort((e,t)=>new Date(e.data.timestamp).getTime()-new Date(t.data.timestamp).getTime());let t=new Map(M.map((e,t)=>[e,t])),r=[],n=[];for(let s of e)t.has(s.data.id)?r.push(s):n.push(s);return r.sort((e,r)=>t.get(e.data.id)-t.get(r.data.id)),n.sort((e,t)=>new Date(e.data.timestamp).getTime()-new Date(t.data.timestamp).getTime()),[...r,...n]},[o,l,M]);H.current=ef,(0,s.useEffect)(()=>{R.current=o.filter(e=>!e.isRunning&&e.command.trim()).map(e=>e.command)},[o]);let ep=async()=>{let t=await u.t4.runPromise((0,tU.QF)(e,r).pipe(eb.sFT(e=>eb.OH5(()=>console.error("Failed to load env:",e))),eb.DM4(()=>({env:{},home:""}))));y(t.env),N.current=t.home},eg=async()=>{S(await u.t4.runPromise((0,tU.Jn)().pipe(eb.sFT(e=>eb.OH5(()=>console.error("Failed to load aliases:",e))),eb.DM4(()=>({})))))},ev=async()=>{if(!r)return;let t=await u.t4.runPromise((0,tU.DN)(e,r).pipe(eb.DM4(()=>[])));t.length>0&&L(t)};return(0,s.useEffect)(()=>{let e={current:!1};return(async()=>{await Z(0),e.current||await ee(e)})(),ep(),eg(),ev(),()=>{e.current=!0}},[Z,ee]),(0,s.useEffect)(()=>()=>{null!==E.current&&cancelAnimationFrame(E.current)},[]),(0,s.useEffect)(()=>()=>{r9()},[]),{commands:o,pluginItems:l,sleepingBubbles:d,consoleItems:ef,currentCwd:m,selectedCommandId:j,setSelectedCommandId:w,customEnv:k,setCustomEnv:y,aliases:C,setAliases:S,isLoadingHistory:h,hasMoreHistory:p,currentPage:b,scrollRef:W,commandHistoryRef:R,ptySizeRef:I,executeCommandRef:D,executeCommand:es,interruptCommand:ea,rerunCommand:el,deleteCommand:ei,addPluginItem:ed,closePluginItem:ec,handleBubbleSleep:em,handleBubbleWake:ex,loadHistory:Z,scrollToBottom:Y,saveBubbleOrder:eh,sendStdin:r4,resizePty:r3,subscribePtyOutput:V,subscribePtyReset:K,subscribePtyRefresh:G}}({cwd:e,initialShellCwd:t,tabId:r,onCwdChange:a}),[W,O]=(0,s.useState)(null),[_,q]=(0,s.useState)(0),[V,U]=(0,s.useState)(0),[K,Q]=(0,s.useState)(!0),[G,J]=(0,s.useState)(!1),[Y,Z]=(0,s.useState)(!1),[X,ee]=(0,s.useState)(!1),[et,er]=(0,s.useState)(!1),en=(0,s.useRef)(null),es=(0,s.useRef)(null),ea=(0,s.useRef)(null),el=(0,s.useRef)(!1),ei=(0,s.useRef)(null),ed=(0,s.useRef)(null),ec=(0,s.useRef)([]);(0,s.useEffect)(()=>{ec.current=c},[c]);let eu=(0,s.useCallback)(()=>{let e=m.current;return!e||e.scrollHeight-e.scrollTop-e.clientHeight<50},[m]),em=(0,s.useCallback)(()=>{let e=m.current;return!e||e.scrollTop<50},[m]),ex=(0,s.useCallback)(()=>{ee(!em()),er(!eu())},[eu,em]),eh=(0,s.useCallback)(()=>{es.current?.scrollIntoView({behavior:"smooth"})},[]),ef=async()=>{let t=await u.t4.runPromiseExit((0,tU.D0)(e));if("Success"===t._tag){let e=t.value.settings;e?.gridLayout!==void 0&&Q(e.gridLayout)}else console.error("Failed to load project settings:",t.cause)};(0,s.useEffect)(()=>{queueMicrotask(()=>ef())},[]);let ep=(0,s.useCallback)(()=>{el.current=!0},[]),eg=(0,s.useCallback)((e,t)=>{if(!el.current)return void e.preventDefault();el.current=!1,ei.current=t,e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",t),e.currentTarget.style.opacity="0.4";let r=e.currentTarget.querySelector("[data-drag-handle]");if(r){let t=r.cloneNode(!0);t.style.cssText="position:fixed;top:-9999px;left:-9999px;width:"+r.offsetWidth+"px;background:hsl(var(--card));color:hsl(var(--foreground));box-shadow:var(--elevation-2);border-radius:8px;padding:4px 12px;opacity:0.9;",document.body.appendChild(t),e.dataTransfer.setDragImage(t,20,16),requestAnimationFrame(()=>document.body.removeChild(t))}},[]),ev=(0,s.useCallback)((e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect="move",ed.current=t},[]),ej=(0,s.useCallback)(e=>{e.preventDefault(),e.currentTarget.classList.add("ring-2","ring-brand")},[]),ew=(0,s.useCallback)(e=>{e.currentTarget.classList.remove("ring-2","ring-brand")},[]),ek=(0,s.useCallback)(e=>{e.preventDefault(),e.currentTarget.classList.remove("ring-2","ring-brand")},[]),ey=(0,s.useCallback)(e=>{e.currentTarget.style.opacity="1";let t=ei.current,r=ed.current;if(ei.current=null,ed.current=null,!t||!r||t===r)return;let n=ec.current.map(e=>e.data.id),s=n.indexOf(t),o=n.indexOf(r);if(-1===s||-1===o)return;let a=[...n];a[s]=r,a[o]=t,R(a)},[R]),eN=(0,s.useCallback)(e=>{O(t=>t===e?null:e)},[]),eC=(0,s.useCallback)((e,t)=>k("browser",e,t),[k]);(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"m"===e.key&&!e.shiftKey&&!e.altKey&&(e.preventDefault(),x&&eN(x))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[x,eN]),(0,s.useEffect)(()=>{let e=m.current;if(!e)return;let t=new ResizeObserver(([e])=>{U(e.contentRect.height)});return t.observe(e),U(e.clientHeight),()=>t.disconnect()},[m]),(0,s.useEffect)(()=>{let e=m.current;if(e)return W?q(e.clientHeight):(e.style.overflow="",q(0)),()=>{e&&(e.style.overflow="")}},[W,m]),(0,s.useEffect)(()=>{let e=m.current;if(!e||!W||!_)return;let t=requestAnimationFrame(()=>{let t=e.querySelector(`[data-bubble-id="${W}"]`);t&&t.scrollIntoView({block:"start"}),e.style.overflow="hidden"});return()=>cancelAnimationFrame(t)},[W,_,m]);let[eS,eM]=(0,s.useState)(null);(0,s.useEffect)(()=>{i&&(O(null),eM(i.commandId))},[i]),(0,s.useEffect)(()=>{if(!eS||!c.some(e=>e.data.id===eS))return;let e=requestAnimationFrame(()=>{let e=m.current,t=e?.querySelector(`[data-bubble-id="${CSS.escape(eS)}"]`);if(!e||!t)return;eM(null),h(eS);let r=t.getBoundingClientRect(),n=e.getBoundingClientRect(),s=r.top-n.top-Math.max(0,(n.height-r.height)/2);e.scrollTo({top:e.scrollTop+s,behavior:"smooth"})});return()=>cancelAnimationFrame(e)},[eS,c,m,h]),(0,s.useEffect)(()=>{if(!eS)return;let e=setTimeout(()=>{eM(null),(0,T.oR)(d("runningTerminals.notFound"),"error")},3e3);return()=>clearTimeout(e)},[eS,d]),(0,s.useEffect)(()=>{let e=e=>{let t=e.detail?.command;t&&w(t)};return window.addEventListener("execute-terminal-command",e),()=>window.removeEventListener("execute-terminal-command",e)},[w]),(0,s.useEffect)(()=>{let e=e=>{let t=e.detail?.url;t&&k("browser",t)};return window.addEventListener("console-open-browser",e),()=>window.removeEventListener("console-open-browser",e)},[k]);let eL=V>0?Math.floor((V-32-12)/2-41):void 0;return(0,n.jsxs)("div",{ref:en,className:"h-full flex flex-col bg-background relative",children:[(0,n.jsx)("div",{ref:m,onScroll:ex,className:`console-scroll-root flex-1 overflow-y-auto ${W?"":"py-4 px-4"}`,children:0===c.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsxs)("div",{className:"w-full max-w-md flex flex-col gap-4 text-sm",children:[(0,n.jsx)("p",{className:"text-muted-foreground",children:d("console.emptyIntro")}),(0,n.jsx)("ul",{className:"flex flex-col gap-2",children:nw.map(e=>(0,n.jsxs)("li",{className:"flex items-start gap-3",children:[(0,n.jsx)("span",{className:"w-16 flex-shrink-0 text-foreground font-medium",children:d(e.label)}),(0,n.jsxs)("span",{className:"flex-1 flex flex-col gap-1",children:[(0,n.jsx)("span",{className:"flex flex-wrap gap-1",children:e.triggers.map(e=>(0,n.jsx)("code",{className:"px-1.5 py-0.5 rounded bg-muted text-xs font-mono text-muted-foreground",children:e},e))}),e.notes?.map(e=>(0,n.jsx)("span",{className:"text-xs leading-snug text-muted-foreground/70",children:d(e)},e))]})]},e.key))}),(0,n.jsxs)("button",{type:"button",onClick:()=>w(nb),title:d("console.launchShell"),className:"self-start flex items-center gap-2 px-4 py-2 rounded-lg border border-input bg-background text-sm text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95 transition-all",children:[(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,n.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]}),"New PTY"]})]})}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{ref:es}),I&&(0,n.jsx)("div",{className:"flex justify-center mb-4",children:(0,n.jsx)("button",{onClick:()=>F(B+1),disabled:D,className:"px-4 py-2 text-sm text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors disabled:opacity-50",children:D?d("console.loadingMore"):d("console.loadMoreHistory")})}),(0,n.jsx)("div",{className:W?"flex flex-col gap-3":K?"grid grid-cols-2 gap-3":"flex flex-col gap-3",children:c.map(t=>(0,n.jsx)(r7,{item:t,selected:x===t.data.id,maximized:W===t.data.id,initialSleeping:N.has(t.data.id),tabId:r,projectCwd:e,expandedHeight:_,bubbleContentHeight:eL,onDragStart:eg,onDragOver:ev,onDragEnter:ej,onDragLeave:ew,onDrop:ek,onDragEnd:ey,onSelectId:h,onInterruptId:f,onStdin:p,onDeleteCommand:g,onRerun:b,subscribePtyOutput:A,subscribePtyReset:H,subscribePtyRefresh:z,ptySizeRef:v,resizePty:j,onToggleMaximizeId:eN,onTitleMouseDown:ep,onClosePlugin:y,addBrowserItem:eC,onSleep:C,onWake:S},t.data.id))}),(0,n.jsx)("div",{ref:ea})]})}),!W&&c.length>0&&(0,n.jsx)(nf,{showTop:X,showBottom:et,onScrollTop:eh,onScrollBottom:M}),(0,n.jsx)(nh,{cwd:e,currentCwd:L,commandHistoryRef:E,gridLayout:K,onGridLayoutChange:t=>{Q(t),u.t4.runFork((0,tU.Yn)({cwd:e,settings:{gridLayout:t}}).pipe(eb.sFT(e=>eb.OH5(()=>console.error("Failed to save project settings:",e))),eb.NWQ(()=>eb.rIH)))},onExecute:w,onAddPluginItem:k,onShowEnvManager:()=>J(!0),onOpenShell:()=>w(nb),onOpenNote:l}),G&&(0,n.jsx)(nr,{cwd:e,tabId:r,onClose:()=>J(!1),onSave:e=>P(e)}),Y&&(0,n.jsx)(ns,{onClose:()=>Z(!1),onSave:e=>$(e)})]})});var ny=r(83897),nN=r(54271);function nC(e,t,r,n){return n&&r&&t.includes(e)}var nS=r(54356),nM=r(76412),nL=r(24058),nE=r(56058),nP=r(32880),n$=r(29899),nT=r(98307),nR=r(65153),nI=r(45720);function nF({cwd:e,sessionId:t,engine:r,onOpenProjectSessions:a,onOpenSessionBrowser:l,onOpenSettings:i}){let{t:d}=(0,o.Bd)(),[c,u]=(0,s.useState)(!1),m=t?(0,nI.X)(r,t):null;return(0,n.jsx)("div",{className:"border-b border-border px-4 py-3 bg-card",children:(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("img",{src:"/icons/icon-72x72.png",alt:"Cockpit",className:"w-6 h-6"}),(0,n.jsxs)("div",{className:"flex items-baseline gap-2",children:[(0,n.jsx)("h1",{className:"text-lg font-semibold text-foreground",children:"Cockpit"}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:"One seat. One AI. Everything under control."})]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[e&&(0,n.jsx)("span",{className:"text-sm text-foreground max-w-md truncate cursor-help","data-tooltip":`CWD: ${e}`,children:e}),!e&&t&&(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:["Session: ",t.slice(0,8),"..."]}),e&&(0,n.jsx)("button",{onClick:a,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:d("sessions.projectSessions"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),(0,n.jsx)("button",{onClick:l,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:d("sessions.browseAllSessions"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}),m&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(m).then(()=>{u(!0),setTimeout(()=>u(!1),2e3)})},className:`p-2 rounded-lg transition-colors ${c?"text-green-11 bg-green-500/10":"text-muted-foreground hover:text-foreground hover:bg-hover"}`,title:c?d("chat.copiedCommandTooltip"):d("chat.copyCommandTooltip",{command:m}),children:c?(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}):(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3m2 4H10m0 0l3-3m-3 3l3 3"})})}),(0,n.jsx)("button",{onClick:i,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:d("settings.title"),children:(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]})})]})]})})}function nB({tokenUsage:e,rateLimitInfo:t}){let{t:r}=(0,o.Bd)(),[a,l]=(0,s.useState)(()=>Date.now());(0,s.useEffect)(()=>{if(!t?.resetsAt)return;let e=setInterval(()=>l(Date.now()),3e4);return()=>clearInterval(e)},[t?.resetsAt]);let i=t?.status==="rejected"?"text-red-11":t?.status==="allowed_warning"?"text-amber-11":"text-muted-foreground",d=t?.status==="rejected"?r("chat.rateLimitRejected","Rate Limited"):t?.status==="allowed_warning"?r("chat.rateLimitWarning","Approaching Limit"):null,c=e=>{if(!e)return"";let t=(e<1e12?1e3*e:e)-a;if(t<=0)return"";let r=Math.ceil(t/6e4);if(r<60)return`${r}m`;let n=Math.floor(r/60),s=r%60;return s>0?`${n}h${s}m`:`${n}h`},u=e=>e?e.replace(/_/g," "):"";return(0,n.jsx)("div",{className:"px-4 py-1.5 border-t border-border ",children:(0,n.jsxs)("div",{className:"flex items-center justify-end gap-4 text-xs text-muted-foreground",children:[t&&d&&(0,n.jsxs)("span",{className:`flex items-center gap-1 ${i}`,"data-tooltip":[t.rateLimitType&&`Type: ${u(t.rateLimitType)}`,null!=t.utilization&&`Usage: ${(100*t.utilization).toFixed(0)}%`,t.resetsAt&&`Resets in: ${c(t.resetsAt)}`,t.isUsingOverage&&"Using overage"].filter(Boolean).join(" \xb7 "),children:["rejected"===t.status?(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}):(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,n.jsxs)("span",{children:[(0,n.jsx)("strong",{children:d}),null!=t.utilization&&` ${(100*t.utilization).toFixed(0)}%`,t.resetsAt&&` \xb7 ${c(t.resetsAt)}`]})]}),t&&!d&&t.resetsAt&&(0,n.jsxs)("span",{className:"flex items-center gap-1.5","data-tooltip":[t.rateLimitType&&u(t.rateLimitType),null!=t.utilization&&`Usage: ${(100*t.utilization).toFixed(0)}%`,`Resets in: ${c(t.resetsAt)}`].filter(Boolean).join(" \xb7 "),children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),null!=t.utilization?(0,n.jsxs)("span",{children:[(100*t.utilization).toFixed(0),"%"]}):(0,n.jsx)("span",{children:c(t.resetsAt)})]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})}),(0,n.jsxs)("span",{children:[r("chat.context"),": ",(0,n.jsx)("strong",{className:"text-foreground",children:(e.inputTokens+e.cacheReadInputTokens+e.cacheCreationInputTokens).toLocaleString()})]})]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z"})}),(0,n.jsxs)("span",{children:[r("chat.output"),": ",(0,n.jsx)("strong",{className:"text-foreground",children:e.outputTokens.toLocaleString()})]})]}),(e.cacheReadInputTokens>0||e.cacheCreationInputTokens>0)&&(0,n.jsxs)("span",{className:"flex items-center gap-1 text-brand",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 7v10c0 2.21 3.582 4 8 4s8-1.79 8-4V7M4 7c0 2.21 3.582 4 8 4s8-1.79 8-4M4 7c0-2.21 3.582-4 8-4s8 1.79 8 4"})}),(0,n.jsxs)("span",{children:["Cache: ",(e.cacheReadInputTokens/(e.inputTokens+e.cacheReadInputTokens+e.cacheCreationInputTokens)*100).toFixed(0),"%"]})]}),e.totalCostUsd>0&&(0,n.jsxs)("span",{className:"flex items-center gap-1 text-green-11",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,n.jsxs)("span",{children:["$",e.totalCostUsd.toFixed(4)]})]})]})})}function nD({isOpen:e,onClose:t,cwd:r,sessionId:a,onSelectMessage:l}){let{t:d}=(0,o.Bd)(),[c,x]=(0,s.useState)(null),[h,f]=(0,s.useState)(!1),[p,g]=(0,s.useState)(""),[v,j]=(0,s.useState)(null),w=(0,s.useRef)(null),k=(0,s.useRef)(null);(0,H.E)(t,e),(0,s.useEffect)(()=>{if(!e){x(null),f(!1),g(""),j(null);return}if(!r||!a)return void x([]);let t=!1;return u.t4.runPromiseExit((0,m.nM)(r,a)).then(e=>{t||("Success"===e._tag?x(e.value.messages):(console.error("Failed to load user message index:",e.cause),f(!0),x([])))}),()=>{t=!0}},[e,r,a]);let y=(0,s.useMemo)(()=>{if(!c)return[];let e=c.map((e,t)=>({entry:e,ordinal:t+1})),t=p.trim().toLowerCase();return t?e.filter(e=>e.entry.content.toLowerCase().includes(t)):e},[c,p]),N=p.trim().length>0;(0,s.useEffect)(()=>{if(!e||N||!c)return;let t=w.current;t&&(t.scrollTop=t.scrollHeight)},[e,N,c]);let C=(0,s.useCallback)(async e=>{j(e.id);try{await l(e)}finally{j(null)}t()},[l,t]);if(!e)return null;let S=null===c,M=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-scrim",onClick:t,children:(0,n.jsxs)("div",{className:i.iG,onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border shrink-0",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground",children:d("userMessages.title")}),c&&c.length>0&&(0,n.jsx)("p",{className:"text-xs text-muted-foreground truncate",children:d("userMessages.count",{shown:y.length,total:c.length})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-3 ml-4",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{ref:k,type:"text",autoFocus:!0,placeholder:d("userMessages.searchPlaceholder"),value:p,onChange:e=>g(e.target.value),className:"px-2 py-1 pr-6 text-xs border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),p&&(0,n.jsx)("button",{onClick:()=>{g(""),k.current?.focus()},className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-foreground-subtle hover:text-foreground rounded-sm transition-colors",title:d("fileBrowser.clear"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-foreground-subtle hover:text-foreground hover:bg-hover rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,n.jsx)("div",{ref:w,className:"flex-1 overflow-y-auto",children:S?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:d("common.loading")}):h?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:d("userMessages.loadFailed")}):0===c.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:d("userMessages.noMessages")}):0===y.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:d("userMessages.noResults")}):(0,n.jsx)("div",{className:"divide-y divide-border",children:y.map(({entry:e,ordinal:t})=>{let r,s=e.timestamp?function(e){let t=new Date(e);if(Number.isNaN(t.getTime()))return"";let r=new Date;return t.toDateString()===r.toDateString()?t.toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"}):t.toLocaleDateString("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}(e.timestamp):"";return(0,n.jsx)("button",{onClick:()=>{C(e)},className:"w-full px-4 py-3 text-left hover:bg-hover transition-colors","data-tooltip":(r=e.content.trim()).length>500?`${r.slice(0,500)}…`:r,children:(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsxs)("span",{className:"text-xs text-muted-foreground font-mono w-6 shrink-0 pt-0.5",children:[t,"."]}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("p",{className:"text-sm text-foreground truncate",children:e.content.replace(/\s+/g," ").trim()}),v===e.id&&(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:d("userMessages.jumping")})]}),s&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground shrink-0 pt-0.5",children:s})]})},e.id)})})})]})});return(0,n.jsx)(b.ZL,{children:M})}var nA=r(67589),nH=r(20917),nz=r(74086),nW=r(201),nO=r(94290),n_=r(80860),nq=r(36351);function nV({image:e,onClose:t}){let{t:r}=(0,o.Bd)(),s=async t=>{t.stopPropagation();try{var n;if(!navigator.clipboard?.write||"u"<typeof ClipboardItem)throw Error("Clipboard image write is unavailable");let t=await (n=e.preview,new Promise((e,t)=>{let r=new Image;r.onload=()=>{let n=document.createElement("canvas");n.width=r.naturalWidth,n.height=r.naturalHeight;let s=n.getContext("2d");s?(s.drawImage(r,0,0),n.toBlob(r=>{r?e(r):t(Error("Could not encode image"))},"image/png")):t(Error("Canvas is unavailable"))},r.onerror=()=>t(Error("Could not load image")),r.src=n}));await navigator.clipboard.write([new ClipboardItem({"image/png":t})]),(0,T.oR)(r("imagePreview.copiedImage"),"success")}catch{(0,T.oR)(r("common.copyFailed"),"error")}},a=(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80",onClick:t,children:[(0,n.jsxs)("div",{className:"absolute top-4 right-4 flex items-center gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:s,className:"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",title:r("imagePreview.copyImage"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 7V5a2 2 0 0 1 2-2h7a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2h-2M7 7h6a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2Z"})})}),(0,n.jsx)("button",{type:"button",onClick:t,className:"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",title:r("common.close"),children:(0,n.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("img",{src:e.preview,alt:r("imagePreview.previewImage"),className:"max-w-[90vw] max-h-[90vh] object-contain",onClick:e=>e.stopPropagation()})]});return(0,n.jsx)(b.ZL,{children:a})}function nU({images:e,onRemove:t,disabled:r}){let{t:a}=(0,o.Bd)(),[l,i]=(0,s.useState)(null);return 0===e.length?null:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"flex flex-wrap gap-2 p-2 border-b border-border",children:e.map(e=>(0,n.jsxs)("div",{className:"relative group w-16 h-16 rounded-lg overflow-hidden border border-border cursor-pointer",onClick:()=>i(e),children:[(0,n.jsx)("img",{src:e.preview,alt:a("imagePreview.previewImage"),className:"w-full h-full object-cover hover:opacity-90 transition-opacity"}),(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),t(e.id)},className:"absolute top-0 right-0 w-5 h-5 bg-black/60 hover:bg-black/80 text-white text-xs flex items-center justify-center rounded-bl-lg opacity-0 group-hover:opacity-100 transition-opacity",title:a("imagePreview.deleteImage"),children:"✕"})]},e.id))}),l&&(0,n.jsx)(nV,{image:l,onClose:()=>i(null)})]})}var nK=r(93777),nQ=r(38798),nG=r(94514),nJ=r(59883),nY=r(56204),nZ=r(49387),nX=r(21362),n0=r(63393);let n1=()=>Math.random().toString(36).slice(2,10),n2=e=>e.replace(/\\n/g,"\n");function n5(e){let t=[],r=null;for(let[n,s]of e.split(/\r?\n/).entries()){if(!s.trim())continue;let e=s.match(/^\s*-(?:\s+(.*))?$/);if(e){let t=(e[1]??"").trim();if(!r)return{ok:!1,line:n+1};r.isGroup=!0,t&&r.children.push(n2(t));continue}if(/^\s/.test(s))return{ok:!1,line:n+1};let o=s.trim();o&&(r={text:n2(o),children:[],isGroup:!1},t.push(r))}return{ok:!0,nodes:t.map(e=>e.isGroup?{id:n1(),name:e.text,items:e.children.map(e=>({id:n1(),text:e}))}:{id:n1(),text:e.text})}}function n4({title:e,nodes:t,onSave:r,onClose:a}){let{t:l}=(0,o.Bd)(),[i,d]=(0,s.useState)(()=>t.flatMap(e=>(0,m._9)(e)?[e.name.replace(/\n/g,"\\n"),...e.items.length>0?e.items.map(e=>`- ${e.text.replace(/\n/g,"\\n")}`):["- "]]:[e.text.replace(/\n/g,"\\n")]).join("\n")),[c,u]=(0,s.useState)(!1),[x,h]=(0,s.useState)(!1),f=n5(i);(0,H.E)(a);let p=(0,s.useCallback)(async()=>{let e=n5(i);!e.ok||c||((u(!0),h(!1),await r(e.nodes))?a():(u(!1),h(!0)))},[a,r,c,i]);return(0,n.jsx)(b.ZL,{children:(0,n.jsx)("div",{"data-quick-instruction-layer":"",className:"fixed inset-0 z-[300] flex items-center justify-center bg-scrim p-4",onMouseDown:e=>{e.target===e.currentTarget&&a()},children:(0,n.jsxs)("div",{role:"dialog","aria-modal":"true","aria-label":e,className:"w-full max-w-4xl max-h-[90vh] bg-card border border-border rounded-xl shadow-lv3 flex flex-col",children:[(0,n.jsxs)("header",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:e}),(0,n.jsx)("p",{className:"mt-0.5 text-xs text-muted-foreground",children:l("chat.quickInstructionsMarkdownHint")})]}),(0,n.jsx)("button",{type:"button",onClick:a,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded","aria-label":l("common.cancel"),children:(0,n.jsx)(ei.A,{className:"w-4 h-4"})})]}),(0,n.jsx)("div",{className:"min-h-0 flex-1 px-4 py-3",children:(0,n.jsx)("textarea",{autoFocus:!0,wrap:"off",value:i,onChange:e=>d(e.target.value),placeholder:l("chat.quickInstructionsMarkdownPlaceholder"),rows:24,spellCheck:!1,className:"w-full h-[60vh] min-h-80 max-h-[70vh] resize-y overflow-x-auto whitespace-pre px-3 py-2 text-sm font-mono leading-6 bg-background border border-border rounded-lg text-foreground focus:outline-none focus:border-brand"})}),(0,n.jsxs)("footer",{className:"flex items-center justify-between gap-3 px-4 py-3 border-t border-border",children:[(0,n.jsx)("span",{className:"text-xs text-destructive",children:f.ok?x?l("chat.saveQuickInstructionsFailed"):"":l("chat.quickInstructionsMarkdownError",{line:f.line})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:a,className:"px-3 py-1.5 text-xs text-muted-foreground hover:text-foreground rounded hover:bg-hover",children:l("common.cancel")}),(0,n.jsx)("button",{type:"button",disabled:!f.ok||c,onClick:p,className:"px-3 py-1.5 text-xs rounded border border-brand text-brand hover:bg-brand/10 disabled:opacity-40",children:l(c?"chat.savingQuickInstructions":"common.save")})]})]})]})})})}let n3="data-quick-instruction-layer",n6=()=>Math.random().toString(36).slice(2,10);function n8({groups:e,value:t,onChange:r,onSubmit:a,onCancel:l}){let{t:i}=(0,o.Bd)(),[d,c]=(0,s.useState)(!1),[u,m]=(0,s.useState)(null),[x,h]=(0,s.useState)(0),f=(0,s.useRef)(null),g=(0,s.useRef)(null),b=[null,...e.map(e=>e.id)],v=null===t?i("chat.instructionGroupNone"):e.find(e=>e.id===t)?.name??i("chat.instructionGroupNone"),j=(0,s.useCallback)(()=>{let r=f.current?.getBoundingClientRect();r&&(m(((e,t,r)=>{let n=Math.min(e.width,r.width-16),s=Math.min(Math.max(8,e.left),Math.max(8,r.width-n-8)),o=r.height-e.bottom-2-8,a=e.top-2-8,l=28*t+8;if(o>=Math.min(l,96)||o>=a)return{left:s,top:e.bottom+2,width:n,maxHeight:Math.max(28,Math.min(l,o))};let i=Math.max(28,Math.min(l,a));return{left:s,top:e.top-2-i,width:n,maxHeight:i}})(r,e.length+1,{width:window.innerWidth,height:window.innerHeight})),h(Math.max(0,b.indexOf(t))),c(!0))},[e.length,b,t]),w=(0,s.useCallback)(()=>{c(!1),m(null),f.current?.focus()},[]),k=(0,s.useCallback)(e=>{r(e),w()},[r,w]);(0,s.useEffect)(()=>{if(!d)return;let e=e=>{let t=e.target;g.current?.contains(t)||f.current?.contains(t)||(c(!1),m(null))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[d]),(0,s.useEffect)(()=>{if(!d)return;let e=()=>{c(!1),m(null)};return window.addEventListener("resize",e),window.addEventListener("scroll",e,!0),()=>{window.removeEventListener("resize",e),window.removeEventListener("scroll",e,!0)}},[d]);let y=(0,s.useCallback)(e=>{d?"Escape"===e.key?(e.preventDefault(),e.stopPropagation(),w()):"ArrowDown"===e.key?(e.preventDefault(),e.stopPropagation(),h(e=>Math.min(b.length-1,e+1))):"ArrowUp"===e.key?(e.preventDefault(),e.stopPropagation(),h(e=>Math.max(0,e-1))):"Enter"===e.key&&(e.preventDefault(),e.stopPropagation(),k(b[x]??null)):"ArrowDown"===e.key||" "===e.key?(e.preventDefault(),e.stopPropagation(),j()):"Enter"===e.key?(e.preventDefault(),e.stopPropagation(),a()):"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),l())},[d,j,w,k,b,x,a,l]);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{ref:f,type:"button",onClick:()=>d?w():j(),onKeyDown:y,className:"w-[140px] min-w-0 flex-shrink-0 px-2 py-1 flex items-center gap-1 text-xs rounded border border-input bg-background hover:bg-hover focus:outline-none focus:ring-1 focus:ring-ring transition-colors",title:i("chat.instructionGroupLabel"),children:[(0,n.jsx)(nQ.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground"}),(0,n.jsx)("span",{className:`flex-1 min-w-0 truncate text-left ${null===t?"text-muted-foreground":""}`,children:v}),(0,n.jsx)(tO.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground"})]}),d&&u&&(0,p.createPortal)((0,n.jsx)("div",{ref:g,[n3]:"",role:"listbox",style:{left:u.left,top:u.top,width:u.width,maxHeight:u.maxHeight},className:"fixed z-[60] py-1 bg-popover border border-border rounded-lg shadow-lv2 overflow-y-auto",children:b.map((r,s)=>{let o=r===t;return(0,n.jsxs)("button",{type:"button",role:"option","aria-selected":o,onClick:()=>k(r),onMouseEnter:()=>h(s),className:`w-full min-w-0 px-2 py-1 flex items-center gap-1.5 text-xs text-left transition-colors ${s===x?"bg-hover":""}`,children:[(0,n.jsx)(nG.A,{className:`w-3 h-3 flex-shrink-0 ${o?"text-brand":"opacity-0"}`}),(0,n.jsx)("span",{className:`flex-1 min-w-0 truncate ${null===r?"text-muted-foreground":""}`,children:null===r?i("chat.instructionGroupNone"):e.find(e=>e.id===r)?.name})]},r??"__none__")})}),document.body)]})}function n9({initialValue:e,placeholder:t,groupChoices:r,initialGroupId:o,onCommit:a,onCancel:l}){let[i,d]=(0,s.useState)(e),[c,u]=(0,s.useState)(o??null),m=(0,s.useCallback)(()=>{let e=i.trim();e&&a(e,c)},[i,c,a]),x=(0,s.useCallback)(e=>{"Enter"!==e.key||e.nativeEvent.isComposing?"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),l()):(e.preventDefault(),e.stopPropagation(),m())},[m,l]);return(0,n.jsxs)("div",{className:"mb-1 flex items-center gap-1",children:[(0,n.jsx)("input",{type:"text",value:i,onChange:e=>d(e.target.value),onKeyDown:x,placeholder:t,autoFocus:!0,className:"flex-1 min-w-0 px-2 py-1 text-xs rounded border border-input bg-background focus:outline-none focus:ring-1 focus:ring-ring"}),r&&r.length>0&&(0,n.jsx)(n8,{groups:r,value:c,onChange:u,onSubmit:m,onCancel:l})]})}let n7=(e,t)=>`flex items-center group min-w-0 rounded transition-opacity ${e?"opacity-50":""} ${t?"border-t-2 border-brand":""}`,se="p-1 text-muted-foreground hover:text-foreground rounded opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0",st=(0,s.memo)(function({item:e,isDragging:t,isDragOver:r,onSelect:s,onInsert:a,onEdit:l,onDelete:i,onDragStart:d,onDragOver:c,onDrop:u,onDragEnd:m,management:x=!0}){let{t:h}=(0,o.Bd)();return(0,n.jsxs)("div",{draggable:x,onDragStart:x?()=>d(e.id):void 0,onDragOver:x?t=>c(t,e.id):void 0,onDrop:x?()=>u(e.id):void 0,onDragEnd:x?m:void 0,className:n7(t,r),children:[x&&(0,n.jsx)(nJ.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity cursor-grab"}),(0,n.jsx)($.m,{content:e.text,children:(0,n.jsxs)("button",{type:"button",onClick:()=>s(e.text),className:"flex-1 min-w-0 flex items-center gap-2 px-2 py-1.5 text-left text-sm rounded hover:bg-hover transition-colors",children:[(0,n.jsx)(nY.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground"}),(0,n.jsx)("span",{className:"truncate",children:e.text})]})}),(0,n.jsx)("button",{type:"button",onClick:()=>a(e.text),className:se,title:h("chat.insertQuickInstruction"),children:(0,n.jsx)(nq.A,{className:"w-3 h-3"})}),x&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:()=>l(e.id),className:se,title:h("common.edit"),children:(0,n.jsx)(nZ.A,{className:"w-3 h-3"})}),(0,n.jsx)("button",{type:"button",onClick:()=>i(e.id),className:`${se} hover:text-destructive`,title:h("common.delete"),children:(0,n.jsx)(ei.A,{className:"w-3 h-3"})})]})]})}),sr=(0,s.memo)(function({group:e,isOpen:t,isDragging:r,isDragOver:a,isDragActive:l,onHoverOpen:i,onHoverClose:d,onToggle:c,onRename:u,onDelete:m,onDragStart:x,onDragOver:h,onDrop:f,onDragEnd:p,management:g=!0}){let{t:b}=(0,o.Bd)(),v=(0,s.useRef)(null),j=(0,s.useCallback)(()=>v.current?.getBoundingClientRect(),[]);return(0,n.jsxs)("div",{ref:v,draggable:g,onDragStart:g?()=>x(e.id):void 0,onDragOver:g?t=>h(t,e.id):void 0,onDrop:g?()=>f(e.id):void 0,onDragEnd:g?p:void 0,onMouseEnter:()=>{if(l)return;let t=j();t&&i(e.id,t)},onMouseLeave:()=>{l||d()},className:`${n7(r,a)} ${t?"bg-hover":""}`,children:[g&&(0,n.jsx)(nJ.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity cursor-grab"}),(0,n.jsxs)("button",{type:"button",onClick:()=>{let t=j();t&&c(e.id,t)},className:"flex-1 min-w-0 flex items-center gap-2 px-2 py-1.5 text-left text-sm rounded hover:bg-hover transition-colors",title:e.name,children:[(0,n.jsx)(nQ.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground"}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:e.name}),(0,n.jsxs)("span",{className:"ml-auto flex items-center gap-1 flex-shrink-0 text-[10px] text-muted-foreground",children:[e.items.length>0&&e.items.length,(0,n.jsx)(nX.A,{className:"w-3 h-3"})]})]}),g&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:()=>u(e.id),className:se,title:b("common.edit"),children:(0,n.jsx)(nZ.A,{className:"w-3 h-3"})}),(0,n.jsx)("button",{type:"button",onClick:()=>m(e.id),className:`${se} hover:text-destructive`,title:b("common.delete"),children:(0,n.jsx)(ei.A,{className:"w-3 h-3"})})]})]})});function sn({group:e,position:t,groupChoices:r,editId:s,isAdding:a,isDragActive:l,dragId:i,dragOverId:d,onMouseEnter:c,onMouseLeave:u,onSelect:m,onInsert:x,onStartEdit:h,onCommitEdit:f,onCancelEdit:g,onDelete:b,onStartAdd:v,onCommitAdd:j,onCancelAdd:w,onDragStart:k,onDragOver:y,onDrop:N,onDragEnd:C,management:S=!0}){let{t:M}=(0,o.Bd)();return(0,p.createPortal)((0,n.jsxs)("div",{[n3]:"",onMouseEnter:c,onMouseLeave:()=>{l||u()},style:{left:t.left,top:t.top,width:t.width,maxHeight:t.maxHeight},className:"fixed z-50 p-2 bg-popover border border-border rounded-lg shadow-lv2 overflow-y-auto",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-muted-foreground px-1 truncate",children:e.name}),S&&(0,n.jsx)("button",{type:"button",onClick:v,className:"p-0.5 text-muted-foreground hover:text-foreground rounded flex-shrink-0",title:M("chat.addQuickInstruction"),children:(0,n.jsx)(nt.A,{className:"w-3.5 h-3.5"})})]}),S&&a&&(0,n.jsx)(n9,{initialValue:"",placeholder:M("chat.quickInstructionPlaceholder"),onCommit:e=>j(e),onCancel:w}),0===e.items.length&&!a&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground px-1 py-1",children:M("chat.noQuickInstructions")}),e.items.map(t=>s===t.id?(0,n.jsx)(n9,{initialValue:t.text,placeholder:M("chat.quickInstructionPlaceholder"),groupChoices:r,initialGroupId:e.id,onCommit:(e,r)=>f(t.id,e,r),onCancel:g},`edit-${t.id}`):(0,n.jsx)(st,{item:t,isDragging:i===t.id,isDragOver:d===t.id&&i!==t.id,onSelect:m,onInsert:x,onEdit:h,onDelete:b,onDragStart:k,onDragOver:y,onDrop:N,onDragEnd:C,management:S},t.id))]}),document.body)}function ss({label:e,nodes:t,scope:r,openGroupId:a,flyoutPosition:l,onOpenFlyout:i,onCloseFlyout:d,onKeepFlyout:c,onSave:u,onSelect:x,onInsert:h,management:f=!0,onManage:p}){let{t:g}=(0,o.Bd)(),[b,v]=(0,s.useState)(null),[j,w]=(0,s.useState)(!1),[k,y]=(0,s.useState)(null),[N,C]=(0,s.useState)(null),[S,M]=(0,s.useState)(null),L=t.filter(m._9),E=a?L.find(e=>e.id===a)??null:null,P=(0,s.useRef)(t);P.current=t;let $=(0,s.useRef)(a);$.current=a;let R=(0,s.useRef)(null);(0,s.useEffect)(()=>{w(!1)},[a]);let I=(0,s.useCallback)(e=>{y(null),u(r,e)},[u,r]),F=(0,s.useCallback)(e=>{v(null),I([...P.current,{id:n6(),text:e}])},[I]),B=(0,s.useCallback)(e=>{v(null),I([...P.current,{id:n6(),name:e,items:[]}])},[I]),D=(0,s.useCallback)((e,t,r,n)=>{let s=P.current,o={id:e,text:t};if(r===n)return void I(s.map(t=>(0,m._9)(t)?t.id===n?{...t,items:t.items.map(t=>t.id===e?o:t)}:t:null===n&&t.id===e?o:t));let a=null===r?s.filter(t=>(0,m._9)(t)||t.id!==e):s.map(t=>(0,m._9)(t)&&t.id===r?{...t,items:t.items.filter(t=>t.id!==e)}:t);I(null===n?[...a,o]:a.map(e=>(0,m._9)(e)&&e.id===n?{...e,items:[...e.items,o]}:e))},[I]),A=(0,s.useCallback)((e,t)=>{I(P.current.map(r=>(0,m._9)(r)&&r.id===e?{...r,name:t}:r))},[I]),H=(0,s.useCallback)(async e=>{let t=P.current.find(t=>t.id===e);if(t&&(0,m._9)(t)&&t.items.length>0){if(!await (0,T.lJ)(g("chat.deleteInstructionGroupConfirm",{name:t.name,count:t.items.length}),{danger:!0,confirmText:g("common.delete")}))return;d()}y(null),I(P.current.filter(t=>t.id!==e))},[I,g,d]),z=(0,s.useCallback)(e=>{let t=$.current;t&&I(P.current.map(r=>(0,m._9)(r)&&r.id===t?e(r):r))},[I]),W=(0,s.useCallback)(e=>{w(!1),z(t=>({...t,items:[...t.items,{id:n6(),text:e}]}))},[z]),O=(0,s.useCallback)(e=>{y(null),z(t=>({...t,items:t.items.filter(t=>t.id!==e)}))},[z]),_=(0,s.useCallback)((e,t,r)=>{D(e,t,$.current,r)},[D]),q=(0,s.useCallback)(e=>{R.current=e,C(e)},[]),V=(0,s.useCallback)(()=>{q(null),M(null)},[q]),U=(0,s.useCallback)(e=>{q(e),d()},[q,d]),K=(0,s.useCallback)((e,t)=>{e.preventDefault(),M(t)},[]),Q=(e,t,r)=>{let n=e.findIndex(e=>e.id===t),s=e.findIndex(e=>e.id===r);if(n<0||s<0)return e;let o=[...e],[a]=o.splice(n,1);return o.splice(s,0,a),o},G=(0,s.useCallback)(e=>{let t=R.current;V(),t&&t!==e&&I(Q(P.current,t,e))},[I,V]),J=(0,s.useCallback)(e=>{let t=R.current;V(),t&&t!==e&&z(r=>({...r,items:Q(r.items,t,e)}))},[z,V]),Y=e=>{let t=P.current.find(t=>(0,m._9)(t)&&t.id===e);return t&&(0,m._9)(t)?t.items.length:0},Z=(0,s.useCallback)((e,t)=>{i(r,e,t,Y(e),!1)},[i,r]),X=(0,s.useCallback)((e,t)=>{$.current===e?d():i(r,e,t,Y(e),!0)},[i,d,r]);return(0,n.jsxs)("div",{className:"p-2",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-muted-foreground px-1",children:e}),f?(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{type:"button",onClick:()=>{y(null),v("group")},className:"p-0.5 text-muted-foreground hover:text-foreground rounded",title:g("chat.addInstructionGroup"),children:(0,n.jsx)(n0.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("button",{type:"button",onClick:()=>{y(null),v("instruction")},className:"p-0.5 text-muted-foreground hover:text-foreground rounded",title:g("chat.addQuickInstruction"),children:(0,n.jsx)(nt.A,{className:"w-3.5 h-3.5"})})]}):p?(0,n.jsx)("button",{type:"button",onClick:p,className:"p-1 text-muted-foreground hover:text-brand rounded hover:bg-hover transition-colors",title:g("common.edit"),"aria-label":g("common.edit"),children:(0,n.jsx)(nZ.A,{className:"w-3.5 h-3.5"})}):null]}),"instruction"===b&&(0,n.jsx)(n9,{initialValue:"",placeholder:g("chat.quickInstructionPlaceholder"),onCommit:e=>F(e),onCancel:()=>v(null)}),"group"===b&&(0,n.jsx)(n9,{initialValue:"",placeholder:g("chat.instructionGroupNamePlaceholder"),onCommit:e=>B(e),onCancel:()=>v(null)}),0===t.length&&!b&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground px-1 py-1",children:g("chat.noQuickInstructions")}),t.map(e=>k===e.id?(0,m._9)(e)?(0,n.jsx)(n9,{initialValue:e.name,placeholder:g("chat.instructionGroupNamePlaceholder"),onCommit:t=>A(e.id,t),onCancel:()=>y(null)},`edit-${e.id}`):(0,n.jsx)(n9,{initialValue:e.text,placeholder:g("chat.quickInstructionPlaceholder"),groupChoices:L,initialGroupId:null,onCommit:(t,r)=>D(e.id,t,null,r),onCancel:()=>y(null)},`edit-${e.id}`):(0,m._9)(e)?(0,n.jsx)(sr,{group:e,isOpen:a===e.id,isDragging:N===e.id,isDragOver:S===e.id&&N!==e.id,isDragActive:null!==N,onHoverOpen:Z,onHoverClose:d,onToggle:X,onRename:y,onDelete:H,onDragStart:U,onDragOver:K,onDrop:G,onDragEnd:V,management:f},e.id):(0,n.jsx)(st,{item:e,isDragging:N===e.id,isDragOver:S===e.id&&N!==e.id,onSelect:x,onInsert:h,onEdit:y,onDelete:H,onDragStart:U,onDragOver:K,onDrop:G,onDragEnd:V,management:f},e.id)),E&&l&&(0,n.jsx)(sn,{group:E,position:l,groupChoices:L,editId:k,isAdding:j,isDragActive:null!==N,dragId:N,dragOverId:S,onMouseEnter:c,onMouseLeave:d,onSelect:x,onInsert:h,onStartEdit:y,onCommitEdit:_,onCancelEdit:()=>y(null),onDelete:O,onStartAdd:()=>{y(null),w(!0)},onCommitAdd:W,onCancelAdd:()=>w(!1),onDragStart:q,onDragOver:K,onDrop:J,onDragEnd:V,management:f})]})}function so({cwd:e,anchorRef:t,onClose:r,onSelect:a,onInsert:l}){let{t:i}=(0,o.Bd)(),[d,c]=(0,s.useState)([]),[x,h]=(0,s.useState)([]),[f,p]=(0,s.useState)(null),[g,b]=(0,s.useState)(null),v=(0,s.useRef)(null),j=(0,s.useRef)(null),w=(0,s.useCallback)(()=>{v.current&&(clearTimeout(v.current),v.current=null),j.current&&(clearTimeout(j.current),j.current=null)},[]);(0,s.useEffect)(()=>w,[w]),(0,s.useEffect)(()=>{let t=!1;return(async()=>{let[r,n]=await Promise.all([u.t4.runPromiseExit((0,m.ZQ)()),e?u.t4.runPromiseExit((0,m.$x)(e)):null]);!t&&("Success"===r._tag?c(r.value.instructions??[]):console.error("Failed to load global instructions:",r.cause),n&&"Success"===n._tag?h(n.value.instructions??[]):n&&console.error("Failed to load project instructions:",n.cause))})(),()=>{t=!0}},[e]),(0,s.useEffect)(()=>{let e=e=>{let n;if((n=e.target)instanceof Element&&null!==n.closest(`[${n3}]`))return;let s=t.current;s&&!s.contains(e.target)&&r()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[t,r]),(0,s.useEffect)(()=>{if(!f)return;let e=()=>{w(),p(null)};return window.addEventListener("resize",e),window.addEventListener("scroll",e,!0),()=>{window.removeEventListener("resize",e),window.removeEventListener("scroll",e,!0)}},[f,w]);let k=(0,s.useCallback)((e,t,r,n,s)=>{w();let o=()=>{var s;let o,a,l,i,d,c,u;return p({scope:e,groupId:t,position:(a=(s={width:window.innerWidth,height:window.innerHeight}).width-r.right-4-8,l=r.left-4-8,i=288,a>=288?o=r.right+4:l>=288?o=r.left-4-288:a>=l?(i=Math.max(180,a),o=r.right+4):(i=Math.max(180,l),o=r.left-4-i),o=Math.min(Math.max(8,o),Math.max(8,s.width-i-8)),c=Math.min(d=Math.max(90,.6*s.height),30*n+40),(u=r.top-4)+c>s.height-8&&(u=s.height-8-c),{left:o,top:u=Math.max(8,u),width:i,maxHeight:d})})};s?o():v.current=setTimeout(o,150)},[w]),y=(0,s.useCallback)(()=>{w(),j.current=setTimeout(()=>p(null),300)},[w]),N=(0,s.useCallback)(()=>w(),[w]),C=(0,s.useCallback)(async(t,r)=>{let n="global"===t?c:h;n(r);let s=await u.t4.runPromiseExit((0,m.hZ)("global"===t?{scope:"global",instructions:r}:{cwd:e,instructions:r}));return"Failure"===s._tag?(console.error(`Failed to save ${t} instructions:`,s.cause),!1):(s.value?.instructions&&n(s.value.instructions),!0)},[e]),S=(0,s.useCallback)(e=>{r(),a(e)},[r,a]),M=(0,s.useCallback)(e=>{r(),l(e)},[r,l]),L=(0,s.useCallback)(async e=>!!g&&C(g,e),[g,C]);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"absolute bottom-full left-0 mb-2 w-80 max-w-[calc(100vw-1.5rem)] bg-popover border border-border rounded-lg shadow-lv2 z-50 max-h-[70vh] overflow-y-auto",children:[(0,n.jsx)(ss,{label:i("chat.globalInstructions"),nodes:d,scope:"global",openGroupId:f?.scope==="global"?f.groupId:null,flyoutPosition:f?.scope==="global"?f.position:null,onOpenFlyout:k,onCloseFlyout:y,onKeepFlyout:N,onSave:C,onSelect:S,onInsert:M,management:!1,onManage:()=>{w(),p(null),b("global")}}),e&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsx)(ss,{label:i("chat.projectInstructions"),nodes:x,scope:"project",openGroupId:f?.scope==="project"?f.groupId:null,flyoutPosition:f?.scope==="project"?f.position:null,onOpenFlyout:k,onCloseFlyout:y,onKeepFlyout:N,onSave:C,onSelect:S,onInsert:M,management:!1,onManage:()=>{w(),p(null),b("project")}})]})]}),g&&(0,n.jsx)(n4,{title:i("global"===g?"chat.editGlobalInstructions":"chat.editProjectInstructions"),nodes:"global"===g?d:x,onSave:L,onClose:()=>b(null)})]})}var sa=r(96625);let sl=(0,s.memo)(function({onSend:e,disabled:t,running:r,cwd:a,engine:l,onShowGitStatus:i,onShowComments:d,hasComments:c,onOpenNote:u,isFavorite:m,onToggleFavorite:x,onCreateScheduledTask:h,draft:f,setDraft:p,draftImages:g,setDraftImages:b,suggestion:v}){let{t:j}=(0,o.Bd)(),w=(0,s.useState)(""),k=(0,s.useState)([]),[y,N]=void 0!==f&&p?[f,p]:w,[C,S]=void 0!==g&&b?[g,b]:k,[M,L]=(0,s.useState)(!1),[E,P]=(0,s.useState)(!1),$=(0,s.useRef)(null),T=(0,s.useRef)(null),R=(0,s.useCallback)(()=>{let e=$.current;if(!e)return;e.style.height="auto";let t=Math.max(38,Math.min(e.scrollHeight,200));e.style.height=`${t}px`},[]);(0,s.useLayoutEffect)(()=>{R()},[y,R]);let I=(0,s.useMemo)(()=>l&&"claude"!==l?[]:[{name:"/plan",description:"Enable plan mode (read-only). /plan <task> to plan a task; /plan off to disable.",source:"builtin",argumentHint:"[task|off]"}],[l]),F=(0,sa.n)({value:y,onChange:N,textareaRef:$,extraCommands:I}),B=(0,s.useCallback)(()=>{let r=y.trim();(r||C.length>0)&&!t&&(e(r,C.length>0?C:void 0),N(""),S([]),$.current&&($.current.style.height="auto"))},[y,C,t,e]),D=(0,s.useCallback)(r=>{t||e(r)},[t,e]),A=(0,s.useCallback)(e=>{N(t=>{let r=t.replace(/\s+$/,"");return r?`${r}
|
|
33
|
+
${e}`:e}),requestAnimationFrame(()=>{let e=$.current;e&&(e.focus(),e.setSelectionRange(e.value.length,e.value.length))})},[]),H=(0,s.useCallback)(e=>{if(!e.nativeEvent.isComposing&&!F.handleKeyDown(e)){if("Tab"===e.key&&!e.shiftKey&&v&&!y){e.preventDefault(),N(v);return}"Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),B())}},[F,B,v,y,N]),z=(0,s.useCallback)(e=>{let t=e.clipboardData?.items;if(!t)return;let r=["image/png","image/jpeg","image/webp","image/gif"];for(let n of Array.from(t)){let t=r.find(e=>n.type===e);if(t){e.preventDefault();let r=n.getAsFile();if(!r)continue;if(r.size>5242880){alert(j("chat.imageSizeLimit",{size:(r.size/1024/1024).toFixed(2)}));continue}let s=new FileReader;s.onload=e=>{let r=e.target?.result;if(!r)return;let n=r.replace(/^data:image\/\w+;base64,/,""),s={id:`img-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,data:n,preview:r,media_type:t};S(e=>[...e,s])},s.readAsDataURL(r)}}},[j]),W=(0,s.useCallback)(e=>{S(t=>t.filter(t=>t.id!==e))},[]);return(0,n.jsxs)("div",{className:"border-t border-border bg-card relative",children:[(0,n.jsx)(nU,{images:C,onRemove:W,disabled:t}),(0,n.jsx)(sa.V,{ac:F,className:"absolute bottom-full left-0 right-0 mx-4 mb-2 max-h-64"}),(0,n.jsxs)("div",{className:"flex gap-2 items-end p-4",children:[i&&(0,n.jsx)("button",{onClick:i,className:"p-2 text-brand hover:text-teal-10 hover:bg-brand/10 active:bg-brand/20 active:scale-95 rounded-lg transition-all",title:j("chat.viewGitChanges"),children:(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"6",cy:"6",r:"2",strokeWidth:2}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"2",strokeWidth:2}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"2",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 8v10M18 8v4c0 2-2 4-6 4"})]})}),d&&(0,n.jsx)("button",{onClick:d,className:`p-2 rounded-lg transition-all active:scale-95 ${c?"text-amber-11 hover:text-amber-10 hover:bg-amber-9/10 active:bg-amber-9/20":"text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted"}`,title:j("chat.viewAllComments"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})})}),u&&(0,n.jsx)("button",{onClick:u,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95 rounded-lg transition-all",title:j("chat.projectNotes"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}),x&&(0,n.jsx)("button",{onClick:x,className:`p-2 rounded-lg transition-all ${m?"text-amber-9 hover:text-amber-10 hover:bg-amber-9/10 active:bg-amber-9/20 active:scale-95":"text-muted-foreground hover:text-amber-9 hover:bg-amber-9/10 active:bg-amber-9/20 active:scale-95"}`,title:j(m?"sessions.removeFavorite":"sessions.addFavorite"),"aria-label":j(m?"sessions.removeFavorite":"sessions.addFavorite"),"aria-pressed":m,children:(0,n.jsx)(nO.A,{className:"w-5 h-5",fill:m?"currentColor":"none"})}),h&&(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("button",{onClick:()=>L(!M),className:`p-2 rounded-lg transition-all ${M?"text-brand bg-brand/10":"text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95"}`,title:j("chat.scheduledTasks"),children:(0,n.jsx)(n_.A,{className:"w-5 h-5"})}),M&&(0,n.jsx)(nK.E,{onClose:()=>L(!1),onCreate:h})]}),(0,n.jsxs)("div",{className:"relative",ref:T,children:[(0,n.jsx)("button",{onClick:()=>P(!E),className:`p-2 rounded-lg transition-all ${E?"text-brand bg-brand/10":"text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95"}`,title:j("chat.quickInstructions"),children:(0,n.jsx)(nq.A,{className:"w-5 h-5"})}),E&&(0,n.jsx)(so,{cwd:a,anchorRef:T,onClose:()=>P(!1),onSelect:D,onInsert:A})]}),(0,n.jsx)("textarea",{ref:$,value:y,onChange:e=>{N(e.target.value),F.trackCaret(e.target)},onSelect:e=>F.trackCaret(e.currentTarget),onKeyDown:H,onPaste:z,placeholder:t?j("chat.placeholderDisabled"):r?j("chat.placeholderRunning"):v||j("chat.placeholder"),rows:1,className:"flex-1 resize-none px-4 py-2 border border-border rounded-lg focus:outline-none focus:ring-2 focus:ring-ring bg-card text-foreground"})]})]})});var si=r(57125);function sd(e){return"env"===e?"from env var":"default"===e?"default":null}function sc({currentModel:e,onModelChange:t}){let[r,o]=(0,s.useState)(!1),[a,l]=(0,s.useState)([]),[i,d]=(0,s.useState)(!1),[c,x]=(0,s.useState)(null),[h,f]=(0,s.useState)(!1),[p,g]=(0,s.useState)(!1),[v,j]=(0,s.useState)(!1),[w,k]=(0,s.useState)(null),[y,N]=(0,s.useState)(""),[C,S]=(0,s.useState)("default"),[M,L]=(0,s.useState)(!1),[E,P]=(0,s.useState)(""),[$,T]=(0,s.useState)("default"),[R,I]=(0,s.useState)(""),[F,B]=(0,s.useState)(!1),D=(0,s.useRef)(null),A=(0,s.useRef)(null),H=(0,s.useRef)(null),[z,W]=(0,s.useState)({top:0,left:0}),O=(0,b.F2)();(0,s.useEffect)(()=>{if(!r)return;let e=e=>{A.current&&!A.current.contains(e.target)&&D.current&&!D.current.contains(e.target)&&o(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[r]);let _=(0,s.useCallback)(async()=>{d(!0),x(null);let e=await u.t4.runPromiseExit((0,m.qD)(()=>f(!0)));if(f(!1),"Failure"===e._tag)x("Connection error");else{let t=e.value;switch(t._tag){case"ok":l(t.models);break;case"not-installed":case"error":x(t.message);break;case"not-running":x("Ollama is not running")}}d(!1)},[]),q=(0,s.useCallback)(e=>{N(e.baseUrl),S(e.baseUrlSource),L(e.hasKey),P(e.maskedKey),T(e.keySource),I(""),B(!1)},[]),V=(0,s.useCallback)(async()=>{g(!0),k(null);let e=await u.t4.runPromiseExit((0,m.F4)());"Failure"===e._tag?k("Failed to load config"):q(e.value),g(!1)},[q]),U=async()=>{j(!0),k(null);let e=await u.t4.runPromiseExit((0,m.yS)({baseUrl:y}));"Failure"===e._tag?k("Save failed"):(q(e.value),await _()),j(!1)},K=async()=>{let e=R.trim();if(!e)return;j(!0),k(null);let t=await u.t4.runPromiseExit((0,m.yS)({apiKey:e}));"Failure"===t._tag?k("Save failed"):q(t.value),j(!1)},Q=async()=>{j(!0),k(null);let e=await u.t4.runPromiseExit((0,m.yS)({apiKey:""}));"Failure"===e._tag?k("Clear failed"):q(e.value),j(!1)},G=e?e.replace(/:latest$/,""):"Select model",J=sd(C),Y=sd($),Z=r?(0,n.jsx)(b.ZL,{children:(0,n.jsxs)("div",{ref:A,className:`${si.ys} min-w-[300px]`,style:{top:z.top,left:z.left},children:[(0,n.jsxs)("div",{className:"px-3 py-1.5",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1.5",children:[(0,n.jsx)("span",{className:"text-[11px] font-medium text-muted-foreground",children:"Server URL"}),J&&!p&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground/70",children:J})]}),p?(0,n.jsxs)("div",{className:"flex items-center gap-2 py-1 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:"w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),"Loading..."]}):(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{type:"text",value:y,onChange:e=>N(e.target.value),onKeyDown:e=>{"Enter"===e.key&&U()},placeholder:"http://127.0.0.1:11434",spellCheck:!1,className:`flex-1 min-w-0 text-xs px-2 py-1 rounded bg-secondary text-foreground border border-border focus:outline-none font-mono ${si.Fx}`}),(0,n.jsx)("button",{onClick:U,disabled:v,className:`text-[11px] px-2 py-1 rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${si.$T}`,children:v?"...":"Save"})]})]}),(0,n.jsxs)("div",{className:"px-3 py-1.5",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1.5",children:[(0,n.jsx)("span",{className:"text-[11px] font-medium text-muted-foreground",children:"API Key"}),Y&&M&&!p&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground/70",children:Y})]}),p?null:M&&!F?(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("code",{className:"flex-1 min-w-0 truncate text-xs px-2 py-1 rounded bg-secondary text-foreground font-mono",children:E}),(0,n.jsx)("button",{onClick:()=>{B(!0),I(""),setTimeout(()=>H.current?.focus(),0)},className:"text-[11px] px-2 py-1 rounded bg-secondary hover:bg-hover text-foreground transition-colors",disabled:v,children:"Edit"}),(0,n.jsx)("button",{onClick:Q,className:"text-[11px] px-2 py-1 rounded text-red-11 hover:bg-red-500/10 transition-colors",disabled:v,children:"Clear"})]}):(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{ref:H,type:"password",value:R,onChange:e=>I(e.target.value),onKeyDown:e=>{"Enter"===e.key&&K()},placeholder:"optional — for authenticated servers",spellCheck:!1,className:`flex-1 min-w-0 text-xs px-2 py-1 rounded bg-secondary text-foreground border border-border focus:outline-none font-mono ${si.Fx}`}),(0,n.jsx)("button",{onClick:K,disabled:v||!R.trim(),className:`text-[11px] px-2 py-1 rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${si.$T}`,children:v?"...":"Save"}),M&&(0,n.jsx)("button",{onClick:()=>{B(!1),I("")},className:"text-[11px] px-2 py-1 rounded text-muted-foreground hover:text-foreground transition-colors",children:"Cancel"})]}),w&&(0,n.jsx)("div",{className:"mt-1 text-[11px] text-red-11",children:w})]}),(0,n.jsx)("div",{className:"my-1 border-t border-border"}),(0,n.jsx)("div",{className:"px-3 pt-1 pb-0.5",children:(0,n.jsx)("span",{className:"text-[11px] font-medium text-muted-foreground",children:"Model"})}),(0,n.jsx)("div",{className:"max-h-[240px] overflow-y-auto",children:i||h?(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:"w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),h?"Starting Ollama...":"Loading models..."]}):c?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-red-11",children:c}):0===a.length?(0,n.jsxs)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:["No models found. Run ",(0,n.jsx)("code",{className:"bg-secondary px-1 rounded",children:"ollama pull <model>"})]}):a.map(r=>{var s;let a=r.name===e;return(0,n.jsxs)("button",{onClick:()=>{t(r.name),o(!1)},className:`w-full flex items-center gap-2 px-3 py-1.5 text-xs transition-colors ${a?si.yI:"text-foreground hover:bg-hover"}`,children:[(0,n.jsx)(si.hG,{selected:a}),(0,n.jsx)("span",{className:"truncate",children:r.name.replace(/:latest$/,"")}),(0,n.jsx)("span",{className:"ml-auto pl-2 text-muted-foreground flex-shrink-0",children:r.parameter_size||((s=r.size)<1e9?`${(s/1e6).toFixed(0)}M`:`${(s/1e9).toFixed(1)}G`)})]},r.name)})})]})}):null;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(si.XY,{buttonRef:D,label:G,title:"Configure Ollama",onClick:()=>{if(!r){if(D.current){let e=D.current.getBoundingClientRect(),t=O?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0;W({top:e.bottom+4-n,left:e.left-r})}V(),_()}o(e=>!e)},icon:(0,n.jsx)(si.eV,{engine:"ollama"}),testId:"ollama-config-picker"}),Z]})}let su={deepseek:{label:"DeepSeek",apiKeysUrl:"https://platform.deepseek.com/api_keys",modelsEndpoint:"/v1/models"},kimi:{label:"Kimi",apiKeysUrl:"https://www.kimi.com/code/console",modelsEndpoint:"/coding/v1/models"},glm:{label:"GLM",apiKeysUrl:"https://bigmodel.cn/apikey/platform",modelsEndpoint:"/coding/paas/v4/models",regions:[{id:"cn",label:"中国大陆",hint:"open.bigmodel.cn"},{id:"global",label:"International",hint:"api.z.ai"}]}};function sm({engine:e,currentModel:t,onModelChange:r,onHasKeyChange:o}){let a=su[e],[l,i]=(0,s.useState)(!1),[d,c]=(0,s.useState)(!1),[x,h]=(0,s.useState)(""),[f,p]=(0,s.useState)(""),[g,v]=(0,s.useState)(!1),[j,w]=(0,s.useState)(!1),[k,y]=(0,s.useState)(!1),[N,C]=(0,s.useState)(null),[S,M]=(0,s.useState)(!1),[L,E]=(0,s.useState)([]),[P,$]=(0,s.useState)(null),[T,R]=(0,s.useState)(null),I=(0,s.useRef)(null),F=(0,s.useRef)(null),B=(0,s.useRef)(null),D=(0,s.useRef)(null);(0,s.useEffect)(()=>()=>{D.current&&clearTimeout(D.current)},[]);let A=(0,s.useRef)(t),H=(0,s.useRef)(r),z=(0,s.useRef)(o);(0,s.useEffect)(()=>{A.current=t,H.current=r,z.current=o}),(0,s.useEffect)(()=>{z.current?.(d)},[d]);let[W,O]=(0,s.useState)({top:0,left:0}),_=(0,b.F2)();(0,s.useEffect)(()=>{let t=!1;return(async()=>{let[r,n]=await Promise.all([u.t4.runPromiseExit((0,m.Hw)(e)),u.t4.runPromiseExit((0,m.td)())]);if(t||"Failure"===r._tag)return;c(r.value.hasKey),h(r.value.maskedKey);let s="Success"===n._tag?n.value?.engines?.[e]:void 0,o=s?.builtinModel;!A.current&&o&&H.current(o)})(),()=>{t=!0}},[e]),(0,s.useEffect)(()=>{if(!l)return;let e=e=>{F.current&&!F.current.contains(e.target)&&I.current&&!I.current.contains(e.target)&&i(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[l]);let q=(0,s.useCallback)(async()=>{w(!0),C(null),$(null);let[n,s]=await Promise.all([u.t4.runPromiseExit((0,m.Hw)(e)),u.t4.runPromiseExit((0,m.td)())]);if("Failure"===n._tag){C("Failed to load settings"),w(!1);return}c(n.value.hasKey),h(n.value.maskedKey),p(""),v(!1);let o="Success"===s._tag?s.value:void 0,l=o?.engines?.[e],i=l?.builtinModel;a.regions&&R(l?.region??("en"===o?.language?"global":"cn"));let d=[];if(n.value.hasKey){let t=await u.t4.runPromiseExit((0,m.Fi)(e));"Success"===t._tag?d=t.value.models:$("Failed to load models — check the API key")}E(d);let x=d.map(e=>e.id),f=i&&x.includes(i)?i:x[0];!f||t&&x.includes(t)||r(f),w(!1)},[e,t,r,a.regions]),V=(0,s.useCallback)(async t=>{let r=await u.t4.runPromiseExit((0,m.td)()),n=("Success"===r._tag?r.value:{}).engines||{},s={...n,[e]:{...n[e]||{},builtinModel:t}};if("Failure"===(await u.t4.runPromiseExit((0,m.em)({engines:s})))._tag)throw Error("Failed to save settings")},[e]),U=(0,s.useCallback)(async t=>{R(t);let r=await u.t4.runPromiseExit((0,m.td)()),n=("Success"===r._tag?r.value:{}).engines||{};"Failure"===(await u.t4.runPromiseExit((0,m.em)({engines:{...n,[e]:{...n[e]||{},region:t}}})))._tag?C("Failed to save region"):q()},[e,q]),K=async()=>{let t=f.trim();if(!t)return;y(!0),C(null);let r=await u.t4.runPromiseExit((0,m.dQ)(e,t));"Failure"===r._tag?C("Save failed"):(c(r.value.hasKey),h(r.value.maskedKey),p(""),v(!1),q()),y(!1)},Q=async()=>{y(!0),C(null);let t=await u.t4.runPromiseExit((0,m.dQ)(e,""));"Failure"===t._tag?C("Clear failed"):(c(t.value.hasKey),h(t.value.maskedKey),p(""),v(!1),E([])),y(!1)},G=async()=>{let t=await u.t4.runPromiseExit((0,m.Ny)(e));if("Failure"===t._tag||!t.value.apiKey)return void C("Copy failed");try{await navigator.clipboard.writeText(t.value.apiKey)}catch{C("Clipboard unavailable");return}C(null),M(!0),D.current&&clearTimeout(D.current),D.current=setTimeout(()=>M(!1),1500)},J=async e=>{r(e);try{await V(e)}catch{}},Y=d?t||"Select model":"Set API key",Z=d?void 0:si.Aw,X=t||"",ee=l?(0,n.jsx)(b.ZL,{children:(0,n.jsx)("div",{ref:F,className:`${si.ys} min-w-[280px]`,style:{top:W.top,left:W.left},children:j?(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:"w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),"Loading..."]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-3 py-1.5",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1 mb-1.5",children:[(0,n.jsx)("span",{className:"text-[11px] font-medium text-muted-foreground",children:"API Key"}),(0,n.jsx)("a",{href:a.apiKeysUrl,target:"_blank",rel:"noopener","data-testid":`${e}-api-keys-link`,title:`Open ${a.label} API keys page`,"aria-label":`Open ${a.label} API keys page`,className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})})]}),d&&!g?(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("code",{className:"flex-1 min-w-0 truncate text-xs px-2 py-1 rounded bg-secondary text-foreground font-mono",children:x}),(0,n.jsx)("button",{onClick:G,"data-testid":`${e}-copy-api-key`,title:S?"Copied":"Copy API key","aria-label":"Copy API key",className:`p-1 rounded transition-colors ${S?"text-green-11":"text-muted-foreground hover:text-foreground hover:bg-hover"}`,disabled:k,children:S?(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}):(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:()=>{v(!0),p(""),setTimeout(()=>B.current?.focus(),0)},className:"text-[11px] px-2 py-1 rounded bg-secondary hover:bg-hover text-foreground transition-colors",disabled:k,children:"Edit"}),(0,n.jsx)("button",{onClick:Q,className:"text-[11px] px-2 py-1 rounded text-red-11 hover:bg-red-500/10 transition-colors",disabled:k,children:"Clear"})]}):(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{ref:B,type:"password",value:f,onChange:e=>p(e.target.value),onKeyDown:e=>{"Enter"===e.key&&K()},placeholder:"sk-...",className:`flex-1 min-w-0 text-xs px-2 py-1 rounded bg-secondary text-foreground border border-border focus:outline-none font-mono ${si.Fx}`,autoFocus:!0}),(0,n.jsx)("button",{onClick:K,disabled:k||!f.trim(),className:`text-[11px] px-2 py-1 rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${si.$T}`,children:k?"Saving...":"Save"}),d&&(0,n.jsx)("button",{onClick:()=>{v(!1),p("")},className:"text-[11px] px-2 py-1 rounded text-muted-foreground hover:text-foreground transition-colors",children:"Cancel"})]}),N&&(0,n.jsx)("div",{className:"mt-1 text-[11px] text-red-11",children:N})]}),(0,n.jsx)("div",{className:"my-1 border-t border-border"}),a.regions&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-3 py-1.5",children:[(0,n.jsx)("div",{className:"text-[11px] font-medium text-muted-foreground mb-1.5",children:"Region"}),(0,n.jsx)("div",{className:"inline-flex rounded-md border border-border overflow-hidden text-xs",role:"group","data-testid":`${e}-region-toggle`,children:a.regions.map(t=>(0,n.jsx)("button",{type:"button","data-testid":`${e}-region-${t.id}`,onClick:()=>U(t.id),title:t.hint,className:`px-2 py-0.5 ${T===t.id?"bg-brand text-white":"bg-transparent text-muted-foreground hover:bg-hover"}`,children:t.label},t.id))})]}),(0,n.jsx)("div",{className:"my-1 border-t border-border"})]}),(0,n.jsxs)("div",{className:"px-3 py-1.5",children:[(0,n.jsx)("div",{className:"text-[11px] font-medium text-muted-foreground mb-1.5",children:"Model"}),P&&(0,n.jsx)("div",{className:"mb-1 text-[11px] text-red-11",children:P}),!P&&0===L.length&&(0,n.jsx)("div",{className:"mb-1 text-[11px] text-muted-foreground",children:d?`No models returned by ${a.modelsEndpoint}`:"Save an API key to list models"}),(0,n.jsx)("div",{className:"flex flex-col gap-0.5",children:L.map(e=>{var t;let r=X===e.id,s=(t=e.contextTokens)&&!(t<=0)?t>=1048576?`${Math.round(t/1048576)}M`:`${Math.round(t/1024)}K`:null;return(0,n.jsxs)("button",{onClick:()=>J(e.id),className:`flex items-center gap-2 px-2 py-1 text-xs rounded transition-colors ${r?si.yI:"text-foreground hover:bg-hover"}`,children:[(0,n.jsx)(si.hG,{selected:r}),(0,n.jsx)("span",{className:"truncate",children:e.id}),e.label&&e.label!==e.id&&(0,n.jsx)("span",{className:"truncate text-[10px] text-muted-foreground",children:e.label}),s&&(0,n.jsx)("span",{className:"ml-auto pl-2 text-[10px] text-muted-foreground flex-shrink-0",children:s})]},e.id)})})]})]})})}):null;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(si.XY,{buttonRef:I,label:Y,labelClassName:Z,title:`Configure ${a.label}`,onClick:()=>{if(!l){if(I.current){let e=I.current.getBoundingClientRect(),t=_?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0;O({top:e.bottom+4-n,left:e.left-r})}q()}i(e=>!e)},icon:(0,n.jsx)(si.eV,{engine:e}),testId:`${e}-config-picker`}),ee]})}var sx=r(53317);let sh="claude-opus-5-5",sf="gpt-6.1-sol",sp=[{id:"low",label:"Low"},{id:"medium",label:"Medium"},{id:"high",label:"High"},{id:"xhigh",label:"Extra High"},{id:"max",label:"Max"},{id:"ultracode",label:"Ultracode"},{id:"ultrathink",label:"Ultrathink"}],sg=[{id:"claude-sonnet-5-5",label:"Claude Sonnet 5.5",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"medium"},{id:"claude-sonnet-5",label:"Claude Sonnet 5",effort:["low","medium","high","xhigh","max","ultrathink"],defaultEffort:"high"},{id:"claude-opus-5-5",label:"Claude Opus 5.5",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"medium",fast:!0},{id:"claude-opus-5",label:"Claude Opus 5",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"high",fast:!0},{id:"claude-fable-5-1",label:"Claude Fable 5.1",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"high"},{id:"claude-haiku-5-5",label:"Claude Haiku 5.5",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"medium"},{id:"claude-haiku-4-5",label:"Claude Haiku 4.5",thinking:!0}],sb=[{id:"low",label:"Low"},{id:"medium",label:"Medium"},{id:"high",label:"High"},{id:"xhigh",label:"Extra High"},{id:"max",label:"Max"},{id:"ultra",label:"Ultra"}],sv=[{id:"gpt-6-astra",label:"GPT-6-Astra",reasoning:["low","medium","high","xhigh","max","ultra"],defaultReasoning:"low"},{id:"gpt-6.1-sol",label:"GPT-6.1-Sol",reasoning:["low","medium","high","xhigh","max","ultra"],defaultReasoning:"low"},{id:"gpt-6-sol",label:"GPT-6-Sol",reasoning:["low","medium","high","xhigh","max","ultra"],defaultReasoning:"medium"},{id:"gpt-6-luna",label:"GPT-6-Luna",reasoning:["low","medium","high","xhigh","max"],defaultReasoning:"medium"},{id:"gpt-5.6-sol",label:"GPT-5.6-Sol",reasoning:["low","medium","high","xhigh","max","ultra"],defaultReasoning:"low"}];function sj(e){return sv.find(t=>t.id===e)?.defaultReasoning??"low"}function sw(e,t){let r=sv.find(t=>t.id===e)?.reasoning;return t&&(!r||r.includes(t))?t:sj(e)}function sk(e,t){return e.find(e=>e.id===t)?.label??t}function sy(e){return sg.find(t=>t.id===e)?.fast===!0}function sN(e){return sg.find(t=>t.id===e)?.thinking===!0}function sC(e){let t=sg.find(t=>t.id===e);return t?t.defaultEffort:"high"}function sS(e,t){let r=sg.find(t=>t.id===e),n=r?.effort;return t&&(!r||n?.includes(t))?t:sC(e)}function sM({value:e,selected:t,label:r,defaultValue:s,onSelect:o}){return(0,n.jsxs)("button",{type:"button",onClick:()=>o(e),className:`flex w-full items-start gap-2 px-3 py-2 text-left text-xs transition-colors ${t?si.yI:"text-muted-foreground hover:bg-hover hover:text-foreground"}`,children:[(0,n.jsx)("span",{className:"mt-0.5",children:(0,n.jsx)(si.hG,{selected:t})}),(0,n.jsx)("span",{className:"min-w-0 flex-1 truncate",children:r}),(0,n.jsx)("span",{className:"shrink-0",children:s&&(0,n.jsx)("span",{className:"rounded bg-muted px-1.5 text-[10px] font-medium text-muted-foreground",children:"Default"})})]})}function sL({title:e,selected:t,value:r,items:o,onSelect:a,icon:l,testId:i}){let d=(0,s.useRef)(null),c=(0,s.useRef)(null),[u,m]=(0,s.useState)(!1),[x,h]=(0,s.useState)({top:0,left:0}),f=(0,b.F2)(),p=()=>{let e=d.current?.getBoundingClientRect();if(!e)return;let t=f?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0;h({top:e.bottom+4-n,left:e.left-r})};return(0,s.useEffect)(()=>{if(!u)return;let e=e=>{let t=e.target;c.current?.contains(t)||d.current?.contains(t)||m(!1)},t=()=>p();return document.addEventListener("mousedown",e),window.addEventListener("resize",t),window.addEventListener("scroll",t,!0),()=>{document.removeEventListener("mousedown",e),window.removeEventListener("resize",t),window.removeEventListener("scroll",t,!0)}},[u]),(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)(si.XY,{buttonRef:d,label:r,labelMaxWidth:"max-w-[180px]",title:`${e}: ${r}`,onClick:()=>{u||p(),m(e=>!e)},icon:l,testId:i}),u&&(0,n.jsx)(b.ZL,{children:(0,n.jsxs)("div",{ref:c,className:`${si.ys} min-w-[190px]`,style:{top:x.top,left:x.left},children:[(0,n.jsx)("div",{className:"px-3 pb-1 text-[11px] font-medium text-muted-foreground",children:e}),(0,n.jsx)("div",{className:"flex flex-col",children:o.map(e=>(0,n.jsx)(sM,{value:e.id,selected:t===e.id,label:e.label,defaultValue:e.defaultValue,onSelect:e=>{a(e),m(!1)}},e.id))})]})})]})}function sE(e){let t,r,s,o=e.engine??"claude",a=e.claudeModel??sh,l=sC(a),i=(t=sg.find(e=>e.id===a)?.effort)?t.map(e=>sp.find(t=>t.id===e)??{id:e,label:e}):[],d=sS(a,e.claudeEffort),c=e.claudeFastMode??!1,u=e.claudeThinking??!1,m=e.codexModel??sf,x=sj(m),h=(r=sv.find(e=>e.id===m)?.reasoning)?r.map(e=>sb.find(t=>t.id===e)??{id:e,label:e}):sb,f=sw(m,e.codexReasoningEffort);return"claude"!==o?(0,n.jsxs)("div",{className:"flex min-w-0 items-center gap-1","data-agent-model-traits":!0,children:[(0,n.jsx)(sL,{title:"Model",selected:m,value:sv.find(e=>e.id===m)?.label??(0,sx.U)(m),items:sv.map(e=>({id:e.id,label:e.label,defaultValue:e.id===sf})),onSelect:t=>{e.onCodexModelChange?.(t),e.onCodexReasoningEffortChange?.(sj(t))},icon:(0,n.jsx)(si.eV,{engine:"codex"}),testId:"codex-model-picker"}),(0,n.jsx)(sL,{title:"Reasoning",selected:f,value:sk(sb,f),items:h.map(e=>({...e,defaultValue:e.id===x})),onSelect:t=>e.onCodexReasoningEffortChange?.(t),testId:"codex-reasoning-picker"})]}):(0,n.jsxs)("div",{className:"flex min-w-0 items-center gap-1","data-agent-model-traits":!0,children:[(0,n.jsx)(sL,{title:"Model",selected:a,value:(s=sg.find(e=>e.id===a))?s.label:a.startsWith("claude-")?`Claude ${(0,sx.J)(a)}`:a,items:sg.map(e=>({id:e.id,label:e.label,defaultValue:e.id===sh})),onSelect:t=>{e.onClaudeModelChange?.(t);let r=sC(t);r&&e.onClaudeEffortChange?.(r),sy(t)||e.onClaudeFastModeChange?.(!1),sN(t)||e.onClaudeThinkingChange?.(!1)},icon:(0,n.jsx)(si.eV,{engine:"claude"}),testId:"claude-model-picker"}),d&&i.length>0&&(0,n.jsx)(sL,{title:"Reasoning",selected:d,value:sk(sp,d),items:i.map(e=>({...e,defaultValue:e.id===l})),onSelect:t=>e.onClaudeEffortChange?.(t),testId:"claude-reasoning-picker"}),sy(a)&&(0,n.jsx)(sL,{title:"Fast Mode",selected:c?"on":"off",value:c?"Fast On":"Fast Off",items:[{id:"on",label:"On"},{id:"off",label:"Off",defaultValue:!0}],onSelect:t=>e.onClaudeFastModeChange?.("on"===t),testId:"claude-fast-mode-picker"}),sN(a)&&(0,n.jsx)(sL,{title:"Thinking",selected:u?"on":"off",value:u?"Thinking On":"Thinking Off",items:[{id:"on",label:"On"},{id:"off",label:"Off",defaultValue:!0}],onSelect:t=>e.onClaudeThinkingChange?.("on"===t),testId:"claude-thinking-picker"})]})}var sP=r(6489);let s$=/^#\s+(.*)$/;function sT(e,t=[]){let r=new Map(t.map(e=>[e.name,e.id])),n=[];for(let[t,r]of e.split(/\r?\n/).entries()){let e=r.match(s$);if(e){n.push({name:e[1].trim(),line:t+1,body:[]});continue}let s=n[n.length-1];if(!s){if(r.trim())return{ok:!1,line:t+1,reason:"content-before-heading"};continue}s.body.push(r)}let s=new Set,o=[];for(let e of n){let t=e.body.join("\n").trim();if(!e.name||!t)return{ok:!1,line:e.line,reason:"empty-style"};if(s.has(e.name))return{ok:!1,line:e.line,reason:"duplicate-name"};s.add(e.name),o.push({id:r.get(e.name)??"",name:e.name,content:t})}return{ok:!0,styles:o}}function sR({styles:e,onSave:t,onClose:r}){let{t:a}=(0,o.Bd)(),[l,i]=(0,s.useState)(()=>e.map(e=>`# ${e.name}
|
|
34
|
+
${e.content}`).join("\n\n")),[d,c]=(0,s.useState)(!1),[u,m]=(0,s.useState)(!1),x=sT(l,e);(0,H.E)(r);let h=(0,s.useCallback)(async()=>{let n=sT(l,e);if(n.ok&&!d){if(c(!0),m(!1),await t(n.styles))return void r();c(!1),m(!0)}},[r,t,d,e,l]),f=a("chat.editOutputStyles");return(0,n.jsx)(b.ZL,{children:(0,n.jsx)("div",{className:"fixed inset-0 z-[300] flex items-center justify-center bg-scrim p-4",onMouseDown:e=>{e.target===e.currentTarget&&r()},children:(0,n.jsxs)("div",{role:"dialog","aria-modal":"true","aria-label":f,className:"w-full max-w-4xl max-h-[90vh] bg-card border border-border rounded-xl shadow-lv3 flex flex-col",children:[(0,n.jsxs)("header",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:f}),(0,n.jsx)("p",{className:"mt-0.5 text-xs text-muted-foreground",children:a("chat.outputStylesMarkdownHint")})]}),(0,n.jsx)("button",{type:"button",onClick:r,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded","aria-label":a("common.cancel"),children:(0,n.jsx)(ei.A,{className:"w-4 h-4"})})]}),(0,n.jsx)("div",{className:"min-h-0 flex-1 px-4 py-3",children:(0,n.jsx)("textarea",{autoFocus:!0,value:l,onChange:e=>i(e.target.value),placeholder:a("chat.outputStylesMarkdownPlaceholder"),rows:24,spellCheck:!1,"data-testid":"output-styles-editor",className:"w-full h-[60vh] min-h-80 max-h-[70vh] resize-y px-3 py-2 text-sm font-mono leading-6 bg-background border border-border rounded-lg text-foreground focus:outline-none focus:border-brand"})}),(0,n.jsxs)("footer",{className:"flex items-center justify-between gap-3 px-4 py-3 border-t border-border",children:[(0,n.jsx)("span",{className:"text-xs text-destructive",children:x.ok?u?a("chat.saveQuickInstructionsFailed"):"":a(`chat.outputStylesError.${x.reason}`,{line:x.line})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:r,className:"px-3 py-1.5 text-xs text-muted-foreground hover:text-foreground rounded hover:bg-hover",children:a("common.cancel")}),(0,n.jsx)("button",{type:"button",disabled:!x.ok||d,onClick:h,"data-testid":"output-styles-save",className:"px-3 py-1.5 text-xs rounded border border-brand text-brand hover:bg-brand/10 disabled:opacity-40",children:a(d?"chat.savingQuickInstructions":"common.save")})]})]})]})})})}let sI=[],sF=sI,sB=!1,sD=null,sA=new Set,sH=e=>{sF=e,sA.forEach(e=>e())};function sz(e=!1){return sB&&!e?Promise.resolve():sD||(sD=(async()=>{let e=await u.t4.runPromiseExit((0,m.K4)());(sD=null,"Failure"===e._tag)?console.error("Failed to load output styles:",e.cause):(sB=!0,sH(e.value.styles??sI))})())}async function sW(e){let t=await u.t4.runPromiseExit((0,m.DF)(e));return"Failure"===t._tag?(console.error("Failed to save output styles:",t.cause),!1):(sB=!0,sH(t.value.styles??sI),!0)}let sO=e=>(sA.add(e),()=>{sA.delete(e)}),s_=()=>sF;function sq({value:e,onChange:t}){let{t:r}=(0,o.Bd)(),a=((0,s.useEffect)(()=>{sz()},[]),(0,s.useSyncExternalStore)(sO,s_,()=>sI)),l=(0,s.useRef)(null),i=(0,s.useRef)(null),[d,c]=(0,s.useState)(!1),[u,m]=(0,s.useState)(!1),[x,h]=(0,s.useState)({top:0,left:0}),f=(0,b.F2)(),p=a.find(t=>t.id===e),g=r("chat.outputStyleNone"),v=p?.name??g,j=(0,s.useCallback)(()=>{let e=l.current?.getBoundingClientRect();if(!e)return;let t=f?.getBoundingClientRect();h({top:e.bottom+4-(t?.top??0),left:e.left-(t?.left??0)})},[f]);(0,s.useEffect)(()=>{if(!d)return;let e=e=>{let t=e.target;i.current?.contains(t)||l.current?.contains(t)||c(!1)};return document.addEventListener("mousedown",e),window.addEventListener("resize",j),window.addEventListener("scroll",j,!0),()=>{document.removeEventListener("mousedown",e),window.removeEventListener("resize",j),window.removeEventListener("scroll",j,!0)}},[d,j]);let w=e=>{t(e),c(!1)},k=e=>`flex w-full items-start gap-2 px-3 py-2 text-left text-xs transition-colors ${e?si.yI:"text-muted-foreground hover:bg-hover hover:text-foreground"}`;return(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)(si.XY,{buttonRef:l,label:v,labelMaxWidth:"max-w-[140px]",title:`${r("chat.outputStyle")}: ${v}`,onClick:()=>{d||(j(),sz(!0)),c(e=>!e)},icon:(0,n.jsx)(sP.A,{className:`h-3.5 w-3.5 flex-shrink-0 ${p?"text-brand":""}`}),testId:"output-style-picker"}),d&&(0,n.jsx)(b.ZL,{children:(0,n.jsxs)("div",{ref:i,className:`${si.ys} min-w-[200px] max-w-[320px]`,style:{top:x.top,left:x.left},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between gap-2 px-3 pb-1",children:[(0,n.jsx)("span",{className:"text-[11px] font-medium text-muted-foreground",children:r("chat.outputStyle")}),(0,n.jsx)("button",{type:"button",onClick:()=>{c(!1),m(!0)},className:"p-1 text-muted-foreground hover:text-foreground rounded hover:bg-hover",title:r("chat.editOutputStyles"),"data-testid":"output-style-edit",children:(0,n.jsx)(nZ.A,{className:"w-3 h-3"})})]}),(0,n.jsxs)("div",{className:"flex flex-col",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>w(""),className:k(!p),children:[(0,n.jsx)("span",{className:"mt-0.5",children:(0,n.jsx)(si.hG,{selected:!p})}),(0,n.jsx)("span",{className:"min-w-0 flex-1 truncate",children:g})]}),a.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>w(e.id),className:k(p?.id===e.id),title:e.content,children:[(0,n.jsx)("span",{className:"mt-0.5",children:(0,n.jsx)(si.hG,{selected:p?.id===e.id})}),(0,n.jsx)("span",{className:"min-w-0 flex-1 truncate",children:e.name})]},e.id)),0===a.length&&(0,n.jsx)("div",{className:"px-3 py-2 text-[11px] text-muted-foreground",children:r("chat.noOutputStyles")})]})]})}),u&&(0,n.jsx)(sR,{styles:a,onSave:sW,onClose:()=>m(!1)})]})}let sV={CNY:"\xa5",USD:"$"};function sU({hasKey:e}){let{t}=(0,o.Bd)(),[r,a]=(0,s.useState)(!1),[l,i]=(0,s.useState)(null),[d,c]=(0,s.useState)(null),x=(0,s.useCallback)(async()=>{a(!0),c(null);let e=await u.t4.runPromiseExit((0,m.he)());"Failure"===e._tag?(i(null),c(t("chat.balanceFailed",{defaultValue:"Query failed — check the API key"}))):i(e.value),a(!1)},[t]),h=l?l.balances.map(e=>`${sV[e.currency]??(e.currency?`${e.currency} `:"")}${e.totalBalance}`).join(" / "):"",f=!!(l&&!l.isAvailable);return(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-2",children:[r&&(0,n.jsx)("span",{className:"w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),!r&&d&&(0,n.jsx)("span",{className:"text-xs text-red-11",children:d}),!r&&!d&&l&&(0,n.jsx)("span",{className:`text-xs font-mono ${f?"text-red-11":si.pe.deepseek}`,"data-tooltip":f?t("chat.balanceUnavailable",{defaultValue:"Account is not available for requests"}):void 0,"data-testid":"deepseek-balance-value",children:h||t("chat.balanceEmpty",{defaultValue:"No balance returned"})}),(0,n.jsx)("button",{type:"button","data-testid":"deepseek-balance-button",disabled:!e||r,onClick:x,"data-tooltip":e?void 0:t("chat.balanceNeedsKey",{defaultValue:"Set a DeepSeek API key first"}),className:"px-2 py-0.5 text-xs rounded border border-border text-muted-foreground hover:bg-hover hover:text-foreground transition-colors disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent",children:t("chat.checkBalance",{defaultValue:"Check balance"})}),(0,n.jsx)("a",{href:"https://platform.deepseek.com/usage",target:"_blank",rel:"noopener","data-testid":"deepseek-usage-link",title:t("chat.openUsagePage",{defaultValue:"Open DeepSeek usage console"}),"aria-label":t("chat.openUsagePage",{defaultValue:"Open DeepSeek usage console"}),className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})})]})}let sK={kimi:"https://www.kimi.com/code/console",glm:"https://bigmodel.cn/coding-plan/personal/usage"};function sQ(e){let t=e.remaining??"?",r=e.limit??"?";return`${e.label} ${t}/${r}`}function sG({engine:e,hasKey:t}){let{t:r}=(0,o.Bd)(),[a,l]=(0,s.useState)(!1),[i,d]=(0,s.useState)(null),[c,x]=(0,s.useState)(null),h=(0,s.useCallback)(async()=>{l(!0),x(null);let t=await u.t4.runPromiseExit((0,m.dM)(e));"Failure"===t._tag?(d(null),x(r("chat.quotaFailed",{defaultValue:"Quota unavailable — check the API key"}))):d(t.value),l(!1)},[r,e]),f=i?.windows??[],p=[i?.tier,...f.map(sQ)].filter(Boolean).join(" \xb7 "),g=function(e){if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:`${t.getMonth()+1}/${t.getDate()} ${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}(f.reduce((e,t)=>t.resetTime&&(!e||t.resetTime>e)?t.resetTime:e,null)),b=f.some(e=>0===e.remaining);return(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-2",children:[a&&(0,n.jsx)("span",{className:"w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),!a&&c&&(0,n.jsx)("span",{className:"text-xs text-red-11",children:c}),!a&&!c&&i&&(0,n.jsx)("span",{className:`text-xs font-mono ${b?"text-red-11":si.pe[e]}`,"data-tooltip":g?r("chat.quotaResetAt",{defaultValue:"Resets {{time}}",time:g}):void 0,"data-testid":`${e}-quota-value`,children:p||r("chat.quotaEmpty",{defaultValue:"No quota returned"})}),(0,n.jsx)("button",{type:"button","data-testid":`${e}-quota-button`,disabled:!t||a,onClick:h,"data-tooltip":t?void 0:r("chat.quotaNeedsKey",{defaultValue:"Set an API key first"}),className:"px-2 py-0.5 text-xs rounded border border-border text-muted-foreground hover:bg-hover hover:text-foreground transition-colors disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent",children:r("chat.checkQuota",{defaultValue:"Check quota"})}),(0,n.jsx)("a",{href:sK[e],target:"_blank",rel:"noopener","data-testid":`${e}-console-link`,title:r("chat.openProviderConsole",{defaultValue:"Open the provider console"}),"aria-label":r("chat.openProviderConsole",{defaultValue:"Open the provider console"}),className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})})]})}var sJ=r(67889),sY=r(46456);function sZ(e){if(0===e.length)return"";let t=[tS.A.t("comments.codeRef"),""],r=e.filter(e=>e.filePath===eM.Un),n=e.filter(e=>e.filePath!==eM.Un);for(let e of(n.length>0&&n.forEach((e,r)=>{let n=e.startLine>0||e.endLine>0?`:${e.startLine}-${e.endLine}`:"";t.push(`[${r+1}] ${e.filePath}${n}`),t.push("```"),t.push(e.codeContent),t.push("```"),e.content&&t.push(tS.A.t("comments.note",{content:e.content})),t.push("")}),r)){let r=e.codeContent.split("\n").map(e=>`> ${e}`).join("\n");t.push(r),e.content&&t.push(e.content),t.push("")}return t.join("\n").trim()}function sX({isOpen:e,onClose:t,cwd:r,onNavigateToComment:a}){let{t:l}=(0,o.Bd)(),i=(0,A.r)(),[d,c]=(0,s.useState)([]),[m,x]=(0,s.useState)(!1),[h,f]=(0,s.useState)(null),[p,g]=(0,s.useState)(!1),[v,w]=(0,s.useState)(!1),k=(0,s.useCallback)(async()=>{if(!r)return;x(!0);let e=await u.t4.runPromiseExit((0,sY.$)(r));"Success"===e._tag?c(e.value.comments??[]):console.error("Failed to load comments:",e.cause),x(!1)},[r]);(0,s.useEffect)(()=>{e&&k()},[e,k]);let y=async e=>{let t=await u.t4.runPromiseExit((0,sY.Tu)(r,e));"Success"===t._tag?(c(t=>t.filter(t=>t.id!==e)),(0,eM.Cm)()):console.error("Failed to delete comment:",t.cause)},N=async e=>{f(e.id);try{let t="";if(e.selectedText)t=e.selectedText;else{let n=await u.t4.runPromiseExit((0,j.K)(r,e.filePath));if("Success"!==n._tag||!n.value.ok)throw Error("Failed to read file");t=(n.value.data?.content||"").split("\n").slice(e.startLine-1,e.endLine).join("\n")}let n={filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,content:e.content,codeContent:t},s=sZ([n]);await navigator.clipboard.writeText(s),(0,T.oR)(l("toast.copiedComment"))}catch(e){console.error("Failed to copy comment:",e)}finally{f(null)}},C=async()=>{if(0!==d.length){g(!0);try{let e=await (0,eM.$3)(r),t=sZ(e);await navigator.clipboard.writeText(t),(0,T.oR)(l("toast.copiedAllComments"))}catch(e){console.error("Failed to copy all comments:",e)}finally{g(!1)}}},S=async()=>{if(0!==d.length&&i&&!i.isLoading&&!v){w(!0);try{let e=(await (0,eM.$3)(r)).map(e=>({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0})),n=(0,eM.Gw)(e,"");i.sendMessage(n),await (0,eM.RP)(r),c([]),t()}catch(e){console.error("Failed to send comments to AI:",e)}finally{w(!1)}}},M=d.reduce((e,t)=>(e[t.filePath]||(e[t.filePath]=[]),e[t.filePath].push(t),e),{});if(!e)return null;let L=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-scrim p-4",onClick:t,children:(0,n.jsxs)("div",{className:"w-full max-w-2xl max-h-[80vh] bg-card border border-border rounded-lg shadow-lv3 flex flex-col overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border ",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h2",{className:"text-lg font-semibold text-foreground",children:l("comments.allComments")}),d.length>0&&(0,n.jsx)("button",{onClick:C,disabled:p,className:"p-1 rounded hover:bg-hover text-muted-foreground disabled:opacity-50",title:l("comments.copyAllComments"),children:p?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 rounded hover:bg-hover text-muted-foreground",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:m?(0,n.jsx)("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:l("common.loading")}):0===d.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[(0,n.jsx)("svg",{className:"w-12 h-12 mb-3 opacity-50",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})}),(0,n.jsx)("span",{children:l("comments.noComments")})]}):(0,n.jsx)("div",{className:"space-y-4",children:Object.entries(M).map(([e,t])=>(0,n.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden",children:[(0,n.jsxs)("div",{className:"px-3 py-2 border-b border-border",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-foreground font-mono",children:e===eM.Un?l("comments.aiReply"):e}),(0,n.jsxs)("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",l("comments.nComments",{count:t.length}),")"]})]}),(0,n.jsx)("div",{className:"divide-y divide-border",children:t.map(e=>{var t;return(0,n.jsx)("div",{className:"px-3 py-2 hover:bg-hover cursor-pointer group",onClick:()=>a?.(e),children:(0,n.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[e.startLine>0||e.endLine>0?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{className:"text-xs text-brand font-mono",children:[l("common.line")," ",e.startLine===e.endLine?e.startLine:`${e.startLine}-${e.endLine}`]}),(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:["(",l("comments.linesCount",{count:e.endLine-e.startLine+1}),")"]})]}):e.selectedText?(0,n.jsxs)("span",{className:"text-xs text-muted-foreground italic truncate max-w-[200px]",children:["“",e.selectedText.slice(0,50),e.selectedText.length>50?"...":"","”"]}):null,(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:(t=e.updatedAt||e.createdAt)?new Date(t).toLocaleString("zh-CN",{month:"numeric",day:"numeric",hour:"2-digit",minute:"2-digit"}):""})]}),(0,n.jsx)("p",{className:"text-sm text-foreground line-clamp-2",children:e.content||(0,n.jsx)("span",{className:"text-muted-foreground italic",children:l("comments.noContent")})})]}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),N(e)},disabled:h===e.id,className:"p-1 rounded opacity-0 group-hover:opacity-100 hover:bg-hover text-muted-foreground transition-opacity disabled:opacity-50",title:l("common.copy"),children:h===e.id?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),y(e.id)},className:"p-1 rounded opacity-0 group-hover:opacity-100 hover:bg-hover text-muted-foreground hover:text-red-9 transition-opacity",title:l("common.delete"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]})},e.id)})})]},e))})}),(0,n.jsxs)("div",{className:"px-4 py-3 border-t border-border flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground",children:l("comments.totalComments",{count:d.length})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[i&&(0,n.jsx)("button",{onClick:S,disabled:0===d.length||i.isLoading||v,className:"px-3 py-1.5 text-sm bg-brand text-white rounded hover:bg-brand/90 disabled:opacity-50 disabled:cursor-not-allowed",title:i.isLoading?l("comments.aiResponding"):void 0,children:v?l("comments.submitting"):l("comments.sendToAI")}),(0,n.jsx)("button",{onClick:async()=>{0===d.length||await (0,eM.RP)(r)&&c([])},disabled:0===d.length,className:"px-3 py-1.5 text-sm bg-red-9 text-white rounded hover:bg-red-10 disabled:opacity-50 disabled:cursor-not-allowed",children:l("comments.clearAll")})]})]})]})});return(0,n.jsx)(b.ZL,{children:L})}let s0=`${sJ.o} pl-3 pr-14 bg-card/50`;function s1({tabId:e,initialCwd:t,initialSessionId:r,engine:l,onEngineChange:i,ollamaModel:x,onOllamaModelChange:h,deepseekModel:g,onDeepseekModelChange:b,kimiModel:v,onKimiModelChange:j,glmModel:w,onGlmModelChange:k,claudeModel:y,onClaudeModelChange:N,claudeEffort:C,onClaudeEffortChange:S,claudeFastMode:M,onClaudeFastModeChange:L,claudeThinking:E,onClaudeThinkingChange:P,codexModel:$,onCodexModelChange:R,codexReasoningEffort:I,onCodexReasoningEffortChange:F,planMode:B,onPlanModeChange:D,noHistory:A,onNoHistoryChange:H,outputStyle:z,onOutputStyleChange:W,hideHeader:O,hideSidebar:_,isActive:q=!0,isFocused:V=q,peerTabId:U,peerSide:K,refreshSignal:Q,onLoadingChange:G,onSessionIdChange:J,onTitleChange:Y,onBotChange:Z,onShowGitStatus:X,onOpenNote:ee,isFavorite:et,onToggleFavorite:er,onCreateScheduledTask:en,onOpenSession:es,onContentSearch:eo,onShowFileDiff:ea,onOpenFileLink:el,onOpenSessionBrowser:ei,onOpenSettings:ed}){let ec,{t:eu}=(0,o.Bd)(),em=(0,s.useContext)(a),[ex,eh]=(0,s.useState)(""),[ef,ep]=(0,s.useState)([]),eg=(0,ny.nH)(),[eb,ev]=(0,s.useState)([]),[ej,ew]=(0,s.useState)(null),[ek,ey]=(0,s.useState)(!1),[eN,eC]=(0,s.useState)(!1),[eS,eL]=(0,s.useState)(!1),eE=function(e){let[t,r]=(0,s.useState)(!1);return(0,s.useEffect)(()=>{if(!e)return void r(!1);let t=!1,n=async()=>{let n=await u.t4.runPromiseExit((0,sY.lb)(e));t||"Success"!==n._tag||r((n.value.comments?.length??0)>0)};n();let s=(0,eM.zL)(n);return()=>{t=!0,s()}},[e]),t}(t),[eP,e$]=(0,s.useState)(!1),[eT,eR]=(0,s.useState)(null),[eI,eF]=(0,s.useState)(!1),eB=B??eI,eD=(0,s.useCallback)(e=>{eF(e),D?.(e)},[D]),[eA,eH]=(0,s.useState)(!1),ez=A??eA,eW=(0,s.useCallback)(e=>{eH(e),H?.(e)},[H]),[eO,e_]=(0,s.useState)(""),eq=z??eO,eV=(0,s.useCallback)(e=>{e_(e),W?.(e)},[W]),[eU,eK]=(0,s.useState)(!1),eQ=(0,s.useRef)(null),eG=(0,s.useRef)(null),eJ=(0,s.useCallback)(async e=>{if(!t)return;let r=await u.t4.runPromiseExit((0,m.n_)({cwd:t,sessionId:e}));"Success"===r._tag&&r.value&&"string"==typeof r.value.title?Y?.(r.value.title):"Failure"===r._tag&&console.error("Failed to fetch session title:",r.cause)},[t,Y]),eY=(0,s.useRef)(null),[eZ,eX]=(0,s.useState)(!1),[e0,e1]=(0,s.useState)(null),[e2,e5]=(0,s.useState)(null),[e4,e3]=(0,s.useState)(nH.R),e6=(0,s.useMemo)(()=>(0,nz.hC)(),[]),e8=(0,s.useRef)(!1);(0,s.useEffect)(()=>{e8.current=eZ},[eZ]);let{isLoadingHistory:e9,isLoadingMore:e7,hasMoreHistory:te,loadMoreHistory:tt,ensureTurnLoaded:tr,loadHistoryByCwdAndSessionId:tn,loadedSessionId:ts,loadedEngine:to,loadedBot:ta}=(0,nA.m)(eb,ev,ej,{cwd:t,initialSessionId:r,onSessionId:ew,onTitleChange:Y,onTokenUsage:eR,liveRunningRef:e8}),tl=to??l??void 0;(0,s.useEffect)(()=>{Z?.(ta)},[ta,Z]);let ti=!tl||"claude"===tl,td="codex"===tl,tc=y??sh,tu=sS(tc,C),tm=$??sf,tx=sw(tm,I),th="deepseek"===tl||"kimi"===tl||"glm"===tl?tl:null,tf="kimi"===th?v:"glm"===th?w:g,tp="kimi"===th?j:"glm"===th?k:b,tg="ollama"===tl||null!==th||ti||td;(0,s.useEffect)(()=>{to&&l!==to&&i?.(to)},[l,to,i]);let{isLoading:tb,tokenUsage:tv,liveOutputTokens:tj,runningStartedAt:tw,rateLimitInfo:tk,apiRetryInfo:ty,backgroundTasks:tN,promptSuggestion:tC,handleSend:tS,handleStop:tM,injectMessage:tL}=(0,nH.e)(eb,ev,{sessionId:ej,cwd:t,engine:tl,planMode:eB,noHistory:ez,outputStyleId:eq,ollamaModel:x,engineModel:tf,claudeModel:tc,claudeEffort:tu,claudeFastMode:M,claudeThinking:E,codexModel:tm,codexReasoningEffort:tx,onSessionId:ew,onFetchTitle:eJ,onRunComplete:()=>eY.current?.(),taskStore:e6}),tE=(0,s.useCallback)((e,t,r)=>{eQ.current?.pinNextUserMessage();let n=ts||ej;return ti&&n&&(tb||e8.current)?tL(e,t,n).catch(t=>{eh(t=>t||e),(0,T.oR)(t instanceof Error?t.message:String(t),"error")}):tS(e,t,r)},[tS,tL,ti,tb,ts,ej]),tP=(0,s.useCallback)(async(e,r)=>{let n=e.split("\n")[0];if(ti){let t=/^\/plan(?:\s+([\s\S]*))?$/.exec(e.trim());if(t){let e=(t[1]??"").trim();"off"===e.toLowerCase()?(eD(!1),(0,T.oR)(eu("chat.planModeOff",{defaultValue:"Plan mode off"}),"info")):""===e?(eD(!0),(0,T.oR)(eu("chat.planModeOn",{defaultValue:"Plan mode on"}),"success")):(eD(!0),tE(e,r,{permissionMode:"plan"}));return}}if(n.startsWith("!")&&n.length>1){let s=n.slice(1).trim();if(!s)return void tE(e,r);let o=e.split("\n").slice(1).join("\n").trim(),a=await u.t4.runPromiseExit((0,m.JC)({command:s,cwd:t}));if("Success"===a._tag){let e=a.value,t=[e.stdout,e.stderr].filter(Boolean).join("\n")||"(no output)",n=eu("chat.executedCommand",{command:s,exitInfo:e.exitCode?` (exit code: ${e.exitCode})`:"",output:t});o&&(n+=`
|
|
35
35
|
|
|
36
|
-
${o}`),tM(n,r)}else tM(eu("chat.executedCommandFailed",{command:s,error:a.cause}),r);return}tM(e,r)},[tM,t,eu,ti,eD]),tE=(0,s.useCallback)(()=>{eD(!1),tM(eu("chat.approvePlanPrompt",{defaultValue:"已批准,按上述计划开始执行。"}),void 0,{permissionMode:null})},[tM,eD,eu]),tP=ts||ej,t$=q&&!tb&&!!tP;(0,nR.u)(tP,ev,t$,tl,{onRunningChange:e=>{e8.current=e,eX(e)},onLiveOutputTokens:e1,onRunStartedAt:e5,onBackgroundTasks:e=>e3(e.length?e:nH.R),taskStore:e6,onComplete:()=>{t&&tP&&tn(t,tP,!0,10)}}),(0,s.useEffect)(()=>{t$||(eX(!1),e1(null),e5(null),e3(nH.R))},[t$]),(0,s.useEffect)(()=>{eY.current=()=>{t&&tP&&tn(t,tP,!0,10)}},[t,tP,tn]);let tT=(0,s.useRef)(q);(0,s.useEffect)(()=>{q&&!tT.current&&ej&&t&&!tb&&!eZ&&tn(t,ej,!0,10),tT.current=q},[q,ej,t,tb,eZ,tn]);let tR=(0,s.useRef)(0);(0,s.useEffect)(()=>{if(!Q||Q.nonce===tR.current)return;tR.current=Q.nonce;let e=ej||ts;!t||!e||Q.sessionId!==ej&&Q.sessionId!==ts||tb||eZ||tn(t,e,!0,10,void 0,!0)},[Q,ej,ts,t,tb,eZ,tn]);let tI=tv||eT,tF=tb?tj:eZ?e0:null,tB=tb?tw:eZ?e2:null,tD=tb?tN:eZ?e4:nH.R;(0,s.useEffect)(()=>{ej&&J?.(ej)},[ej,J]);let tA=(0,s.useRef)(!1);(0,s.useEffect)(()=>{if(G?.(tb),tA.current&&!tb&&t&&ej){let e;for(let t=eb.length-1;t>=0;t--)if("user"===eb[t].role&&eb[t].content){e=eb[t].content.slice(0,100);break}(0,d.F)(c.n.SessionComplete,{cwd:t,sessionId:ej,lastUserMessage:e})}tA.current=tb},[tb,G,t]),(0,s.useEffect)(()=>{if(e&&eg&&(eg.setChatLoading(e,q&&tb),q))return()=>{eg.setChatLoading(e,!1)}},[e,tb,q,eg]),(0,s.useEffect)(()=>{if(e&&eg)return eg.registerChat(e=>{eG.current?.(e)},e),()=>{eg.unregisterChat(e)}},[e,eg]),(0,s.useEffect)(()=>{e&&q&&V&&eg&&eg.setActiveTab(e)},[e,q,V,eg]),(0,s.useEffect)(()=>{eG.current=tL},[tL]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&ek&&(tb||eZ)&&tS()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[ek,tb,eZ,tS]);let tH=(0,s.useCallback)(async(e,r)=>{let n=ts??ej;if(!t||!n)return;let s=await u.t4.runPromiseExit((0,m.Zr)(n,{cwd:t,fromMessageUuid:e,scope:r}));if("Success"===s._tag&&s.value.newSessionId){let e=s.value.newSessionId;es?es(e,"single"===r?"Excerpt":"Fork"):(0,d.F)(c.n.OpenProject,{cwd:t,sessionId:e})}else"Failure"===s._tag&&(console.error("Fork failed:",s.cause),(0,T.oR)("single"===r?eu("toast.excerptFailed",{defaultValue:"Failed to excerpt this turn"}):eu("toast.forkFailed",{defaultValue:"Failed to fork session"}),"error"))},[t,ts,ej,es,eu]),tz=(0,s.useRef)(tH);tz.current=tH;let tW=(0,s.useRef)((e,t)=>tz.current(e,t)).current,tO=(0,s.useCallback)(async e=>{let r=ts??ej;if(!t||!r||tb||eZ)return;let n=Math.max(10,eb.filter(e=>"user"===e.role).length),s=await u.t4.runPromiseExit((0,m.$N)(r,{cwd:t,messageUuid:e}));"Success"===s._tag?(ev(t=>{let r=t.findIndex(t=>t.id===e);if(r<0)return t;let n=r;for(;n>=0&&"user"!==t[n].role;)n-=1;if(n<0)return t;let s=n+1;for(;s<t.length&&"user"!==t[s].role;)s+=1;return[...t.slice(0,n),...t.slice(s)]}),await tn(t,r,!1,n,void 0,!0),(0,T.oR)(eu("toast.turnDeleted",{defaultValue:"Turn deleted"}),"success")):(console.error("Delete turn failed:",s.cause),(0,T.oR)(eu("toast.deleteTurnFailed",{defaultValue:"Failed to delete this turn"}),"error"))},[t,ts,ej,tb,eZ,eb,tn,eu]),t_=(0,s.useRef)(tO);t_.current=tO;let tq=(0,s.useRef)(e=>t_.current(e)).current,tV=(0,s.useCallback)(e=>{if(U&&eg){if(!eg.sendToTab(U,e))return void(0,T.oR)(eu("toast.sendToPeerFailed",{defaultValue:"Failed to send to the other pane"}),"error");(0,T.oR)(eu("toast.sentToPeer",{defaultValue:"Sent to the other pane"}),"success")}},[U,eg,eu]),tU=(0,s.useRef)(tV);tU.current=tV;let tK=(0,s.useRef)(e=>tU.current(e)).current,tQ=(0,s.useCallback)(()=>{eL(!0)},[]),tG=(0,s.useCallback)(()=>{e$(!0)},[]),tJ=(0,s.useRef)(eb);tJ.current=eb;let tY=(0,s.useCallback)(async e=>{if(tJ.current.some(t=>t.id===e.id))return void eQ.current?.scrollToMessage(e.id);await tr(e.turnIndex);for(let t=0;t<30;t++)if(await new Promise(e=>requestAnimationFrame(()=>e())),eQ.current?.scrollToMessage(e.id))return},[tr]),tZ=(0,s.useMemo)(()=>{if(en&&t&&e)return r=>{en({...r,cwd:t,tabId:e,sessionId:ej??crypto.randomUUID(),engine:tl,..."ollama"===tl&&x&&{model:x},...th&&tf&&{model:tf},...ti&&{model:tc},...td&&{model:tm}})}},[en,t,e,ej,tl,x,th,tf,ti,tc,td,tm]),tX=tg?(0,n.jsxs)("label",{className:"flex items-center gap-2 text-xs cursor-pointer select-none","data-tooltip":eu("chat.noHistoryDesc",{defaultValue:"each prompt is independent"}),children:[(0,n.jsx)("input",{type:"checkbox","data-testid":"nohistory-toggle",checked:ez,onChange:e=>eW(e.target.checked),className:"peer sr-only"}),(0,n.jsx)("span",{"aria-hidden":"true",className:"relative inline-flex h-4 w-7 shrink-0 items-center rounded-full bg-muted-foreground/30 transition-colors peer-checked:bg-brand peer-focus-visible:outline-none peer-focus-visible:ring-2 peer-focus-visible:ring-ring",children:(0,n.jsx)("span",{className:`h-3 w-3 rounded-full bg-white shadow-sm transition-transform ${ez?"translate-x-3.5":"translate-x-0.5"}`})}),(0,n.jsxs)("span",{className:"flex items-center gap-1.5 text-foreground",children:[(0,n.jsx)(n$.A,{className:"w-3.5 h-3.5"}),eu("chat.noHistory",{defaultValue:"No history context"})]})]}):null,t0=(0,n.jsx)(sq,{value:eq,onChange:eV});return(0,n.jsx)(nz.I$.Provider,{value:e6,children:(0,n.jsxs)("div",{className:`flex ${O&&_?"h-full":"h-screen"} bg-card`,children:[(0,n.jsxs)("div",{id:"chat-screen",className:"flex-1 flex flex-col min-w-0 relative",onMouseEnter:()=>ey(!0),onMouseLeave:()=>ey(!1),children:[!O&&(0,n.jsx)(nF,{cwd:t,sessionId:ej,engine:tl,onOpenProjectSessions:()=>eC(!0),onOpenSessionBrowser:ei,onOpenSettings:ed}),(ti||td)&&(0,n.jsxs)("div",{className:s0,children:[(0,n.jsx)(sE,{engine:td?"codex":"claude",claudeModel:tc,onClaudeModelChange:N,claudeEffort:tu,onClaudeEffortChange:S,claudeFastMode:M,onClaudeFastModeChange:L,claudeThinking:E,onClaudeThinkingChange:P,codexModel:tm,onCodexModelChange:R,codexReasoningEffort:tx,onCodexReasoningEffortChange:F}),ti&&(0,n.jsxs)("label",{className:"flex items-center gap-2 text-xs cursor-pointer select-none","data-tooltip":eu("chat.planModeDesc",{defaultValue:"read-only \xb7 plan first, no edits"}),children:[(0,n.jsx)("input",{type:"checkbox","data-testid":"planmode-toggle",checked:eB,onChange:e=>eD(e.target.checked),className:"peer sr-only"}),(0,n.jsx)("span",{"aria-hidden":"true",className:"relative inline-flex h-4 w-7 shrink-0 items-center rounded-full bg-muted-foreground/30 transition-colors peer-checked:bg-brand peer-focus-visible:outline-none peer-focus-visible:ring-2 peer-focus-visible:ring-ring",children:(0,n.jsx)("span",{className:`h-3 w-3 rounded-full bg-white shadow-sm transition-transform ${eB?"translate-x-3.5":"translate-x-0.5"}`})}),(0,n.jsxs)("span",{className:"flex items-center gap-1.5 text-foreground",children:[(0,n.jsx)(nT.A,{className:"w-3.5 h-3.5"}),eu("chat.planMode",{defaultValue:"Plan mode"})]})]}),tX,t0]}),"ollama"===tl&&(0,n.jsxs)("div",{className:s0,children:[h&&(0,n.jsx)(sc,{currentModel:x,onModelChange:h}),tX,t0]}),th&&(0,n.jsxs)("div",{className:s0,children:[tp&&(0,n.jsx)(sm,{engine:th,currentModel:tf,onModelChange:tp,onHasKeyChange:eK}),tX,t0,(0,n.jsx)("div",{className:"ml-auto pl-2",children:"deepseek"===th?(0,n.jsx)(sU,{hasKey:eU}):(0,n.jsx)(sG,{engine:th,hasKey:eU})})]}),e9?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("span",{className:"text-muted-foreground",children:eu("sessions.loadingHistory")})}):(0,n.jsx)(nW.M,{ref:eQ,messages:eb,isLoading:tb||eZ,liveOutputTokens:tF,runningStartedAt:tB,cwd:t,sessionId:ej,engine:tl,botName:ta,apiRetryInfo:ty,backgroundTasks:tD,hasMoreHistory:te,isLoadingMore:e7,onLoadMore:tt,onFork:tW,onDeleteTurn:tq,onSendToPeer:tK,peerSide:K,isActive:q,onContentSearch:eo,onShowFileDiff:ea,onOpenFileLink:el,onApprovePlan:tE,onShowUserMessages:tG}),tI&&(0,n.jsx)(nB,{tokenUsage:tI,rateLimitInfo:tk}),em&&!V?null:(ec=(0,n.jsx)(sl,{onSend:tL,disabled:tb||eZ,cwd:t,engine:tl,onShowGitStatus:X,onShowComments:t?tQ:void 0,hasComments:eE,onOpenNote:ee,isFavorite:et,onToggleFavorite:er,onCreateScheduledTask:tZ,draft:ex,setDraft:eh,draftImages:ef,setDraftImages:ep}),em?(0,p.createPortal)(ec,em):ec)]}),!O&&t&&(0,n.jsx)(f,{isOpen:eN,onClose:()=>eC(!1),cwd:t}),t&&(0,n.jsx)(sX,{isOpen:eS,onClose:()=>eL(!1),cwd:t}),(0,n.jsx)(nD,{isOpen:eP,onClose:()=>e$(!1),cwd:t,sessionId:ts??ej,onSelectMessage:tY})]})})}function s2({tabId:e,cwd:t,sessionId:r,engine:o,onEngineChange:a,ollamaModel:l,onOllamaModelChange:i,deepseekModel:d,onDeepseekModelChange:c,kimiModel:u,onKimiModelChange:m,glmModel:x,onGlmModelChange:h,claudeModel:f,onClaudeModelChange:p,claudeEffort:g,onClaudeEffortChange:b,claudeFastMode:v,onClaudeFastModeChange:j,claudeThinking:w,onClaudeThinkingChange:k,codexModel:y,onCodexModelChange:N,codexReasoningEffort:C,onCodexReasoningEffortChange:S,planMode:M,onPlanModeChange:L,noHistory:E,onNoHistoryChange:P,outputStyle:$,onOutputStyleChange:T,isActive:R,isFocused:I,peerTabId:F,peerSide:B,refreshSignal:D,onStateChange:A,onShowGitStatus:H,onOpenNote:z,isFavorite:W,onToggleFavorite:O,onCreateScheduledTask:_,onOpenSession:q,onContentSearch:V,onShowFileDiff:U,onOpenFileLink:K}){let Q=(0,s.useCallback)(t=>{A(e,{isLoading:t})},[e,A]),G=(0,s.useCallback)(t=>{A(e,{sessionId:t})},[e,A]),J=(0,s.useCallback)(t=>{A(e,{title:t})},[e,A]),Y=(0,s.useCallback)(t=>{A(e,{bot:t??void 0})},[e,A]),Z=(0,s.useCallback)(t=>{a?.(e,t)},[e,a]),X=(0,s.useCallback)(t=>{i?.(e,t)},[e,i]),ee=(0,s.useCallback)(t=>{c?.(e,t)},[e,c]),et=(0,s.useCallback)(t=>{m?.(e,t)},[e,m]),er=(0,s.useCallback)(t=>{h?.(e,t)},[e,h]),en=(0,s.useCallback)(t=>{p?.(e,t)},[e,p]),es=(0,s.useCallback)(t=>{b?.(e,t)},[e,b]),eo=(0,s.useCallback)(t=>{j?.(e,t)},[e,j]),ea=(0,s.useCallback)(t=>{k?.(e,t)},[e,k]),el=(0,s.useCallback)(t=>{N?.(e,t)},[e,N]),ei=(0,s.useCallback)(t=>{S?.(e,t)},[e,S]),ed=(0,s.useCallback)(t=>{L?.(e,t)},[e,L]),ec=(0,s.useCallback)(t=>{P?.(e,t)},[e,P]),eu=(0,s.useCallback)(t=>{T?.(e,t)},[e,T]),em=(0,s.useCallback)(()=>{O?.(e)},[e,O]);return(0,n.jsx)(s1,{tabId:e,initialCwd:t,initialSessionId:r,engine:o,onEngineChange:Z,ollamaModel:l,onOllamaModelChange:X,deepseekModel:d,onDeepseekModelChange:ee,kimiModel:u,onKimiModelChange:et,glmModel:x,onGlmModelChange:er,claudeModel:f,onClaudeModelChange:en,claudeEffort:g,onClaudeEffortChange:es,claudeFastMode:v,onClaudeFastModeChange:eo,claudeThinking:w,onClaudeThinkingChange:ea,codexModel:y,onCodexModelChange:el,codexReasoningEffort:C,onCodexReasoningEffortChange:ei,planMode:M,onPlanModeChange:ed,noHistory:E,onNoHistoryChange:ec,outputStyle:$,onOutputStyleChange:eu,hideHeader:!0,hideSidebar:!0,isActive:R,isFocused:I,peerTabId:F,peerSide:B,refreshSignal:D,onLoadingChange:Q,onSessionIdChange:G,onTitleChange:J,onBotChange:Y,onShowGitStatus:H,onOpenNote:z,isFavorite:W,onToggleFavorite:r&&O?em:void 0,onCreateScheduledTask:_,onOpenSession:q,onContentSearch:V,onShowFileDiff:U,onOpenFileLink:K})}var s5=r(3292),s4=r(23121),s3=r(88292),s6=r(76900),s8=r(96472);function s9(e,t){if(!t.split)return{};let r=t.panes.indexOf(e);return -1===r?{}:{peerTabId:t.panes[1-r],peerSide:0===r?"right":"left"}}function s7({tabId:e,panes:t,activePane:r,row:s,maximized:a,onFocusPane:l,onClosePane:i,onToggleMaximize:d,children:c}){let{t:u}=(0,o.Bd)(),m=t.indexOf(e),x=t.length>1;return(0,n.jsxs)("div",{onMouseDownCapture:x?()=>l(m):void 0,style:s&&-1!==m&&!a?{order:m}:void 0,className:`group/pane ${function(e,t,r,n,s){let o=t.indexOf(e);if(-1===o)return"relative hidden";if(s)return"absolute inset-0 z-30 border-y border-y-transparent";if(!n)return"relative h-full block";let a=t.length>1?` border-y ${o===r?"border-y-brand":"border-y-transparent"}`:"";return`relative h-full flex-1 min-w-0${a}${o>0?" border-l border-border":""}`}(e,t,r,s,a)}`,children:[x&&-1!==m&&(0,n.jsxs)("div",{className:"absolute top-1 right-1 z-20 flex items-center gap-0.5 opacity-0 pointer-events-none transition-opacity focus-within:opacity-100 focus-within:pointer-events-auto group-hover/pane:opacity-100 group-hover/pane:pointer-events-auto",children:[(0,n.jsx)("button",{type:"button",onClick:()=>d(m),title:u(a?"chat.restorePane":"chat.maximizePane"),"aria-label":u(a?"chat.restorePane":"chat.maximizePane"),"aria-pressed":a,className:"flex items-center justify-center w-6 h-6 text-muted-foreground transition-colors hover:text-foreground",children:a?(0,n.jsx)(nE.A,{className:"w-3.5 h-3.5"}):(0,n.jsx)(nP.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("button",{type:"button",onClick:()=>i(m),title:u("chat.closePane"),"aria-label":u("chat.closePane"),className:"flex items-center justify-center w-6 h-6 text-muted-foreground transition-colors hover:text-foreground",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),c]})}function oe({initialCwd:e,initialSessionId:t,initialBlank:r,initialView:a,initialFile:i,initialBubble:d}){let{t:m}=(0,o.Bd)(),[x,h]=(0,s.useState)(a??"agent"),[p,g]=(0,s.useState)(null),{tabs:v,activeTabId:j,activeTab:w,paneTabIds:k,activePane:y,toggleSideBySide:N,focusPane:C,closePane:S,unreadTabs:M,globalLoadingTabs:L,pageVisible:E,dragTabIndex:P,dragOverTabIndex:$,closeTab:T,closeAllTabs:R,switchTab:I,handleSelectSession:F,handleNewTab:B,handleNewCodexTab:D,handleNewKimiTab:A,handleNewGlmTab:H,handleNewOllamaTab:z,handleNewDeepseekTab:W,handleOpenSession:O,updateTabState:_,updateTabEngine:q,updateTabOllamaModel:V,updateTabDeepseekModel:U,updateTabKimiModel:K,updateTabGlmModel:Q,updateTabClaudeModel:G,updateTabClaudeEffort:J,updateTabClaudeFastMode:Y,updateTabClaudeThinking:Z,updateTabCodexModel:X,updateTabCodexReasoningEffort:ee,updateTabPlanMode:et,updateTabNoHistory:er,updateTabOutputStyle:en,handleTabDragStart:es,handleTabDragOver:ea,handleTabDrop:el,handleTabDragEnd:ei}=(0,nS.useTabState)({initialCwd:e,initialSessionId:t,initialBlank:r,activeView:x}),{isPinned:ed,pinSession:ec,unpinSession:eu}=(0,s5.P)(),{createTask:em}=(0,s4.nS)(),ex=(0,s.useCallback)(e=>{let t=v.find(t=>t.id===e);return!!t?.sessionId&&ed(t.sessionId)},[v,ed]),eh=(0,s.useCallback)(t=>{let r=v.find(e=>e.id===t);r?.sessionId&&(ed(r.sessionId)?eu(r.sessionId):ec(r.sessionId,r.cwd||e||"",r.title))},[v,ed,ec,eu,e]),[ef,ep]=(0,s.useState)(!1),[eg,ev]=(0,s.useState)(!1),[ej,ew]=(0,s.useState)(!1),[ek,ey]=(0,s.useState)(null),[eN,eC]=(0,s.useState)(!1),[eS,eM]=(0,s.useState)("tree"),[eL,eE]=(0,s.useState)(0),[eP,e$]=(0,s.useState)(null),[eT,eR]=(0,s.useState)(0),[eI,eF]=(0,s.useState)(i?{path:i,nonce:0}:null),[eB,eD]=(0,s.useState)(d?{commandId:d,nonce:0}:null),eA=(0,s.useRef)(()=>{}),[eH,ez]=(0,s.useState)(null),eW=null!==eH,eO=(0,s.useMemo)(()=>{let e;return{panes:e=eW?[j]:k,activePane:eW?0:y,row:e.length>1||eW,split:e.length>1,diffOrder:e.length}},[k,y,j,eW]),[e_,eq]=(0,s.useState)(null),[eV,eU]=(0,s.useState)();(0,s.useEffect)(()=>{window.parent.postMessage({type:"GET_PROJECT_NUMBER",cwd:e},"*")},[e]),(0,s.useEffect)(()=>{e&&!a&&u.t4.runPromiseExit((0,s6.D0)(e)).then(e=>{if("Success"===e._tag){let t=e.value.settings;t?.activeView&&h(t.activeView)}})},[e,a]);let[eK,eQ]=(0,s.useState)(!1),eG=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=e=>{let{active:t}=e.detail;t?(eG.current=x,h("console"),eQ(!0)):(eQ(!1),eG.current&&"console"!==eG.current&&h(eG.current),eG.current=null)};return window.addEventListener("cockpit-screenshot-state",e),()=>window.removeEventListener("cockpit-screenshot-state",e)},[x]);let eJ=(0,s.useCallback)(t=>{h(t),e&&(u.t4.runFork((0,s6.Yn)({cwd:e,settings:{activeView:t}}).pipe(eb.NWQ(()=>eb.rIH))),u.t4.runFork(eb.qIB(s3.d,r=>r.publish(c.n.ViewChange,{cwd:e,view:t}))))},[e]);(0,s.useEffect)(()=>{let e=()=>eJ("console");return window.addEventListener("console-open-browser",e),()=>window.removeEventListener("console-open-browser",e)},[eJ]);let eY=(0,s.useCallback)(async()=>{if(!e)return;let t=await u.t4.runPromiseExit((0,s6.b2)(e));if("Success"===t._tag){let r=t.value;if(eC(!!r.isGitRepo),r.isGitRepo&&r.worktrees&&r.worktrees.length>0){let t=r.worktrees.find(t=>t.path===e);t&&ey(t.branch)}}else console.error("Failed to load git info:",t.cause)},[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>eY())},[eY]);let eZ=(0,s.useCallback)(e=>{let{data:t}=e;Array.isArray(t)&&t.some(e=>"git"===e.type)&&eY()},[eY]);(0,eo.h)({url:`/ws/watch?cwd=${encodeURIComponent(e||"")}`,onMessage:eZ,enabled:!!e}),(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&("1"===e.key?(e.preventDefault(),eJ("agent")):"2"===e.key?(e.preventDefault(),eJ("explorer")):"3"===e.key?(e.preventDefault(),eJ("console")):"s"===e.key&&e.preventDefault())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]),(0,s.useEffect)(()=>{e&&window.parent!==window&&window.parent.postMessage({type:"SESSION_NUMBERS",cwd:e,sessionIds:v.map(e=>e.sessionId??null)},"*")},[e,v]),(0,s.useEffect)(()=>{let t=t=>{if(t.data?.type==="PROJECT_NUMBER"&&"number"==typeof t.data?.projectNumber)return void eU(t.data.projectNumber);if(t.data?.type==="IFRAME_VISIBILITY"&&"number"==typeof t.data?.projectNumber&&eU(t.data.projectNumber),t.data?.type==="GET_SESSION_NUMBERS"&&t.data?.requestId&&e)return void window.parent.postMessage({type:"SESSION_NUMBERS",requestId:t.data.requestId,cwd:e,sessionIds:v.map(e=>e.sessionId??null)},"*");if(t.data?.type==="SWITCH_SESSION"){let{sessionId:r,switchToAgent:n}=t.data;if(r){F(r),n&&eJ("agent");let t=v.find(e=>e.sessionId===r);t&&eq(e=>({sessionId:r,nonce:(e?.nonce??0)+1})),e&&!t?.isLoading&&(u.t4.runFork((0,s8.KJ)(e,r,"normal").pipe(eb.NWQ(()=>eb.rIH))),u.t4.runFork((0,s8.M2)(r).pipe(eb.NWQ(()=>eb.rIH))))}}t.data?.type==="OPEN_FILE"&&"string"==typeof t.data?.path&&eA.current({path:t.data.path}),t.data?.type==="FOCUS_CONSOLE_BUBBLE"&&"string"==typeof t.data?.commandId&&(eJ("console"),eD(e=>({commandId:t.data.commandId,nonce:(e?.nonce??0)+1})))};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[F,eJ,e,v]);let eX=(0,s.useCallback)(()=>{eM("status"),eE(e=>e+1),eJ("explorer")},[eJ]),e0=(0,s.useCallback)(e=>{e$(e),eR(e=>e+1),eJ("explorer")},[eJ]),e1=(0,s.useCallback)(()=>eJ("agent"),[eJ]),[e2,e5]=(0,s.useState)(!1);(0,s.useEffect)(()=>{eW||e5(!1)},[eW]);let[e4,e3]=(0,s.useState)(!1),e6=e4&&eO.split?eO.panes[eO.activePane]??null:null;(0,s.useEffect)(()=>{eO.split||e3(!1)},[eO.split]);let e8=(0,s.useCallback)(e=>{e3(e=>!e),C(e)},[C]),e9=(0,s.useCallback)(()=>e5(e=>!e),[]),e7=(0,s.useCallback)(()=>ez(null),[]),te=(0,s.useRef)(null),tt=(0,s.useCallback)(e=>{let t=te.current;if(!t)return;let r=e.offset>0&&null!==e.target&&t.contains(e.target);if("move"===e.phase){if(!r)return;let n=Math.min(.5*e.offset,t.offsetWidth);t.style.transition="none",t.style.transform=`translateX(${n}px)`;return}r&&e.triggered?(t.style.transition="transform 140ms ease-out, opacity 140ms ease-out",t.style.transform="translateX(100%)",t.style.opacity="0",window.setTimeout(e7,140)):(t.style.transition="transform 180ms cubic-bezier(0.2, 0.8, 0.2, 1)",t.style.transform="")},[e7]);(0,s.useEffect)(()=>{let e=te.current;e&&(e.style.transition="",e.style.transform="",e.style.opacity="")},[eH]);let tr=(0,s.useRef)(eW);(0,s.useEffect)(()=>{tr.current=eW},[eW]);let tn=(0,s.useRef)(e6);(0,s.useEffect)(()=>{tn.current=e6},[e6]);let ts=(0,s.useCallback)(()=>{tr.current?e7():null!==tn.current?e3(!1):N()},[N,e7]),to=(0,s.useCallback)((e,t,r,n,s)=>{ez(o=>{var a;return a={messageId:e,toolCalls:t,cwd:r,sessionId:n},!0!==s?a:o?.messageId!==a.messageId?o:{...o,toolCalls:a.toolCalls}}),s||eJ("agent")},[eJ]),ta=(0,s.useCallback)(e=>{eF({...e,nonce:Date.now()}),eJ("explorer")},[eJ]);(0,s.useEffect)(()=>{eA.current=ta},[ta]);let tl=(0,s.useCallback)(()=>{e&&u.t4.runFork(eb.qIB(s3.d,t=>t.publish(c.n.OpenNote,{cwd:e})))},[e]);return(0,n.jsx)(ny.k_,{children:(0,n.jsx)(tI.fY,{activeView:x,onViewChange:eJ,onOverscroll:tt,children:(0,n.jsxs)("div",{className:"flex h-screen bg-card",children:[(0,n.jsxs)("div",{className:"flex-1 flex flex-col min-w-0",children:[(0,n.jsx)(nM.TabManagerTopBar,{initialCwd:e,activeTab:w,isGitRepo:eN,currentBranch:ek,onOpenWorktree:()=>ev(!0),onOpenAliasManager:()=>ew(!0),onBranchSwitched:eY}),eK&&(0,n.jsxs)("div",{className:"flex items-center justify-center gap-2 py-1 bg-brand/15 text-brand text-xs font-medium border-b border-brand/20",children:[(0,n.jsx)("span",{className:"animate-pulse",children:"●"}),m("console.screenshotting")]}),e?(0,n.jsxs)(tI.c0,{children:[(0,n.jsx)("div",{className:"w-1/3 h-full flex flex-col overflow-hidden",children:(0,n.jsx)(b.a9,{children:(0,n.jsxs)("div",{className:"w-full h-full flex flex-col",children:[(0,n.jsx)(nL.TabBar,{tabs:v,selectedTabId:j,sideBySide:eO.split,onToggleSideBySide:ts,unreadTabs:M,globalLoadingTabs:L,dragTabIndex:P,dragOverTabIndex:$,isPinned:ex,onSwitchTab:I,onCloseTab:T,onCloseAllTabs:R,onNewTab:B,onNewCodexTab:D,onNewKimiTab:A,onNewGlmTab:H,onNewOllamaTab:z,onNewDeepseekTab:W,onOpenProjectSessions:()=>ep(!0),onDragStart:es,onDragOver:ea,onDrop:el,onDragEnd:ei}),(0,n.jsx)(l,{value:eO.split?p:null,children:(0,n.jsxs)("div",{className:`flex-1 overflow-hidden relative ${eO.row?"flex":""}`,children:[v.map(e=>(0,n.jsx)(s7,{tabId:e.id,panes:eO.panes,activePane:eO.activePane,row:eO.row,maximized:e6===e.id,onFocusPane:C,onClosePane:S,onToggleMaximize:e8,children:(0,n.jsx)(s2,{tabId:e.id,...s9(e.id,eO),cwd:e.cwd,sessionId:e.sessionId,engine:e.engine,onEngineChange:q,ollamaModel:e.ollamaModel,onOllamaModelChange:V,deepseekModel:e.deepseekModel,onDeepseekModelChange:U,kimiModel:e.kimiModel,onKimiModelChange:K,glmModel:e.glmModel,onGlmModelChange:Q,claudeModel:e.claudeModel,onClaudeModelChange:G,claudeEffort:e.claudeEffort,onClaudeEffortChange:J,claudeFastMode:e.claudeFastMode,onClaudeFastModeChange:Y,claudeThinking:e.claudeThinking,onClaudeThinkingChange:Z,codexModel:e.codexModel,onCodexModelChange:X,codexReasoningEffort:e.codexReasoningEffort,onCodexReasoningEffortChange:ee,planMode:e.planMode,onPlanModeChange:et,noHistory:e.noHistory,onNoHistoryChange:er,outputStyle:e.outputStyle,onOutputStyleChange:en,isActive:nC(e.id,k,"agent"===x,E),isFocused:e.id===j,refreshSignal:e_,onStateChange:_,onShowGitStatus:eX,onContentSearch:e0,onShowFileDiff:to,onOpenFileLink:ta,onOpenNote:tl,isFavorite:ex(e.id),onToggleFavorite:eh,onCreateScheduledTask:em,onOpenSession:O})},e.id)),eH&&(0,n.jsx)("div",{ref:te,"data-diff-column":"",className:e2?"absolute inset-0 z-30 bg-card":"h-full flex-1 min-w-0 border-l border-border",style:e2?void 0:{order:eO.diffOrder},children:(0,n.jsx)(nN.e$,{toolCalls:eH.toolCalls,cwd:eH.cwd,sessionId:eH.sessionId,onClose:e7,onContentSearch:e0,fullscreen:e2,onToggleFullscreen:e9},eH.messageId)})]})}),eO.split&&(0,n.jsx)("div",{ref:g,className:"flex-shrink-0"})]})})}),(0,n.jsx)("div",{className:"w-1/3 h-full overflow-hidden relative",children:(0,n.jsx)(b.a9,{children:(0,n.jsx)(tB,{onClose:e1,cwd:e,initialTab:eS,tabSwitchTrigger:eL,initialSearchQuery:eP,searchQueryTrigger:eT,fileOpenRequest:eI})})}),(0,n.jsx)("div",{className:"w-1/3 h-full overflow-hidden",children:(0,n.jsx)(b.a9,{children:(0,n.jsx)(nk,{cwd:e,tabId:"default",onOpenNote:tl,focusBubble:eB})})})]}):(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,n.jsx)(nL.TabBar,{tabs:v,selectedTabId:j,sideBySide:eO.split,onToggleSideBySide:ts,unreadTabs:M,globalLoadingTabs:L,dragTabIndex:P,dragOverTabIndex:$,isPinned:ex,onSwitchTab:I,onCloseTab:T,onCloseAllTabs:R,onNewTab:B,onNewCodexTab:D,onNewKimiTab:A,onNewGlmTab:H,onNewDeepseekTab:W,onDragStart:es,onDragOver:ea,onDrop:el,onDragEnd:ei}),(0,n.jsx)(l,{value:eO.split?p:null,children:(0,n.jsx)("div",{className:`flex-1 overflow-hidden relative ${eO.row?"flex":""}`,children:v.map(e=>(0,n.jsx)(s7,{tabId:e.id,panes:eO.panes,activePane:eO.activePane,row:eO.row,maximized:e6===e.id,onFocusPane:C,onClosePane:S,onToggleMaximize:e8,children:(0,n.jsx)(s2,{tabId:e.id,...s9(e.id,eO),cwd:e.cwd,sessionId:e.sessionId,engine:e.engine,onEngineChange:q,ollamaModel:e.ollamaModel,onOllamaModelChange:V,deepseekModel:e.deepseekModel,onDeepseekModelChange:U,kimiModel:e.kimiModel,onKimiModelChange:K,glmModel:e.glmModel,onGlmModelChange:Q,claudeModel:e.claudeModel,onClaudeModelChange:G,claudeEffort:e.claudeEffort,onClaudeEffortChange:J,claudeFastMode:e.claudeFastMode,onClaudeFastModeChange:Y,claudeThinking:e.claudeThinking,onClaudeThinkingChange:Z,codexModel:e.codexModel,onCodexModelChange:X,codexReasoningEffort:e.codexReasoningEffort,onCodexReasoningEffortChange:ee,planMode:e.planMode,onPlanModeChange:et,noHistory:e.noHistory,onNoHistoryChange:er,outputStyle:e.outputStyle,onOutputStyleChange:en,isActive:nC(e.id,k,!0,E),isFocused:e.id===j,refreshSignal:e_,onStateChange:_,isFavorite:ex(e.id),onToggleFavorite:eh,onCreateScheduledTask:em,onOpenSession:O})},e.id))})}),eO.split&&(0,n.jsx)("div",{ref:g,className:"flex-shrink-0"})]})]}),e&&(0,n.jsx)(f,{isOpen:ef,onClose:()=>ep(!1),cwd:e,onSelectSession:F,projectNumber:eV,openSessionIds:v.map(e=>e.sessionId)}),e&&eN&&(0,n.jsx)(tD,{isOpen:eg,onClose:()=>ev(!1),cwd:e}),ej&&(0,n.jsx)(ns,{onClose:()=>ew(!1),onSave:()=>ew(!1)})]})})})}},96472:(e,t,r)=>{r.d(t,{KJ:()=>l,M2:()=>d,T$:()=>i,ej:()=>a,n8:()=>o});var n=r(49433),s=r(82680);let o=e=>n.$mh({try:async()=>{let t=await fetch(`/api/project-state?cwd=${encodeURIComponent(e)}`);if(!t.ok)throw Error(`HTTP ${t.status}`);return await t.json()},catch:e=>new s.uV({message:"loadProjectState failed",cause:e})}),a=e=>n.$mh({try:async()=>{let t=await fetch("/api/project-state",{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:"saveProjectState failed",cause:e})}),l=(e,t,r)=>n.$mh({try:async()=>{let n=await fetch("/api/global-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,sessionId:t,status:r,action:"status"})});if(!n.ok)throw Error(`HTTP ${n.status}`)},catch:e=>new s.uV({message:"updateSessionStatus failed",cause:e})}),i=(e,t)=>n.$mh({try:async()=>{let r=await fetch("/api/global-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,sessionId:t,action:"touch"})});if(!r.ok)throw Error(`HTTP ${r.status}`)},catch:e=>new s.uV({message:"touchRecentSession failed",cause:e})}),d=e=>n.$mh({try:async()=>{let t=await fetch("/api/scheduled-tasks",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"markReadBySessionId",fields:{sessionId:e}})});if(!t.ok)throw Error(`HTTP ${t.status}`)},catch:e=>new s.uV({message:"markScheduledTasksReadBySession failed",cause:e})})},96625:(e,t,r)=>{r.d(t,{V:()=>m,n:()=>u});var n=r(95155),s=r(12115),o=r(79114),a=r(58250),l=r(23348),i=r(33442),d=r(86957),c=r(83448);function u({value:e,onChange:t,textareaRef:r,extraCommands:n}){let[o,m]=(0,s.useState)(e.length),[x,h]=(0,s.useState)([]),[f,p]=(0,s.useState)([]),[g,b]=(0,s.useState)([]),[v,j]=(0,s.useState)(0),[w,k]=(0,s.useState)(()=>e.length>0),y=(0,s.useRef)(null);(0,s.useEffect)(()=>{d.t4.runPromiseExit((0,c.M5)()).then(e=>{"Success"===e._tag?h(e.value):console.error("Failed to load commands:",e.cause)})},[]);let N=(0,s.useCallback)(async()=>{let e=await d.t4.runPromiseExit((0,c.l1)());if("Success"===e._tag){let t=e.value.skills??e.value;p((Array.isArray(t)?t:[]).filter(e=>e.valid&&!!e.name).map(e=>({name:`/${e.name}`,description:e.description||"",source:"skill",skillPath:e.path,argumentHint:e.argumentHint})))}else console.error("Failed to load skills:",e.cause)},[]);(0,s.useEffect)(()=>(N(),(0,a.U)(N)),[N]);let C=(0,s.useCallback)(async()=>{let e=await d.t4.runPromiseExit((0,l.jm)());"Success"===e._tag?b(e.value.flatMap(e=>e.valid?[{name:`@${e.name}`,description:e.description,source:"bot"}]:[])):console.error("Failed to load bots:",e.cause)},[]);(0,s.useEffect)(()=>(C(),(0,i.a)(C)),[C]);let S=(0,s.useMemo)(()=>{let t=0===o?0:e.lastIndexOf("\n",o-1)+1,r=e.indexOf("\n",o),n=-1===r?e.length:r;return{text:e.slice(t,n),start:t,end:n}},[e,o]),M=(0,s.useMemo)(()=>{let e=S.text.match(/^\s*(\/@|\/|@)([a-zA-Z0-9-]*)$/);return e?{marker:e[1],verb:e[2].toLowerCase()}:null},[S.text]),L=(0,s.useMemo)(()=>{if(!M)return[];let{verb:e}=M,t=t=>t.name.slice(1).toLowerCase().startsWith(e);return"@"===M.marker?g.filter(t):[...(n??[]).filter(t),...x.filter(t),...f.filter(t)]},[M,n,x,f,g]),E=!w&&!!M&&L.length>0,P=(0,s.useRef)(e);(0,s.useLayoutEffect)(()=>{P.current!==e&&(queueMicrotask(()=>j(0)),w&&queueMicrotask(()=>k(!1)),P.current=e)},[e,w]),(0,s.useLayoutEffect)(()=>{if(E&&y.current){let e=y.current.children[v];e&&e.scrollIntoView({block:"nearest"})}},[v,E]);let $=(0,s.useCallback)(e=>{m(e.selectionStart??0)},[]),T=(0,s.useCallback)(n=>{let s=M?.marker??"/",o=`${s}${n.name.slice(1)} `,a=e.slice(0,S.start),l=e.slice(S.end),i=a.length+o.length;t(a+o+l),m(i),requestAnimationFrame(()=>{let e=r.current;e&&(e.focus(),e.setSelectionRange(i,i))})},[e,S,M,t,r]),R=(0,s.useCallback)(e=>{if(e.nativeEvent.isComposing||!E||0===L.length)return!1;let t=()=>{e.preventDefault(),e.stopPropagation()};return"ArrowDown"===e.key?(t(),j(e=>(e+1)%L.length),!0):"ArrowUp"===e.key?(t(),j(e=>(e-1+L.length)%L.length),!0):"Enter"===e.key||"Tab"===e.key?(t(),T(L[v]),!0):"Escape"===e.key&&(t(),k(!0),!0)},[E,L,v,T]);return{isOpen:E,items:L,selectedIndex:v,marker:M?.marker??"/",listRef:y,selectCommand:T,handleKeyDown:R,trackCaret:$}}function m({ac:e,className:t=""}){let{t:r}=(0,o.Bd)(),{isOpen:s,items:a,selectedIndex:l,marker:i,listRef:d,selectCommand:c}=e;return s&&0!==a.length?(0,n.jsx)("div",{ref:d,className:`overflow-y-auto bg-card border border-border rounded-lg shadow-lv2 ${t}`,children:a.map((e,t)=>{let s=t>0?a[t-1]:null,o="skill"===e.source&&(!s||"skill"!==s.source),d="bot"===e.source&&(!s||"bot"!==s.source),u="builtin"===e.source&&0===t;return(0,n.jsxs)("div",{children:[u&&(0,n.jsx)("div",{className:"px-4 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-muted/40",children:"Commands"}),o&&(0,n.jsx)("div",{className:"px-4 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-muted/40",children:"Skills"}),d&&(0,n.jsx)("div",{className:"px-4 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-muted/40",children:"Bots"}),(0,n.jsxs)("div",{onClick:()=>c(e),className:`px-4 py-2 cursor-pointer ${t===l?"bg-brand/10":"hover:bg-hover"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("span",{className:"font-mono text-sm font-medium text-foreground",children:i+e.name.slice(1)}),(0,n.jsx)("span",{className:"flex-1 text-sm text-muted-foreground truncate",children:"builtin"===e.source?r(`commands.${e.name.slice(1)}`,{defaultValue:e.description}):e.description}),(0,n.jsx)("span",{className:`text-xs px-1.5 py-0.5 rounded ${(e=>{switch(e){case"builtin":return"bg-brand/15 text-brand dark:bg-brand/25 dark:text-teal-11";case"skill":return"bg-purple-9/15 text-purple-11 dark:bg-purple-9/25 dark:text-purple-11";case"bot":return"bg-teal-9/15 text-teal-11 dark:bg-teal-9/25 dark:text-teal-11"}})(e.source)}`,children:(e=>{switch(e){case"builtin":return r("common.builtin");case"skill":return"Skill";case"bot":return"Bot"}})(e.source)})]}),"skill"===e.source&&e.argumentHint&&(0,n.jsx)("div",{className:"font-mono text-xs text-muted-foreground mt-0.5 pl-0 truncate",children:e.argumentHint})]})]},e.name)})}):null}}}]);
|
|
36
|
+
${o}`),tE(n,r)}else tE(eu("chat.executedCommandFailed",{command:s,error:a.cause}),r);return}tE(e,r)},[tE,t,eu,ti,eD]),t$=(0,s.useCallback)(()=>{eD(!1),tE(eu("chat.approvePlanPrompt",{defaultValue:"已批准,按上述计划开始执行。"}),void 0,{permissionMode:null})},[tE,eD,eu]),tT=ts||ej,tR=q&&!tb&&!!tT;(0,nR.u)(tT,ev,tR,tl,{onRunningChange:e=>{e8.current=e,eX(e)},onLiveOutputTokens:e1,onRunStartedAt:e5,onBackgroundTasks:e=>e3(e.length?e:nH.R),taskStore:e6,onComplete:()=>{t&&tT&&tn(t,tT,!0,10)}}),(0,s.useEffect)(()=>{tR||(eX(!1),e1(null),e5(null),e3(nH.R))},[tR]),(0,s.useEffect)(()=>{eY.current=()=>{t&&tT&&tn(t,tT,!0,10)}},[t,tT,tn]);let tI=(0,s.useRef)(q);(0,s.useEffect)(()=>{q&&!tI.current&&ej&&t&&!tb&&!eZ&&tn(t,ej,!0,10),tI.current=q},[q,ej,t,tb,eZ,tn]);let tF=(0,s.useRef)(0);(0,s.useEffect)(()=>{if(!Q||Q.nonce===tF.current)return;tF.current=Q.nonce;let e=ej||ts;!t||!e||Q.sessionId!==ej&&Q.sessionId!==ts||tb||eZ||tn(t,e,!0,10,void 0,!0)},[Q,ej,ts,t,tb,eZ,tn]);let tB=tv||eT,tD=tb?tj:eZ?e0:null,tA=tb?tw:eZ?e2:null,tH=tb?tN:eZ?e4:nH.R;(0,s.useEffect)(()=>{ej&&J?.(ej)},[ej,J]);let tz=(0,s.useRef)(!1);(0,s.useEffect)(()=>{if(G?.(tb),tz.current&&!tb&&t&&ej){let e;for(let t=eb.length-1;t>=0;t--)if("user"===eb[t].role&&eb[t].content){e=eb[t].content.slice(0,100);break}(0,d.F)(c.n.SessionComplete,{cwd:t,sessionId:ej,lastUserMessage:e})}tz.current=tb},[tb,G,t]),(0,s.useEffect)(()=>{if(e&&eg&&(eg.setChatLoading(e,q&&tb),q))return()=>{eg.setChatLoading(e,!1)}},[e,tb,q,eg]),(0,s.useEffect)(()=>{if(e&&eg)return eg.registerChat(e=>{eG.current?.(e)},e),()=>{eg.unregisterChat(e)}},[e,eg]),(0,s.useEffect)(()=>{e&&q&&V&&eg&&eg.setActiveTab(e)},[e,q,V,eg]),(0,s.useEffect)(()=>{eG.current=tP},[tP]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&ek&&(tb||eZ)&&tM()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[ek,tb,eZ,tM]);let tW=(0,s.useCallback)(async(e,r)=>{let n=ts??ej;if(!t||!n)return;let s=await u.t4.runPromiseExit((0,m.Zr)(n,{cwd:t,fromMessageUuid:e,scope:r}));if("Success"===s._tag&&s.value.newSessionId){let e=s.value.newSessionId;es?es(e,"single"===r?"Excerpt":"Fork"):(0,d.F)(c.n.OpenProject,{cwd:t,sessionId:e})}else"Failure"===s._tag&&(console.error("Fork failed:",s.cause),(0,T.oR)("single"===r?eu("toast.excerptFailed",{defaultValue:"Failed to excerpt this turn"}):eu("toast.forkFailed",{defaultValue:"Failed to fork session"}),"error"))},[t,ts,ej,es,eu]),tO=(0,s.useRef)(tW);tO.current=tW;let t_=(0,s.useRef)((e,t)=>tO.current(e,t)).current,tq=(0,s.useCallback)(async e=>{let r=ts??ej;if(!t||!r||tb||eZ)return;let n=Math.max(10,eb.filter(e=>"user"===e.role).length),s=await u.t4.runPromiseExit((0,m.$N)(r,{cwd:t,messageUuid:e}));"Success"===s._tag?(ev(t=>{let r=t.findIndex(t=>t.id===e);if(r<0)return t;let n=r;for(;n>=0&&"user"!==t[n].role;)n-=1;if(n<0)return t;let s=n+1;for(;s<t.length&&"user"!==t[s].role;)s+=1;return[...t.slice(0,n),...t.slice(s)]}),await tn(t,r,!1,n,void 0,!0),(0,T.oR)(eu("toast.turnDeleted",{defaultValue:"Turn deleted"}),"success")):(console.error("Delete turn failed:",s.cause),(0,T.oR)(eu("toast.deleteTurnFailed",{defaultValue:"Failed to delete this turn"}),"error"))},[t,ts,ej,tb,eZ,eb,tn,eu]),tV=(0,s.useRef)(tq);tV.current=tq;let tU=(0,s.useRef)(e=>tV.current(e)).current,tK=(0,s.useCallback)(e=>{if(U&&eg){if(!eg.sendToTab(U,e))return void(0,T.oR)(eu("toast.sendToPeerFailed",{defaultValue:"Failed to send to the other pane"}),"error");(0,T.oR)(eu("toast.sentToPeer",{defaultValue:"Sent to the other pane"}),"success")}},[U,eg,eu]),tQ=(0,s.useRef)(tK);tQ.current=tK;let tG=(0,s.useRef)(e=>tQ.current(e)).current,tJ=(0,s.useCallback)(()=>{eL(!0)},[]),tY=(0,s.useCallback)(()=>{e$(!0)},[]),tZ=(0,s.useRef)(eb);tZ.current=eb;let tX=(0,s.useCallback)(async e=>{if(tZ.current.some(t=>t.id===e.id))return void eQ.current?.scrollToMessage(e.id);await tr(e.turnIndex);for(let t=0;t<30;t++)if(await new Promise(e=>requestAnimationFrame(()=>e())),eQ.current?.scrollToMessage(e.id))return},[tr]),t0=(0,s.useMemo)(()=>{if(en&&t&&e)return r=>{en({...r,cwd:t,tabId:e,sessionId:ej??crypto.randomUUID(),engine:tl,..."ollama"===tl&&x&&{model:x},...th&&tf&&{model:tf},...ti&&{model:tc},...td&&{model:tm}})}},[en,t,e,ej,tl,x,th,tf,ti,tc,td,tm]),t1=tg?(0,n.jsxs)("label",{className:"flex items-center gap-2 text-xs cursor-pointer select-none","data-tooltip":eu("chat.noHistoryDesc",{defaultValue:"each prompt is independent"}),children:[(0,n.jsx)("input",{type:"checkbox","data-testid":"nohistory-toggle",checked:ez,onChange:e=>eW(e.target.checked),className:"peer sr-only"}),(0,n.jsx)("span",{"aria-hidden":"true",className:"relative inline-flex h-4 w-7 shrink-0 items-center rounded-full bg-muted-foreground/30 transition-colors peer-checked:bg-brand peer-focus-visible:outline-none peer-focus-visible:ring-2 peer-focus-visible:ring-ring",children:(0,n.jsx)("span",{className:`h-3 w-3 rounded-full bg-white shadow-sm transition-transform ${ez?"translate-x-3.5":"translate-x-0.5"}`})}),(0,n.jsxs)("span",{className:"flex items-center gap-1.5 text-foreground",children:[(0,n.jsx)(n$.A,{className:"w-3.5 h-3.5"}),eu("chat.noHistory",{defaultValue:"No history context"})]})]}):null,t2=(0,n.jsx)(sq,{value:eq,onChange:eV});return(0,n.jsx)(nz.I$.Provider,{value:e6,children:(0,n.jsxs)("div",{className:`flex ${O&&_?"h-full":"h-screen"} bg-card`,children:[(0,n.jsxs)("div",{id:"chat-screen",className:"flex-1 flex flex-col min-w-0 relative",onMouseEnter:()=>ey(!0),onMouseLeave:()=>ey(!1),children:[!O&&(0,n.jsx)(nF,{cwd:t,sessionId:ej,engine:tl,onOpenProjectSessions:()=>eC(!0),onOpenSessionBrowser:ei,onOpenSettings:ed}),(ti||td)&&(0,n.jsxs)("div",{className:s0,children:[(0,n.jsx)(sE,{engine:td?"codex":"claude",claudeModel:tc,onClaudeModelChange:N,claudeEffort:tu,onClaudeEffortChange:S,claudeFastMode:M,onClaudeFastModeChange:L,claudeThinking:E,onClaudeThinkingChange:P,codexModel:tm,onCodexModelChange:R,codexReasoningEffort:tx,onCodexReasoningEffortChange:F}),ti&&(0,n.jsxs)("label",{className:"flex items-center gap-2 text-xs cursor-pointer select-none","data-tooltip":eu("chat.planModeDesc",{defaultValue:"read-only \xb7 plan first, no edits"}),children:[(0,n.jsx)("input",{type:"checkbox","data-testid":"planmode-toggle",checked:eB,onChange:e=>eD(e.target.checked),className:"peer sr-only"}),(0,n.jsx)("span",{"aria-hidden":"true",className:"relative inline-flex h-4 w-7 shrink-0 items-center rounded-full bg-muted-foreground/30 transition-colors peer-checked:bg-brand peer-focus-visible:outline-none peer-focus-visible:ring-2 peer-focus-visible:ring-ring",children:(0,n.jsx)("span",{className:`h-3 w-3 rounded-full bg-white shadow-sm transition-transform ${eB?"translate-x-3.5":"translate-x-0.5"}`})}),(0,n.jsxs)("span",{className:"flex items-center gap-1.5 text-foreground",children:[(0,n.jsx)(nT.A,{className:"w-3.5 h-3.5"}),eu("chat.planMode",{defaultValue:"Plan mode"})]})]}),t1,t2]}),"ollama"===tl&&(0,n.jsxs)("div",{className:s0,children:[h&&(0,n.jsx)(sc,{currentModel:x,onModelChange:h}),t1,t2]}),th&&(0,n.jsxs)("div",{className:s0,children:[tp&&(0,n.jsx)(sm,{engine:th,currentModel:tf,onModelChange:tp,onHasKeyChange:eK}),t1,t2,(0,n.jsx)("div",{className:"ml-auto pl-2",children:"deepseek"===th?(0,n.jsx)(sU,{hasKey:eU}):(0,n.jsx)(sG,{engine:th,hasKey:eU})})]}),e9?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("span",{className:"text-muted-foreground",children:eu("sessions.loadingHistory")})}):(0,n.jsx)(nW.M,{ref:eQ,messages:eb,isLoading:tb||eZ,liveOutputTokens:tD,runningStartedAt:tA,cwd:t,sessionId:ej,engine:tl,botName:ta,apiRetryInfo:ty,backgroundTasks:tH,hasMoreHistory:te,isLoadingMore:e7,onLoadMore:tt,onFork:t_,onDeleteTurn:tU,onSendToPeer:tG,peerSide:K,isActive:q,onContentSearch:eo,onShowFileDiff:ea,onOpenFileLink:el,onApprovePlan:t$,onShowUserMessages:tY}),tB&&(0,n.jsx)(nB,{tokenUsage:tB,rateLimitInfo:tk}),em&&!V?null:(ec=(0,n.jsx)(sl,{onSend:tP,disabled:(tb||eZ)&&!(ti&&(ts||ej)),running:tb||eZ,cwd:t,engine:tl,onShowGitStatus:X,onShowComments:t?tJ:void 0,hasComments:eE,onOpenNote:ee,isFavorite:et,onToggleFavorite:er,onCreateScheduledTask:t0,draft:ex,setDraft:eh,draftImages:ef,setDraftImages:ep,suggestion:tC}),em?(0,p.createPortal)(ec,em):ec)]}),!O&&t&&(0,n.jsx)(f,{isOpen:eN,onClose:()=>eC(!1),cwd:t}),t&&(0,n.jsx)(sX,{isOpen:eS,onClose:()=>eL(!1),cwd:t}),(0,n.jsx)(nD,{isOpen:eP,onClose:()=>e$(!1),cwd:t,sessionId:ts??ej,onSelectMessage:tX})]})})}function s2({tabId:e,cwd:t,sessionId:r,engine:o,onEngineChange:a,ollamaModel:l,onOllamaModelChange:i,deepseekModel:d,onDeepseekModelChange:c,kimiModel:u,onKimiModelChange:m,glmModel:x,onGlmModelChange:h,claudeModel:f,onClaudeModelChange:p,claudeEffort:g,onClaudeEffortChange:b,claudeFastMode:v,onClaudeFastModeChange:j,claudeThinking:w,onClaudeThinkingChange:k,codexModel:y,onCodexModelChange:N,codexReasoningEffort:C,onCodexReasoningEffortChange:S,planMode:M,onPlanModeChange:L,noHistory:E,onNoHistoryChange:P,outputStyle:$,onOutputStyleChange:T,isActive:R,isFocused:I,peerTabId:F,peerSide:B,refreshSignal:D,onStateChange:A,onShowGitStatus:H,onOpenNote:z,isFavorite:W,onToggleFavorite:O,onCreateScheduledTask:_,onOpenSession:q,onContentSearch:V,onShowFileDiff:U,onOpenFileLink:K}){let Q=(0,s.useCallback)(t=>{A(e,{isLoading:t})},[e,A]),G=(0,s.useCallback)(t=>{A(e,{sessionId:t})},[e,A]),J=(0,s.useCallback)(t=>{A(e,{title:t})},[e,A]),Y=(0,s.useCallback)(t=>{A(e,{bot:t??void 0})},[e,A]),Z=(0,s.useCallback)(t=>{a?.(e,t)},[e,a]),X=(0,s.useCallback)(t=>{i?.(e,t)},[e,i]),ee=(0,s.useCallback)(t=>{c?.(e,t)},[e,c]),et=(0,s.useCallback)(t=>{m?.(e,t)},[e,m]),er=(0,s.useCallback)(t=>{h?.(e,t)},[e,h]),en=(0,s.useCallback)(t=>{p?.(e,t)},[e,p]),es=(0,s.useCallback)(t=>{b?.(e,t)},[e,b]),eo=(0,s.useCallback)(t=>{j?.(e,t)},[e,j]),ea=(0,s.useCallback)(t=>{k?.(e,t)},[e,k]),el=(0,s.useCallback)(t=>{N?.(e,t)},[e,N]),ei=(0,s.useCallback)(t=>{S?.(e,t)},[e,S]),ed=(0,s.useCallback)(t=>{L?.(e,t)},[e,L]),ec=(0,s.useCallback)(t=>{P?.(e,t)},[e,P]),eu=(0,s.useCallback)(t=>{T?.(e,t)},[e,T]),em=(0,s.useCallback)(()=>{O?.(e)},[e,O]);return(0,n.jsx)(s1,{tabId:e,initialCwd:t,initialSessionId:r,engine:o,onEngineChange:Z,ollamaModel:l,onOllamaModelChange:X,deepseekModel:d,onDeepseekModelChange:ee,kimiModel:u,onKimiModelChange:et,glmModel:x,onGlmModelChange:er,claudeModel:f,onClaudeModelChange:en,claudeEffort:g,onClaudeEffortChange:es,claudeFastMode:v,onClaudeFastModeChange:eo,claudeThinking:w,onClaudeThinkingChange:ea,codexModel:y,onCodexModelChange:el,codexReasoningEffort:C,onCodexReasoningEffortChange:ei,planMode:M,onPlanModeChange:ed,noHistory:E,onNoHistoryChange:ec,outputStyle:$,onOutputStyleChange:eu,hideHeader:!0,hideSidebar:!0,isActive:R,isFocused:I,peerTabId:F,peerSide:B,refreshSignal:D,onLoadingChange:Q,onSessionIdChange:G,onTitleChange:J,onBotChange:Y,onShowGitStatus:H,onOpenNote:z,isFavorite:W,onToggleFavorite:r&&O?em:void 0,onCreateScheduledTask:_,onOpenSession:q,onContentSearch:V,onShowFileDiff:U,onOpenFileLink:K})}var s5=r(3292),s4=r(23121),s3=r(88292),s6=r(76900),s8=r(96472);function s9(e,t){if(!t.split)return{};let r=t.panes.indexOf(e);return -1===r?{}:{peerTabId:t.panes[1-r],peerSide:0===r?"right":"left"}}function s7({tabId:e,panes:t,activePane:r,row:s,maximized:a,onFocusPane:l,onClosePane:i,onToggleMaximize:d,children:c}){let{t:u}=(0,o.Bd)(),m=t.indexOf(e),x=t.length>1;return(0,n.jsxs)("div",{onMouseDownCapture:x?()=>l(m):void 0,style:s&&-1!==m&&!a?{order:m}:void 0,className:`group/pane ${function(e,t,r,n,s){let o=t.indexOf(e);if(-1===o)return"relative hidden";if(s)return"absolute inset-0 z-30 border-y border-y-transparent";if(!n)return"relative h-full block";let a=t.length>1?` border-y ${o===r?"border-y-brand":"border-y-transparent"}`:"";return`relative h-full flex-1 min-w-0${a}${o>0?" border-l border-border":""}`}(e,t,r,s,a)}`,children:[x&&-1!==m&&(0,n.jsxs)("div",{className:"absolute top-1 right-1 z-20 flex items-center gap-0.5 opacity-0 pointer-events-none transition-opacity focus-within:opacity-100 focus-within:pointer-events-auto group-hover/pane:opacity-100 group-hover/pane:pointer-events-auto",children:[(0,n.jsx)("button",{type:"button",onClick:()=>d(m),title:u(a?"chat.restorePane":"chat.maximizePane"),"aria-label":u(a?"chat.restorePane":"chat.maximizePane"),"aria-pressed":a,className:"flex items-center justify-center w-6 h-6 text-muted-foreground transition-colors hover:text-foreground",children:a?(0,n.jsx)(nE.A,{className:"w-3.5 h-3.5"}):(0,n.jsx)(nP.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("button",{type:"button",onClick:()=>i(m),title:u("chat.closePane"),"aria-label":u("chat.closePane"),className:"flex items-center justify-center w-6 h-6 text-muted-foreground transition-colors hover:text-foreground",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),c]})}function oe({initialCwd:e,initialSessionId:t,initialBlank:r,initialView:a,initialFile:i,initialBubble:d}){let{t:m}=(0,o.Bd)(),[x,h]=(0,s.useState)(a??"agent"),[p,g]=(0,s.useState)(null),{tabs:v,activeTabId:j,activeTab:w,paneTabIds:k,activePane:y,toggleSideBySide:N,focusPane:C,closePane:S,unreadTabs:M,globalLoadingTabs:L,pageVisible:E,dragTabIndex:P,dragOverTabIndex:$,closeTab:T,closeAllTabs:R,switchTab:I,handleSelectSession:F,handleNewTab:B,handleNewCodexTab:D,handleNewKimiTab:A,handleNewGlmTab:H,handleNewOllamaTab:z,handleNewDeepseekTab:W,handleOpenSession:O,updateTabState:_,updateTabEngine:q,updateTabOllamaModel:V,updateTabDeepseekModel:U,updateTabKimiModel:K,updateTabGlmModel:Q,updateTabClaudeModel:G,updateTabClaudeEffort:J,updateTabClaudeFastMode:Y,updateTabClaudeThinking:Z,updateTabCodexModel:X,updateTabCodexReasoningEffort:ee,updateTabPlanMode:et,updateTabNoHistory:er,updateTabOutputStyle:en,handleTabDragStart:es,handleTabDragOver:ea,handleTabDrop:el,handleTabDragEnd:ei}=(0,nS.useTabState)({initialCwd:e,initialSessionId:t,initialBlank:r,activeView:x}),{isPinned:ed,pinSession:ec,unpinSession:eu}=(0,s5.P)(),{createTask:em}=(0,s4.nS)(),ex=(0,s.useCallback)(e=>{let t=v.find(t=>t.id===e);return!!t?.sessionId&&ed(t.sessionId)},[v,ed]),eh=(0,s.useCallback)(t=>{let r=v.find(e=>e.id===t);r?.sessionId&&(ed(r.sessionId)?eu(r.sessionId):ec(r.sessionId,r.cwd||e||"",r.title))},[v,ed,ec,eu,e]),[ef,ep]=(0,s.useState)(!1),[eg,ev]=(0,s.useState)(!1),[ej,ew]=(0,s.useState)(!1),[ek,ey]=(0,s.useState)(null),[eN,eC]=(0,s.useState)(!1),[eS,eM]=(0,s.useState)("tree"),[eL,eE]=(0,s.useState)(0),[eP,e$]=(0,s.useState)(null),[eT,eR]=(0,s.useState)(0),[eI,eF]=(0,s.useState)(i?{path:i,nonce:0}:null),[eB,eD]=(0,s.useState)(d?{commandId:d,nonce:0}:null),eA=(0,s.useRef)(()=>{}),[eH,ez]=(0,s.useState)(null),eW=null!==eH,eO=(0,s.useMemo)(()=>{let e;return{panes:e=eW?[j]:k,activePane:eW?0:y,row:e.length>1||eW,split:e.length>1,diffOrder:e.length}},[k,y,j,eW]),[e_,eq]=(0,s.useState)(null),[eV,eU]=(0,s.useState)();(0,s.useEffect)(()=>{window.parent.postMessage({type:"GET_PROJECT_NUMBER",cwd:e},"*")},[e]),(0,s.useEffect)(()=>{e&&!a&&u.t4.runPromiseExit((0,s6.D0)(e)).then(e=>{if("Success"===e._tag){let t=e.value.settings;t?.activeView&&h(t.activeView)}})},[e,a]);let[eK,eQ]=(0,s.useState)(!1),eG=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=e=>{let{active:t}=e.detail;t?(eG.current=x,h("console"),eQ(!0)):(eQ(!1),eG.current&&"console"!==eG.current&&h(eG.current),eG.current=null)};return window.addEventListener("cockpit-screenshot-state",e),()=>window.removeEventListener("cockpit-screenshot-state",e)},[x]);let eJ=(0,s.useCallback)(t=>{h(t),e&&(u.t4.runFork((0,s6.Yn)({cwd:e,settings:{activeView:t}}).pipe(eb.NWQ(()=>eb.rIH))),u.t4.runFork(eb.qIB(s3.d,r=>r.publish(c.n.ViewChange,{cwd:e,view:t}))))},[e]);(0,s.useEffect)(()=>{let e=()=>eJ("console");return window.addEventListener("console-open-browser",e),()=>window.removeEventListener("console-open-browser",e)},[eJ]);let eY=(0,s.useCallback)(async()=>{if(!e)return;let t=await u.t4.runPromiseExit((0,s6.b2)(e));if("Success"===t._tag){let r=t.value;if(eC(!!r.isGitRepo),r.isGitRepo&&r.worktrees&&r.worktrees.length>0){let t=r.worktrees.find(t=>t.path===e);t&&ey(t.branch)}}else console.error("Failed to load git info:",t.cause)},[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>eY())},[eY]);let eZ=(0,s.useCallback)(e=>{let{data:t}=e;Array.isArray(t)&&t.some(e=>"git"===e.type)&&eY()},[eY]);(0,eo.h)({url:`/ws/watch?cwd=${encodeURIComponent(e||"")}`,onMessage:eZ,enabled:!!e}),(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&("1"===e.key?(e.preventDefault(),eJ("agent")):"2"===e.key?(e.preventDefault(),eJ("explorer")):"3"===e.key?(e.preventDefault(),eJ("console")):"s"===e.key&&e.preventDefault())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]),(0,s.useEffect)(()=>{e&&window.parent!==window&&window.parent.postMessage({type:"SESSION_NUMBERS",cwd:e,sessionIds:v.map(e=>e.sessionId??null)},"*")},[e,v]),(0,s.useEffect)(()=>{let t=t=>{if(t.data?.type==="PROJECT_NUMBER"&&"number"==typeof t.data?.projectNumber)return void eU(t.data.projectNumber);if(t.data?.type==="IFRAME_VISIBILITY"&&"number"==typeof t.data?.projectNumber&&eU(t.data.projectNumber),t.data?.type==="GET_SESSION_NUMBERS"&&t.data?.requestId&&e)return void window.parent.postMessage({type:"SESSION_NUMBERS",requestId:t.data.requestId,cwd:e,sessionIds:v.map(e=>e.sessionId??null)},"*");if(t.data?.type==="SWITCH_SESSION"){let{sessionId:r,switchToAgent:n}=t.data;if(r){F(r),n&&eJ("agent");let t=v.find(e=>e.sessionId===r);t&&eq(e=>({sessionId:r,nonce:(e?.nonce??0)+1})),e&&!t?.isLoading&&(u.t4.runFork((0,s8.KJ)(e,r,"normal").pipe(eb.NWQ(()=>eb.rIH))),u.t4.runFork((0,s8.M2)(r).pipe(eb.NWQ(()=>eb.rIH))))}}t.data?.type==="OPEN_FILE"&&"string"==typeof t.data?.path&&eA.current({path:t.data.path}),t.data?.type==="FOCUS_CONSOLE_BUBBLE"&&"string"==typeof t.data?.commandId&&(eJ("console"),eD(e=>({commandId:t.data.commandId,nonce:(e?.nonce??0)+1})))};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[F,eJ,e,v]);let eX=(0,s.useCallback)(()=>{eM("status"),eE(e=>e+1),eJ("explorer")},[eJ]),e0=(0,s.useCallback)(e=>{e$(e),eR(e=>e+1),eJ("explorer")},[eJ]),e1=(0,s.useCallback)(()=>eJ("agent"),[eJ]),[e2,e5]=(0,s.useState)(!1);(0,s.useEffect)(()=>{eW||e5(!1)},[eW]);let[e4,e3]=(0,s.useState)(!1),e6=e4&&eO.split?eO.panes[eO.activePane]??null:null;(0,s.useEffect)(()=>{eO.split||e3(!1)},[eO.split]);let e8=(0,s.useCallback)(e=>{e3(e=>!e),C(e)},[C]),e9=(0,s.useCallback)(()=>e5(e=>!e),[]),e7=(0,s.useCallback)(()=>ez(null),[]),te=(0,s.useRef)(null),tt=(0,s.useCallback)(e=>{let t=te.current;if(!t)return;let r=e.offset>0&&null!==e.target&&t.contains(e.target);if("move"===e.phase){if(!r)return;let n=Math.min(.5*e.offset,t.offsetWidth);t.style.transition="none",t.style.transform=`translateX(${n}px)`;return}r&&e.triggered?(t.style.transition="transform 140ms ease-out, opacity 140ms ease-out",t.style.transform="translateX(100%)",t.style.opacity="0",window.setTimeout(e7,140)):(t.style.transition="transform 180ms cubic-bezier(0.2, 0.8, 0.2, 1)",t.style.transform="")},[e7]);(0,s.useEffect)(()=>{let e=te.current;e&&(e.style.transition="",e.style.transform="",e.style.opacity="")},[eH]);let tr=(0,s.useRef)(eW);(0,s.useEffect)(()=>{tr.current=eW},[eW]);let tn=(0,s.useRef)(e6);(0,s.useEffect)(()=>{tn.current=e6},[e6]);let ts=(0,s.useCallback)(()=>{tr.current?e7():null!==tn.current?e3(!1):N()},[N,e7]),to=(0,s.useCallback)((e,t,r,n,s)=>{ez(o=>{var a;return a={messageId:e,toolCalls:t,cwd:r,sessionId:n},!0!==s?a:o?.messageId!==a.messageId?o:{...o,toolCalls:a.toolCalls}}),s||eJ("agent")},[eJ]),ta=(0,s.useCallback)(e=>{eF({...e,nonce:Date.now()}),eJ("explorer")},[eJ]);(0,s.useEffect)(()=>{eA.current=ta},[ta]);let tl=(0,s.useCallback)(()=>{e&&u.t4.runFork(eb.qIB(s3.d,t=>t.publish(c.n.OpenNote,{cwd:e})))},[e]);return(0,n.jsx)(ny.k_,{children:(0,n.jsx)(tI.fY,{activeView:x,onViewChange:eJ,onOverscroll:tt,children:(0,n.jsxs)("div",{className:"flex h-screen bg-card",children:[(0,n.jsxs)("div",{className:"flex-1 flex flex-col min-w-0",children:[(0,n.jsx)(nM.TabManagerTopBar,{initialCwd:e,activeTab:w,isGitRepo:eN,currentBranch:ek,onOpenWorktree:()=>ev(!0),onOpenAliasManager:()=>ew(!0),onBranchSwitched:eY}),eK&&(0,n.jsxs)("div",{className:"flex items-center justify-center gap-2 py-1 bg-brand/15 text-brand text-xs font-medium border-b border-brand/20",children:[(0,n.jsx)("span",{className:"animate-pulse",children:"●"}),m("console.screenshotting")]}),e?(0,n.jsxs)(tI.c0,{children:[(0,n.jsx)("div",{className:"w-1/3 h-full flex flex-col overflow-hidden",children:(0,n.jsx)(b.a9,{children:(0,n.jsxs)("div",{className:"w-full h-full flex flex-col",children:[(0,n.jsx)(nL.TabBar,{tabs:v,selectedTabId:j,sideBySide:eO.split,onToggleSideBySide:ts,unreadTabs:M,globalLoadingTabs:L,dragTabIndex:P,dragOverTabIndex:$,isPinned:ex,onSwitchTab:I,onCloseTab:T,onCloseAllTabs:R,onNewTab:B,onNewCodexTab:D,onNewKimiTab:A,onNewGlmTab:H,onNewOllamaTab:z,onNewDeepseekTab:W,onOpenProjectSessions:()=>ep(!0),onDragStart:es,onDragOver:ea,onDrop:el,onDragEnd:ei}),(0,n.jsx)(l,{value:eO.split?p:null,children:(0,n.jsxs)("div",{className:`flex-1 overflow-hidden relative ${eO.row?"flex":""}`,children:[v.map(e=>(0,n.jsx)(s7,{tabId:e.id,panes:eO.panes,activePane:eO.activePane,row:eO.row,maximized:e6===e.id,onFocusPane:C,onClosePane:S,onToggleMaximize:e8,children:(0,n.jsx)(s2,{tabId:e.id,...s9(e.id,eO),cwd:e.cwd,sessionId:e.sessionId,engine:e.engine,onEngineChange:q,ollamaModel:e.ollamaModel,onOllamaModelChange:V,deepseekModel:e.deepseekModel,onDeepseekModelChange:U,kimiModel:e.kimiModel,onKimiModelChange:K,glmModel:e.glmModel,onGlmModelChange:Q,claudeModel:e.claudeModel,onClaudeModelChange:G,claudeEffort:e.claudeEffort,onClaudeEffortChange:J,claudeFastMode:e.claudeFastMode,onClaudeFastModeChange:Y,claudeThinking:e.claudeThinking,onClaudeThinkingChange:Z,codexModel:e.codexModel,onCodexModelChange:X,codexReasoningEffort:e.codexReasoningEffort,onCodexReasoningEffortChange:ee,planMode:e.planMode,onPlanModeChange:et,noHistory:e.noHistory,onNoHistoryChange:er,outputStyle:e.outputStyle,onOutputStyleChange:en,isActive:nC(e.id,k,"agent"===x,E),isFocused:e.id===j,refreshSignal:e_,onStateChange:_,onShowGitStatus:eX,onContentSearch:e0,onShowFileDiff:to,onOpenFileLink:ta,onOpenNote:tl,isFavorite:ex(e.id),onToggleFavorite:eh,onCreateScheduledTask:em,onOpenSession:O})},e.id)),eH&&(0,n.jsx)("div",{ref:te,"data-diff-column":"",className:e2?"absolute inset-0 z-30 bg-card":"h-full flex-1 min-w-0 border-l border-border",style:e2?void 0:{order:eO.diffOrder},children:(0,n.jsx)(nN.e$,{toolCalls:eH.toolCalls,cwd:eH.cwd,sessionId:eH.sessionId,onClose:e7,onContentSearch:e0,fullscreen:e2,onToggleFullscreen:e9},eH.messageId)})]})}),eO.split&&(0,n.jsx)("div",{ref:g,className:"flex-shrink-0"})]})})}),(0,n.jsx)("div",{className:"w-1/3 h-full overflow-hidden relative",children:(0,n.jsx)(b.a9,{children:(0,n.jsx)(tB,{onClose:e1,cwd:e,initialTab:eS,tabSwitchTrigger:eL,initialSearchQuery:eP,searchQueryTrigger:eT,fileOpenRequest:eI})})}),(0,n.jsx)("div",{className:"w-1/3 h-full overflow-hidden",children:(0,n.jsx)(b.a9,{children:(0,n.jsx)(nk,{cwd:e,tabId:"default",onOpenNote:tl,focusBubble:eB})})})]}):(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,n.jsx)(nL.TabBar,{tabs:v,selectedTabId:j,sideBySide:eO.split,onToggleSideBySide:ts,unreadTabs:M,globalLoadingTabs:L,dragTabIndex:P,dragOverTabIndex:$,isPinned:ex,onSwitchTab:I,onCloseTab:T,onCloseAllTabs:R,onNewTab:B,onNewCodexTab:D,onNewKimiTab:A,onNewGlmTab:H,onNewDeepseekTab:W,onDragStart:es,onDragOver:ea,onDrop:el,onDragEnd:ei}),(0,n.jsx)(l,{value:eO.split?p:null,children:(0,n.jsx)("div",{className:`flex-1 overflow-hidden relative ${eO.row?"flex":""}`,children:v.map(e=>(0,n.jsx)(s7,{tabId:e.id,panes:eO.panes,activePane:eO.activePane,row:eO.row,maximized:e6===e.id,onFocusPane:C,onClosePane:S,onToggleMaximize:e8,children:(0,n.jsx)(s2,{tabId:e.id,...s9(e.id,eO),cwd:e.cwd,sessionId:e.sessionId,engine:e.engine,onEngineChange:q,ollamaModel:e.ollamaModel,onOllamaModelChange:V,deepseekModel:e.deepseekModel,onDeepseekModelChange:U,kimiModel:e.kimiModel,onKimiModelChange:K,glmModel:e.glmModel,onGlmModelChange:Q,claudeModel:e.claudeModel,onClaudeModelChange:G,claudeEffort:e.claudeEffort,onClaudeEffortChange:J,claudeFastMode:e.claudeFastMode,onClaudeFastModeChange:Y,claudeThinking:e.claudeThinking,onClaudeThinkingChange:Z,codexModel:e.codexModel,onCodexModelChange:X,codexReasoningEffort:e.codexReasoningEffort,onCodexReasoningEffortChange:ee,planMode:e.planMode,onPlanModeChange:et,noHistory:e.noHistory,onNoHistoryChange:er,outputStyle:e.outputStyle,onOutputStyleChange:en,isActive:nC(e.id,k,!0,E),isFocused:e.id===j,refreshSignal:e_,onStateChange:_,isFavorite:ex(e.id),onToggleFavorite:eh,onCreateScheduledTask:em,onOpenSession:O})},e.id))})}),eO.split&&(0,n.jsx)("div",{ref:g,className:"flex-shrink-0"})]})]}),e&&(0,n.jsx)(f,{isOpen:ef,onClose:()=>ep(!1),cwd:e,onSelectSession:F,projectNumber:eV,openSessionIds:v.map(e=>e.sessionId)}),e&&eN&&(0,n.jsx)(tD,{isOpen:eg,onClose:()=>ev(!1),cwd:e}),ej&&(0,n.jsx)(ns,{onClose:()=>ew(!1),onSave:()=>ew(!1)})]})})})}},96472:(e,t,r)=>{r.d(t,{KJ:()=>l,M2:()=>d,T$:()=>i,ej:()=>a,n8:()=>o});var n=r(49433),s=r(82680);let o=e=>n.$mh({try:async()=>{let t=await fetch(`/api/project-state?cwd=${encodeURIComponent(e)}`);if(!t.ok)throw Error(`HTTP ${t.status}`);return await t.json()},catch:e=>new s.uV({message:"loadProjectState failed",cause:e})}),a=e=>n.$mh({try:async()=>{let t=await fetch("/api/project-state",{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:"saveProjectState failed",cause:e})}),l=(e,t,r)=>n.$mh({try:async()=>{let n=await fetch("/api/global-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,sessionId:t,status:r,action:"status"})});if(!n.ok)throw Error(`HTTP ${n.status}`)},catch:e=>new s.uV({message:"updateSessionStatus failed",cause:e})}),i=(e,t)=>n.$mh({try:async()=>{let r=await fetch("/api/global-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,sessionId:t,action:"touch"})});if(!r.ok)throw Error(`HTTP ${r.status}`)},catch:e=>new s.uV({message:"touchRecentSession failed",cause:e})}),d=e=>n.$mh({try:async()=>{let t=await fetch("/api/scheduled-tasks",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"markReadBySessionId",fields:{sessionId:e}})});if(!t.ok)throw Error(`HTTP ${t.status}`)},catch:e=>new s.uV({message:"markScheduledTasksReadBySession failed",cause:e})})},96625:(e,t,r)=>{r.d(t,{V:()=>m,n:()=>u});var n=r(95155),s=r(12115),o=r(79114),a=r(58250),l=r(23348),i=r(33442),d=r(86957),c=r(83448);function u({value:e,onChange:t,textareaRef:r,extraCommands:n}){let[o,m]=(0,s.useState)(e.length),[x,h]=(0,s.useState)([]),[f,p]=(0,s.useState)([]),[g,b]=(0,s.useState)([]),[v,j]=(0,s.useState)(0),[w,k]=(0,s.useState)(()=>e.length>0),y=(0,s.useRef)(null);(0,s.useEffect)(()=>{d.t4.runPromiseExit((0,c.M5)()).then(e=>{"Success"===e._tag?h(e.value):console.error("Failed to load commands:",e.cause)})},[]);let N=(0,s.useCallback)(async()=>{let e=await d.t4.runPromiseExit((0,c.l1)());if("Success"===e._tag){let t=e.value.skills??e.value;p((Array.isArray(t)?t:[]).filter(e=>e.valid&&!!e.name).map(e=>({name:`/${e.name}`,description:e.description||"",source:"skill",skillPath:e.path,argumentHint:e.argumentHint})))}else console.error("Failed to load skills:",e.cause)},[]);(0,s.useEffect)(()=>(N(),(0,a.U)(N)),[N]);let C=(0,s.useCallback)(async()=>{let e=await d.t4.runPromiseExit((0,l.jm)());"Success"===e._tag?b(e.value.flatMap(e=>e.valid?[{name:`@${e.name}`,description:e.description,source:"bot"}]:[])):console.error("Failed to load bots:",e.cause)},[]);(0,s.useEffect)(()=>(C(),(0,i.a)(C)),[C]);let S=(0,s.useMemo)(()=>{let t=0===o?0:e.lastIndexOf("\n",o-1)+1,r=e.indexOf("\n",o),n=-1===r?e.length:r;return{text:e.slice(t,n),start:t,end:n}},[e,o]),M=(0,s.useMemo)(()=>{let e=S.text.match(/^\s*(\/@|\/|@)([a-zA-Z0-9-]*)$/);return e?{marker:e[1],verb:e[2].toLowerCase()}:null},[S.text]),L=(0,s.useMemo)(()=>{if(!M)return[];let{verb:e}=M,t=t=>t.name.slice(1).toLowerCase().startsWith(e);return"@"===M.marker?g.filter(t):[...(n??[]).filter(t),...x.filter(t),...f.filter(t)]},[M,n,x,f,g]),E=!w&&!!M&&L.length>0,P=(0,s.useRef)(e);(0,s.useLayoutEffect)(()=>{P.current!==e&&(queueMicrotask(()=>j(0)),w&&queueMicrotask(()=>k(!1)),P.current=e)},[e,w]),(0,s.useLayoutEffect)(()=>{if(E&&y.current){let e=y.current.children[v];e&&e.scrollIntoView({block:"nearest"})}},[v,E]);let $=(0,s.useCallback)(e=>{m(e.selectionStart??0)},[]),T=(0,s.useCallback)(n=>{let s=M?.marker??"/",o=`${s}${n.name.slice(1)} `,a=e.slice(0,S.start),l=e.slice(S.end),i=a.length+o.length;t(a+o+l),m(i),requestAnimationFrame(()=>{let e=r.current;e&&(e.focus(),e.setSelectionRange(i,i))})},[e,S,M,t,r]),R=(0,s.useCallback)(e=>{if(e.nativeEvent.isComposing||!E||0===L.length)return!1;let t=()=>{e.preventDefault(),e.stopPropagation()};return"ArrowDown"===e.key?(t(),j(e=>(e+1)%L.length),!0):"ArrowUp"===e.key?(t(),j(e=>(e-1+L.length)%L.length),!0):"Enter"===e.key||"Tab"===e.key?(t(),T(L[v]),!0):"Escape"===e.key&&(t(),k(!0),!0)},[E,L,v,T]);return{isOpen:E,items:L,selectedIndex:v,marker:M?.marker??"/",listRef:y,selectCommand:T,handleKeyDown:R,trackCaret:$}}function m({ac:e,className:t=""}){let{t:r}=(0,o.Bd)(),{isOpen:s,items:a,selectedIndex:l,marker:i,listRef:d,selectCommand:c}=e;return s&&0!==a.length?(0,n.jsx)("div",{ref:d,className:`overflow-y-auto bg-card border border-border rounded-lg shadow-lv2 ${t}`,children:a.map((e,t)=>{let s=t>0?a[t-1]:null,o="skill"===e.source&&(!s||"skill"!==s.source),d="bot"===e.source&&(!s||"bot"!==s.source),u="builtin"===e.source&&0===t;return(0,n.jsxs)("div",{children:[u&&(0,n.jsx)("div",{className:"px-4 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-muted/40",children:"Commands"}),o&&(0,n.jsx)("div",{className:"px-4 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-muted/40",children:"Skills"}),d&&(0,n.jsx)("div",{className:"px-4 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-muted/40",children:"Bots"}),(0,n.jsxs)("div",{onClick:()=>c(e),className:`px-4 py-2 cursor-pointer ${t===l?"bg-brand/10":"hover:bg-hover"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("span",{className:"font-mono text-sm font-medium text-foreground",children:i+e.name.slice(1)}),(0,n.jsx)("span",{className:"flex-1 text-sm text-muted-foreground truncate",children:"builtin"===e.source?r(`commands.${e.name.slice(1)}`,{defaultValue:e.description}):e.description}),(0,n.jsx)("span",{className:`text-xs px-1.5 py-0.5 rounded ${(e=>{switch(e){case"builtin":return"bg-brand/15 text-brand dark:bg-brand/25 dark:text-teal-11";case"skill":return"bg-purple-9/15 text-purple-11 dark:bg-purple-9/25 dark:text-purple-11";case"bot":return"bg-teal-9/15 text-teal-11 dark:bg-teal-9/25 dark:text-teal-11"}})(e.source)}`,children:(e=>{switch(e){case"builtin":return r("common.builtin");case"skill":return"Skill";case"bot":return"Bot"}})(e.source)})]}),"skill"===e.source&&e.argumentHint&&(0,n.jsx)("div",{className:"font-mono text-xs text-muted-foreground mt-0.5 pl-0 truncate",children:e.argumentHint})]})]},e.name)})}):null}}}]);
|