@surething/cockpit 1.0.270 → 1.0.271

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/.next-prod/BUILD_ID +1 -1
  2. package/.next-prod/app-path-routes-manifest.json +7 -7
  3. package/.next-prod/build-manifest.json +2 -2
  4. package/.next-prod/cockpit-build.json +1 -1
  5. package/.next-prod/prerender-manifest.json +3 -3
  6. package/.next-prod/server/app/_global-error/page_client-reference-manifest.js +1 -1
  7. package/.next-prod/server/app/_global-error.html +1 -1
  8. package/.next-prod/server/app/_global-error.rsc +1 -1
  9. package/.next-prod/server/app/_global-error.segments/_full.segment.rsc +1 -1
  10. package/.next-prod/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  11. package/.next-prod/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  12. package/.next-prod/server/app/_not-found/page_client-reference-manifest.js +1 -1
  13. package/.next-prod/server/app/_not-found.html +2 -2
  14. package/.next-prod/server/app/_not-found.rsc +3 -3
  15. package/.next-prod/server/app/_not-found.segments/_full.segment.rsc +3 -3
  16. package/.next-prod/server/app/_not-found.segments/_index.segment.rsc +3 -3
  17. package/.next-prod/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  18. package/.next-prod/server/app/_not-found.segments/_tree.segment.rsc +2 -2
  19. package/.next-prod/server/app/api/session/[sessionId]/history/route.js +1 -1
  20. package/.next-prod/server/app/api/session-by-path/route.js +1 -1
  21. package/.next-prod/server/app/m/page.js +1 -1
  22. package/.next-prod/server/app/m/page_client-reference-manifest.js +1 -1
  23. package/.next-prod/server/app/page_client-reference-manifest.js +1 -1
  24. package/.next-prod/server/app/project/page_client-reference-manifest.js +1 -1
  25. package/.next-prod/server/app/review/[id]/page_client-reference-manifest.js +1 -1
  26. package/.next-prod/server/app-paths-manifest.json +7 -7
  27. package/.next-prod/server/chunks/516.js +1 -1
  28. package/.next-prod/server/chunks/5750.js +11 -9
  29. package/.next-prod/server/middleware-build-manifest.js +1 -1
  30. package/.next-prod/server/pages/404.html +2 -2
  31. package/.next-prod/server/pages/500.html +1 -1
  32. package/.next-prod/server/server-reference-manifest.json +1 -1
  33. package/.next-prod/static/chunks/{2302-ebf06ca1396efcce.js → 2302-5e8daad0800c3c02.js} +2 -2
  34. package/.next-prod/static/chunks/7184-b6fb5d3287fc073c.js +17 -0
  35. package/.next-prod/static/chunks/app/m/{page-0304eea2c0cf03f6.js → page-241cf89338a0f255.js} +1 -1
  36. package/.next-prod/static/css/ea27ccfe01ce807c.css +1 -0
  37. package/.next-prod/trace +14 -14
  38. package/.next-prod/trace-build +1 -1
  39. package/dist/scheduledTasks.mjs +8 -4
  40. package/package.json +3 -3
  41. package/.next-prod/static/chunks/7184-efdf8613e83ae823.js +0 -15
  42. package/.next-prod/static/css/4e29dd2bca2bb1ac.css +0 -1
  43. /package/.next-prod/static/{cqNAEj5KI8Y8li81B5f7n → BRgWyE48IVXSuUJ4BLHQb}/_buildManifest.js +0 -0
  44. /package/.next-prod/static/{cqNAEj5KI8Y8li81B5f7n → BRgWyE48IVXSuUJ4BLHQb}/_ssgManifest.js +0 -0
@@ -27,6 +27,6 @@ Error: ${t.message}`,exitCode:1,isRunning:!1,pid:void 0}:r))}},[C,m,k,r,e,O,Q,q,
27
27
  `:"";c||T.current.set(t,u),c&&$.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=B.current.get(t);try{await r4({cwd:n.cwd||m,command:d,commandId:t,tabId:r||"",projectCwd:e,env:k,usePty:c,sourceId:H.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)O(t,r.data);else if("exit"===e){let e=Q(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=Q(t);q(t),a(n=>n.map(n=>n.id===t?{...n,output:r+`
28
28
  Error: ${e}`,exitCode:1,isRunning:!1,pid:void 0}:n))}})}catch(r){let e=Q(t);q(t),a(n=>n.map(n=>n.id===t?{...n,output:e+`
29
29
  Error: ${r.message}`,exitCode:1,isRunning:!1,pid:void 0}:n))}},[o,C,m,k,r,e,O,Q,q]),ei=(0,s.useCallback)(async t=>{a(e=>e.filter(e=>e.id!==t)),q(t),r&&await d.t4.runPromise(tU(e,r,t,H.current).pipe(eh.tapError(e=>eh.sync(()=>console.error("Failed to delete command:",e))),eh.orElse(()=>eh.void)))},[e,r,q]),ed=(0,s.useCallback)((t,n,s)=>{var o;let a=t4(t);if(!a)return;let l=a.parse(n);"cwd"in l&&!l.cwd&&(l.cwd=m);let c={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,c]),w(c.id),setTimeout(Z,100),s){let t=M&&M.length>0?[...M]:z.current.map(e=>e.data.id),n=t.indexOf(s);-1!==n?t.splice(n+1,0,c.id):t.push(c.id),L(t),r&&d.t4.runFork(tq(e,r,t,H.current).pipe(eh.orElse(()=>eh.void)))}if(r){let n=a.toHistory(c);d.t4.runFork(tV(e,r,{type:t,id:c.id,timestamp:c.timestamp,...n},H.current).pipe(eh.tapError(e=>eh.sync(()=>console.error(`Failed to save ${t} item:`,e))),eh.orElse(()=>eh.void)))}},[Z,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),u(e=>{let r=new Set(e);return r.delete(t),r}),n){let e=t4(n._type);e?.onClose?.(n)}r&&d.t4.runFork(tU(e,r,t,H.current).pipe(eh.tapError(e=>eh.sync(()=>console.error("Failed to delete plugin item:",e))),eh.orElse(()=>eh.void)))},[l,e,r]);A.current=ed,D.current=eo;let eu=(0,s.useCallback)((t,n)=>{let s,o,a,l;r&&d.t4.runFork((s=e,o=r,a=t,l={sleeping:n},tz("/api/terminal/history",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:s,tabId:o,id:a,fields:l,sourceId:H.current})})).pipe(eh.orElse(()=>eh.void)))},[e,r]),em=(0,s.useCallback)(e=>{u(t=>new Set(t).add(e)),eu(e,!0)},[eu]),ex=(0,s.useCallback)(e=>{u(t=>{let r=new Set(t);return r.delete(e),r}),eu(e,!1)},[eu]),ef=(0,s.useCallback)(async t=>{L(t),r&&await d.t4.runPromise(tq(e,r,t,H.current).pipe(eh.orElse(()=>eh.void)))},[e,r]),ep=(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]);z.current=ep,(0,s.useEffect)(()=>{R.current=o.filter(e=>!e.isRunning&&e.command.trim()).map(e=>e.command)},[o]);let eg=async()=>{let t=await d.t4.runPromise(tW(e,r).pipe(eh.tapError(e=>eh.sync(()=>console.error("Failed to load env:",e))),eh.orElseSucceed(()=>({env:{},home:""}))));y(t.env),N.current=t.home},eb=async()=>{S(await d.t4.runPromise(t_().pipe(eh.tapError(e=>eh.sync(()=>console.error("Failed to load aliases:",e))),eh.orElseSucceed(()=>({})))))},ev=async()=>{if(!r)return;let t=await d.t4.runPromise(tA(tO(e,r)).pipe(eh.map(e=>e.order||[])).pipe(eh.orElseSucceed(()=>[])));t.length>0&&L(t)};return(0,s.useEffect)(()=>{let e={current:!1};return(async()=>{await X(0),e.current||await ee(e)})(),eg(),eb(),ev(),()=>{e.current=!0}},[X,ee]),(0,s.useEffect)(()=>()=>{null!==E.current&&cancelAnimationFrame(E.current)},[]),(0,s.useEffect)(()=>()=>{ne()},[]),{commands:o,pluginItems:l,sleepingBubbles:c,consoleItems:ep,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:B,executeCommandRef:D,executeCommand:eo,interruptCommand:ea,rerunCommand:el,deleteCommand:ei,addPluginItem:ed,closePluginItem:ec,handleBubbleSleep:em,handleBubbleWake:ex,loadHistory:X,scrollToBottom:Z,saveBubbleOrder:ef,sendStdin:r6,resizePty:r8,subscribePtyOutput:V,subscribePtyReset:K,subscribePtyRefresh:J}}({cwd:e,initialShellCwd:t,tabId:r,onCwdChange:a}),[z,H]=(0,s.useState)(null),[W,_]=(0,s.useState)(0),[O,q]=(0,s.useState)(0),[V,U]=(0,s.useState)(!0),[K,G]=(0,s.useState)(!1),[J,Q]=(0,s.useState)(!1),[Z,X]=(0,s.useState)(!1),[Y,ee]=(0,s.useState)(!1),er=(0,s.useRef)(null),en=(0,s.useRef)(null),es=(0,s.useRef)(null),eo=(0,s.useRef)(!1),ea=(0,s.useRef)(null),el=(0,s.useRef)(null),ei=(0,s.useRef)([]);(0,s.useEffect)(()=>{ei.current=c},[c]);let ed=(0,s.useCallback)(()=>{let e=u.current;return!e||e.scrollHeight-e.scrollTop-e.clientHeight<50},[u]),ec=(0,s.useCallback)(()=>{let e=u.current;return!e||e.scrollTop<50},[u]),eu=(0,s.useCallback)(()=>{X(!ec()),ee(!ed())},[ed,ec]),em=(0,s.useCallback)(()=>{en.current?.scrollIntoView({behavior:"smooth"})},[]),ex=async()=>{let t=await d.t4.runPromiseExit(tA(`/api/project-settings?cwd=${encodeURIComponent(e)}`));if("Success"===t._tag){let e=t.value.settings;e?.gridLayout!==void 0&&U(e.gridLayout)}else console.error("Failed to load project settings:",t.cause)};(0,s.useEffect)(()=>{queueMicrotask(()=>ex())},[]);let ef=(0,s.useCallback)(()=>{eo.current=!0},[]),ep=(0,s.useCallback)((e,t)=>{if(!eo.current)return void e.preventDefault();eo.current=!1,ea.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))}},[]),eg=(0,s.useCallback)((e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect="move",el.current=t},[]),eb=(0,s.useCallback)(e=>{e.preventDefault(),e.currentTarget.classList.add("ring-2","ring-brand")},[]),ev=(0,s.useCallback)(e=>{e.currentTarget.classList.remove("ring-2","ring-brand")},[]),ej=(0,s.useCallback)(e=>{e.preventDefault(),e.currentTarget.classList.remove("ring-2","ring-brand")},[]),ew=(0,s.useCallback)(e=>{e.currentTarget.style.opacity="1";let t=ea.current,r=el.current;if(ea.current=null,el.current=null,!t||!r||t===r)return;let n=ei.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,T(a)},[T]),ek=(0,s.useCallback)(e=>{H(t=>t===e?null:e)},[]),ey=(0,s.useCallback)((e,t)=>w("browser",e,t),[w]);(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"m"===e.key&&!e.shiftKey&&!e.altKey&&(e.preventDefault(),m&&ek(m))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[m,ek]),(0,s.useEffect)(()=>{let e=u.current;if(!e)return;let t=new ResizeObserver(([e])=>{q(e.contentRect.height)});return t.observe(e),q(e.clientHeight),()=>t.disconnect()},[u]),(0,s.useEffect)(()=>{let e=u.current;if(e)return z?_(e.clientHeight):(e.style.overflow="",_(0)),()=>{e&&(e.style.overflow="")}},[z,u]),(0,s.useEffect)(()=>{let e=u.current;if(!e||!z||!W)return;let t=requestAnimationFrame(()=>{let t=e.querySelector(`[data-bubble-id="${z}"]`);t&&t.scrollIntoView({block:"start"}),e.style.overflow="hidden"});return()=>cancelAnimationFrame(t)},[z,W,u]),(0,s.useEffect)(()=>{let e=e=>{let t=e.detail?.command;t&&j(t)};return window.addEventListener("execute-terminal-command",e),()=>window.removeEventListener("execute-terminal-command",e)},[j]),(0,s.useEffect)(()=>{let e=e=>{let t=e.detail?.url;t&&w("browser",t)};return window.addEventListener("console-open-browser",e),()=>window.removeEventListener("console-open-browser",e)},[w]);let eN=O>0?Math.floor((O-32-12)/2-41):void 0;return(0,n.jsxs)("div",{ref:er,className:"h-full flex flex-col bg-background relative",children:[(0,n.jsx)("div",{ref:u,onScroll:eu,className:`console-scroll-root flex-1 overflow-y-auto ${z?"":"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:i("console.emptyIntro")}),(0,n.jsx)("ul",{className:"flex flex-col gap-2",children:ny.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:i(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:i(e)},e))]})]},e.key))}),(0,n.jsxs)("button",{type:"button",onClick:()=>j(nj),title:i("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:en}),$&&(0,n.jsx)("div",{className:"flex justify-center mb-4",children:(0,n.jsx)("button",{onClick:()=>R(B+1),disabled:F,className:"px-4 py-2 text-sm text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors disabled:opacity-50",children:F?i("console.loadingMore"):i("console.loadMoreHistory")})}),(0,n.jsx)("div",{className:z?"flex flex-col gap-3":V?"grid grid-cols-2 gap-3":"flex flex-col gap-3",children:c.map(t=>(0,n.jsx)(nt,{item:t,selected:m===t.data.id,maximized:z===t.data.id,initialSleeping:y.has(t.data.id),tabId:r,projectCwd:e,expandedHeight:W,bubbleContentHeight:eN,onDragStart:ep,onDragOver:eg,onDragEnter:eb,onDragLeave:ev,onDrop:ej,onDragEnd:ew,onSelectId:x,onInterruptId:h,onStdin:f,onDeleteCommand:p,onRerun:g,subscribePtyOutput:I,subscribePtyReset:D,subscribePtyRefresh:A,ptySizeRef:b,resizePty:v,onToggleMaximizeId:ek,onTitleMouseDown:ef,onClosePlugin:k,addBrowserItem:ey,onSleep:N,onWake:C},t.data.id))}),(0,n.jsx)("div",{ref:es})]})}),!z&&c.length>0&&(0,n.jsx)(ng,{showTop:Z,showBottom:Y,onScrollTop:em,onScrollBottom:S}),(0,n.jsx)(np,{cwd:e,currentCwd:M,commandHistoryRef:L,gridLayout:V,onGridLayoutChange:t=>{U(t);d.t4.runFork(tH("/api/project-settings",{cwd:e,settings:{gridLayout:t}}).pipe(eh.tapError(e=>eh.sync(()=>console.error("Failed to save project settings:",e))),eh.orElse(()=>eh.void)))},onExecute:j,onAddPluginItem:w,onShowEnvManager:()=>G(!0),onOpenShell:()=>j(nj),onOpenNote:l}),K&&(0,n.jsx)(ns,{cwd:e,tabId:r,onClose:()=>G(!1),onSave:e=>E(e)}),J&&(0,n.jsx)(na,{onClose:()=>Q(!1),onSave:e=>P(e)})]})});var nC=r(83897),nS=r(38987),nM=r(89039),nL=r(76412),nE=r(24058),nP=r(1709),nT=r(98307),n$=r(65153),nR=r(45720);function nB({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,nR.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 nF({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 nI({isOpen:e,onClose:t,messages:r,onSelectMessage:s}){let{t:a}=(0,o.Bd)();if((0,B.E)(t,e),!e)return null;let l=r.filter(e=>"user"===e.role),i=(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:"bg-card rounded-lg shadow-lv3 w-full max-w-2xl max-h-[85vh] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border shrink-0",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground",children:a("userMessages.title")}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-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",{className:"flex-1 overflow-y-auto",children:0===l.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:a("userMessages.noMessages")}):(0,n.jsx)("div",{className:"divide-y divide-border",children:l.map((e,r)=>{let o,a,l,i=(o=e.id.match(/^user-(\d+)/))?parseInt(o[1],10):null,d=i?(a=new Date(i),l=new Date,a.toDateString()===l.toDateString()?a.toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"}):a.toLocaleDateString("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})):"";return(0,n.jsx)("button",{onClick:()=>{s(e.id),t()},className:"w-full px-4 py-3 text-left hover:bg-hover transition-colors",children:(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsxs)("span",{className:"text-xs text-muted-foreground font-mono w-6 shrink-0 pt-0.5",children:[r+1,"."]}),(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)("p",{className:"text-sm text-foreground truncate",children:e.content.replace(/\s+/g," ").trim()})}),d&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground shrink-0 pt-0.5",children:d})]})},e.id)})})})]})});return(0,n.jsx)(f.ZL,{children:i})}var nD=r(67589),nA=r(20917),nz=r(46266);function nH({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,L.oR)(r("imagePreview.copiedImage"),"success")}catch{(0,L.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)(f.ZL,{children:a})}function nW({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)(nH,{image:l,onClose:()=>i(null)})]})}var n_=r(93777),nO=r(59883),nq=r(56204),nV=r(36351),nU=r(49387);function nK({initialValue:e,placeholder:t,onCommit:r,onCancel:o}){let[a,l]=(0,s.useState)(e),i=(0,s.useCallback)(e=>{if("Enter"!==e.key||e.nativeEvent.isComposing)"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),o());else{e.preventDefault(),e.stopPropagation();let t=a.trim();t&&r(t)}},[a,r,o]);return(0,n.jsx)("input",{type:"text",value:a,onChange:e=>l(e.target.value),onKeyDown:i,placeholder:t,autoFocus:!0,className:"w-full min-w-0 px-2 py-1 mb-1 text-xs rounded border border-input bg-background focus:outline-none focus:ring-1 focus:ring-ring"})}function nG({label:e,prompts:t,isAdding:r,onStartAdd:a,onCancelAdd:l,onAdd:i,onUpdate:d,onDelete:c,onReorder:u,onSelect:m,onInsert:x}){let{t:h}=(0,o.Bd)(),[f,p]=(0,s.useState)(null),[g,b]=(0,s.useState)(null),[v,j]=(0,s.useState)(null),w=(0,s.useCallback)(()=>{b(null),j(null)},[]),k=(0,s.useCallback)((e,t)=>{e.preventDefault(),j(t)},[]),y=(0,s.useCallback)(e=>{if(null===g||g===e)return void w();let r=[...t],[n]=r.splice(g,1);r.splice(e,0,n),w(),p(null),u(r)},[g,t,u,w]);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}),(0,n.jsx)("button",{type:"button",onClick:()=>{p(null),a()},className:"p-0.5 text-muted-foreground hover:text-foreground rounded",title:h("chat.addQuickPrompt"),children:(0,n.jsx)(nn.A,{className:"w-3.5 h-3.5"})})]}),r&&(0,n.jsx)(nK,{initialValue:"",placeholder:h("chat.quickPromptPlaceholder"),onCommit:i,onCancel:l}),0===t.length&&!r&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground px-1 py-1",children:h("chat.noQuickPrompts")}),t.map((e,t)=>f===t?(0,n.jsx)(nK,{initialValue:e,placeholder:h("chat.quickPromptPlaceholder"),onCommit:e=>{p(null),d(t,e)},onCancel:()=>p(null)},`edit-${t}`):(0,n.jsxs)("div",{draggable:!0,onDragStart:()=>b(t),onDragOver:e=>k(e,t),onDrop:()=>y(t),onDragEnd:w,className:`flex items-center group min-w-0 rounded transition-opacity ${g===t?"opacity-50":""} ${v===t&&g!==t?"border-t-2 border-brand":""}`,children:[(0,n.jsx)(nO.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.m,{content:e,children:(0,n.jsxs)("button",{type:"button",onClick:()=>m(e),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)(nq.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground"}),(0,n.jsx)("span",{className:"truncate",children:e})]})}),(0,n.jsx)("button",{type:"button",onClick:()=>x(e),className:"p-1 text-muted-foreground hover:text-foreground rounded opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0",title:h("chat.insertQuickPrompt"),children:(0,n.jsx)(nV.A,{className:"w-3 h-3"})}),(0,n.jsx)("button",{type:"button",onClick:()=>p(t),className:"p-1 text-muted-foreground hover:text-foreground rounded opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0",title:h("common.edit"),children:(0,n.jsx)(nU.A,{className:"w-3 h-3"})}),(0,n.jsx)("button",{type:"button",onClick:()=>{p(null),c(t)},className:"p-1 text-muted-foreground hover:text-destructive rounded opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0",title:h("common.delete"),children:(0,n.jsx)(es.A,{className:"w-3 h-3"})})]},t))]})}function nJ({cwd:e,anchorRef:t,onClose:r,onSelect:a,onInsert:l}){let{t:i}=(0,o.Bd)(),[u,m]=(0,s.useState)([]),[x,h]=(0,s.useState)([]),[f,p]=(0,s.useState)(null);(0,s.useEffect)(()=>{let t=!1;return(async()=>{let[r,n]=await Promise.all([d.t4.runPromiseExit((0,c.XO)()),e?d.t4.runPromiseExit((0,c.tf)(e)):null]);!t&&("Success"===r._tag?m(r.value.prompts??[]):console.error("Failed to load global prompts:",r.cause),n&&"Success"===n._tag?h(n.value.prompts??[]):n&&console.error("Failed to load project prompts:",n.cause))})(),()=>{t=!0}},[e]),(0,s.useEffect)(()=>{let e=e=>{let n=t.current;n&&!n.contains(e.target)&&r()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[t,r]);let g=(0,s.useCallback)(async(t,r)=>{let n="global"===t?m:h;n(r);let s=await d.t4.runPromiseExit((0,c.tY)("global"===t?{scope:"global",prompts:r}:{cwd:e,prompts:r}));"Failure"===s._tag?console.error(`Failed to save ${t} prompts:`,s.cause):s.value?.prompts&&n(s.value.prompts)},[e]),b=(0,s.useCallback)(e=>{r(),a(e)},[r,a]),v=(0,s.useCallback)(e=>{r(),l(e)},[r,l]);return(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)(nG,{label:i("chat.globalPrompts"),prompts:u,isAdding:"global"===f,onStartAdd:()=>p("global"),onCancelAdd:()=>p(null),onAdd:e=>{g("global",[...u,e]),p(null)},onUpdate:(e,t)=>g("global",u.map((r,n)=>n===e?t:r)),onDelete:e=>g("global",u.filter((t,r)=>r!==e)),onReorder:e=>g("global",e),onSelect:b,onInsert:v}),e&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsx)(nG,{label:i("chat.projectPrompts"),prompts:x,isAdding:"project"===f,onStartAdd:()=>p("project"),onCancelAdd:()=>p(null),onAdd:e=>{g("project",[...x,e]),p(null)},onUpdate:(e,t)=>g("project",x.map((r,n)=>n===e?t:r)),onDelete:e=>g("project",x.filter((t,r)=>r!==e)),onReorder:e=>g("project",e),onSelect:b,onInsert:v})]})]})}var nQ=r(96625);let nZ=(0,s.memo)(function({onSend:e,disabled:t,cwd:r,engine:a,onShowGitStatus:l,onShowComments:i,onShowUserMessages:d,onOpenNote:c,onCreateScheduledTask:u}){let{t:m}=(0,o.Bd)(),[x,h]=(0,s.useState)(""),[f,p]=(0,s.useState)([]),[g,b]=(0,s.useState)(!1),[v,j]=(0,s.useState)(!1),w=(0,s.useRef)(null),k=(0,s.useRef)(null),y=(0,s.useCallback)(()=>{let e=w.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)(()=>{y()},[x,y]);let N=(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]),C=(0,nQ.n)({value:x,onChange:h,textareaRef:w,extraCommands:N}),S=(0,s.useCallback)(()=>{let r=x.trim();(r||f.length>0)&&!t&&(e(r,f.length>0?f:void 0),h(""),p([]),w.current&&(w.current.style.height="auto"))},[x,f,t,e]),M=(0,s.useCallback)(r=>{t||e(r)},[t,e]),L=(0,s.useCallback)(e=>{h(t=>{let r=t.replace(/\s+$/,"");return r?`${r}
30
- ${e}`:e}),requestAnimationFrame(()=>{let e=w.current;e&&(e.focus(),e.setSelectionRange(e.value.length,e.value.length))})},[]),E=(0,s.useCallback)(e=>{e.nativeEvent.isComposing||!C.handleKeyDown(e)&&("Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),S()))},[C,S]),P=(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(m("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};p(e=>[...e,s])},s.readAsDataURL(r)}}},[m]),T=(0,s.useCallback)(e=>{p(t=>t.filter(t=>t.id!==e))},[]);return(0,n.jsxs)("div",{className:"border-t border-border bg-card relative",children:[(0,n.jsx)(nW,{images:f,onRemove:T,disabled:t}),(0,n.jsx)(nQ.V,{ac:C,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:m("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 text-amber-11 hover:text-amber-10 hover:bg-amber-9/10 active:bg-amber-9/20 active:scale-95 rounded-lg transition-all",title:m("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"})})}),d&&(0,n.jsx)("button",{onClick:d,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95 rounded-lg transition-all",title:m("chat.userMessages"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16M4 18h16"})})}),c&&(0,n.jsx)("button",{onClick:c,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95 rounded-lg transition-all",title:m("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"})})}),u&&(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("button",{onClick:()=>b(!g),className:`p-2 rounded-lg transition-all ${g?"text-brand bg-brand/10":"text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95"}`,title:m("chat.scheduledTasks"),children:(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6v6l4 2"})]})}),g&&(0,n.jsx)(n_.E,{onClose:()=>b(!1),onCreate:u})]}),(0,n.jsxs)("div",{className:"relative",ref:k,children:[(0,n.jsx)("button",{onClick:()=>j(!v),className:`p-2 rounded-lg transition-all ${v?"text-brand bg-brand/10":"text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95"}`,title:m("chat.quickPrompts"),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:"M13 10V3L4 14h7v7l9-11h-7z"})})}),v&&(0,n.jsx)(nJ,{cwd:r,anchorRef:k,onClose:()=>j(!1),onSelect:M,onInsert:L})]}),(0,n.jsx)("textarea",{ref:w,value:x,onChange:e=>{h(e.target.value),C.trackCaret(e.target)},onSelect:e=>C.trackCaret(e.currentTarget),onKeyDown:E,onPaste:P,placeholder:t?m("chat.placeholderDisabled"):m("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 nX=r(57125);function nY(e){return"env"===e?"from env var":"default"===e?"default":null}function n0({currentModel:e,onModelChange:t}){let[r,o]=(0,s.useState)(!1),[a,l]=(0,s.useState)([]),[i,u]=(0,s.useState)(!1),[m,x]=(0,s.useState)(null),[h,p]=(0,s.useState)(!1),[g,b]=(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,B]=(0,s.useState)(""),[F,I]=(0,s.useState)(!1),D=(0,s.useRef)(null),A=(0,s.useRef)(null),z=(0,s.useRef)(null),[H,W]=(0,s.useState)({top:0,left:0}),_=(0,f.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 O=(0,s.useCallback)(async()=>{u(!0),x(null);let e=await d.t4.runPromiseExit((0,c.qD)(()=>p(!0)));if(p(!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")}}u(!1)},[]),q=(0,s.useCallback)(e=>{N(e.baseUrl),S(e.baseUrlSource),L(e.hasKey),P(e.maskedKey),$(e.keySource),B(""),I(!1)},[]),V=(0,s.useCallback)(async()=>{b(!0),k(null);let e=await d.t4.runPromiseExit((0,c.F4)());"Failure"===e._tag?k("Failed to load config"):q(e.value),b(!1)},[q]),U=async()=>{j(!0),k(null);let e=await d.t4.runPromiseExit((0,c.yS)({baseUrl:y}));"Failure"===e._tag?k("Save failed"):(q(e.value),await O()),j(!1)},K=async()=>{let e=R.trim();if(!e)return;j(!0),k(null);let t=await d.t4.runPromiseExit((0,c.yS)({apiKey:e}));"Failure"===t._tag?k("Save failed"):q(t.value),j(!1)},G=async()=>{j(!0),k(null);let e=await d.t4.runPromiseExit((0,c.yS)({apiKey:""}));"Failure"===e._tag?k("Clear failed"):q(e.value),j(!1)},J=e?e.replace(/:latest$/,""):"Select model",Q=nY(C),Z=nY(T),X=r?(0,n.jsx)(f.ZL,{children:(0,n.jsxs)("div",{ref:A,className:`${nX.ys} min-w-[300px]`,style:{top:H.top,left:H.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"}),Q&&!g&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground/70",children:Q})]}),g?(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 ${nX.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 ${nX.$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"}),Z&&M&&!g&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground/70",children:Z})]}),g?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:()=>{I(!0),B(""),setTimeout(()=>z.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:G,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:z,type:"password",value:R,onChange:e=>B(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 ${nX.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 ${nX.$T}`,children:v?"...":"Save"}),M&&(0,n.jsx)("button",{onClick:()=>{I(!1),B("")},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..."]}):m?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-red-11",children:m}):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?nX.yI:"text-foreground hover:bg-hover"}`,children:[(0,n.jsx)(nX.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)(nX.XY,{buttonRef:D,label:J,title:"Configure Ollama",onClick:()=>{if(!r){if(D.current){let e=D.current.getBoundingClientRect(),t=_?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0;W({top:e.bottom+4-n,left:e.left-r})}V(),O()}o(e=>!e)},icon:(0,n.jsx)(nX.eV,{engine:"ollama"}),testId:"ollama-config-picker"}),X]})}let n1={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 n2({engine:e,currentModel:t,onModelChange:r,onHasKeyChange:o}){let a=n1[e],[l,i]=(0,s.useState)(!1),[u,m]=(0,s.useState)(!1),[x,h]=(0,s.useState)(""),[p,g]=(0,s.useState)(""),[b,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,T]=(0,s.useState)(null),[$,R]=(0,s.useState)(null),B=(0,s.useRef)(null),F=(0,s.useRef)(null),I=(0,s.useRef)(null),D=(0,s.useRef)(null);(0,s.useEffect)(()=>()=>{D.current&&clearTimeout(D.current)},[]);let A=(0,s.useRef)(t),z=(0,s.useRef)(r),H=(0,s.useRef)(o);(0,s.useEffect)(()=>{A.current=t,z.current=r,H.current=o}),(0,s.useEffect)(()=>{H.current?.(u)},[u]);let[W,_]=(0,s.useState)({top:0,left:0}),O=(0,f.F2)();(0,s.useEffect)(()=>{let t=!1;return(async()=>{let[r,n]=await Promise.all([d.t4.runPromiseExit((0,c.Hw)(e)),d.t4.runPromiseExit((0,c.td)())]);if(t||"Failure"===r._tag)return;m(r.value.hasKey),h(r.value.maskedKey);let s="Success"===n._tag?n.value?.engines?.[e]:void 0,o=s?.builtinModel;!A.current&&o&&z.current(o)})(),()=>{t=!0}},[e]),(0,s.useEffect)(()=>{if(!l)return;let e=e=>{F.current&&!F.current.contains(e.target)&&B.current&&!B.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),T(null);let[n,s]=await Promise.all([d.t4.runPromiseExit((0,c.Hw)(e)),d.t4.runPromiseExit((0,c.td)())]);if("Failure"===n._tag){C("Failed to load settings"),w(!1);return}m(n.value.hasKey),h(n.value.maskedKey),g(""),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 u=[];if(n.value.hasKey){let t=await d.t4.runPromiseExit((0,c.Fi)(e));"Success"===t._tag?u=t.value.models:T("Failed to load models — check the API key")}E(u);let x=u.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 d.t4.runPromiseExit((0,c.td)()),n=("Success"===r._tag?r.value:{}).engines||{},s={...n,[e]:{...n[e]||{},builtinModel:t}};if("Failure"===(await d.t4.runPromiseExit((0,c.em)({engines:s})))._tag)throw Error("Failed to save settings")},[e]),U=(0,s.useCallback)(async t=>{R(t);let r=await d.t4.runPromiseExit((0,c.td)()),n=("Success"===r._tag?r.value:{}).engines||{};"Failure"===(await d.t4.runPromiseExit((0,c.em)({engines:{...n,[e]:{...n[e]||{},region:t}}})))._tag?C("Failed to save region"):q()},[e,q]),K=async()=>{let t=p.trim();if(!t)return;y(!0),C(null);let r=await d.t4.runPromiseExit((0,c.dQ)(e,t));"Failure"===r._tag?C("Save failed"):(m(r.value.hasKey),h(r.value.maskedKey),g(""),v(!1),q()),y(!1)},G=async()=>{y(!0),C(null);let t=await d.t4.runPromiseExit((0,c.dQ)(e,""));"Failure"===t._tag?C("Clear failed"):(m(t.value.hasKey),h(t.value.maskedKey),g(""),v(!1),E([])),y(!1)},J=async()=>{let t=await d.t4.runPromiseExit((0,c.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)},Q=async e=>{r(e);try{await V(e)}catch{}},Z=u?t||"Select model":"Set API key",X=u?void 0:nX.Aw,Y=t||"",ee=l?(0,n.jsx)(f.ZL,{children:(0,n.jsx)("div",{ref:F,className:`${nX.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"})})})]}),u&&!b?(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:J,"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),g(""),setTimeout(()=>I.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:G,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:I,type:"password",value:p,onChange:e=>g(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 ${nX.Fx}`,autoFocus:!0}),(0,n.jsx)("button",{onClick:K,disabled:k||!p.trim(),className:`text-[11px] px-2 py-1 rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${nX.$T}`,children:k?"Saving...":"Save"}),u&&(0,n.jsx)("button",{onClick:()=>{v(!1),g("")},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.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:u?`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=Y===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:()=>Q(e.id),className:`flex items-center gap-2 px-2 py-1 text-xs rounded transition-colors ${r?nX.yI:"text-foreground hover:bg-hover"}`,children:[(0,n.jsx)(nX.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)(nX.XY,{buttonRef:B,label:Z,labelClassName:X,title:`Configure ${a.label}`,onClick:()=>{if(!l){if(B.current){let e=B.current.getBoundingClientRect(),t=O?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0;_({top:e.bottom+4-n,left:e.left-r})}q()}i(e=>!e)},icon:(0,n.jsx)(nX.eV,{engine:e}),testId:`${e}-config-picker`}),ee]})}let n5="claude-opus-5",n4="gpt-5.6-sol",n3=[{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"}],n6=[{id:"claude-sonnet-5",label:"Claude Sonnet 5",effort:["low","medium","high","xhigh","max","ultrathink"],defaultEffort:"high",context:["200k","1m"],defaultContext:"200k"},{id:"claude-opus-5",label:"Claude Opus 5",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"high",context:["200k","1m"],defaultContext:"1m",fast:!0},{id:"claude-fable-5-1",label:"Claude Fable 5.1",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"high",context:["200k","1m"],defaultContext:"1m"},{id:"claude-fable-5",label:"Claude Fable 5",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"high",context:["200k","1m"],defaultContext:"1m"},{id:"claude-opus-4-8",label:"Claude Opus 4.8",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"high",fast:!0},{id:"claude-opus-4-7",label:"Claude Opus 4.7",effort:["low","medium","high","xhigh","max","ultrathink"],defaultEffort:"xhigh",fast:!0},{id:"claude-opus-4-6",label:"Claude Opus 4.6",effort:["low","medium","high","max","ultrathink"],defaultEffort:"high",context:["200k","1m"],defaultContext:"1m",fast:!0},{id:"claude-sonnet-4-6",label:"Claude Sonnet 4.6",effort:["low","medium","high","max","ultrathink"],defaultEffort:"high",context:["200k","1m"],defaultContext:"200k"},{id:"claude-haiku-4-5",label:"Claude Haiku 4.5",thinking:!0}],n8=[{id:"minimal",label:"Minimal"},{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"}],n9=[{id:"gpt-5.6-sol",label:"GPT-5.6-Sol",reasoning:["low","medium","high","xhigh","max","ultra"],defaultReasoning:"medium"},{id:"gpt-5.6-terra",label:"GPT-5.6-Terra",reasoning:["low","medium","high","xhigh","max","ultra"],defaultReasoning:"medium"},{id:"gpt-5.6-luna",label:"GPT-5.6-Luna",reasoning:["low","medium","high","xhigh","max"],defaultReasoning:"medium"}];function n7(e){return n9.find(t=>t.id===e)?.defaultReasoning??"low"}function se(e,t){let r=n9.find(t=>t.id===e)?.reasoning;return t&&(!r||r.includes(t))?t:n7(e)}function st(e,t){return e.find(e=>e.id===t)?.label??t}function sr(e){return n6.find(t=>t.id===e)?.fast===!0}function sn(e){return n6.find(t=>t.id===e)?.thinking===!0}function ss(e){let t=n6.find(t=>t.id===e);return t?t.defaultEffort:"high"}function so(e,t){let r=n6.find(t=>t.id===e),n=r?.effort;return t&&(!r||n?.includes(t))?t:ss(e)}function sa(e){let t=n6.find(t=>t.id===e);return t?t.defaultContext:"200k"}function sl(e,t){let r=n6.find(t=>t.id===e),n=r?.context;return t&&(!r||n?.includes(t))?t:sa(e)}function si({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?nX.yI:"text-muted-foreground hover:bg-hover hover:text-foreground"}`,children:[(0,n.jsx)("span",{className:"mt-0.5",children:(0,n.jsx)(nX.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 sd({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}),p=(0,f.F2)(),g=()=>{let e=d.current?.getBoundingClientRect();if(!e)return;let t=p?.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=()=>g();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)(nX.XY,{buttonRef:d,label:r,labelMaxWidth:"max-w-[180px]",title:`${e}: ${r}`,onClick:()=>{u||g(),m(e=>!e)},icon:l,testId:i}),u&&(0,n.jsx)(f.ZL,{children:(0,n.jsxs)("div",{ref:c,className:`${nX.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)(si,{value:e.id,selected:t===e.id,label:e.label,defaultValue:e.defaultValue,onSelect:e=>{a(e),m(!1)}},e.id))})]})})]})}function sc(e){let t,r,s=e.engine??"claude",o=e.claudeModel??n5,a=ss(o),l=(t=n6.find(e=>e.id===o)?.effort)?t.map(e=>n3.find(t=>t.id===e)??{id:e,label:e}):[],i=so(o,e.claudeEffort),d=sa(o),c=n6.find(e=>e.id===o)?.context??[],u=sl(o,e.claudeContextWindow),m=e.claudeFastMode??!1,x=e.claudeThinking??!1,h=e.codexModel??n4,f=n7(h),p=(r=n9.find(e=>e.id===h)?.reasoning)?r.map(e=>n8.find(t=>t.id===e)??{id:e,label:e}):n8,g=se(h,e.codexReasoningEffort);return"claude"!==s?(0,n.jsxs)("div",{className:"flex min-w-0 items-center gap-1","data-agent-model-traits":!0,children:[(0,n.jsx)(sd,{title:"Model",selected:h,value:st(n9,h),items:n9.map(e=>({id:e.id,label:e.label,defaultValue:e.id===n4})),onSelect:t=>{e.onCodexModelChange?.(t),e.onCodexReasoningEffortChange?.(n7(t))},icon:(0,n.jsx)(nX.eV,{engine:"codex"}),testId:"codex-model-picker"}),(0,n.jsx)(sd,{title:"Reasoning",selected:g,value:st(n8,g),items:p.map(e=>({...e,defaultValue:e.id===f})),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)(sd,{title:"Model",selected:o,value:st(n6,o),items:n6.map(e=>({id:e.id,label:e.label,defaultValue:e.id===n5})),onSelect:t=>{e.onClaudeModelChange?.(t);let r=ss(t),n=sa(t);r&&e.onClaudeEffortChange?.(r),n&&e.onClaudeContextWindowChange?.(n),sr(t)||e.onClaudeFastModeChange?.(!1),sn(t)||e.onClaudeThinkingChange?.(!1)},icon:(0,n.jsx)(nX.eV,{engine:"claude"}),testId:"claude-model-picker"}),i&&l.length>0&&(0,n.jsx)(sd,{title:"Reasoning",selected:i,value:st(n3,i),items:l.map(e=>({...e,defaultValue:e.id===a})),onSelect:t=>e.onClaudeEffortChange?.(t),testId:"claude-reasoning-picker"}),u&&c.length>0&&(0,n.jsx)(sd,{title:"Context Window",selected:u,value:"1m"===u?"1M":"200K",items:c.map(e=>({id:e,label:"1m"===e?"1M":"200K",defaultValue:e===d})),onSelect:t=>e.onClaudeContextWindowChange?.(t),testId:"claude-context-picker"}),sr(o)&&(0,n.jsx)(sd,{title:"Fast Mode",selected:m?"on":"off",value:m?"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(o)&&(0,n.jsx)(sd,{title:"Thinking",selected:x?"on":"off",value:x?"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"})]})}let su={CNY:"\xa5",USD:"$"};function sm({hasKey:e}){let{t}=(0,o.Bd)(),[r,a]=(0,s.useState)(!1),[l,i]=(0,s.useState)(null),[u,m]=(0,s.useState)(null),x=(0,s.useCallback)(async()=>{a(!0),m(null);let e=await d.t4.runPromiseExit((0,c.he)());"Failure"===e._tag?(i(null),m(t("chat.balanceFailed",{defaultValue:"Query failed — check the API key"}))):i(e.value),a(!1)},[t]),h=l?l.balances.map(e=>`${su[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&&u&&(0,n.jsx)("span",{className:"text-xs text-red-11",children:u}),!r&&!u&&l&&(0,n.jsx)("span",{className:`text-xs font-mono ${f?"text-red-11":nX.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 sx={kimi:"https://www.kimi.com/code/console",glm:"https://bigmodel.cn/coding-plan/personal/usage"};function sh(e){let t=e.remaining??"?",r=e.limit??"?";return`${e.label} ${t}/${r}`}function sf({engine:e,hasKey:t}){let{t:r}=(0,o.Bd)(),[a,l]=(0,s.useState)(!1),[i,u]=(0,s.useState)(null),[m,x]=(0,s.useState)(null),h=(0,s.useCallback)(async()=>{l(!0),x(null);let t=await d.t4.runPromiseExit((0,c.dM)(e));"Failure"===t._tag?(u(null),x(r("chat.quotaFailed",{defaultValue:"Quota unavailable — check the API key"}))):u(t.value),l(!1)},[r,e]),f=i?.windows??[],p=[i?.tier,...f.map(sh)].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&&m&&(0,n.jsx)("span",{className:"text-xs text-red-11",children:m}),!a&&!m&&i&&(0,n.jsx)("span",{className:`text-xs font-mono ${b?"text-red-11":nX.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:sx[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 sp=r(46456);function sg(e){if(0===e.length)return"";let t=[tv.A.t("comments.codeRef"),""],r=e.filter(e=>e.filePath===ey.Un),n=e.filter(e=>e.filePath!==ey.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(tv.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 sb({isOpen:e,onClose:t,cwd:r,onNavigateToComment:a}){let{t:l}=(0,o.Bd)(),i=(0,R.r)(),[c,u]=(0,s.useState)([]),[m,x]=(0,s.useState)(!1),[h,p]=(0,s.useState)(null),[b,v]=(0,s.useState)(!1),[j,w]=(0,s.useState)(!1),k=(0,s.useCallback)(async()=>{if(!r)return;x(!0);let e=await d.t4.runPromiseExit((0,sp.$)(r));"Success"===e._tag?u(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 d.t4.runPromiseExit((0,sp.Tu)(r,e));"Success"===t._tag?(u(t=>t.filter(t=>t.id!==e)),(0,ey.Cm)()):console.error("Failed to delete comment:",t.cause)},N=async e=>{p(e.id);try{let t="";if(e.selectedText)t=e.selectedText;else{let n=await d.t4.runPromiseExit((0,g.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=sg([n]);await navigator.clipboard.writeText(s),(0,L.oR)(l("toast.copiedComment"))}catch(e){console.error("Failed to copy comment:",e)}finally{p(null)}},C=async()=>{if(0!==c.length){v(!0);try{let e=await (0,ey.$3)(r),t=sg(e);await navigator.clipboard.writeText(t),(0,L.oR)(l("toast.copiedAllComments"))}catch(e){console.error("Failed to copy all comments:",e)}finally{v(!1)}}},S=async()=>{if(0!==c.length&&i&&!i.isLoading&&!j){w(!0);try{let e=(await (0,ey.$3)(r)).map(e=>({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0})),n=(0,ey.Gw)(e,"");i.sendMessage(n),await (0,ey.RP)(r),u([]),t()}catch(e){console.error("Failed to send comments to AI:",e)}finally{w(!1)}}},M=c.reduce((e,t)=>(e[t.filePath]||(e[t.filePath]=[]),e[t.filePath].push(t),e),{});if(!e)return null;let E=(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")}),c.length>0&&(0,n.jsx)("button",{onClick:C,disabled:b,className:"p-1 rounded hover:bg-hover text-muted-foreground disabled:opacity-50",title:l("comments.copyAllComments"),children:b?(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===c.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===ey.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:c.length})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[i&&(0,n.jsx)("button",{onClick:S,disabled:0===c.length||i.isLoading||j,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:j?l("comments.submitting"):l("comments.sendToAI")}),(0,n.jsx)("button",{onClick:async()=>{0===c.length||await (0,ey.RP)(r)&&u([])},disabled:0===c.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)(f.ZL,{children:E})}function sv({tabId:e,initialCwd:t,initialSessionId:r,engine:a,onEngineChange:u,ollamaModel:m,onOllamaModelChange:h,deepseekModel:f,onDeepseekModelChange:p,kimiModel:g,onKimiModelChange:b,glmModel:v,onGlmModelChange:j,claudeModel:w,onClaudeModelChange:k,claudeEffort:y,onClaudeEffortChange:N,claudeContextWindow:C,onClaudeContextWindowChange:S,claudeFastMode:M,onClaudeFastModeChange:E,claudeThinking:P,onClaudeThinkingChange:T,codexModel:$,onCodexModelChange:R,codexReasoningEffort:B,onCodexReasoningEffortChange:F,planMode:I,onPlanModeChange:D,noHistory:A,onNoHistoryChange:z,hideHeader:H,hideSidebar:W,isActive:_=!0,refreshSignal:O,onLoadingChange:q,onSessionIdChange:V,onTitleChange:U,onShowGitStatus:K,onOpenNote:G,onCreateScheduledTask:J,onOpenSession:Q,onContentSearch:Z,onShowFileDiff:X,onOpenFileLink:Y,onOpenSessionBrowser:ee,onOpenSettings:et}){let{t:er}=(0,o.Bd)(),en=(0,nC.nH)(),[es,eo]=(0,s.useState)([]),[ea,el]=(0,s.useState)(null),[ei,ed]=(0,s.useState)(!1),[ec,eu]=(0,s.useState)(!1),[em,ex]=(0,s.useState)(!1),[eh,ef]=(0,s.useState)(!1),[ep,eg]=(0,s.useState)(null),[eb,ev]=(0,s.useState)(!1),ej=I??eb,ew=(0,s.useCallback)(e=>{ev(e),D?.(e)},[D]),[ek,ey]=(0,s.useState)(!1),eN=A??ek,eC=(0,s.useCallback)(e=>{ey(e),z?.(e)},[z]),[eS,eM]=(0,s.useState)(!1),eL=(0,s.useRef)(null),eE=(0,s.useRef)(null),eP=(0,s.useCallback)(async e=>{if(!t)return;let r=await d.t4.runPromiseExit((0,c.n_)({cwd:t,sessionId:e}));"Success"===r._tag&&r.value&&"string"==typeof r.value.title?U?.(r.value.title):"Failure"===r._tag&&console.error("Failed to fetch session title:",r.cause)},[t,U]),eT=(0,s.useRef)(null),[e$,eR]=(0,s.useState)(!1),[eB,eF]=(0,s.useState)(null),[eI,eD]=(0,s.useState)(null),eA=(0,s.useRef)(!1);(0,s.useEffect)(()=>{eA.current=e$},[e$]);let{isLoadingHistory:ez,isLoadingMore:eH,hasMoreHistory:eW,loadMoreHistory:e_,loadHistoryByCwdAndSessionId:eO,loadedSessionId:eq,loadedEngine:eV}=(0,nD.m)(es,eo,ea,{cwd:t,initialSessionId:r,onSessionId:el,onTitleChange:U,onTokenUsage:eg,liveRunningRef:eA}),eU=eV??a??void 0,eK=!eU||"claude"===eU,eG="codex"===eU,eJ=w??n5,eQ=so(eJ,y),eZ=sl(eJ,C),eX=$??n4,eY=se(eX,B),e0="deepseek"===eU||"kimi"===eU||"glm"===eU?eU:null,e1="kimi"===e0?g:"glm"===e0?v:f,e2="kimi"===e0?b:"glm"===e0?j:p,e5="ollama"===eU||null!==e0||eK||eG;(0,s.useEffect)(()=>{eV&&a!==eV&&u?.(eV)},[a,eV,u]);let{isLoading:e4,tokenUsage:e3,liveOutputTokens:e6,runningStartedAt:e8,rateLimitInfo:e9,apiRetryInfo:e7,backgroundTasks:te,handleSend:tt,handleStop:tr}=(0,nA.e)(es,eo,{sessionId:ea,cwd:t,engine:eU,planMode:ej,noHistory:eN,ollamaModel:m,engineModel:e1,claudeModel:eJ,claudeEffort:eQ,claudeContextWindow:eZ,claudeFastMode:M,claudeThinking:P,codexModel:eX,codexReasoningEffort:eY,onSessionId:el,onFetchTitle:eP,onRunComplete:()=>eT.current?.()}),tn=(0,s.useCallback)(async(e,r)=>{let n=e.split("\n")[0];if(eK){let t=/^\/plan(?:\s+([\s\S]*))?$/.exec(e.trim());if(t){let e=(t[1]??"").trim();"off"===e.toLowerCase()?(ew(!1),(0,L.oR)(er("chat.planModeOff",{defaultValue:"Plan mode off"}),"info")):""===e?(ew(!0),(0,L.oR)(er("chat.planModeOn",{defaultValue:"Plan mode on"}),"success")):(ew(!0),tt(e,r,{permissionMode:"plan"}));return}}if(n.startsWith("!")&&n.length>1){let s=n.slice(1).trim();if(!s)return void tt(e,r);let o=e.split("\n").slice(1).join("\n").trim(),a=await d.t4.runPromiseExit((0,c.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=er("chat.executedCommand",{command:s,exitInfo:e.exitCode?` (exit code: ${e.exitCode})`:"",output:t});o&&(n+=`
30
+ ${e}`:e}),requestAnimationFrame(()=>{let e=w.current;e&&(e.focus(),e.setSelectionRange(e.value.length,e.value.length))})},[]),E=(0,s.useCallback)(e=>{e.nativeEvent.isComposing||!C.handleKeyDown(e)&&("Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),S()))},[C,S]),P=(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(m("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};p(e=>[...e,s])},s.readAsDataURL(r)}}},[m]),T=(0,s.useCallback)(e=>{p(t=>t.filter(t=>t.id!==e))},[]);return(0,n.jsxs)("div",{className:"border-t border-border bg-card relative",children:[(0,n.jsx)(nW,{images:f,onRemove:T,disabled:t}),(0,n.jsx)(nQ.V,{ac:C,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:m("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 text-amber-11 hover:text-amber-10 hover:bg-amber-9/10 active:bg-amber-9/20 active:scale-95 rounded-lg transition-all",title:m("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"})})}),d&&(0,n.jsx)("button",{onClick:d,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95 rounded-lg transition-all",title:m("chat.userMessages"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16M4 18h16"})})}),c&&(0,n.jsx)("button",{onClick:c,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95 rounded-lg transition-all",title:m("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"})})}),u&&(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("button",{onClick:()=>b(!g),className:`p-2 rounded-lg transition-all ${g?"text-brand bg-brand/10":"text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95"}`,title:m("chat.scheduledTasks"),children:(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6v6l4 2"})]})}),g&&(0,n.jsx)(n_.E,{onClose:()=>b(!1),onCreate:u})]}),(0,n.jsxs)("div",{className:"relative",ref:k,children:[(0,n.jsx)("button",{onClick:()=>j(!v),className:`p-2 rounded-lg transition-all ${v?"text-brand bg-brand/10":"text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95"}`,title:m("chat.quickPrompts"),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:"M13 10V3L4 14h7v7l9-11h-7z"})})}),v&&(0,n.jsx)(nJ,{cwd:r,anchorRef:k,onClose:()=>j(!1),onSelect:M,onInsert:L})]}),(0,n.jsx)("textarea",{ref:w,value:x,onChange:e=>{h(e.target.value),C.trackCaret(e.target)},onSelect:e=>C.trackCaret(e.currentTarget),onKeyDown:E,onPaste:P,placeholder:t?m("chat.placeholderDisabled"):m("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 nX=r(57125);function nY(e){return"env"===e?"from env var":"default"===e?"default":null}function n0({currentModel:e,onModelChange:t}){let[r,o]=(0,s.useState)(!1),[a,l]=(0,s.useState)([]),[i,u]=(0,s.useState)(!1),[m,x]=(0,s.useState)(null),[h,p]=(0,s.useState)(!1),[g,b]=(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,B]=(0,s.useState)(""),[F,I]=(0,s.useState)(!1),D=(0,s.useRef)(null),A=(0,s.useRef)(null),z=(0,s.useRef)(null),[H,W]=(0,s.useState)({top:0,left:0}),_=(0,f.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 O=(0,s.useCallback)(async()=>{u(!0),x(null);let e=await d.t4.runPromiseExit((0,c.qD)(()=>p(!0)));if(p(!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")}}u(!1)},[]),q=(0,s.useCallback)(e=>{N(e.baseUrl),S(e.baseUrlSource),L(e.hasKey),P(e.maskedKey),$(e.keySource),B(""),I(!1)},[]),V=(0,s.useCallback)(async()=>{b(!0),k(null);let e=await d.t4.runPromiseExit((0,c.F4)());"Failure"===e._tag?k("Failed to load config"):q(e.value),b(!1)},[q]),U=async()=>{j(!0),k(null);let e=await d.t4.runPromiseExit((0,c.yS)({baseUrl:y}));"Failure"===e._tag?k("Save failed"):(q(e.value),await O()),j(!1)},K=async()=>{let e=R.trim();if(!e)return;j(!0),k(null);let t=await d.t4.runPromiseExit((0,c.yS)({apiKey:e}));"Failure"===t._tag?k("Save failed"):q(t.value),j(!1)},G=async()=>{j(!0),k(null);let e=await d.t4.runPromiseExit((0,c.yS)({apiKey:""}));"Failure"===e._tag?k("Clear failed"):q(e.value),j(!1)},J=e?e.replace(/:latest$/,""):"Select model",Q=nY(C),Z=nY(T),X=r?(0,n.jsx)(f.ZL,{children:(0,n.jsxs)("div",{ref:A,className:`${nX.ys} min-w-[300px]`,style:{top:H.top,left:H.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"}),Q&&!g&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground/70",children:Q})]}),g?(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 ${nX.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 ${nX.$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"}),Z&&M&&!g&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground/70",children:Z})]}),g?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:()=>{I(!0),B(""),setTimeout(()=>z.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:G,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:z,type:"password",value:R,onChange:e=>B(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 ${nX.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 ${nX.$T}`,children:v?"...":"Save"}),M&&(0,n.jsx)("button",{onClick:()=>{I(!1),B("")},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..."]}):m?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-red-11",children:m}):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?nX.yI:"text-foreground hover:bg-hover"}`,children:[(0,n.jsx)(nX.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)(nX.XY,{buttonRef:D,label:J,title:"Configure Ollama",onClick:()=>{if(!r){if(D.current){let e=D.current.getBoundingClientRect(),t=_?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0;W({top:e.bottom+4-n,left:e.left-r})}V(),O()}o(e=>!e)},icon:(0,n.jsx)(nX.eV,{engine:"ollama"}),testId:"ollama-config-picker"}),X]})}let n1={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 n2({engine:e,currentModel:t,onModelChange:r,onHasKeyChange:o}){let a=n1[e],[l,i]=(0,s.useState)(!1),[u,m]=(0,s.useState)(!1),[x,h]=(0,s.useState)(""),[p,g]=(0,s.useState)(""),[b,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,T]=(0,s.useState)(null),[$,R]=(0,s.useState)(null),B=(0,s.useRef)(null),F=(0,s.useRef)(null),I=(0,s.useRef)(null),D=(0,s.useRef)(null);(0,s.useEffect)(()=>()=>{D.current&&clearTimeout(D.current)},[]);let A=(0,s.useRef)(t),z=(0,s.useRef)(r),H=(0,s.useRef)(o);(0,s.useEffect)(()=>{A.current=t,z.current=r,H.current=o}),(0,s.useEffect)(()=>{H.current?.(u)},[u]);let[W,_]=(0,s.useState)({top:0,left:0}),O=(0,f.F2)();(0,s.useEffect)(()=>{let t=!1;return(async()=>{let[r,n]=await Promise.all([d.t4.runPromiseExit((0,c.Hw)(e)),d.t4.runPromiseExit((0,c.td)())]);if(t||"Failure"===r._tag)return;m(r.value.hasKey),h(r.value.maskedKey);let s="Success"===n._tag?n.value?.engines?.[e]:void 0,o=s?.builtinModel;!A.current&&o&&z.current(o)})(),()=>{t=!0}},[e]),(0,s.useEffect)(()=>{if(!l)return;let e=e=>{F.current&&!F.current.contains(e.target)&&B.current&&!B.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),T(null);let[n,s]=await Promise.all([d.t4.runPromiseExit((0,c.Hw)(e)),d.t4.runPromiseExit((0,c.td)())]);if("Failure"===n._tag){C("Failed to load settings"),w(!1);return}m(n.value.hasKey),h(n.value.maskedKey),g(""),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 u=[];if(n.value.hasKey){let t=await d.t4.runPromiseExit((0,c.Fi)(e));"Success"===t._tag?u=t.value.models:T("Failed to load models — check the API key")}E(u);let x=u.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 d.t4.runPromiseExit((0,c.td)()),n=("Success"===r._tag?r.value:{}).engines||{},s={...n,[e]:{...n[e]||{},builtinModel:t}};if("Failure"===(await d.t4.runPromiseExit((0,c.em)({engines:s})))._tag)throw Error("Failed to save settings")},[e]),U=(0,s.useCallback)(async t=>{R(t);let r=await d.t4.runPromiseExit((0,c.td)()),n=("Success"===r._tag?r.value:{}).engines||{};"Failure"===(await d.t4.runPromiseExit((0,c.em)({engines:{...n,[e]:{...n[e]||{},region:t}}})))._tag?C("Failed to save region"):q()},[e,q]),K=async()=>{let t=p.trim();if(!t)return;y(!0),C(null);let r=await d.t4.runPromiseExit((0,c.dQ)(e,t));"Failure"===r._tag?C("Save failed"):(m(r.value.hasKey),h(r.value.maskedKey),g(""),v(!1),q()),y(!1)},G=async()=>{y(!0),C(null);let t=await d.t4.runPromiseExit((0,c.dQ)(e,""));"Failure"===t._tag?C("Clear failed"):(m(t.value.hasKey),h(t.value.maskedKey),g(""),v(!1),E([])),y(!1)},J=async()=>{let t=await d.t4.runPromiseExit((0,c.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)},Q=async e=>{r(e);try{await V(e)}catch{}},Z=u?t||"Select model":"Set API key",X=u?void 0:nX.Aw,Y=t||"",ee=l?(0,n.jsx)(f.ZL,{children:(0,n.jsx)("div",{ref:F,className:`${nX.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"})})})]}),u&&!b?(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:J,"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),g(""),setTimeout(()=>I.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:G,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:I,type:"password",value:p,onChange:e=>g(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 ${nX.Fx}`,autoFocus:!0}),(0,n.jsx)("button",{onClick:K,disabled:k||!p.trim(),className:`text-[11px] px-2 py-1 rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${nX.$T}`,children:k?"Saving...":"Save"}),u&&(0,n.jsx)("button",{onClick:()=>{v(!1),g("")},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.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:u?`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=Y===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:()=>Q(e.id),className:`flex items-center gap-2 px-2 py-1 text-xs rounded transition-colors ${r?nX.yI:"text-foreground hover:bg-hover"}`,children:[(0,n.jsx)(nX.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)(nX.XY,{buttonRef:B,label:Z,labelClassName:X,title:`Configure ${a.label}`,onClick:()=>{if(!l){if(B.current){let e=B.current.getBoundingClientRect(),t=O?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0;_({top:e.bottom+4-n,left:e.left-r})}q()}i(e=>!e)},icon:(0,n.jsx)(nX.eV,{engine:e}),testId:`${e}-config-picker`}),ee]})}let n5="claude-opus-5",n4="gpt-5.6-sol",n3=[{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"}],n6=[{id:"claude-sonnet-5",label:"Claude Sonnet 5",effort:["low","medium","high","xhigh","max","ultrathink"],defaultEffort:"high",context:["200k","1m"],defaultContext:"200k"},{id:"claude-opus-5",label:"Claude Opus 5",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"high",context:["200k","1m"],defaultContext:"1m",fast:!0},{id:"claude-fable-5-1",label:"Claude Fable 5.1",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"high",context:["200k","1m"],defaultContext:"1m"},{id:"claude-fable-5",label:"Claude Fable 5",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"high",context:["200k","1m"],defaultContext:"1m"},{id:"claude-opus-4-8",label:"Claude Opus 4.8",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"high",fast:!0},{id:"claude-opus-4-7",label:"Claude Opus 4.7",effort:["low","medium","high","xhigh","max","ultrathink"],defaultEffort:"xhigh",fast:!0},{id:"claude-opus-4-6",label:"Claude Opus 4.6",effort:["low","medium","high","max","ultrathink"],defaultEffort:"high",context:["200k","1m"],defaultContext:"1m",fast:!0},{id:"claude-sonnet-4-6",label:"Claude Sonnet 4.6",effort:["low","medium","high","max","ultrathink"],defaultEffort:"high",context:["200k","1m"],defaultContext:"200k"},{id:"claude-haiku-4-5",label:"Claude Haiku 4.5",thinking:!0}],n8=[{id:"minimal",label:"Minimal"},{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"}],n9=[{id:"gpt-6-astra",label:"GPT-6-Astra",reasoning:["low","medium","high","xhigh","max","ultra"],defaultReasoning:"low"},{id:"gpt-5.6-sol",label:"GPT-5.6-Sol",reasoning:["low","medium","high","xhigh","max","ultra"],defaultReasoning:"medium"},{id:"gpt-5.6-terra",label:"GPT-5.6-Terra",reasoning:["low","medium","high","xhigh","max","ultra"],defaultReasoning:"medium"},{id:"gpt-5.6-luna",label:"GPT-5.6-Luna",reasoning:["low","medium","high","xhigh","max"],defaultReasoning:"medium"}];function n7(e){return n9.find(t=>t.id===e)?.defaultReasoning??"low"}function se(e,t){let r=n9.find(t=>t.id===e)?.reasoning;return t&&(!r||r.includes(t))?t:n7(e)}function st(e,t){return e.find(e=>e.id===t)?.label??t}function sr(e){return n6.find(t=>t.id===e)?.fast===!0}function sn(e){return n6.find(t=>t.id===e)?.thinking===!0}function ss(e){let t=n6.find(t=>t.id===e);return t?t.defaultEffort:"high"}function so(e,t){let r=n6.find(t=>t.id===e),n=r?.effort;return t&&(!r||n?.includes(t))?t:ss(e)}function sa(e){let t=n6.find(t=>t.id===e);return t?t.defaultContext:"200k"}function sl(e,t){let r=n6.find(t=>t.id===e),n=r?.context;return t&&(!r||n?.includes(t))?t:sa(e)}function si({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?nX.yI:"text-muted-foreground hover:bg-hover hover:text-foreground"}`,children:[(0,n.jsx)("span",{className:"mt-0.5",children:(0,n.jsx)(nX.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 sd({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}),p=(0,f.F2)(),g=()=>{let e=d.current?.getBoundingClientRect();if(!e)return;let t=p?.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=()=>g();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)(nX.XY,{buttonRef:d,label:r,labelMaxWidth:"max-w-[180px]",title:`${e}: ${r}`,onClick:()=>{u||g(),m(e=>!e)},icon:l,testId:i}),u&&(0,n.jsx)(f.ZL,{children:(0,n.jsxs)("div",{ref:c,className:`${nX.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)(si,{value:e.id,selected:t===e.id,label:e.label,defaultValue:e.defaultValue,onSelect:e=>{a(e),m(!1)}},e.id))})]})})]})}function sc(e){let t,r,s=e.engine??"claude",o=e.claudeModel??n5,a=ss(o),l=(t=n6.find(e=>e.id===o)?.effort)?t.map(e=>n3.find(t=>t.id===e)??{id:e,label:e}):[],i=so(o,e.claudeEffort),d=sa(o),c=n6.find(e=>e.id===o)?.context??[],u=sl(o,e.claudeContextWindow),m=e.claudeFastMode??!1,x=e.claudeThinking??!1,h=e.codexModel??n4,f=n7(h),p=(r=n9.find(e=>e.id===h)?.reasoning)?r.map(e=>n8.find(t=>t.id===e)??{id:e,label:e}):n8,g=se(h,e.codexReasoningEffort);return"claude"!==s?(0,n.jsxs)("div",{className:"flex min-w-0 items-center gap-1","data-agent-model-traits":!0,children:[(0,n.jsx)(sd,{title:"Model",selected:h,value:st(n9,h),items:n9.map(e=>({id:e.id,label:e.label,defaultValue:e.id===n4})),onSelect:t=>{e.onCodexModelChange?.(t),e.onCodexReasoningEffortChange?.(n7(t))},icon:(0,n.jsx)(nX.eV,{engine:"codex"}),testId:"codex-model-picker"}),(0,n.jsx)(sd,{title:"Reasoning",selected:g,value:st(n8,g),items:p.map(e=>({...e,defaultValue:e.id===f})),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)(sd,{title:"Model",selected:o,value:st(n6,o),items:n6.map(e=>({id:e.id,label:e.label,defaultValue:e.id===n5})),onSelect:t=>{e.onClaudeModelChange?.(t);let r=ss(t),n=sa(t);r&&e.onClaudeEffortChange?.(r),n&&e.onClaudeContextWindowChange?.(n),sr(t)||e.onClaudeFastModeChange?.(!1),sn(t)||e.onClaudeThinkingChange?.(!1)},icon:(0,n.jsx)(nX.eV,{engine:"claude"}),testId:"claude-model-picker"}),i&&l.length>0&&(0,n.jsx)(sd,{title:"Reasoning",selected:i,value:st(n3,i),items:l.map(e=>({...e,defaultValue:e.id===a})),onSelect:t=>e.onClaudeEffortChange?.(t),testId:"claude-reasoning-picker"}),u&&c.length>0&&(0,n.jsx)(sd,{title:"Context Window",selected:u,value:"1m"===u?"1M":"200K",items:c.map(e=>({id:e,label:"1m"===e?"1M":"200K",defaultValue:e===d})),onSelect:t=>e.onClaudeContextWindowChange?.(t),testId:"claude-context-picker"}),sr(o)&&(0,n.jsx)(sd,{title:"Fast Mode",selected:m?"on":"off",value:m?"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(o)&&(0,n.jsx)(sd,{title:"Thinking",selected:x?"on":"off",value:x?"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"})]})}let su={CNY:"\xa5",USD:"$"};function sm({hasKey:e}){let{t}=(0,o.Bd)(),[r,a]=(0,s.useState)(!1),[l,i]=(0,s.useState)(null),[u,m]=(0,s.useState)(null),x=(0,s.useCallback)(async()=>{a(!0),m(null);let e=await d.t4.runPromiseExit((0,c.he)());"Failure"===e._tag?(i(null),m(t("chat.balanceFailed",{defaultValue:"Query failed — check the API key"}))):i(e.value),a(!1)},[t]),h=l?l.balances.map(e=>`${su[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&&u&&(0,n.jsx)("span",{className:"text-xs text-red-11",children:u}),!r&&!u&&l&&(0,n.jsx)("span",{className:`text-xs font-mono ${f?"text-red-11":nX.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 sx={kimi:"https://www.kimi.com/code/console",glm:"https://bigmodel.cn/coding-plan/personal/usage"};function sh(e){let t=e.remaining??"?",r=e.limit??"?";return`${e.label} ${t}/${r}`}function sf({engine:e,hasKey:t}){let{t:r}=(0,o.Bd)(),[a,l]=(0,s.useState)(!1),[i,u]=(0,s.useState)(null),[m,x]=(0,s.useState)(null),h=(0,s.useCallback)(async()=>{l(!0),x(null);let t=await d.t4.runPromiseExit((0,c.dM)(e));"Failure"===t._tag?(u(null),x(r("chat.quotaFailed",{defaultValue:"Quota unavailable — check the API key"}))):u(t.value),l(!1)},[r,e]),f=i?.windows??[],p=[i?.tier,...f.map(sh)].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&&m&&(0,n.jsx)("span",{className:"text-xs text-red-11",children:m}),!a&&!m&&i&&(0,n.jsx)("span",{className:`text-xs font-mono ${b?"text-red-11":nX.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:sx[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 sp=r(46456);function sg(e){if(0===e.length)return"";let t=[tv.A.t("comments.codeRef"),""],r=e.filter(e=>e.filePath===ey.Un),n=e.filter(e=>e.filePath!==ey.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(tv.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 sb({isOpen:e,onClose:t,cwd:r,onNavigateToComment:a}){let{t:l}=(0,o.Bd)(),i=(0,R.r)(),[c,u]=(0,s.useState)([]),[m,x]=(0,s.useState)(!1),[h,p]=(0,s.useState)(null),[b,v]=(0,s.useState)(!1),[j,w]=(0,s.useState)(!1),k=(0,s.useCallback)(async()=>{if(!r)return;x(!0);let e=await d.t4.runPromiseExit((0,sp.$)(r));"Success"===e._tag?u(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 d.t4.runPromiseExit((0,sp.Tu)(r,e));"Success"===t._tag?(u(t=>t.filter(t=>t.id!==e)),(0,ey.Cm)()):console.error("Failed to delete comment:",t.cause)},N=async e=>{p(e.id);try{let t="";if(e.selectedText)t=e.selectedText;else{let n=await d.t4.runPromiseExit((0,g.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=sg([n]);await navigator.clipboard.writeText(s),(0,L.oR)(l("toast.copiedComment"))}catch(e){console.error("Failed to copy comment:",e)}finally{p(null)}},C=async()=>{if(0!==c.length){v(!0);try{let e=await (0,ey.$3)(r),t=sg(e);await navigator.clipboard.writeText(t),(0,L.oR)(l("toast.copiedAllComments"))}catch(e){console.error("Failed to copy all comments:",e)}finally{v(!1)}}},S=async()=>{if(0!==c.length&&i&&!i.isLoading&&!j){w(!0);try{let e=(await (0,ey.$3)(r)).map(e=>({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0})),n=(0,ey.Gw)(e,"");i.sendMessage(n),await (0,ey.RP)(r),u([]),t()}catch(e){console.error("Failed to send comments to AI:",e)}finally{w(!1)}}},M=c.reduce((e,t)=>(e[t.filePath]||(e[t.filePath]=[]),e[t.filePath].push(t),e),{});if(!e)return null;let E=(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")}),c.length>0&&(0,n.jsx)("button",{onClick:C,disabled:b,className:"p-1 rounded hover:bg-hover text-muted-foreground disabled:opacity-50",title:l("comments.copyAllComments"),children:b?(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===c.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===ey.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:c.length})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[i&&(0,n.jsx)("button",{onClick:S,disabled:0===c.length||i.isLoading||j,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:j?l("comments.submitting"):l("comments.sendToAI")}),(0,n.jsx)("button",{onClick:async()=>{0===c.length||await (0,ey.RP)(r)&&u([])},disabled:0===c.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)(f.ZL,{children:E})}function sv({tabId:e,initialCwd:t,initialSessionId:r,engine:a,onEngineChange:u,ollamaModel:m,onOllamaModelChange:h,deepseekModel:f,onDeepseekModelChange:p,kimiModel:g,onKimiModelChange:b,glmModel:v,onGlmModelChange:j,claudeModel:w,onClaudeModelChange:k,claudeEffort:y,onClaudeEffortChange:N,claudeContextWindow:C,onClaudeContextWindowChange:S,claudeFastMode:M,onClaudeFastModeChange:E,claudeThinking:P,onClaudeThinkingChange:T,codexModel:$,onCodexModelChange:R,codexReasoningEffort:B,onCodexReasoningEffortChange:F,planMode:I,onPlanModeChange:D,noHistory:A,onNoHistoryChange:z,hideHeader:H,hideSidebar:W,isActive:_=!0,refreshSignal:O,onLoadingChange:q,onSessionIdChange:V,onTitleChange:U,onShowGitStatus:K,onOpenNote:G,onCreateScheduledTask:J,onOpenSession:Q,onContentSearch:Z,onShowFileDiff:X,onOpenFileLink:Y,onOpenSessionBrowser:ee,onOpenSettings:et}){let{t:er}=(0,o.Bd)(),en=(0,nC.nH)(),[es,eo]=(0,s.useState)([]),[ea,el]=(0,s.useState)(null),[ei,ed]=(0,s.useState)(!1),[ec,eu]=(0,s.useState)(!1),[em,ex]=(0,s.useState)(!1),[eh,ef]=(0,s.useState)(!1),[ep,eg]=(0,s.useState)(null),[eb,ev]=(0,s.useState)(!1),ej=I??eb,ew=(0,s.useCallback)(e=>{ev(e),D?.(e)},[D]),[ek,ey]=(0,s.useState)(!1),eN=A??ek,eC=(0,s.useCallback)(e=>{ey(e),z?.(e)},[z]),[eS,eM]=(0,s.useState)(!1),eL=(0,s.useRef)(null),eE=(0,s.useRef)(null),eP=(0,s.useCallback)(async e=>{if(!t)return;let r=await d.t4.runPromiseExit((0,c.n_)({cwd:t,sessionId:e}));"Success"===r._tag&&r.value&&"string"==typeof r.value.title?U?.(r.value.title):"Failure"===r._tag&&console.error("Failed to fetch session title:",r.cause)},[t,U]),eT=(0,s.useRef)(null),[e$,eR]=(0,s.useState)(!1),[eB,eF]=(0,s.useState)(null),[eI,eD]=(0,s.useState)(null),[eA,ez]=(0,s.useState)(nA.R),eH=(0,s.useRef)(!1);(0,s.useEffect)(()=>{eH.current=e$},[e$]);let{isLoadingHistory:eW,isLoadingMore:e_,hasMoreHistory:eO,loadMoreHistory:eq,loadHistoryByCwdAndSessionId:eV,loadedSessionId:eU,loadedEngine:eK}=(0,nD.m)(es,eo,ea,{cwd:t,initialSessionId:r,onSessionId:el,onTitleChange:U,onTokenUsage:eg,liveRunningRef:eH}),eG=eK??a??void 0,eJ=!eG||"claude"===eG,eQ="codex"===eG,eZ=w??n5,eX=so(eZ,y),eY=sl(eZ,C),e0=$??n4,e1=se(e0,B),e2="deepseek"===eG||"kimi"===eG||"glm"===eG?eG:null,e5="kimi"===e2?g:"glm"===e2?v:f,e4="kimi"===e2?b:"glm"===e2?j:p,e3="ollama"===eG||null!==e2||eJ||eQ;(0,s.useEffect)(()=>{eK&&a!==eK&&u?.(eK)},[a,eK,u]);let{isLoading:e6,tokenUsage:e8,liveOutputTokens:e9,runningStartedAt:e7,rateLimitInfo:te,apiRetryInfo:tt,backgroundTasks:tr,handleSend:tn,handleStop:ts}=(0,nA.e)(es,eo,{sessionId:ea,cwd:t,engine:eG,planMode:ej,noHistory:eN,ollamaModel:m,engineModel:e5,claudeModel:eZ,claudeEffort:eX,claudeContextWindow:eY,claudeFastMode:M,claudeThinking:P,codexModel:e0,codexReasoningEffort:e1,onSessionId:el,onFetchTitle:eP,onRunComplete:()=>eT.current?.()}),to=(0,s.useCallback)(async(e,r)=>{let n=e.split("\n")[0];if(eJ){let t=/^\/plan(?:\s+([\s\S]*))?$/.exec(e.trim());if(t){let e=(t[1]??"").trim();"off"===e.toLowerCase()?(ew(!1),(0,L.oR)(er("chat.planModeOff",{defaultValue:"Plan mode off"}),"info")):""===e?(ew(!0),(0,L.oR)(er("chat.planModeOn",{defaultValue:"Plan mode on"}),"success")):(ew(!0),tn(e,r,{permissionMode:"plan"}));return}}if(n.startsWith("!")&&n.length>1){let s=n.slice(1).trim();if(!s)return void tn(e,r);let o=e.split("\n").slice(1).join("\n").trim(),a=await d.t4.runPromiseExit((0,c.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=er("chat.executedCommand",{command:s,exitInfo:e.exitCode?` (exit code: ${e.exitCode})`:"",output:t});o&&(n+=`
31
31
 
32
- ${o}`),tt(n,r)}else tt(er("chat.executedCommandFailed",{command:s,error:a.cause}),r);return}tt(e,r)},[tt,t,er,eK,ew]),ts=(0,s.useCallback)(()=>{ew(!1),tt(er("chat.approvePlanPrompt",{defaultValue:"已批准,按上述计划开始执行。"}),void 0,{permissionMode:null})},[tt,ew,er]),to=eq||ea,ta=_&&!e4&&!!to;(0,n$.u)(to,eo,ta,eU,{onRunningChange:e=>{eA.current=e,eR(e)},onLiveOutputTokens:eF,onRunStartedAt:eD,onComplete:()=>{t&&to&&eO(t,to,!0,10)}}),(0,s.useEffect)(()=>{ta||(eR(!1),eF(null),eD(null))},[ta]),(0,s.useEffect)(()=>{eT.current=()=>{t&&to&&eO(t,to,!0,10)}},[t,to,eO]);let tl=(0,s.useRef)(_);(0,s.useEffect)(()=>{_&&!tl.current&&ea&&t&&!e4&&!e$&&eO(t,ea,!0,10),tl.current=_},[_,ea,t,e4,e$,eO]);let ti=(0,s.useRef)(0);(0,s.useEffect)(()=>{if(!O||O.nonce===ti.current)return;ti.current=O.nonce;let e=ea||eq;!t||!e||O.sessionId!==ea&&O.sessionId!==eq||e4||e$||eO(t,e,!0,10,void 0,!0)},[O,ea,eq,t,e4,e$,eO]);let td=e3||ep,tc=e4?e6:e$?eB:null,tu=e4?e8:e$?eI:null;(0,s.useEffect)(()=>{ea&&V?.(ea)},[ea,V]);let tm=(0,s.useRef)(!1);(0,s.useEffect)(()=>{if(q?.(e4),tm.current&&!e4&&t&&ea){let e;for(let t=es.length-1;t>=0;t--)if("user"===es[t].role&&es[t].content){e=es[t].content.slice(0,100);break}(0,l.F)(i.n.SessionComplete,{cwd:t,sessionId:ea,lastUserMessage:e})}tm.current=e4},[e4,q,t]),(0,s.useEffect)(()=>{_&&en?.setIsLoading(e4)},[e4,_,en]),(0,s.useEffect)(()=>{if(e&&en)return en.registerChat(e=>{eE.current?.(e)},e),()=>{en.unregisterChat(e)}},[e,en]),(0,s.useEffect)(()=>{e&&_&&en&&en.setActiveTab(e)},[e,_,en]),(0,s.useEffect)(()=>{eE.current=tn},[tn]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&ei&&(e4||e$)&&tr()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[ei,e4,e$,tr]);let tx=(0,s.useCallback)(async(e,r)=>{let n=eq??ea;if(!t||!n)return;let s=await d.t4.runPromiseExit((0,c.Zr)(n,{cwd:t,fromMessageUuid:e,scope:r}));if("Success"===s._tag&&s.value.newSessionId){let e=s.value.newSessionId;Q?Q(e,"single"===r?"Excerpt":"Fork"):(0,l.F)(i.n.OpenProject,{cwd:t,sessionId:e})}else"Failure"===s._tag&&(console.error("Fork failed:",s.cause),(0,L.oR)("single"===r?er("toast.excerptFailed",{defaultValue:"Failed to excerpt this turn"}):er("toast.forkFailed",{defaultValue:"Failed to fork session"}),"error"))},[t,eq,ea,Q,er]),th=(0,s.useRef)(tx);th.current=tx;let tf=(0,s.useRef)((e,t)=>th.current(e,t)).current,tp=(0,s.useCallback)(()=>{ex(!0)},[]),tg=(0,s.useCallback)(()=>{ef(!0)},[]),tb=(0,s.useMemo)(()=>{if(J&&t&&e)return r=>{J({...r,cwd:t,tabId:e,sessionId:ea??crypto.randomUUID(),engine:eU,..."ollama"===eU&&m&&{model:m},...e0&&e1&&{model:e1},...eK&&{model:eJ},...eG&&{model:eX}})}},[J,t,e,ea,eU,m,e0,e1,eK,eJ,eG,eX]),tv=e5?(0,n.jsxs)("label",{className:"flex items-center gap-1.5 text-xs cursor-pointer select-none",title:er("chat.noHistoryHint",{defaultValue:"Independent task: each message is sent to the model on its own, with no prior conversation. The transcript above still records everything."}),children:[(0,n.jsx)("input",{type:"checkbox","data-testid":"nohistory-toggle",checked:eN,onChange:e=>eC(e.target.checked),className:"accent-brand"}),(0,n.jsxs)("span",{className:"flex items-center gap-1 text-foreground",children:[(0,n.jsx)(nP.A,{className:"w-3.5 h-3.5"}),er("chat.noHistory",{defaultValue:"Independent task"})]}),(0,n.jsx)("span",{className:"text-muted-foreground",children:er("chat.noHistoryDesc",{defaultValue:"no history sent"})})]}):null;return(0,n.jsxs)("div",{className:`flex ${H&&W?"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:()=>ed(!0),onMouseLeave:()=>ed(!1),children:[!H&&(0,n.jsx)(nB,{cwd:t,sessionId:ea,engine:eU,onOpenProjectSessions:()=>eu(!0),onOpenSessionBrowser:ee,onOpenSettings:et}),(eK||eG)&&(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border bg-card/50",children:[(0,n.jsx)(sc,{engine:eG?"codex":"claude",claudeModel:eJ,onClaudeModelChange:k,claudeEffort:eQ,onClaudeEffortChange:N,claudeContextWindow:eZ,onClaudeContextWindowChange:S,claudeFastMode:M,onClaudeFastModeChange:E,claudeThinking:P,onClaudeThinkingChange:T,codexModel:eX,onCodexModelChange:R,codexReasoningEffort:eY,onCodexReasoningEffortChange:F}),eK&&(0,n.jsxs)("label",{className:"flex items-center gap-1.5 text-xs cursor-pointer select-none",title:er("chat.planModeHint",{defaultValue:"Plan mode: read-only exploration that produces a plan without editing. Uncheck and resend to implement."}),children:[(0,n.jsx)("input",{type:"checkbox","data-testid":"planmode-toggle",checked:ej,onChange:e=>ew(e.target.checked),className:"accent-brand"}),(0,n.jsxs)("span",{className:"flex items-center gap-1 text-foreground",children:[(0,n.jsx)(nT.A,{className:"w-3.5 h-3.5"}),er("chat.planMode",{defaultValue:"Plan mode"})]}),(0,n.jsx)("span",{className:"text-muted-foreground",children:er("chat.planModeDesc",{defaultValue:"read-only \xb7 plan first, no edits"})})]}),tv]}),"ollama"===eU&&(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border bg-card/50",children:[h&&(0,n.jsx)(n0,{currentModel:m,onModelChange:h}),tv]}),e0&&(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border bg-card/50",children:[e2&&(0,n.jsx)(n2,{engine:e0,currentModel:e1,onModelChange:e2,onHasKeyChange:eM}),tv,(0,n.jsx)("div",{className:"ml-auto pl-2",children:"deepseek"===e0?(0,n.jsx)(sm,{hasKey:eS}):(0,n.jsx)(sf,{engine:e0,hasKey:eS})})]}),ez?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("span",{className:"text-muted-foreground",children:er("sessions.loadingHistory")})}):(0,n.jsx)(nz.M,{ref:eL,messages:es,isLoading:e4||e$,liveOutputTokens:tc,runningStartedAt:tu,cwd:t,sessionId:ea,engine:eU,apiRetryInfo:e7,backgroundTasks:te,hasMoreHistory:eW,isLoadingMore:eH,onLoadMore:e_,onFork:tf,isActive:_,onContentSearch:Z,onShowFileDiff:X,onOpenFileLink:Y,onApprovePlan:ts}),td&&(0,n.jsx)(nF,{tokenUsage:td,rateLimitInfo:e9}),(0,n.jsx)(nZ,{onSend:tn,disabled:e4||e$,cwd:t,engine:eU,onShowGitStatus:K,onShowComments:t?tp:void 0,onShowUserMessages:tg,onOpenNote:G,onCreateScheduledTask:tb})]}),!H&&t&&(0,n.jsx)(x,{isOpen:ec,onClose:()=>eu(!1),cwd:t}),t&&(0,n.jsx)(sb,{isOpen:em,onClose:()=>ex(!1),cwd:t}),(0,n.jsx)(nI,{isOpen:eh,onClose:()=>ef(!1),messages:es,onSelectMessage:e=>{eL.current?.scrollToMessage(e)}})]})}function sj({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,claudeContextWindow:v,onClaudeContextWindowChange:j,claudeFastMode:w,onClaudeFastModeChange:k,claudeThinking:y,onClaudeThinkingChange:N,codexModel:C,onCodexModelChange:S,codexReasoningEffort:M,onCodexReasoningEffortChange:L,planMode:E,onPlanModeChange:P,noHistory:T,onNoHistoryChange:$,isActive:R,refreshSignal:B,onStateChange:F,onShowGitStatus:I,onOpenNote:D,onCreateScheduledTask:A,onOpenSession:z,onContentSearch:H,onShowFileDiff:W,onOpenFileLink:_}){let O=(0,s.useCallback)(t=>{F(e,{isLoading:t})},[e,F]),q=(0,s.useCallback)(t=>{F(e,{sessionId:t})},[e,F]),V=(0,s.useCallback)(t=>{F(e,{title:t})},[e,F]),U=(0,s.useCallback)(t=>{a?.(e,t)},[e,a]),K=(0,s.useCallback)(t=>{i?.(e,t)},[e,i]),G=(0,s.useCallback)(t=>{c?.(e,t)},[e,c]),J=(0,s.useCallback)(t=>{m?.(e,t)},[e,m]),Q=(0,s.useCallback)(t=>{h?.(e,t)},[e,h]),Z=(0,s.useCallback)(t=>{p?.(e,t)},[e,p]),X=(0,s.useCallback)(t=>{b?.(e,t)},[e,b]),Y=(0,s.useCallback)(t=>{j?.(e,t)},[e,j]),ee=(0,s.useCallback)(t=>{k?.(e,t)},[e,k]),et=(0,s.useCallback)(t=>{N?.(e,t)},[e,N]),er=(0,s.useCallback)(t=>{S?.(e,t)},[e,S]),en=(0,s.useCallback)(t=>{L?.(e,t)},[e,L]),es=(0,s.useCallback)(t=>{P?.(e,t)},[e,P]),eo=(0,s.useCallback)(t=>{$?.(e,t)},[e,$]);return(0,n.jsx)(sv,{tabId:e,initialCwd:t,initialSessionId:r,engine:o,onEngineChange:U,ollamaModel:l,onOllamaModelChange:K,deepseekModel:d,onDeepseekModelChange:G,kimiModel:u,onKimiModelChange:J,glmModel:x,onGlmModelChange:Q,claudeModel:f,onClaudeModelChange:Z,claudeEffort:g,onClaudeEffortChange:X,claudeContextWindow:v,onClaudeContextWindowChange:Y,claudeFastMode:w,onClaudeFastModeChange:ee,claudeThinking:y,onClaudeThinkingChange:et,codexModel:C,onCodexModelChange:er,codexReasoningEffort:M,onCodexReasoningEffortChange:en,planMode:E,onPlanModeChange:es,noHistory:T,onNoHistoryChange:eo,hideHeader:!0,hideSidebar:!0,isActive:R,refreshSignal:B,onLoadingChange:O,onSessionIdChange:q,onTitleChange:V,onShowGitStatus:I,onOpenNote:D,onCreateScheduledTask:A,onOpenSession:z,onContentSearch:H,onShowFileDiff:W,onOpenFileLink:_})}var sw=r(3292),sk=r(23121),sy=r(88292),sN=r(76900),sC=r(96472);function sS({initialCwd:e,initialSessionId:t,initialView:r}){let{t:a}=(0,o.Bd)(),[l,c]=(0,s.useState)(r??"agent"),{tabs:u,activeTabId:m,activeTab:h,unreadTabs:p,dragTabIndex:g,dragOverTabIndex:b,closeTab:v,closeAllTabs:j,switchTab:w,handleSelectSession:k,handleNewTab:y,handleNewCodexTab:N,handleNewKimiTab:C,handleNewGlmTab:S,handleNewOllamaTab:M,handleNewDeepseekTab:L,handleOpenSession:E,updateTabState:P,updateTabEngine:T,updateTabOllamaModel:$,updateTabDeepseekModel:R,updateTabKimiModel:B,updateTabGlmModel:F,updateTabClaudeModel:I,updateTabClaudeEffort:D,updateTabClaudeContextWindow:A,updateTabClaudeFastMode:z,updateTabClaudeThinking:H,updateTabCodexModel:W,updateTabCodexReasoningEffort:_,updateTabPlanMode:O,updateTabNoHistory:q,handleTabDragStart:V,handleTabDragOver:U,handleTabDrop:K,handleTabDragEnd:G}=(0,nM.useTabState)({initialCwd:e,initialSessionId:t,activeView:l}),{isPinned:J,pinSession:Q,unpinSession:Z}=(0,sw.P)(),{createTask:X}=(0,sk.nS)(),Y=(0,s.useCallback)(e=>{let t=u.find(t=>t.id===e);return!!t?.sessionId&&J(t.sessionId)},[u,J]),ee=(0,s.useCallback)(t=>{let r=u.find(e=>e.id===t);r?.sessionId&&(J(r.sessionId)?Z(r.sessionId):Q(r.sessionId,r.cwd||e||"",r.title))},[u,J,Q,Z,e]),[er,en]=(0,s.useState)(!1),[es,eo]=(0,s.useState)(!1),[ea,el]=(0,s.useState)(!1),[ei,ed]=(0,s.useState)(null),[ec,eu]=(0,s.useState)(!1),[em,ex]=(0,s.useState)("tree"),[ef,ep]=(0,s.useState)(0),[eg,eb]=(0,s.useState)(null),[ev,ej]=(0,s.useState)(0),[ew,ek]=(0,s.useState)(null),[ey,eN]=(0,s.useState)(null),[eC,eS]=(0,s.useState)(null),[eM,eL]=(0,s.useState)();(0,s.useEffect)(()=>{window.parent.postMessage({type:"GET_PROJECT_NUMBER",cwd:e},"*")},[e]),(0,s.useEffect)(()=>{e&&!r&&d.t4.runPromiseExit((0,sN.D0)(e)).then(e=>{if("Success"===e._tag){let t=e.value.settings;t?.activeView&&c(t.activeView)}})},[e,r]);let[eE,eP]=(0,s.useState)(!1),eT=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=e=>{let{active:t}=e.detail;t?(eT.current=l,c("console"),eP(!0)):(eP(!1),eT.current&&"console"!==eT.current&&c(eT.current),eT.current=null)};return window.addEventListener("cockpit-screenshot-state",e),()=>window.removeEventListener("cockpit-screenshot-state",e)},[l]);let e$=(0,s.useCallback)(t=>{c(t),e&&(d.t4.runFork((0,sN.Yn)({cwd:e,settings:{activeView:t}}).pipe(eh.orElse(()=>eh.void))),d.t4.runFork(eh.flatMap(sy.d,r=>r.publish(i.n.ViewChange,{cwd:e,view:t}))))},[e]);(0,s.useEffect)(()=>{let e=()=>e$("console");return window.addEventListener("console-open-browser",e),()=>window.removeEventListener("console-open-browser",e)},[e$]);let eR=(0,s.useCallback)(async()=>{if(!e)return;let t=await d.t4.runPromiseExit((0,sN.b2)(e));if("Success"===t._tag){let r=t.value;if(eu(!!r.isGitRepo),r.isGitRepo&&r.worktrees&&r.worktrees.length>0){let t=r.worktrees.find(t=>t.path===e);t&&ed(t.branch)}}else console.error("Failed to load git info:",t.cause)},[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>eR())},[eR]);let eB=(0,s.useCallback)(e=>{let{data:t}=e;Array.isArray(t)&&t.some(e=>"git"===e.type)&&eR()},[eR]);(0,et.h)({url:`/ws/watch?cwd=${encodeURIComponent(e||"")}`,onMessage:eB,enabled:!!e}),(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&("1"===e.key?(e.preventDefault(),e$("agent")):"2"===e.key?(e.preventDefault(),e$("explorer")):"3"===e.key?(e.preventDefault(),e$("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:u.map(e=>e.sessionId??null)},"*")},[e,u]),(0,s.useEffect)(()=>{let t=t=>{if(t.data?.type==="PROJECT_NUMBER"&&"number"==typeof t.data?.projectNumber)return void eL(t.data.projectNumber);if(t.data?.type==="IFRAME_VISIBILITY"&&"number"==typeof t.data?.projectNumber&&eL(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:u.map(e=>e.sessionId??null)},"*");if(t.data?.type==="SWITCH_SESSION"){let{sessionId:r,switchToAgent:n}=t.data;if(r){k(r),n&&e$("agent");let t=u.find(e=>e.sessionId===r);t&&eS(e=>({sessionId:r,nonce:(e?.nonce??0)+1})),e&&!t?.isLoading&&(d.t4.runFork((0,sC.KJ)(e,r,"normal").pipe(eh.orElse(()=>eh.void))),d.t4.runFork((0,sC.M2)(r).pipe(eh.orElse(()=>eh.void))))}}};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[k,e$,e,u]);let eF=(0,s.useCallback)(()=>{ex("status"),ep(e=>e+1),e$("explorer")},[e$]),eI=(0,s.useCallback)(e=>{eb(e),ej(e=>e+1),e$("explorer")},[e$]),eD=(0,s.useCallback)(e=>{eN(null),eI(e)},[eI]),eA=(0,s.useCallback)(()=>e$("agent"),[e$]),ez=(0,s.useCallback)((e,t,r,n,s,o)=>{eN(a=>{var l;return l={messageId:e,toolCalls:t,cwd:r,sessionId:n,runId:s},!0!==o?l:a?.messageId!==l.messageId?a:{...a,toolCalls:l.toolCalls}}),o||e$("explorer")},[e$]),eH=(0,s.useCallback)(e=>{eN(null),ek({...e,nonce:Date.now()}),e$("explorer")},[e$]);(0,s.useEffect)(()=>{eN(null)},[ef,ev]);let eW=(0,s.useCallback)(()=>{e&&d.t4.runFork(eh.flatMap(sy.d,t=>t.publish(i.n.OpenNote,{cwd:e})))},[e]);return(0,n.jsx)(nC.k_,{children:(0,n.jsx)(tM.fY,{activeView:l,onViewChange:e$,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)(nL.TabManagerTopBar,{initialCwd:e,activeTab:h,isGitRepo:ec,currentBranch:ei,onOpenWorktree:()=>eo(!0),onOpenAliasManager:()=>el(!0),onBranchSwitched:eR}),eE&&(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:"●"}),a("console.screenshotting")]}),e?(0,n.jsxs)(tM.c0,{children:[(0,n.jsx)("div",{className:"w-1/3 h-full flex flex-col overflow-hidden",children:(0,n.jsx)(f.a9,{children:(0,n.jsxs)("div",{className:"w-full h-full flex flex-col",children:[(0,n.jsx)(nE.TabBar,{tabs:u,activeTabId:m,unreadTabs:p,dragTabIndex:g,dragOverTabIndex:b,isPinned:Y,onTogglePin:ee,onSwitchTab:w,onCloseTab:v,onCloseAllTabs:j,onNewTab:y,onNewCodexTab:N,onNewKimiTab:C,onNewGlmTab:S,onNewOllamaTab:M,onNewDeepseekTab:L,onOpenProjectSessions:()=>en(!0),onDragStart:V,onDragOver:U,onDrop:K,onDragEnd:G}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden relative",children:u.map(e=>(0,n.jsx)("div",{className:`h-full ${e.id===m?"block":"hidden"}`,children:(0,n.jsx)(sj,{tabId:e.id,cwd:e.cwd,sessionId:e.sessionId,engine:e.engine,onEngineChange:T,ollamaModel:e.ollamaModel,onOllamaModelChange:$,deepseekModel:e.deepseekModel,onDeepseekModelChange:R,kimiModel:e.kimiModel,onKimiModelChange:B,glmModel:e.glmModel,onGlmModelChange:F,claudeModel:e.claudeModel,onClaudeModelChange:I,claudeEffort:e.claudeEffort,onClaudeEffortChange:D,claudeContextWindow:e.claudeContextWindow,onClaudeContextWindowChange:A,claudeFastMode:e.claudeFastMode,onClaudeFastModeChange:z,claudeThinking:e.claudeThinking,onClaudeThinkingChange:H,codexModel:e.codexModel,onCodexModelChange:W,codexReasoningEffort:e.codexReasoningEffort,onCodexReasoningEffortChange:_,planMode:e.planMode,onPlanModeChange:O,noHistory:e.noHistory,onNoHistoryChange:q,isActive:e.id===m&&"agent"===l,refreshSignal:eC,onStateChange:P,onShowGitStatus:eF,onContentSearch:eI,onShowFileDiff:ez,onOpenFileLink:eH,onOpenNote:eW,onCreateScheduledTask:X,onOpenSession:E})},e.id))})]})})}),(0,n.jsx)("div",{className:"w-1/3 h-full overflow-hidden relative",children:(0,n.jsxs)(f.a9,{children:[(0,n.jsx)(tL,{onClose:eA,cwd:e,initialTab:em,tabSwitchTrigger:ef,initialSearchQuery:eg,searchQueryTrigger:ev,fileOpenRequest:ew}),ey&&(0,n.jsx)("div",{className:"absolute inset-0 z-20 flex bg-scrim p-[4vmin]",onClick:()=>eN(null),children:(0,n.jsx)(nS.e$,{toolCalls:ey.toolCalls,cwd:ey.cwd,sessionId:ey.sessionId,runId:ey.runId,onClose:()=>eN(null),onContentSearch:eD},ey.messageId)})]})}),(0,n.jsx)("div",{className:"w-1/3 h-full overflow-hidden",children:(0,n.jsx)(f.a9,{children:(0,n.jsx)(nN,{cwd:e,tabId:"default",onOpenNote:eW})})})]}):(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,n.jsx)(nE.TabBar,{tabs:u,activeTabId:m,unreadTabs:p,dragTabIndex:g,dragOverTabIndex:b,isPinned:Y,onTogglePin:ee,onSwitchTab:w,onCloseTab:v,onCloseAllTabs:j,onNewTab:y,onNewCodexTab:N,onNewKimiTab:C,onNewGlmTab:S,onNewDeepseekTab:L,onDragStart:V,onDragOver:U,onDrop:K,onDragEnd:G}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden relative",children:u.map(e=>(0,n.jsx)("div",{className:`h-full ${e.id===m?"block":"hidden"}`,children:(0,n.jsx)(sj,{tabId:e.id,cwd:e.cwd,sessionId:e.sessionId,engine:e.engine,onEngineChange:T,ollamaModel:e.ollamaModel,onOllamaModelChange:$,deepseekModel:e.deepseekModel,onDeepseekModelChange:R,kimiModel:e.kimiModel,onKimiModelChange:B,glmModel:e.glmModel,onGlmModelChange:F,claudeModel:e.claudeModel,onClaudeModelChange:I,claudeEffort:e.claudeEffort,onClaudeEffortChange:D,claudeContextWindow:e.claudeContextWindow,onClaudeContextWindowChange:A,claudeFastMode:e.claudeFastMode,onClaudeFastModeChange:z,claudeThinking:e.claudeThinking,onClaudeThinkingChange:H,codexModel:e.codexModel,onCodexModelChange:W,codexReasoningEffort:e.codexReasoningEffort,onCodexReasoningEffortChange:_,planMode:e.planMode,onPlanModeChange:O,noHistory:e.noHistory,onNoHistoryChange:q,isActive:e.id===m,refreshSignal:eC,onStateChange:P,onCreateScheduledTask:X,onOpenSession:E})},e.id))})]})]}),e&&(0,n.jsx)(x,{isOpen:er,onClose:()=>en(!1),cwd:e,onSelectSession:k,projectNumber:eM,openSessionIds:u.map(e=>e.sessionId)}),e&&ec&&(0,n.jsx)(tE,{isOpen:es,onClose:()=>eo(!1),cwd:e}),ea&&(0,n.jsx)(na,{onClose:()=>el(!1),onSave:()=>el(!1)})]})})})}},92689:(e,t,r)=>{r.d(t,{S:()=>o});var n=r(95155),s=r(57125);function o({engine:e,tooltip:t,size:r="md"}){let a=e||"claude";return(0,s.ch)(a)?(0,n.jsx)("span",{className:"shrink-0 inline-flex items-center","data-tooltip":t??s.H[a],children:(0,n.jsx)(s.eV,{engine:a,className:"sm"===r?"h-3 w-3":"h-3.5 w-3.5"})}):(0,n.jsx)("span",{className:"shrink-0 px-1 py-0.5 text-[10px] leading-none font-medium rounded bg-muted text-muted-foreground","data-tooltip":t??a,children:a})}},93777:(e,t,r)=>{r.d(t,{E:()=>c});var n=r(95155),s=r(12115),o=r(79114),a=r(69809),l=r(12786),i=r(96625);let d={once:[{labelKey:"scheduledTasks.5minLater",value:5},{labelKey:"scheduledTasks.15minLater",value:15},{labelKey:"scheduledTasks.30minLater",value:30},{labelKey:"scheduledTasks.1hourLater",value:60}],interval:[{labelKey:"scheduledTasks.every15min",value:15},{labelKey:"scheduledTasks.every30min",value:30},{labelKey:"scheduledTasks.every1hour",value:60},{labelKey:"scheduledTasks.every2hours",value:120}],cron:[{labelKey:"scheduledTasks.daily9am",value:"0 9 * * *"},{labelKey:"scheduledTasks.daily6pm",value:"0 18 * * *"},{labelKey:"scheduledTasks.weeklyMon9am",value:"0 9 * * 1"},{labelKey:"scheduledTasks.monthly1st9am",value:"0 9 1 * *"}]};function c({onClose:e,onCreate:t,editTask:r,onUpdate:u}){let{t:m}=(0,o.Bd)(),x=!!r,[h,f]=(0,s.useState)(r?.type||"once"),[p,g]=(0,s.useState)(r?.message||""),[b,v]=(0,s.useState)(r?.taskFile?"file":"message"),[j,w]=(0,s.useState)(r?.taskFile||""),[k,y]=(0,s.useState)(r?String(r.delayMinutes||r.intervalMinutes||""):""),[N,C]=(0,s.useState)(r?.cron||""),[S,M]=(0,s.useState)(r?.activeFrom||"09:00"),[L,E]=(0,s.useState)(r?.activeTo||"18:00"),[P,T]=(0,s.useState)(!!(r?.activeFrom&&r?.activeTo)),[$,R]=(0,s.useState)(null),B=(0,s.useRef)(null),F=(0,s.useRef)(null),I=(0,i.n)({value:p,onChange:g,textareaRef:F});(0,s.useEffect)(()=>{F.current?.focus()},[]),(0,s.useEffect)(()=>{let t=t=>{B.current&&!B.current.contains(t.target)&&e()};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[e]);let D=(0,s.useCallback)(()=>{let n="file"===b,s=n?{message:"",taskFile:j.trim()}:{message:p.trim(),taskFile:""};if(n?!s.taskFile:!s.message)return;let o=null;if("once"===h){let e=$||parseInt(k,10);if(!e||e<=0)return;o={...s,type:"once",delayMinutes:e}}else if("interval"===h){let e=$||parseInt(k,10);if(!e||e<=0)return;o={...s,type:"interval",intervalMinutes:e,...P?{activeFrom:S,activeTo:L}:{}}}else if("cron"===h){let e=$||N.trim();if(!e)return;o={...s,type:"cron",cron:e}}o&&(x&&r&&u?u(r.id,o):t(o),e())},[p,b,j,h,$,k,N,P,S,L,t,e,x,r,u]);return(0,n.jsxs)("div",{ref:B,className:`w-[28rem] max-w-[calc(100vw-1.5rem)] bg-popover border border-border rounded-lg shadow-lv2 z-50 ${x?"":"absolute bottom-full left-0 mb-2"}`,onKeyDown:t=>{"Escape"===t.key?e():"Enter"===t.key&&(t.metaKey||t.ctrlKey)&&D()},children:[(0,n.jsx)("div",{className:"px-3 py-2 border-b border-border bg-muted/50 rounded-t-lg",children:(0,n.jsx)("span",{className:"text-sm font-medium",children:x?m("scheduledTasks.editTask"):m("scheduledTasks.createTask")})}),(0,n.jsxs)("div",{className:"p-4 space-y-4 max-h-[min(52rem,calc(100vh-3rem))] overflow-y-auto",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"flex gap-1 mb-1.5",children:["message","file"].map(e=>(0,n.jsx)("button",{onClick:()=>v(e),className:`px-2 py-1 text-xs rounded transition-colors ${b===e?"bg-brand text-white":"bg-muted text-muted-foreground hover:text-foreground"}`,children:"message"===e?m("scheduledTasks.sendMessage"):m("scheduledTasks.taskFile")},e))}),"message"===b?(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("textarea",{ref:F,value:p,onChange:e=>{g(e.target.value),I.trackCaret(e.target)},onSelect:e=>I.trackCaret(e.currentTarget),onKeyDown:e=>{I.handleKeyDown(e)},placeholder:m("scheduledTasks.messagePlaceholder"),rows:5,className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring resize-y min-h-[6rem]"}),(0,n.jsx)(i.V,{ac:I,className:"absolute top-full left-0 right-0 mt-1 max-h-48 z-10"})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("input",{type:"text",value:j,onChange:e=>w(e.target.value),placeholder:m("scheduledTasks.taskFilePlaceholder"),className:"w-full px-2 py-1.5 text-sm font-mono border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring"}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:m("scheduledTasks.taskFileHint")})]})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:m("scheduledTasks.type")}),(0,n.jsx)("div",{className:"flex gap-1",children:["once","interval","cron"].map(e=>(0,n.jsx)("button",{onClick:()=>{f(e),R(null),y(""),C("")},className:`flex-1 px-2 py-1 text-xs rounded transition-colors ${h===e?"bg-brand text-white":"bg-muted text-muted-foreground hover:text-foreground"}`,children:"once"===e?m("scheduledTasks.once"):"interval"===e?m("scheduledTasks.interval"):"Cron"},e))})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:m("scheduledTasks.quickSelect")}),(0,n.jsx)("div",{className:"grid grid-cols-2 gap-1",children:d[h].map(e=>(0,n.jsx)("button",{onClick:()=>{R(e.value),"cron"===h?C(String(e.value)):y(String(e.value))},className:`px-2 py-1 text-xs rounded border transition-colors ${$===e.value?"border-brand bg-brand/10 text-brand":"border-border text-muted-foreground hover:text-foreground hover:border-foreground/30"}`,children:m(e.labelKey)},e.labelKey))})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:"cron"===h?m("scheduledTasks.customCron"):m("scheduledTasks.customMinutes")}),"cron"===h?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("input",{type:"text",value:N,onChange:e=>{C(e.target.value),R(null)},placeholder:m("scheduledTasks.cronPlaceholder"),className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring font-mono"}),N.trim()&&(0,n.jsx)("div",{className:"mt-1 text-xs text-muted-foreground",children:function(e){let t=a.A.t,r=e.trim().split(/\s+/);if(5!==r.length)return null;let[n,s,o,l,i]=r,d={0:t("cron.dowSun"),1:t("cron.dowMon"),2:t("cron.dowTue"),3:t("cron.dowWed"),4:t("cron.dowThu"),5:t("cron.dowFri"),6:t("cron.dowSat")},c={1:`1${t("cron.monthPrefix")}`,2:`2${t("cron.monthPrefix")}`,3:`3${t("cron.monthPrefix")}`,4:`4${t("cron.monthPrefix")}`,5:`5${t("cron.monthPrefix")}`,6:`6${t("cron.monthPrefix")}`,7:`7${t("cron.monthPrefix")}`,8:`8${t("cron.monthPrefix")}`,9:`9${t("cron.monthPrefix")}`,10:`10${t("cron.monthPrefix")}`,11:`11${t("cron.monthPrefix")}`,12:`12${t("cron.monthPrefix")}`};try{let e="";if(n.includes("/")||s.includes("/")){if("*"===s&&n.includes("/"))return t("cron.everyNMinutes",{n:n.split("/")[1]});if("0"===n&&s.includes("/"))return t("cron.everyNHours",{n:s.split("/")[1]});return null}let r=parseInt(s,10),a=parseInt(n,10);if(isNaN(r)&&"*"!==s||isNaN(a)&&"*"!==n)return null;e="*"===s&&"*"===n?t("cron.everyMinute"):"*"===s?t("cron.everyHourAtMin",{m:a}):"*"===n?t("cron.hourlyEveryMin",{h:r}):`${String(r).padStart(2,"0")}:${String(a).padStart(2,"0")}`;let u=[];if("*"!==l){let e=l.split(",").map(e=>c[e]||`${e}${t("cron.monthPrefix")}`);u.push(e.join(", "))}if("*"!==o)if(o.includes("-")){let[e,r]=o.split("-");u.push(t("cron.dayRange",{a:e,b:r}))}else o.includes(",")?u.push(o.split(",").map(e=>`${e}${t("cron.dayOfMonth")}`).join(", ")):u.push(`${o}${t("cron.dayOfMonth")}`);if("*"!==i)if("1-5"===i)u.push(t("cron.weekdays"));else if("0,6"===i||"6,0"===i)u.push(t("cron.weekends"));else{let e=i.split(",").map(e=>{if(e.includes("-")){let[r,n]=e.split("-");return t("cron.weekdayRange",{a:d[r]||r,b:d[n]||n})}return`${t("cron.weekdayPrefix")}${d[e]||e}`});u.push(e.join(", "))}if(0===u.length&&"*"===o&&"*"===l&&"*"===i)return t("cron.daily",{time:e});return`${u.join(" ")} ${e}`}catch{return null}}(N.trim())||(0,n.jsx)("span",{className:"text-destructive",children:m("scheduledTasks.cronFormat")})})]}):(0,n.jsx)("input",{type:"number",value:k,onChange:e=>{y(e.target.value),R(null)},placeholder:m("scheduledTasks.minutesPlaceholder"),min:1,className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring"})]}),"interval"===h&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("label",{className:"flex items-center gap-2 text-xs text-muted-foreground mb-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:P,onChange:e=>T(e.target.checked),className:"rounded border-border"}),m("scheduledTasks.limitTimeRange")]}),P&&(0,n.jsxs)("div",{className:"flex items-center gap-2 mt-1",children:[(0,n.jsx)("input",{type:"time",value:S,onChange:e=>M(e.target.value),className:"flex-1 px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring"}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:m("scheduledTasks.to")}),(0,n.jsx)("input",{type:"time",value:L,onChange:e=>E(e.target.value),className:"flex-1 px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring"})]})]}),(0,n.jsx)("button",{onClick:D,disabled:!(("file"===b?!!j.trim():!!p.trim())&&("once"===h||"interval"===h?!!($||k&&parseInt(k,10)>0):"cron"===h&&!!($||N.trim()))),className:"w-full py-1.5 text-sm font-medium rounded bg-brand text-white hover:bg-brand/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:x?m("scheduledTasks.saveBtn",{modKey:(0,l.Mu)()}):m("scheduledTasks.createBtn",{modKey:(0,l.Mu)()})})]})]})}},96472:(e,t,r)=>{r.d(t,{KJ:()=>l,M2:()=>i,ej:()=>a,n8:()=>o});var n=r(49433),s=r(82680);let o=e=>n.tryPromise({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.tryPromise({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.tryPromise({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})});if(!n.ok)throw Error(`HTTP ${n.status}`)},catch:e=>new s.uV({message:"updateSessionStatus failed",cause:e})}),i=e=>n.tryPromise({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:()=>c,n:()=>d});var n=r(95155),s=r(12115),o=r(79114),a=r(58250),l=r(86957),i=r(83448);function d({value:e,onChange:t,textareaRef:r,extraCommands:n}){let[o,c]=(0,s.useState)(e.length),[u,m]=(0,s.useState)([]),[x,h]=(0,s.useState)([]),[f,p]=(0,s.useState)(0),[g,b]=(0,s.useState)(()=>e.length>0),v=(0,s.useRef)(null);(0,s.useEffect)(()=>{l.t4.runPromiseExit((0,i.M5)()).then(e=>{"Success"===e._tag?m(e.value):console.error("Failed to load commands:",e.cause)})},[]);let j=(0,s.useCallback)(async()=>{let e=await l.t4.runPromiseExit((0,i.l1)());if("Success"===e._tag){let t=e.value.skills??e.value;h((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)(()=>(j(),(0,a.U)(j)),[j]);let w=(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]),k=(0,s.useMemo)(()=>{let e=w.text.match(/^\s*([/@])([a-zA-Z0-9-]*)$/);return e?{marker:e[1],verb:e[2].toLowerCase()}:null},[w.text]),y=(0,s.useMemo)(()=>{if(!k)return[];let{verb:e}=k,t=t=>t.name.slice(1).toLowerCase().startsWith(e);return[...(n??[]).filter(t),...u.filter(t),...x.filter(t)]},[k,n,u,x]),N=!g&&!!k&&y.length>0,C=(0,s.useRef)(e);(0,s.useLayoutEffect)(()=>{C.current!==e&&(queueMicrotask(()=>p(0)),g&&queueMicrotask(()=>b(!1)),C.current=e)},[e,g]),(0,s.useLayoutEffect)(()=>{if(N&&v.current){let e=v.current.children[f];e&&e.scrollIntoView({block:"nearest"})}},[f,N]);let S=(0,s.useCallback)(e=>{c(e.selectionStart??0)},[]),M=(0,s.useCallback)(n=>{let s=k?.marker??"/",o=`${s}${n.name.slice(1)} `,a=e.slice(0,w.start),l=e.slice(w.end),i=a.length+o.length;t(a+o+l),c(i),requestAnimationFrame(()=>{let e=r.current;e&&(e.focus(),e.setSelectionRange(i,i))})},[e,w,k,t,r]),L=(0,s.useCallback)(e=>{if(e.nativeEvent.isComposing||!N||0===y.length)return!1;let t=()=>{e.preventDefault(),e.stopPropagation()};return"ArrowDown"===e.key?(t(),p(e=>(e+1)%y.length),!0):"ArrowUp"===e.key?(t(),p(e=>(e-1+y.length)%y.length),!0):"Enter"===e.key||"Tab"===e.key?(t(),M(y[f]),!0):"Escape"===e.key&&(t(),b(!0),!0)},[N,y,f,M]);return{isOpen:N,items:y,selectedIndex:f,marker:k?.marker??"/",listRef:v,selectCommand:M,handleKeyDown:L,trackCaret:S}}function c({ac:e,className:t=""}){let{t:r}=(0,o.Bd)(),{isOpen:s,items:a,selectedIndex:l,marker:i,listRef:d,selectCommand:u}=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="skill"!==e.source&&0===t;return(0,n.jsxs)("div",{children:[d&&(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"}),(0,n.jsxs)("div",{onClick:()=>u(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"}})(e.source)}`,children:(e=>{switch(e){case"builtin":return r("common.builtin");case"skill":return"Skill"}})(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}}}]);
32
+ ${o}`),tn(n,r)}else tn(er("chat.executedCommandFailed",{command:s,error:a.cause}),r);return}tn(e,r)},[tn,t,er,eJ,ew]),ta=(0,s.useCallback)(()=>{ew(!1),tn(er("chat.approvePlanPrompt",{defaultValue:"已批准,按上述计划开始执行。"}),void 0,{permissionMode:null})},[tn,ew,er]),tl=eU||ea,ti=_&&!e6&&!!tl;(0,n$.u)(tl,eo,ti,eG,{onRunningChange:e=>{eH.current=e,eR(e)},onLiveOutputTokens:eF,onRunStartedAt:eD,onBackgroundTasks:e=>ez(e.length?e:nA.R),onComplete:()=>{t&&tl&&eV(t,tl,!0,10)}}),(0,s.useEffect)(()=>{ti||(eR(!1),eF(null),eD(null),ez(nA.R))},[ti]),(0,s.useEffect)(()=>{eT.current=()=>{t&&tl&&eV(t,tl,!0,10)}},[t,tl,eV]);let td=(0,s.useRef)(_);(0,s.useEffect)(()=>{_&&!td.current&&ea&&t&&!e6&&!e$&&eV(t,ea,!0,10),td.current=_},[_,ea,t,e6,e$,eV]);let tc=(0,s.useRef)(0);(0,s.useEffect)(()=>{if(!O||O.nonce===tc.current)return;tc.current=O.nonce;let e=ea||eU;!t||!e||O.sessionId!==ea&&O.sessionId!==eU||e6||e$||eV(t,e,!0,10,void 0,!0)},[O,ea,eU,t,e6,e$,eV]);let tu=e8||ep,tm=e6?e9:e$?eB:null,tx=e6?e7:e$?eI:null,th=e6?tr:e$?eA:nA.R;(0,s.useEffect)(()=>{ea&&V?.(ea)},[ea,V]);let tf=(0,s.useRef)(!1);(0,s.useEffect)(()=>{if(q?.(e6),tf.current&&!e6&&t&&ea){let e;for(let t=es.length-1;t>=0;t--)if("user"===es[t].role&&es[t].content){e=es[t].content.slice(0,100);break}(0,l.F)(i.n.SessionComplete,{cwd:t,sessionId:ea,lastUserMessage:e})}tf.current=e6},[e6,q,t]),(0,s.useEffect)(()=>{_&&en?.setIsLoading(e6)},[e6,_,en]),(0,s.useEffect)(()=>{if(e&&en)return en.registerChat(e=>{eE.current?.(e)},e),()=>{en.unregisterChat(e)}},[e,en]),(0,s.useEffect)(()=>{e&&_&&en&&en.setActiveTab(e)},[e,_,en]),(0,s.useEffect)(()=>{eE.current=to},[to]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&ei&&(e6||e$)&&ts()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[ei,e6,e$,ts]);let tp=(0,s.useCallback)(async(e,r)=>{let n=eU??ea;if(!t||!n)return;let s=await d.t4.runPromiseExit((0,c.Zr)(n,{cwd:t,fromMessageUuid:e,scope:r}));if("Success"===s._tag&&s.value.newSessionId){let e=s.value.newSessionId;Q?Q(e,"single"===r?"Excerpt":"Fork"):(0,l.F)(i.n.OpenProject,{cwd:t,sessionId:e})}else"Failure"===s._tag&&(console.error("Fork failed:",s.cause),(0,L.oR)("single"===r?er("toast.excerptFailed",{defaultValue:"Failed to excerpt this turn"}):er("toast.forkFailed",{defaultValue:"Failed to fork session"}),"error"))},[t,eU,ea,Q,er]),tg=(0,s.useRef)(tp);tg.current=tp;let tb=(0,s.useRef)((e,t)=>tg.current(e,t)).current,tv=(0,s.useCallback)(()=>{ex(!0)},[]),tj=(0,s.useCallback)(()=>{ef(!0)},[]),tw=(0,s.useMemo)(()=>{if(J&&t&&e)return r=>{J({...r,cwd:t,tabId:e,sessionId:ea??crypto.randomUUID(),engine:eG,..."ollama"===eG&&m&&{model:m},...e2&&e5&&{model:e5},...eJ&&{model:eZ},...eQ&&{model:e0}})}},[J,t,e,ea,eG,m,e2,e5,eJ,eZ,eQ,e0]),tk=e3?(0,n.jsxs)("label",{className:"flex items-center gap-1.5 text-xs cursor-pointer select-none",title:er("chat.noHistoryHint",{defaultValue:"Independent task: each message is sent to the model on its own, with no prior conversation. The transcript above still records everything."}),children:[(0,n.jsx)("input",{type:"checkbox","data-testid":"nohistory-toggle",checked:eN,onChange:e=>eC(e.target.checked),className:"accent-brand"}),(0,n.jsxs)("span",{className:"flex items-center gap-1 text-foreground",children:[(0,n.jsx)(nP.A,{className:"w-3.5 h-3.5"}),er("chat.noHistory",{defaultValue:"Independent task"})]}),(0,n.jsx)("span",{className:"text-muted-foreground",children:er("chat.noHistoryDesc",{defaultValue:"no history sent"})})]}):null;return(0,n.jsxs)("div",{className:`flex ${H&&W?"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:()=>ed(!0),onMouseLeave:()=>ed(!1),children:[!H&&(0,n.jsx)(nB,{cwd:t,sessionId:ea,engine:eG,onOpenProjectSessions:()=>eu(!0),onOpenSessionBrowser:ee,onOpenSettings:et}),(eJ||eQ)&&(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border bg-card/50",children:[(0,n.jsx)(sc,{engine:eQ?"codex":"claude",claudeModel:eZ,onClaudeModelChange:k,claudeEffort:eX,onClaudeEffortChange:N,claudeContextWindow:eY,onClaudeContextWindowChange:S,claudeFastMode:M,onClaudeFastModeChange:E,claudeThinking:P,onClaudeThinkingChange:T,codexModel:e0,onCodexModelChange:R,codexReasoningEffort:e1,onCodexReasoningEffortChange:F}),eJ&&(0,n.jsxs)("label",{className:"flex items-center gap-1.5 text-xs cursor-pointer select-none",title:er("chat.planModeHint",{defaultValue:"Plan mode: read-only exploration that produces a plan without editing. Uncheck and resend to implement."}),children:[(0,n.jsx)("input",{type:"checkbox","data-testid":"planmode-toggle",checked:ej,onChange:e=>ew(e.target.checked),className:"accent-brand"}),(0,n.jsxs)("span",{className:"flex items-center gap-1 text-foreground",children:[(0,n.jsx)(nT.A,{className:"w-3.5 h-3.5"}),er("chat.planMode",{defaultValue:"Plan mode"})]}),(0,n.jsx)("span",{className:"text-muted-foreground",children:er("chat.planModeDesc",{defaultValue:"read-only \xb7 plan first, no edits"})})]}),tk]}),"ollama"===eG&&(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border bg-card/50",children:[h&&(0,n.jsx)(n0,{currentModel:m,onModelChange:h}),tk]}),e2&&(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border bg-card/50",children:[e4&&(0,n.jsx)(n2,{engine:e2,currentModel:e5,onModelChange:e4,onHasKeyChange:eM}),tk,(0,n.jsx)("div",{className:"ml-auto pl-2",children:"deepseek"===e2?(0,n.jsx)(sm,{hasKey:eS}):(0,n.jsx)(sf,{engine:e2,hasKey:eS})})]}),eW?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("span",{className:"text-muted-foreground",children:er("sessions.loadingHistory")})}):(0,n.jsx)(nz.M,{ref:eL,messages:es,isLoading:e6||e$,liveOutputTokens:tm,runningStartedAt:tx,cwd:t,sessionId:ea,engine:eG,apiRetryInfo:tt,backgroundTasks:th,hasMoreHistory:eO,isLoadingMore:e_,onLoadMore:eq,onFork:tb,isActive:_,onContentSearch:Z,onShowFileDiff:X,onOpenFileLink:Y,onApprovePlan:ta}),tu&&(0,n.jsx)(nF,{tokenUsage:tu,rateLimitInfo:te}),(0,n.jsx)(nZ,{onSend:to,disabled:e6||e$,cwd:t,engine:eG,onShowGitStatus:K,onShowComments:t?tv:void 0,onShowUserMessages:tj,onOpenNote:G,onCreateScheduledTask:tw})]}),!H&&t&&(0,n.jsx)(x,{isOpen:ec,onClose:()=>eu(!1),cwd:t}),t&&(0,n.jsx)(sb,{isOpen:em,onClose:()=>ex(!1),cwd:t}),(0,n.jsx)(nI,{isOpen:eh,onClose:()=>ef(!1),messages:es,onSelectMessage:e=>{eL.current?.scrollToMessage(e)}})]})}function sj({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,claudeContextWindow:v,onClaudeContextWindowChange:j,claudeFastMode:w,onClaudeFastModeChange:k,claudeThinking:y,onClaudeThinkingChange:N,codexModel:C,onCodexModelChange:S,codexReasoningEffort:M,onCodexReasoningEffortChange:L,planMode:E,onPlanModeChange:P,noHistory:T,onNoHistoryChange:$,isActive:R,refreshSignal:B,onStateChange:F,onShowGitStatus:I,onOpenNote:D,onCreateScheduledTask:A,onOpenSession:z,onContentSearch:H,onShowFileDiff:W,onOpenFileLink:_}){let O=(0,s.useCallback)(t=>{F(e,{isLoading:t})},[e,F]),q=(0,s.useCallback)(t=>{F(e,{sessionId:t})},[e,F]),V=(0,s.useCallback)(t=>{F(e,{title:t})},[e,F]),U=(0,s.useCallback)(t=>{a?.(e,t)},[e,a]),K=(0,s.useCallback)(t=>{i?.(e,t)},[e,i]),G=(0,s.useCallback)(t=>{c?.(e,t)},[e,c]),J=(0,s.useCallback)(t=>{m?.(e,t)},[e,m]),Q=(0,s.useCallback)(t=>{h?.(e,t)},[e,h]),Z=(0,s.useCallback)(t=>{p?.(e,t)},[e,p]),X=(0,s.useCallback)(t=>{b?.(e,t)},[e,b]),Y=(0,s.useCallback)(t=>{j?.(e,t)},[e,j]),ee=(0,s.useCallback)(t=>{k?.(e,t)},[e,k]),et=(0,s.useCallback)(t=>{N?.(e,t)},[e,N]),er=(0,s.useCallback)(t=>{S?.(e,t)},[e,S]),en=(0,s.useCallback)(t=>{L?.(e,t)},[e,L]),es=(0,s.useCallback)(t=>{P?.(e,t)},[e,P]),eo=(0,s.useCallback)(t=>{$?.(e,t)},[e,$]);return(0,n.jsx)(sv,{tabId:e,initialCwd:t,initialSessionId:r,engine:o,onEngineChange:U,ollamaModel:l,onOllamaModelChange:K,deepseekModel:d,onDeepseekModelChange:G,kimiModel:u,onKimiModelChange:J,glmModel:x,onGlmModelChange:Q,claudeModel:f,onClaudeModelChange:Z,claudeEffort:g,onClaudeEffortChange:X,claudeContextWindow:v,onClaudeContextWindowChange:Y,claudeFastMode:w,onClaudeFastModeChange:ee,claudeThinking:y,onClaudeThinkingChange:et,codexModel:C,onCodexModelChange:er,codexReasoningEffort:M,onCodexReasoningEffortChange:en,planMode:E,onPlanModeChange:es,noHistory:T,onNoHistoryChange:eo,hideHeader:!0,hideSidebar:!0,isActive:R,refreshSignal:B,onLoadingChange:O,onSessionIdChange:q,onTitleChange:V,onShowGitStatus:I,onOpenNote:D,onCreateScheduledTask:A,onOpenSession:z,onContentSearch:H,onShowFileDiff:W,onOpenFileLink:_})}var sw=r(3292),sk=r(23121),sy=r(88292),sN=r(76900),sC=r(96472);function sS({initialCwd:e,initialSessionId:t,initialView:r}){let{t:a}=(0,o.Bd)(),[l,c]=(0,s.useState)(r??"agent"),{tabs:u,activeTabId:m,activeTab:h,unreadTabs:p,dragTabIndex:g,dragOverTabIndex:b,closeTab:v,closeAllTabs:j,switchTab:w,handleSelectSession:k,handleNewTab:y,handleNewCodexTab:N,handleNewKimiTab:C,handleNewGlmTab:S,handleNewOllamaTab:M,handleNewDeepseekTab:L,handleOpenSession:E,updateTabState:P,updateTabEngine:T,updateTabOllamaModel:$,updateTabDeepseekModel:R,updateTabKimiModel:B,updateTabGlmModel:F,updateTabClaudeModel:I,updateTabClaudeEffort:D,updateTabClaudeContextWindow:A,updateTabClaudeFastMode:z,updateTabClaudeThinking:H,updateTabCodexModel:W,updateTabCodexReasoningEffort:_,updateTabPlanMode:O,updateTabNoHistory:q,handleTabDragStart:V,handleTabDragOver:U,handleTabDrop:K,handleTabDragEnd:G}=(0,nM.useTabState)({initialCwd:e,initialSessionId:t,activeView:l}),{isPinned:J,pinSession:Q,unpinSession:Z}=(0,sw.P)(),{createTask:X}=(0,sk.nS)(),Y=(0,s.useCallback)(e=>{let t=u.find(t=>t.id===e);return!!t?.sessionId&&J(t.sessionId)},[u,J]),ee=(0,s.useCallback)(t=>{let r=u.find(e=>e.id===t);r?.sessionId&&(J(r.sessionId)?Z(r.sessionId):Q(r.sessionId,r.cwd||e||"",r.title))},[u,J,Q,Z,e]),[er,en]=(0,s.useState)(!1),[es,eo]=(0,s.useState)(!1),[ea,el]=(0,s.useState)(!1),[ei,ed]=(0,s.useState)(null),[ec,eu]=(0,s.useState)(!1),[em,ex]=(0,s.useState)("tree"),[ef,ep]=(0,s.useState)(0),[eg,eb]=(0,s.useState)(null),[ev,ej]=(0,s.useState)(0),[ew,ek]=(0,s.useState)(null),[ey,eN]=(0,s.useState)(null),[eC,eS]=(0,s.useState)(null),[eM,eL]=(0,s.useState)();(0,s.useEffect)(()=>{window.parent.postMessage({type:"GET_PROJECT_NUMBER",cwd:e},"*")},[e]),(0,s.useEffect)(()=>{e&&!r&&d.t4.runPromiseExit((0,sN.D0)(e)).then(e=>{if("Success"===e._tag){let t=e.value.settings;t?.activeView&&c(t.activeView)}})},[e,r]);let[eE,eP]=(0,s.useState)(!1),eT=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=e=>{let{active:t}=e.detail;t?(eT.current=l,c("console"),eP(!0)):(eP(!1),eT.current&&"console"!==eT.current&&c(eT.current),eT.current=null)};return window.addEventListener("cockpit-screenshot-state",e),()=>window.removeEventListener("cockpit-screenshot-state",e)},[l]);let e$=(0,s.useCallback)(t=>{c(t),e&&(d.t4.runFork((0,sN.Yn)({cwd:e,settings:{activeView:t}}).pipe(eh.orElse(()=>eh.void))),d.t4.runFork(eh.flatMap(sy.d,r=>r.publish(i.n.ViewChange,{cwd:e,view:t}))))},[e]);(0,s.useEffect)(()=>{let e=()=>e$("console");return window.addEventListener("console-open-browser",e),()=>window.removeEventListener("console-open-browser",e)},[e$]);let eR=(0,s.useCallback)(async()=>{if(!e)return;let t=await d.t4.runPromiseExit((0,sN.b2)(e));if("Success"===t._tag){let r=t.value;if(eu(!!r.isGitRepo),r.isGitRepo&&r.worktrees&&r.worktrees.length>0){let t=r.worktrees.find(t=>t.path===e);t&&ed(t.branch)}}else console.error("Failed to load git info:",t.cause)},[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>eR())},[eR]);let eB=(0,s.useCallback)(e=>{let{data:t}=e;Array.isArray(t)&&t.some(e=>"git"===e.type)&&eR()},[eR]);(0,et.h)({url:`/ws/watch?cwd=${encodeURIComponent(e||"")}`,onMessage:eB,enabled:!!e}),(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&("1"===e.key?(e.preventDefault(),e$("agent")):"2"===e.key?(e.preventDefault(),e$("explorer")):"3"===e.key?(e.preventDefault(),e$("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:u.map(e=>e.sessionId??null)},"*")},[e,u]),(0,s.useEffect)(()=>{let t=t=>{if(t.data?.type==="PROJECT_NUMBER"&&"number"==typeof t.data?.projectNumber)return void eL(t.data.projectNumber);if(t.data?.type==="IFRAME_VISIBILITY"&&"number"==typeof t.data?.projectNumber&&eL(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:u.map(e=>e.sessionId??null)},"*");if(t.data?.type==="SWITCH_SESSION"){let{sessionId:r,switchToAgent:n}=t.data;if(r){k(r),n&&e$("agent");let t=u.find(e=>e.sessionId===r);t&&eS(e=>({sessionId:r,nonce:(e?.nonce??0)+1})),e&&!t?.isLoading&&(d.t4.runFork((0,sC.KJ)(e,r,"normal").pipe(eh.orElse(()=>eh.void))),d.t4.runFork((0,sC.M2)(r).pipe(eh.orElse(()=>eh.void))))}}};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[k,e$,e,u]);let eF=(0,s.useCallback)(()=>{ex("status"),ep(e=>e+1),e$("explorer")},[e$]),eI=(0,s.useCallback)(e=>{eb(e),ej(e=>e+1),e$("explorer")},[e$]),eD=(0,s.useCallback)(e=>{eN(null),eI(e)},[eI]),eA=(0,s.useCallback)(()=>e$("agent"),[e$]),ez=(0,s.useCallback)((e,t,r,n,s,o)=>{eN(a=>{var l;return l={messageId:e,toolCalls:t,cwd:r,sessionId:n,runId:s},!0!==o?l:a?.messageId!==l.messageId?a:{...a,toolCalls:l.toolCalls}}),o||e$("explorer")},[e$]),eH=(0,s.useCallback)(e=>{eN(null),ek({...e,nonce:Date.now()}),e$("explorer")},[e$]);(0,s.useEffect)(()=>{eN(null)},[ef,ev]);let eW=(0,s.useCallback)(()=>{e&&d.t4.runFork(eh.flatMap(sy.d,t=>t.publish(i.n.OpenNote,{cwd:e})))},[e]);return(0,n.jsx)(nC.k_,{children:(0,n.jsx)(tM.fY,{activeView:l,onViewChange:e$,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)(nL.TabManagerTopBar,{initialCwd:e,activeTab:h,isGitRepo:ec,currentBranch:ei,onOpenWorktree:()=>eo(!0),onOpenAliasManager:()=>el(!0),onBranchSwitched:eR}),eE&&(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:"●"}),a("console.screenshotting")]}),e?(0,n.jsxs)(tM.c0,{children:[(0,n.jsx)("div",{className:"w-1/3 h-full flex flex-col overflow-hidden",children:(0,n.jsx)(f.a9,{children:(0,n.jsxs)("div",{className:"w-full h-full flex flex-col",children:[(0,n.jsx)(nE.TabBar,{tabs:u,activeTabId:m,unreadTabs:p,dragTabIndex:g,dragOverTabIndex:b,isPinned:Y,onTogglePin:ee,onSwitchTab:w,onCloseTab:v,onCloseAllTabs:j,onNewTab:y,onNewCodexTab:N,onNewKimiTab:C,onNewGlmTab:S,onNewOllamaTab:M,onNewDeepseekTab:L,onOpenProjectSessions:()=>en(!0),onDragStart:V,onDragOver:U,onDrop:K,onDragEnd:G}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden relative",children:u.map(e=>(0,n.jsx)("div",{className:`h-full ${e.id===m?"block":"hidden"}`,children:(0,n.jsx)(sj,{tabId:e.id,cwd:e.cwd,sessionId:e.sessionId,engine:e.engine,onEngineChange:T,ollamaModel:e.ollamaModel,onOllamaModelChange:$,deepseekModel:e.deepseekModel,onDeepseekModelChange:R,kimiModel:e.kimiModel,onKimiModelChange:B,glmModel:e.glmModel,onGlmModelChange:F,claudeModel:e.claudeModel,onClaudeModelChange:I,claudeEffort:e.claudeEffort,onClaudeEffortChange:D,claudeContextWindow:e.claudeContextWindow,onClaudeContextWindowChange:A,claudeFastMode:e.claudeFastMode,onClaudeFastModeChange:z,claudeThinking:e.claudeThinking,onClaudeThinkingChange:H,codexModel:e.codexModel,onCodexModelChange:W,codexReasoningEffort:e.codexReasoningEffort,onCodexReasoningEffortChange:_,planMode:e.planMode,onPlanModeChange:O,noHistory:e.noHistory,onNoHistoryChange:q,isActive:e.id===m&&"agent"===l,refreshSignal:eC,onStateChange:P,onShowGitStatus:eF,onContentSearch:eI,onShowFileDiff:ez,onOpenFileLink:eH,onOpenNote:eW,onCreateScheduledTask:X,onOpenSession:E})},e.id))})]})})}),(0,n.jsx)("div",{className:"w-1/3 h-full overflow-hidden relative",children:(0,n.jsxs)(f.a9,{children:[(0,n.jsx)(tL,{onClose:eA,cwd:e,initialTab:em,tabSwitchTrigger:ef,initialSearchQuery:eg,searchQueryTrigger:ev,fileOpenRequest:ew}),ey&&(0,n.jsx)("div",{className:"absolute inset-0 z-20 flex bg-scrim p-[4vmin]",onClick:()=>eN(null),children:(0,n.jsx)(nS.e$,{toolCalls:ey.toolCalls,cwd:ey.cwd,sessionId:ey.sessionId,runId:ey.runId,onClose:()=>eN(null),onContentSearch:eD},ey.messageId)})]})}),(0,n.jsx)("div",{className:"w-1/3 h-full overflow-hidden",children:(0,n.jsx)(f.a9,{children:(0,n.jsx)(nN,{cwd:e,tabId:"default",onOpenNote:eW})})})]}):(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,n.jsx)(nE.TabBar,{tabs:u,activeTabId:m,unreadTabs:p,dragTabIndex:g,dragOverTabIndex:b,isPinned:Y,onTogglePin:ee,onSwitchTab:w,onCloseTab:v,onCloseAllTabs:j,onNewTab:y,onNewCodexTab:N,onNewKimiTab:C,onNewGlmTab:S,onNewDeepseekTab:L,onDragStart:V,onDragOver:U,onDrop:K,onDragEnd:G}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden relative",children:u.map(e=>(0,n.jsx)("div",{className:`h-full ${e.id===m?"block":"hidden"}`,children:(0,n.jsx)(sj,{tabId:e.id,cwd:e.cwd,sessionId:e.sessionId,engine:e.engine,onEngineChange:T,ollamaModel:e.ollamaModel,onOllamaModelChange:$,deepseekModel:e.deepseekModel,onDeepseekModelChange:R,kimiModel:e.kimiModel,onKimiModelChange:B,glmModel:e.glmModel,onGlmModelChange:F,claudeModel:e.claudeModel,onClaudeModelChange:I,claudeEffort:e.claudeEffort,onClaudeEffortChange:D,claudeContextWindow:e.claudeContextWindow,onClaudeContextWindowChange:A,claudeFastMode:e.claudeFastMode,onClaudeFastModeChange:z,claudeThinking:e.claudeThinking,onClaudeThinkingChange:H,codexModel:e.codexModel,onCodexModelChange:W,codexReasoningEffort:e.codexReasoningEffort,onCodexReasoningEffortChange:_,planMode:e.planMode,onPlanModeChange:O,noHistory:e.noHistory,onNoHistoryChange:q,isActive:e.id===m,refreshSignal:eC,onStateChange:P,onCreateScheduledTask:X,onOpenSession:E})},e.id))})]})]}),e&&(0,n.jsx)(x,{isOpen:er,onClose:()=>en(!1),cwd:e,onSelectSession:k,projectNumber:eM,openSessionIds:u.map(e=>e.sessionId)}),e&&ec&&(0,n.jsx)(tE,{isOpen:es,onClose:()=>eo(!1),cwd:e}),ea&&(0,n.jsx)(na,{onClose:()=>el(!1),onSave:()=>el(!1)})]})})})}},92689:(e,t,r)=>{r.d(t,{S:()=>o});var n=r(95155),s=r(57125);function o({engine:e,tooltip:t,size:r="md"}){let a=e||"claude";return(0,s.ch)(a)?(0,n.jsx)("span",{className:"shrink-0 inline-flex items-center","data-tooltip":t??s.H[a],children:(0,n.jsx)(s.eV,{engine:a,className:"sm"===r?"h-3 w-3":"h-3.5 w-3.5"})}):(0,n.jsx)("span",{className:"shrink-0 px-1 py-0.5 text-[10px] leading-none font-medium rounded bg-muted text-muted-foreground","data-tooltip":t??a,children:a})}},93777:(e,t,r)=>{r.d(t,{E:()=>c});var n=r(95155),s=r(12115),o=r(79114),a=r(69809),l=r(12786),i=r(96625);let d={once:[{labelKey:"scheduledTasks.5minLater",value:5},{labelKey:"scheduledTasks.15minLater",value:15},{labelKey:"scheduledTasks.30minLater",value:30},{labelKey:"scheduledTasks.1hourLater",value:60}],interval:[{labelKey:"scheduledTasks.every15min",value:15},{labelKey:"scheduledTasks.every30min",value:30},{labelKey:"scheduledTasks.every1hour",value:60},{labelKey:"scheduledTasks.every2hours",value:120}],cron:[{labelKey:"scheduledTasks.daily9am",value:"0 9 * * *"},{labelKey:"scheduledTasks.daily6pm",value:"0 18 * * *"},{labelKey:"scheduledTasks.weeklyMon9am",value:"0 9 * * 1"},{labelKey:"scheduledTasks.monthly1st9am",value:"0 9 1 * *"}]};function c({onClose:e,onCreate:t,editTask:r,onUpdate:u}){let{t:m}=(0,o.Bd)(),x=!!r,[h,f]=(0,s.useState)(r?.type||"once"),[p,g]=(0,s.useState)(r?.message||""),[b,v]=(0,s.useState)(r?.taskFile?"file":"message"),[j,w]=(0,s.useState)(r?.taskFile||""),[k,y]=(0,s.useState)(r?String(r.delayMinutes||r.intervalMinutes||""):""),[N,C]=(0,s.useState)(r?.cron||""),[S,M]=(0,s.useState)(r?.activeFrom||"09:00"),[L,E]=(0,s.useState)(r?.activeTo||"18:00"),[P,T]=(0,s.useState)(!!(r?.activeFrom&&r?.activeTo)),[$,R]=(0,s.useState)(null),B=(0,s.useRef)(null),F=(0,s.useRef)(null),I=(0,i.n)({value:p,onChange:g,textareaRef:F});(0,s.useEffect)(()=>{F.current?.focus()},[]),(0,s.useEffect)(()=>{let t=t=>{B.current&&!B.current.contains(t.target)&&e()};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[e]);let D=(0,s.useCallback)(()=>{let n="file"===b,s=n?{message:"",taskFile:j.trim()}:{message:p.trim(),taskFile:""};if(n?!s.taskFile:!s.message)return;let o=null;if("once"===h){let e=$||parseInt(k,10);if(!e||e<=0)return;o={...s,type:"once",delayMinutes:e}}else if("interval"===h){let e=$||parseInt(k,10);if(!e||e<=0)return;o={...s,type:"interval",intervalMinutes:e,...P?{activeFrom:S,activeTo:L}:{}}}else if("cron"===h){let e=$||N.trim();if(!e)return;o={...s,type:"cron",cron:e}}o&&(x&&r&&u?u(r.id,o):t(o),e())},[p,b,j,h,$,k,N,P,S,L,t,e,x,r,u]);return(0,n.jsxs)("div",{ref:B,className:`w-[28rem] max-w-[calc(100vw-1.5rem)] bg-popover border border-border rounded-lg shadow-lv2 z-50 ${x?"":"absolute bottom-full left-0 mb-2"}`,onKeyDown:t=>{"Escape"===t.key?e():"Enter"===t.key&&(t.metaKey||t.ctrlKey)&&D()},children:[(0,n.jsx)("div",{className:"px-3 py-2 border-b border-border bg-muted/50 rounded-t-lg",children:(0,n.jsx)("span",{className:"text-sm font-medium",children:x?m("scheduledTasks.editTask"):m("scheduledTasks.createTask")})}),(0,n.jsxs)("div",{className:"p-4 space-y-4 max-h-[min(52rem,calc(100vh-3rem))] overflow-y-auto",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"flex gap-1 mb-1.5",children:["message","file"].map(e=>(0,n.jsx)("button",{onClick:()=>v(e),className:`px-2 py-1 text-xs rounded transition-colors ${b===e?"bg-brand text-white":"bg-muted text-muted-foreground hover:text-foreground"}`,children:"message"===e?m("scheduledTasks.sendMessage"):m("scheduledTasks.taskFile")},e))}),"message"===b?(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("textarea",{ref:F,value:p,onChange:e=>{g(e.target.value),I.trackCaret(e.target)},onSelect:e=>I.trackCaret(e.currentTarget),onKeyDown:e=>{I.handleKeyDown(e)},placeholder:m("scheduledTasks.messagePlaceholder"),rows:5,className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring resize-y min-h-[6rem]"}),(0,n.jsx)(i.V,{ac:I,className:"absolute top-full left-0 right-0 mt-1 max-h-48 z-10"})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("input",{type:"text",value:j,onChange:e=>w(e.target.value),placeholder:m("scheduledTasks.taskFilePlaceholder"),className:"w-full px-2 py-1.5 text-sm font-mono border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring"}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:m("scheduledTasks.taskFileHint")})]})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:m("scheduledTasks.type")}),(0,n.jsx)("div",{className:"flex gap-1",children:["once","interval","cron"].map(e=>(0,n.jsx)("button",{onClick:()=>{f(e),R(null),y(""),C("")},className:`flex-1 px-2 py-1 text-xs rounded transition-colors ${h===e?"bg-brand text-white":"bg-muted text-muted-foreground hover:text-foreground"}`,children:"once"===e?m("scheduledTasks.once"):"interval"===e?m("scheduledTasks.interval"):"Cron"},e))})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:m("scheduledTasks.quickSelect")}),(0,n.jsx)("div",{className:"grid grid-cols-2 gap-1",children:d[h].map(e=>(0,n.jsx)("button",{onClick:()=>{R(e.value),"cron"===h?C(String(e.value)):y(String(e.value))},className:`px-2 py-1 text-xs rounded border transition-colors ${$===e.value?"border-brand bg-brand/10 text-brand":"border-border text-muted-foreground hover:text-foreground hover:border-foreground/30"}`,children:m(e.labelKey)},e.labelKey))})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:"cron"===h?m("scheduledTasks.customCron"):m("scheduledTasks.customMinutes")}),"cron"===h?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("input",{type:"text",value:N,onChange:e=>{C(e.target.value),R(null)},placeholder:m("scheduledTasks.cronPlaceholder"),className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring font-mono"}),N.trim()&&(0,n.jsx)("div",{className:"mt-1 text-xs text-muted-foreground",children:function(e){let t=a.A.t,r=e.trim().split(/\s+/);if(5!==r.length)return null;let[n,s,o,l,i]=r,d={0:t("cron.dowSun"),1:t("cron.dowMon"),2:t("cron.dowTue"),3:t("cron.dowWed"),4:t("cron.dowThu"),5:t("cron.dowFri"),6:t("cron.dowSat")},c={1:`1${t("cron.monthPrefix")}`,2:`2${t("cron.monthPrefix")}`,3:`3${t("cron.monthPrefix")}`,4:`4${t("cron.monthPrefix")}`,5:`5${t("cron.monthPrefix")}`,6:`6${t("cron.monthPrefix")}`,7:`7${t("cron.monthPrefix")}`,8:`8${t("cron.monthPrefix")}`,9:`9${t("cron.monthPrefix")}`,10:`10${t("cron.monthPrefix")}`,11:`11${t("cron.monthPrefix")}`,12:`12${t("cron.monthPrefix")}`};try{let e="";if(n.includes("/")||s.includes("/")){if("*"===s&&n.includes("/"))return t("cron.everyNMinutes",{n:n.split("/")[1]});if("0"===n&&s.includes("/"))return t("cron.everyNHours",{n:s.split("/")[1]});return null}let r=parseInt(s,10),a=parseInt(n,10);if(isNaN(r)&&"*"!==s||isNaN(a)&&"*"!==n)return null;e="*"===s&&"*"===n?t("cron.everyMinute"):"*"===s?t("cron.everyHourAtMin",{m:a}):"*"===n?t("cron.hourlyEveryMin",{h:r}):`${String(r).padStart(2,"0")}:${String(a).padStart(2,"0")}`;let u=[];if("*"!==l){let e=l.split(",").map(e=>c[e]||`${e}${t("cron.monthPrefix")}`);u.push(e.join(", "))}if("*"!==o)if(o.includes("-")){let[e,r]=o.split("-");u.push(t("cron.dayRange",{a:e,b:r}))}else o.includes(",")?u.push(o.split(",").map(e=>`${e}${t("cron.dayOfMonth")}`).join(", ")):u.push(`${o}${t("cron.dayOfMonth")}`);if("*"!==i)if("1-5"===i)u.push(t("cron.weekdays"));else if("0,6"===i||"6,0"===i)u.push(t("cron.weekends"));else{let e=i.split(",").map(e=>{if(e.includes("-")){let[r,n]=e.split("-");return t("cron.weekdayRange",{a:d[r]||r,b:d[n]||n})}return`${t("cron.weekdayPrefix")}${d[e]||e}`});u.push(e.join(", "))}if(0===u.length&&"*"===o&&"*"===l&&"*"===i)return t("cron.daily",{time:e});return`${u.join(" ")} ${e}`}catch{return null}}(N.trim())||(0,n.jsx)("span",{className:"text-destructive",children:m("scheduledTasks.cronFormat")})})]}):(0,n.jsx)("input",{type:"number",value:k,onChange:e=>{y(e.target.value),R(null)},placeholder:m("scheduledTasks.minutesPlaceholder"),min:1,className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring"})]}),"interval"===h&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("label",{className:"flex items-center gap-2 text-xs text-muted-foreground mb-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:P,onChange:e=>T(e.target.checked),className:"rounded border-border"}),m("scheduledTasks.limitTimeRange")]}),P&&(0,n.jsxs)("div",{className:"flex items-center gap-2 mt-1",children:[(0,n.jsx)("input",{type:"time",value:S,onChange:e=>M(e.target.value),className:"flex-1 px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring"}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:m("scheduledTasks.to")}),(0,n.jsx)("input",{type:"time",value:L,onChange:e=>E(e.target.value),className:"flex-1 px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring"})]})]}),(0,n.jsx)("button",{onClick:D,disabled:!(("file"===b?!!j.trim():!!p.trim())&&("once"===h||"interval"===h?!!($||k&&parseInt(k,10)>0):"cron"===h&&!!($||N.trim()))),className:"w-full py-1.5 text-sm font-medium rounded bg-brand text-white hover:bg-brand/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:x?m("scheduledTasks.saveBtn",{modKey:(0,l.Mu)()}):m("scheduledTasks.createBtn",{modKey:(0,l.Mu)()})})]})]})}},96472:(e,t,r)=>{r.d(t,{KJ:()=>l,M2:()=>i,ej:()=>a,n8:()=>o});var n=r(49433),s=r(82680);let o=e=>n.tryPromise({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.tryPromise({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.tryPromise({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})});if(!n.ok)throw Error(`HTTP ${n.status}`)},catch:e=>new s.uV({message:"updateSessionStatus failed",cause:e})}),i=e=>n.tryPromise({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:()=>c,n:()=>d});var n=r(95155),s=r(12115),o=r(79114),a=r(58250),l=r(86957),i=r(83448);function d({value:e,onChange:t,textareaRef:r,extraCommands:n}){let[o,c]=(0,s.useState)(e.length),[u,m]=(0,s.useState)([]),[x,h]=(0,s.useState)([]),[f,p]=(0,s.useState)(0),[g,b]=(0,s.useState)(()=>e.length>0),v=(0,s.useRef)(null);(0,s.useEffect)(()=>{l.t4.runPromiseExit((0,i.M5)()).then(e=>{"Success"===e._tag?m(e.value):console.error("Failed to load commands:",e.cause)})},[]);let j=(0,s.useCallback)(async()=>{let e=await l.t4.runPromiseExit((0,i.l1)());if("Success"===e._tag){let t=e.value.skills??e.value;h((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)(()=>(j(),(0,a.U)(j)),[j]);let w=(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]),k=(0,s.useMemo)(()=>{let e=w.text.match(/^\s*([/@])([a-zA-Z0-9-]*)$/);return e?{marker:e[1],verb:e[2].toLowerCase()}:null},[w.text]),y=(0,s.useMemo)(()=>{if(!k)return[];let{verb:e}=k,t=t=>t.name.slice(1).toLowerCase().startsWith(e);return[...(n??[]).filter(t),...u.filter(t),...x.filter(t)]},[k,n,u,x]),N=!g&&!!k&&y.length>0,C=(0,s.useRef)(e);(0,s.useLayoutEffect)(()=>{C.current!==e&&(queueMicrotask(()=>p(0)),g&&queueMicrotask(()=>b(!1)),C.current=e)},[e,g]),(0,s.useLayoutEffect)(()=>{if(N&&v.current){let e=v.current.children[f];e&&e.scrollIntoView({block:"nearest"})}},[f,N]);let S=(0,s.useCallback)(e=>{c(e.selectionStart??0)},[]),M=(0,s.useCallback)(n=>{let s=k?.marker??"/",o=`${s}${n.name.slice(1)} `,a=e.slice(0,w.start),l=e.slice(w.end),i=a.length+o.length;t(a+o+l),c(i),requestAnimationFrame(()=>{let e=r.current;e&&(e.focus(),e.setSelectionRange(i,i))})},[e,w,k,t,r]),L=(0,s.useCallback)(e=>{if(e.nativeEvent.isComposing||!N||0===y.length)return!1;let t=()=>{e.preventDefault(),e.stopPropagation()};return"ArrowDown"===e.key?(t(),p(e=>(e+1)%y.length),!0):"ArrowUp"===e.key?(t(),p(e=>(e-1+y.length)%y.length),!0):"Enter"===e.key||"Tab"===e.key?(t(),M(y[f]),!0):"Escape"===e.key&&(t(),b(!0),!0)},[N,y,f,M]);return{isOpen:N,items:y,selectedIndex:f,marker:k?.marker??"/",listRef:v,selectCommand:M,handleKeyDown:L,trackCaret:S}}function c({ac:e,className:t=""}){let{t:r}=(0,o.Bd)(),{isOpen:s,items:a,selectedIndex:l,marker:i,listRef:d,selectCommand:u}=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="skill"!==e.source&&0===t;return(0,n.jsxs)("div",{children:[d&&(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"}),(0,n.jsxs)("div",{onClick:()=>u(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"}})(e.source)}`,children:(e=>{switch(e){case"builtin":return r("common.builtin");case"skill":return"Skill"}})(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}}}]);