@surething/cockpit 1.0.233 → 1.0.234
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.next-prod/BUILD_ID +1 -1
- package/.next-prod/app-path-routes-manifest.json +2 -2
- package/.next-prod/build-manifest.json +3 -3
- package/.next-prod/prerender-manifest.json +3 -3
- package/.next-prod/react-loadable-manifest.json +7 -0
- package/.next-prod/server/app/_global-error/page.js.nft.json +1 -1
- package/.next-prod/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/_global-error.html +1 -1
- package/.next-prod/server/app/_global-error.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next-prod/server/app/_not-found/page.js.nft.json +1 -1
- package/.next-prod/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/_not-found.html +2 -2
- package/.next-prod/server/app/_not-found.rsc +2 -2
- package/.next-prod/server/app/_not-found.segments/_full.segment.rsc +2 -2
- package/.next-prod/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/.next-prod/server/app/_not-found.segments/_index.segment.rsc +2 -2
- package/.next-prod/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/.next-prod/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/.next-prod/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/.next-prod/server/app/api/agent/test/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/bash/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/chat/codex/route.js +1 -1
- package/.next-prod/server/app/api/chat/codex/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/chat/deepseek/route.js +1 -1
- package/.next-prod/server/app/api/chat/deepseek/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/chat/kimi/route.js +1 -1
- package/.next-prod/server/app/api/chat/kimi/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/chat/ollama/route.js +1 -1
- package/.next-prod/server/app/api/chat/ollama/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/chat/pty-input/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/chat/route.js +1 -1
- package/.next-prod/server/app/api/chat/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/chat/stop/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/claude-stats/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/commands/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/comments/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/db/columns/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/db/connect/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/db/disconnect/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/db/export/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/db/query/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/db/schemas/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/dev/spans/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/extension/version/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/file/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/blame/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/clipboard/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/copy/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/delete/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/expanded/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/index/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/init/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/paste/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/read/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/readdir/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/recent/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/save/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/search/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/stat/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/text/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/git/branch-diff/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/git/branches/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/git/commit-diff/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/git/commits/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/git/current-branch/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/git/diff/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/git/discard/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/git/stage/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/git/status/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/git/unstage/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/git/worktree/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/global-state/route.js +1 -1
- package/.next-prod/server/app/api/global-state/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/health/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/jupyter/load/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/jupyter/save/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/jupyter/shutdown/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/lsp/definition/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/lsp/hover/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/lsp/references/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/lsp/status/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/lsp/warmup/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/mysql/columns/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/mysql/connect/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/mysql/disconnect/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/mysql/export/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/mysql/query/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/mysql/schemas/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/neo4j/connect/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/neo4j/disconnect/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/neo4j/query/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/neo4j/schema/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/note/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/ollama/models/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/ollama/start/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/open-cursor/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/open-vscode/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/pick-folder/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/pinned-sessions/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/project-settings/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/project-state/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/projectGraph/affected/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/projectGraph/callees/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/projectGraph/callers/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/projectGraph/coedit/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/projectGraph/context/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/projectGraph/file/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/projectGraph/file-functions/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/projectGraph/impact/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/projectGraph/related/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/projectGraph/risk/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/projectGraph/search/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/projects/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/push/public-key/route.js +1 -1
- package/.next-prod/server/app/api/push/public-key/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/push/subscribe/route.js +1 -1
- package/.next-prod/server/app/api/push/subscribe/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/push/unsubscribe/route.js +1 -1
- package/.next-prod/server/app/api/push/unsubscribe/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/redis/command/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/redis/connect/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/redis/delete/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/redis/disconnect/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/redis/get/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/redis/keys/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/redis/set/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/review/[id]/comments/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/review/[id]/replies/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/review/[id]/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/review/identify/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/review/order/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/review/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/review/share-info/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/review/users/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/scheduled-tasks/route.js +1 -1
- package/.next-prod/server/app/api/scheduled-tasks/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/services/config/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/services/scripts/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/session/[sessionId]/fork/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/session/[sessionId]/history/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/session-by-path/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/sessions/projects/[encodedPath]/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/sessions/projects/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/sessions/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/settings/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/skills/[id]/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/skills/content/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/skills/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/terminal/aliases/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/terminal/autocomplete/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/terminal/bubble-order/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/terminal/env/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/terminal/history/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/version/route.js.nft.json +1 -1
- package/.next-prod/server/app/favicon.ico/route.js.nft.json +1 -1
- package/.next-prod/server/app/m/page.js +2 -2
- package/.next-prod/server/app/m/page.js.nft.json +1 -1
- package/.next-prod/server/app/m/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/manifest.webmanifest/route.js.nft.json +1 -1
- package/.next-prod/server/app/page.js +1 -1
- package/.next-prod/server/app/page.js.nft.json +1 -1
- package/.next-prod/server/app/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/project/page.js +1 -1
- package/.next-prod/server/app/project/page.js.nft.json +1 -1
- package/.next-prod/server/app/project/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/review/[id]/page.js +2 -2
- package/.next-prod/server/app/review/[id]/page.js.nft.json +1 -1
- package/.next-prod/server/app/review/[id]/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app-paths-manifest.json +2 -2
- package/.next-prod/server/chunks/{1035.js → 5897.js} +2 -2
- package/.next-prod/server/chunks/9658.js +26 -26
- package/.next-prod/server/chunks/9830.js +1 -1
- package/.next-prod/server/middleware-build-manifest.js +1 -1
- package/.next-prod/server/middleware-react-loadable-manifest.js +1 -1
- package/.next-prod/server/pages/404.html +2 -2
- package/.next-prod/server/pages/500.html +1 -1
- package/.next-prod/server/server-reference-manifest.json +1 -1
- package/.next-prod/static/chunks/{2625-bc4748f0cd7db618.js → 1332-5e141e2acf28015a.js} +10 -10
- package/.next-prod/static/chunks/{217-92f800c2c438c550.js → 217-e929c46c0bd599a7.js} +2 -2
- package/.next-prod/static/chunks/2502-fb8682bc7a61e04d.js +4 -0
- package/.next-prod/static/chunks/4523.3f277a24fbcfde6d.js +138 -0
- package/.next-prod/static/chunks/9304-ddde9008da31b2ce.js +1 -0
- package/.next-prod/static/chunks/app/{layout-ac2f1f67df01cc89.js → layout-d202f8e0bcc90661.js} +1 -1
- package/.next-prod/static/chunks/app/m/page-71570a066f3eacf8.js +1 -0
- package/.next-prod/static/chunks/app/{page-1f0a6f49656a4c52.js → page-814b50b5b440249d.js} +1 -1
- package/.next-prod/static/chunks/app/project/{page-1f0a6f49656a4c52.js → page-814b50b5b440249d.js} +1 -1
- package/.next-prod/static/chunks/app/review/[id]/{page-39fa3a843adf617e.js → page-0c5d03d65758c7dc.js} +1 -1
- package/.next-prod/static/chunks/webpack-2c71a79c277961bc.js +1 -0
- package/.next-prod/trace +13 -13
- package/.next-prod/trace-build +1 -1
- package/bin/cock-browser.mjs +12 -9
- package/bin/cock.mjs +5 -5
- package/bin/postinstall.mjs +6 -6
- package/chrome-extension/automation.js +45 -40
- package/chrome-extension/background.js +70 -67
- package/chrome-extension/content.js +38 -38
- package/chrome-extension/disguise.js +4 -4
- package/chrome-extension/network-capture.js +16 -16
- package/dist/{chunk-VHFWPI2X.mjs → chunk-3M3JSZ5R.mjs} +28 -1
- package/dist/scheduledTasks.mjs +1 -1
- package/dist/wsServer.mjs +6 -31
- package/package.json +1 -1
- package/server.mjs +122 -26
- package/.next-prod/server/chunks/7003.js +0 -1
- package/.next-prod/static/chunks/471-504b396c8302f4f2.js +0 -4
- package/.next-prod/static/chunks/app/m/page-8b1af6f31b60c485.js +0 -1
- package/.next-prod/static/chunks/webpack-dbba7fa77ee1faa4.js +0 -1
- /package/.next-prod/static/{WfNQMmytl62j_8KtgCW9_ → JfwcuC5YjyhQWeQD-4Gvn}/_buildManifest.js +0 -0
- /package/.next-prod/static/{WfNQMmytl62j_8KtgCW9_ → JfwcuC5YjyhQWeQD-4Gvn}/_ssgManifest.js +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[217],{1058:(e,t,n)=>{n.d(t,{_:()=>o});var r=n(12115),s=n(90717),l=n(86957),a=n(46456);function o({cwd:e,filePath:t}){let[n,i]=(0,r.useState)([]),[c,u]=(0,r.useState)(!1),[d,m]=(0,r.useState)(null),h=(0,r.useCallback)(async()=>{if(!e||!t)return;u(!0),m(null);let n=await l.t4.runPromiseExit((0,a.lb)(e,t));if("Success"===n._tag)i(n.value.comments??[]);else{let e="Fail"===n.cause._tag?n.cause.error:null,t=e?.cause;m(t instanceof Error?t.message:"Failed to load comments")}u(!1)},[e,t]);(0,r.useEffect)(()=>{h()},[h]),(0,r.useEffect)(()=>(0,s.zL)(()=>{h()}),[h]);let f=(0,r.useCallback)(async(n,r,s,o)=>{let c=await l.t4.runPromiseExit((0,a.BC)({cwd:e,filePath:t,startLine:n,endLine:r,content:s,...o?{selectedText:o}:{}}));if("Success"===c._tag&&c.value.comment){let e=c.value.comment;return i(t=>[...t,e]),e}return"Failure"===c._tag&&console.error("Failed to add comment:",c.cause),null},[e,t]),x=(0,r.useCallback)(async(t,n)=>{let r=await l.t4.runPromiseExit((0,a.vv)(e,t,n));if("Success"===r._tag&&r.value.comment){let e=r.value.comment;return i(n=>n.map(n=>n.id===t?e:n)),!0}return"Failure"===r._tag&&console.error("Failed to update comment:",r.cause),!1},[e]),p=(0,r.useCallback)(async t=>{let n=await l.t4.runPromiseExit((0,a.Tu)(e,t));return"Success"===n._tag?(i(e=>e.filter(e=>e.id!==t)),!0):(console.error("Failed to delete comment:",n.cause),!1)},[e]),g=(0,r.useCallback)(e=>n.filter(t=>e>=t.startLine&&e<=t.endLine),[n]);return{comments:n,isLoading:c,error:d,addComment:f,updateComment:x,deleteComment:p,refresh:h,getCommentsForLine:g}}},3292:(e,t,n)=>{n.d(t,{P:()=>c});var r=n(12115),s=n(95045),l=n(75346),a=n(49433),o=n(86957),i=n(82680);function c(){let[e,t]=(0,r.useState)([]),n=(0,r.useCallback)(()=>{let e=a.tryPromise({try:async()=>{let e=await fetch("/api/pinned-sessions");return await e.json()},catch:e=>new i.uV({message:"loadPinnedSessions failed",cause:e})});o.t4.runPromise(e.pipe(a.match({onSuccess:e=>t(e.sessions||[]),onFailure:()=>{}})))},[]);(0,r.useEffect)(()=>{n()},[n]),(0,r.useEffect)(()=>{let e=e=>{e.data?.type==="PINNED_SESSIONS_CHANGED"&&n()};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[n]);let c=(0,r.useCallback)(e=>{t(e);let n=a.tryPromise({try:async()=>{await fetch("/api/pinned-sessions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessions:e})})},catch:e=>new i.uV({message:"savePinnedSessions failed",cause:e})});o.t4.runFork(n.pipe(a.orElse(()=>a.void))),(0,s.F)(l.n.PinnedSessionsChanged,{})},[]),u=(0,r.useCallback)(t=>e.some(e=>e.sessionId===t),[e]),d=(0,r.useCallback)((t,n,r)=>{e.some(e=>e.sessionId===t)||c([...e,{sessionId:t,cwd:n,customTitle:r}])},[e,c]),m=(0,r.useCallback)(t=>{c(e.filter(e=>e.sessionId!==t))},[e,c]),h=(0,r.useCallback)((t,n)=>{c(e.map(e=>e.sessionId===t?{...e,customTitle:n}:e))},[e,c]);return{pinnedSessions:e,isPinned:u,pinSession:d,unpinSession:m,updateTitle:h,reorder:(0,r.useCallback)(e=>{c(e)},[c]),reload:n}}},5135:(e,t,n)=>{n.d(t,{M:()=>k});var r=n(95155),s=n(12115),l=n(79114),a=n(47650),o=n(70188),i=n(89109),c=n(7320),u=n(37614),d=n(1058),m=n(48347),h=n(90717),f=n(13219),x=n(97251),p=n(11890),g=n(47215),b=n(47176),v=n(79968),y=n(27570);let w=[x.W];function k({content:e,filePath:t,cwd:n,onClose:x,sourceFile:j,embedded:C=!1,onLocalMdLink:N,scrollToAnchor:S}){let E=j||(n&&t.startsWith(n)?t.slice(n.endsWith("/")?n.length:n.length+1):t),{t:L}=(0,l.Bd)(),M=(0,o.iN)(),R=(0,m.r)(),{comments:T,addComment:$,updateComment:I,deleteComment:P,refresh:_}=(0,d._)({cwd:n,filePath:t}),[A,F]=(0,s.useState)(!1),[D,O]=(0,s.useState)(null),[V,B]=(0,s.useState)(null),[W,H]=(0,s.useState)(null),z=(0,s.useMemo)(()=>e.split("\n"),[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>F(!0))},[]);let[K,U]=(0,s.useState)(null),q=(0,s.useRef)(null);(0,s.useEffect)(()=>{q.current!==K&&U(q.current)});let X=(0,s.useCallback)(e=>{if(!N||/^[a-z][a-z0-9+.-]*:/i.test(e))return!1;let t=e.indexOf("#"),n=t>=0?e.slice(0,t):e,r=t>=0?e.slice(t+1):null;if(!n)return!1;let s=n;try{s=decodeURIComponent(n)}catch{}return!!(0,g.e$)(s)&&(N((0,g.WU)(E,s),r),!0)},[N,E]);(0,s.useEffect)(()=>{if(!S)return;let e=setTimeout(()=>{(0,p.O)(q.current,S)},80);return()=>clearTimeout(e)},[S,e]);let{toolbarRef:Z,bumpRef:J,clearToolbar:Y}=(0,y.L)({enabled:!0,container:K,resolveLineRange:e=>{let t=function(e){let t=e.nodeType===Node.TEXT_NODE?e.parentElement:e;if(!t||!("closest"in t))return null;let n=t.closest("[data-source-start]");if(!n)return null;let r=n.getAttribute("data-source-start"),s=n.getAttribute("data-source-end");return r&&s?{start:parseInt(r,10),end:parseInt(s,10)}:null}(e);return t?{start:t.start,end:t.end}:null},buildLineSnapshot:({start:e,end:t})=>{let n=Math.max(0,e-1),r=Math.min(z.length,t);return z.slice(n,r).join("\n")}}),Q=(0,s.useCallback)(()=>{let e=Z.current;e&&(O({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),Y())},[Y,Z]),G=(0,s.useCallback)(()=>{let e=Z.current;e&&(B({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),Y())},[Y,Z]),ee=(0,s.useCallback)(async e=>{D&&(await $(D.range.start,D.range.end,e,D.selectedText),O(null))},[D,$]),et=(0,s.useCallback)(async e=>{if(V&&R)try{let r=await (0,h.$3)(n),s=[];for(let e of r)s.push({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0});s.push({filePath:t,startLine:V.range.start,endLine:V.range.end,codeContent:V.lineSnapshot});let l=(0,h.Gw)(s,e);R.sendMessage(l),await (0,h.RP)(n),_(),B(null)}catch(e){console.error("Failed to send to AI:",e)}},[V,R,t,n,_]),en=(0,s.useMemo)(()=>{if(0===T.length)return[];let e=new Map;for(let t of T){let n=`${t.startLine}-${t.endLine}`;e.has(n)||e.set(n,[]),e.get(n).push(t)}return Array.from(e.entries()).map(([e,t])=>({key:e,startLine:t[0].startLine,endLine:t[0].endLine,comments:t}))},[T]),[er,es]=(0,s.useState)([]);return(0,s.useEffect)(()=>{if(0===en.length||!q.current)return void queueMicrotask(()=>es([]));let e=setTimeout(()=>{let e=q.current;if(!e)return;let t=[],n=e.querySelectorAll("[data-source-start]");for(let r of en){let s=null,l=1/0;for(let e of n){let t=parseInt(e.getAttribute("data-source-start"),10),n=parseInt(e.getAttribute("data-source-end"),10);if(t<=r.startLine&&n>=r.endLine){let r=n-t;r<l&&(l=r,s=e)}}if(s){let n=e.getBoundingClientRect(),l=s.getBoundingClientRect();t.push({key:r.key,top:l.top-n.top+e.scrollTop,comments:r.comments})}}es(t)},100);return()=>clearTimeout(e)},[en,e]),(0,s.useEffect)(()=>{let e=e=>{if("Escape"===e.key){if(V){B(null),e.stopPropagation();return}if(D){O(null),e.stopPropagation();return}if(Z.current){Z.current=null,J.current(),e.stopPropagation();return}if(W){H(null),e.stopPropagation();return}x?.()}};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[V,D,W,x]),(0,r.jsxs)(r.Fragment,{children:[!C&&(0,r.jsxs)("div",{className:"px-4 py-3 border-b border-border flex items-center justify-between flex-shrink-0",children:[(0,r.jsx)("span",{className:"text-sm font-medium text-foreground truncate",children:t}),(0,r.jsxs)("div",{className:"flex items-center gap-3",children:[(0,r.jsx)(v.ShareReviewToggle,{content:e,sourceFile:E}),(0,r.jsx)("button",{onClick:x,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:L("common.close"),children:(0,r.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,r.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[(0,r.jsx)(b.l,{content:e,containerRef:q}),(0,r.jsxs)("div",{className:"flex-1 overflow-auto relative",ref:q,children:[(0,r.jsx)("div",{className:"p-6",children:(0,r.jsx)(f.T,{content:e,rehypePlugins:w,onLinkClick:X})}),er.map(({key:e,top:t,comments:n})=>(0,r.jsx)("div",{className:"absolute right-3 cursor-pointer z-10",style:{top:t},onClick:e=>{e.stopPropagation(),H({comment:n[0],x:e.clientX,y:e.clientY})},children:(0,r.jsx)("div",{className:"w-5 h-5 rounded-full bg-amber-500/80 text-white text-xs flex items-center justify-center shadow-sm hover:bg-amber-500 transition-colors",children:n.length})},e))]})]}),A&&M&&(0,a.createPortal)((0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(i.f,{floatingToolbarRef:Z,bumpRef:J,container:M,onAddComment:Q,onSendToAI:G,isChatLoading:R?.isLoading}),D&&(0,r.jsx)(c.t,{x:D.x,y:D.y,range:D.range,lineSnapshot:D.lineSnapshot,container:M,onSubmit:ee,onClose:()=>O(null)}),V&&(0,r.jsx)(c.G,{x:V.x,y:V.y,range:V.range,filePath:t,lineSnapshot:V.lineSnapshot,container:M,onSubmit:et,onClose:()=>B(null),isChatLoading:R?.isLoading}),W&&(0,r.jsx)(u.t,{x:W.x,y:W.y,comment:W.comment,container:M,onClose:()=>H(null),onUpdateComment:I,onDeleteComment:P})]}),M)]})}},7320:(e,t,n)=>{n.d(t,{G:()=>o,t:()=>a});var r=n(95155),s=n(12115),l=n(79114);function a({x:e,y:t,range:n,lineSnapshot:o,container:i,onSubmit:c,onClose:u}){let{t:d}=(0,l.Bd)(),[m,h]=(0,s.useState)(""),[f,x]=(0,s.useState)(!1),p=(0,s.useRef)(null),g=(0,s.useRef)(null),[b,v]=(0,s.useState)({x:0,y:0}),y=o?.split("\n").slice(0,5).join("\n"),w=!!o&&o.split("\n").length>5;return(0,s.useEffect)(()=>{if(p.current&&i){let n=i.getBoundingClientRect(),r=p.current.getBoundingClientRect(),s=e-n.left,l=t-n.top;s+r.width>n.width-16&&(s=n.width-r.width-16),s<16&&(s=16),l+r.height>n.height-16&&(l=l-r.height-8),l<16&&(l=16),queueMicrotask(()=>v({x:s,y:l}))}},[e,t,i]),(0,s.useEffect)(()=>{g.current?.focus()},[]),(0,s.useEffect)(()=>{let e=e=>{f||!p.current||p.current.contains(e.target)||u()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[u,f]),(0,r.jsxs)("div",{ref:p,className:"absolute z-[200] w-[640px] bg-card border border-border rounded-lg shadow-lg overflow-hidden",style:{left:b.x,top:b.y},children:[(0,r.jsx)("div",{className:"px-3 py-2 bg-amber-9/10 border-b border-border",children:(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsx)("span",{className:"text-xs font-medium text-amber-11",children:d("comments.addComment")}),(n.start>0||n.end>0)&&(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:d("comments.lineRange",{start:n.start,end:n.end})})]})}),o&&(0,r.jsx)("div",{className:"px-3 py-2 bg-secondary/50 border-b border-border max-h-24 overflow-hidden",children:(0,r.jsxs)("pre",{className:"text-xs font-mono text-muted-foreground whitespace-pre-wrap break-all",children:[y,w&&(0,r.jsx)("span",{className:"text-muted-foreground/50",children:"..."})]})}),(0,r.jsxs)("div",{className:"p-2",children:[(0,r.jsx)("textarea",{ref:g,value:m,onChange:e=>h(e.target.value),placeholder:d("comments.inputPlaceholder"),className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card resize-none focus:outline-none focus:ring-1 focus:ring-ring disabled:opacity-50 disabled:cursor-not-allowed",rows:2,disabled:f,onKeyDown:e=>{"Enter"===e.key&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),!f&&m.trim()&&(x(!0),c(m.trim()))),"Escape"!==e.key||f||u()}}),(0,r.jsx)("div",{className:"mt-1 text-xs text-muted-foreground",children:d(f?"comments.submitting":"comments.enterSubmit")})]})]})}function o({x:e,y:t,range:n,filePath:a,lineSnapshot:i,container:c,onSubmit:u,onClose:d,isChatLoading:m}){let{t:h}=(0,l.Bd)(),[f,x]=(0,s.useState)(""),p=(0,s.useRef)(null),g=(0,s.useRef)(null),[b,v]=(0,s.useState)({x:0,y:0});(0,s.useEffect)(()=>{if(p.current&&c){let n=c.getBoundingClientRect(),r=p.current.getBoundingClientRect(),s=e-n.left,l=t-n.top;s+r.width>n.width-16&&(s=n.width-r.width-16),s<16&&(s=16),l+r.height>n.height-16&&(l=l-r.height-8),l<16&&(l=16),queueMicrotask(()=>v({x:s,y:l}))}},[e,t,c]),(0,s.useEffect)(()=>{g.current?.focus()},[]),(0,s.useEffect)(()=>{let e=e=>{p.current&&!p.current.contains(e.target)&&d()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[d]);let y=i?.split("\n").slice(0,5).join("\n"),w=!!i&&i.split("\n").length>5;return(0,r.jsxs)("div",{ref:p,className:"absolute z-[200] w-[640px] bg-card border border-border rounded-lg shadow-lg overflow-hidden",style:{left:b.x,top:b.y},children:[(0,r.jsxs)("div",{className:"px-3 py-2 bg-brand/10 border-b border-border",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsx)("span",{className:"text-xs font-medium text-brand",children:h("comments.askAI")}),(n.start>0||n.end>0)&&(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:h("comments.lineRange",{start:n.start,end:n.end})})]}),a&&(0,r.jsx)("div",{className:"mt-1 text-xs text-muted-foreground truncate",children:a})]}),i&&(0,r.jsx)("div",{className:"px-3 py-2 bg-secondary/50 border-b border-border max-h-24 overflow-hidden",children:(0,r.jsxs)("pre",{className:"text-xs font-mono text-muted-foreground whitespace-pre-wrap break-all",children:[y,w&&(0,r.jsx)("span",{className:"text-muted-foreground/50",children:"..."})]})}),(0,r.jsxs)("div",{className:"p-2",children:[(0,r.jsx)("textarea",{ref:g,value:f,onChange:e=>x(e.target.value),placeholder:h("comments.inputQuestion"),className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card resize-none focus:outline-none focus:ring-1 focus:ring-ring disabled:opacity-50 disabled:cursor-not-allowed",rows:2,disabled:m,onKeyDown:e=>{"Enter"===e.key&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),!m&&f.trim()&&(u(f.trim()),d())),"Escape"===e.key&&d()}}),(0,r.jsx)("div",{className:"mt-1 text-xs text-muted-foreground",children:h(m?"comments.aiGenerating":"comments.enterSend")})]})]})}},8988:(e,t,n)=>{n.d(t,{M:()=>em});var r=n(95155),s=n(12115),l=n(83897),a=n(64428),o=n(34075),i=n(12651),c=n(81165),u=n(16950),d=n(11019),m=n(12612),h=n(79114),f=n(86957),x=n(85839);function p({cwd:e,sessionId:t,toolCall:n,workflowRef:l,onClose:o}){let{t:i}=(0,h.Bd)(),[c,u]=(0,s.useState)(null),[d,m]=(0,s.useState)(null),[g,b]=(0,s.useState)(!1),v=(0,s.useRef)(void 0),y=l?!!l.running:!n?.result,w=(0,s.useCallback)(async()=>{let r=await f.t4.runPromiseExit((0,x.z)({cwd:e,sessionId:t,...l?{workflowId:l.runId,workflowAgentId:l.agentId}:{toolUseId:n?.id},ifFingerprint:v.current}));if(b(!0),"Success"!==r._tag||!r.value)return;let s=r.value;s.fingerprint&&(v.current=s.fingerprint),!s.notModified&&(s.messages&&u(s.messages),s.subagent&&m(s.subagent))},[e,t,n?.id,l?.runId,l?.agentId]);(0,s.useEffect)(()=>{if(w(),!y)return;let e=setInterval(w,5e3);return()=>clearInterval(e)},[y,w]);let k=(0,s.useRef)(null),j=(0,s.useRef)(!0);(0,s.useEffect)(()=>{let e=k.current;e&&j.current&&(e.scrollTop=e.scrollHeight)},[c]);let C="string"==typeof n?.input?.description?n.input.description:"",N=l?l.label||"":[d?.agentType,C].filter(Boolean).join(" \xb7 ");return(0,r.jsx)(a.ZL,{children:(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:o,children:(0,r.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-[90vh] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 px-4 py-3 border-b border-border flex-shrink-0",children:[(0,r.jsx)("span",{className:"text-base",children:"\uD83E\uDD16"}),(0,r.jsx)("span",{className:"font-medium text-sm text-foreground flex-shrink-0",children:i("chat.subagent")}),N&&(0,r.jsx)("span",{className:"text-xs text-muted-foreground truncate flex-1 min-w-0",title:N,children:N}),(0,r.jsxs)("span",{className:"ml-auto flex items-center gap-2 flex-shrink-0",children:[y&&(0,r.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"}),(0,r.jsx)("button",{onClick:o,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:i("common.close"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,r.jsx)("div",{ref:k,onScroll:()=>{let e=k.current;e&&(j.current=e.scrollTop+e.clientHeight>=e.scrollHeight-40)},className:"flex-1 overflow-y-auto px-4 py-3",children:null===c?(0,r.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:i(g?"chat.subagentEmpty":"common.loading")}):c.map(t=>(0,r.jsx)(eo,{message:t,cwd:e},t.id))})]})})})}function g(e){return e?e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e):"0"}function b(e){if(!e)return"–";let t=Math.round(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);return`${n}m${t%60}s`}let v={done:"text-green-9",running:"text-brand",queued:"text-muted-foreground",error:"text-red-9",failed:"text-red-9"};function y({cwd:e,sessionId:t,runId:n,isRunning:l,onClose:o}){let{t:i}=(0,h.Bd)(),[c,u]=(0,s.useState)(null),[d,m]=(0,s.useState)(!1),[v,k]=(0,s.useState)(null),j=(0,s.useRef)(void 0),C=l||null!=c&&"completed"!==c.status&&"failed"!==c.status,N=(0,s.useCallback)(async()=>{let r=await f.t4.runPromiseExit((0,x.z)({cwd:e,sessionId:t,workflowId:n,ifFingerprint:j.current}));if(m(!0),"Success"!==r._tag||!r.value)return;let s=r.value;s.fingerprint&&(j.current=s.fingerprint),!s.notModified&&s.workflow&&u(s.workflow)},[e,t,n]);(0,s.useEffect)(()=>{if(N(),!C)return;let e=setInterval(N,5e3);return()=>clearInterval(e)},[C,N]);let S=[];if(c?.agents){let e=new Map;for(let t of c.agents){let n=t.phaseTitle||i("chat.workflowUngrouped");e.has(n)||e.set(n,[]),e.get(n).push(t)}for(let[t,n]of e)S.push({title:t,agents:n})}let E=c?[c.workflowName,c.status,`${c.agentCount??c.agents?.length??0} ${i("chat.workflowAgents")}`,`${g(c.totalTokens)} tok`,b(c.durationMs)].filter(Boolean).join(" \xb7 "):"";return(0,r.jsxs)(a.ZL,{children:[(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:o,children:(0,r.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-[90vh] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 px-4 py-3 border-b border-border flex-shrink-0",children:[(0,r.jsx)("span",{className:"text-base",children:"\uD83E\uDDE9"}),(0,r.jsx)("span",{className:"font-medium text-sm text-foreground flex-shrink-0",children:i("chat.workflowRun")}),E&&(0,r.jsx)("span",{className:"text-xs text-muted-foreground truncate flex-1 min-w-0",title:E,children:E}),(0,r.jsxs)("span",{className:"ml-auto flex items-center gap-2 flex-shrink-0",children:[C&&(0,r.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"}),(0,r.jsx)("button",{onClick:o,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:i("common.close"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,r.jsx)("div",{className:"flex-1 overflow-y-auto px-4 py-3",children:null===c?(0,r.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:i(d?"chat.workflowEmpty":"common.loading")}):(0,r.jsxs)(r.Fragment,{children:[c.summary&&(0,r.jsx)("div",{className:"mb-3 text-xs text-muted-foreground whitespace-pre-wrap",children:c.summary}),S.map(e=>(0,r.jsxs)(s.Fragment,{children:[(0,r.jsx)("div",{className:"text-xs font-semibold text-foreground/80 mt-3 mb-1 sticky top-0 bg-card py-1",children:e.title}),e.agents.map(e=>(0,r.jsx)(w,{agent:e,onOpen:()=>e.agentId&&k({runId:n,agentId:e.agentId,label:e.label,running:"done"!==e.state&&C})},`${e.index}-${e.agentId}`))]},e.title))]})})]})}),v&&(0,r.jsx)(p,{cwd:e,sessionId:t,workflowRef:v,onClose:()=>k(null)})]})}function w({agent:e,onOpen:t}){let{t:n}=(0,h.Bd)(),[l,a]=(0,s.useState)(!1),o=e.state&&v[e.state]||"text-muted-foreground",i=e.resultPreview||e.promptPreview||"";return(0,r.jsxs)("div",{className:"border border-border rounded-md mb-1 bg-secondary/50",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 px-2 py-1.5",children:[(0,r.jsx)("button",{onClick:()=>a(e=>!e),className:"text-slate-9 text-xs flex-shrink-0",title:n(l?"chat.collapse":"chat.expand"),children:l?"▲":"▼"}),(0,r.jsx)("span",{className:"text-xs text-foreground truncate flex-1 min-w-0",title:e.label||"",children:e.label||e.agentId}),(0,r.jsx)("span",{className:`text-[10px] flex-shrink-0 ${o}`,children:e.state}),(0,r.jsxs)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:[g(e.tokens)," tok \xb7 ",b(e.durationMs)]}),e.agentId&&(0,r.jsx)("span",{role:"button",tabIndex:0,onClick:t,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&t()},className:"text-xs text-brand hover:text-teal-10 cursor-pointer flex-shrink-0",title:n("chat.subagentViewTitle"),children:n("chat.workflowViewAgent")})]}),l&&i&&(0,r.jsx)("pre",{className:"text-[11px] bg-secondary px-2 py-1.5 rounded-b overflow-x-auto max-h-32 overflow-y-auto text-muted-foreground whitespace-pre-wrap border-t border-border",children:i})]})}var k=n(60938),j=n(67362),C=n(38408),N=n(13219),S=n(47176),E=n(97251),L=n(56045),M=n(50860),R=n(47215);function T({filePath:e}){let[t,n]=(0,s.useState)(null),[l,a]=(0,s.useState)(!0),[o,i]=(0,s.useState)(null),c=(0,s.useRef)(!1),u=(0,R.e$)(e),d=(0,R.u)(e);return((0,s.useEffect)(()=>{d?a(!1):c.current||(c.current=!0,(async()=>{a(!0),i(null);let t=await f.t4.runPromiseExit((0,k.nM)(e));if("Success"===t._tag)n(t.value.content??null);else{let e="Fail"===t.cause._tag?t.cause.error:null,n=e?.cause;i(n instanceof Error?n.message:"Failed to load file")}a(!1),c.current=!1})())},[e,d]),o)?(0,r.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,r.jsx)("div",{className:"text-xs text-red-11",children:o})}):l?(0,r.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,r.jsx)("span",{className:"text-sm text-muted-foreground",children:"Loading..."})}):(0,R.u)(e)?(0,r.jsx)(M.I,{absPath:e,className:"flex items-center justify-center h-full overflow-auto",imgClassName:"max-w-full max-h-full object-contain",alt:e.split("/").pop()||"image"}):t?u?(0,r.jsx)(I,{content:t}):(0,r.jsx)(C.Cv,{content:t,filePath:e,showLineNumbers:!0,showSearch:!0,className:"h-full"}):(0,r.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,r.jsx)("span",{className:"text-sm text-muted-foreground",children:"No content"})})}let $=[E.W];function I({content:e}){let t=(0,s.useRef)(null);return(0,r.jsxs)("div",{className:"h-full flex",children:[(0,r.jsx)(S.l,{content:e,containerRef:t}),(0,r.jsx)("div",{ref:t,className:"flex-1 overflow-auto p-4",children:(0,r.jsx)(N.T,{content:e,rehypePlugins:$})})]})}function P({title:e,content:t,toolName:n,onClose:l}){let{t:i}=(0,h.Bd)(),c=(0,R.jU)(t),u=(0,R.zs)(t),d=(0,R.oK)(t),m=!!u,f=!!d,[x,p]=(0,s.useState)(("Read"===n||"Write"===n)&&f?"file":m?"diff-unified":c?"readable":"json"),g=(0,s.useRef)(null),b=(0,L.o)(g);(0,s.useEffect)(()=>{let e=e=>{if((e.metaKey||e.ctrlKey)&&"f"===e.key&&"readable"===x&&c){e.preventDefault(),b.open();return}if("Escape"===e.key){if(b.isVisible)return void b.close();document.activeElement instanceof HTMLElement&&document.activeElement.blur(),l()}};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[l,x,c,b]);let v=(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-0 md:p-4",onClick:l,children:(0,r.jsxs)("div",{className:"bg-card shadow-xl w-full max-w-[90%] h-full md:h-[90vh] rounded-none md:rounded-lg flex flex-col transition-all",onClick:e=>e.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("h3",{className:"text-sm font-medium text-foreground",children:e}),d&&(0,r.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(d),(0,o.oR)(i("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:i("common.copyAbsPath"),children:(0,r.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}),(0,r.jsxs)("div",{className:"flex items-center gap-3",children:[c&&(0,r.jsxs)("div",{className:"flex items-center gap-1 bg-accent rounded p-0.5",children:[m&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{onClick:()=>p("diff-split"),className:`px-2 py-1 text-xs rounded transition-colors ${"diff-split"===x?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,title:i("diffViewer.sideBySide"),children:"Split"}),(0,r.jsx)("button",{onClick:()=>p("diff-unified"),className:`px-2 py-1 text-xs rounded transition-colors ${"diff-unified"===x?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,title:i("diffViewer.unified"),children:"Unified"})]}),f&&(0,r.jsx)("button",{onClick:()=>p("file"),className:`px-2 py-1 text-xs rounded transition-colors ${"file"===x?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,title:i("diffViewer.previewFile"),children:"File"}),(0,r.jsx)("button",{onClick:()=>p("readable"),className:`px-2 py-1 text-xs rounded transition-colors ${"readable"===x?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:i("common.readable")}),(0,r.jsx)("button",{onClick:()=>p("json"),className:`px-2 py-1 text-xs rounded transition-colors ${"json"===x?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:"JSON"})]}),(0,r.jsx)("button",{onClick:l,className:"p-1 text-slate-9 hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,r.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,r.jsx)("div",{className:"flex-1 overflow-auto p-4",children:"file"===x&&d?(0,r.jsx)(T,{filePath:d}):"diff-unified"===x&&u?(0,r.jsx)(j.xU,{oldContent:u.old_string,newContent:u.new_string,filePath:u.file_path}):"diff-split"===x&&u?(0,r.jsx)(j.xZ,{oldContent:u.old_string,newContent:u.new_string,filePath:u.file_path}):"readable"===x&&c?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(L._,{search:b}),(0,r.jsx)("pre",{ref:g,className:"text-foreground whitespace-pre-wrap break-words",style:{fontSize:"0.8125rem"},children:(0,R.xb)(t)})]}):(0,r.jsx)("pre",{className:"text-foreground whitespace-pre-wrap break-words",style:{fontSize:"0.8125rem"},children:c?(0,R.C6)(t):t})})]})});return(0,r.jsx)(a.ZL,{children:v})}let _={Read:"\uD83D\uDCC4",Write:"✏️",Edit:"\uD83D\uDCDD",Bash:"\uD83D\uDCBB",Glob:"\uD83D\uDD0D",Grep:"\uD83D\uDD0E",WebFetch:"\uD83C\uDF10",WebSearch:"\uD83D\uDD0D",Workflow:"\uD83E\uDDE9",Skill:"\uD83D\uDEE0️"};function A({toolCall:e,cwd:t,sessionId:n}){var l;let{t:a}=(0,h.Bd)(),[i,c]=(0,s.useState)(!1),[u,d]=(0,s.useState)(null),[m,f]=(0,s.useState)(!1),[x,g]=(0,s.useState)(!1),b=_[e.name]||"\uD83D\uDD27",v="Agent"===e.name||"Task"===e.name,w=v&&!!t&&!!n,k="Workflow"===e.name,j=k&&(l=e.result)?l.match(/subagents\/workflows\/(wf_[A-Za-z0-9_-]+)/)?.[1]??null:null,C=k&&!!j&&!!t&&!!n,N="Skill"===e.name,S=v||k||N,E=(()=>{let t=e.input;if("Bash"===e.name&&t.command&&"string"==typeof t.command)return t.command;if(v&&t.description&&"string"==typeof t.description)return t.description;if(k){let e=["string"==typeof t.name?t.name:"","string"==typeof t.args?t.args:"string"==typeof t.resumeFromRunId?t.resumeFromRunId:""].filter(Boolean).join(" \xb7 ");if(e)return e}if(N&&"string"==typeof t.skill){let e="string"==typeof t.args?t.args:"";return[t.skill,e].filter(Boolean).join(" \xb7 ")}return"Glob"===e.name&&t.pattern&&"string"==typeof t.pattern||"Grep"===e.name&&t.pattern&&"string"==typeof t.pattern?t.pattern:"ToolSearch"===e.name&&t.query&&"string"==typeof t.query?t.query:"TaskCreate"===e.name&&t.subject&&"string"==typeof t.subject?t.subject:t.file_path&&"string"==typeof t.file_path?t.file_path:t.path&&"string"==typeof t.path?t.path:null})(),L="Glob"===e.name||"Grep"===e.name||"Bash"===e.name||v||k||N,M=E?L?E:(e=>{if(t&&e.startsWith(t)){let n=e.slice(t.length);return n.startsWith("/")?n.slice(1):n}let n=e.split("/");return n.length>2?".../"+n.slice(-2).join("/"):e})(E):null,R=t=>{let n="input"===t?a("toolCall.inputParams"):a("toolCall.resultLabel"),r="input"===t?JSON.stringify(e.input,null,2):"string"==typeof e.result?e.result:JSON.stringify(e.result,null,2);d({title:`${e.name}${M?` ${M}`:""} - ${n}`,content:r,toolName:e.name})};return(0,r.jsxs)("div",{className:"my-1 border border-border rounded-lg overflow-hidden bg-secondary",children:[(0,r.jsxs)("button",{onClick:()=>c(!i),className:"w-full px-3 py-1.5 flex items-center gap-2 text-left hover:bg-accent transition-colors",children:[(0,r.jsx)("span",{className:"text-sm",children:b}),(0,r.jsx)("span",{className:"font-medium text-sm text-foreground flex-shrink-0",children:e.name}),M&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"text-xs text-muted-foreground truncate flex-1 min-w-0",title:E||"",children:M}),!S&&(0,r.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),E&&(navigator.clipboard.writeText(E),(0,o.oR)(a("common.copiedPath")))},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),E&&(navigator.clipboard.writeText(E),(0,o.oR)(a("common.copiedPath"))))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0 cursor-pointer",title:a("common.copyAbsPath"),children:(0,r.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}),(0,r.jsxs)("span",{className:"ml-auto flex items-center gap-2",children:[w&&(0,r.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),f(!0)},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),f(!0))},className:"text-xs text-brand hover:text-teal-10 cursor-pointer",title:a("chat.subagentViewTitle"),children:a("chat.subagent")}),C&&(0,r.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),g(!0)},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),g(!0))},className:"text-xs text-brand hover:text-teal-10 cursor-pointer",title:a("chat.workflowViewTitle"),children:a("chat.workflowRun")}),i&&!e.isLoading&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),R("input")},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),R("input"))},className:"text-xs text-brand hover:text-teal-10 cursor-pointer",title:a("toolCall.inputParamsTitle"),children:a("toolCall.input")}),e.result&&(0,r.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),R("result")},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),R("result"))},className:"text-xs text-brand hover:text-teal-10 cursor-pointer",title:a("toolCall.resultTitle"),children:a("toolCall.result")})]}),e.isLoading?(0,r.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"}):(0,r.jsx)("span",{className:"text-slate-9 text-xs",children:i?"▲":"▼"})]})]}),i&&(0,r.jsxs)("div",{className:"border-t border-border",children:[(0,r.jsxs)("div",{className:"px-3 py-2",children:[(0,r.jsx)("div",{className:"mb-1",children:(0,r.jsxs)("span",{className:"text-xs text-muted-foreground",children:[a("toolCall.inputParams"),":"]})}),(0,r.jsx)("pre",{className:"text-xs bg-secondary p-2 rounded overflow-x-auto max-h-24 overflow-y-auto text-foreground",children:JSON.stringify(e.input,null,2)})]}),e.result&&(0,r.jsxs)("div",{className:"px-3 py-2 border-t border-border",children:[(0,r.jsx)("div",{className:"mb-1",children:(0,r.jsxs)("span",{className:"text-xs text-muted-foreground",children:[a("toolCall.resultLabel"),":"]})}),(0,r.jsx)("pre",{className:"text-xs bg-secondary p-2 rounded overflow-x-auto max-h-24 overflow-y-auto text-foreground",children:"string"==typeof e.result?e.result:JSON.stringify(e.result,null,2)})]}),e.skillContent&&(0,r.jsxs)("div",{className:"px-3 py-2 border-t border-border",children:[(0,r.jsx)("div",{className:"mb-1",children:(0,r.jsxs)("span",{className:"text-xs text-muted-foreground",children:[a("toolCall.skillContent",{defaultValue:"Skill content"}),":"]})}),(0,r.jsx)("pre",{className:"text-xs bg-secondary p-2 rounded overflow-x-auto max-h-60 overflow-y-auto text-foreground whitespace-pre-wrap",children:e.skillContent})]})]}),u&&(0,r.jsx)(P,{title:u.title,content:u.content,toolName:u.toolName,onClose:()=>d(null)}),m&&t&&n&&(0,r.jsx)(p,{cwd:t,sessionId:n,toolCall:e,onClose:()=>f(!1)}),x&&t&&n&&j&&(0,r.jsx)(y,{cwd:t,sessionId:n,runId:j,isRunning:!!e.isLoading,onClose:()=>g(!1)})]})}var F=n(56204),D=n(67635),O=n(33210),V=n(58515),B=n(36201),W=n(55804),H=n(37618);function z(e){let t=e.input?.questions||[],n=e.input?.answers||{},r={};if(e.result)try{let t=JSON.parse(e.result);t?.answers&&(r=t.answers)}catch{}return{questions:t,answers:{...n,...r}}}function K(e,t){return`${e}-${t}`}function U({toolCalls:e,onClose:t}){let{t:n}=(0,h.Bd)(),i=(0,l.nH)(),[c,u]=(0,s.useState)({}),[d,m]=(0,s.useState)({}),[f,x]=(0,s.useState)({}),[p,g]=(0,s.useState)({});(0,s.useEffect)(()=>{let t={};e.forEach((e,n)=>{let{questions:r,answers:s}=z(e);r.forEach((e,r)=>{let l=s[e.question];if(l){let s=K(n,r);t[s]=l,e.options.some(e=>e.label===l)||(m(e=>({...e,[s]:!0})),x(e=>({...e,[s]:l})))}})}),queueMicrotask(()=>u(t))},[e]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&t()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[t]);let b=e.reduce((e,t)=>{let{questions:n}=z(t);return e+n.length},0),v=Object.values(p).filter(Boolean).length,y=(0,s.useCallback)((e,t)=>{u(n=>({...n,[e]:t})),m(t=>({...t,[e]:!1}))},[]),w=(0,s.useCallback)(e=>{m(t=>{let n=!t[e];if(n){let t=f[e]||"";t&&u(n=>({...n,[e]:t}))}return{...t,[e]:n}})},[f]),k=(0,s.useCallback)((e,t)=>{x(n=>({...n,[e]:t})),t&&u(n=>({...n,[e]:t}))},[]),j=(0,s.useCallback)(e=>{g(t=>({...t,[e]:!t[e]}))},[]),C=(0,s.useCallback)(()=>{let t=v>0,r=[];return e.forEach((e,s)=>{let{questions:l}=z(e);l.forEach((e,l)=>{let a=K(s,l);if(t&&!p[a])return;let o=c[a];r.push(`Q: ${e.question}`),r.push(`A: ${o||n("askQuestion.notSelected")}`),r.push("")})}),r.join("\n").trim()},[e,c,p,v,n]),N=(0,s.useCallback)(()=>{navigator.clipboard.writeText(C()),(0,o.oR)(v>0?n("toast.copiedQA",{count:v}):n("toast.copiedAllQA"))},[C,v,n]),S=(0,s.useCallback)(()=>{i?(i.sendMessage(C()),(0,o.oR)(n("toast.sentQA")),t()):(0,o.oR)(n("askQuestion.sendNoChat"))},[i,C,t,n]),E=(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:t,children:(0,r.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-6xl h-[90vh] flex flex-col overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border flex-shrink-0",children:[(0,r.jsxs)("div",{className:"flex items-center gap-3",children:[(0,r.jsx)("h3",{className:"text-sm font-medium text-foreground",children:n("askQuestion.title")}),(0,r.jsxs)("span",{className:"text-xs text-muted-foreground",children:[n("askQuestion.nQuestions",{count:b}),v>0&&` \xb7 ${n("askQuestion.checkedN",{count:v})}`]})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("button",{onClick:S,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:v>0?n("askQuestion.sendChecked",{count:v}):n("askQuestion.sendAll"),children:(0,r.jsx)(F.A,{className:"w-4 h-4"})}),(0,r.jsx)("button",{onClick:N,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:v>0?n("askQuestion.copyChecked",{count:v}):n("askQuestion.copyAll"),children:(0,r.jsx)(D.A,{className:"w-4 h-4"})}),(0,r.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,r.jsx)(O.A,{className:"w-5 h-5"})})]})]}),(0,r.jsx)("div",{className:"flex-1 overflow-y-auto px-6 py-4 space-y-6",children:e.map((t,s)=>{let{questions:l}=z(t);return l.map((t,a)=>{let o=K(s,a),i=c[o],u=d[o]||!1,m=p[o]||!1;return(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsxs)("div",{className:"flex items-start gap-2",children:[(0,r.jsx)("button",{onClick:()=>j(o),className:"mt-0.5 flex-shrink-0 p-0.5 rounded hover:bg-accent transition-colors",title:n("askQuestion.checkToCopy"),children:m?(0,r.jsx)(V.A,{className:"w-4 h-4 text-brand"}):(0,r.jsx)(B.A,{className:"w-4 h-4 text-muted-foreground"})}),t.header&&(0,r.jsx)("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium bg-brand/10 text-brand flex-shrink-0 mt-0.5",children:t.header}),(0,r.jsx)("span",{className:"text-sm font-medium text-foreground",children:t.question})]}),(0,r.jsxs)("div",{className:"space-y-1 ml-7",children:[t.options.map((e,t)=>{let n=i===e.label&&!u;return(0,r.jsxs)("button",{onClick:()=>y(o,e.label),className:`flex items-start gap-2 px-2.5 py-1.5 rounded-md transition-colors w-full text-left cursor-pointer hover:bg-accent/50 ${n?"bg-brand/10 hover:bg-brand/15":""}`,children:[(0,r.jsx)("div",{className:"mt-0.5 flex-shrink-0",children:n?(0,r.jsx)(W.A,{className:"w-3.5 h-3.5 text-brand"}):(0,r.jsx)("div",{className:"w-3.5 h-3.5 rounded-full border border-muted-foreground"})}),(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsx)("div",{className:`text-sm ${n?"text-foreground font-medium":"text-foreground"}`,children:e.label}),e.description&&(0,r.jsx)("div",{className:"text-xs text-muted-foreground mt-0.5",children:e.description})]})]},t)}),(0,r.jsxs)("button",{onClick:()=>w(o),className:`flex items-start gap-2 px-2.5 py-1.5 rounded-md transition-colors w-full text-left cursor-pointer hover:bg-accent/50 ${u?"bg-brand/10 hover:bg-brand/15":""}`,children:[(0,r.jsx)("div",{className:"mt-0.5 flex-shrink-0",children:u?(0,r.jsx)(W.A,{className:"w-3.5 h-3.5 text-brand"}):(0,r.jsx)("div",{className:"w-3.5 h-3.5 rounded-full border border-muted-foreground"})}),(0,r.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,r.jsx)(H.A,{className:"w-3.5 h-3.5 text-muted-foreground"}),(0,r.jsx)("span",{className:"text-sm text-muted-foreground",children:n("askQuestion.custom")})]})]}),u&&(0,r.jsx)("div",{className:"ml-6 mt-1",children:(0,r.jsx)("input",{type:"text",autoFocus:!0,value:f[o]||"",onChange:e=>k(o,e.target.value),placeholder:n("askQuestion.customPlaceholder"),className:"w-full px-3 py-1.5 text-sm bg-background border border-border rounded-md focus:outline-none focus:ring-1 focus:ring-brand text-foreground placeholder:text-muted-foreground"})})]}),(s!==e.length-1||a!==l.length-1)&&(0,r.jsx)("div",{className:"border-b border-border/50 mt-3"})]},o)})})})]})});return(0,r.jsx)(a.ZL,{children:E})}var q=n(48368),X=n(66088),Z=n(21362),J=n(12710);function Y(e,t){if(t&&e.startsWith(t)){let n=e.slice(t.length);return n.startsWith("/")?n.slice(1):n}return e}function Q({node:e,selectedUid:t,onSelect:n,depth:l=0}){let[a,o]=(0,s.useState)(!0);if(e.isFile&&e.change){let s=t===e.change.uid;return(0,r.jsxs)("button",{onClick:()=>n(e.change),className:`w-full flex items-center gap-1.5 px-2 py-1 text-xs text-left rounded transition-colors ${s?"bg-brand/15 text-brand":"text-foreground hover:bg-accent"}`,style:{paddingLeft:`${12*l+8}px`},"data-tooltip":e.fullPath,children:[(0,r.jsx)(q.A,{className:"w-3.5 h-3.5 flex-shrink-0 opacity-60"}),(0,r.jsx)("span",{className:"truncate",children:e.name}),(0,r.jsx)("span",{className:`ml-auto text-[10px] flex-shrink-0 ${"write"===e.change.type?"text-green-500":"text-yellow-500"}`,children:"write"===e.change.type?"new":"edit"})]})}return(0,r.jsxs)("div",{children:[(0,r.jsxs)("button",{onClick:()=>o(!a),className:"w-full flex items-center gap-1 px-2 py-1 text-xs text-muted-foreground hover:text-foreground transition-colors",style:{paddingLeft:`${12*l+8}px`},children:[a?(0,r.jsx)(X.A,{className:"w-3 h-3"}):(0,r.jsx)(Z.A,{className:"w-3 h-3"}),(0,r.jsx)("span",{className:"truncate",children:e.name})]}),a&&e.children.map((e,s)=>(0,r.jsx)(Q,{node:e,selectedUid:t,onSelect:n,depth:l+1},e.isFile&&e.change?e.change.uid:`${e.fullPath}-${s}`))]})}function G({toolCalls:e,cwd:t,onClose:n}){let{t:l}=(0,h.Bd)(),o=(0,s.useMemo)(()=>(function(e,t){let n=[],r=0;for(let s of e)if("Edit"===s.name){let e=s.input;e.file_path&&"string"==typeof e.old_string&&"string"==typeof e.new_string&&n.push({filePath:Y(e.file_path,t),uid:`change-${r++}`,type:"edit",old_string:e.old_string,new_string:e.new_string})}else if("Write"===s.name){let e=s.input;e.file_path&&"string"==typeof e.content&&n.push({filePath:Y(e.file_path,t),uid:`change-${r++}`,type:"write",old_string:"",new_string:e.content})}return n})(e,t),[e,t]),i=(0,s.useMemo)(()=>(function e(t){return t.map(t=>{if(!t.isFile&&1===t.children.length&&!t.children[0].isFile){let n=t.children[0];return{...n,name:t.name+"/"+n.name,children:e(n.children)}}return{...t,children:e(t.children)}})})(function(e){let t=[];for(let n of e){let e=n.filePath.split("/").filter(Boolean),r=t;for(let t=0;t<e.length;t++){let s=e[t],l=t===e.length-1,a=e.slice(0,t+1).join("/");if(l){let e={name:s,fullPath:a,isFile:!0,children:[],change:n};r.push(e)}else{let e=r.find(e=>e.name===s&&!e.isFile);e||(e={name:s,fullPath:a,isFile:!1,children:[]},r.push(e)),r=e.children}}}return t}(o)),[o]),[c,u]=(0,s.useState)(o[0]||null),[d,m]=(0,s.useState)("unified"),f=(0,s.useRef)(null),[x,p]=(0,s.useState)(()=>window.innerWidth>=768);if((0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&n()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[n]),0===o.length)return null;let g=(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-0 md:p-4",onClick:n,children:(0,r.jsxs)("div",{className:"bg-card shadow-xl w-full h-full rounded-none md:max-w-[90%] md:h-[90vh] md:rounded-lg flex flex-col transition-all",onClick:e=>e.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("button",{onClick:()=>p(e=>!e),"aria-label":l("diffViewer.toggleFileTree"),className:`p-1 rounded transition-colors ${x?"text-foreground bg-accent":"text-muted-foreground hover:text-foreground hover:bg-accent"}`,children:(0,r.jsx)(J.A,{className:"w-4 h-4"})}),(0,r.jsx)("h3",{className:"text-sm font-medium text-foreground",children:l("diffViewer.fileChanges",{count:o.length})})]}),(0,r.jsxs)("div",{className:"flex items-center gap-3",children:[(0,r.jsxs)("div",{className:"flex items-center gap-1 bg-accent rounded p-0.5",children:[(0,r.jsx)("button",{onClick:()=>m("unified"),className:`px-2 py-1 text-xs rounded transition-colors ${"unified"===d?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:"Unified"}),(0,r.jsx)("button",{onClick:()=>m("split"),className:`px-2 py-1 text-xs rounded transition-colors ${"split"===d?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:"Split"})]}),(0,r.jsx)("button",{onClick:n,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,r.jsx)(O.A,{className:"w-5 h-5"})})]})]}),(0,r.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[x&&(0,r.jsx)("div",{ref:f,className:"w-56 flex-shrink-0 border-r border-border overflow-y-auto py-2",children:i.map((e,t)=>(0,r.jsx)(Q,{node:e,selectedUid:c?.uid||"",onSelect:e=>{u(e),window.innerWidth<768&&p(!1)}},e.isFile&&e.change?e.change.uid:`${e.fullPath}-${t}`))}),(0,r.jsx)("div",{className:"flex-1 overflow-auto",children:c?"unified"===d?(0,r.jsx)(j.xU,{oldContent:c.old_string,newContent:c.new_string,filePath:c.filePath}):(0,r.jsx)(j.xZ,{oldContent:c.old_string,newContent:c.new_string,filePath:c.filePath,isNew:"write"===c.type}):(0,r.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:l("diffViewer.selectFileToView")})})]})]})});return(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(a.ZL,{children:g})})}var ee=n(5135),et=n(38175),en=n(70188),er=n(83448);function es({image:e,onClose:t}){let{t:n}=(0,h.Bd)(),s=(0,r.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80",onClick:t,children:[(0,r.jsx)("button",{onClick:t,className:"absolute top-4 right-4 w-10 h-10 flex items-center justify-center text-white/80 hover:text-white bg-black/40 hover:bg-black/60 rounded-full transition-colors",children:(0,r.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),(0,r.jsx)("img",{src:`data:${e.media_type};base64,${e.data}`,alt:n("chat.imagePreview"),className:"max-w-[90vw] max-h-[90vh] object-contain",onClick:e=>e.stopPropagation()})]});return(0,r.jsx)(a.ZL,{children:s})}function el({filePath:e,content:t,cwd:n,onClose:l}){let[o,i]=(0,s.useState)(null);return(0,r.jsx)(a.ZL,{children:(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-0 md:p-4",onClick:l,children:(0,r.jsx)("div",{ref:i,className:"bg-card shadow-xl w-full h-full rounded-none md:max-w-[90%] md:h-[90vh] md:rounded-lg flex flex-col relative",onClick:e=>e.stopPropagation(),children:(0,r.jsx)(en.SU,{container:o,children:(0,r.jsx)(ee.M,{content:t,filePath:e,cwd:n,onClose:l})})})})})}function ea({filePath:e,content:t,onClose:n}){return(0,r.jsx)(a.ZL,{children:(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-0 md:p-4",onClick:n,children:(0,r.jsxs)("div",{className:"bg-card shadow-xl w-full h-full rounded-none md:max-w-[90%] md:h-[90vh] md:rounded-lg flex flex-col relative overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border flex-shrink-0",children:[(0,r.jsx)("span",{className:"text-sm text-muted-foreground truncate",children:e.split("/").pop()}),(0,r.jsx)("button",{onClick:n,className:"text-muted-foreground hover:text-foreground px-1.5 py-0.5 rounded hover:bg-accent transition-colors",children:"✕"})]}),(0,r.jsx)("div",{className:"flex-1 overflow-hidden",children:(0,r.jsx)(et.E,{content:t,filePath:e})})]})})})}let eo=(0,s.memo)(function({message:e,cwd:t,sessionId:n,onFork:l,onApprovePlan:x,isLoading:p}){let g,b,v,y,{t:w}=(0,h.Bd)(),[k,j]=(0,s.useState)(null),[C,S]=(0,s.useState)(()=>1===(e.toolCalls?.length||0)),[E,L]=(0,s.useState)(!1),[M,T]=(0,s.useState)(!1),[$,I]=(0,s.useState)(!1),P="user"===e.role,_=e.images&&e.images.length>0,F=e.toolCalls?.length||0,D=!!n&&!!t&&!!l,O=(0,s.useMemo)(()=>e.toolCalls?.some(e=>"Edit"===e.name||"Write"===e.name)||!1,[e.toolCalls]),V=(0,s.useMemo)(()=>{if(!e.toolCalls)return null;for(let t=e.toolCalls.length-1;t>=0;t--)if("TodoWrite"===e.toolCalls[t].name)return e.toolCalls[t];return null},[e.toolCalls]),B=(0,s.useMemo)(()=>e.toolCalls?e.toolCalls.filter(e=>"AskUserQuestion"===e.name):[],[e.toolCalls]),W=(0,s.useMemo)(()=>{if(!e.toolCalls)return null;for(let t=e.toolCalls.length-1;t>=0;t--)if("ExitPlanMode"===e.toolCalls[t].name){let n=e.toolCalls[t].input?.plan;return"string"==typeof n&&n?n:null}return null},[e.toolCalls]),H=(0,s.useMemo)(()=>e.toolCalls?.filter(e=>"ExitPlanMode"!==e.name)??[],[e.toolCalls]),z=(0,s.useMemo)(()=>{if(!e.toolCalls)return[];let t=new Set,n=[];for(let r of e.toolCalls)if("Read"===r.name||"Edit"===r.name||"Write"===r.name){let e=r.input.file_path;e&&((0,R.e$)(e)||(0,R.aR)(e))&&!t.has(e)&&(t.add(e),n.push(e))}return n},[e.toolCalls]),K=(0,s.useMemo)(()=>{if(!e.toolCalls)return[];let t=[];for(let n of e.toolCalls){let e=n.input?.thought;if(e&&"string"==typeof e){let r=e.match(/PREVIOUS:\s*(.*?)\s*→\s*THIS:\s*(.*?)\s*→\s*EXPECT:\s*(.*)/i);r?t.push({previous:r[1].trim(),current:r[2].trim(),expect:r[3].trim(),raw:e,toolName:n.name}):t.push({previous:"",current:e,expect:"",raw:e,toolName:n.name})}}return t},[e.toolCalls]),[q,X]=(0,s.useState)(null),[Z,J]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!q)return void queueMicrotask(()=>J(null));let e=!1;return f.t4.runPromiseExit((0,er.an)(q)).then(t=>{e||("Success"===t._tag&&void 0!==t.value.content?J(t.value.content):((0,o.oR)(w("toast.readFileFailed"),"error"),X(null)))}),()=>{e=!0}},[q,w]);let Y=()=>{e.content&&(navigator.clipboard.writeText(e.content),(0,o.oR)(w("toast.copiedMessage")))},Q=()=>{D&&l(e.id)},ee=(e=>{if(!e)return"";let t=new Date(e);if(isNaN(t.getTime()))return"";let n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),l=String(t.getMinutes()).padStart(2,"0");return`${n}-${r} ${s}:${l}`})(e.timestamp);if("system"===e.role){let t=e.systemEvent,n=t?.kind==="task-notification"?"failed"===t.status?"⚠️":"stopped"===t.status?"⏹️":"\uD83D\uDD14":"ℹ️",s=t?.detail||e.content;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"flex justify-center my-2 px-2","data-role":"system",children:(0,r.jsxs)("button",{type:"button",onClick:()=>I(!0),className:"flex items-center gap-1.5 max-w-[85%] text-[11px] text-muted-foreground bg-secondary/40 border border-border/50 rounded-full px-3 py-1 hover:bg-secondary hover:text-foreground transition-colors cursor-pointer",title:w("chat.viewDetails",{defaultValue:"Click for details"}),children:[(0,r.jsx)("span",{className:"flex-shrink-0",children:n}),(0,r.jsx)("span",{className:"truncate",children:e.content})]})}),$&&(0,r.jsx)(a.ZL,{children:(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:()=>I(!1),children:(0,r.jsxs)("div",{className:"bg-card shadow-xl w-full max-w-4xl max-h-[80vh] rounded-lg flex flex-col overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border flex-shrink-0",children:[(0,r.jsxs)("span",{className:"text-sm text-foreground flex items-center gap-1.5",children:[(0,r.jsx)("span",{children:n}),t?.kind==="task-notification"?w("chat.taskNotification",{defaultValue:"Task notification"}):w("chat.systemNotice",{defaultValue:"Notice"})]}),(0,r.jsx)("button",{onClick:()=>I(!1),className:"text-muted-foreground hover:text-foreground px-1.5 py-0.5 rounded hover:bg-accent transition-colors",children:"✕"})]}),(0,r.jsx)("pre",{className:"flex-1 overflow-auto px-4 py-3 text-xs text-foreground whitespace-pre-wrap break-words",children:s})]})})})]})}return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:`flex flex-col ${P?"items-end":"items-start"} mb-4 group`,"data-role":e.role,children:[ee&&(0,r.jsx)("span",{className:"text-[11px] text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity mb-0.5 px-1",children:ee}),(0,r.jsxs)("div",{className:`flex ${P?"justify-end":"justify-start"} w-full`,children:[P&&(0,r.jsxs)("div",{className:"self-start mt-2 mr-1 flex flex-col gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.content&&(0,r.jsx)("button",{onClick:Y,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:w("chat.copyMessage"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),D&&(0,r.jsx)("button",{onClick:Q,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:w("chat.forkSession"),children:(0,r.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("circle",{cx:"12",cy:"18",r:"3"}),(0,r.jsx)("circle",{cx:"6",cy:"6",r:"3"}),(0,r.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,r.jsx)("path",{d:"M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9"}),(0,r.jsx)("path",{d:"M12 12v3"})]})})]}),(0,r.jsxs)("div",{className:`max-w-[80%] ${P?"bg-accent text-foreground border border-brand rounded-2xl rounded-br-md":"bg-accent text-foreground dark:text-slate-11 rounded-2xl rounded-bl-md"} px-4 py-2`,children:[_&&(0,r.jsx)("div",{className:`flex flex-wrap gap-2 ${e.content?"mb-2":""}`,children:e.images.map((e,t)=>(0,r.jsx)("div",{className:"relative w-16 h-16 rounded-lg overflow-hidden border border-white/20 cursor-pointer hover:opacity-90 transition-opacity",onClick:()=>j(e),children:(0,r.jsx)("img",{src:`data:${e.media_type};base64,${e.data}`,alt:w("chat.imageN",{index:t+1}),className:"w-full h-full object-cover"})},t))}),e.content&&(0,r.jsxs)("div",{className:"break-words",children:[(0,r.jsx)(N.T,{content:e.content,isUser:P,isStreaming:e.isStreaming,enableMath:!1}),e.isStreaming&&(0,r.jsx)("span",{className:"inline-block w-2 h-4 ml-1 bg-current animate-pulse"})]}),V&&(v=(b=Array.isArray(g=V.input?.todos)?g:[]).filter(e=>"completed"===e.status).length,y=b.length,(0,r.jsx)("div",{className:`${e.content||_?"mt-2":""}`,children:(0,r.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden bg-secondary/50 px-3 py-2 space-y-1",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 mb-1.5",children:[(0,r.jsx)("div",{className:"flex-1 h-1 bg-secondary rounded-full overflow-hidden",children:(0,r.jsx)("div",{className:"h-full bg-green-500 rounded-full transition-all duration-300",style:{width:`${y>0?v/y*100:0}%`}})}),(0,r.jsxs)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:[v,"/",y]})]}),b.map((e,t)=>(0,r.jsxs)("div",{className:`flex items-center gap-1.5 ${"completed"===e.status?"opacity-50":""}`,children:["completed"===e.status?(0,r.jsx)(i.A,{className:"w-3 h-3 text-green-500 flex-shrink-0"}):"in_progress"===e.status?(0,r.jsx)(c.A,{className:"w-3 h-3 text-brand flex-shrink-0 animate-spin"}):(0,r.jsx)(u.A,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"}),(0,r.jsx)("span",{className:`text-xs truncate ${"completed"===e.status?"text-muted-foreground":"text-foreground"}`,children:"in_progress"===e.status&&e.activeForm?e.activeForm:e.content})]},t))]})})),W&&(0,r.jsx)("div",{className:`${e.content||_||V?"mt-2":""}`,children:(0,r.jsxs)("div",{className:"border border-brand/40 rounded-lg overflow-hidden bg-secondary/50",children:[(0,r.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-1.5 border-b border-border bg-brand/10",children:[(0,r.jsx)("span",{className:"text-sm",children:"\uD83D\uDCCB"}),(0,r.jsx)("span",{className:"text-xs font-medium text-foreground",children:w("chat.planTitle",{defaultValue:"Plan (awaiting your review)"})})]}),(0,r.jsx)("div",{className:"px-3 py-2",children:(0,r.jsx)(N.T,{content:W,isUser:!1,enableMath:!1})}),x&&(0,r.jsxs)("div",{className:"px-3 py-2 border-t border-border flex items-center justify-between gap-2",children:[(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:w("chat.planApproveHint",{defaultValue:"本环境无审批弹窗,点此退出 Plan 并执行"})}),(0,r.jsxs)("button",{onClick:()=>x(),disabled:p,className:"flex items-center gap-1.5 px-3 py-1 rounded-md bg-brand text-white text-xs font-medium hover:bg-brand/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors flex-shrink-0",children:[(0,r.jsx)("span",{children:"✓"}),(0,r.jsx)("span",{children:w("chat.approvePlan",{defaultValue:"批准并执行"})})]})]})]})}),z.length>0&&(0,r.jsx)("div",{className:`${e.content||_||V?"mt-2":""}`,children:(0,r.jsx)("div",{className:"border border-border rounded-lg overflow-hidden bg-secondary/50 px-3 py-2 space-y-0.5",children:z.map(e=>(0,r.jsxs)("button",{onClick:()=>X(e),className:"flex items-center gap-1.5 w-full text-left hover:bg-accent rounded px-1 py-0.5 transition-colors group/md",children:[(0,R.aR)(e)?(0,r.jsx)("svg",{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4"})}):(0,r.jsx)("svg",{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground group-hover/md:text-foreground truncate",children:e.split("/").pop()})]},e))})}),K.length>0&&(0,r.jsx)("div",{className:`${e.content||_||V||z.length>0?"mt-2":""}`,children:(0,r.jsx)("div",{className:"border border-border rounded-lg overflow-hidden bg-secondary/50",children:(0,r.jsxs)("table",{className:"w-full text-xs",children:[(0,r.jsx)("thead",{children:(0,r.jsxs)("tr",{className:"border-b border-border text-muted-foreground",children:[(0,r.jsx)("th",{className:"px-2 py-1.5 text-left font-medium w-[60px]",children:"Tool"}),(0,r.jsx)("th",{className:"px-2 py-1.5 text-left font-medium",children:"Previous"}),(0,r.jsx)("th",{className:"px-2 py-1.5 text-left font-medium",children:"Action"}),(0,r.jsx)("th",{className:"px-2 py-1.5 text-left font-medium",children:"Expect"})]})}),(0,r.jsx)("tbody",{children:K.map((e,t)=>(0,r.jsxs)("tr",{className:t<K.length-1?"border-b border-border/50":"",children:[(0,r.jsx)("td",{className:"px-2 py-1 text-muted-foreground font-mono",children:e.toolName}),(0,r.jsx)("td",{className:"px-2 py-1 text-muted-foreground",children:e.previous||"—"}),(0,r.jsx)("td",{className:"px-2 py-1 text-foreground",children:e.current}),(0,r.jsx)("td",{className:"px-2 py-1 text-muted-foreground",children:e.expect||"—"})]},t))})]})})}),H.length>0&&(0,r.jsx)("div",{className:`${e.content||_?"mt-2":""}`,children:F>0?(0,r.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden bg-secondary",children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsxs)("button",{onClick:()=>S(!C),className:"flex-1 px-3 py-1.5 flex items-center gap-2 text-left hover:bg-accent transition-colors active:bg-muted",children:[(0,r.jsx)("span",{className:"text-sm",children:"\uD83D\uDD27"}),(0,r.jsx)("span",{className:"font-medium text-foreground",children:w("chat.toolCalls",{count:H.length})}),(0,r.jsx)("span",{className:"ml-auto text-muted-foreground text-sm",children:C?w("chat.collapse"):w("chat.expand")})]}),B.length>0&&(0,r.jsx)("button",{onClick:()=>T(!0),className:"px-3 py-1.5 text-muted-foreground hover:text-foreground hover:bg-accent transition-colors border-l border-border",title:w("chat.viewQuestions"),children:(0,r.jsx)(d.A,{className:"w-4 h-4"})}),O&&(0,r.jsx)("button",{onClick:()=>L(!0),className:"px-3 py-1.5 text-muted-foreground hover:text-foreground hover:bg-accent transition-colors border-l border-border",title:w("chat.viewAllFileChanges"),children:(0,r.jsx)(m.A,{className:"w-4 h-4"})})]}),C&&(0,r.jsx)("div",{className:"border-t border-border p-2 space-y-1",children:H.map((e,s)=>(0,r.jsx)(A,{toolCall:e,cwd:t,sessionId:n},`${e.id}-${s}`))})]}):H.map((e,s)=>(0,r.jsx)(A,{toolCall:e,cwd:t,sessionId:n},`${e.id}-${s}`))})]}),!P&&(0,r.jsxs)("div",{className:"self-start mt-2 ml-1 flex flex-col gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.content&&(0,r.jsx)("button",{onClick:Y,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:w("chat.copyMessage"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),D&&(0,r.jsx)("button",{onClick:Q,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:w("chat.forkSession"),children:(0,r.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("circle",{cx:"12",cy:"18",r:"3"}),(0,r.jsx)("circle",{cx:"6",cy:"6",r:"3"}),(0,r.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,r.jsx)("path",{d:"M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9"}),(0,r.jsx)("path",{d:"M12 12v3"})]})})]})]})]}),k&&(0,r.jsx)(es,{image:k,onClose:()=>j(null)}),E&&e.toolCalls&&(0,r.jsx)(G,{toolCalls:e.toolCalls,cwd:t,onClose:()=>L(!1)}),M&&B.length>0&&(0,r.jsx)(U,{toolCalls:B,onClose:()=>T(!1)}),q&&null!==Z&&((0,R.aR)(q)?(0,r.jsx)(ea,{filePath:q,content:Z,onClose:()=>X(null)}):(0,r.jsx)(el,{filePath:q,content:Z,cwd:t||"",onClose:()=>X(null)}))]})});var ei=n(1058),ec=n(90717),eu=n(89109),ed=n(7320);let em=(0,s.forwardRef)(function({messages:e,isLoading:t,cwd:n,sessionId:a,engine:o,apiRetryInfo:i,ptyNotice:c,hasMoreHistory:u,isLoadingMore:d,onLoadMore:m,onFork:f,isActive:x=!0,onContentSearch:p,onApprovePlan:g},b){let{t:v}=(0,h.Bd)(),y=(0,s.useRef)(null),w=(0,s.useRef)(null),k=(0,s.useRef)(null),j=(0,s.useRef)(null),[C,N]=(0,s.useState)(null),[S,E]=(0,s.useState)(!0),[L,M]=(0,s.useState)(!1),[R,T]=(0,s.useState)(!1);(0,s.useEffect)(()=>{N(j.current)},[]);let{isSearchVisible:$,searchQuery:I,setSearchQuery:P,matches:_,currentMatchIndex:A,goToNextMatch:F,goToPrevMatch:D,closeSearch:O,searchInputRef:V,handleSearchKeyDown:B}=function(e){let[t,n]=(0,s.useState)(!1),[r,l]=(0,s.useState)(""),[a,o]=(0,s.useState)([]),[i,c]=(0,s.useState)(0),u=(0,s.useRef)(null),d=(0,s.useRef)([]),m=(0,s.useCallback)(()=>{let t=e.current;t&&(t.querySelectorAll("mark.chat-search-match, mark.chat-search-current").forEach(e=>{let t=e.parentNode;t&&(t.replaceChild(document.createTextNode(e.textContent||""),e),t.normalize())}),d.current=[])},[e]),h=(0,s.useCallback)(t=>{if(m(),!t||!e.current){o([]),c(0);return}let n=[],r=[],s=t.toLowerCase();e.current.querySelectorAll("[data-message-id]").forEach(e=>{let l,a=e.getAttribute("data-message-id")||"",o=0,i=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,null),c=[];for(;l=i.nextNode();)c.push(l);for(let e of c){let l=(e.textContent||"").toLowerCase(),i=0,c=[];for(;;){let e=l.indexOf(s,i);if(-1===e)break;c.push({start:e,end:e+t.length}),i=e+1}if(0!==c.length)for(let t=c.length-1;t>=0;t--){let s=c[t];e.splitText(s.end);let l=e.splitText(s.start),i=document.createElement("mark");i.className="chat-search-match",i.textContent=l.textContent,l.parentNode.replaceChild(i,l),n.push({messageId:a,markIndex:o}),r.push(i),o++}}}),n.reverse(),r.reverse(),d.current=r,o(n),c(n.length>0?0:-1)},[e,m]);(0,s.useEffect)(()=>{queueMicrotask(()=>h(r))},[r,h]),(0,s.useEffect)(()=>{let e=d.current;e.forEach((e,t)=>{e.className=t===i?"chat-search-current":"chat-search-match"}),i>=0&&i<e.length&&e[i].scrollIntoView({behavior:"smooth",block:"center"})},[i,a]);let f=(0,s.useCallback)(()=>{0!==a.length&&c(e=>(e+1)%a.length)},[a.length]),x=(0,s.useCallback)(()=>{0!==a.length&&c(e=>(e-1+a.length)%a.length)},[a.length]),p=(0,s.useCallback)(()=>{n(!0),setTimeout(()=>u.current?.focus(),0)},[]),g=(0,s.useCallback)(()=>{n(!1),l(""),m(),o([]),c(0)},[m]),b=(0,s.useCallback)(e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?x():f()),"Escape"===e.key&&g()},[f,x,g]);return(0,s.useEffect)(()=>{let t=e.current;if(!t)return;let n=e=>{(e.metaKey||e.ctrlKey)&&"f"===e.key&&(e.preventDefault(),e.stopPropagation(),p())};return t.addEventListener("keydown",n),()=>t.removeEventListener("keydown",n)},[e,p]),{isSearchVisible:t,searchQuery:r,setSearchQuery:l,matches:a,currentMatchIndex:i,goToNextMatch:f,goToPrevMatch:x,openSearch:p,closeSearch:g,searchInputRef:u,handleSearchKeyDown:b}}(j),W=(0,l.nH)(),H=(0,s.useRef)(null),z=(0,s.useRef)(()=>{}),{addComment:K,refresh:U}=(0,ei._)({cwd:n||"",filePath:ec.Un}),[q,X]=(0,s.useState)(null),[Z,J]=(0,s.useState)(null),Y=(0,s.useCallback)(e=>{if(q||Z)return;let t=window.getSelection();if(!t||t.isCollapsed||!t.rangeCount){H.current=null,z.current();return}let n=t.toString().trim();if(!n){H.current=null,z.current();return}let r=t.anchorNode instanceof HTMLElement?t.anchorNode:t.anchorNode?.parentElement;if(r?.closest('[data-role="user"]')){H.current=null,z.current();return}H.current={x:e.clientX,y:e.clientY,range:{start:0,end:0},selectedText:n,lineSnapshot:n},z.current()},[q,Z]),Q=(0,s.useCallback)(e=>{let t=e.target;!(t.closest(".floating-toolbar")||t.closest('[class*="z-[200]"]'))&&H.current&&(H.current=null,z.current())},[]),G=(0,s.useCallback)(()=>{let e=H.current;e&&(X({x:e.x,y:e.y,text:e.selectedText}),H.current=null,z.current(),window.getSelection()?.removeAllRanges())},[]),ee=(0,s.useCallback)(()=>{let e=H.current;e&&(J({x:e.x,y:e.y,text:e.selectedText}),H.current=null,z.current(),window.getSelection()?.removeAllRanges())},[]),et=(0,s.useCallback)(()=>{let e=H.current;if(!e||!p)return;let t=e.selectedText.trim();H.current=null,z.current(),window.getSelection()?.removeAllRanges(),t&&p(t)},[p]),en=(0,s.useCallback)(async e=>{q&&(await K(0,0,e,q.text),X(null))},[q,K]),er=(0,s.useCallback)(async e=>{if(Z&&W&&n)try{let t=(await (0,ec.$3)(n)).map(e=>({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0}));t.push({filePath:ec.Un,startLine:0,endLine:0,codeContent:Z.text});let r=(0,ec.Gw)(t,e);W.sendMessage(r),await (0,ec.RP)(n),U(),J(null)}catch(e){console.error("Failed to send to AI:",e)}},[Z,W,n,U]),es=(0,s.useMemo)(()=>{let t=new Set;return e.filter(e=>!t.has(e.id)&&(t.add(e.id),!0))},[e]),el=(0,s.useRef)(0),ea=(0,s.useRef)(!1),em=(0,s.useCallback)(()=>{let e=k.current;return!e||e.scrollHeight-e.scrollTop-e.clientHeight<50},[]),eh=(0,s.useCallback)(()=>{let e=k.current;return!e||e.scrollTop<50},[]),ef=(0,s.useCallback)(()=>{let e=em(),t=eh();if(E(e),M(!t),T(!e),t&&u&&!d&&m){let e=k.current;e&&(el.current=e.scrollHeight,ea.current=!0),m()}},[em,eh,u,d,m]),ex=(0,s.useCallback)(()=>{w.current?.scrollIntoView({behavior:"smooth"})},[]),ep=(0,s.useCallback)(()=>{y.current?.scrollIntoView({behavior:"smooth"})},[]),eg=(0,s.useCallback)(e=>{let t=k.current;if(!t)return;let n=t.querySelector(`[data-message-id="${e}"]`);n&&(n.scrollIntoView({behavior:"smooth",block:"center"}),n.classList.add("ring-2","ring-brand","ring-offset-2"),setTimeout(()=>{n.classList.remove("ring-2","ring-brand","ring-offset-2")},2e3))},[]);(0,s.useImperativeHandle)(b,()=>({scrollToMessage:eg}),[eg]);let eb=(0,s.useRef)(0),ev=(0,s.useRef)(!0);(0,s.useEffect)(()=>{let t=eb.current,n=e.length;eb.current=n,!ev.current&&S&&n>t&&y.current?.scrollIntoView({behavior:"smooth"})},[e,S]),(0,s.useEffect)(()=>{S&&t&&y.current?.scrollIntoView({behavior:"smooth"})},[t,S]),(0,s.useEffect)(()=>{if(ea.current&&!d){let e=k.current;if(e){let t=e.scrollHeight-el.current;e.scrollTop=t,ea.current=!1}}},[e,d]);let ey=(0,s.useRef)(!1);return(0,s.useEffect)(()=>{x&&ey.current&&e.length>0&&(ey.current=!1,y.current?.scrollIntoView({behavior:"instant"}))},[x,e.length]),(0,s.useEffect)(()=>{ev.current&&e.length>0&&(ev.current=!1,x?y.current?.scrollIntoView({behavior:"instant"}):ey.current=!0)},[e.length,x]),(0,r.jsxs)("div",{ref:j,className:"relative flex-1 min-h-0 overflow-hidden flex flex-col outline-none",tabIndex:-1,onMouseUp:Y,onMouseDown:Q,children:[$&&(0,r.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-2 px-3 py-2 bg-secondary border-b border-border",children:[(0,r.jsx)("input",{ref:V,type:"text",value:I,onChange:e=>P(e.target.value),onKeyDown:B,placeholder:v("codeViewer.searchChat"),className:"flex-1 max-w-xs px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:_.length>0?`${A+1}/${_.length}`:v("common.noMatch")}),(0,r.jsx)("button",{onClick:D,disabled:0===_.length,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:v("codeViewer.prevShiftEnter"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"})})}),(0,r.jsx)("button",{onClick:F,disabled:0===_.length,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:v("codeViewer.nextEnter"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})}),(0,r.jsx)("button",{onClick:O,className:"p-1 rounded hover:bg-accent",title:v("codeViewer.closeEsc"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,r.jsx)("div",{ref:k,onScroll:ef,className:"relative flex-1 min-h-0 overflow-y-auto p-4",children:0!==e.length||t?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{ref:w}),u&&(0,r.jsx)("div",{className:"flex justify-center py-3",children:d?(0,r.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground text-sm",children:[(0,r.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"}),(0,r.jsx)("span",{children:v("chat.loadMoreHistory")})]}):(0,r.jsx)("button",{onClick:m,className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:v("chat.scrollUpForMore")})}),es.map(e=>(0,r.jsx)("div",{"data-message-id":e.id,className:"transition-[box-shadow] duration-300",children:(0,r.jsx)(eo,{message:e,cwd:n,sessionId:a,onFork:f,onApprovePlan:g,isLoading:t})},e.id)),t&&(0,r.jsx)("div",{className:"flex justify-start mb-4",children:(0,r.jsxs)("div",{className:"bg-accent rounded-2xl rounded-bl-md px-4 py-3 max-w-[90%]",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,r.jsx)("span",{className:"inline-block w-5 h-5 border-2 border-brand border-t-transparent rounded-full animate-spin"}),(0,r.jsx)("span",{className:"text-sm",children:"claude2"===o?"Claude 2 is thinking...":"codex"===o?"Codex is thinking...":"kimi"===o?"Kimi is thinking...":"ollama"===o?"Ollama is thinking...":"deepseek"===o?"DeepSeek is thinking...":v("chat.claudeThinking")})]}),i&&(0,r.jsxs)("div",{className:"mt-2 flex items-start gap-2 text-xs text-amber-400 border-t border-border/50 pt-2",children:[(0,r.jsx)("svg",{className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0 animate-spin",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),(0,r.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,r.jsxs)("div",{children:["Retrying API call (attempt ",i.attempt,i.maxRetries>0?`/${i.maxRetries}`:"",i.delayMs>0?`, delay ${(i.delayMs/1e3).toFixed(1)}s`:"",")"]}),(i.errorStatus||i.error)&&(0,r.jsxs)("div",{className:"text-muted-foreground/80 break-words",children:[i.errorStatus?`${i.errorStatus}`:"",i.errorStatus&&i.error?" \xb7 ":"",i.error||""]})]})]}),c&&(0,r.jsxs)("div",{className:"mt-2 flex items-start gap-2 text-xs text-amber-400 border-t border-border/50 pt-2",children:[(0,r.jsx)("svg",{className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01M5.07 19h13.86c1.54 0 2.5-1.67 1.73-3L13.73 4a2 2 0 00-3.46 0L3.34 16c-.77 1.33.19 3 1.73 3z"})}),(0,r.jsx)("div",{className:"flex-1 min-w-0 break-words",children:c})]})]})}),(0,r.jsx)("div",{ref:y})]}):(0,r.jsx)("div",{className:"flex items-center justify-center h-full text-slate-9",children:(0,r.jsxs)("div",{className:"text-center",children:[(0,r.jsx)("div",{className:"text-4xl mb-4",children:"\uD83D\uDCAC"}),(0,r.jsx)("div",{children:v("chat.startConversation")})]})})}),L&&e.length>0&&(0,r.jsx)("button",{onClick:ex,className:"absolute top-2 left-1/2 -translate-x-1/2 p-2 bg-card text-muted-foreground hover:text-foreground shadow-md rounded-full transition-all hover:shadow-lg active:scale-95",title:v("chat.jumpToStart"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"})})}),R&&e.length>0&&(0,r.jsx)("button",{onClick:ep,className:"absolute bottom-2 left-1/2 -translate-x-1/2 p-2 bg-card text-muted-foreground hover:text-foreground shadow-md rounded-full transition-all hover:shadow-lg active:scale-95",title:v("chat.jumpToLatest"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})}),C&&(0,r.jsx)(eu.f,{floatingToolbarRef:H,bumpRef:z,container:C,onAddComment:G,onSendToAI:ee,onSearch:p?et:void 0,isChatLoading:W?.isLoading}),q&&C&&(0,r.jsx)(ed.t,{x:q.x,y:q.y,range:{start:0,end:0},lineSnapshot:q.text,container:C,onSubmit:en,onClose:()=>X(null)}),Z&&C&&(0,r.jsx)(ed.G,{x:Z.x,y:Z.y,range:{start:0,end:0},lineSnapshot:Z.text,container:C,onSubmit:er,onClose:()=>J(null),isChatLoading:W?.isLoading})]})})},17196:(e,t,n)=>{n.d(t,{Np:()=>u,ZD:()=>i,b8:()=>c,kS:()=>a,sQ:()=>o});var r=n(67014);let s=null,l=["typescript","tsx","javascript","jsx","html","css","scss","json","yaml","python","go","rust","java","ruby","php","bash","shell","markdown","sql","c","cpp","swift","kotlin","dart","lua","graphql","xml"];function a(){return s||(s=(0,r.O_)({themes:["github-dark","github-light"],langs:[...l]})),s}function o(e){let t=e.split("/").pop()?.toLowerCase()||"",n=t.split(".").pop()?.toLowerCase();if(".env"===t||t.startsWith(".env.")||"dockerfile"===t||t.startsWith("dockerfile.")||"makefile"===t)return"bash";let r={ts:"typescript",tsx:"tsx",js:"javascript",jsx:"jsx",mjs:"javascript",cjs:"javascript",html:"html",htm:"html",css:"css",scss:"scss",json:"json",yaml:"yaml",yml:"yaml",xml:"xml",py:"python",go:"go",rs:"rust",java:"java",kt:"kotlin",rb:"ruby",php:"php",cs:"cpp",cpp:"cpp",c:"c",h:"c",sh:"bash",bash:"bash",zsh:"bash",md:"markdown",mdx:"markdown",sql:"sql",swift:"swift",dart:"dart",lua:"lua",graphql:"graphql",gql:"graphql",toml:"yaml",sass:"scss",less:"css",scala:"java",r:"python",vim:"bash",env:"bash"}[n||""]||"text";return l.includes(r)?r:"text"}function i(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function c(e){return e.map(e=>e.color?`<span style="color:${e.color}">${i(e.content)}</span>`:i(e.content)).join("")}function u(e,t,n,r){if(!t)return[];let s=[],l=n?t:t.toLowerCase();for(let t=0;t<e.length;t++){let a=n?e[t]:e[t].toLowerCase(),o=0;for(;;){let e=a.indexOf(l,o);if(-1===e)break;let n=e+l.length;if(r){let r=e>0?a[e-1]:" ",l=n<a.length?a[n]:" ",o=!/\w/.test(r),i=!/\w/.test(l);o&&i&&s.push({lineIndex:t,startCol:e,endCol:n})}else s.push({lineIndex:t,startCol:e,endCol:n});o=e+1}}return s}},20917:(e,t,n)=>{n.d(t,{e:()=>i});var r=n(12115),s=n(48948),l=n(69809),a=n(2111),o=n(95942);function i(e,t,{sessionId:n,cwd:c,engine:u,chatMode:d,planMode:m,ollamaModel:h,deepseekModel:f,onSessionId:x,onFetchTitle:p,onPtyOutput:g,onRunComplete:b}){let[v,y]=(0,r.useState)(!1),[w,k]=(0,r.useState)(null),[j,C]=(0,r.useState)(null),[N,S]=(0,r.useState)(null),[E,L]=(0,r.useState)(null),M=(0,r.useRef)(null),[R,T]=(0,r.useState)(null),$=(0,r.useRef)(R);$.current=R;let I=(0,r.useRef)(b);I.current=b;let P=(0,r.useRef)(!1),_=(0,r.useRef)(null),A=(0,r.useRef)(n);A.current=n;let F=(0,r.useRef)(null),D=(0,r.useRef)(null),O=(0,r.useRef)(null),V=(0,r.useRef)(!1),B=(0,r.useRef)(!1),W=(0,r.useRef)(0),H=(0,r.useCallback)(()=>{let e=F.current;if(e&&e.text){let{messageId:n,text:r}=e;t(e=>(0,s.F)(e,{type:"stream_event",event:{type:"content_block_delta",delta:{type:"text_delta",text:r}}},{engine:u,assistantId:n})),F.current={messageId:n,text:""}}D.current=null},[t,u]),z=(0,r.useCallback)(()=>{D.current&&(clearTimeout(D.current),D.current=null),_.current&&(clearTimeout(_.current),_.current=null),H(),y(!1);let e=$.current,n=O.current;e&&t(t=>t.map(t=>t.id===e.assistantId||t.id===n?{...t,isStreaming:!1}:t)),T(null),I.current?.()},[H,t]),K=(0,r.useCallback)(()=>{let e=$.current;fetch("/api/chat/stop",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:A.current,runId:e?.runKey})}).catch(()=>{}),z()},[z]),U=(0,r.useCallback)((e,n)=>{let r=e.type;if("pty_output"===r)return void g?.(e.data);if("pty_notice"===r){let r=e.messageKey?l.A.t(e.messageKey,e.params||{}):e.message;if(!r)return;e.terminal?t(e=>e.map(e=>e.id===n?{...e,content:r,isStreaming:!1}:e)):L(r);return}if("system"===r&&"init"===e.subtype){let n=e.session_id;if(x(n),A.current=n,S(null),V.current){let e=`auto-asst-${++W.current}`;O.current=e,t(t=>[...t,{id:e,role:"assistant",content:"",toolCalls:[],isStreaming:!0,runKey:$.current?.runKey}])}B.current=!0;return}if("system"===r&&"task_notification"===e.subtype){if(!B.current){let n=e.status,r=e.summary||"",s=e.task_id,l=`<task-notification>
|
|
1
|
+
"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[217],{1058:(e,t,n)=>{n.d(t,{_:()=>o});var r=n(12115),s=n(90717),l=n(86957),a=n(46456);function o({cwd:e,filePath:t}){let[n,i]=(0,r.useState)([]),[c,u]=(0,r.useState)(!1),[d,m]=(0,r.useState)(null),h=(0,r.useCallback)(async()=>{if(!e||!t)return;u(!0),m(null);let n=await l.t4.runPromiseExit((0,a.lb)(e,t));if("Success"===n._tag)i(n.value.comments??[]);else{let e="Fail"===n.cause._tag?n.cause.error:null,t=e?.cause;m(t instanceof Error?t.message:"Failed to load comments")}u(!1)},[e,t]);(0,r.useEffect)(()=>{h()},[h]),(0,r.useEffect)(()=>(0,s.zL)(()=>{h()}),[h]);let f=(0,r.useCallback)(async(n,r,s,o)=>{let c=await l.t4.runPromiseExit((0,a.BC)({cwd:e,filePath:t,startLine:n,endLine:r,content:s,...o?{selectedText:o}:{}}));if("Success"===c._tag&&c.value.comment){let e=c.value.comment;return i(t=>[...t,e]),e}return"Failure"===c._tag&&console.error("Failed to add comment:",c.cause),null},[e,t]),x=(0,r.useCallback)(async(t,n)=>{let r=await l.t4.runPromiseExit((0,a.vv)(e,t,n));if("Success"===r._tag&&r.value.comment){let e=r.value.comment;return i(n=>n.map(n=>n.id===t?e:n)),!0}return"Failure"===r._tag&&console.error("Failed to update comment:",r.cause),!1},[e]),p=(0,r.useCallback)(async t=>{let n=await l.t4.runPromiseExit((0,a.Tu)(e,t));return"Success"===n._tag?(i(e=>e.filter(e=>e.id!==t)),!0):(console.error("Failed to delete comment:",n.cause),!1)},[e]),g=(0,r.useCallback)(e=>n.filter(t=>e>=t.startLine&&e<=t.endLine),[n]);return{comments:n,isLoading:c,error:d,addComment:f,updateComment:x,deleteComment:p,refresh:h,getCommentsForLine:g}}},3292:(e,t,n)=>{n.d(t,{P:()=>c});var r=n(12115),s=n(95045),l=n(75346),a=n(49433),o=n(86957),i=n(82680);function c(){let[e,t]=(0,r.useState)([]),n=(0,r.useCallback)(()=>{let e=a.tryPromise({try:async()=>{let e=await fetch("/api/pinned-sessions");return await e.json()},catch:e=>new i.uV({message:"loadPinnedSessions failed",cause:e})});o.t4.runPromise(e.pipe(a.match({onSuccess:e=>t(e.sessions||[]),onFailure:()=>{}})))},[]);(0,r.useEffect)(()=>{n()},[n]),(0,r.useEffect)(()=>{let e=e=>{e.data?.type==="PINNED_SESSIONS_CHANGED"&&n()};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[n]);let c=(0,r.useCallback)(e=>{t(e);let n=a.tryPromise({try:async()=>{await fetch("/api/pinned-sessions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessions:e})})},catch:e=>new i.uV({message:"savePinnedSessions failed",cause:e})});o.t4.runFork(n.pipe(a.orElse(()=>a.void))),(0,s.F)(l.n.PinnedSessionsChanged,{})},[]),u=(0,r.useCallback)(t=>e.some(e=>e.sessionId===t),[e]),d=(0,r.useCallback)((t,n,r)=>{e.some(e=>e.sessionId===t)||c([...e,{sessionId:t,cwd:n,customTitle:r}])},[e,c]),m=(0,r.useCallback)(t=>{c(e.filter(e=>e.sessionId!==t))},[e,c]),h=(0,r.useCallback)((t,n)=>{c(e.map(e=>e.sessionId===t?{...e,customTitle:n}:e))},[e,c]);return{pinnedSessions:e,isPinned:u,pinSession:d,unpinSession:m,updateTitle:h,reorder:(0,r.useCallback)(e=>{c(e)},[c]),reload:n}}},5135:(e,t,n)=>{n.d(t,{M:()=>k});var r=n(95155),s=n(12115),l=n(79114),a=n(47650),o=n(70188),i=n(89109),c=n(7320),u=n(37614),d=n(1058),m=n(48347),h=n(90717),f=n(13219),x=n(97251),p=n(11890),g=n(47215),b=n(47176),v=n(79968),y=n(27570);let w=[x.W];function k({content:e,filePath:t,cwd:n,onClose:x,sourceFile:j,embedded:C=!1,onLocalMdLink:N,scrollToAnchor:S}){let E=j||(n&&t.startsWith(n)?t.slice(n.endsWith("/")?n.length:n.length+1):t),{t:L}=(0,l.Bd)(),M=(0,o.iN)(),R=(0,m.r)(),{comments:T,addComment:$,updateComment:I,deleteComment:P,refresh:_}=(0,d._)({cwd:n,filePath:t}),[A,F]=(0,s.useState)(!1),[D,O]=(0,s.useState)(null),[V,B]=(0,s.useState)(null),[W,H]=(0,s.useState)(null),z=(0,s.useMemo)(()=>e.split("\n"),[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>F(!0))},[]);let[K,U]=(0,s.useState)(null),q=(0,s.useRef)(null);(0,s.useEffect)(()=>{q.current!==K&&U(q.current)});let X=(0,s.useCallback)(e=>{if(!N||/^[a-z][a-z0-9+.-]*:/i.test(e))return!1;let t=e.indexOf("#"),n=t>=0?e.slice(0,t):e,r=t>=0?e.slice(t+1):null;if(!n)return!1;let s=n;try{s=decodeURIComponent(n)}catch{}return!!(0,g.e$)(s)&&(N((0,g.WU)(E,s),r),!0)},[N,E]);(0,s.useEffect)(()=>{if(!S)return;let e=setTimeout(()=>{(0,p.O)(q.current,S)},80);return()=>clearTimeout(e)},[S,e]);let{toolbarRef:Z,bumpRef:J,clearToolbar:Y}=(0,y.L)({enabled:!0,container:K,resolveLineRange:e=>{let t=function(e){let t=e.nodeType===Node.TEXT_NODE?e.parentElement:e;if(!t||!("closest"in t))return null;let n=t.closest("[data-source-start]");if(!n)return null;let r=n.getAttribute("data-source-start"),s=n.getAttribute("data-source-end");return r&&s?{start:parseInt(r,10),end:parseInt(s,10)}:null}(e);return t?{start:t.start,end:t.end}:null},buildLineSnapshot:({start:e,end:t})=>{let n=Math.max(0,e-1),r=Math.min(z.length,t);return z.slice(n,r).join("\n")}}),Q=(0,s.useCallback)(()=>{let e=Z.current;e&&(O({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),Y())},[Y,Z]),G=(0,s.useCallback)(()=>{let e=Z.current;e&&(B({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),Y())},[Y,Z]),ee=(0,s.useCallback)(async e=>{D&&(await $(D.range.start,D.range.end,e,D.selectedText),O(null))},[D,$]),et=(0,s.useCallback)(async e=>{if(V&&R)try{let r=await (0,h.$3)(n),s=[];for(let e of r)s.push({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0});s.push({filePath:t,startLine:V.range.start,endLine:V.range.end,codeContent:V.lineSnapshot});let l=(0,h.Gw)(s,e);R.sendMessage(l),await (0,h.RP)(n),_(),B(null)}catch(e){console.error("Failed to send to AI:",e)}},[V,R,t,n,_]),en=(0,s.useMemo)(()=>{if(0===T.length)return[];let e=new Map;for(let t of T){let n=`${t.startLine}-${t.endLine}`;e.has(n)||e.set(n,[]),e.get(n).push(t)}return Array.from(e.entries()).map(([e,t])=>({key:e,startLine:t[0].startLine,endLine:t[0].endLine,comments:t}))},[T]),[er,es]=(0,s.useState)([]);return(0,s.useEffect)(()=>{if(0===en.length||!q.current)return void queueMicrotask(()=>es([]));let e=setTimeout(()=>{let e=q.current;if(!e)return;let t=[],n=e.querySelectorAll("[data-source-start]");for(let r of en){let s=null,l=1/0;for(let e of n){let t=parseInt(e.getAttribute("data-source-start"),10),n=parseInt(e.getAttribute("data-source-end"),10);if(t<=r.startLine&&n>=r.endLine){let r=n-t;r<l&&(l=r,s=e)}}if(s){let n=e.getBoundingClientRect(),l=s.getBoundingClientRect();t.push({key:r.key,top:l.top-n.top+e.scrollTop,comments:r.comments})}}es(t)},100);return()=>clearTimeout(e)},[en,e]),(0,s.useEffect)(()=>{let e=e=>{if("Escape"===e.key){if(V){B(null),e.stopPropagation();return}if(D){O(null),e.stopPropagation();return}if(Z.current){Z.current=null,J.current(),e.stopPropagation();return}if(W){H(null),e.stopPropagation();return}x?.()}};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[V,D,W,x]),(0,r.jsxs)(r.Fragment,{children:[!C&&(0,r.jsxs)("div",{className:"px-4 py-3 border-b border-border flex items-center justify-between flex-shrink-0",children:[(0,r.jsx)("span",{className:"text-sm font-medium text-foreground truncate",children:t}),(0,r.jsxs)("div",{className:"flex items-center gap-3",children:[(0,r.jsx)(v.ShareReviewToggle,{content:e,sourceFile:E}),(0,r.jsx)("button",{onClick:x,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:L("common.close"),children:(0,r.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,r.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[(0,r.jsx)(b.l,{content:e,containerRef:q}),(0,r.jsxs)("div",{className:"flex-1 overflow-auto relative",ref:q,children:[(0,r.jsx)("div",{className:"p-6",children:(0,r.jsx)(f.T,{content:e,rehypePlugins:w,onLinkClick:X})}),er.map(({key:e,top:t,comments:n})=>(0,r.jsx)("div",{className:"absolute right-3 cursor-pointer z-10",style:{top:t},onClick:e=>{e.stopPropagation(),H({comment:n[0],x:e.clientX,y:e.clientY})},children:(0,r.jsx)("div",{className:"w-5 h-5 rounded-full bg-amber-500/80 text-white text-xs flex items-center justify-center shadow-sm hover:bg-amber-500 transition-colors",children:n.length})},e))]})]}),A&&M&&(0,a.createPortal)((0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(i.f,{floatingToolbarRef:Z,bumpRef:J,container:M,onAddComment:Q,onSendToAI:G,isChatLoading:R?.isLoading}),D&&(0,r.jsx)(c.t,{x:D.x,y:D.y,range:D.range,lineSnapshot:D.lineSnapshot,container:M,onSubmit:ee,onClose:()=>O(null)}),V&&(0,r.jsx)(c.G,{x:V.x,y:V.y,range:V.range,filePath:t,lineSnapshot:V.lineSnapshot,container:M,onSubmit:et,onClose:()=>B(null),isChatLoading:R?.isLoading}),W&&(0,r.jsx)(u.t,{x:W.x,y:W.y,comment:W.comment,container:M,onClose:()=>H(null),onUpdateComment:I,onDeleteComment:P})]}),M)]})}},7320:(e,t,n)=>{n.d(t,{G:()=>o,t:()=>a});var r=n(95155),s=n(12115),l=n(79114);function a({x:e,y:t,range:n,lineSnapshot:o,container:i,onSubmit:c,onClose:u}){let{t:d}=(0,l.Bd)(),[m,h]=(0,s.useState)(""),[f,x]=(0,s.useState)(!1),p=(0,s.useRef)(null),g=(0,s.useRef)(null),[b,v]=(0,s.useState)({x:0,y:0}),y=o?.split("\n").slice(0,5).join("\n"),w=!!o&&o.split("\n").length>5;return(0,s.useEffect)(()=>{if(p.current&&i){let n=i.getBoundingClientRect(),r=p.current.getBoundingClientRect(),s=e-n.left,l=t-n.top;s+r.width>n.width-16&&(s=n.width-r.width-16),s<16&&(s=16),l+r.height>n.height-16&&(l=l-r.height-8),l<16&&(l=16),queueMicrotask(()=>v({x:s,y:l}))}},[e,t,i]),(0,s.useEffect)(()=>{g.current?.focus()},[]),(0,s.useEffect)(()=>{let e=e=>{f||!p.current||p.current.contains(e.target)||u()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[u,f]),(0,r.jsxs)("div",{ref:p,className:"absolute z-[200] w-[640px] bg-card border border-border rounded-lg shadow-lg overflow-hidden",style:{left:b.x,top:b.y},children:[(0,r.jsx)("div",{className:"px-3 py-2 bg-amber-9/10 border-b border-border",children:(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsx)("span",{className:"text-xs font-medium text-amber-11",children:d("comments.addComment")}),(n.start>0||n.end>0)&&(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:d("comments.lineRange",{start:n.start,end:n.end})})]})}),o&&(0,r.jsx)("div",{className:"px-3 py-2 bg-secondary/50 border-b border-border max-h-24 overflow-hidden",children:(0,r.jsxs)("pre",{className:"text-xs font-mono text-muted-foreground whitespace-pre-wrap break-all",children:[y,w&&(0,r.jsx)("span",{className:"text-muted-foreground/50",children:"..."})]})}),(0,r.jsxs)("div",{className:"p-2",children:[(0,r.jsx)("textarea",{ref:g,value:m,onChange:e=>h(e.target.value),placeholder:d("comments.inputPlaceholder"),className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card resize-none focus:outline-none focus:ring-1 focus:ring-ring disabled:opacity-50 disabled:cursor-not-allowed",rows:2,disabled:f,onKeyDown:e=>{"Enter"===e.key&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),!f&&m.trim()&&(x(!0),c(m.trim()))),"Escape"!==e.key||f||u()}}),(0,r.jsx)("div",{className:"mt-1 text-xs text-muted-foreground",children:d(f?"comments.submitting":"comments.enterSubmit")})]})]})}function o({x:e,y:t,range:n,filePath:a,lineSnapshot:i,container:c,onSubmit:u,onClose:d,isChatLoading:m}){let{t:h}=(0,l.Bd)(),[f,x]=(0,s.useState)(""),p=(0,s.useRef)(null),g=(0,s.useRef)(null),[b,v]=(0,s.useState)({x:0,y:0});(0,s.useEffect)(()=>{if(p.current&&c){let n=c.getBoundingClientRect(),r=p.current.getBoundingClientRect(),s=e-n.left,l=t-n.top;s+r.width>n.width-16&&(s=n.width-r.width-16),s<16&&(s=16),l+r.height>n.height-16&&(l=l-r.height-8),l<16&&(l=16),queueMicrotask(()=>v({x:s,y:l}))}},[e,t,c]),(0,s.useEffect)(()=>{g.current?.focus()},[]),(0,s.useEffect)(()=>{let e=e=>{p.current&&!p.current.contains(e.target)&&d()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[d]);let y=i?.split("\n").slice(0,5).join("\n"),w=!!i&&i.split("\n").length>5;return(0,r.jsxs)("div",{ref:p,className:"absolute z-[200] w-[640px] bg-card border border-border rounded-lg shadow-lg overflow-hidden",style:{left:b.x,top:b.y},children:[(0,r.jsxs)("div",{className:"px-3 py-2 bg-brand/10 border-b border-border",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsx)("span",{className:"text-xs font-medium text-brand",children:h("comments.askAI")}),(n.start>0||n.end>0)&&(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:h("comments.lineRange",{start:n.start,end:n.end})})]}),a&&(0,r.jsx)("div",{className:"mt-1 text-xs text-muted-foreground truncate",children:a})]}),i&&(0,r.jsx)("div",{className:"px-3 py-2 bg-secondary/50 border-b border-border max-h-24 overflow-hidden",children:(0,r.jsxs)("pre",{className:"text-xs font-mono text-muted-foreground whitespace-pre-wrap break-all",children:[y,w&&(0,r.jsx)("span",{className:"text-muted-foreground/50",children:"..."})]})}),(0,r.jsxs)("div",{className:"p-2",children:[(0,r.jsx)("textarea",{ref:g,value:f,onChange:e=>x(e.target.value),placeholder:h("comments.inputQuestion"),className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card resize-none focus:outline-none focus:ring-1 focus:ring-ring disabled:opacity-50 disabled:cursor-not-allowed",rows:2,disabled:m,onKeyDown:e=>{"Enter"===e.key&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),!m&&f.trim()&&(u(f.trim()),d())),"Escape"===e.key&&d()}}),(0,r.jsx)("div",{className:"mt-1 text-xs text-muted-foreground",children:h(m?"comments.aiGenerating":"comments.enterSend")})]})]})}},8988:(e,t,n)=>{n.d(t,{M:()=>em});var r=n(95155),s=n(12115),l=n(83897),a=n(64428),o=n(34075),i=n(12651),c=n(81165),u=n(16950),d=n(11019),m=n(12612),h=n(79114),f=n(86957),x=n(85839);function p({cwd:e,sessionId:t,toolCall:n,workflowRef:l,onClose:o}){let{t:i}=(0,h.Bd)(),[c,u]=(0,s.useState)(null),[d,m]=(0,s.useState)(null),[g,b]=(0,s.useState)(!1),v=(0,s.useRef)(void 0),y=l?!!l.running:!n?.result,w=(0,s.useCallback)(async()=>{let r=await f.t4.runPromiseExit((0,x.z)({cwd:e,sessionId:t,...l?{workflowId:l.runId,workflowAgentId:l.agentId}:{toolUseId:n?.id},ifFingerprint:v.current}));if(b(!0),"Success"!==r._tag||!r.value)return;let s=r.value;s.fingerprint&&(v.current=s.fingerprint),!s.notModified&&(s.messages&&u(s.messages),s.subagent&&m(s.subagent))},[e,t,n?.id,l?.runId,l?.agentId]);(0,s.useEffect)(()=>{if(w(),!y)return;let e=setInterval(w,5e3);return()=>clearInterval(e)},[y,w]);let k=(0,s.useRef)(null),j=(0,s.useRef)(!0);(0,s.useEffect)(()=>{let e=k.current;e&&j.current&&(e.scrollTop=e.scrollHeight)},[c]);let C="string"==typeof n?.input?.description?n.input.description:"",N=l?l.label||"":[d?.agentType,C].filter(Boolean).join(" \xb7 ");return(0,r.jsx)(a.ZL,{children:(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:o,children:(0,r.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-[90vh] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 px-4 py-3 border-b border-border flex-shrink-0",children:[(0,r.jsx)("span",{className:"text-base",children:"\uD83E\uDD16"}),(0,r.jsx)("span",{className:"font-medium text-sm text-foreground flex-shrink-0",children:i("chat.subagent")}),N&&(0,r.jsx)("span",{className:"text-xs text-muted-foreground truncate flex-1 min-w-0",title:N,children:N}),(0,r.jsxs)("span",{className:"ml-auto flex items-center gap-2 flex-shrink-0",children:[y&&(0,r.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"}),(0,r.jsx)("button",{onClick:o,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:i("common.close"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,r.jsx)("div",{ref:k,onScroll:()=>{let e=k.current;e&&(j.current=e.scrollTop+e.clientHeight>=e.scrollHeight-40)},className:"flex-1 overflow-y-auto px-4 py-3",children:null===c?(0,r.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:i(g?"chat.subagentEmpty":"common.loading")}):c.map(t=>(0,r.jsx)(eo,{message:t,cwd:e},t.id))})]})})})}function g(e){return e?e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e):"0"}function b(e){if(!e)return"–";let t=Math.round(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);return`${n}m${t%60}s`}let v={done:"text-green-9",running:"text-brand",queued:"text-muted-foreground",error:"text-red-9",failed:"text-red-9"};function y({cwd:e,sessionId:t,runId:n,isRunning:l,onClose:o}){let{t:i}=(0,h.Bd)(),[c,u]=(0,s.useState)(null),[d,m]=(0,s.useState)(!1),[v,k]=(0,s.useState)(null),j=(0,s.useRef)(void 0),C=l||null!=c&&"completed"!==c.status&&"failed"!==c.status,N=(0,s.useCallback)(async()=>{let r=await f.t4.runPromiseExit((0,x.z)({cwd:e,sessionId:t,workflowId:n,ifFingerprint:j.current}));if(m(!0),"Success"!==r._tag||!r.value)return;let s=r.value;s.fingerprint&&(j.current=s.fingerprint),!s.notModified&&s.workflow&&u(s.workflow)},[e,t,n]);(0,s.useEffect)(()=>{if(N(),!C)return;let e=setInterval(N,5e3);return()=>clearInterval(e)},[C,N]);let S=[];if(c?.agents){let e=new Map;for(let t of c.agents){let n=t.phaseTitle||i("chat.workflowUngrouped");e.has(n)||e.set(n,[]),e.get(n).push(t)}for(let[t,n]of e)S.push({title:t,agents:n})}let E=c?[c.workflowName,c.status,`${c.agentCount??c.agents?.length??0} ${i("chat.workflowAgents")}`,`${g(c.totalTokens)} tok`,b(c.durationMs)].filter(Boolean).join(" \xb7 "):"";return(0,r.jsxs)(a.ZL,{children:[(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:o,children:(0,r.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-[90vh] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 px-4 py-3 border-b border-border flex-shrink-0",children:[(0,r.jsx)("span",{className:"text-base",children:"\uD83E\uDDE9"}),(0,r.jsx)("span",{className:"font-medium text-sm text-foreground flex-shrink-0",children:i("chat.workflowRun")}),E&&(0,r.jsx)("span",{className:"text-xs text-muted-foreground truncate flex-1 min-w-0",title:E,children:E}),(0,r.jsxs)("span",{className:"ml-auto flex items-center gap-2 flex-shrink-0",children:[C&&(0,r.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"}),(0,r.jsx)("button",{onClick:o,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:i("common.close"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,r.jsx)("div",{className:"flex-1 overflow-y-auto px-4 py-3",children:null===c?(0,r.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:i(d?"chat.workflowEmpty":"common.loading")}):(0,r.jsxs)(r.Fragment,{children:[c.summary&&(0,r.jsx)("div",{className:"mb-3 text-xs text-muted-foreground whitespace-pre-wrap",children:c.summary}),S.map(e=>(0,r.jsxs)(s.Fragment,{children:[(0,r.jsx)("div",{className:"text-xs font-semibold text-foreground/80 mt-3 mb-1 sticky top-0 bg-card py-1",children:e.title}),e.agents.map(e=>(0,r.jsx)(w,{agent:e,onOpen:()=>e.agentId&&k({runId:n,agentId:e.agentId,label:e.label,running:"done"!==e.state&&C})},`${e.index}-${e.agentId}`))]},e.title))]})})]})}),v&&(0,r.jsx)(p,{cwd:e,sessionId:t,workflowRef:v,onClose:()=>k(null)})]})}function w({agent:e,onOpen:t}){let{t:n}=(0,h.Bd)(),[l,a]=(0,s.useState)(!1),o=e.state&&v[e.state]||"text-muted-foreground",i=e.resultPreview||e.promptPreview||"";return(0,r.jsxs)("div",{className:"border border-border rounded-md mb-1 bg-secondary/50",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 px-2 py-1.5",children:[(0,r.jsx)("button",{onClick:()=>a(e=>!e),className:"text-slate-9 text-xs flex-shrink-0",title:n(l?"chat.collapse":"chat.expand"),children:l?"▲":"▼"}),(0,r.jsx)("span",{className:"text-xs text-foreground truncate flex-1 min-w-0",title:e.label||"",children:e.label||e.agentId}),(0,r.jsx)("span",{className:`text-[10px] flex-shrink-0 ${o}`,children:e.state}),(0,r.jsxs)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:[g(e.tokens)," tok \xb7 ",b(e.durationMs)]}),e.agentId&&(0,r.jsx)("span",{role:"button",tabIndex:0,onClick:t,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&t()},className:"text-xs text-brand hover:text-teal-10 cursor-pointer flex-shrink-0",title:n("chat.subagentViewTitle"),children:n("chat.workflowViewAgent")})]}),l&&i&&(0,r.jsx)("pre",{className:"text-[11px] bg-secondary px-2 py-1.5 rounded-b overflow-x-auto max-h-32 overflow-y-auto text-muted-foreground whitespace-pre-wrap border-t border-border",children:i})]})}var k=n(60938),j=n(67362),C=n(38408),N=n(13219),S=n(47176),E=n(97251),L=n(56045),M=n(50860),R=n(47215);function T({filePath:e}){let[t,n]=(0,s.useState)(null),[l,a]=(0,s.useState)(!0),[o,i]=(0,s.useState)(null),c=(0,s.useRef)(!1),u=(0,R.e$)(e),d=(0,R.u)(e);return((0,s.useEffect)(()=>{d?a(!1):c.current||(c.current=!0,(async()=>{a(!0),i(null);let t=await f.t4.runPromiseExit((0,k.nM)(e));if("Success"===t._tag)n(t.value.content??null);else{let e="Fail"===t.cause._tag?t.cause.error:null,n=e?.cause;i(n instanceof Error?n.message:"Failed to load file")}a(!1),c.current=!1})())},[e,d]),o)?(0,r.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,r.jsx)("div",{className:"text-xs text-red-11",children:o})}):l?(0,r.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,r.jsx)("span",{className:"text-sm text-muted-foreground",children:"Loading..."})}):(0,R.u)(e)?(0,r.jsx)(M.I,{absPath:e,className:"flex items-center justify-center h-full overflow-auto",imgClassName:"max-w-full max-h-full object-contain",alt:e.split("/").pop()||"image"}):t?u?(0,r.jsx)(I,{content:t}):(0,r.jsx)(C.Cv,{content:t,filePath:e,showLineNumbers:!0,showSearch:!0,className:"h-full"}):(0,r.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,r.jsx)("span",{className:"text-sm text-muted-foreground",children:"No content"})})}let $=[E.W];function I({content:e}){let t=(0,s.useRef)(null);return(0,r.jsxs)("div",{className:"h-full flex",children:[(0,r.jsx)(S.l,{content:e,containerRef:t}),(0,r.jsx)("div",{ref:t,className:"flex-1 overflow-auto p-4",children:(0,r.jsx)(N.T,{content:e,rehypePlugins:$})})]})}function P({title:e,content:t,toolName:n,onClose:l}){let{t:i}=(0,h.Bd)(),c=(0,R.jU)(t),u=(0,R.zs)(t),d=(0,R.oK)(t),m=!!u,f=!!d,[x,p]=(0,s.useState)(("Read"===n||"Write"===n)&&f?"file":m?"diff-unified":c?"readable":"json"),g=(0,s.useRef)(null),b=(0,L.o)(g);(0,s.useEffect)(()=>{let e=e=>{if((e.metaKey||e.ctrlKey)&&"f"===e.key&&"readable"===x&&c){e.preventDefault(),b.open();return}if("Escape"===e.key){if(b.isVisible)return void b.close();document.activeElement instanceof HTMLElement&&document.activeElement.blur(),l()}};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[l,x,c,b]);let v=(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-0 md:p-4",onClick:l,children:(0,r.jsxs)("div",{className:"bg-card shadow-xl w-full max-w-[90%] h-full md:h-[90vh] rounded-none md:rounded-lg flex flex-col transition-all",onClick:e=>e.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("h3",{className:"text-sm font-medium text-foreground",children:e}),d&&(0,r.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(d),(0,o.oR)(i("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:i("common.copyAbsPath"),children:(0,r.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}),(0,r.jsxs)("div",{className:"flex items-center gap-3",children:[c&&(0,r.jsxs)("div",{className:"flex items-center gap-1 bg-accent rounded p-0.5",children:[m&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{onClick:()=>p("diff-split"),className:`px-2 py-1 text-xs rounded transition-colors ${"diff-split"===x?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,title:i("diffViewer.sideBySide"),children:"Split"}),(0,r.jsx)("button",{onClick:()=>p("diff-unified"),className:`px-2 py-1 text-xs rounded transition-colors ${"diff-unified"===x?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,title:i("diffViewer.unified"),children:"Unified"})]}),f&&(0,r.jsx)("button",{onClick:()=>p("file"),className:`px-2 py-1 text-xs rounded transition-colors ${"file"===x?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,title:i("diffViewer.previewFile"),children:"File"}),(0,r.jsx)("button",{onClick:()=>p("readable"),className:`px-2 py-1 text-xs rounded transition-colors ${"readable"===x?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:i("common.readable")}),(0,r.jsx)("button",{onClick:()=>p("json"),className:`px-2 py-1 text-xs rounded transition-colors ${"json"===x?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:"JSON"})]}),(0,r.jsx)("button",{onClick:l,className:"p-1 text-slate-9 hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,r.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,r.jsx)("div",{className:"flex-1 overflow-auto p-4",children:"file"===x&&d?(0,r.jsx)(T,{filePath:d}):"diff-unified"===x&&u?(0,r.jsx)(j.xU,{oldContent:u.old_string,newContent:u.new_string,filePath:u.file_path}):"diff-split"===x&&u?(0,r.jsx)(j.xZ,{oldContent:u.old_string,newContent:u.new_string,filePath:u.file_path}):"readable"===x&&c?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(L._,{search:b}),(0,r.jsx)("pre",{ref:g,className:"text-foreground whitespace-pre-wrap break-words",style:{fontSize:"0.8125rem"},children:(0,R.xb)(t)})]}):(0,r.jsx)("pre",{className:"text-foreground whitespace-pre-wrap break-words",style:{fontSize:"0.8125rem"},children:c?(0,R.C6)(t):t})})]})});return(0,r.jsx)(a.ZL,{children:v})}let _={Read:"\uD83D\uDCC4",Write:"✏️",Edit:"\uD83D\uDCDD",Bash:"\uD83D\uDCBB",Glob:"\uD83D\uDD0D",Grep:"\uD83D\uDD0E",WebFetch:"\uD83C\uDF10",WebSearch:"\uD83D\uDD0D",Workflow:"\uD83E\uDDE9",Skill:"\uD83D\uDEE0️"};function A({toolCall:e,cwd:t,sessionId:n}){var l;let{t:a}=(0,h.Bd)(),[i,c]=(0,s.useState)(!1),[u,d]=(0,s.useState)(null),[m,f]=(0,s.useState)(!1),[x,g]=(0,s.useState)(!1),b=_[e.name]||"\uD83D\uDD27",v="Agent"===e.name||"Task"===e.name,w=v&&!!t&&!!n,k="Workflow"===e.name,j=k&&(l=e.result)?l.match(/subagents\/workflows\/(wf_[A-Za-z0-9_-]+)/)?.[1]??null:null,C=k&&!!j&&!!t&&!!n,N="Skill"===e.name,S=v||k||N,E=(()=>{let t=e.input;if("Bash"===e.name&&t.command&&"string"==typeof t.command)return t.command;if(v&&t.description&&"string"==typeof t.description)return t.description;if(k){let e=["string"==typeof t.name?t.name:"","string"==typeof t.args?t.args:"string"==typeof t.resumeFromRunId?t.resumeFromRunId:""].filter(Boolean).join(" \xb7 ");if(e)return e}if(N&&"string"==typeof t.skill){let e="string"==typeof t.args?t.args:"";return[t.skill,e].filter(Boolean).join(" \xb7 ")}return"Glob"===e.name&&t.pattern&&"string"==typeof t.pattern||"Grep"===e.name&&t.pattern&&"string"==typeof t.pattern?t.pattern:"ToolSearch"===e.name&&t.query&&"string"==typeof t.query?t.query:"TaskCreate"===e.name&&t.subject&&"string"==typeof t.subject?t.subject:t.file_path&&"string"==typeof t.file_path?t.file_path:t.path&&"string"==typeof t.path?t.path:null})(),L="Glob"===e.name||"Grep"===e.name||"Bash"===e.name||v||k||N,M=E?L?E:(e=>{if(t&&e.startsWith(t)){let n=e.slice(t.length);return n.startsWith("/")?n.slice(1):n}let n=e.split("/");return n.length>2?".../"+n.slice(-2).join("/"):e})(E):null,R=t=>{let n="input"===t?a("toolCall.inputParams"):a("toolCall.resultLabel"),r="input"===t?JSON.stringify(e.input,null,2):"string"==typeof e.result?e.result:JSON.stringify(e.result,null,2);d({title:`${e.name}${M?` ${M}`:""} - ${n}`,content:r,toolName:e.name})};return(0,r.jsxs)("div",{className:"my-1 border border-border rounded-lg overflow-hidden bg-secondary",children:[(0,r.jsxs)("button",{onClick:()=>c(!i),className:"w-full px-3 py-1.5 flex items-center gap-2 text-left hover:bg-accent transition-colors",children:[(0,r.jsx)("span",{className:"text-sm",children:b}),(0,r.jsx)("span",{className:"font-medium text-sm text-foreground flex-shrink-0",children:e.name}),M&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"text-xs text-muted-foreground truncate flex-1 min-w-0",title:E||"",children:M}),!S&&(0,r.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),E&&(navigator.clipboard.writeText(E),(0,o.oR)(a("common.copiedPath")))},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),E&&(navigator.clipboard.writeText(E),(0,o.oR)(a("common.copiedPath"))))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0 cursor-pointer",title:a("common.copyAbsPath"),children:(0,r.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}),(0,r.jsxs)("span",{className:"ml-auto flex items-center gap-2",children:[w&&(0,r.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),f(!0)},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),f(!0))},className:"text-xs text-brand hover:text-teal-10 cursor-pointer",title:a("chat.subagentViewTitle"),children:a("chat.subagent")}),C&&(0,r.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),g(!0)},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),g(!0))},className:"text-xs text-brand hover:text-teal-10 cursor-pointer",title:a("chat.workflowViewTitle"),children:a("chat.workflowRun")}),i&&!e.isLoading&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),R("input")},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),R("input"))},className:"text-xs text-brand hover:text-teal-10 cursor-pointer",title:a("toolCall.inputParamsTitle"),children:a("toolCall.input")}),e.result&&(0,r.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),R("result")},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),R("result"))},className:"text-xs text-brand hover:text-teal-10 cursor-pointer",title:a("toolCall.resultTitle"),children:a("toolCall.result")})]}),e.isLoading?(0,r.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"}):(0,r.jsx)("span",{className:"text-slate-9 text-xs",children:i?"▲":"▼"})]})]}),i&&(0,r.jsxs)("div",{className:"border-t border-border",children:[(0,r.jsxs)("div",{className:"px-3 py-2",children:[(0,r.jsx)("div",{className:"mb-1",children:(0,r.jsxs)("span",{className:"text-xs text-muted-foreground",children:[a("toolCall.inputParams"),":"]})}),(0,r.jsx)("pre",{className:"text-xs bg-secondary p-2 rounded overflow-x-auto max-h-24 overflow-y-auto text-foreground",children:JSON.stringify(e.input,null,2)})]}),e.result&&(0,r.jsxs)("div",{className:"px-3 py-2 border-t border-border",children:[(0,r.jsx)("div",{className:"mb-1",children:(0,r.jsxs)("span",{className:"text-xs text-muted-foreground",children:[a("toolCall.resultLabel"),":"]})}),(0,r.jsx)("pre",{className:"text-xs bg-secondary p-2 rounded overflow-x-auto max-h-24 overflow-y-auto text-foreground",children:"string"==typeof e.result?e.result:JSON.stringify(e.result,null,2)})]}),e.skillContent&&(0,r.jsxs)("div",{className:"px-3 py-2 border-t border-border",children:[(0,r.jsx)("div",{className:"mb-1",children:(0,r.jsxs)("span",{className:"text-xs text-muted-foreground",children:[a("toolCall.skillContent",{defaultValue:"Skill content"}),":"]})}),(0,r.jsx)("pre",{className:"text-xs bg-secondary p-2 rounded overflow-x-auto max-h-60 overflow-y-auto text-foreground whitespace-pre-wrap",children:e.skillContent})]})]}),u&&(0,r.jsx)(P,{title:u.title,content:u.content,toolName:u.toolName,onClose:()=>d(null)}),m&&t&&n&&(0,r.jsx)(p,{cwd:t,sessionId:n,toolCall:e,onClose:()=>f(!1)}),x&&t&&n&&j&&(0,r.jsx)(y,{cwd:t,sessionId:n,runId:j,isRunning:!!e.isLoading,onClose:()=>g(!1)})]})}var F=n(56204),D=n(67635),O=n(33210),V=n(58515),B=n(36201),W=n(55804),H=n(37618);function z(e){let t=e.input?.questions||[],n=e.input?.answers||{},r={};if(e.result)try{let t=JSON.parse(e.result);t?.answers&&(r=t.answers)}catch{}return{questions:t,answers:{...n,...r}}}function K(e,t){return`${e}-${t}`}function U({toolCalls:e,onClose:t}){let{t:n}=(0,h.Bd)(),i=(0,l.nH)(),[c,u]=(0,s.useState)({}),[d,m]=(0,s.useState)({}),[f,x]=(0,s.useState)({}),[p,g]=(0,s.useState)({});(0,s.useEffect)(()=>{let t={};e.forEach((e,n)=>{let{questions:r,answers:s}=z(e);r.forEach((e,r)=>{let l=s[e.question];if(l){let s=K(n,r);t[s]=l,e.options.some(e=>e.label===l)||(m(e=>({...e,[s]:!0})),x(e=>({...e,[s]:l})))}})}),queueMicrotask(()=>u(t))},[e]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&t()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[t]);let b=e.reduce((e,t)=>{let{questions:n}=z(t);return e+n.length},0),v=Object.values(p).filter(Boolean).length,y=(0,s.useCallback)((e,t)=>{u(n=>({...n,[e]:t})),m(t=>({...t,[e]:!1}))},[]),w=(0,s.useCallback)(e=>{m(t=>{let n=!t[e];if(n){let t=f[e]||"";t&&u(n=>({...n,[e]:t}))}return{...t,[e]:n}})},[f]),k=(0,s.useCallback)((e,t)=>{x(n=>({...n,[e]:t})),t&&u(n=>({...n,[e]:t}))},[]),j=(0,s.useCallback)(e=>{g(t=>({...t,[e]:!t[e]}))},[]),C=(0,s.useCallback)(()=>{let t=v>0,r=[];return e.forEach((e,s)=>{let{questions:l}=z(e);l.forEach((e,l)=>{let a=K(s,l);if(t&&!p[a])return;let o=c[a];r.push(`Q: ${e.question}`),r.push(`A: ${o||n("askQuestion.notSelected")}`),r.push("")})}),r.join("\n").trim()},[e,c,p,v,n]),N=(0,s.useCallback)(()=>{navigator.clipboard.writeText(C()),(0,o.oR)(v>0?n("toast.copiedQA",{count:v}):n("toast.copiedAllQA"))},[C,v,n]),S=(0,s.useCallback)(()=>{i?(i.sendMessage(C()),(0,o.oR)(n("toast.sentQA")),t()):(0,o.oR)(n("askQuestion.sendNoChat"))},[i,C,t,n]),E=(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:t,children:(0,r.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-6xl h-[90vh] flex flex-col overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border flex-shrink-0",children:[(0,r.jsxs)("div",{className:"flex items-center gap-3",children:[(0,r.jsx)("h3",{className:"text-sm font-medium text-foreground",children:n("askQuestion.title")}),(0,r.jsxs)("span",{className:"text-xs text-muted-foreground",children:[n("askQuestion.nQuestions",{count:b}),v>0&&` \xb7 ${n("askQuestion.checkedN",{count:v})}`]})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("button",{onClick:S,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:v>0?n("askQuestion.sendChecked",{count:v}):n("askQuestion.sendAll"),children:(0,r.jsx)(F.A,{className:"w-4 h-4"})}),(0,r.jsx)("button",{onClick:N,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:v>0?n("askQuestion.copyChecked",{count:v}):n("askQuestion.copyAll"),children:(0,r.jsx)(D.A,{className:"w-4 h-4"})}),(0,r.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,r.jsx)(O.A,{className:"w-5 h-5"})})]})]}),(0,r.jsx)("div",{className:"flex-1 overflow-y-auto px-6 py-4 space-y-6",children:e.map((t,s)=>{let{questions:l}=z(t);return l.map((t,a)=>{let o=K(s,a),i=c[o],u=d[o]||!1,m=p[o]||!1;return(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsxs)("div",{className:"flex items-start gap-2",children:[(0,r.jsx)("button",{onClick:()=>j(o),className:"mt-0.5 flex-shrink-0 p-0.5 rounded hover:bg-accent transition-colors",title:n("askQuestion.checkToCopy"),children:m?(0,r.jsx)(V.A,{className:"w-4 h-4 text-brand"}):(0,r.jsx)(B.A,{className:"w-4 h-4 text-muted-foreground"})}),t.header&&(0,r.jsx)("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium bg-brand/10 text-brand flex-shrink-0 mt-0.5",children:t.header}),(0,r.jsx)("span",{className:"text-sm font-medium text-foreground",children:t.question})]}),(0,r.jsxs)("div",{className:"space-y-1 ml-7",children:[t.options.map((e,t)=>{let n=i===e.label&&!u;return(0,r.jsxs)("button",{onClick:()=>y(o,e.label),className:`flex items-start gap-2 px-2.5 py-1.5 rounded-md transition-colors w-full text-left cursor-pointer hover:bg-accent/50 ${n?"bg-brand/10 hover:bg-brand/15":""}`,children:[(0,r.jsx)("div",{className:"mt-0.5 flex-shrink-0",children:n?(0,r.jsx)(W.A,{className:"w-3.5 h-3.5 text-brand"}):(0,r.jsx)("div",{className:"w-3.5 h-3.5 rounded-full border border-muted-foreground"})}),(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsx)("div",{className:`text-sm ${n?"text-foreground font-medium":"text-foreground"}`,children:e.label}),e.description&&(0,r.jsx)("div",{className:"text-xs text-muted-foreground mt-0.5",children:e.description})]})]},t)}),(0,r.jsxs)("button",{onClick:()=>w(o),className:`flex items-start gap-2 px-2.5 py-1.5 rounded-md transition-colors w-full text-left cursor-pointer hover:bg-accent/50 ${u?"bg-brand/10 hover:bg-brand/15":""}`,children:[(0,r.jsx)("div",{className:"mt-0.5 flex-shrink-0",children:u?(0,r.jsx)(W.A,{className:"w-3.5 h-3.5 text-brand"}):(0,r.jsx)("div",{className:"w-3.5 h-3.5 rounded-full border border-muted-foreground"})}),(0,r.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,r.jsx)(H.A,{className:"w-3.5 h-3.5 text-muted-foreground"}),(0,r.jsx)("span",{className:"text-sm text-muted-foreground",children:n("askQuestion.custom")})]})]}),u&&(0,r.jsx)("div",{className:"ml-6 mt-1",children:(0,r.jsx)("input",{type:"text",autoFocus:!0,value:f[o]||"",onChange:e=>k(o,e.target.value),placeholder:n("askQuestion.customPlaceholder"),className:"w-full px-3 py-1.5 text-sm bg-background border border-border rounded-md focus:outline-none focus:ring-1 focus:ring-brand text-foreground placeholder:text-muted-foreground"})})]}),(s!==e.length-1||a!==l.length-1)&&(0,r.jsx)("div",{className:"border-b border-border/50 mt-3"})]},o)})})})]})});return(0,r.jsx)(a.ZL,{children:E})}var q=n(48368),X=n(66088),Z=n(21362),J=n(12710);function Y(e,t){if(t&&e.startsWith(t)){let n=e.slice(t.length);return n.startsWith("/")?n.slice(1):n}return e}function Q({node:e,selectedUid:t,onSelect:n,depth:l=0}){let[a,o]=(0,s.useState)(!0);if(e.isFile&&e.change){let s=t===e.change.uid;return(0,r.jsxs)("button",{onClick:()=>n(e.change),className:`w-full flex items-center gap-1.5 px-2 py-1 text-xs text-left rounded transition-colors ${s?"bg-brand/15 text-brand":"text-foreground hover:bg-accent"}`,style:{paddingLeft:`${12*l+8}px`},"data-tooltip":e.fullPath,children:[(0,r.jsx)(q.A,{className:"w-3.5 h-3.5 flex-shrink-0 opacity-60"}),(0,r.jsx)("span",{className:"truncate",children:e.name}),(0,r.jsx)("span",{className:`ml-auto text-[10px] flex-shrink-0 ${"write"===e.change.type?"text-green-500":"text-yellow-500"}`,children:"write"===e.change.type?"new":"edit"})]})}return(0,r.jsxs)("div",{children:[(0,r.jsxs)("button",{onClick:()=>o(!a),className:"w-full flex items-center gap-1 px-2 py-1 text-xs text-muted-foreground hover:text-foreground transition-colors",style:{paddingLeft:`${12*l+8}px`},children:[a?(0,r.jsx)(X.A,{className:"w-3 h-3"}):(0,r.jsx)(Z.A,{className:"w-3 h-3"}),(0,r.jsx)("span",{className:"truncate",children:e.name})]}),a&&e.children.map((e,s)=>(0,r.jsx)(Q,{node:e,selectedUid:t,onSelect:n,depth:l+1},e.isFile&&e.change?e.change.uid:`${e.fullPath}-${s}`))]})}function G({toolCalls:e,cwd:t,onClose:n}){let{t:l}=(0,h.Bd)(),o=(0,s.useMemo)(()=>(function(e,t){let n=[],r=0;for(let s of e)if("Edit"===s.name){let e=s.input;e.file_path&&"string"==typeof e.old_string&&"string"==typeof e.new_string&&n.push({filePath:Y(e.file_path,t),uid:`change-${r++}`,type:"edit",old_string:e.old_string,new_string:e.new_string})}else if("Write"===s.name){let e=s.input;e.file_path&&"string"==typeof e.content&&n.push({filePath:Y(e.file_path,t),uid:`change-${r++}`,type:"write",old_string:"",new_string:e.content})}return n})(e,t),[e,t]),i=(0,s.useMemo)(()=>(function e(t){return t.map(t=>{if(!t.isFile&&1===t.children.length&&!t.children[0].isFile){let n=t.children[0];return{...n,name:t.name+"/"+n.name,children:e(n.children)}}return{...t,children:e(t.children)}})})(function(e){let t=[];for(let n of e){let e=n.filePath.split("/").filter(Boolean),r=t;for(let t=0;t<e.length;t++){let s=e[t],l=t===e.length-1,a=e.slice(0,t+1).join("/");if(l){let e={name:s,fullPath:a,isFile:!0,children:[],change:n};r.push(e)}else{let e=r.find(e=>e.name===s&&!e.isFile);e||(e={name:s,fullPath:a,isFile:!1,children:[]},r.push(e)),r=e.children}}}return t}(o)),[o]),[c,u]=(0,s.useState)(o[0]||null),[d,m]=(0,s.useState)("unified"),f=(0,s.useRef)(null),[x,p]=(0,s.useState)(()=>window.innerWidth>=768);if((0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&n()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[n]),0===o.length)return null;let g=(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-0 md:p-4",onClick:n,children:(0,r.jsxs)("div",{className:"bg-card shadow-xl w-full h-full rounded-none md:max-w-[90%] md:h-[90vh] md:rounded-lg flex flex-col transition-all",onClick:e=>e.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("button",{onClick:()=>p(e=>!e),"aria-label":l("diffViewer.toggleFileTree"),className:`p-1 rounded transition-colors ${x?"text-foreground bg-accent":"text-muted-foreground hover:text-foreground hover:bg-accent"}`,children:(0,r.jsx)(J.A,{className:"w-4 h-4"})}),(0,r.jsx)("h3",{className:"text-sm font-medium text-foreground",children:l("diffViewer.fileChanges",{count:o.length})})]}),(0,r.jsxs)("div",{className:"flex items-center gap-3",children:[(0,r.jsxs)("div",{className:"flex items-center gap-1 bg-accent rounded p-0.5",children:[(0,r.jsx)("button",{onClick:()=>m("unified"),className:`px-2 py-1 text-xs rounded transition-colors ${"unified"===d?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:"Unified"}),(0,r.jsx)("button",{onClick:()=>m("split"),className:`px-2 py-1 text-xs rounded transition-colors ${"split"===d?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:"Split"})]}),(0,r.jsx)("button",{onClick:n,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,r.jsx)(O.A,{className:"w-5 h-5"})})]})]}),(0,r.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[x&&(0,r.jsx)("div",{ref:f,className:"w-56 flex-shrink-0 border-r border-border overflow-y-auto py-2",children:i.map((e,t)=>(0,r.jsx)(Q,{node:e,selectedUid:c?.uid||"",onSelect:e=>{u(e),window.innerWidth<768&&p(!1)}},e.isFile&&e.change?e.change.uid:`${e.fullPath}-${t}`))}),(0,r.jsx)("div",{className:"flex-1 overflow-auto",children:c?"unified"===d?(0,r.jsx)(j.xU,{oldContent:c.old_string,newContent:c.new_string,filePath:c.filePath}):(0,r.jsx)(j.xZ,{oldContent:c.old_string,newContent:c.new_string,filePath:c.filePath,isNew:"write"===c.type}):(0,r.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:l("diffViewer.selectFileToView")})})]})]})});return(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(a.ZL,{children:g})})}var ee=n(5135),et=n(38175),en=n(70188),er=n(83448);function es({image:e,onClose:t}){let{t:n}=(0,h.Bd)(),s=(0,r.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80",onClick:t,children:[(0,r.jsx)("button",{onClick:t,className:"absolute top-4 right-4 w-10 h-10 flex items-center justify-center text-white/80 hover:text-white bg-black/40 hover:bg-black/60 rounded-full transition-colors",children:(0,r.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),(0,r.jsx)("img",{src:`data:${e.media_type};base64,${e.data}`,alt:n("chat.imagePreview"),className:"max-w-[90vw] max-h-[90vh] object-contain",onClick:e=>e.stopPropagation()})]});return(0,r.jsx)(a.ZL,{children:s})}function el({filePath:e,content:t,cwd:n,onClose:l}){let[o,i]=(0,s.useState)(null);return(0,r.jsx)(a.ZL,{children:(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-0 md:p-4",onClick:l,children:(0,r.jsx)("div",{ref:i,className:"bg-card shadow-xl w-full h-full rounded-none md:max-w-[90%] md:h-[90vh] md:rounded-lg flex flex-col relative",onClick:e=>e.stopPropagation(),children:(0,r.jsx)(en.SU,{container:o,children:(0,r.jsx)(ee.M,{content:t,filePath:e,cwd:n,onClose:l})})})})})}function ea({filePath:e,content:t,onClose:n}){return(0,r.jsx)(a.ZL,{children:(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-0 md:p-4",onClick:n,children:(0,r.jsxs)("div",{className:"bg-card shadow-xl w-full h-full rounded-none md:max-w-[90%] md:h-[90vh] md:rounded-lg flex flex-col relative overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border flex-shrink-0",children:[(0,r.jsx)("span",{className:"text-sm text-muted-foreground truncate",children:e.split("/").pop()}),(0,r.jsx)("button",{onClick:n,className:"text-muted-foreground hover:text-foreground px-1.5 py-0.5 rounded hover:bg-accent transition-colors",children:"✕"})]}),(0,r.jsx)("div",{className:"flex-1 overflow-hidden",children:(0,r.jsx)(et.E,{content:t,filePath:e})})]})})})}let eo=(0,s.memo)(function({message:e,cwd:t,sessionId:n,onFork:l,onApprovePlan:x,isLoading:p}){let g,b,v,y,{t:w}=(0,h.Bd)(),[k,j]=(0,s.useState)(null),[C,S]=(0,s.useState)(()=>1===(e.toolCalls?.length||0)),[E,L]=(0,s.useState)(!1),[M,T]=(0,s.useState)(!1),[$,I]=(0,s.useState)(!1),P="user"===e.role,_=e.images&&e.images.length>0,F=e.toolCalls?.length||0,D=!!n&&!!t&&!!l,O=(0,s.useMemo)(()=>e.toolCalls?.some(e=>"Edit"===e.name||"Write"===e.name)||!1,[e.toolCalls]),V=(0,s.useMemo)(()=>{if(!e.toolCalls)return null;for(let t=e.toolCalls.length-1;t>=0;t--)if("TodoWrite"===e.toolCalls[t].name)return e.toolCalls[t];return null},[e.toolCalls]),B=(0,s.useMemo)(()=>e.toolCalls?e.toolCalls.filter(e=>"AskUserQuestion"===e.name):[],[e.toolCalls]),W=(0,s.useMemo)(()=>{if(!e.toolCalls)return null;for(let t=e.toolCalls.length-1;t>=0;t--)if("ExitPlanMode"===e.toolCalls[t].name){let n=e.toolCalls[t].input?.plan;return"string"==typeof n&&n?n:null}return null},[e.toolCalls]),H=(0,s.useMemo)(()=>e.toolCalls?.filter(e=>"ExitPlanMode"!==e.name)??[],[e.toolCalls]),z=(0,s.useMemo)(()=>{if(!e.toolCalls)return[];let t=new Set,n=[];for(let r of e.toolCalls)if("Read"===r.name||"Edit"===r.name||"Write"===r.name){let e=r.input.file_path;e&&((0,R.e$)(e)||(0,R.aR)(e))&&!t.has(e)&&(t.add(e),n.push(e))}return n},[e.toolCalls]),K=(0,s.useMemo)(()=>{if(!e.toolCalls)return[];let t=[];for(let n of e.toolCalls){let e=n.input?.thought;if(e&&"string"==typeof e){let r=e.match(/PREVIOUS:\s*(.*?)\s*→\s*THIS:\s*(.*?)\s*→\s*EXPECT:\s*(.*)/i);r?t.push({previous:r[1].trim(),current:r[2].trim(),expect:r[3].trim(),raw:e,toolName:n.name}):t.push({previous:"",current:e,expect:"",raw:e,toolName:n.name})}}return t},[e.toolCalls]),[q,X]=(0,s.useState)(null),[Z,J]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!q)return void queueMicrotask(()=>J(null));let e=!1;return f.t4.runPromiseExit((0,er.an)(q)).then(t=>{e||("Success"===t._tag&&void 0!==t.value.content?J(t.value.content):((0,o.oR)(w("toast.readFileFailed"),"error"),X(null)))}),()=>{e=!0}},[q,w]);let Y=()=>{e.content&&(navigator.clipboard.writeText(e.content),(0,o.oR)(w("toast.copiedMessage")))},Q=()=>{D&&l(e.id)},ee=(e=>{if(!e)return"";let t=new Date(e);if(isNaN(t.getTime()))return"";let n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),l=String(t.getMinutes()).padStart(2,"0");return`${n}-${r} ${s}:${l}`})(e.timestamp);if("system"===e.role){let t=e.systemEvent,n=t?.kind==="task-notification"?"failed"===t.status?"⚠️":"stopped"===t.status?"⏹️":"\uD83D\uDD14":"ℹ️",s=t?.detail||e.content;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"flex justify-center my-2 px-2","data-role":"system",children:(0,r.jsxs)("button",{type:"button",onClick:()=>I(!0),className:"flex items-center gap-1.5 max-w-[85%] text-[11px] text-muted-foreground bg-secondary/40 border border-border/50 rounded-full px-3 py-1 hover:bg-secondary hover:text-foreground transition-colors cursor-pointer",title:w("chat.viewDetails",{defaultValue:"Click for details"}),children:[(0,r.jsx)("span",{className:"flex-shrink-0",children:n}),(0,r.jsx)("span",{className:"truncate",children:e.content})]})}),$&&(0,r.jsx)(a.ZL,{children:(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:()=>I(!1),children:(0,r.jsxs)("div",{className:"bg-card shadow-xl w-full max-w-4xl max-h-[80vh] rounded-lg flex flex-col overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border flex-shrink-0",children:[(0,r.jsxs)("span",{className:"text-sm text-foreground flex items-center gap-1.5",children:[(0,r.jsx)("span",{children:n}),t?.kind==="task-notification"?w("chat.taskNotification",{defaultValue:"Task notification"}):w("chat.systemNotice",{defaultValue:"Notice"})]}),(0,r.jsx)("button",{onClick:()=>I(!1),className:"text-muted-foreground hover:text-foreground px-1.5 py-0.5 rounded hover:bg-accent transition-colors",children:"✕"})]}),(0,r.jsx)("pre",{className:"flex-1 overflow-auto px-4 py-3 text-xs text-foreground whitespace-pre-wrap break-words",children:s})]})})})]})}return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:`flex flex-col ${P?"items-end":"items-start"} mb-4 group`,"data-role":e.role,children:[ee&&(0,r.jsx)("span",{className:"text-[11px] text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity mb-0.5 px-1",children:ee}),(0,r.jsxs)("div",{className:`flex ${P?"justify-end":"justify-start"} w-full`,children:[P&&(0,r.jsxs)("div",{className:"self-start mt-2 mr-1 flex flex-col gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.content&&(0,r.jsx)("button",{onClick:Y,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:w("chat.copyMessage"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),D&&(0,r.jsx)("button",{onClick:Q,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:w("chat.forkSession"),children:(0,r.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("circle",{cx:"12",cy:"18",r:"3"}),(0,r.jsx)("circle",{cx:"6",cy:"6",r:"3"}),(0,r.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,r.jsx)("path",{d:"M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9"}),(0,r.jsx)("path",{d:"M12 12v3"})]})})]}),(0,r.jsxs)("div",{className:`max-w-[80%] ${P?"bg-accent text-foreground border border-brand rounded-2xl rounded-br-md":"bg-accent text-foreground dark:text-slate-11 rounded-2xl rounded-bl-md"} px-4 py-2`,children:[_&&(0,r.jsx)("div",{className:`flex flex-wrap gap-2 ${e.content?"mb-2":""}`,children:e.images.map((e,t)=>(0,r.jsx)("div",{className:"relative w-16 h-16 rounded-lg overflow-hidden border border-white/20 cursor-pointer hover:opacity-90 transition-opacity",onClick:()=>j(e),children:(0,r.jsx)("img",{src:`data:${e.media_type};base64,${e.data}`,alt:w("chat.imageN",{index:t+1}),className:"w-full h-full object-cover"})},t))}),e.content&&(0,r.jsxs)("div",{className:"break-words",children:[(0,r.jsx)(N.T,{content:e.content,isUser:P,isStreaming:e.isStreaming,enableMath:!1}),e.isStreaming&&(0,r.jsx)("span",{className:"inline-block w-2 h-4 ml-1 bg-current animate-pulse"})]}),V&&(v=(b=Array.isArray(g=V.input?.todos)?g:[]).filter(e=>"completed"===e.status).length,y=b.length,(0,r.jsx)("div",{className:`${e.content||_?"mt-2":""}`,children:(0,r.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden bg-secondary/50 px-3 py-2 space-y-1",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 mb-1.5",children:[(0,r.jsx)("div",{className:"flex-1 h-1 bg-secondary rounded-full overflow-hidden",children:(0,r.jsx)("div",{className:"h-full bg-green-500 rounded-full transition-all duration-300",style:{width:`${y>0?v/y*100:0}%`}})}),(0,r.jsxs)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:[v,"/",y]})]}),b.map((e,t)=>(0,r.jsxs)("div",{className:`flex items-center gap-1.5 ${"completed"===e.status?"opacity-50":""}`,children:["completed"===e.status?(0,r.jsx)(i.A,{className:"w-3 h-3 text-green-500 flex-shrink-0"}):"in_progress"===e.status?(0,r.jsx)(c.A,{className:"w-3 h-3 text-brand flex-shrink-0 animate-spin"}):(0,r.jsx)(u.A,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"}),(0,r.jsx)("span",{className:`text-xs truncate ${"completed"===e.status?"text-muted-foreground":"text-foreground"}`,children:"in_progress"===e.status&&e.activeForm?e.activeForm:e.content})]},t))]})})),W&&(0,r.jsx)("div",{className:`${e.content||_||V?"mt-2":""}`,children:(0,r.jsxs)("div",{className:"border border-brand/40 rounded-lg overflow-hidden bg-secondary/50",children:[(0,r.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-1.5 border-b border-border bg-brand/10",children:[(0,r.jsx)("span",{className:"text-sm",children:"\uD83D\uDCCB"}),(0,r.jsx)("span",{className:"text-xs font-medium text-foreground",children:w("chat.planTitle",{defaultValue:"Plan (awaiting your review)"})})]}),(0,r.jsx)("div",{className:"px-3 py-2",children:(0,r.jsx)(N.T,{content:W,isUser:!1,enableMath:!1})}),x&&(0,r.jsxs)("div",{className:"px-3 py-2 border-t border-border flex items-center justify-between gap-2",children:[(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:w("chat.planApproveHint",{defaultValue:"本环境无审批弹窗,点此退出 Plan 并执行"})}),(0,r.jsxs)("button",{onClick:()=>x(),disabled:p,className:"flex items-center gap-1.5 px-3 py-1 rounded-md bg-brand text-white text-xs font-medium hover:bg-brand/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors flex-shrink-0",children:[(0,r.jsx)("span",{children:"✓"}),(0,r.jsx)("span",{children:w("chat.approvePlan",{defaultValue:"批准并执行"})})]})]})]})}),z.length>0&&(0,r.jsx)("div",{className:`${e.content||_||V?"mt-2":""}`,children:(0,r.jsx)("div",{className:"border border-border rounded-lg overflow-hidden bg-secondary/50 px-3 py-2 space-y-0.5",children:z.map(e=>(0,r.jsxs)("button",{onClick:()=>X(e),className:"flex items-center gap-1.5 w-full text-left hover:bg-accent rounded px-1 py-0.5 transition-colors group/md",children:[(0,R.aR)(e)?(0,r.jsx)("svg",{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4"})}):(0,r.jsx)("svg",{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground group-hover/md:text-foreground truncate",children:e.split("/").pop()})]},e))})}),K.length>0&&(0,r.jsx)("div",{className:`${e.content||_||V||z.length>0?"mt-2":""}`,children:(0,r.jsx)("div",{className:"border border-border rounded-lg overflow-hidden bg-secondary/50",children:(0,r.jsxs)("table",{className:"w-full text-xs",children:[(0,r.jsx)("thead",{children:(0,r.jsxs)("tr",{className:"border-b border-border text-muted-foreground",children:[(0,r.jsx)("th",{className:"px-2 py-1.5 text-left font-medium w-[60px]",children:"Tool"}),(0,r.jsx)("th",{className:"px-2 py-1.5 text-left font-medium",children:"Previous"}),(0,r.jsx)("th",{className:"px-2 py-1.5 text-left font-medium",children:"Action"}),(0,r.jsx)("th",{className:"px-2 py-1.5 text-left font-medium",children:"Expect"})]})}),(0,r.jsx)("tbody",{children:K.map((e,t)=>(0,r.jsxs)("tr",{className:t<K.length-1?"border-b border-border/50":"",children:[(0,r.jsx)("td",{className:"px-2 py-1 text-muted-foreground font-mono",children:e.toolName}),(0,r.jsx)("td",{className:"px-2 py-1 text-muted-foreground",children:e.previous||"—"}),(0,r.jsx)("td",{className:"px-2 py-1 text-foreground",children:e.current}),(0,r.jsx)("td",{className:"px-2 py-1 text-muted-foreground",children:e.expect||"—"})]},t))})]})})}),H.length>0&&(0,r.jsx)("div",{className:`${e.content||_?"mt-2":""}`,children:F>0?(0,r.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden bg-secondary",children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsxs)("button",{onClick:()=>S(!C),className:"flex-1 px-3 py-1.5 flex items-center gap-2 text-left hover:bg-accent transition-colors active:bg-muted",children:[(0,r.jsx)("span",{className:"text-sm",children:"\uD83D\uDD27"}),(0,r.jsx)("span",{className:"font-medium text-foreground",children:w("chat.toolCalls",{count:H.length})}),(0,r.jsx)("span",{className:"ml-auto text-muted-foreground text-sm",children:C?w("chat.collapse"):w("chat.expand")})]}),B.length>0&&(0,r.jsx)("button",{onClick:()=>T(!0),className:"px-3 py-1.5 text-muted-foreground hover:text-foreground hover:bg-accent transition-colors border-l border-border",title:w("chat.viewQuestions"),children:(0,r.jsx)(d.A,{className:"w-4 h-4"})}),O&&(0,r.jsx)("button",{onClick:()=>L(!0),className:"px-3 py-1.5 text-muted-foreground hover:text-foreground hover:bg-accent transition-colors border-l border-border",title:w("chat.viewAllFileChanges"),children:(0,r.jsx)(m.A,{className:"w-4 h-4"})})]}),C&&(0,r.jsx)("div",{className:"border-t border-border p-2 space-y-1",children:H.map((e,s)=>(0,r.jsx)(A,{toolCall:e,cwd:t,sessionId:n},`${e.id}-${s}`))})]}):H.map((e,s)=>(0,r.jsx)(A,{toolCall:e,cwd:t,sessionId:n},`${e.id}-${s}`))})]}),!P&&(0,r.jsxs)("div",{className:"self-start mt-2 ml-1 flex flex-col gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.content&&(0,r.jsx)("button",{onClick:Y,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:w("chat.copyMessage"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),D&&(0,r.jsx)("button",{onClick:Q,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:w("chat.forkSession"),children:(0,r.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("circle",{cx:"12",cy:"18",r:"3"}),(0,r.jsx)("circle",{cx:"6",cy:"6",r:"3"}),(0,r.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,r.jsx)("path",{d:"M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9"}),(0,r.jsx)("path",{d:"M12 12v3"})]})})]})]})]}),k&&(0,r.jsx)(es,{image:k,onClose:()=>j(null)}),E&&e.toolCalls&&(0,r.jsx)(G,{toolCalls:e.toolCalls,cwd:t,onClose:()=>L(!1)}),M&&B.length>0&&(0,r.jsx)(U,{toolCalls:B,onClose:()=>T(!1)}),q&&null!==Z&&((0,R.aR)(q)?(0,r.jsx)(ea,{filePath:q,content:Z,onClose:()=>X(null)}):(0,r.jsx)(el,{filePath:q,content:Z,cwd:t||"",onClose:()=>X(null)}))]})});var ei=n(1058),ec=n(90717),eu=n(89109),ed=n(7320);let em=(0,s.forwardRef)(function({messages:e,isLoading:t,cwd:n,sessionId:a,engine:o,apiRetryInfo:i,ptyNotice:c,hasMoreHistory:u,isLoadingMore:d,onLoadMore:m,onFork:f,isActive:x=!0,onContentSearch:p,onApprovePlan:g},b){let{t:v}=(0,h.Bd)(),y=(0,s.useRef)(null),w=(0,s.useRef)(null),k=(0,s.useRef)(null),j=(0,s.useRef)(null),[C,N]=(0,s.useState)(null),[S,E]=(0,s.useState)(!0),[L,M]=(0,s.useState)(!1),[R,T]=(0,s.useState)(!1);(0,s.useEffect)(()=>{N(j.current)},[]);let{isSearchVisible:$,searchQuery:I,setSearchQuery:P,matches:_,currentMatchIndex:A,goToNextMatch:F,goToPrevMatch:D,closeSearch:O,searchInputRef:V,handleSearchKeyDown:B}=function(e){let[t,n]=(0,s.useState)(!1),[r,l]=(0,s.useState)(""),[a,o]=(0,s.useState)([]),[i,c]=(0,s.useState)(0),u=(0,s.useRef)(null),d=(0,s.useRef)([]),m=(0,s.useCallback)(()=>{let t=e.current;t&&(t.querySelectorAll("mark.chat-search-match, mark.chat-search-current").forEach(e=>{let t=e.parentNode;t&&(t.replaceChild(document.createTextNode(e.textContent||""),e),t.normalize())}),d.current=[])},[e]),h=(0,s.useCallback)(t=>{if(m(),!t||!e.current){o([]),c(0);return}let n=[],r=[],s=t.toLowerCase();e.current.querySelectorAll("[data-message-id]").forEach(e=>{let l,a=e.getAttribute("data-message-id")||"",o=0,i=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,null),c=[];for(;l=i.nextNode();)c.push(l);for(let e of c){let l=(e.textContent||"").toLowerCase(),i=0,c=[];for(;;){let e=l.indexOf(s,i);if(-1===e)break;c.push({start:e,end:e+t.length}),i=e+1}if(0!==c.length)for(let t=c.length-1;t>=0;t--){let s=c[t];e.splitText(s.end);let l=e.splitText(s.start),i=document.createElement("mark");i.className="chat-search-match",i.textContent=l.textContent,l.parentNode.replaceChild(i,l),n.push({messageId:a,markIndex:o}),r.push(i),o++}}}),n.reverse(),r.reverse(),d.current=r,o(n),c(n.length>0?0:-1)},[e,m]);(0,s.useEffect)(()=>{queueMicrotask(()=>h(r))},[r,h]),(0,s.useEffect)(()=>{let e=d.current;e.forEach((e,t)=>{e.className=t===i?"chat-search-current":"chat-search-match"}),i>=0&&i<e.length&&e[i].scrollIntoView({behavior:"smooth",block:"center"})},[i,a]);let f=(0,s.useCallback)(()=>{0!==a.length&&c(e=>(e+1)%a.length)},[a.length]),x=(0,s.useCallback)(()=>{0!==a.length&&c(e=>(e-1+a.length)%a.length)},[a.length]),p=(0,s.useCallback)(()=>{n(!0),setTimeout(()=>u.current?.focus(),0)},[]),g=(0,s.useCallback)(()=>{n(!1),l(""),m(),o([]),c(0)},[m]),b=(0,s.useCallback)(e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?x():f()),"Escape"===e.key&&g()},[f,x,g]);return(0,s.useEffect)(()=>{let t=e.current;if(!t)return;let n=e=>{(e.metaKey||e.ctrlKey)&&"f"===e.key&&(e.preventDefault(),e.stopPropagation(),p())};return t.addEventListener("keydown",n),()=>t.removeEventListener("keydown",n)},[e,p]),{isSearchVisible:t,searchQuery:r,setSearchQuery:l,matches:a,currentMatchIndex:i,goToNextMatch:f,goToPrevMatch:x,openSearch:p,closeSearch:g,searchInputRef:u,handleSearchKeyDown:b}}(j),W=(0,l.nH)(),H=(0,s.useRef)(null),z=(0,s.useRef)(()=>{}),{addComment:K,refresh:U}=(0,ei._)({cwd:n||"",filePath:ec.Un}),[q,X]=(0,s.useState)(null),[Z,J]=(0,s.useState)(null),Y=(0,s.useCallback)(e=>{if(q||Z)return;let t=window.getSelection();if(!t||t.isCollapsed||!t.rangeCount){H.current=null,z.current();return}let n=t.toString().trim();if(!n){H.current=null,z.current();return}let r=t.anchorNode instanceof HTMLElement?t.anchorNode:t.anchorNode?.parentElement;if(r?.closest('[data-role="user"]')){H.current=null,z.current();return}H.current={x:e.clientX,y:e.clientY,range:{start:0,end:0},selectedText:n,lineSnapshot:n},z.current()},[q,Z]),Q=(0,s.useCallback)(e=>{let t=e.target;!(t.closest(".floating-toolbar")||t.closest('[class*="z-[200]"]'))&&H.current&&(H.current=null,z.current())},[]),G=(0,s.useCallback)(()=>{let e=H.current;e&&(X({x:e.x,y:e.y,text:e.selectedText}),H.current=null,z.current(),window.getSelection()?.removeAllRanges())},[]),ee=(0,s.useCallback)(()=>{let e=H.current;e&&(J({x:e.x,y:e.y,text:e.selectedText}),H.current=null,z.current(),window.getSelection()?.removeAllRanges())},[]),et=(0,s.useCallback)(()=>{let e=H.current;if(!e||!p)return;let t=e.selectedText.trim();H.current=null,z.current(),window.getSelection()?.removeAllRanges(),t&&p(t)},[p]),en=(0,s.useCallback)(async e=>{q&&(await K(0,0,e,q.text),X(null))},[q,K]),er=(0,s.useCallback)(async e=>{if(Z&&W&&n)try{let t=(await (0,ec.$3)(n)).map(e=>({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0}));t.push({filePath:ec.Un,startLine:0,endLine:0,codeContent:Z.text});let r=(0,ec.Gw)(t,e);W.sendMessage(r),await (0,ec.RP)(n),U(),J(null)}catch(e){console.error("Failed to send to AI:",e)}},[Z,W,n,U]),es=(0,s.useMemo)(()=>{let t=new Set;return e.filter(e=>!t.has(e.id)&&(t.add(e.id),!0))},[e]),el=(0,s.useRef)(0),ea=(0,s.useRef)(!1),em=(0,s.useCallback)(()=>{let e=k.current;return!e||e.scrollHeight-e.scrollTop-e.clientHeight<50},[]),eh=(0,s.useCallback)(()=>{let e=k.current;return!e||e.scrollTop<50},[]),ef=(0,s.useCallback)(()=>{let e=em(),t=eh();if(E(e),M(!t),T(!e),t&&u&&!d&&m){let e=k.current;e&&(el.current=e.scrollHeight,ea.current=!0),m()}},[em,eh,u,d,m]),ex=(0,s.useCallback)(()=>{w.current?.scrollIntoView({behavior:"smooth"})},[]),ep=(0,s.useCallback)(()=>{y.current?.scrollIntoView({behavior:"smooth"})},[]),eg=(0,s.useCallback)(e=>{let t=k.current;if(!t)return;let n=t.querySelector(`[data-message-id="${e}"]`);n&&(n.scrollIntoView({behavior:"smooth",block:"center"}),n.classList.add("ring-2","ring-brand","ring-offset-2"),setTimeout(()=>{n.classList.remove("ring-2","ring-brand","ring-offset-2")},2e3))},[]);(0,s.useImperativeHandle)(b,()=>({scrollToMessage:eg}),[eg]);let eb=(0,s.useRef)(0),ev=(0,s.useRef)(!0);(0,s.useEffect)(()=>{let t=eb.current,n=e.length;eb.current=n,!ev.current&&S&&n>t&&y.current?.scrollIntoView({behavior:"smooth"})},[e,S]),(0,s.useEffect)(()=>{S&&t&&y.current?.scrollIntoView({behavior:"smooth"})},[t,S]),(0,s.useEffect)(()=>{if(ea.current&&!d){let e=k.current;if(e){let t=e.scrollHeight-el.current;e.scrollTop=t,ea.current=!1}}},[e,d]);let ey=(0,s.useRef)(!1);return(0,s.useEffect)(()=>{x&&ey.current&&e.length>0&&(ey.current=!1,y.current?.scrollIntoView({behavior:"instant"}))},[x,e.length]),(0,s.useEffect)(()=>{ev.current&&e.length>0&&(ev.current=!1,x?y.current?.scrollIntoView({behavior:"instant"}):ey.current=!0)},[e.length,x]),(0,r.jsxs)("div",{ref:j,className:"relative flex-1 min-h-0 overflow-hidden flex flex-col outline-none",tabIndex:-1,onMouseUp:Y,onMouseDown:Q,children:[$&&(0,r.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-2 px-3 py-2 bg-secondary border-b border-border",children:[(0,r.jsx)("input",{ref:V,type:"text",value:I,onChange:e=>P(e.target.value),onKeyDown:B,placeholder:v("codeViewer.searchChat"),className:"flex-1 max-w-xs px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:_.length>0?`${A+1}/${_.length}`:v("common.noMatch")}),(0,r.jsx)("button",{onClick:D,disabled:0===_.length,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:v("codeViewer.prevShiftEnter"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"})})}),(0,r.jsx)("button",{onClick:F,disabled:0===_.length,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:v("codeViewer.nextEnter"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})}),(0,r.jsx)("button",{onClick:O,className:"p-1 rounded hover:bg-accent",title:v("codeViewer.closeEsc"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,r.jsx)("div",{ref:k,onScroll:ef,className:"relative flex-1 min-h-0 overflow-y-auto p-4",children:0!==e.length||t?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{ref:w}),u&&(0,r.jsx)("div",{className:"flex justify-center py-3",children:d?(0,r.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground text-sm",children:[(0,r.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"}),(0,r.jsx)("span",{children:v("chat.loadMoreHistory")})]}):(0,r.jsx)("button",{onClick:m,className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:v("chat.scrollUpForMore")})}),es.map(e=>(0,r.jsx)("div",{"data-message-id":e.id,className:"transition-[box-shadow] duration-300",children:(0,r.jsx)(eo,{message:e,cwd:n,sessionId:a,onFork:f,onApprovePlan:g,isLoading:t})},e.id)),t&&(0,r.jsx)("div",{className:"flex justify-start mb-4",children:(0,r.jsxs)("div",{className:"bg-accent rounded-2xl rounded-bl-md px-4 py-3 max-w-[90%]",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,r.jsx)("span",{className:"inline-block w-5 h-5 border-2 border-brand border-t-transparent rounded-full animate-spin"}),(0,r.jsx)("span",{className:"text-sm",children:"claude2"===o?"Claude 2 is thinking...":"codex"===o?"Codex is thinking...":"kimi"===o?"Kimi is thinking...":"ollama"===o?"Ollama is thinking...":"deepseek"===o?"DeepSeek is thinking...":v("chat.claudeThinking")})]}),i&&(0,r.jsxs)("div",{className:"mt-2 flex items-start gap-2 text-xs text-amber-400 border-t border-border/50 pt-2",children:[(0,r.jsx)("svg",{className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0 animate-spin",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),(0,r.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,r.jsxs)("div",{children:["Retrying API call (attempt ",i.attempt,i.maxRetries>0?`/${i.maxRetries}`:"",i.delayMs>0?`, delay ${(i.delayMs/1e3).toFixed(1)}s`:"",")"]}),(i.errorStatus||i.error)&&(0,r.jsxs)("div",{className:"text-muted-foreground/80 break-words",children:[i.errorStatus?`${i.errorStatus}`:"",i.errorStatus&&i.error?" \xb7 ":"",i.error||""]})]})]}),c&&(0,r.jsxs)("div",{className:"mt-2 flex items-start gap-2 text-xs text-amber-400 border-t border-border/50 pt-2",children:[(0,r.jsx)("svg",{className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01M5.07 19h13.86c1.54 0 2.5-1.67 1.73-3L13.73 4a2 2 0 00-3.46 0L3.34 16c-.77 1.33.19 3 1.73 3z"})}),(0,r.jsx)("div",{className:"flex-1 min-w-0 break-words",children:c})]})]})}),(0,r.jsx)("div",{ref:y})]}):(0,r.jsx)("div",{className:"flex items-center justify-center h-full text-slate-9",children:(0,r.jsxs)("div",{className:"text-center",children:[(0,r.jsx)("div",{className:"text-4xl mb-4",children:"\uD83D\uDCAC"}),(0,r.jsx)("div",{children:v("chat.startConversation")})]})})}),L&&e.length>0&&(0,r.jsx)("button",{onClick:ex,className:"absolute top-2 left-1/2 -translate-x-1/2 p-2 bg-card text-muted-foreground hover:text-foreground shadow-md rounded-full transition-all hover:shadow-lg active:scale-95",title:v("chat.jumpToStart"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"})})}),R&&e.length>0&&(0,r.jsx)("button",{onClick:ep,className:"absolute bottom-2 left-1/2 -translate-x-1/2 p-2 bg-card text-muted-foreground hover:text-foreground shadow-md rounded-full transition-all hover:shadow-lg active:scale-95",title:v("chat.jumpToLatest"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})}),C&&(0,r.jsx)(eu.f,{floatingToolbarRef:H,bumpRef:z,container:C,onAddComment:G,onSendToAI:ee,onSearch:p?et:void 0,isChatLoading:W?.isLoading}),q&&C&&(0,r.jsx)(ed.t,{x:q.x,y:q.y,range:{start:0,end:0},lineSnapshot:q.text,container:C,onSubmit:en,onClose:()=>X(null)}),Z&&C&&(0,r.jsx)(ed.G,{x:Z.x,y:Z.y,range:{start:0,end:0},lineSnapshot:Z.text,container:C,onSubmit:er,onClose:()=>J(null),isChatLoading:W?.isLoading})]})})},17196:(e,t,n)=>{n.d(t,{Np:()=>c,ZD:()=>o,b8:()=>i,kS:()=>l,sQ:()=>a});let r=null,s=["typescript","tsx","javascript","jsx","html","css","scss","json","yaml","python","go","rust","java","ruby","php","bash","shell","markdown","sql","c","cpp","swift","kotlin","dart","lua","graphql","xml"];function l(){return r||(r=Promise.all([n.e(9304),n.e(4523)]).then(n.bind(n,64523)).then(({createHighlighter:e})=>e({themes:["github-dark","github-light"],langs:[...s]}))),r}function a(e){let t=e.split("/").pop()?.toLowerCase()||"",n=t.split(".").pop()?.toLowerCase();if(".env"===t||t.startsWith(".env.")||"dockerfile"===t||t.startsWith("dockerfile.")||"makefile"===t)return"bash";let r={ts:"typescript",tsx:"tsx",js:"javascript",jsx:"jsx",mjs:"javascript",cjs:"javascript",html:"html",htm:"html",css:"css",scss:"scss",json:"json",yaml:"yaml",yml:"yaml",xml:"xml",py:"python",go:"go",rs:"rust",java:"java",kt:"kotlin",rb:"ruby",php:"php",cs:"cpp",cpp:"cpp",c:"c",h:"c",sh:"bash",bash:"bash",zsh:"bash",md:"markdown",mdx:"markdown",sql:"sql",swift:"swift",dart:"dart",lua:"lua",graphql:"graphql",gql:"graphql",toml:"yaml",sass:"scss",less:"css",scala:"java",r:"python",vim:"bash",env:"bash"}[n||""]||"text";return s.includes(r)?r:"text"}function o(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function i(e){return e.map(e=>e.color?`<span style="color:${e.color}">${o(e.content)}</span>`:o(e.content)).join("")}function c(e,t,n,r){if(!t)return[];let s=[],l=n?t:t.toLowerCase();for(let t=0;t<e.length;t++){let a=n?e[t]:e[t].toLowerCase(),o=0;for(;;){let e=a.indexOf(l,o);if(-1===e)break;let n=e+l.length;if(r){let r=e>0?a[e-1]:" ",l=n<a.length?a[n]:" ",o=!/\w/.test(r),i=!/\w/.test(l);o&&i&&s.push({lineIndex:t,startCol:e,endCol:n})}else s.push({lineIndex:t,startCol:e,endCol:n});o=e+1}}return s}},20917:(e,t,n)=>{n.d(t,{e:()=>i});var r=n(12115),s=n(48948),l=n(69809),a=n(2111),o=n(95942);function i(e,t,{sessionId:n,cwd:c,engine:u,chatMode:d,planMode:m,ollamaModel:h,deepseekModel:f,onSessionId:x,onFetchTitle:p,onPtyOutput:g,onRunComplete:b}){let[v,y]=(0,r.useState)(!1),[w,k]=(0,r.useState)(null),[j,C]=(0,r.useState)(null),[N,S]=(0,r.useState)(null),[E,L]=(0,r.useState)(null),M=(0,r.useRef)(null),[R,T]=(0,r.useState)(null),$=(0,r.useRef)(R);$.current=R;let I=(0,r.useRef)(b);I.current=b;let P=(0,r.useRef)(!1),_=(0,r.useRef)(null),A=(0,r.useRef)(n);A.current=n;let F=(0,r.useRef)(null),D=(0,r.useRef)(null),O=(0,r.useRef)(null),V=(0,r.useRef)(!1),B=(0,r.useRef)(!1),W=(0,r.useRef)(0),H=(0,r.useCallback)(()=>{let e=F.current;if(e&&e.text){let{messageId:n,text:r}=e;t(e=>(0,s.F)(e,{type:"stream_event",event:{type:"content_block_delta",delta:{type:"text_delta",text:r}}},{engine:u,assistantId:n})),F.current={messageId:n,text:""}}D.current=null},[t,u]),z=(0,r.useCallback)(()=>{D.current&&(clearTimeout(D.current),D.current=null),_.current&&(clearTimeout(_.current),_.current=null),H(),y(!1);let e=$.current,n=O.current;e&&t(t=>t.map(t=>t.id===e.assistantId||t.id===n?{...t,isStreaming:!1}:t)),T(null),I.current?.()},[H,t]),K=(0,r.useCallback)(()=>{let e=$.current;fetch("/api/chat/stop",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:A.current,runId:e?.runKey})}).catch(()=>{}),z()},[z]),U=(0,r.useCallback)((e,n)=>{let r=e.type;if("pty_output"===r)return void g?.(e.data);if("pty_notice"===r){let r=e.messageKey?l.A.t(e.messageKey,e.params||{}):e.message;if(!r)return;e.terminal?t(e=>e.map(e=>e.id===n?{...e,content:r,isStreaming:!1}:e)):L(r);return}if("system"===r&&"init"===e.subtype){let n=e.session_id;if(x(n),A.current=n,S(null),V.current){let e=`auto-asst-${++W.current}`;O.current=e,t(t=>[...t,{id:e,role:"assistant",content:"",toolCalls:[],isStreaming:!0,runKey:$.current?.runKey}])}B.current=!0;return}if("system"===r&&"task_notification"===e.subtype){if(!B.current){let n=e.status,r=e.summary||"",s=e.task_id,l=`<task-notification>
|
|
2
2
|
`+(s?`<task-id>${s}</task-id>
|
|
3
3
|
`:"")+(n?`<status>${n}</status>
|
|
4
4
|
`:"")+(r?`<summary>${r}</summary>
|
|
@@ -12,4 +12,4 @@
|
|
|
12
12
|
`:"")+(e.status?`<status>${e.status}</status>
|
|
13
13
|
`:"")+(e.summary?`<summary>${e.summary}</summary>
|
|
14
14
|
`:"")+(e.output_file?`<output-file>${e.output_file}</output-file>
|
|
15
|
-
`:"")+"</task-notification>";t(t=>[...t,{id:n,role:"system",content:e.summary||"",systemEvent:{kind:"task-notification",...e.status?{status:e.status}:{},detail:r}}])}return}if("user"===e.type&&e._human){let n=e.message?.content,r="string"==typeof n?n:Array.isArray(n)?n.map(e=>e?.text||"").join(""):"",s=`live-user-${++c.current}`;t(e=>{for(let t=e.length-1;t>=0;t--)if("user"===e[t].role){if(e[t].content===r)return e;break}return[...e,{id:s,role:"user",content:r}]});return}"result"===e.type&&(u.current=!1);let n=i.current??d();t(t=>(0,l.F)(t,e,{engine:a,assistantId:n}))};(0,s.h)({url:e?`/ws/session-stream?sessionId=${encodeURIComponent(e)}`:"/ws/session-stream",enabled:n&&!!e,onMessage:e=>{if("run-snapshot"===e.type&&Array.isArray(e.events)){if("running"!==e.status)return void o?.onRunningChange?.(!1);let n=e.events.find(e=>e?.type==="user"&&e?._human),r=n?.message?.content,s="string"==typeof r?r:"",l=new Set,a=new Set;for(let t of e.events){let e=t?.uuid;if("string"==typeof e&&l.add(e),t?.type==="assistant"&&Array.isArray(t.message?.content))for(let e of t.message.content)e?.name&&"string"==typeof e.id&&a.add(e.id)}for(let n of(t(e=>{let t=e.filter(e=>!("string"==typeof e.id&&e.id.startsWith("live-")));if(!s)return t;let n=-1;for(let e=t.length-1;e>=0;e--)if("user"===t[e].role){t[e].content===s&&(n=e);break}return -1===n?t:t.slice(n+1).every(e=>"assistant"===e.role&&("string"==typeof e.id&&l.has(e.id)||!!e.toolCalls?.length&&e.toolCalls.every(e=>a.has(e.id))))?t.slice(0,n):t}),i.current=null,c.current=0,u.current=!1,e.events))m(n);o?.onRunningChange?.(!0)}else if("run-event"===e.type&&e.message){if("run-ended"===e.message.type){o?.onRunningChange?.(!1),o?.onComplete?.();return}m(e.message),o?.onRunningChange?.(!0)}else"run-idle"===e.type&&o?.onRunningChange?.(!1)}})}},67362:(e,t,n)=>{n.d(t,{xU:()=>j,xZ:()=>k});var r=n(95155),s=n(12115),l=n(47650),a=n(79114),o=n(64702),i=n(1058),c=n(90717),u=n(70188),d=n(48347),m=n(89109),h=n(7320),f=n(22576),x=n(34075),p=n(56978),g=n(17196);function b({lines:e,containerRef:t}){let n=(0,s.useRef)(null),[l,a]=(0,s.useState)({top:0,height:0});if((0,s.useEffect)(()=>{let e=t.current;if(!e)return;let r=()=>{let{scrollTop:t,scrollHeight:r,clientHeight:s}=e,l=n.current?.clientHeight||0;if(r<=s)a({top:0,height:l});else{let e=l/r;a({top:t*e,height:s*e})}};return r(),e.addEventListener("scroll",r),window.addEventListener("resize",r),()=>{e.removeEventListener("scroll",r),window.removeEventListener("resize",r)}},[t]),0===e.length)return null;let o=100/e.length;return(0,r.jsxs)("div",{ref:n,className:"w-4 flex-shrink-0 bg-secondary border-l border-border relative cursor-pointer",onClick:e=>{let r=t.current,s=n.current;if(!r||!s)return;let l=s.getBoundingClientRect(),a=(e.clientY-l.top)/l.height*r.scrollHeight-r.clientHeight/2;r.scrollTo({top:Math.max(0,a),behavior:"smooth"})},children:[e.map((e,t)=>"unchanged"!==e.type&&(0,r.jsx)("div",{className:`absolute left-0 right-0 ${"removed"===e.type?"bg-red-9":"bg-green-9"}`,style:{top:`${t*o}%`,height:`${Math.max(o,.5)}%`,minHeight:"2px"}},t)),(0,r.jsx)("div",{className:"absolute left-0 right-0 bg-muted/60 border-y border-border",style:{top:`${l.top}px`,height:`${Math.max(l.height,10)}px`}})]})}var v=n(37614),y=n(27570);function w(e){return e.params?`${e.name}(${e.params.join(", ")})`:e.name}function k({oldContent:e,newContent:t,filePath:n,isNew:j=!1,isDeleted:C=!1,cwd:N,enableComments:S=!1,onPreview:E,previewLabel:L,onContentSearch:M,targetLine:R,compact:T=!1,symbols:$}){let{t:I}=(0,a.Bd)(),P=L??I("common.preview"),_=(0,s.useMemo)(()=>(0,f.X)(e,t),[e,t]),A=(0,s.useRef)(null),F=(0,s.useRef)(null),D=(0,s.useRef)(null),O=(0,s.useRef)(!1),[V,B]=(0,s.useState)(!1),W=(0,u.iN)(),H=(0,d.r)(),z=S&&!!N,{comments:K,addComment:U,updateComment:q,deleteComment:X,refresh:Z}=(0,i._)({cwd:N||"",filePath:n}),[J,Y]=(0,s.useState)(null),[Q,G]=(0,s.useState)(null);(0,s.useEffect)(()=>{D.current!==Q&&G(D.current)});let{toolbarRef:ee,bumpRef:et,clearToolbar:en}=(0,y.L)({enabled:z,container:Q,resolveLineRange:e=>{if(!document.contains(e))return null;let t=e.nodeType===Node.TEXT_NODE?e.parentElement:e,n=t?.closest("[data-new-line]");if(!n)return null;let r=parseInt(n.getAttribute("data-new-line")||"0",10);return!Number.isFinite(r)||r<=0?null:{start:r,end:r}},buildLineSnapshot:({start:e,end:t})=>{let n=[],r=0;for(let s of _)("unchanged"===s.type||"added"===s.type)&&++r>=e&&r<=t&&n.push(s.content);return n.join("\n")}}),[er,es]=(0,s.useState)(null),[el,ea]=(0,s.useState)(null);(0,s.useEffect)(()=>{B(!0)},[]);let eo=(0,s.useMemo)(()=>{let e=new Set;for(let t of K)for(let n=t.startLine;n<=t.endLine;n++)e.add(n);return e},[K]),ei=(0,s.useMemo)(()=>{let e=new Map;for(let t of K){let n=t.endLine;e.has(n)||e.set(n,[]),e.get(n).push(t)}return e},[K]),ec=(0,s.useCallback)((e,t)=>{t.stopPropagation(),Y({comment:e,x:t.clientX,y:t.clientY}),en(),es(null),ea(null)},[en]),eu=(0,s.useCallback)(()=>{let e=ee.current;e&&(es({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),en())},[en,ee]),ed=(0,s.useCallback)(()=>{let e=ee.current;e&&(ea({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),en())},[en,ee]),em=(0,s.useCallback)(()=>{let e=ee.current;if(!e||!M)return;let t=e.selectedText.trim();en(),t&&M(t)},[M,en,ee]),eh=(0,s.useCallback)(async e=>{if(el&&H&&N)try{let t=await (0,c.$3)(N),r=[];for(let e of t)r.push({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0});r.push({filePath:n,startLine:el.range.start,endLine:el.range.end,codeContent:el.lineSnapshot});let s=(0,c.Gw)(r,e);H.sendMessage(s),await (0,c.RP)(N),Z(),ea(null)}catch(e){console.error("Failed to send to AI:",e)}},[el,H,n,N,Z]),ef=(0,s.useCallback)(async e=>{er&&(await U(er.range.start,er.range.end,e,er.selectedText),es(null))},[er,U]);(0,s.useEffect)(()=>{let e=F.current,t=D.current;if(!e||!t)return;let n=(e,t)=>{O.current||(O.current=!0,t.scrollLeft=e.scrollLeft,requestAnimationFrame(()=>{O.current=!1}))},r=()=>n(e,t),s=()=>n(t,e);return e.addEventListener("scroll",r),t.addEventListener("scroll",s),()=>{e.removeEventListener("scroll",r),t.removeEventListener("scroll",s)}},[]);let{leftLines:ex,rightLines:ep}=(0,s.useMemo)(()=>{let e=[],t=[],n=0,r=0;for(let s=0;s<_.length;s++){let l=_[s];if("unchanged"===l.type){for(;e.length<t.length;)e.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});for(;t.length<e.length;)t.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});n++,r++,e.push({lineNum:n,content:l.content,type:"unchanged",originalIdx:s}),t.push({lineNum:r,content:l.content,type:"unchanged",originalIdx:s})}else"removed"===l.type?(n++,e.push({lineNum:n,content:l.content,type:"removed",originalIdx:s})):"added"===l.type&&(r++,t.push({lineNum:r,content:l.content,type:"added",originalIdx:s}))}for(;e.length<t.length;)e.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});for(;t.length<e.length;)t.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});return{leftLines:e,rightLines:t}},[_]),eg=(0,s.useMemo)(()=>_.map(e=>e.content),[_]),eb=(0,p.C)(eg,n),[ev,ey]=(0,s.useState)(()=>new Map);(0,s.useLayoutEffect)(()=>{ey(new Map),eL.measure()},[ex,ep]);let ew=(0,s.useMemo)(()=>$??[],[$]),{rows:ek,gaps:ej}=(0,s.useMemo)(()=>T?function(e,t,n,r=[]){let s=e.length,l=n=>"unchanged"!==e[n].type||"unchanged"!==t[n].type,a=new Set;for(let e=0;e<s;e++){if(!l(e))continue;let t=Math.max(0,e-3),n=Math.min(s-1,e+3);for(let e=t;e<=n;e++)a.add(e)}let o=[];for(let e=0;e<s;e++){if(a.has(e))continue;let t=e;for(;e<s&&!a.has(e);)e++;o.push({id:o.length,startIdx:t,endIdx:e-1}),e--}for(let e of o){let t=n.get(e.id)??{topRevealed:0,bottomRevealed:0},r=e.endIdx-e.startIdx+1,s=Math.max(0,Math.min(t.topRevealed,r)),l=Math.max(0,Math.min(t.bottomRevealed,r-s));for(let t=e.startIdx;t<e.startIdx+s;t++)a.add(t);for(let t=e.endIdx-l+1;t<=e.endIdx;t++)a.add(t)}let i=[];for(let e=0;e<s;e++){let n;if(a.has(e)){i.push({kind:"diff",idx:e});continue}let l=e;for(;e<s&&!a.has(e);)e++;let c=e-1;e--;let u=o.find(e=>e.startIdx<=l&&c<=e.endIdx);if(!u)continue;let d=c-l+1,m=Math.min(20,d);if(r.length>0&&c+1<s)for(let e=c+1;e<s;e++){let s=t[e].lineNum;if(!(s<=0)){n=function(e,t){let n=null;for(let r of e)r.startLine<=t&&t<=r.endLine&&(!n||r.endLine-r.startLine<n.endLine-n.startLine)&&(n=r);return n}(r,s)??void 0;break}}i.push({kind:"gap-expand",gapId:u.id,direction:"up",revealCount:m}),i.push({kind:"gap-label",gapId:u.id,hiddenCount:d,enclosingFn:n}),i.push({kind:"gap-expand",gapId:u.id,direction:"down",revealCount:m})}return{rows:i,gaps:o}}(ex,ep,ev,ew):{rows:ex.map((e,t)=>({kind:"diff",idx:t})),gaps:[]},[T,ex,ex,ep,ev,ew]),eC=(0,s.useCallback)((e,t)=>{let n=ej.find(t=>t.id===e);n&&ey(r=>{let s=r.get(e)??{topRevealed:0,bottomRevealed:0},l=n.endIdx-n.startIdx+1-s.topRevealed-s.bottomRevealed;if(l<=0)return r;let a=Math.min(20,l),o="up"===t?{...s,topRevealed:s.topRevealed+a}:{...s,bottomRevealed:s.bottomRevealed+a};return new Map(r).set(e,o)})},[ej]),eN=(0,s.useCallback)(e=>{for(let t of ej)if(e>=t.startIdx&&e<=t.endIdx)return t.id;return null},[ej]),eS=(0,s.useCallback)(e=>ek[e]?.kind==="gap-label"?28:20,[ek]),eE=(0,s.useCallback)(e=>{let t=ek[e];if(!t)return e;if("gap-label"===t.kind)return`gl:${t.gapId}`;if("gap-expand"===t.kind)return`ge:${t.gapId}:${t.direction}`;let n=ex[t.idx],r=ep[t.idx];return`d:${n?.lineNum??"x"}:${n?.type??"x"}:${r?.lineNum??"x"}:${r?.type??"x"}`},[ek,ex,ep]),eL=(0,o.Te)({count:ek.length,getScrollElement:()=>A.current,estimateSize:eS,getItemKey:eE,overscan:20}),eM=j?"w-1/4":C?"w-3/4":"w-1/2",eR=j?"w-3/4":C?"w-1/4":"w-1/2",eT=(0,s.useMemo)(()=>ek.map(e=>{if("diff"!==e.kind)return{type:"unchanged"};let t=ex[e.idx],n=ep[e.idx];return"removed"===t.type?{type:"removed"}:n?.type==="added"?{type:"added"}:{type:"unchanged"}}),[ek,ex,ep]),e$=eL.getTotalSize(),eI=eL.getVirtualItems();return(0,s.useEffect)(()=>{if(!R)return;let e=("after"===R.side?ep:ex).findIndex(e=>e.lineNum===R.line);if(-1===e)return;let t=ek.findIndex(t=>"diff"===t.kind&&t.idx===e);if(-1===t){let t=eN(e);if(null!==t){let e=ej.find(e=>e.id===t);if(!e)return;let n=e.endIdx-e.startIdx+1;ey(e=>{let r=e.get(t)??{topRevealed:0,bottomRevealed:0};if(r.topRevealed+r.bottomRevealed>=n)return e;let s=new Map(e);return s.set(t,{topRevealed:n,bottomRevealed:0}),s})}return}let n=requestAnimationFrame(()=>{eL.scrollToIndex(t,{align:"start"})});return()=>cancelAnimationFrame(n)},[R,ex,ep,ek]),(0,r.jsxs)("div",{className:"font-mono flex flex-col h-full text-sm",children:[(0,r.jsxs)("div",{className:"flex flex-shrink-0 border-b border-border",children:[(0,r.jsx)("div",{className:`${eM} min-w-0 px-2 py-1 bg-accent text-muted-foreground text-center text-xs font-medium border-r border-border`,children:j?"(New File)":C?"Deleted":"Old"}),(0,r.jsxs)("div",{className:`${eR} min-w-0 px-2 py-1 bg-accent text-muted-foreground text-xs font-medium relative`,children:[(0,r.jsx)("span",{className:"block text-center",children:C?"(Deleted)":"New"}),(0,r.jsxs)("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center gap-2",children:[E&&(0,r.jsx)("button",{onClick:E,className:"text-muted-foreground hover:text-foreground transition-colors",children:P}),!C&&t&&(0,r.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(t),(0,x.oR)(I("diffViewer.copiedAll"))},className:"text-muted-foreground hover:text-foreground transition-colors",children:I("common.copy")})]})]}),(0,r.jsx)("div",{className:"w-4 flex-shrink-0 bg-accent"})]}),(0,r.jsxs)("div",{className:"flex-1 min-h-0 flex",children:[(0,r.jsx)("div",{ref:A,className:"flex-1 overflow-y-auto overflow-x-hidden",children:(0,r.jsxs)("div",{className:"flex",style:{height:`${e$}px`},children:[(0,r.jsx)("div",{ref:F,className:`${eM} overflow-x-auto border-r border-border`,children:(0,r.jsx)("div",{className:"min-w-max h-full",style:{position:"relative"},children:eI.map(e=>{let t=ek[e.index];if("gap-expand"===t.kind||"gap-label"===t.kind){let n="gap-label"===t.kind;return(0,r.jsx)("div",{ref:eL.measureElement,"data-index":e.index,style:{position:"absolute",top:0,left:0,width:"100%",height:`${Math.max(e.size,eS(e.index))}px`,transform:`translateY(${e.start}px)`},className:n?"bg-accent border-y border-border":""},e.key)}let n=ex[t.idx];return(0,r.jsxs)("div",{ref:eL.measureElement,"data-index":e.index,"data-row-idx":t.idx,style:{position:"absolute",top:0,left:0,minWidth:"100%",width:"max-content",height:`${Math.max(e.size,eS(e.index))}px`,transform:`translateY(${e.start}px)`},className:`flex ${"removed"===n.type?"bg-red-9/15 dark:bg-red-9/25":""}`,children:[(0,r.jsx)("span",{className:"w-10 flex-shrink-0 text-right pr-2 text-slate-9 select-none border-r border-border",children:n.lineNum||""}),(0,r.jsx)("span",{className:"whitespace-pre pl-2",dangerouslySetInnerHTML:{__html:n.originalIdx>=0&&eb[n.originalIdx]||(0,g.ZD)(n.content||" ")}})]},e.key)})})}),(0,r.jsx)("div",{ref:D,className:`${eR} overflow-x-auto`,children:(0,r.jsx)("div",{className:"min-w-max h-full",style:{position:"relative"},children:eI.map(e=>{let t=ek[e.index];if("gap-expand"===t.kind)return(0,r.jsx)("button",{ref:eL.measureElement,"data-index":e.index,type:"button",onClick:()=>eC(t.gapId,t.direction),style:{position:"absolute",top:0,left:0,width:"100%",height:`${Math.max(e.size,eS(e.index))}px`,transform:`translateY(${e.start}px)`},className:"flex items-center justify-center text-[11px] text-foreground/50 hover:bg-accent hover:text-brand active:bg-brand/15 transition-colors duration-100 cursor-pointer focus:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-brand/60",title:I("up"===t.direction?"diffViewer.gap.expandUp":"diffViewer.gap.expandDown",{count:t.revealCount}),"aria-label":I("up"===t.direction?"diffViewer.gap.expandUp":"diffViewer.gap.expandDown",{count:t.revealCount}),children:(0,r.jsx)("span",{className:"select-none",children:I("diffViewer.gap.more",{count:t.revealCount})})},e.key);if("gap-label"===t.kind)return(0,r.jsxs)("div",{ref:eL.measureElement,"data-index":e.index,"data-gap-id":t.gapId,style:{position:"absolute",top:0,left:0,width:"100%",height:`${Math.max(e.size,eS(e.index))}px`,transform:`translateY(${e.start}px)`},className:"flex items-center justify-center gap-2 px-3 text-[11px] text-foreground/80 bg-accent border-y border-border min-w-0 select-none",children:[(0,r.jsx)("span",{className:"flex-shrink-0",children:I("diffViewer.gap.hidden",{count:t.hiddenCount})}),t.enclosingFn&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"opacity-50 flex-shrink-0",children:"\xb7"}),(0,r.jsx)("span",{className:"truncate min-w-0 font-medium",title:w(t.enclosingFn),children:w(t.enclosingFn)})]})]},e.key);let n=ep[t.idx],s=n?.lineNum||0,l=s>0&&eo.has(s),a=ei.get(s),o=a?.[0],i=er&&s>=er.range.start&&s<=er.range.end,c=el&&s>=el.range.start&&s<=el.range.end,u=i||c;return(0,r.jsxs)("div",{ref:eL.measureElement,"data-index":e.index,"data-new-line":s||void 0,"data-row-idx":t.idx,style:{position:"absolute",top:0,left:0,minWidth:"100%",width:"max-content",height:`${Math.max(e.size,eS(e.index))}px`,transform:`translateY(${e.start}px)`},className:`flex ${u?"bg-blue-9/20":l?"bg-amber-9/10":n?.type==="added"?"bg-green-9/15 dark:bg-green-9/25":""}`,children:[(0,r.jsxs)("span",{className:`flex-shrink-0 flex items-center gap-0.5 pr-1 text-slate-9 select-none border-r border-border ${u?"bg-blue-9/30":""}`,style:{width:z?"52px":"40px"},children:[z&&s>0&&l&&o&&(0,r.jsx)("button",{onClick:e=>ec(o,e),className:"w-4 h-4 flex items-center justify-center rounded hover:bg-accent text-amber-9",title:I("codeViewer.nComments",{count:a?.length}),children:(0,r.jsx)("svg",{className:"w-3 h-3",fill:"currentColor",viewBox:"0 0 20 20",children:(0,r.jsx)("path",{fillRule:"evenodd",d:"M18 10c0 3.866-3.582 7-8 7a8.841 8.841 0 01-4.083-.98L2 17l1.338-3.123C2.493 12.767 2 11.434 2 10c0-3.866 3.582-7 8-7s8 3.134 8 7zM7 9H5v2h2V9zm8 0h-2v2h2V9zM9 9h2v2H9V9z",clipRule:"evenodd"})})}),z&&s>0&&!l&&(0,r.jsx)("span",{className:"w-4"}),(0,r.jsx)("span",{className:"flex-1 text-right pr-1",children:s||""})]}),(0,r.jsx)("span",{className:"whitespace-pre pl-2",dangerouslySetInnerHTML:{__html:n?.originalIdx>=0&&eb[n.originalIdx]||(0,g.ZD)(n?.content||" ")}})]},e.key)})})})]})}),(0,r.jsx)(b,{lines:eT,containerRef:A})]}),V&&W&&(0,l.createPortal)((0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(m.f,{floatingToolbarRef:ee,bumpRef:et,container:W,onAddComment:eu,onSendToAI:ed,onSearch:M?em:void 0,isChatLoading:H?.isLoading??!1}),er&&(0,r.jsx)(h.t,{x:er.x,y:er.y,range:er.range,lineSnapshot:er.lineSnapshot,container:W,onSubmit:ef,onClose:()=>es(null)}),el&&(0,r.jsx)(h.G,{x:el.x,y:el.y,range:el.range,filePath:n,lineSnapshot:el.lineSnapshot,container:W,onSubmit:eh,onClose:()=>ea(null),isChatLoading:H?.isLoading}),J&&(0,r.jsx)(v.t,{x:J.x,y:J.y,comment:J.comment,container:W,onClose:()=>Y(null),onUpdateComment:q,onDeleteComment:X})]}),W)]})}function j({oldContent:e,newContent:t,filePath:n}){let l=(0,s.useMemo)(()=>(0,f.X)(e,t),[e,t]),a=(0,s.useRef)(null),i=(0,s.useMemo)(()=>l.map(e=>e.content),[l]),c=(0,p.C)(i,n),u=(0,s.useCallback)(e=>{let t=l[e];return t?`${t.type}:${t.oldLineNum??"x"}:${t.newLineNum??"x"}`:e},[l]),d=(0,o.Te)({count:l.length,getScrollElement:()=>a.current,estimateSize:()=>20,getItemKey:u,overscan:20});return(0,r.jsx)("div",{ref:a,className:"font-mono text-sm overflow-auto h-full",children:(0,r.jsx)("div",{style:{height:`${d.getTotalSize()}px`,position:"relative"},children:d.getVirtualItems().map(e=>{let t=l[e.index];return(0,r.jsxs)("div",{style:{position:"absolute",top:0,left:0,minWidth:"100%",width:"max-content",height:`${e.size}px`,transform:`translateY(${e.start}px)`},className:`flex ${"removed"===t.type?"bg-red-9/15 dark:bg-red-9/25":"added"===t.type?"bg-green-9/15 dark:bg-green-9/25":""}`,children:[(0,r.jsx)("span",{className:"w-10 flex-shrink-0 text-right pr-2 text-slate-9 select-none border-r border-border",children:"added"!==t.type?t.oldLineNum:""}),(0,r.jsx)("span",{className:"w-10 flex-shrink-0 text-right pr-2 text-slate-9 select-none border-r border-border",children:"removed"!==t.type?t.newLineNum:""}),(0,r.jsx)("span",{className:`w-6 flex-shrink-0 text-center select-none ${"removed"===t.type?"text-red-11":"added"===t.type?"text-green-11":"text-slate-9"}`,children:"removed"===t.type?"-":"added"===t.type?"+":" "}),(0,r.jsx)("span",{className:"flex-1 whitespace-pre pl-1",dangerouslySetInnerHTML:{__html:c[e.index]||(0,g.ZD)(t.content||" ")}})]},e.key)})})})}},70188:(e,t,n)=>{n.d(t,{Ee:()=>m,SU:()=>c,ft:()=>d,iN:()=>u});var r=n(95155),s=n(12115),l=n(79114),a=n(47650),o=n(34075);let i=(0,s.createContext)(null);function c({container:e,children:t}){return(0,r.jsx)(i.Provider,{value:e,children:t})}function u(){return(0,s.useContext)(i)}function d({x:e,y:t,path:n,cwd:c,isDirectory:u,onClose:m,onCreateFile:h,onDelete:f,onRefresh:x,onCopyFile:p,onPaste:g}){let{t:b}=(0,l.Bd)(),v=(0,s.useRef)(null),y=(0,s.useContext)(i),w=n.split("/").pop()||n,k=`${c}/${n}`,j=n.includes("/")?n.substring(0,n.lastIndexOf("/")):"",C=j?`${c}/${j}`:c,N=u?n:j,S=u?k:C;(0,s.useEffect)(()=>{let e=e=>{v.current&&!v.current.contains(e.target)&&m()},t=e=>{"Escape"===e.key&&m()};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[m]);let[E,L]=(0,s.useState)({x:0,y:0});(0,s.useEffect)(()=>{if(v.current&&y){let n=y.getBoundingClientRect(),r=v.current.getBoundingClientRect(),s=e-n.left,l=t-n.top;s=Math.min(s,n.width-r.width-8),l=Math.min(l,n.height-r.height-8),L({x:s=Math.max(8,s),y:l=Math.max(8,l)})}else if(v.current){let n=v.current.getBoundingClientRect();L({x:Math.max(8,Math.min(e,window.innerWidth-n.width-8)),y:Math.max(8,Math.min(t,window.innerHeight-n.height-8))})}},[e,t,y]);let M=(0,s.useCallback)(async(e,t)=>{try{await navigator.clipboard.writeText(e),(0,o.oR)(b("toast.copiedName",{name:t}),"success")}catch{(0,o.oR)(b("toast.copyFailed"),"error")}m()},[m,b]),R=u?n:j,T=[{label:b("fileContextMenu.copyRelativePath"),value:n},{label:b("fileContextMenu.copyAbsolutePath"),value:k},{label:b("fileContextMenu.copyRelativeDirPath"),value:N||"."},{label:b("fileContextMenu.copyAbsoluteDirPath"),value:S},{label:u?b("fileContextMenu.copyFolderName"):b("fileContextMenu.copyFileName"),value:w}],$=(0,r.jsxs)("div",{ref:v,className:"absolute z-[200] bg-card border border-border rounded-lg shadow-lg py-1 w-fit whitespace-nowrap",style:{left:E.x,top:E.y},children:[h&&(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>{m(),h(R)},children:b("fileContextMenu.createFile")}),p&&(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>{m(),p(n)},children:u?b("fileContextMenu.copyFolder"):b("fileContextMenu.copyFile")}),g&&(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>{m(),g(R)},children:b("fileContextMenu.pasteHere")}),f&&(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-destructive hover:bg-accent transition-colors",onClick:()=>{m(),f(n,u,w)},children:u?b("fileContextMenu.deleteFolder"):b("fileContextMenu.deleteFile")}),(h||f||p||g)&&(0,r.jsx)("div",{className:"my-1 border-t border-border"}),T.map((e,t)=>(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>M(e.value,e.label),children:e.label},t))]});return y?(0,a.createPortal)($,y):$}function m(){let[e,t]=(0,s.useState)(null);return{contextMenu:e,showContextMenu:(0,s.useCallback)((e,n,r)=>{e.preventDefault(),e.stopPropagation(),t({x:e.clientX,y:e.clientY,path:n,isDirectory:r})},[]),hideContextMenu:(0,s.useCallback)(()=>{t(null)},[])}}},75346:(e,t,n)=>{n.d(t,{n:()=>s});var r=n(88292);let s={SessionChange:(0,r.R)("session-change"),ViewChange:(0,r.R)("view-change"),OpenNote:(0,r.R)("open-note"),LangChange:(0,r.R)("lang-change"),TabAdd:(0,r.R)("tab-add"),TabClose:(0,r.R)("tab-close"),SwitchSession:(0,r.R)("switch-session"),ProjectChange:(0,r.R)("project-change"),OpenProject:(0,r.R)("open-project"),SessionComplete:(0,r.R)("session-complete"),OpenTokenStats:(0,r.R)("open-token-stats"),PinnedSessionsChanged:(0,r.R)("pinned-sessions-changed"),ScheduledTasksChanged:(0,r.R)("scheduled-tasks-changed"),ScreenshotPrepare:(0,r.R)("screenshot-prepare"),ScreenshotDone:(0,r.R)("screenshot-done")}},82292:(e,t,n)=>{function r(e,t){for(let n of e){if(n.path===t)return n;if(n.children){let e=r(n.children,t);if(e)return e}}return null}function s(e,t){if(!e)return"";let n=r(t,e);if(n?.isDirectory)return e;let s=e.split("/");return s.pop(),s.join("/")}function l(e){let t=[];for(let n of e){let e=n.split("/"),r=t;for(let t=0;t<e.length;t++){let n=e[t],s=t===e.length-1,l=e.slice(0,t+1).join("/"),a=r.find(e=>e.name===n);a||(a={name:n,path:l,isDirectory:!s,children:s?void 0:[]},r.push(a)),!s&&a.children&&(r=a.children)}}let n=e=>{e.sort((e,t)=>e.isDirectory&&!t.isDirectory?-1:!e.isDirectory&&t.isDirectory?1:e.name.localeCompare(t.name)),e.forEach(e=>{e.children&&n(e.children)})};return n(t),t}function a(e){let t=[],n=e=>{for(let r of e)r.isDirectory&&(t.push(r.path),r.children&&n(r.children))};return n(e),t}n.d(t,{B_:()=>f,HR:()=>function e(t,n){if(0===n.length)return t;let r=new Map(n.map(e=>[e.path,e]));return t.map(t=>{let n=r.get(t.path);return n&&t.isDirectory?void 0===t.children&&void 0!==n.children?{...t,children:n.children}:void 0!==t.children&&void 0!==n.children?{...t,children:e(t.children,n.children)}:t:t})},KH:()=>u,MB:()=>r,S7:()=>s,fw:()=>d,q3:()=>c,r6:()=>m,tE:()=>h,tW:()=>a,u:()=>i,v3:()=>l});let o=new Set(["png","jpg","jpeg","gif","svg","webp","ico","bmp"]);function i(e){let t=e.split(".").pop()?.toLowerCase();return o.has(t||"")}function c(e,t,n=!1){let r=new Set;if(!t)return r;let s=t.toLowerCase(),l=e=>{if(r.add(e.path),e.children)for(let t of e.children)l(t)},a=(e,t)=>{let o=e.name.toLowerCase(),i=n?o===s:o.includes(s);if(i&&e.children)return l(e),t.forEach(e=>r.add(e)),!0;let c=!1;if(e.children)for(let n of e.children)a(n,[...t,e.path])&&(c=!0);return(!!i||!!c)&&(r.add(e.path),t.forEach(e=>r.add(e)),!0)};for(let t of e)a(t,[]);return r}function u(e,t,n=!1){let r=new Set;if(!t)return r;let s=t.toLowerCase();for(let t of e){let e=t.split("/");for(let t=0;t<e.length;t++){let l=e[t].toLowerCase();if(n?l===s:l.includes(s)){for(let t=0;t<=e.length-1;t++)r.add(e.slice(0,t+1).join("/"));break}}}return r}function d(e){let t=Math.floor(Math.floor((Date.now()-1e3*e)/1e3)/60),n=Math.floor(t/60),r=Math.floor(n/24),s=Math.floor(r/30),l=Math.floor(r/365);return l>0?`${l}y ago`:s>0?`${s}mo ago`:r>0?`${r}d ago`:n>0?`${n}h ago`:t>0?`${t}m ago`:"just now"}function m(e){let t=new Date(e),n=new Date,r=t.getFullYear()===n.getFullYear(),s=String(t.getMonth()+1).padStart(2,"0"),l=String(t.getDate()).padStart(2,"0"),a=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return r?`${s}-${l} ${a}:${o}`:`${t.getFullYear()}-${s}-${l} ${a}:${o}`}let h=()=>{},f=50},83448:(e,t,n)=>{n.d(t,{Cr:()=>v,JC:()=>d,M5:()=>c,QW:()=>f,Zr:()=>h,an:()=>b,em:()=>i,l1:()=>u,n_:()=>m,qD:()=>g,td:()=>o,z2:()=>x});var r=n(49433),s=n(82680);let l=(e,t)=>r.tryPromise({try:async()=>{let n=await fetch(e,t);if(!n.ok)throw Error(`HTTP ${n.status}`);return await n.json()},catch:n=>new s.uV({message:`${t?.method??"GET"} ${e} failed`,cause:n})}),a=(e,t)=>l(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),o=()=>l("/api/settings"),i=e=>l("/api/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),c=()=>l("/api/commands"),u=()=>l("/api/skills"),d=e=>a("/api/bash",e),m=e=>r.tryPromise({try:async()=>{let t=await fetch("/api/session-by-path",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});return t.ok?await t.json():null},catch:e=>new s.uV({message:"POST /api/session-by-path failed",cause:e})}),h=(e,t)=>a(`/api/session/${encodeURIComponent(e)}/fork`,t),f=e=>l(`/api/sessions/projects/${encodeURIComponent(e)}`),x=()=>l("/api/global-state").pipe(r.map(e=>e.sessions??[])),p=()=>r.tryPromise({try:async()=>{let e=await fetch("/api/ollama/models");return 503===e.status?{_tag:"not-running"}:e.ok?{_tag:"ok",models:(await e.json()).models??[]}:{_tag:"error",message:"Failed to fetch models"}},catch:e=>new s.uV({message:"fetch ollama models failed",cause:e})}),g=e=>r.gen(function*(){let t=yield*p();if("not-running"!==t._tag)return t;e&&(yield*r.sync(e));let n=yield*r.tryPromise({try:async()=>{let e=await fetch("/api/ollama/start",{method:"POST"}),t=await e.json().catch(()=>({}));return 404===e.status?{_tag:"not-installed",message:t.message||"Ollama is not installed"}:e.ok?{_tag:"started"}:{_tag:"error",message:"Failed to start Ollama"}},catch:e=>new s.uV({message:"start ollama failed",cause:e})});if("not-installed"===n._tag)return{_tag:"not-installed",message:n.message};if("error"===n._tag)return{_tag:"error",message:n.message};let l=yield*p();return"not-running"===l._tag?{_tag:"error",message:"Ollama started but cannot fetch models"}:l}),b=e=>l(`/api/file?path=${encodeURIComponent(e)}`),v=e=>l(`/api/claude-stats?engine=${encodeURIComponent(e)}`)},83897:(e,t,n)=>{n.d(t,{k_:()=>o,nH:()=>i});var r=n(95155),s=n(12115),l=n(48347);let a=(0,s.createContext)(null);function o({children:e}){let t=(0,s.useRef)(new Map),n=(0,s.useRef)(null),[i,c]=(0,s.useState)(!1),u=(0,s.useCallback)((e,n)=>{t.current.set(n,e)},[]),d=(0,s.useCallback)(e=>{t.current.delete(e)},[]),m=(0,s.useCallback)(e=>{n.current=e},[]),h=(0,s.useCallback)(e=>{let r=n.current;if(!r)return void console.warn("No active tab to send message");let s=t.current.get(r);s?s(e):console.warn(`No chat sender registered for tab ${r}`)},[]),f=(0,s.useMemo)(()=>({sendMessage:h,isLoading:i,registerChat:u,unregisterChat:d,setActiveTab:m,setIsLoading:c}),[h,i,u,d,m]),x=(0,s.useMemo)(()=>({sendMessage:h,isLoading:i}),[h,i]);return(0,r.jsx)(a.Provider,{value:f,children:(0,r.jsx)(l.H,{value:x,children:e})})}function i(){return(0,s.useContext)(a)}},85839:(e,t,n)=>{n.d(t,{m:()=>i,z:()=>o});var r=n(12115),s=n(49433),l=n(86957),a=n(82680);let o=e=>s.tryPromise({try:async()=>{let t=await fetch("/api/session-by-path",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});return t.ok?await t.json():null},catch:e=>new a.uV({message:"session-by-path failed",cause:e})});function i(e,t,n,{cwd:c,initialSessionId:u,onSessionId:d,onTitleChange:m,onTokenUsage:h,liveRunningRef:f}){let[x,p]=(0,r.useState)(!1),[g,b]=(0,r.useState)(!1),[v,y]=(0,r.useState)(!1),[w,k]=(0,r.useState)(void 0),[j,C]=(0,r.useState)(0),[N,S]=(0,r.useState)(null),[E,L]=(0,r.useState)(null),M=(0,r.useRef)(m);M.current=m;let R=(0,r.useRef)(h);R.current=h;let T=(0,r.useRef)(void 0),$=(0,r.useRef)(0),I=(0,r.useCallback)(async(e,n,r=!1,s,a)=>{if(r){let e=Date.now();if(e-$.current<5e3)return;$.current=e}r||p(!0);try{let i={cwd:e,sessionId:n,limit:s,beforeTurnIndex:a};r&&T.current&&(i.ifFingerprint=T.current);let c=await l.t4.runPromiseExit(o(i));if("Success"===c._tag&&c.value){let e=c.value;if(e.notModified)return;e.fingerprint&&(T.current=e.fingerprint),void 0!==e.totalTurns&&C(e.totalTurns),void 0!==e.hasMore&&y(e.hasMore),e.messages&&e.messages.length>0&&(r?t(t=>{let n=e.messages;if(t.length===n.length&&t.length>0&&t[t.length-1].content===n[n.length-1].content)return t;let r=0;for(let e=0;e<Math.min(t.length,n.length)&&t[e].id===n[e].id&&t[e].content===n[e].content;e++)r=e+1;return r===t.length&&r<n.length?[...t,...n.slice(r)]:n}):f?.current||t(e.messages),S(n)),e.sessionId&&d(e.sessionId),e.engine&&L(e.engine),e.title&&M.current?.(e.title),e.usage&&R.current?.({inputTokens:e.usage.input_tokens||0,outputTokens:e.usage.output_tokens||0,cacheCreationInputTokens:e.usage.cache_creation_input_tokens||0,cacheReadInputTokens:e.usage.cache_read_input_tokens||0,totalCostUsd:0})}}catch(e){console.error("Failed to load history by cwd and sessionId:",e)}finally{r||p(!1)}},[t,d]),P=(0,r.useCallback)(async()=>{if(c&&n&&!g&&v){b(!0);try{let r=void 0!==w?w:j-Math.ceil(e.filter(e=>"user"===e.role).length),s=await l.t4.runPromiseExit(o({cwd:c,sessionId:n,limit:10,beforeTurnIndex:r>0?r:void 0}));if("Success"===s._tag&&s.value){let e=s.value;if(e.messages&&e.messages.length>0){t(t=>[...e.messages,...t]);let s=e.messages.filter(e=>"user"===e.role).length;k(r-s),S(n)}void 0!==e.hasMore&&y(e.hasMore),e.fingerprint&&(T.current=e.fingerprint)}else"Failure"===s._tag&&console.error("Failed to load more history:",s.cause)}finally{b(!1)}}},[c,n,g,v,w,j,e,t]),_=(0,r.useCallback)(async e=>{p(!0);let n=s.tryPromise({try:async()=>{let t=await fetch(`/api/session/${e}/history`);return t.ok?await t.json():null},catch:e=>new a.uV({message:"load session history failed",cause:e})}),r=await l.t4.runPromiseExit(n);"Success"===r._tag&&r.value?.messages&&r.value.messages.length>0?(t(r.value.messages),S(e)):"Failure"===r._tag&&console.error("Failed to load history:",r.cause),p(!1)},[t]);return(0,r.useEffect)(()=>{c&&u&&I(c,u,!1,10)},[]),{isLoadingHistory:x,isLoadingMore:g,hasMoreHistory:v,loadMoreHistory:P,loadHistory:_,loadHistoryByCwdAndSessionId:I,loadedSessionId:N,loadedEngine:E}}},89109:(e,t,n)=>{n.d(t,{f:()=>o});var r=n(95155),s=n(12115),l=n(79114);function a({x:e,y:t,visible:n,container:s,onAddComment:o,onSendToAI:i,onSearch:c,isChatLoading:u}){let{t:d}=(0,l.Bd)(),m=s.getBoundingClientRect(),h=e-m.left,f=Math.max(0,t-m.top-40);return(0,r.jsxs)("div",{className:"floating-toolbar absolute z-[200] flex items-center gap-1.5 bg-card border border-border rounded-lg shadow-xl p-1.5",style:{left:h+8,top:f,visibility:n?"visible":"hidden",pointerEvents:n?"auto":"none"},children:[(0,r.jsx)("button",{className:"px-3 py-1.5 text-xs font-medium border border-brand text-brand rounded-md hover:bg-brand/10 transition-colors",onClick:o,children:d("floatingToolbar.addComment")}),(0,r.jsx)("button",{className:"px-3 py-1.5 text-xs font-medium border border-brand text-brand rounded-md hover:bg-brand/10 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",onClick:i,disabled:u,title:d(u?"comments.aiResponding":"floatingToolbar.sendToAI"),children:d("floatingToolbar.sendToAI")}),c&&(0,r.jsx)("button",{className:"px-3 py-1.5 text-xs font-medium border border-brand text-brand rounded-md hover:bg-brand/10 transition-colors",onClick:c,children:d("floatingToolbar.search")})]})}let o=(0,s.memo)(function({floatingToolbarRef:e,bumpRef:t,container:n,onAddComment:l,onSendToAI:o,onSearch:i,isChatLoading:c}){let[u,d]=(0,s.useState)(0);(0,s.useEffect)(()=>{t.current=()=>d(e=>e+1)},[t]);let m=(0,s.useMemo)(()=>e.current,[u]);return(0,r.jsx)(a,{x:m?.x??0,y:m?.y??0,visible:!!m,container:n,onAddComment:l,onSendToAI:o,onSearch:i,isChatLoading:c})})},90717:(e,t,n)=>{n.d(t,{$3:()=>d,Cm:()=>u,Gw:()=>f,RP:()=>m,Un:()=>h,zL:()=>c});var r=n(69809),s=n(49433),l=n(86957),a=n(82680),o=n(46456);let i=new Set;function c(e){return i.add(e),()=>i.delete(e)}function u(){i.forEach(e=>e())}async function d(e){let t=await l.t4.runPromiseExit((0,o.lb)(e));if("Success"!==t._tag)throw Error("Failed to fetch comments");let n=t.value.comments??[];if(0===n.length)return[];let r=new Map;for(let e of n)e.selectedText||(r.has(e.filePath)||r.set(e.filePath,[]),r.get(e.filePath).push(e));let i=new Map;await Promise.all(Array.from(r.keys()).map(async t=>{let n=await l.t4.runPromiseExit(s.tryPromise({try:async()=>{let n=await fetch(`/api/files/text?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`);return n.ok?await n.json():null},catch:e=>new a.uV({message:`read file text ${t} failed`,cause:e})}));"Success"===n._tag&&n.value&&"string"==typeof n.value.content?i.set(t,n.value.content.split("\n")):"Failure"===n._tag&&console.error(`Failed to read file ${t}:`,n.cause)}));let c=[];for(let e of n){if(e.selectedText){c.push({...e,codeContent:e.selectedText});continue}let t=i.get(e.filePath),n="";if(t){let r=Math.max(0,e.startLine-1),s=Math.min(t.length,e.endLine);n=t.slice(r,s).join("\n")}c.push({...e,codeContent:n})}return c}async function m(e){let t=await l.t4.runPromiseExit((0,o.tj)(e));return"Success"===t._tag?(u(),!0):(console.error("Failed to clear comments:",t.cause),!1)}let h="__chat__";function f(e,t){let n=e.filter(e=>e.filePath===h),s=e.filter(e=>e.filePath!==h),l=[];for(let e of(s.length>0&&(l.push(`${r.A.t("comments.codeRef")}`,""),s.forEach((e,t)=>{l.push(`[${t+1}] ${e.filePath}:${e.startLine}-${e.endLine}`),l.push("```"),l.push(e.codeContent),l.push("```"),e.note&&l.push(r.A.t("comments.note",{content:e.note})),l.push("")})),n)){let t=e.codeContent.split("\n").map(e=>`> ${e}`).join("\n");l.push(t),e.note&&l.push(e.note),l.push("")}return l.push(r.A.t("comments.question",{question:t})),l.join("\n")}},95045:(e,t,n)=>{n.d(t,{F:()=>a});var r=n(49433),s=n(88292),l=n(86957);let a=(e,t)=>{l.t4.runFork(r.flatMap(s.d,n=>n.publish(e,t)))}},95942:(e,t,n)=>{n.d(t,{EE:()=>o,K2:()=>i,ri:()=>c});var r=n(95155),s=n(12115),l=n(79114),a=n(8422);let o=80,i=24,c=(0,s.forwardRef)(function({visible:e,running:t,onInput:n},c){let{t:u}=(0,l.Bd)(),d=(0,s.useRef)(n);(0,s.useEffect)(()=>{d.current=n},[n]);let[m,h]=(0,s.useState)(!1),f=(0,s.useRef)(!1);(0,s.useEffect)(()=>{t&&!f.current?h(!0):!t&&f.current&&h(!1),f.current=t},[t]);let x=(0,s.useRef)(null),p=(0,s.useRef)(null),g=(0,s.useRef)(""),b=(0,s.useCallback)(()=>{if(p.current||!x.current)return;let e=new a.B({cols:o,rows:i,fontSize:11,fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, "Courier New", monospace',convertEol:!1,scrollback:2e3,theme:{background:"#0a0a0a",foreground:"#d4d4d8"},disableStdin:!1,allowProposedApi:!0});e.open(x.current),e.onData(e=>d.current?.(e)),g.current&&e.write(g.current),p.current=e},[]);return((0,s.useEffect)(()=>{m&&e?b():(p.current?.dispose(),p.current=null)},[m,e,b]),(0,s.useImperativeHandle)(c,()=>({write:e=>{g.current+=e,g.current.length>2e5&&(g.current=g.current.slice(-15e4)),p.current?.write(e)},clear:()=>{g.current="",p.current?.clear()}}),[]),e)?(0,r.jsxs)("div",{className:"absolute top-12 right-3 z-30 rounded-lg border border-border bg-card shadow-lg overflow-hidden",style:{width:m?"auto":180},"data-testid":"pty-floating-window",children:[(0,r.jsxs)("button",{type:"button",onClick:()=>h(e=>!e),"data-testid":"pty-floating-toggle",className:"w-full flex items-center justify-between gap-3 px-2.5 py-1.5 text-xs bg-accent/60 hover:bg-accent",children:[(0,r.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,r.jsx)("span",{className:`inline-block w-2 h-2 rounded-full ${t?"bg-green-500 animate-pulse":"bg-muted-foreground"}`}),(0,r.jsxs)("span",{className:"text-muted-foreground",children:[u("chat.ptyTerminal"),t?` \xb7 ${u("chat.ptyRunning")}`:""]})]}),(0,r.jsx)("span",{className:"text-muted-foreground",children:m?`${u("chat.ptyCollapse")} ▾`:`${u("chat.ptyExpand")} ▸`})]}),(0,r.jsx)("div",{ref:x,"data-testid":"pty-floating-term",style:{display:m?"block":"none",padding:4},className:"bg-[#0a0a0a]"})]}):null})}}]);
|
|
15
|
+
`:"")+"</task-notification>";t(t=>[...t,{id:n,role:"system",content:e.summary||"",systemEvent:{kind:"task-notification",...e.status?{status:e.status}:{},detail:r}}])}return}if("user"===e.type&&e._human){let n=e.message?.content,r="string"==typeof n?n:Array.isArray(n)?n.map(e=>e?.text||"").join(""):"",s=`live-user-${++c.current}`;t(e=>{for(let t=e.length-1;t>=0;t--)if("user"===e[t].role){if(e[t].content===r)return e;break}return[...e,{id:s,role:"user",content:r}]});return}"result"===e.type&&(u.current=!1);let n=i.current??d();t(t=>(0,l.F)(t,e,{engine:a,assistantId:n}))};(0,s.h)({url:e?`/ws/session-stream?sessionId=${encodeURIComponent(e)}`:"/ws/session-stream",enabled:n&&!!e,onMessage:e=>{if("run-snapshot"===e.type&&Array.isArray(e.events)){if("running"!==e.status)return void o?.onRunningChange?.(!1);let n=e.events.find(e=>e?.type==="user"&&e?._human),r=n?.message?.content,s="string"==typeof r?r:"",l=new Set,a=new Set;for(let t of e.events){let e=t?.uuid;if("string"==typeof e&&l.add(e),t?.type==="assistant"&&Array.isArray(t.message?.content))for(let e of t.message.content)e?.name&&"string"==typeof e.id&&a.add(e.id)}for(let n of(t(e=>{let t=e.filter(e=>!("string"==typeof e.id&&e.id.startsWith("live-")));if(!s)return t;let n=-1;for(let e=t.length-1;e>=0;e--)if("user"===t[e].role){t[e].content===s&&(n=e);break}return -1===n?t:t.slice(n+1).every(e=>"assistant"===e.role&&("string"==typeof e.id&&l.has(e.id)||!!e.toolCalls?.length&&e.toolCalls.every(e=>a.has(e.id))))?t.slice(0,n):t}),i.current=null,c.current=0,u.current=!1,e.events))m(n);o?.onRunningChange?.(!0)}else if("run-event"===e.type&&e.message){if("run-ended"===e.message.type){o?.onRunningChange?.(!1),o?.onComplete?.();return}m(e.message),o?.onRunningChange?.(!0)}else"run-idle"===e.type&&o?.onRunningChange?.(!1)}})}},67362:(e,t,n)=>{n.d(t,{xU:()=>j,xZ:()=>k});var r=n(95155),s=n(12115),l=n(47650),a=n(79114),o=n(64702),i=n(1058),c=n(90717),u=n(70188),d=n(48347),m=n(89109),h=n(7320),f=n(22576),x=n(34075),p=n(56978),g=n(17196);function b({lines:e,containerRef:t}){let n=(0,s.useRef)(null),[l,a]=(0,s.useState)({top:0,height:0});if((0,s.useEffect)(()=>{let e=t.current;if(!e)return;let r=()=>{let{scrollTop:t,scrollHeight:r,clientHeight:s}=e,l=n.current?.clientHeight||0;if(r<=s)a({top:0,height:l});else{let e=l/r;a({top:t*e,height:s*e})}};return r(),e.addEventListener("scroll",r),window.addEventListener("resize",r),()=>{e.removeEventListener("scroll",r),window.removeEventListener("resize",r)}},[t]),0===e.length)return null;let o=100/e.length;return(0,r.jsxs)("div",{ref:n,className:"w-4 flex-shrink-0 bg-secondary border-l border-border relative cursor-pointer",onClick:e=>{let r=t.current,s=n.current;if(!r||!s)return;let l=s.getBoundingClientRect(),a=(e.clientY-l.top)/l.height*r.scrollHeight-r.clientHeight/2;r.scrollTo({top:Math.max(0,a),behavior:"smooth"})},children:[e.map((e,t)=>"unchanged"!==e.type&&(0,r.jsx)("div",{className:`absolute left-0 right-0 ${"removed"===e.type?"bg-red-9":"bg-green-9"}`,style:{top:`${t*o}%`,height:`${Math.max(o,.5)}%`,minHeight:"2px"}},t)),(0,r.jsx)("div",{className:"absolute left-0 right-0 bg-muted/60 border-y border-border",style:{top:`${l.top}px`,height:`${Math.max(l.height,10)}px`}})]})}var v=n(37614),y=n(27570);function w(e){return e.params?`${e.name}(${e.params.join(", ")})`:e.name}function k({oldContent:e,newContent:t,filePath:n,isNew:j=!1,isDeleted:C=!1,cwd:N,enableComments:S=!1,onPreview:E,previewLabel:L,onContentSearch:M,targetLine:R,compact:T=!1,symbols:$}){let{t:I}=(0,a.Bd)(),P=L??I("common.preview"),_=(0,s.useMemo)(()=>(0,f.X)(e,t),[e,t]),A=(0,s.useRef)(null),F=(0,s.useRef)(null),D=(0,s.useRef)(null),O=(0,s.useRef)(!1),[V,B]=(0,s.useState)(!1),W=(0,u.iN)(),H=(0,d.r)(),z=S&&!!N,{comments:K,addComment:U,updateComment:q,deleteComment:X,refresh:Z}=(0,i._)({cwd:N||"",filePath:n}),[J,Y]=(0,s.useState)(null),[Q,G]=(0,s.useState)(null);(0,s.useEffect)(()=>{D.current!==Q&&G(D.current)});let{toolbarRef:ee,bumpRef:et,clearToolbar:en}=(0,y.L)({enabled:z,container:Q,resolveLineRange:e=>{if(!document.contains(e))return null;let t=e.nodeType===Node.TEXT_NODE?e.parentElement:e,n=t?.closest("[data-new-line]");if(!n)return null;let r=parseInt(n.getAttribute("data-new-line")||"0",10);return!Number.isFinite(r)||r<=0?null:{start:r,end:r}},buildLineSnapshot:({start:e,end:t})=>{let n=[],r=0;for(let s of _)("unchanged"===s.type||"added"===s.type)&&++r>=e&&r<=t&&n.push(s.content);return n.join("\n")}}),[er,es]=(0,s.useState)(null),[el,ea]=(0,s.useState)(null);(0,s.useEffect)(()=>{B(!0)},[]);let eo=(0,s.useMemo)(()=>{let e=new Set;for(let t of K)for(let n=t.startLine;n<=t.endLine;n++)e.add(n);return e},[K]),ei=(0,s.useMemo)(()=>{let e=new Map;for(let t of K){let n=t.endLine;e.has(n)||e.set(n,[]),e.get(n).push(t)}return e},[K]),ec=(0,s.useCallback)((e,t)=>{t.stopPropagation(),Y({comment:e,x:t.clientX,y:t.clientY}),en(),es(null),ea(null)},[en]),eu=(0,s.useCallback)(()=>{let e=ee.current;e&&(es({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),en())},[en,ee]),ed=(0,s.useCallback)(()=>{let e=ee.current;e&&(ea({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),en())},[en,ee]),em=(0,s.useCallback)(()=>{let e=ee.current;if(!e||!M)return;let t=e.selectedText.trim();en(),t&&M(t)},[M,en,ee]),eh=(0,s.useCallback)(async e=>{if(el&&H&&N)try{let t=await (0,c.$3)(N),r=[];for(let e of t)r.push({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0});r.push({filePath:n,startLine:el.range.start,endLine:el.range.end,codeContent:el.lineSnapshot});let s=(0,c.Gw)(r,e);H.sendMessage(s),await (0,c.RP)(N),Z(),ea(null)}catch(e){console.error("Failed to send to AI:",e)}},[el,H,n,N,Z]),ef=(0,s.useCallback)(async e=>{er&&(await U(er.range.start,er.range.end,e,er.selectedText),es(null))},[er,U]);(0,s.useEffect)(()=>{let e=F.current,t=D.current;if(!e||!t)return;let n=(e,t)=>{O.current||(O.current=!0,t.scrollLeft=e.scrollLeft,requestAnimationFrame(()=>{O.current=!1}))},r=()=>n(e,t),s=()=>n(t,e);return e.addEventListener("scroll",r),t.addEventListener("scroll",s),()=>{e.removeEventListener("scroll",r),t.removeEventListener("scroll",s)}},[]);let{leftLines:ex,rightLines:ep}=(0,s.useMemo)(()=>{let e=[],t=[],n=0,r=0;for(let s=0;s<_.length;s++){let l=_[s];if("unchanged"===l.type){for(;e.length<t.length;)e.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});for(;t.length<e.length;)t.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});n++,r++,e.push({lineNum:n,content:l.content,type:"unchanged",originalIdx:s}),t.push({lineNum:r,content:l.content,type:"unchanged",originalIdx:s})}else"removed"===l.type?(n++,e.push({lineNum:n,content:l.content,type:"removed",originalIdx:s})):"added"===l.type&&(r++,t.push({lineNum:r,content:l.content,type:"added",originalIdx:s}))}for(;e.length<t.length;)e.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});for(;t.length<e.length;)t.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});return{leftLines:e,rightLines:t}},[_]),eg=(0,s.useMemo)(()=>_.map(e=>e.content),[_]),eb=(0,p.C)(eg,n),[ev,ey]=(0,s.useState)(()=>new Map);(0,s.useLayoutEffect)(()=>{ey(new Map),eL.measure()},[ex,ep]);let ew=(0,s.useMemo)(()=>$??[],[$]),{rows:ek,gaps:ej}=(0,s.useMemo)(()=>T?function(e,t,n,r=[]){let s=e.length,l=n=>"unchanged"!==e[n].type||"unchanged"!==t[n].type,a=new Set;for(let e=0;e<s;e++){if(!l(e))continue;let t=Math.max(0,e-3),n=Math.min(s-1,e+3);for(let e=t;e<=n;e++)a.add(e)}let o=[];for(let e=0;e<s;e++){if(a.has(e))continue;let t=e;for(;e<s&&!a.has(e);)e++;o.push({id:o.length,startIdx:t,endIdx:e-1}),e--}for(let e of o){let t=n.get(e.id)??{topRevealed:0,bottomRevealed:0},r=e.endIdx-e.startIdx+1,s=Math.max(0,Math.min(t.topRevealed,r)),l=Math.max(0,Math.min(t.bottomRevealed,r-s));for(let t=e.startIdx;t<e.startIdx+s;t++)a.add(t);for(let t=e.endIdx-l+1;t<=e.endIdx;t++)a.add(t)}let i=[];for(let e=0;e<s;e++){let n;if(a.has(e)){i.push({kind:"diff",idx:e});continue}let l=e;for(;e<s&&!a.has(e);)e++;let c=e-1;e--;let u=o.find(e=>e.startIdx<=l&&c<=e.endIdx);if(!u)continue;let d=c-l+1,m=Math.min(20,d);if(r.length>0&&c+1<s)for(let e=c+1;e<s;e++){let s=t[e].lineNum;if(!(s<=0)){n=function(e,t){let n=null;for(let r of e)r.startLine<=t&&t<=r.endLine&&(!n||r.endLine-r.startLine<n.endLine-n.startLine)&&(n=r);return n}(r,s)??void 0;break}}i.push({kind:"gap-expand",gapId:u.id,direction:"up",revealCount:m}),i.push({kind:"gap-label",gapId:u.id,hiddenCount:d,enclosingFn:n}),i.push({kind:"gap-expand",gapId:u.id,direction:"down",revealCount:m})}return{rows:i,gaps:o}}(ex,ep,ev,ew):{rows:ex.map((e,t)=>({kind:"diff",idx:t})),gaps:[]},[T,ex,ex,ep,ev,ew]),eC=(0,s.useCallback)((e,t)=>{let n=ej.find(t=>t.id===e);n&&ey(r=>{let s=r.get(e)??{topRevealed:0,bottomRevealed:0},l=n.endIdx-n.startIdx+1-s.topRevealed-s.bottomRevealed;if(l<=0)return r;let a=Math.min(20,l),o="up"===t?{...s,topRevealed:s.topRevealed+a}:{...s,bottomRevealed:s.bottomRevealed+a};return new Map(r).set(e,o)})},[ej]),eN=(0,s.useCallback)(e=>{for(let t of ej)if(e>=t.startIdx&&e<=t.endIdx)return t.id;return null},[ej]),eS=(0,s.useCallback)(e=>ek[e]?.kind==="gap-label"?28:20,[ek]),eE=(0,s.useCallback)(e=>{let t=ek[e];if(!t)return e;if("gap-label"===t.kind)return`gl:${t.gapId}`;if("gap-expand"===t.kind)return`ge:${t.gapId}:${t.direction}`;let n=ex[t.idx],r=ep[t.idx];return`d:${n?.lineNum??"x"}:${n?.type??"x"}:${r?.lineNum??"x"}:${r?.type??"x"}`},[ek,ex,ep]),eL=(0,o.Te)({count:ek.length,getScrollElement:()=>A.current,estimateSize:eS,getItemKey:eE,overscan:20}),eM=j?"w-1/4":C?"w-3/4":"w-1/2",eR=j?"w-3/4":C?"w-1/4":"w-1/2",eT=(0,s.useMemo)(()=>ek.map(e=>{if("diff"!==e.kind)return{type:"unchanged"};let t=ex[e.idx],n=ep[e.idx];return"removed"===t.type?{type:"removed"}:n?.type==="added"?{type:"added"}:{type:"unchanged"}}),[ek,ex,ep]),e$=eL.getTotalSize(),eI=eL.getVirtualItems();return(0,s.useEffect)(()=>{if(!R)return;let e=("after"===R.side?ep:ex).findIndex(e=>e.lineNum===R.line);if(-1===e)return;let t=ek.findIndex(t=>"diff"===t.kind&&t.idx===e);if(-1===t){let t=eN(e);if(null!==t){let e=ej.find(e=>e.id===t);if(!e)return;let n=e.endIdx-e.startIdx+1;ey(e=>{let r=e.get(t)??{topRevealed:0,bottomRevealed:0};if(r.topRevealed+r.bottomRevealed>=n)return e;let s=new Map(e);return s.set(t,{topRevealed:n,bottomRevealed:0}),s})}return}let n=requestAnimationFrame(()=>{eL.scrollToIndex(t,{align:"start"})});return()=>cancelAnimationFrame(n)},[R,ex,ep,ek]),(0,r.jsxs)("div",{className:"font-mono flex flex-col h-full text-sm",children:[(0,r.jsxs)("div",{className:"flex flex-shrink-0 border-b border-border",children:[(0,r.jsx)("div",{className:`${eM} min-w-0 px-2 py-1 bg-accent text-muted-foreground text-center text-xs font-medium border-r border-border`,children:j?"(New File)":C?"Deleted":"Old"}),(0,r.jsxs)("div",{className:`${eR} min-w-0 px-2 py-1 bg-accent text-muted-foreground text-xs font-medium relative`,children:[(0,r.jsx)("span",{className:"block text-center",children:C?"(Deleted)":"New"}),(0,r.jsxs)("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center gap-2",children:[E&&(0,r.jsx)("button",{onClick:E,className:"text-muted-foreground hover:text-foreground transition-colors",children:P}),!C&&t&&(0,r.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(t),(0,x.oR)(I("diffViewer.copiedAll"))},className:"text-muted-foreground hover:text-foreground transition-colors",children:I("common.copy")})]})]}),(0,r.jsx)("div",{className:"w-4 flex-shrink-0 bg-accent"})]}),(0,r.jsxs)("div",{className:"flex-1 min-h-0 flex",children:[(0,r.jsx)("div",{ref:A,className:"flex-1 overflow-y-auto overflow-x-hidden",children:(0,r.jsxs)("div",{className:"flex",style:{height:`${e$}px`},children:[(0,r.jsx)("div",{ref:F,className:`${eM} overflow-x-auto border-r border-border`,children:(0,r.jsx)("div",{className:"min-w-max h-full",style:{position:"relative"},children:eI.map(e=>{let t=ek[e.index];if("gap-expand"===t.kind||"gap-label"===t.kind){let n="gap-label"===t.kind;return(0,r.jsx)("div",{ref:eL.measureElement,"data-index":e.index,style:{position:"absolute",top:0,left:0,width:"100%",height:`${Math.max(e.size,eS(e.index))}px`,transform:`translateY(${e.start}px)`},className:n?"bg-accent border-y border-border":""},e.key)}let n=ex[t.idx];return(0,r.jsxs)("div",{ref:eL.measureElement,"data-index":e.index,"data-row-idx":t.idx,style:{position:"absolute",top:0,left:0,minWidth:"100%",width:"max-content",height:`${Math.max(e.size,eS(e.index))}px`,transform:`translateY(${e.start}px)`},className:`flex ${"removed"===n.type?"bg-red-9/15 dark:bg-red-9/25":""}`,children:[(0,r.jsx)("span",{className:"w-10 flex-shrink-0 text-right pr-2 text-slate-9 select-none border-r border-border",children:n.lineNum||""}),(0,r.jsx)("span",{className:"whitespace-pre pl-2",dangerouslySetInnerHTML:{__html:n.originalIdx>=0&&eb[n.originalIdx]||(0,g.ZD)(n.content||" ")}})]},e.key)})})}),(0,r.jsx)("div",{ref:D,className:`${eR} overflow-x-auto`,children:(0,r.jsx)("div",{className:"min-w-max h-full",style:{position:"relative"},children:eI.map(e=>{let t=ek[e.index];if("gap-expand"===t.kind)return(0,r.jsx)("button",{ref:eL.measureElement,"data-index":e.index,type:"button",onClick:()=>eC(t.gapId,t.direction),style:{position:"absolute",top:0,left:0,width:"100%",height:`${Math.max(e.size,eS(e.index))}px`,transform:`translateY(${e.start}px)`},className:"flex items-center justify-center text-[11px] text-foreground/50 hover:bg-accent hover:text-brand active:bg-brand/15 transition-colors duration-100 cursor-pointer focus:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-brand/60",title:I("up"===t.direction?"diffViewer.gap.expandUp":"diffViewer.gap.expandDown",{count:t.revealCount}),"aria-label":I("up"===t.direction?"diffViewer.gap.expandUp":"diffViewer.gap.expandDown",{count:t.revealCount}),children:(0,r.jsx)("span",{className:"select-none",children:I("diffViewer.gap.more",{count:t.revealCount})})},e.key);if("gap-label"===t.kind)return(0,r.jsxs)("div",{ref:eL.measureElement,"data-index":e.index,"data-gap-id":t.gapId,style:{position:"absolute",top:0,left:0,width:"100%",height:`${Math.max(e.size,eS(e.index))}px`,transform:`translateY(${e.start}px)`},className:"flex items-center justify-center gap-2 px-3 text-[11px] text-foreground/80 bg-accent border-y border-border min-w-0 select-none",children:[(0,r.jsx)("span",{className:"flex-shrink-0",children:I("diffViewer.gap.hidden",{count:t.hiddenCount})}),t.enclosingFn&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"opacity-50 flex-shrink-0",children:"\xb7"}),(0,r.jsx)("span",{className:"truncate min-w-0 font-medium",title:w(t.enclosingFn),children:w(t.enclosingFn)})]})]},e.key);let n=ep[t.idx],s=n?.lineNum||0,l=s>0&&eo.has(s),a=ei.get(s),o=a?.[0],i=er&&s>=er.range.start&&s<=er.range.end,c=el&&s>=el.range.start&&s<=el.range.end,u=i||c;return(0,r.jsxs)("div",{ref:eL.measureElement,"data-index":e.index,"data-new-line":s||void 0,"data-row-idx":t.idx,style:{position:"absolute",top:0,left:0,minWidth:"100%",width:"max-content",height:`${Math.max(e.size,eS(e.index))}px`,transform:`translateY(${e.start}px)`},className:`flex ${u?"bg-blue-9/20":l?"bg-amber-9/10":n?.type==="added"?"bg-green-9/15 dark:bg-green-9/25":""}`,children:[(0,r.jsxs)("span",{className:`flex-shrink-0 flex items-center gap-0.5 pr-1 text-slate-9 select-none border-r border-border ${u?"bg-blue-9/30":""}`,style:{width:z?"52px":"40px"},children:[z&&s>0&&l&&o&&(0,r.jsx)("button",{onClick:e=>ec(o,e),className:"w-4 h-4 flex items-center justify-center rounded hover:bg-accent text-amber-9",title:I("codeViewer.nComments",{count:a?.length}),children:(0,r.jsx)("svg",{className:"w-3 h-3",fill:"currentColor",viewBox:"0 0 20 20",children:(0,r.jsx)("path",{fillRule:"evenodd",d:"M18 10c0 3.866-3.582 7-8 7a8.841 8.841 0 01-4.083-.98L2 17l1.338-3.123C2.493 12.767 2 11.434 2 10c0-3.866 3.582-7 8-7s8 3.134 8 7zM7 9H5v2h2V9zm8 0h-2v2h2V9zM9 9h2v2H9V9z",clipRule:"evenodd"})})}),z&&s>0&&!l&&(0,r.jsx)("span",{className:"w-4"}),(0,r.jsx)("span",{className:"flex-1 text-right pr-1",children:s||""})]}),(0,r.jsx)("span",{className:"whitespace-pre pl-2",dangerouslySetInnerHTML:{__html:n?.originalIdx>=0&&eb[n.originalIdx]||(0,g.ZD)(n?.content||" ")}})]},e.key)})})})]})}),(0,r.jsx)(b,{lines:eT,containerRef:A})]}),V&&W&&(0,l.createPortal)((0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(m.f,{floatingToolbarRef:ee,bumpRef:et,container:W,onAddComment:eu,onSendToAI:ed,onSearch:M?em:void 0,isChatLoading:H?.isLoading??!1}),er&&(0,r.jsx)(h.t,{x:er.x,y:er.y,range:er.range,lineSnapshot:er.lineSnapshot,container:W,onSubmit:ef,onClose:()=>es(null)}),el&&(0,r.jsx)(h.G,{x:el.x,y:el.y,range:el.range,filePath:n,lineSnapshot:el.lineSnapshot,container:W,onSubmit:eh,onClose:()=>ea(null),isChatLoading:H?.isLoading}),J&&(0,r.jsx)(v.t,{x:J.x,y:J.y,comment:J.comment,container:W,onClose:()=>Y(null),onUpdateComment:q,onDeleteComment:X})]}),W)]})}function j({oldContent:e,newContent:t,filePath:n}){let l=(0,s.useMemo)(()=>(0,f.X)(e,t),[e,t]),a=(0,s.useRef)(null),i=(0,s.useMemo)(()=>l.map(e=>e.content),[l]),c=(0,p.C)(i,n),u=(0,s.useCallback)(e=>{let t=l[e];return t?`${t.type}:${t.oldLineNum??"x"}:${t.newLineNum??"x"}`:e},[l]),d=(0,o.Te)({count:l.length,getScrollElement:()=>a.current,estimateSize:()=>20,getItemKey:u,overscan:20});return(0,r.jsx)("div",{ref:a,className:"font-mono text-sm overflow-auto h-full",children:(0,r.jsx)("div",{style:{height:`${d.getTotalSize()}px`,position:"relative"},children:d.getVirtualItems().map(e=>{let t=l[e.index];return(0,r.jsxs)("div",{style:{position:"absolute",top:0,left:0,minWidth:"100%",width:"max-content",height:`${e.size}px`,transform:`translateY(${e.start}px)`},className:`flex ${"removed"===t.type?"bg-red-9/15 dark:bg-red-9/25":"added"===t.type?"bg-green-9/15 dark:bg-green-9/25":""}`,children:[(0,r.jsx)("span",{className:"w-10 flex-shrink-0 text-right pr-2 text-slate-9 select-none border-r border-border",children:"added"!==t.type?t.oldLineNum:""}),(0,r.jsx)("span",{className:"w-10 flex-shrink-0 text-right pr-2 text-slate-9 select-none border-r border-border",children:"removed"!==t.type?t.newLineNum:""}),(0,r.jsx)("span",{className:`w-6 flex-shrink-0 text-center select-none ${"removed"===t.type?"text-red-11":"added"===t.type?"text-green-11":"text-slate-9"}`,children:"removed"===t.type?"-":"added"===t.type?"+":" "}),(0,r.jsx)("span",{className:"flex-1 whitespace-pre pl-1",dangerouslySetInnerHTML:{__html:c[e.index]||(0,g.ZD)(t.content||" ")}})]},e.key)})})})}},70188:(e,t,n)=>{n.d(t,{Ee:()=>m,SU:()=>c,ft:()=>d,iN:()=>u});var r=n(95155),s=n(12115),l=n(79114),a=n(47650),o=n(34075);let i=(0,s.createContext)(null);function c({container:e,children:t}){return(0,r.jsx)(i.Provider,{value:e,children:t})}function u(){return(0,s.useContext)(i)}function d({x:e,y:t,path:n,cwd:c,isDirectory:u,onClose:m,onCreateFile:h,onDelete:f,onRefresh:x,onCopyFile:p,onPaste:g}){let{t:b}=(0,l.Bd)(),v=(0,s.useRef)(null),y=(0,s.useContext)(i),w=n.split("/").pop()||n,k=`${c}/${n}`,j=n.includes("/")?n.substring(0,n.lastIndexOf("/")):"",C=j?`${c}/${j}`:c,N=u?n:j,S=u?k:C;(0,s.useEffect)(()=>{let e=e=>{v.current&&!v.current.contains(e.target)&&m()},t=e=>{"Escape"===e.key&&m()};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[m]);let[E,L]=(0,s.useState)({x:0,y:0});(0,s.useEffect)(()=>{if(v.current&&y){let n=y.getBoundingClientRect(),r=v.current.getBoundingClientRect(),s=e-n.left,l=t-n.top;s=Math.min(s,n.width-r.width-8),l=Math.min(l,n.height-r.height-8),L({x:s=Math.max(8,s),y:l=Math.max(8,l)})}else if(v.current){let n=v.current.getBoundingClientRect();L({x:Math.max(8,Math.min(e,window.innerWidth-n.width-8)),y:Math.max(8,Math.min(t,window.innerHeight-n.height-8))})}},[e,t,y]);let M=(0,s.useCallback)(async(e,t)=>{try{await navigator.clipboard.writeText(e),(0,o.oR)(b("toast.copiedName",{name:t}),"success")}catch{(0,o.oR)(b("toast.copyFailed"),"error")}m()},[m,b]),R=u?n:j,T=[{label:b("fileContextMenu.copyRelativePath"),value:n},{label:b("fileContextMenu.copyAbsolutePath"),value:k},{label:b("fileContextMenu.copyRelativeDirPath"),value:N||"."},{label:b("fileContextMenu.copyAbsoluteDirPath"),value:S},{label:u?b("fileContextMenu.copyFolderName"):b("fileContextMenu.copyFileName"),value:w}],$=(0,r.jsxs)("div",{ref:v,className:"absolute z-[200] bg-card border border-border rounded-lg shadow-lg py-1 w-fit whitespace-nowrap",style:{left:E.x,top:E.y},children:[h&&(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>{m(),h(R)},children:b("fileContextMenu.createFile")}),p&&(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>{m(),p(n)},children:u?b("fileContextMenu.copyFolder"):b("fileContextMenu.copyFile")}),g&&(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>{m(),g(R)},children:b("fileContextMenu.pasteHere")}),f&&(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-destructive hover:bg-accent transition-colors",onClick:()=>{m(),f(n,u,w)},children:u?b("fileContextMenu.deleteFolder"):b("fileContextMenu.deleteFile")}),(h||f||p||g)&&(0,r.jsx)("div",{className:"my-1 border-t border-border"}),T.map((e,t)=>(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>M(e.value,e.label),children:e.label},t))]});return y?(0,a.createPortal)($,y):$}function m(){let[e,t]=(0,s.useState)(null);return{contextMenu:e,showContextMenu:(0,s.useCallback)((e,n,r)=>{e.preventDefault(),e.stopPropagation(),t({x:e.clientX,y:e.clientY,path:n,isDirectory:r})},[]),hideContextMenu:(0,s.useCallback)(()=>{t(null)},[])}}},75346:(e,t,n)=>{n.d(t,{n:()=>s});var r=n(88292);let s={SessionChange:(0,r.R)("session-change"),ViewChange:(0,r.R)("view-change"),OpenNote:(0,r.R)("open-note"),LangChange:(0,r.R)("lang-change"),TabAdd:(0,r.R)("tab-add"),TabClose:(0,r.R)("tab-close"),SwitchSession:(0,r.R)("switch-session"),ProjectChange:(0,r.R)("project-change"),OpenProject:(0,r.R)("open-project"),SessionComplete:(0,r.R)("session-complete"),OpenTokenStats:(0,r.R)("open-token-stats"),PinnedSessionsChanged:(0,r.R)("pinned-sessions-changed"),ScheduledTasksChanged:(0,r.R)("scheduled-tasks-changed"),ScreenshotPrepare:(0,r.R)("screenshot-prepare"),ScreenshotDone:(0,r.R)("screenshot-done")}},82292:(e,t,n)=>{function r(e,t){for(let n of e){if(n.path===t)return n;if(n.children){let e=r(n.children,t);if(e)return e}}return null}function s(e,t){if(!e)return"";let n=r(t,e);if(n?.isDirectory)return e;let s=e.split("/");return s.pop(),s.join("/")}function l(e){let t=[];for(let n of e){let e=n.split("/"),r=t;for(let t=0;t<e.length;t++){let n=e[t],s=t===e.length-1,l=e.slice(0,t+1).join("/"),a=r.find(e=>e.name===n);a||(a={name:n,path:l,isDirectory:!s,children:s?void 0:[]},r.push(a)),!s&&a.children&&(r=a.children)}}let n=e=>{e.sort((e,t)=>e.isDirectory&&!t.isDirectory?-1:!e.isDirectory&&t.isDirectory?1:e.name.localeCompare(t.name)),e.forEach(e=>{e.children&&n(e.children)})};return n(t),t}function a(e){let t=[],n=e=>{for(let r of e)r.isDirectory&&(t.push(r.path),r.children&&n(r.children))};return n(e),t}n.d(t,{B_:()=>f,HR:()=>function e(t,n){if(0===n.length)return t;let r=new Map(n.map(e=>[e.path,e]));return t.map(t=>{let n=r.get(t.path);return n&&t.isDirectory?void 0===t.children&&void 0!==n.children?{...t,children:n.children}:void 0!==t.children&&void 0!==n.children?{...t,children:e(t.children,n.children)}:t:t})},KH:()=>u,MB:()=>r,S7:()=>s,fw:()=>d,q3:()=>c,r6:()=>m,tE:()=>h,tW:()=>a,u:()=>i,v3:()=>l});let o=new Set(["png","jpg","jpeg","gif","svg","webp","ico","bmp"]);function i(e){let t=e.split(".").pop()?.toLowerCase();return o.has(t||"")}function c(e,t,n=!1){let r=new Set;if(!t)return r;let s=t.toLowerCase(),l=e=>{if(r.add(e.path),e.children)for(let t of e.children)l(t)},a=(e,t)=>{let o=e.name.toLowerCase(),i=n?o===s:o.includes(s);if(i&&e.children)return l(e),t.forEach(e=>r.add(e)),!0;let c=!1;if(e.children)for(let n of e.children)a(n,[...t,e.path])&&(c=!0);return(!!i||!!c)&&(r.add(e.path),t.forEach(e=>r.add(e)),!0)};for(let t of e)a(t,[]);return r}function u(e,t,n=!1){let r=new Set;if(!t)return r;let s=t.toLowerCase();for(let t of e){let e=t.split("/");for(let t=0;t<e.length;t++){let l=e[t].toLowerCase();if(n?l===s:l.includes(s)){for(let t=0;t<=e.length-1;t++)r.add(e.slice(0,t+1).join("/"));break}}}return r}function d(e){let t=Math.floor(Math.floor((Date.now()-1e3*e)/1e3)/60),n=Math.floor(t/60),r=Math.floor(n/24),s=Math.floor(r/30),l=Math.floor(r/365);return l>0?`${l}y ago`:s>0?`${s}mo ago`:r>0?`${r}d ago`:n>0?`${n}h ago`:t>0?`${t}m ago`:"just now"}function m(e){let t=new Date(e),n=new Date,r=t.getFullYear()===n.getFullYear(),s=String(t.getMonth()+1).padStart(2,"0"),l=String(t.getDate()).padStart(2,"0"),a=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return r?`${s}-${l} ${a}:${o}`:`${t.getFullYear()}-${s}-${l} ${a}:${o}`}let h=()=>{},f=50},83448:(e,t,n)=>{n.d(t,{Cr:()=>v,JC:()=>d,M5:()=>c,QW:()=>f,Zr:()=>h,an:()=>b,em:()=>i,l1:()=>u,n_:()=>m,qD:()=>g,td:()=>o,z2:()=>x});var r=n(49433),s=n(82680);let l=(e,t)=>r.tryPromise({try:async()=>{let n=await fetch(e,t);if(!n.ok)throw Error(`HTTP ${n.status}`);return await n.json()},catch:n=>new s.uV({message:`${t?.method??"GET"} ${e} failed`,cause:n})}),a=(e,t)=>l(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),o=()=>l("/api/settings"),i=e=>l("/api/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),c=()=>l("/api/commands"),u=()=>l("/api/skills"),d=e=>a("/api/bash",e),m=e=>r.tryPromise({try:async()=>{let t=await fetch("/api/session-by-path",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});return t.ok?await t.json():null},catch:e=>new s.uV({message:"POST /api/session-by-path failed",cause:e})}),h=(e,t)=>a(`/api/session/${encodeURIComponent(e)}/fork`,t),f=e=>l(`/api/sessions/projects/${encodeURIComponent(e)}`),x=()=>l("/api/global-state").pipe(r.map(e=>e.sessions??[])),p=()=>r.tryPromise({try:async()=>{let e=await fetch("/api/ollama/models");return 503===e.status?{_tag:"not-running"}:e.ok?{_tag:"ok",models:(await e.json()).models??[]}:{_tag:"error",message:"Failed to fetch models"}},catch:e=>new s.uV({message:"fetch ollama models failed",cause:e})}),g=e=>r.gen(function*(){let t=yield*p();if("not-running"!==t._tag)return t;e&&(yield*r.sync(e));let n=yield*r.tryPromise({try:async()=>{let e=await fetch("/api/ollama/start",{method:"POST"}),t=await e.json().catch(()=>({}));return 404===e.status?{_tag:"not-installed",message:t.message||"Ollama is not installed"}:e.ok?{_tag:"started"}:{_tag:"error",message:"Failed to start Ollama"}},catch:e=>new s.uV({message:"start ollama failed",cause:e})});if("not-installed"===n._tag)return{_tag:"not-installed",message:n.message};if("error"===n._tag)return{_tag:"error",message:n.message};let l=yield*p();return"not-running"===l._tag?{_tag:"error",message:"Ollama started but cannot fetch models"}:l}),b=e=>l(`/api/file?path=${encodeURIComponent(e)}`),v=e=>l(`/api/claude-stats?engine=${encodeURIComponent(e)}`)},83897:(e,t,n)=>{n.d(t,{k_:()=>o,nH:()=>i});var r=n(95155),s=n(12115),l=n(48347);let a=(0,s.createContext)(null);function o({children:e}){let t=(0,s.useRef)(new Map),n=(0,s.useRef)(null),[i,c]=(0,s.useState)(!1),u=(0,s.useCallback)((e,n)=>{t.current.set(n,e)},[]),d=(0,s.useCallback)(e=>{t.current.delete(e)},[]),m=(0,s.useCallback)(e=>{n.current=e},[]),h=(0,s.useCallback)(e=>{let r=n.current;if(!r)return void console.warn("No active tab to send message");let s=t.current.get(r);s?s(e):console.warn(`No chat sender registered for tab ${r}`)},[]),f=(0,s.useMemo)(()=>({sendMessage:h,isLoading:i,registerChat:u,unregisterChat:d,setActiveTab:m,setIsLoading:c}),[h,i,u,d,m]),x=(0,s.useMemo)(()=>({sendMessage:h,isLoading:i}),[h,i]);return(0,r.jsx)(a.Provider,{value:f,children:(0,r.jsx)(l.H,{value:x,children:e})})}function i(){return(0,s.useContext)(a)}},85839:(e,t,n)=>{n.d(t,{m:()=>c,z:()=>o});var r=n(12115),s=n(49433),l=n(86957),a=n(82680);let o=e=>s.tryPromise({try:async()=>{let t=await fetch("/api/session-by-path",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});return t.ok?await t.json():null},catch:e=>new a.uV({message:"session-by-path failed",cause:e})}),i=new Map;function c(e,t,n,{cwd:u,initialSessionId:d,onSessionId:m,onTitleChange:h,onTokenUsage:f,liveRunningRef:x}){let[p,g]=(0,r.useState)(!1),[b,v]=(0,r.useState)(!1),[y,w]=(0,r.useState)(!1),[k,j]=(0,r.useState)(void 0),[C,N]=(0,r.useState)(0),[S,E]=(0,r.useState)(null),[L,M]=(0,r.useState)(null),R=(0,r.useRef)(h);R.current=h;let T=(0,r.useRef)(f);T.current=f;let $=(0,r.useRef)(void 0),I=(0,r.useRef)(0),P=(0,r.useCallback)(async(e,n,r=!1,s,a)=>{if(r){let e=Date.now();if(e-I.current<5e3)return;I.current=e}let c=(e,r)=>{e.fingerprint&&($.current=e.fingerprint),void 0!==e.totalTurns&&N(e.totalTurns),void 0!==e.hasMore&&w(e.hasMore),e.messages&&e.messages.length>0&&(r?t(t=>{let n=e.messages;if(t.length===n.length&&t.length>0&&t[t.length-1].content===n[n.length-1].content)return t;let r=0;for(let e=0;e<Math.min(t.length,n.length)&&t[e].id===n[e].id&&t[e].content===n[e].content;e++)r=e+1;return r===t.length&&r<n.length?[...t,...n.slice(r)]:n}):x?.current||t(e.messages),E(n)),e.sessionId&&m(e.sessionId),e.engine&&M(e.engine),e.title&&R.current?.(e.title),e.usage&&T.current?.({inputTokens:e.usage.input_tokens||0,outputTokens:e.usage.output_tokens||0,cacheCreationInputTokens:e.usage.cache_creation_input_tokens||0,cacheReadInputTokens:e.usage.cache_read_input_tokens||0,totalCostUsd:0})},u=`${e}::${n}`,d=!r&&void 0===a,h=d?i.get(u):void 0;r||(h?c(h.data,!1):g(!0));try{let t={cwd:e,sessionId:n,limit:s,beforeTurnIndex:a};r&&$.current?t.ifFingerprint=$.current:h&&(t.ifFingerprint=h.fingerprint);let m=await l.t4.runPromiseExit(o(t));if("Success"===m._tag&&m.value){let e=m.value;if(e.notModified)return;if(c(e,r),d&&e.fingerprint&&e.messages&&e.messages.length>0&&(i.delete(u),i.set(u,{data:e,fingerprint:e.fingerprint}),i.size>20)){let e=i.keys().next().value;void 0!==e&&i.delete(e)}}}catch(e){console.error("Failed to load history by cwd and sessionId:",e)}finally{r||g(!1)}},[t,m]),_=(0,r.useCallback)(async()=>{if(u&&n&&!b&&y){v(!0);try{let r=void 0!==k?k:C-Math.ceil(e.filter(e=>"user"===e.role).length),s=await l.t4.runPromiseExit(o({cwd:u,sessionId:n,limit:10,beforeTurnIndex:r>0?r:void 0}));if("Success"===s._tag&&s.value){let e=s.value;if(e.messages&&e.messages.length>0){t(t=>[...e.messages,...t]);let s=e.messages.filter(e=>"user"===e.role).length;j(r-s),E(n)}void 0!==e.hasMore&&w(e.hasMore),e.fingerprint&&($.current=e.fingerprint)}else"Failure"===s._tag&&console.error("Failed to load more history:",s.cause)}finally{v(!1)}}},[u,n,b,y,k,C,e,t]),A=(0,r.useCallback)(async e=>{g(!0);let n=s.tryPromise({try:async()=>{let t=await fetch(`/api/session/${e}/history`);return t.ok?await t.json():null},catch:e=>new a.uV({message:"load session history failed",cause:e})}),r=await l.t4.runPromiseExit(n);"Success"===r._tag&&r.value?.messages&&r.value.messages.length>0?(t(r.value.messages),E(e)):"Failure"===r._tag&&console.error("Failed to load history:",r.cause),g(!1)},[t]);return(0,r.useEffect)(()=>{u&&d&&P(u,d,!1,10)},[]),{isLoadingHistory:p,isLoadingMore:b,hasMoreHistory:y,loadMoreHistory:_,loadHistory:A,loadHistoryByCwdAndSessionId:P,loadedSessionId:S,loadedEngine:L}}},89109:(e,t,n)=>{n.d(t,{f:()=>o});var r=n(95155),s=n(12115),l=n(79114);function a({x:e,y:t,visible:n,container:s,onAddComment:o,onSendToAI:i,onSearch:c,isChatLoading:u}){let{t:d}=(0,l.Bd)(),m=s.getBoundingClientRect(),h=e-m.left,f=Math.max(0,t-m.top-40);return(0,r.jsxs)("div",{className:"floating-toolbar absolute z-[200] flex items-center gap-1.5 bg-card border border-border rounded-lg shadow-xl p-1.5",style:{left:h+8,top:f,visibility:n?"visible":"hidden",pointerEvents:n?"auto":"none"},children:[(0,r.jsx)("button",{className:"px-3 py-1.5 text-xs font-medium border border-brand text-brand rounded-md hover:bg-brand/10 transition-colors",onClick:o,children:d("floatingToolbar.addComment")}),(0,r.jsx)("button",{className:"px-3 py-1.5 text-xs font-medium border border-brand text-brand rounded-md hover:bg-brand/10 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",onClick:i,disabled:u,title:d(u?"comments.aiResponding":"floatingToolbar.sendToAI"),children:d("floatingToolbar.sendToAI")}),c&&(0,r.jsx)("button",{className:"px-3 py-1.5 text-xs font-medium border border-brand text-brand rounded-md hover:bg-brand/10 transition-colors",onClick:c,children:d("floatingToolbar.search")})]})}let o=(0,s.memo)(function({floatingToolbarRef:e,bumpRef:t,container:n,onAddComment:l,onSendToAI:o,onSearch:i,isChatLoading:c}){let[u,d]=(0,s.useState)(0);(0,s.useEffect)(()=>{t.current=()=>d(e=>e+1)},[t]);let m=(0,s.useMemo)(()=>e.current,[u]);return(0,r.jsx)(a,{x:m?.x??0,y:m?.y??0,visible:!!m,container:n,onAddComment:l,onSendToAI:o,onSearch:i,isChatLoading:c})})},90717:(e,t,n)=>{n.d(t,{$3:()=>d,Cm:()=>u,Gw:()=>f,RP:()=>m,Un:()=>h,zL:()=>c});var r=n(69809),s=n(49433),l=n(86957),a=n(82680),o=n(46456);let i=new Set;function c(e){return i.add(e),()=>i.delete(e)}function u(){i.forEach(e=>e())}async function d(e){let t=await l.t4.runPromiseExit((0,o.lb)(e));if("Success"!==t._tag)throw Error("Failed to fetch comments");let n=t.value.comments??[];if(0===n.length)return[];let r=new Map;for(let e of n)e.selectedText||(r.has(e.filePath)||r.set(e.filePath,[]),r.get(e.filePath).push(e));let i=new Map;await Promise.all(Array.from(r.keys()).map(async t=>{let n=await l.t4.runPromiseExit(s.tryPromise({try:async()=>{let n=await fetch(`/api/files/text?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`);return n.ok?await n.json():null},catch:e=>new a.uV({message:`read file text ${t} failed`,cause:e})}));"Success"===n._tag&&n.value&&"string"==typeof n.value.content?i.set(t,n.value.content.split("\n")):"Failure"===n._tag&&console.error(`Failed to read file ${t}:`,n.cause)}));let c=[];for(let e of n){if(e.selectedText){c.push({...e,codeContent:e.selectedText});continue}let t=i.get(e.filePath),n="";if(t){let r=Math.max(0,e.startLine-1),s=Math.min(t.length,e.endLine);n=t.slice(r,s).join("\n")}c.push({...e,codeContent:n})}return c}async function m(e){let t=await l.t4.runPromiseExit((0,o.tj)(e));return"Success"===t._tag?(u(),!0):(console.error("Failed to clear comments:",t.cause),!1)}let h="__chat__";function f(e,t){let n=e.filter(e=>e.filePath===h),s=e.filter(e=>e.filePath!==h),l=[];for(let e of(s.length>0&&(l.push(`${r.A.t("comments.codeRef")}`,""),s.forEach((e,t)=>{l.push(`[${t+1}] ${e.filePath}:${e.startLine}-${e.endLine}`),l.push("```"),l.push(e.codeContent),l.push("```"),e.note&&l.push(r.A.t("comments.note",{content:e.note})),l.push("")})),n)){let t=e.codeContent.split("\n").map(e=>`> ${e}`).join("\n");l.push(t),e.note&&l.push(e.note),l.push("")}return l.push(r.A.t("comments.question",{question:t})),l.join("\n")}},95045:(e,t,n)=>{n.d(t,{F:()=>a});var r=n(49433),s=n(88292),l=n(86957);let a=(e,t)=>{l.t4.runFork(r.flatMap(s.d,n=>n.publish(e,t)))}},95942:(e,t,n)=>{n.d(t,{EE:()=>o,K2:()=>i,ri:()=>c});var r=n(95155),s=n(12115),l=n(79114),a=n(8422);let o=80,i=24,c=(0,s.forwardRef)(function({visible:e,running:t,onInput:n},c){let{t:u}=(0,l.Bd)(),d=(0,s.useRef)(n);(0,s.useEffect)(()=>{d.current=n},[n]);let[m,h]=(0,s.useState)(!1),f=(0,s.useRef)(!1);(0,s.useEffect)(()=>{t&&!f.current?h(!0):!t&&f.current&&h(!1),f.current=t},[t]);let x=(0,s.useRef)(null),p=(0,s.useRef)(null),g=(0,s.useRef)(""),b=(0,s.useCallback)(()=>{if(p.current||!x.current)return;let e=new a.B({cols:o,rows:i,fontSize:11,fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, "Courier New", monospace',convertEol:!1,scrollback:2e3,theme:{background:"#0a0a0a",foreground:"#d4d4d8"},disableStdin:!1,allowProposedApi:!0});e.open(x.current),e.onData(e=>d.current?.(e)),g.current&&e.write(g.current),p.current=e},[]);return((0,s.useEffect)(()=>{m&&e?b():(p.current?.dispose(),p.current=null)},[m,e,b]),(0,s.useImperativeHandle)(c,()=>({write:e=>{g.current+=e,g.current.length>2e5&&(g.current=g.current.slice(-15e4)),p.current?.write(e)},clear:()=>{g.current="",p.current?.clear()}}),[]),e)?(0,r.jsxs)("div",{className:"absolute top-12 right-3 z-30 rounded-lg border border-border bg-card shadow-lg overflow-hidden",style:{width:m?"auto":180},"data-testid":"pty-floating-window",children:[(0,r.jsxs)("button",{type:"button",onClick:()=>h(e=>!e),"data-testid":"pty-floating-toggle",className:"w-full flex items-center justify-between gap-3 px-2.5 py-1.5 text-xs bg-accent/60 hover:bg-accent",children:[(0,r.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,r.jsx)("span",{className:`inline-block w-2 h-2 rounded-full ${t?"bg-green-500 animate-pulse":"bg-muted-foreground"}`}),(0,r.jsxs)("span",{className:"text-muted-foreground",children:[u("chat.ptyTerminal"),t?` \xb7 ${u("chat.ptyRunning")}`:""]})]}),(0,r.jsx)("span",{className:"text-muted-foreground",children:m?`${u("chat.ptyCollapse")} ▾`:`${u("chat.ptyExpand")} ▸`})]}),(0,r.jsx)("div",{ref:x,"data-testid":"pty-floating-term",style:{display:m?"block":"none",padding:4},className:"bg-[#0a0a0a]"})]}):null})}}]);
|