@surething/cockpit 1.0.227 → 1.0.229

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. package/.next-prod/BUILD_ID +1 -1
  2. package/.next-prod/app-path-routes-manifest.json +1 -1
  3. package/.next-prod/build-manifest.json +3 -3
  4. package/.next-prod/prerender-manifest.json +3 -3
  5. package/.next-prod/react-loadable-manifest.json +1 -1
  6. package/.next-prod/server/app/_global-error/page.js.nft.json +1 -1
  7. package/.next-prod/server/app/_global-error/page_client-reference-manifest.js +1 -1
  8. package/.next-prod/server/app/_global-error.html +1 -1
  9. package/.next-prod/server/app/_global-error.rsc +1 -1
  10. package/.next-prod/server/app/_global-error.segments/_full.segment.rsc +1 -1
  11. package/.next-prod/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  12. package/.next-prod/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  13. package/.next-prod/server/app/_global-error.segments/_head.segment.rsc +1 -1
  14. package/.next-prod/server/app/_global-error.segments/_index.segment.rsc +1 -1
  15. package/.next-prod/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  16. package/.next-prod/server/app/_not-found/page.js +1 -1
  17. package/.next-prod/server/app/_not-found/page.js.nft.json +1 -1
  18. package/.next-prod/server/app/_not-found/page_client-reference-manifest.js +1 -1
  19. package/.next-prod/server/app/_not-found.html +2 -2
  20. package/.next-prod/server/app/_not-found.rsc +3 -3
  21. package/.next-prod/server/app/_not-found.segments/_full.segment.rsc +3 -3
  22. package/.next-prod/server/app/_not-found.segments/_head.segment.rsc +1 -1
  23. package/.next-prod/server/app/_not-found.segments/_index.segment.rsc +3 -3
  24. package/.next-prod/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  25. package/.next-prod/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  26. package/.next-prod/server/app/_not-found.segments/_tree.segment.rsc +2 -2
  27. package/.next-prod/server/app/api/agent/test/route.js.nft.json +1 -1
  28. package/.next-prod/server/app/api/bash/route.js.nft.json +1 -1
  29. package/.next-prod/server/app/api/chat/codex/route.js.nft.json +1 -1
  30. package/.next-prod/server/app/api/chat/deepseek/route.js.nft.json +1 -1
  31. package/.next-prod/server/app/api/chat/kimi/route.js.nft.json +1 -1
  32. package/.next-prod/server/app/api/chat/ollama/route.js.nft.json +1 -1
  33. package/.next-prod/server/app/api/chat/pty-input/route.js.nft.json +1 -1
  34. package/.next-prod/server/app/api/chat/route.js.nft.json +1 -1
  35. package/.next-prod/server/app/api/chat/stop/route.js.nft.json +1 -1
  36. package/.next-prod/server/app/api/claude-stats/route.js.nft.json +1 -1
  37. package/.next-prod/server/app/api/commands/route.js.nft.json +1 -1
  38. package/.next-prod/server/app/api/comments/route.js.nft.json +1 -1
  39. package/.next-prod/server/app/api/db/columns/route.js.nft.json +1 -1
  40. package/.next-prod/server/app/api/db/connect/route.js.nft.json +1 -1
  41. package/.next-prod/server/app/api/db/disconnect/route.js.nft.json +1 -1
  42. package/.next-prod/server/app/api/db/export/route.js.nft.json +1 -1
  43. package/.next-prod/server/app/api/db/query/route.js.nft.json +1 -1
  44. package/.next-prod/server/app/api/db/schemas/route.js.nft.json +1 -1
  45. package/.next-prod/server/app/api/dev/spans/route.js.nft.json +1 -1
  46. package/.next-prod/server/app/api/extension/version/route.js.nft.json +1 -1
  47. package/.next-prod/server/app/api/file/route.js.nft.json +1 -1
  48. package/.next-prod/server/app/api/files/blame/route.js.nft.json +1 -1
  49. package/.next-prod/server/app/api/files/clipboard/route.js.nft.json +1 -1
  50. package/.next-prod/server/app/api/files/copy/route.js.nft.json +1 -1
  51. package/.next-prod/server/app/api/files/delete/route.js.nft.json +1 -1
  52. package/.next-prod/server/app/api/files/expanded/route.js.nft.json +1 -1
  53. package/.next-prod/server/app/api/files/index/route.js.nft.json +1 -1
  54. package/.next-prod/server/app/api/files/init/route.js.nft.json +1 -1
  55. package/.next-prod/server/app/api/files/paste/route.js.nft.json +1 -1
  56. package/.next-prod/server/app/api/files/read/route.js.nft.json +1 -1
  57. package/.next-prod/server/app/api/files/readdir/route.js.nft.json +1 -1
  58. package/.next-prod/server/app/api/files/recent/route.js.nft.json +1 -1
  59. package/.next-prod/server/app/api/files/save/route.js.nft.json +1 -1
  60. package/.next-prod/server/app/api/files/search/route.js.nft.json +1 -1
  61. package/.next-prod/server/app/api/files/stat/route.js.nft.json +1 -1
  62. package/.next-prod/server/app/api/files/text/route.js.nft.json +1 -1
  63. package/.next-prod/server/app/api/git/branch-diff/route.js.nft.json +1 -1
  64. package/.next-prod/server/app/api/git/branches/route.js.nft.json +1 -1
  65. package/.next-prod/server/app/api/git/commit-diff/route.js.nft.json +1 -1
  66. package/.next-prod/server/app/api/git/commits/route.js.nft.json +1 -1
  67. package/.next-prod/server/app/api/git/current-branch/route.js.nft.json +1 -1
  68. package/.next-prod/server/app/api/git/diff/route.js.nft.json +1 -1
  69. package/.next-prod/server/app/api/git/discard/route.js.nft.json +1 -1
  70. package/.next-prod/server/app/api/git/stage/route.js.nft.json +1 -1
  71. package/.next-prod/server/app/api/git/status/route.js.nft.json +1 -1
  72. package/.next-prod/server/app/api/git/unstage/route.js.nft.json +1 -1
  73. package/.next-prod/server/app/api/git/worktree/route.js.nft.json +1 -1
  74. package/.next-prod/server/app/api/global-state/route.js +1 -1
  75. package/.next-prod/server/app/api/global-state/route.js.nft.json +1 -1
  76. package/.next-prod/server/app/api/health/route.js.nft.json +1 -1
  77. package/.next-prod/server/app/api/jupyter/load/route.js.nft.json +1 -1
  78. package/.next-prod/server/app/api/jupyter/save/route.js.nft.json +1 -1
  79. package/.next-prod/server/app/api/jupyter/shutdown/route.js.nft.json +1 -1
  80. package/.next-prod/server/app/api/lsp/definition/route.js.nft.json +1 -1
  81. package/.next-prod/server/app/api/lsp/hover/route.js.nft.json +1 -1
  82. package/.next-prod/server/app/api/lsp/references/route.js.nft.json +1 -1
  83. package/.next-prod/server/app/api/lsp/status/route.js.nft.json +1 -1
  84. package/.next-prod/server/app/api/lsp/warmup/route.js.nft.json +1 -1
  85. package/.next-prod/server/app/api/mysql/columns/route.js.nft.json +1 -1
  86. package/.next-prod/server/app/api/mysql/connect/route.js.nft.json +1 -1
  87. package/.next-prod/server/app/api/mysql/disconnect/route.js.nft.json +1 -1
  88. package/.next-prod/server/app/api/mysql/export/route.js.nft.json +1 -1
  89. package/.next-prod/server/app/api/mysql/query/route.js.nft.json +1 -1
  90. package/.next-prod/server/app/api/mysql/schemas/route.js.nft.json +1 -1
  91. package/.next-prod/server/app/api/neo4j/connect/route.js.nft.json +1 -1
  92. package/.next-prod/server/app/api/neo4j/disconnect/route.js.nft.json +1 -1
  93. package/.next-prod/server/app/api/neo4j/query/route.js.nft.json +1 -1
  94. package/.next-prod/server/app/api/neo4j/schema/route.js.nft.json +1 -1
  95. package/.next-prod/server/app/api/note/route.js.nft.json +1 -1
  96. package/.next-prod/server/app/api/ollama/models/route.js.nft.json +1 -1
  97. package/.next-prod/server/app/api/ollama/start/route.js.nft.json +1 -1
  98. package/.next-prod/server/app/api/open-cursor/route.js.nft.json +1 -1
  99. package/.next-prod/server/app/api/open-vscode/route.js.nft.json +1 -1
  100. package/.next-prod/server/app/api/pick-folder/route.js.nft.json +1 -1
  101. package/.next-prod/server/app/api/pinned-sessions/route.js.nft.json +1 -1
  102. package/.next-prod/server/app/api/project-settings/route.js.nft.json +1 -1
  103. package/.next-prod/server/app/api/project-state/route.js.nft.json +1 -1
  104. package/.next-prod/server/app/api/projectGraph/affected/route.js.nft.json +1 -1
  105. package/.next-prod/server/app/api/projectGraph/callees/route.js.nft.json +1 -1
  106. package/.next-prod/server/app/api/projectGraph/callers/route.js.nft.json +1 -1
  107. package/.next-prod/server/app/api/projectGraph/coedit/route.js.nft.json +1 -1
  108. package/.next-prod/server/app/api/projectGraph/context/route.js.nft.json +1 -1
  109. package/.next-prod/server/app/api/projectGraph/file/route.js.nft.json +1 -1
  110. package/.next-prod/server/app/api/projectGraph/file-functions/route.js.nft.json +1 -1
  111. package/.next-prod/server/app/api/projectGraph/impact/route.js.nft.json +1 -1
  112. package/.next-prod/server/app/api/projectGraph/related/route.js.nft.json +1 -1
  113. package/.next-prod/server/app/api/projectGraph/risk/route.js.nft.json +1 -1
  114. package/.next-prod/server/app/api/projectGraph/search/route.js.nft.json +1 -1
  115. package/.next-prod/server/app/api/projects/route.js.nft.json +1 -1
  116. package/.next-prod/server/app/api/push/public-key/route.js.nft.json +1 -1
  117. package/.next-prod/server/app/api/push/subscribe/route.js.nft.json +1 -1
  118. package/.next-prod/server/app/api/push/unsubscribe/route.js.nft.json +1 -1
  119. package/.next-prod/server/app/api/redis/command/route.js.nft.json +1 -1
  120. package/.next-prod/server/app/api/redis/connect/route.js.nft.json +1 -1
  121. package/.next-prod/server/app/api/redis/delete/route.js.nft.json +1 -1
  122. package/.next-prod/server/app/api/redis/disconnect/route.js.nft.json +1 -1
  123. package/.next-prod/server/app/api/redis/get/route.js.nft.json +1 -1
  124. package/.next-prod/server/app/api/redis/keys/route.js.nft.json +1 -1
  125. package/.next-prod/server/app/api/redis/set/route.js.nft.json +1 -1
  126. package/.next-prod/server/app/api/review/[id]/comments/route.js.nft.json +1 -1
  127. package/.next-prod/server/app/api/review/[id]/replies/route.js.nft.json +1 -1
  128. package/.next-prod/server/app/api/review/[id]/route.js.nft.json +1 -1
  129. package/.next-prod/server/app/api/review/identify/route.js.nft.json +1 -1
  130. package/.next-prod/server/app/api/review/order/route.js.nft.json +1 -1
  131. package/.next-prod/server/app/api/review/route.js.nft.json +1 -1
  132. package/.next-prod/server/app/api/review/share-info/route.js.nft.json +1 -1
  133. package/.next-prod/server/app/api/review/users/route.js.nft.json +1 -1
  134. package/.next-prod/server/app/api/scheduled-tasks/route.js.nft.json +1 -1
  135. package/.next-prod/server/app/api/services/config/route.js.nft.json +1 -1
  136. package/.next-prod/server/app/api/services/scripts/route.js.nft.json +1 -1
  137. package/.next-prod/server/app/api/session/[sessionId]/fork/route.js.nft.json +1 -1
  138. package/.next-prod/server/app/api/session/[sessionId]/history/route.js.nft.json +1 -1
  139. package/.next-prod/server/app/api/session-by-path/route.js.nft.json +1 -1
  140. package/.next-prod/server/app/api/sessions/projects/[encodedPath]/route.js.nft.json +1 -1
  141. package/.next-prod/server/app/api/sessions/projects/route.js.nft.json +1 -1
  142. package/.next-prod/server/app/api/sessions/route.js.nft.json +1 -1
  143. package/.next-prod/server/app/api/settings/route.js.nft.json +1 -1
  144. package/.next-prod/server/app/api/skills/[id]/route.js.nft.json +1 -1
  145. package/.next-prod/server/app/api/skills/content/route.js.nft.json +1 -1
  146. package/.next-prod/server/app/api/skills/route.js.nft.json +1 -1
  147. package/.next-prod/server/app/api/terminal/aliases/route.js.nft.json +1 -1
  148. package/.next-prod/server/app/api/terminal/autocomplete/route.js.nft.json +1 -1
  149. package/.next-prod/server/app/api/terminal/bubble-order/route.js.nft.json +1 -1
  150. package/.next-prod/server/app/api/terminal/env/route.js.nft.json +1 -1
  151. package/.next-prod/server/app/api/terminal/history/route.js +1 -1
  152. package/.next-prod/server/app/api/terminal/history/route.js.nft.json +1 -1
  153. package/.next-prod/server/app/api/version/route.js.nft.json +1 -1
  154. package/.next-prod/server/app/favicon.ico/route.js.nft.json +1 -1
  155. package/.next-prod/server/app/m/page.js +1 -1
  156. package/.next-prod/server/app/m/page.js.nft.json +1 -1
  157. package/.next-prod/server/app/m/page_client-reference-manifest.js +1 -1
  158. package/.next-prod/server/app/manifest.webmanifest/route.js.nft.json +1 -1
  159. package/.next-prod/server/app/page.js +1 -1
  160. package/.next-prod/server/app/page.js.nft.json +1 -1
  161. package/.next-prod/server/app/page_client-reference-manifest.js +1 -1
  162. package/.next-prod/server/app/project/page.js +1 -1
  163. package/.next-prod/server/app/project/page.js.nft.json +1 -1
  164. package/.next-prod/server/app/project/page_client-reference-manifest.js +1 -1
  165. package/.next-prod/server/app/review/[id]/page.js +2 -2
  166. package/.next-prod/server/app/review/[id]/page.js.nft.json +1 -1
  167. package/.next-prod/server/app/review/[id]/page_client-reference-manifest.js +1 -1
  168. package/.next-prod/server/app-paths-manifest.json +1 -1
  169. package/.next-prod/server/chunks/3633.js +1 -1
  170. package/.next-prod/server/chunks/{5337.js → 4257.js} +3 -3
  171. package/.next-prod/server/chunks/8916.js +1 -1
  172. package/.next-prod/server/chunks/9658.js +5 -5
  173. package/.next-prod/server/middleware-build-manifest.js +1 -1
  174. package/.next-prod/server/middleware-react-loadable-manifest.js +1 -1
  175. package/.next-prod/server/pages/404.html +2 -2
  176. package/.next-prod/server/pages/500.html +1 -1
  177. package/.next-prod/server/server-reference-manifest.json +1 -1
  178. package/.next-prod/static/chunks/{217-259a6d7d3cac75d8.js → 217-d644348194c14361.js} +2 -2
  179. package/.next-prod/static/chunks/{2576-26748a4d5cfa8668.js → 2576-49c4aeffa6a6b95e.js} +8 -8
  180. package/.next-prod/static/chunks/{327-9ffab8f0b2b0b4cd.js → 2625-bc4748f0cd7db618.js} +10 -10
  181. package/.next-prod/static/chunks/327.8ecab0b86d52b597.js +1 -0
  182. package/.next-prod/static/chunks/{471-7c4fab47613ffe5c.js → 471-504b396c8302f4f2.js} +1 -1
  183. package/.next-prod/static/chunks/6784-b644510a0e060aac.js +0 -0
  184. package/.next-prod/static/chunks/app/{layout-edef27fb2f6b346e.js → layout-03c738d41e660f72.js} +1 -1
  185. package/.next-prod/static/chunks/app/m/{page-50afaa8bd837e768.js → page-8b1af6f31b60c485.js} +1 -1
  186. package/.next-prod/static/chunks/app/{page-49470b6c107b5dee.js → page-677439ad5fd63732.js} +1 -1
  187. package/.next-prod/static/chunks/app/project/{page-49470b6c107b5dee.js → page-677439ad5fd63732.js} +1 -1
  188. package/.next-prod/static/chunks/app/review/[id]/{page-31d70fd518d4c7e6.js → page-39fa3a843adf617e.js} +1 -1
  189. package/.next-prod/static/chunks/webpack-dbba7fa77ee1faa4.js +1 -0
  190. package/.next-prod/static/css/1d4a0de85e617fe5.css +1 -0
  191. package/.next-prod/trace +13 -13
  192. package/.next-prod/trace-build +1 -1
  193. package/dist/{chunk-R564FMS3.mjs → chunk-RJMSCVG5.mjs} +31 -0
  194. package/dist/{chunk-J5B4FIW5.mjs → chunk-XW5CKMXI.mjs} +7 -2
  195. package/dist/httpApi.mjs +1 -1
  196. package/dist/scheduledTasks.mjs +1 -1
  197. package/dist/{server-J7ZUYRI6.mjs → server-K4DO2GUO.mjs} +3 -1
  198. package/dist/wsServer.mjs +3 -3
  199. package/package.json +4 -1
  200. package/.next-prod/static/chunks/2708.7263182a029113c8.js +0 -1
  201. package/.next-prod/static/chunks/9469-7902249e8fbf7955.js +0 -14
  202. package/.next-prod/static/chunks/webpack-2404d47da29b5b14.js +0 -1
  203. package/.next-prod/static/css/330d330a9236397f.css +0 -1
  204. /package/.next-prod/static/{t45T3Imr0gQh7MYDeURiy → fLCxsDN9EciQYDYw-OdS3}/_buildManifest.js +0 -0
  205. /package/.next-prod/static/{t45T3Imr0gQh7MYDeURiy → fLCxsDN9EciQYDYw-OdS3}/_ssgManifest.js +0 -0
@@ -1,5 +1,5 @@
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(45048),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:A}=(0,d._)({cwd:n,filePath:t}),[_,F]=(0,s.useState)(!1),[D,O]=(0,s.useState)(null),[V,B]=(0,s.useState)(null),[H,W]=(0,s.useState)(null),z=(0,s.useMemo)(()=>e.split("\n"),[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>F(!0))},[]);let[U,K]=(0,s.useState)(null),q=(0,s.useRef)(null);(0,s.useEffect)(()=>{q.current!==U&&K(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:J,bumpRef:Z,clearToolbar:Y}=(0,y.L)({enabled:!0,container:U,resolveLineRange:e=>{let t=function(e){let t=e.nodeType===Node.TEXT_NODE?e.parentElement:e;if(!t||!("closest"in t))return null;let n=t.closest("[data-source-start]");if(!n)return null;let r=n.getAttribute("data-source-start"),s=n.getAttribute("data-source-end");return r&&s?{start:parseInt(r,10),end:parseInt(s,10)}:null}(e);return t?{start:t.start,end:t.end}:null},buildLineSnapshot:({start:e,end:t})=>{let n=Math.max(0,e-1),r=Math.min(z.length,t);return z.slice(n,r).join("\n")}}),Q=(0,s.useCallback)(()=>{let e=J.current;e&&(O({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),Y())},[Y,J]),G=(0,s.useCallback)(()=>{let e=J.current;e&&(B({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),Y())},[Y,J]),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),A(),B(null)}catch(e){console.error("Failed to send to AI:",e)}},[V,R,t,n,A]),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(J.current){J.current=null,Z.current(),e.stopPropagation();return}if(H){W(null),e.stopPropagation();return}x?.()}};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[V,D,H,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(),W({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))]})]}),_&&M&&(0,a.createPortal)((0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(i.f,{floatingToolbarRef:J,bumpRef:Z,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}),H&&(0,r.jsx)(u.t,{x:H.x,y:H.y,comment:H.comment,container:M,onClose:()=>W(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:()=>eu});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)(el,{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(45048),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 A={Read:"\uD83D\uDCC4",Write:"✏️",Edit:"\uD83D\uDCDD",Bash:"\uD83D\uDCBB",Glob:"\uD83D\uDD0D",Grep:"\uD83D\uDD0E",WebFetch:"\uD83C\uDF10",WebSearch:"\uD83D\uDD0D",Workflow:"\uD83E\uDDE9",Skill:"\uD83D\uDEE0️"};function _({toolCall:e,cwd:t,sessionId:n}){var l;let{t:a}=(0,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=A[e.name]||"\uD83D\uDD27",v="Agent"===e.name||"Task"===e.name,w=v&&!!t&&!!n,k="Workflow"===e.name,j=k&&(l=e.result)?l.match(/subagents\/workflows\/(wf_[A-Za-z0-9_-]+)/)?.[1]??null:null,C=k&&!!j&&!!t&&!!n,N="Skill"===e.name,S=v||k||N,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: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-2 border border-border rounded-lg overflow-hidden bg-secondary",children:[(0,r.jsxs)("button",{onClick:()=>c(!i),className:"w-full px-3 py-2 flex items-center gap-2 text-left hover:bg-accent transition-colors",children:[(0,r.jsx)("span",{className:"text-base",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)})]})]}),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),H=n(55804),W=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 U(e,t){return`${e}-${t}`}function K({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=U(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=U(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=U(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)(H.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)(H.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)(W.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),J=n(21362),Z=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)(J.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)(Z.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(70188),en=n(83448);function er({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 es({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)(et.SU,{container:o,children:(0,r.jsx)(ee.M,{content:t,filePath:e,cwd:n,onClose:l})})})})})}let el=(0,s.memo)(function({message:e,cwd:t,sessionId:n,onFork:l,onApprovePlan:a,isLoading:x}){let p,g,b,v,{t:y}=(0,h.Bd)(),[w,k]=(0,s.useState)(null),[j,C]=(0,s.useState)(()=>1===(e.toolCalls?.length||0)),[S,E]=(0,s.useState)(!1),[L,M]=(0,s.useState)(!1),R="user"===e.role,T=e.images&&e.images.length>0,$=e.toolCalls?.length||0,I=!!n&&!!t&&!!l,P=(0,s.useMemo)(()=>e.toolCalls?.some(e=>"Edit"===e.name||"Write"===e.name)||!1,[e.toolCalls]),A=(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]),F=(0,s.useMemo)(()=>e.toolCalls?e.toolCalls.filter(e=>"AskUserQuestion"===e.name):[],[e.toolCalls]),D=(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]),O=(0,s.useMemo)(()=>e.toolCalls?.filter(e=>"ExitPlanMode"!==e.name)??[],[e.toolCalls]),V=(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&&e.toLowerCase().endsWith(".md")&&!t.has(e)&&(t.add(e),n.push(e))}return n},[e.toolCalls]),B=(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]),[H,W]=(0,s.useState)(null),[z,U]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!H)return void queueMicrotask(()=>U(null));let e=!1;return f.t4.runPromiseExit((0,en.an)(H)).then(t=>{e||("Success"===t._tag&&void 0!==t.value.content?U(t.value.content):((0,o.oR)(y("toast.readFileFailed"),"error"),W(null)))}),()=>{e=!0}},[H,y]);let q=()=>{e.content&&(navigator.clipboard.writeText(e.content),(0,o.oR)(y("toast.copiedMessage")))},X=()=>{I&&l(e.id)},J=(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);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:`flex flex-col ${R?"items-end":"items-start"} mb-4 group`,"data-role":e.role,children:[J&&(0,r.jsx)("span",{className:"text-[11px] text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity mb-0.5 px-1",children:J}),(0,r.jsxs)("div",{className:`flex ${R?"justify-end":"justify-start"} w-full`,children:[R&&(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:q,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:y("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"})})}),I&&(0,r.jsx)("button",{onClick:X,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:y("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%] ${R?"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:[T&&(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:()=>k(e),children:(0,r.jsx)("img",{src:`data:${e.media_type};base64,${e.data}`,alt:y("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:R,isStreaming:e.isStreaming,enableMath:!1}),e.isStreaming&&(0,r.jsx)("span",{className:"inline-block w-2 h-4 ml-1 bg-current animate-pulse"})]}),A&&(b=(g=Array.isArray(p=A.input?.todos)?p:[]).filter(e=>"completed"===e.status).length,v=g.length,(0,r.jsx)("div",{className:`${e.content||T?"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:`${v>0?b/v*100:0}%`}})}),(0,r.jsxs)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:[b,"/",v]})]}),g.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))]})})),D&&(0,r.jsx)("div",{className:`${e.content||T||A?"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:y("chat.planTitle",{defaultValue:"Plan (awaiting your review)"})})]}),(0,r.jsx)("div",{className:"px-3 py-2",children:(0,r.jsx)(N.T,{content:D,isUser:!1,enableMath:!1})}),a&&(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:y("chat.planApproveHint",{defaultValue:"本环境无审批弹窗,点此退出 Plan 并执行"})}),(0,r.jsxs)("button",{onClick:()=>a(),disabled:x,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:y("chat.approvePlan",{defaultValue:"批准并执行"})})]})]})]})}),V.length>0&&(0,r.jsx)("div",{className:`${e.content||T||A?"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:V.map(e=>(0,r.jsxs)("button",{onClick:()=>W(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.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))})}),B.length>0&&(0,r.jsx)("div",{className:`${e.content||T||A||V.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:B.map((e,t)=>(0,r.jsxs)("tr",{className:t<B.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))})]})})}),O.length>0&&(0,r.jsx)("div",{className:`${e.content||T?"mt-2":""}`,children:$>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:()=>C(!j),className:"flex-1 px-3 py-2 flex items-center gap-2 text-left hover:bg-accent transition-colors active:bg-muted",children:[(0,r.jsx)("span",{className:"text-lg",children:"\uD83D\uDD27"}),(0,r.jsx)("span",{className:"font-medium text-foreground",children:y("chat.toolCalls",{count:O.length})}),(0,r.jsx)("span",{className:"ml-auto text-muted-foreground text-sm",children:j?y("chat.collapse"):y("chat.expand")})]}),F.length>0&&(0,r.jsx)("button",{onClick:()=>M(!0),className:"px-3 py-2 text-muted-foreground hover:text-foreground hover:bg-accent transition-colors border-l border-border",title:y("chat.viewQuestions"),children:(0,r.jsx)(d.A,{className:"w-4 h-4"})}),P&&(0,r.jsx)("button",{onClick:()=>E(!0),className:"px-3 py-2 text-muted-foreground hover:text-foreground hover:bg-accent transition-colors border-l border-border",title:y("chat.viewAllFileChanges"),children:(0,r.jsx)(m.A,{className:"w-4 h-4"})})]}),j&&(0,r.jsx)("div",{className:"border-t border-border p-2 space-y-1",children:O.map((e,s)=>(0,r.jsx)(_,{toolCall:e,cwd:t,sessionId:n},`${e.id}-${s}`))})]}):O.map((e,s)=>(0,r.jsx)(_,{toolCall:e,cwd:t,sessionId:n},`${e.id}-${s}`))})]}),!R&&(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:q,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:y("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"})})}),I&&(0,r.jsx)("button",{onClick:X,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:y("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"})]})})]})]})]}),w&&(0,r.jsx)(er,{image:w,onClose:()=>k(null)}),S&&e.toolCalls&&(0,r.jsx)(G,{toolCalls:e.toolCalls,cwd:t,onClose:()=>E(!1)}),L&&F.length>0&&(0,r.jsx)(K,{toolCalls:F,onClose:()=>M(!1)}),H&&null!==z&&(0,r.jsx)(es,{filePath:H,content:z,cwd:t||"",onClose:()=>W(null)})]})});var ea=n(1058),eo=n(90717),ei=n(89109),ec=n(7320);let eu=(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:A,currentMatchIndex:_,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),H=(0,l.nH)(),W=(0,s.useRef)(null),z=(0,s.useRef)(()=>{}),{addComment:U,refresh:K}=(0,ea._)({cwd:n||"",filePath:eo.Un}),[q,X]=(0,s.useState)(null),[J,Z]=(0,s.useState)(null),Y=(0,s.useCallback)(e=>{if(q||J)return;let t=window.getSelection();if(!t||t.isCollapsed||!t.rangeCount){W.current=null,z.current();return}let n=t.toString().trim();if(!n){W.current=null,z.current();return}let r=t.anchorNode instanceof HTMLElement?t.anchorNode:t.anchorNode?.parentElement;if(r?.closest('[data-role="user"]')){W.current=null,z.current();return}W.current={x:e.clientX,y:e.clientY,range:{start:0,end:0},selectedText:n,lineSnapshot:n},z.current()},[q,J]),Q=(0,s.useCallback)(e=>{let t=e.target;!(t.closest(".floating-toolbar")||t.closest('[class*="z-[200]"]'))&&W.current&&(W.current=null,z.current())},[]),G=(0,s.useCallback)(()=>{let e=W.current;e&&(X({x:e.x,y:e.y,text:e.selectedText}),W.current=null,z.current(),window.getSelection()?.removeAllRanges())},[]),ee=(0,s.useCallback)(()=>{let e=W.current;e&&(Z({x:e.x,y:e.y,text:e.selectedText}),W.current=null,z.current(),window.getSelection()?.removeAllRanges())},[]),et=(0,s.useCallback)(()=>{let e=W.current;if(!e||!p)return;let t=e.selectedText.trim();W.current=null,z.current(),window.getSelection()?.removeAllRanges(),t&&p(t)},[p]),en=(0,s.useCallback)(async e=>{q&&(await U(0,0,e,q.text),X(null))},[q,U]),er=(0,s.useCallback)(async e=>{if(J&&H&&n)try{let t=(await (0,eo.$3)(n)).map(e=>({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0}));t.push({filePath:eo.Un,startLine:0,endLine:0,codeContent:J.text});let r=(0,eo.Gw)(t,e);H.sendMessage(r),await (0,eo.RP)(n),K(),Z(null)}catch(e){console.error("Failed to send to AI:",e)}},[J,H,n,K]),es=(0,s.useMemo)(()=>{let t=new Set;return e.filter(e=>!t.has(e.id)&&(t.add(e.id),!0))},[e]),eu=(0,s.useRef)(0),ed=(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&&(eu.current=e.scrollHeight,ed.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(ed.current&&!d){let e=k.current;if(e){let t=e.scrollHeight-eu.current;e.scrollTop=t,ed.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:A.length>0?`${_+1}/${A.length}`:v("common.noMatch")}),(0,r.jsx)("button",{onClick:D,disabled:0===A.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===A.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)(el,{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)(ei.f,{floatingToolbarRef:W,bumpRef:z,container:C,onAddComment:G,onSendToAI:ee,onSearch:p?et:void 0,isChatLoading:H?.isLoading}),q&&C&&(0,r.jsx)(ec.t,{x:q.x,y:q.y,range:{start:0,end:0},lineSnapshot:q.text,container:C,onSubmit:en,onClose:()=>X(null)}),J&&C&&(0,r.jsx)(ec.G,{x:J.x,y:J.y,range:{start:0,end:0},lineSnapshot:J.text,container:C,onSubmit:er,onClose:()=>Z(null),isChatLoading:H?.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,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}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}){let[b,v]=(0,r.useState)(!1),[y,w]=(0,r.useState)(null),[k,j]=(0,r.useState)(null),[C,N]=(0,r.useState)(null),[S,E]=(0,r.useState)(null),L=(0,r.useRef)(null),[M,R]=(0,r.useState)(null),T=(0,r.useRef)(M);T.current=M;let $=(0,r.useRef)(!1),I=(0,r.useRef)(null),P=(0,r.useRef)(n);P.current=n;let A=(0,r.useRef)(null),_=(0,r.useRef)(null),F=(0,r.useCallback)(()=>{let e=A.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})),A.current={messageId:n,text:""}}_.current=null},[t,u]),D=(0,r.useCallback)(()=>{_.current&&(clearTimeout(_.current),_.current=null),I.current&&(clearTimeout(I.current),I.current=null),F(),v(!1);let e=T.current;e&&t(t=>t.map(t=>t.id===e.assistantId?{...t,isStreaming:!1}:t)),R(null)},[F,t]),O=(0,r.useCallback)(()=>{let e=T.current;fetch("/api/chat/stop",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:P.current,runId:e?.runKey})}).catch(()=>{}),D()},[D]),V=(0,r.useCallback)((e,n)=>{let r=e.type;if("pty_output"===r)return void g?.(e.data);if("pty_notice"===r){let r=e.messageKey?l.A.t(e.messageKey,e.params||{}):e.message;if(!r)return;e.terminal?t(e=>e.map(e=>e.id===n?{...e,content:r,isStreaming:!1}:e)):E(r);return}if("system"===r&&"init"===e.subtype){let t=e.session_id;x(t),P.current=t,N(null);return}if("system"===r&&"api_retry"===e.subtype)return void N({attempt:e.attempt??0,maxRetries:e.max_retries??0,delayMs:e.retry_delay_ms??0,errorStatus:e.error_status,error:e.error});if("rate_limit_event"===r){let t=e.rate_limit_info;t&&j({status:t.status||"allowed",resetsAt:t.resetsAt,rateLimitType:t.rateLimitType,utilization:t.utilization,overageStatus:t.overageStatus,overageDisabledReason:t.overageDisabledReason,isUsingOverage:t.isUsingOverage,surpassedThreshold:t.surpassedThreshold});return}if("error"===r){let r=e.error||l.A.t("chat.errorRetry",{defaultValue:"An error occurred. Please try again."});N(null),_.current&&(clearTimeout(_.current),_.current=null),F(),t(e=>e.map(e=>e.id===n?{...e,content:e.content?`${e.content}
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:A}=(0,d._)({cwd:n,filePath:t}),[_,F]=(0,s.useState)(!1),[D,O]=(0,s.useState)(null),[V,B]=(0,s.useState)(null),[H,W]=(0,s.useState)(null),z=(0,s.useMemo)(()=>e.split("\n"),[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>F(!0))},[]);let[U,K]=(0,s.useState)(null),q=(0,s.useRef)(null);(0,s.useEffect)(()=>{q.current!==U&&K(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:J,bumpRef:Z,clearToolbar:Y}=(0,y.L)({enabled:!0,container:U,resolveLineRange:e=>{let t=function(e){let t=e.nodeType===Node.TEXT_NODE?e.parentElement:e;if(!t||!("closest"in t))return null;let n=t.closest("[data-source-start]");if(!n)return null;let r=n.getAttribute("data-source-start"),s=n.getAttribute("data-source-end");return r&&s?{start:parseInt(r,10),end:parseInt(s,10)}:null}(e);return t?{start:t.start,end:t.end}:null},buildLineSnapshot:({start:e,end:t})=>{let n=Math.max(0,e-1),r=Math.min(z.length,t);return z.slice(n,r).join("\n")}}),Q=(0,s.useCallback)(()=>{let e=J.current;e&&(O({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),Y())},[Y,J]),G=(0,s.useCallback)(()=>{let e=J.current;e&&(B({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),Y())},[Y,J]),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),A(),B(null)}catch(e){console.error("Failed to send to AI:",e)}},[V,R,t,n,A]),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(J.current){J.current=null,Z.current(),e.stopPropagation();return}if(H){W(null),e.stopPropagation();return}x?.()}};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[V,D,H,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(),W({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))]})]}),_&&M&&(0,a.createPortal)((0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(i.f,{floatingToolbarRef:J,bumpRef:Z,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}),H&&(0,r.jsx)(u.t,{x:H.x,y:H.y,comment:H.comment,container:M,onClose:()=>W(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:()=>eu});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)(el,{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 A={Read:"\uD83D\uDCC4",Write:"✏️",Edit:"\uD83D\uDCDD",Bash:"\uD83D\uDCBB",Glob:"\uD83D\uDD0D",Grep:"\uD83D\uDD0E",WebFetch:"\uD83C\uDF10",WebSearch:"\uD83D\uDD0D",Workflow:"\uD83E\uDDE9",Skill:"\uD83D\uDEE0️"};function _({toolCall:e,cwd:t,sessionId:n}){var l;let{t:a}=(0,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=A[e.name]||"\uD83D\uDD27",v="Agent"===e.name||"Task"===e.name,w=v&&!!t&&!!n,k="Workflow"===e.name,j=k&&(l=e.result)?l.match(/subagents\/workflows\/(wf_[A-Za-z0-9_-]+)/)?.[1]??null:null,C=k&&!!j&&!!t&&!!n,N="Skill"===e.name,S=v||k||N,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: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-2 border border-border rounded-lg overflow-hidden bg-secondary",children:[(0,r.jsxs)("button",{onClick:()=>c(!i),className:"w-full px-3 py-2 flex items-center gap-2 text-left hover:bg-accent transition-colors",children:[(0,r.jsx)("span",{className:"text-base",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)})]})]}),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),H=n(55804),W=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 U(e,t){return`${e}-${t}`}function K({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=U(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=U(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=U(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)(H.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)(H.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)(W.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),J=n(21362),Z=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)(J.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)(Z.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(70188),en=n(83448);function er({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 es({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)(et.SU,{container:o,children:(0,r.jsx)(ee.M,{content:t,filePath:e,cwd:n,onClose:l})})})})})}let el=(0,s.memo)(function({message:e,cwd:t,sessionId:n,onFork:l,onApprovePlan:a,isLoading:x}){let p,g,b,v,{t:y}=(0,h.Bd)(),[w,k]=(0,s.useState)(null),[j,C]=(0,s.useState)(()=>1===(e.toolCalls?.length||0)),[S,E]=(0,s.useState)(!1),[L,M]=(0,s.useState)(!1),R="user"===e.role,T=e.images&&e.images.length>0,$=e.toolCalls?.length||0,I=!!n&&!!t&&!!l,P=(0,s.useMemo)(()=>e.toolCalls?.some(e=>"Edit"===e.name||"Write"===e.name)||!1,[e.toolCalls]),A=(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]),F=(0,s.useMemo)(()=>e.toolCalls?e.toolCalls.filter(e=>"AskUserQuestion"===e.name):[],[e.toolCalls]),D=(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]),O=(0,s.useMemo)(()=>e.toolCalls?.filter(e=>"ExitPlanMode"!==e.name)??[],[e.toolCalls]),V=(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&&e.toLowerCase().endsWith(".md")&&!t.has(e)&&(t.add(e),n.push(e))}return n},[e.toolCalls]),B=(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]),[H,W]=(0,s.useState)(null),[z,U]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!H)return void queueMicrotask(()=>U(null));let e=!1;return f.t4.runPromiseExit((0,en.an)(H)).then(t=>{e||("Success"===t._tag&&void 0!==t.value.content?U(t.value.content):((0,o.oR)(y("toast.readFileFailed"),"error"),W(null)))}),()=>{e=!0}},[H,y]);let q=()=>{e.content&&(navigator.clipboard.writeText(e.content),(0,o.oR)(y("toast.copiedMessage")))},X=()=>{I&&l(e.id)},J=(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);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:`flex flex-col ${R?"items-end":"items-start"} mb-4 group`,"data-role":e.role,children:[J&&(0,r.jsx)("span",{className:"text-[11px] text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity mb-0.5 px-1",children:J}),(0,r.jsxs)("div",{className:`flex ${R?"justify-end":"justify-start"} w-full`,children:[R&&(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:q,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:y("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"})})}),I&&(0,r.jsx)("button",{onClick:X,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:y("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%] ${R?"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:[T&&(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:()=>k(e),children:(0,r.jsx)("img",{src:`data:${e.media_type};base64,${e.data}`,alt:y("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:R,isStreaming:e.isStreaming,enableMath:!1}),e.isStreaming&&(0,r.jsx)("span",{className:"inline-block w-2 h-4 ml-1 bg-current animate-pulse"})]}),A&&(b=(g=Array.isArray(p=A.input?.todos)?p:[]).filter(e=>"completed"===e.status).length,v=g.length,(0,r.jsx)("div",{className:`${e.content||T?"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:`${v>0?b/v*100:0}%`}})}),(0,r.jsxs)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:[b,"/",v]})]}),g.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))]})})),D&&(0,r.jsx)("div",{className:`${e.content||T||A?"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:y("chat.planTitle",{defaultValue:"Plan (awaiting your review)"})})]}),(0,r.jsx)("div",{className:"px-3 py-2",children:(0,r.jsx)(N.T,{content:D,isUser:!1,enableMath:!1})}),a&&(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:y("chat.planApproveHint",{defaultValue:"本环境无审批弹窗,点此退出 Plan 并执行"})}),(0,r.jsxs)("button",{onClick:()=>a(),disabled:x,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:y("chat.approvePlan",{defaultValue:"批准并执行"})})]})]})]})}),V.length>0&&(0,r.jsx)("div",{className:`${e.content||T||A?"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:V.map(e=>(0,r.jsxs)("button",{onClick:()=>W(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.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))})}),B.length>0&&(0,r.jsx)("div",{className:`${e.content||T||A||V.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:B.map((e,t)=>(0,r.jsxs)("tr",{className:t<B.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))})]})})}),O.length>0&&(0,r.jsx)("div",{className:`${e.content||T?"mt-2":""}`,children:$>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:()=>C(!j),className:"flex-1 px-3 py-2 flex items-center gap-2 text-left hover:bg-accent transition-colors active:bg-muted",children:[(0,r.jsx)("span",{className:"text-lg",children:"\uD83D\uDD27"}),(0,r.jsx)("span",{className:"font-medium text-foreground",children:y("chat.toolCalls",{count:O.length})}),(0,r.jsx)("span",{className:"ml-auto text-muted-foreground text-sm",children:j?y("chat.collapse"):y("chat.expand")})]}),F.length>0&&(0,r.jsx)("button",{onClick:()=>M(!0),className:"px-3 py-2 text-muted-foreground hover:text-foreground hover:bg-accent transition-colors border-l border-border",title:y("chat.viewQuestions"),children:(0,r.jsx)(d.A,{className:"w-4 h-4"})}),P&&(0,r.jsx)("button",{onClick:()=>E(!0),className:"px-3 py-2 text-muted-foreground hover:text-foreground hover:bg-accent transition-colors border-l border-border",title:y("chat.viewAllFileChanges"),children:(0,r.jsx)(m.A,{className:"w-4 h-4"})})]}),j&&(0,r.jsx)("div",{className:"border-t border-border p-2 space-y-1",children:O.map((e,s)=>(0,r.jsx)(_,{toolCall:e,cwd:t,sessionId:n},`${e.id}-${s}`))})]}):O.map((e,s)=>(0,r.jsx)(_,{toolCall:e,cwd:t,sessionId:n},`${e.id}-${s}`))})]}),!R&&(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:q,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:y("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"})})}),I&&(0,r.jsx)("button",{onClick:X,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:y("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"})]})})]})]})]}),w&&(0,r.jsx)(er,{image:w,onClose:()=>k(null)}),S&&e.toolCalls&&(0,r.jsx)(G,{toolCalls:e.toolCalls,cwd:t,onClose:()=>E(!1)}),L&&F.length>0&&(0,r.jsx)(K,{toolCalls:F,onClose:()=>M(!1)}),H&&null!==z&&(0,r.jsx)(es,{filePath:H,content:z,cwd:t||"",onClose:()=>W(null)})]})});var ea=n(1058),eo=n(90717),ei=n(89109),ec=n(7320);let eu=(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:A,currentMatchIndex:_,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),H=(0,l.nH)(),W=(0,s.useRef)(null),z=(0,s.useRef)(()=>{}),{addComment:U,refresh:K}=(0,ea._)({cwd:n||"",filePath:eo.Un}),[q,X]=(0,s.useState)(null),[J,Z]=(0,s.useState)(null),Y=(0,s.useCallback)(e=>{if(q||J)return;let t=window.getSelection();if(!t||t.isCollapsed||!t.rangeCount){W.current=null,z.current();return}let n=t.toString().trim();if(!n){W.current=null,z.current();return}let r=t.anchorNode instanceof HTMLElement?t.anchorNode:t.anchorNode?.parentElement;if(r?.closest('[data-role="user"]')){W.current=null,z.current();return}W.current={x:e.clientX,y:e.clientY,range:{start:0,end:0},selectedText:n,lineSnapshot:n},z.current()},[q,J]),Q=(0,s.useCallback)(e=>{let t=e.target;!(t.closest(".floating-toolbar")||t.closest('[class*="z-[200]"]'))&&W.current&&(W.current=null,z.current())},[]),G=(0,s.useCallback)(()=>{let e=W.current;e&&(X({x:e.x,y:e.y,text:e.selectedText}),W.current=null,z.current(),window.getSelection()?.removeAllRanges())},[]),ee=(0,s.useCallback)(()=>{let e=W.current;e&&(Z({x:e.x,y:e.y,text:e.selectedText}),W.current=null,z.current(),window.getSelection()?.removeAllRanges())},[]),et=(0,s.useCallback)(()=>{let e=W.current;if(!e||!p)return;let t=e.selectedText.trim();W.current=null,z.current(),window.getSelection()?.removeAllRanges(),t&&p(t)},[p]),en=(0,s.useCallback)(async e=>{q&&(await U(0,0,e,q.text),X(null))},[q,U]),er=(0,s.useCallback)(async e=>{if(J&&H&&n)try{let t=(await (0,eo.$3)(n)).map(e=>({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0}));t.push({filePath:eo.Un,startLine:0,endLine:0,codeContent:J.text});let r=(0,eo.Gw)(t,e);H.sendMessage(r),await (0,eo.RP)(n),K(),Z(null)}catch(e){console.error("Failed to send to AI:",e)}},[J,H,n,K]),es=(0,s.useMemo)(()=>{let t=new Set;return e.filter(e=>!t.has(e.id)&&(t.add(e.id),!0))},[e]),eu=(0,s.useRef)(0),ed=(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&&(eu.current=e.scrollHeight,ed.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(ed.current&&!d){let e=k.current;if(e){let t=e.scrollHeight-eu.current;e.scrollTop=t,ed.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:A.length>0?`${_+1}/${A.length}`:v("common.noMatch")}),(0,r.jsx)("button",{onClick:D,disabled:0===A.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===A.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)(el,{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)(ei.f,{floatingToolbarRef:W,bumpRef:z,container:C,onAddComment:G,onSendToAI:ee,onSearch:p?et:void 0,isChatLoading:H?.isLoading}),q&&C&&(0,r.jsx)(ec.t,{x:q.x,y:q.y,range:{start:0,end:0},lineSnapshot:q.text,container:C,onSubmit:en,onClose:()=>X(null)}),J&&C&&(0,r.jsx)(ec.G,{x:J.x,y:J.y,range:{start:0,end:0},lineSnapshot:J.text,container:C,onSubmit:er,onClose:()=>Z(null),isChatLoading:H?.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,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}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}){let[b,v]=(0,r.useState)(!1),[y,w]=(0,r.useState)(null),[k,j]=(0,r.useState)(null),[C,N]=(0,r.useState)(null),[S,E]=(0,r.useState)(null),L=(0,r.useRef)(null),[M,R]=(0,r.useState)(null),T=(0,r.useRef)(M);T.current=M;let $=(0,r.useRef)(!1),I=(0,r.useRef)(null),P=(0,r.useRef)(n);P.current=n;let A=(0,r.useRef)(null),_=(0,r.useRef)(null),F=(0,r.useCallback)(()=>{let e=A.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})),A.current={messageId:n,text:""}}_.current=null},[t,u]),D=(0,r.useCallback)(()=>{_.current&&(clearTimeout(_.current),_.current=null),I.current&&(clearTimeout(I.current),I.current=null),F(),v(!1);let e=T.current;e&&t(t=>t.map(t=>t.id===e.assistantId?{...t,isStreaming:!1}:t)),R(null)},[F,t]),O=(0,r.useCallback)(()=>{let e=T.current;fetch("/api/chat/stop",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:P.current,runId:e?.runKey})}).catch(()=>{}),D()},[D]),V=(0,r.useCallback)((e,n)=>{let r=e.type;if("pty_output"===r)return void g?.(e.data);if("pty_notice"===r){let r=e.messageKey?l.A.t(e.messageKey,e.params||{}):e.message;if(!r)return;e.terminal?t(e=>e.map(e=>e.id===n?{...e,content:r,isStreaming:!1}:e)):E(r);return}if("system"===r&&"init"===e.subtype){let t=e.session_id;x(t),P.current=t,N(null);return}if("system"===r&&"api_retry"===e.subtype)return void N({attempt:e.attempt??0,maxRetries:e.max_retries??0,delayMs:e.retry_delay_ms??0,errorStatus:e.error_status,error:e.error});if("rate_limit_event"===r){let t=e.rate_limit_info;t&&j({status:t.status||"allowed",resetsAt:t.resetsAt,rateLimitType:t.rateLimitType,utilization:t.utilization,overageStatus:t.overageStatus,overageDisabledReason:t.overageDisabledReason,isUsingOverage:t.isUsingOverage,surpassedThreshold:t.surpassedThreshold});return}if("error"===r){let r=e.error||l.A.t("chat.errorRetry",{defaultValue:"An error occurred. Please try again."});N(null),_.current&&(clearTimeout(_.current),_.current=null),F(),t(e=>e.map(e=>e.id===n?{...e,content:e.content?`${e.content}
2
2
 
3
3
  ⚠️ ${r}`:`⚠️ ${r}`,isStreaming:!1}:e));return}if("stream_event"===r){N(e=>e?null:e),E(e=>e?null:e);let t=e.event;if(t?.type==="content_block_delta"&&t.delta?.type==="text_delta"){let e=t.delta.text||"";A.current&&A.current.messageId===n?A.current.text+=e:A.current={messageId:n,text:e},_.current||(_.current=setTimeout(F,50))}return}if("assistant"===r&&t(t=>(0,s.F)(t,e,{engine:u,assistantId:n})),"user"===r&&t(t=>(0,s.F)(t,e,{engine:u,assistantId:n})),"result"===r){N(null),_.current&&(clearTimeout(_.current),_.current=null),F();let r=P.current;r&&c&&t(e=>(2===e.length&&p(r),e));let l=e.usage,a=e.total_cost_usd;l&&w({inputTokens:l.input_tokens||0,outputTokens:l.output_tokens||0,cacheCreationInputTokens:l.cache_creation_input_tokens||0,cacheReadInputTokens:l.cache_read_input_tokens||0,totalCostUsd:a||0}),t(t=>(0,s.F)(t,e,{engine:u,assistantId:n}))}},[t,F,x,p,c,u,g]);return(0,a.h)({url:M?`/ws/session-stream?sessionId=${encodeURIComponent(M.runKey)}`:"/ws/session-stream",enabled:!!M,onMessage:e=>{$.current=!0,I.current&&(clearTimeout(I.current),I.current=null);let n=T.current;if(n)if("run-snapshot"===e.type&&Array.isArray(e.events)){for(let r of(_.current&&(clearTimeout(_.current),_.current=null),A.current=null,t(e=>e.map(e=>e.id===n.assistantId?{...e,content:"",toolCalls:[]}:e)),e.events))V(r,n.assistantId);e.status&&"running"!==e.status&&D()}else if("run-event"===e.type&&e.message){if("run-ended"===e.message.type)return void D();V(e.message,n.assistantId)}else"run-idle"===e.type&&D()}}),{isLoading:b,tokenUsage:y,rateLimitInfo:k,apiRetryInfo:C,ptyNotice:S,handleSend:(0,r.useCallback)(async(e,n,r)=>{let s=r&&"permissionMode"in r?"plan"===r.permissionMode:m,a=n?.map(e=>({type:"base64",media_type:e.media_type,data:e.data})),i={id:`user-${Date.now()}`,role:"user",content:e,images:a};t(e=>[...e,i]),v(!0),N(null),E(null);let x=`assistant-${Date.now()}`,p={id:x,role:"assistant",content:"",toolCalls:[],isStreaming:!0};t(e=>[...e,p]);let g=!u||"claude"===u||"claude2"===u,b="pty"===d&&g,y=function(){try{return crypto.randomUUID()}catch{return`run-${Date.now()}-${Math.floor(1e9*Math.random())}`}}();try{if("ollama"===u&&!h)throw Error("Please select an Ollama model first (click the model picker above)");let n="codex"===u?"/api/chat/codex":"kimi"===u?"/api/chat/kimi":"ollama"===u?"/api/chat/ollama":"deepseek"===u?"/api/chat/deepseek":"/api/chat",r=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:e,sessionId:P.current,runId:y,images:a,cwd:c,language:l.A.language,..."ollama"===u&&h&&{model:h},..."deepseek"===u&&f&&{model:f},..."claude2"===u&&{engine:"claude2"},...b&&{mode:"pty",ptyCols:o.EE,ptyRows:o.K2},...s&&!b&&g&&{permissionMode:"plan"}})});if(400===r.status&&"deepseek"===u){let e=await r.json().catch(()=>null);throw Error(e?.error||"DeepSeek request failed")}if(!r.ok)throw Error(l.A.t("chat.requestFailed",{defaultValue:"Request failed"}));let i=await r.json().catch(()=>({}));R({runKey:i.runKey||y,assistantId:x}),$.current=!1,I.current&&clearTimeout(I.current),I.current=setTimeout(()=>{T.current&&!$.current&&(t(e=>e.map(e=>e.id!==x||e.content?e:{...e,content:l.A.t("chat.errorRetry",{defaultValue:"An error occurred. Please try again."})})),D())},15e3)}catch(n){console.error("Chat error:",n);let e=n instanceof Error?n.message:l.A.t("chat.errorRetry",{defaultValue:"An error occurred. Please try again."});t(t=>t.map(t=>t.id===x?{...t,content:e,isStreaming:!1}:t)),v(!1),R(null)}},[c,u,d,m,h,f,t,D]),handleStop:O,abortControllerRef:L}}},22576:(e,t,n)=>{n.d(t,{X:()=>r});function r(e,t){let n=e.split("\n"),r=t.split("\n"),s=[],l=n.length,a=r.length,o=Array(l+1).fill(null).map(()=>Array(a+1).fill(0));for(let e=1;e<=l;e++)for(let t=1;t<=a;t++)n[e-1]===r[t-1]?o[e][t]=o[e-1][t-1]+1:o[e][t]=Math.max(o[e-1][t],o[e][t-1]);let i=l,c=a,u=[];for(;i>0||c>0;)i>0&&c>0&&n[i-1]===r[c-1]?(u.push({type:"unchanged",content:n[i-1],oldLineNum:i,newLineNum:c}),i--,c--):c>0&&(0===i||o[i][c-1]>=o[i-1][c])?(u.push({type:"added",content:r[c-1],newLineNum:c}),c--):(u.push({type:"removed",content:n[i-1],oldLineNum:i}),i--);for(;u.length>0;)s.push(u.pop());return s}},27570:(e,t,n)=>{n.d(t,{L:()=>s});var r=n(12115);function s({enabled:e,container:t,resolveLineRange:n,buildLineSnapshot:l,dragThresholdPx:a=5}){let o=(0,r.useRef)(null),i=(0,r.useRef)(()=>{}),c=(0,r.useRef)(n),u=(0,r.useRef)(l),d=(0,r.useRef)(a);return c.current=n,u.current=l,d.current=a,(0,r.useEffect)(()=>{if(!e||!t)return;let n=!1,r=0,s=0,l=()=>{o.current&&(o.current=null,i.current())},a=e=>{n=!0,r=e.clientX,s=e.clientY;let t=e.target;t?.closest?.(".floating-toolbar")||l()},m=e=>{n=!1;let a=e.target;if(a?.closest?.(".floating-toolbar"))return;let m=d.current,h=Math.abs(e.clientX-r)>m||Math.abs(e.clientY-s)>m,f=window.getSelection();if(!f||f.isCollapsed||!f.toString().trim()||!h)return void l();let x=f.getRangeAt(0);if(!t.contains(x.commonAncestorContainer))return void l();let p=c.current(x.startContainer),g=c.current(x.endContainer);if(!p||!g)return void l();let b=Math.min(p.start,g.start),v=Math.max(p.end,g.end),y=f.toString(),w=u.current({start:b,end:v});o.current={x:e.clientX,y:e.clientY,range:{start:b,end:v},selectedText:y,lineSnapshot:w},i.current()},h=()=>{if(n||!o.current)return;let e=window.getSelection();e&&!e.isCollapsed&&e.toString().trim()||l()};return t.addEventListener("mousedown",a),document.addEventListener("mouseup",m),document.addEventListener("selectionchange",h),()=>{t.removeEventListener("mousedown",a),document.removeEventListener("mouseup",m),document.removeEventListener("selectionchange",h)}},[e,t]),{toolbarRef:o,bumpRef:i,clearToolbar:()=>{o.current&&(o.current=null,i.current())}}}},37614:(e,t,n)=>{n.d(t,{t:()=>a});var r=n(95155),s=n(12115),l=n(79114);function a({x:e,y:t,comment:n,container:o,onClose:i,onUpdateComment:c,onDeleteComment:u}){let{t:d}=(0,l.Bd)(),[m,h]=(0,s.useState)(!1),[f,x]=(0,s.useState)(n.content),p=(0,s.useRef)(null),[g,b]=(0,s.useState)({x:0,y:0});(0,s.useEffect)(()=>{if(p.current&&o){let n=o.getBoundingClientRect(),r=p.current.getBoundingClientRect(),s=e-n.left,l=t-n.top;s+r.width>n.width-16&&(s=n.width-r.width-16),s<16&&(s=16),l+r.height>n.height-16&&(l=l-r.height-8),l<16&&(l=16),queueMicrotask(()=>b({x:s,y:l}))}},[e,t,o]),(0,s.useEffect)(()=>{let e=e=>{p.current&&!p.current.contains(e.target)&&i()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[i]);let v=async()=>{f.trim()&&(await c(n.id,f.trim()),h(!1))},y=async()=>{await u(n.id),i()};return(0,r.jsx)("div",{ref:p,className:"absolute z-[200] w-96 bg-card border border-border rounded-lg shadow-lg overflow-hidden",style:{left:g.x,top:g.y},children:(0,r.jsx)("div",{className:"p-3",children:m?(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)("textarea",{value:f,onChange:e=>x(e.target.value),className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card resize-none focus:outline-none focus:ring-1 focus:ring-ring",rows:3,autoFocus:!0,onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),v()),"Escape"===e.key&&(h(!1),x(n.content))}}),(0,r.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,r.jsx)("button",{onClick:()=>{h(!1),x(n.content)},className:"px-2 py-1 text-xs text-muted-foreground hover:text-foreground",children:d("common.cancel")}),(0,r.jsx)("button",{onClick:v,className:"px-2 py-1 text-xs bg-brand text-white rounded hover:bg-brand/90",children:d("common.save")})]})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("p",{className:"text-sm text-foreground whitespace-pre-wrap",children:n.content}),(0,r.jsxs)("div",{className:"mt-2 flex items-center justify-between",children:[(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:d("comments.lineRange",{start:n.startLine,end:n.endLine})}),(0,r.jsxs)("div",{className:"flex gap-1",children:[(0,r.jsx)("button",{onClick:()=>h(!0),className:"p-1 rounded hover:bg-accent text-muted-foreground",title:d("common.edit"),children:(0,r.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}),(0,r.jsx)("button",{onClick:y,className:"p-1 rounded hover:bg-accent text-muted-foreground hover:text-red-9",title:d("common.delete"),children:(0,r.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]})]})]})})})}},38408:(e,t,n)=>{n.d(t,{Cv:()=>P,XO:()=>A});var r=n(95155),s=n(12115),l=n(79114),a=n(47650),o=n(86957),i=n(60938),c=n(70188),u=n(7320),d=n(56978),m=n(17196),h=n(89109),f=n(37614),x=n(69809),p=n(64428);function g({blame:e,onClick:t}){let{t:n}=(0,l.Bd)(),a=(0,s.useRef)(null),o=(0,s.useRef)(null),i=(0,p.F2)(),c=(0,s.useRef)(!1),u=(0,s.useRef)(!1),d=(0,s.useRef)(null),m=(0,s.useRef)(null),h=(0,s.useRef)(null),f=(0,s.useRef)(e);(0,s.useEffect)(()=>{f.current=e},[e]);let b=(0,s.useRef)(t);(0,s.useEffect)(()=>{b.current=t},[t]);let v=(0,s.useCallback)(()=>{let e,t=o.current,n=a.current;if(!t||!n)return;let r=n.getBoundingClientRect(),s=t.getBoundingClientRect(),l=i?.getBoundingClientRect(),c=l?.left??0,u=l?.top??0,d=l?.width??window.innerWidth,m=l?.height??window.innerHeight,h=r.left-c;h+s.width>d-8&&(h=d-s.width-8),h<8&&(h=8);let f=r.top-u,x=r.bottom-u;(e=f-s.height-4<0?x+4:f-s.height-4)+s.height>m-8&&(e=m-s.height-8),t.style.left=`${h}px`,t.style.top=`${e}px`},[i]),y=(0,s.useCallback)(()=>{d.current&&(clearTimeout(d.current),d.current=null),m.current&&(clearTimeout(m.current),m.current=null),c.current=!1,u.current=!1,o.current&&(o.current.style.display="none"),h.current&&(document.removeEventListener("mousedown",h.current.down),document.removeEventListener("mouseup",h.current.up),h.current=null)},[]),w=(0,s.useCallback)(()=>{let e=o.current;if(!e||c.current)return;c.current=!0,e.style.left="-9999px",e.style.top="-9999px",e.style.display="block",requestAnimationFrame(()=>requestAnimationFrame(v));let t=0,n=0,r=e=>{t=e.clientX,n=e.clientY},s=e=>{if(!(Math.abs(e.clientX-t)>5||Math.abs(e.clientY-n)>5)){let t;t=e.target,o.current?.contains(t)||a.current?.contains(t)||y()}};document.addEventListener("mousedown",r),document.addEventListener("mouseup",s),h.current={down:r,up:s}},[v,y]),k=(0,s.useCallback)(()=>{if(d.current&&clearTimeout(d.current),m.current&&(clearTimeout(m.current),m.current=null),c.current)return;let e=window.getSelection();(!e||e.isCollapsed)&&(d.current=setTimeout(w,500))},[w]),j=(0,s.useCallback)(()=>{d.current&&(clearTimeout(d.current),d.current=null),c.current&&(m.current=setTimeout(()=>{u.current||y()},200))},[y]),C=(0,s.useCallback)(()=>{u.current=!0,m.current&&(clearTimeout(m.current),m.current=null)},[]),N=(0,s.useCallback)(()=>{u.current=!1,y()},[y]),S=(0,s.useCallback)(e=>{e.stopPropagation();let t=window.getSelection();t&&t.toString().length>0&&o.current?.contains(t.anchorNode)||(b.current?.(f.current),y())},[y]);(0,s.useEffect)(()=>()=>y(),[y]);let E=e.message.split("\n")[0]||"",L=e.message.split("\n").slice(1).join("\n").trim();return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("span",{ref:a,className:"select-none text-xs text-muted-foreground/50 ml-6 cursor-default hover:text-muted-foreground/80",onMouseEnter:k,onMouseLeave:j,children:[e.author.split(" ")[0],", ",function(e){let t=x.A.t,n=Math.floor((Date.now()-1e3*e)/1e3);if(n<60)return t("common.justNow");let r=Math.floor(n/60);if(r<60)return t("common.minutesAgo",{count:r});let s=Math.floor(r/60);if(s<24)return t("common.hoursAgo",{count:s});let l=Math.floor(s/24);if(l<30)return t("common.daysAgo",{count:l});let a=Math.floor(l/30);return a<12?t("common.monthsAgo",{count:a}):t("common.yearsAgo",{count:Math.floor(a/12)})}(e.time)," \xb7 ",E]}),(0,r.jsx)(p.ZL,{children:(0,r.jsxs)("div",{ref:o,className:"fixed z-[9999] bg-card border border-border rounded-lg shadow-xl p-3 text-xs text-foreground whitespace-pre-wrap max-w-md select-text",style:{display:"none",minWidth:280,cursor:"text"},"data-inline-blame-tip":"",onMouseEnter:C,onMouseLeave:N,children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 mb-1.5",children:[(0,r.jsx)("span",{className:"font-mono text-brand",children:e.hash}),(0,r.jsx)("span",{className:"text-muted-foreground",children:e.author}),(0,r.jsx)("span",{className:"text-muted-foreground/60",children:new Date(1e3*e.time).toLocaleString()})]}),(0,r.jsx)("div",{className:"font-medium",children:E}),L&&(0,r.jsx)("div",{className:"mt-1 text-muted-foreground",children:L}),(0,r.jsx)("div",{className:"mt-2 text-[11px] text-brand border-t border-border pt-2 cursor-pointer hover:underline",onClick:S,children:n("codeViewer.clickToViewDetails")})]})})]})}let b=[{bg:"rgba(59, 130, 246, 0.15)",border:"rgb(59, 130, 246)"},{bg:"rgba(16, 185, 129, 0.15)",border:"rgb(16, 185, 129)"},{bg:"rgba(245, 158, 11, 0.15)",border:"rgb(245, 158, 11)"},{bg:"rgba(239, 68, 68, 0.15)",border:"rgb(239, 68, 68)"},{bg:"rgba(168, 85, 247, 0.15)",border:"rgb(168, 85, 247)"},{bg:"rgba(236, 72, 153, 0.15)",border:"rgb(236, 72, 153)"},{bg:"rgba(20, 184, 166, 0.15)",border:"rgb(20, 184, 166)"},{bg:"rgba(249, 115, 22, 0.15)",border:"rgb(249, 115, 22)"}];function v(e,t){let n,r=document.caretRangeFromPoint(e.clientX,e.clientY);if(!r||!t.contains(r.startContainer))return 1;let s=r.startContainer,l=r.startOffset,a=document.createTreeWalker(t,NodeFilter.SHOW_TEXT),o=1;for(;n=a.nextNode();){if(n===s){o+=l;break}o+=n.textContent?.length||0}return o}let y=(0,s.memo)(function({virtualKey:e,lineNum:t,highlightedHtml:n,hasComments:a,firstComment:o,lineCommentsCount:i,isInRange:c,showLineNumbers:u,lineNumChars:d,commentsEnabled:m,virtualItemSize:h,virtualItemStart:f,onCommentBubbleClick:x,onCmdClick:p,onTokenHover:b,onTokenHoverLeave:y,flashLine:w,blameLine:k,showBlameInfo:j,blameAuthorColor:C,isBlameHovered:N,onBlameClick:S,onBlameMouseEnter:E,onBlameMouseLeave:L,inlineBlameData:M,onInlineBlameClick:R,isCursorLine:T,cursorCol:$}){let{t:I}=(0,l.Bd)(),P=(0,s.useMemo)(()=>T&&null!=$?function(e,t){let n=0,r=0;for(;r<e.length;){if("<"===e[r]){let t=e.indexOf(">",r);if(-1!==t){r=t+1;continue}}if(n===t){let t;if("&"===e[r]){let n=e.indexOf(";",r);t=-1!==n&&n-r<10?n+1:r+1}else t=r+1;let n=e.substring(r,t);return e.substring(0,r)+'<span class="vi-char-cursor">'+n+"</span>"+e.substring(t)}if("&"===e[r]){let t=e.indexOf(";",r);r=-1!==t&&t-r<10?t+1:r+1}else r++;n++}return e+'<span class="vi-char-cursor"> </span>'}(n,$):n,[n,T,$]),A=(0,s.useCallback)(e=>{if(!e.metaKey||!p)return;e.preventDefault(),e.stopPropagation();let n=e.currentTarget,r=v(e,n);window.getSelection()?.removeAllRanges(),p(t,r)},[t,p]),_=(0,s.useCallback)(e=>{if(!b||0!==e.buttons)return;let n=window.getSelection();if(n&&!n.isCollapsed)return;let r=e.target;if("SPAN"!==r.tagName||!r.style.color)return;let s=e.currentTarget,l=v(e,s),a=r.getBoundingClientRect();b(t,l,{x:a.left,y:a.bottom+4})},[t,b]),F=(0,s.useCallback)(()=>{k&&S&&S(k)},[k,S]),D=(0,s.useCallback)(e=>{k&&E&&E(k,e)},[k,E]);return(0,r.jsxs)("div",{"data-line":t,style:{position:"absolute",top:0,left:0,width:"100%",height:`${h}px`,transform:`translateY(${f}px)`,backgroundColor:N&&C?C.bg:void 0},className:`flex ${w===t?"flash-line":""} ${T?"vi-cursor-line":""} ${c?"bg-blue-9/20":a?"bg-amber-9/10":"hover:bg-accent/50"}`,children:[(0,r.jsxs)("div",{className:"flex shrink-0 sticky left-0 z-[2] bg-secondary",style:{backgroundColor:N&&C?C.bg:void 0},children:[k&&C&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"w-1 flex-shrink-0",style:{backgroundColor:C.border}}),(0,r.jsx)("div",{className:"w-48 flex-shrink-0 px-2 flex items-center gap-2 border-r border-border text-muted-foreground cursor-pointer hover:bg-accent/50",onMouseEnter:D,onMouseLeave:L,onClick:F,title:I("codeViewer.clickToViewCommit"),children:j?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"font-medium",style:{color:C.border},children:k.hash}),(0,r.jsx)("span",{className:"truncate flex-1",children:k.author.split(" ")[0]})]}):null})]}),u&&(0,r.jsxs)("span",{className:`flex-shrink-0 flex items-center justify-end gap-0.5 pr-2 select-none border-r border-border font-variant-tabular ${c?"bg-blue-9/30 text-blue-11":"bg-card/50 text-slate-9"}`,children:[m&&a&&o&&(0,r.jsx)("button",{onClick:e=>x(o,e),className:"w-4 h-4 flex items-center justify-center rounded hover:bg-accent text-amber-9",title:I("codeViewer.nComments",{count:i}),children:(0,r.jsx)("svg",{className:"w-3 h-3",fill:"currentColor",viewBox:"0 0 20 20",children:(0,r.jsx)("path",{fillRule:"evenodd",d:"M18 10c0 3.866-3.582 7-8 7a8.841 8.841 0 01-4.083-.98L2 17l1.338-3.123C2.493 12.767 2 11.434 2 10c0-3.866 3.582-7 8-7s8 3.134 8 7zM7 9H5v2h2V9zm8 0h-2v2h2V9zM9 9h2v2H9V9z",clipRule:"evenodd"})})}),m&&!a&&(0,r.jsx)("span",{className:"w-4"}),(0,r.jsx)("span",{className:"text-right",style:{minWidth:`${d}ch`},children:t})]})]}),(0,r.jsxs)("span",{className:"flex-1 px-3 whitespace-pre select-text",onClick:A,onMouseOver:_,onMouseLeave:y,"data-code-content":!0,children:[(0,r.jsx)("span",{dangerouslySetInnerHTML:{__html:P}}),M&&(0,r.jsx)(g,{blame:M,onClick:R})]})]},e)});var w=n(64702),k=n(1058),j=n(90717),C=n(48347),N=n(27570);function S(e,t,n){let r,s=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),l=0;for(;(r=s.nextNode())&&r!==t;)l+=r.textContent.length;return l+n}function E(e,t){let n,r=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),s=t,l=null;for(;n=r.nextNode();){l=n;let e=n.textContent.length;if(s<=e)return{node:n,offset:s};s-=e}return l?{node:l,offset:l.textContent.length}:null}var L=n(82292),M=n(34075);let R="white-space:pre;padding:0 12px;min-height:20px;line-height:20px";function T(e){let t=window.getSelection();if(!t?.rangeCount)return null;let n=t.getRangeAt(0),r=n.startContainer;for(;r&&r.parentElement!==e;)r=r.parentElement;if(!r)return null;let s=Array.from(e.children).indexOf(r);if(s<0)return null;let l=document.createRange();return l.selectNodeContents(r),l.setEnd(n.startContainer,n.startOffset),{line:s,offset:l.toString().length}}function $(e,t){let n,r=e.children[t.line];if(!r)return;let s=document.createTreeWalker(r,NodeFilter.SHOW_TEXT),l=t.offset;for(;n=s.nextNode();){let e=n.textContent?.length||0;if(l<=e){let e=window.getSelection(),t=document.createRange();t.setStart(n,l),t.collapse(!0),e?.removeAllRanges(),e?.addRange(t);return}l-=e}let a=window.getSelection(),o=document.createRange();o.selectNodeContents(r),o.collapse(!1),a?.removeAllRanges(),a?.addRange(o)}function I(e){return e.map(e=>`<div style="${R}">${e}</div>`).join("")}let P=(0,s.forwardRef)(function({content:e,filePath:t,showLineNumbers:n=!0,showSearch:x=!0,className:p="",cwd:g,enableComments:v=!1,scrollToLine:P=null,scrollToLineAlign:A="center",onScrollToLineComplete:_,highlightKeyword:F=null,visibleLineRef:D,onCmdClick:O,onTokenHover:V,onTokenHoverLeave:B,onTokenHoverCancel:H,blameLines:W,inlineBlameLines:z,onSelectCommit:U,editable:K=!1,initialMtime:q,onEditorClose:X,onSaved:J,onEditorStateChange:Z,viMode:Y=!1,onContentMutate:Q,onEnterInsertMode:G,onViSave:ee,viStateRef:et,initialCursorLine:en,initialCursorCol:er,onInitialCursorSet:es,onContentSearch:el},ea){let{t:eo}=(0,l.Bd)(),ei=(0,s.useRef)(e),ec=(0,s.useRef)(!1),[eu,ed]=(0,s.useState)(!1),[em,eh]=(0,s.useState)(!1),[ef,ex]=(0,s.useState)(()=>e.split("\n").length),ep=(0,s.useRef)(e.split("\n").length),[eg,eb]=(0,s.useState)({show:!1}),ev=(0,s.useRef)(null),ey=(0,s.useRef)(null),ew=(0,s.useRef)(q),ek=(0,s.useRef)(null),ej=(0,s.useRef)(!1),eC=(0,s.useRef)(!1),{parentRef:eN,containerRef:eS,searchInputRef:eE,floatingToolbarRef:eL,suppressHoverRef:eM,bumpToolbarRef:eR,savedSelectionRef:eT,highlightedLines:e$,isMounted:eI,cmdHeld:eP,flashLine:eA,isSearchVisible:e_,searchQuery:eF,caseSensitive:eD,wholeWord:eO,currentMatchIndex:eV,viewingComment:eB,addCommentInput:eH,sendToAIInput:eW,aiBridge:ez,commentsEnabled:eU,updateComment:eK,deleteComment:eq,lines:eX,matches:eJ,rowData:eZ,virtualizer:eY,commentsByEndLine:eQ,linesWithComments:eG,setIsSearchVisible:e0,setSearchQuery:e1,setCaseSensitive:e2,setWholeWord:e5,setViewingComment:e4,setAddCommentInput:e3,setSendToAIInput:e8,goToNextMatch:e6,goToPrevMatch:e9,handleSearchKeyDown:e7,handleCommentBubbleClick:te,handleToolbarAddComment:tt,handleToolbarSendToAI:tn,handleToolbarSearch:tr,handleCommentSubmit:ts,handleSendToAISubmit:tl,getHighlightedLineHtml:ta,suppressMatchScrollRef:to,inlineBlameLineRef:ti,inlineBlameVersion:tc}=function({content:e,filePath:t,showSearch:n=!0,cwd:r,enableComments:l=!1,scrollToLine:a=null,scrollToLineAlign:o="center",onScrollToLineComplete:i,visibleLineRef:c,onContentSearch:u}){let[h,f]=(0,s.useState)(!1),x=(0,s.useRef)(null),p=(0,s.useRef)(null),g=(0,s.useRef)(null),b=(0,C.r)();(0,s.useEffect)(()=>{f(!0)},[]);let[v,y]=(0,s.useState)(!1),[E,L]=(0,s.useState)(null),M=(0,s.useRef)(null),[R,T]=(0,s.useState)(!1),[$,I]=(0,s.useState)(""),[P,A]=(0,s.useState)(!1),[_,F]=(0,s.useState)(!1),[D,O]=(0,s.useState)(0),[V,B]=(0,s.useState)(0),H=(0,s.useRef)(!1),[W,z]=(0,s.useState)(null),U=(0,s.useRef)(!1),K=(0,s.useRef)(null),[q,X]=(0,s.useState)(null),[J,Z]=(0,s.useState)(null),Y=(0,s.useMemo)(()=>e.split("\n"),[e]),[Q,G]=(0,s.useState)(null);(0,s.useEffect)(()=>{x.current!==Q&&G(x.current)});let ee=l&&!!r,{toolbarRef:et,bumpRef:en,clearToolbar:er}=(0,N.L)({enabled:ee,container:Q,resolveLineRange:e=>{if(!document.contains(e))return null;let t=e.nodeType===Node.TEXT_NODE?e.parentElement:e,n=t?.closest("[data-line]");if(!n)return null;let r=parseInt(n.getAttribute("data-line")||"0",10);return!Number.isFinite(r)||r<=0?null:{start:r,end:r}},buildLineSnapshot:({start:e,end:t})=>Y.slice(e-1,t).join("\n")}),es=(0,s.useRef)(null),[el,ea]=(0,s.useState)(0),{comments:eo,addComment:ei,updateComment:ec,deleteComment:eu,refresh:ed}=(0,k._)({cwd:r||"",filePath:t}),em=(0,d.C)(Y,t),eh=(0,s.useMemo)(()=>{let e=new Map;for(let t of eo){let n=t.endLine;e.has(n)||e.set(n,[]),e.get(n).push(t)}return e},[eo]),ef=(0,s.useMemo)(()=>{let e=new Set;for(let t of eo)for(let n=t.startLine;n<=t.endLine;n++)e.add(n);return e},[eo]),ex=(0,s.useMemo)(()=>(0,m.Np)(Y,$,P,_),[Y,$,P,_]);(0,s.useEffect)(()=>{ex.length>0&&O(0)},[ex.length,$,P,_]);let ep=(0,s.useMemo)(()=>{let e=[];for(let t=0;t<Y.length;t++)e.push({type:"code",lineIndex:t});return e},[Y.length]),eg=(0,w.Te)({count:ep.length,getScrollElement:()=>x.current,estimateSize:()=>20,overscan:10});(0,s.useEffect)(()=>{if(!c)return;let e=x.current;if(!e)return;let t=()=>{if(!eg.range)return;let t=e.scrollTop;for(let e of eg.getVirtualItems())if(e.start>=t){let t=ep[e.index];t?.type==="code"&&(c.current=t.lineIndex+1);return}};return e.addEventListener("scroll",t,{passive:!0}),t(),()=>e.removeEventListener("scroll",t)},[c,ep]),(0,s.useEffect)(()=>{let e=e=>{"Meta"===e.key&&y(!0)},t=e=>{"Meta"===e.key&&y(!1)},n=()=>y(!1);return window.addEventListener("keydown",e),window.addEventListener("keyup",t),window.addEventListener("blur",n),()=>{window.removeEventListener("keydown",e),window.removeEventListener("keyup",t),window.removeEventListener("blur",n)}},[]),(0,s.useEffect)(()=>{if(!n)return;let e=e=>{(e.metaKey||e.ctrlKey)&&"f"===e.key&&(e.preventDefault(),T(!0),setTimeout(()=>g.current?.focus(),0)),"Escape"===e.key&&(R?(T(!1),I("")):J?Z(null):q?X(null):et.current?er():W&&z(null))},t=p.current;if(t)return t.addEventListener("keydown",e),()=>t.removeEventListener("keydown",e)},[n,R,J,q,W]),(0,s.useEffect)(()=>{if(H.current){H.current=!1;return}if(ex.length>0&&D>=0&&D<ex.length){let e=ex[D],t=ep.findIndex(t=>"code"===t.type&&t.lineIndex===e.lineIndex);t>=0&&eg.scrollToIndex(t,{align:"center"})}},[D,ex,eg,ep,V]);let eb=(0,s.useCallback)(()=>{0!==ex.length&&(O(e=>(e+1)%ex.length),B(e=>e+1))},[ex.length]),ev=(0,s.useCallback)(()=>{0!==ex.length&&(O(e=>(e-1+ex.length)%ex.length),B(e=>e+1))},[ex.length]),ey=(0,s.useRef)(a);ey.current=a,(0,s.useEffect)(()=>{if(null!==ey.current&&ey.current>0&&ep.length>0){let e=ey.current,t=e-1,n=ep.findIndex(e=>"code"===e.type&&e.lineIndex===t);if(n>=0){let t=()=>{eg.scrollToIndex(n,{align:o}),"center"===o&&(M.current&&clearTimeout(M.current),L(e),M.current=setTimeout(()=>L(null),500)),i?.()};"start"===o?requestAnimationFrame(t):setTimeout(t,150)}}},[a,o,ep.length,eg,i]);let ew=(0,s.useCallback)(e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?ev():eb()),"Escape"===e.key&&(T(!1),I(""))},[eb,ev]),ek=(0,s.useCallback)((e,t)=>{ee&&(t.stopPropagation(),z({comment:e,x:t.clientX,y:t.clientY}),er(),X(null),Z(null))},[ee,er]);(0,s.useEffect)(()=>{if(!ee)return;let e=x.current,t=!1,n=()=>{t=!0,K.current=null,U.current=!0},r=()=>{t=!1;let e=window.getSelection();if(!e||e.isCollapsed||!e.toString().trim()){U.current=!1;return}let n=e.getRangeAt(0),r=x.current;if(!r||!r.contains(n.commonAncestorContainer))return;let s=n.startContainer,l=n.endContainer,a=(s.nodeType===Node.TEXT_NODE?s.parentElement:s)?.closest("[data-line]"),o=(l.nodeType===Node.TEXT_NODE?l.parentElement:l)?.closest("[data-line]");if(!a||!o)return;let i=parseInt(a.getAttribute("data-line")||"0",10),c=parseInt(o.getAttribute("data-line")||"0",10);i&&c&&(U.current=!0,K.current={startLine:i,startOffset:S(a,n.startContainer,n.startOffset),endLine:c,endOffset:S(o,n.endContainer,n.endOffset)})},s=()=>{if(t)return;let e=window.getSelection();e&&!e.isCollapsed&&e.toString().trim()||(K.current=null,U.current=!1)};return e?.addEventListener("mousedown",n),document.addEventListener("mouseup",r),document.addEventListener("selectionchange",s),()=>{e?.removeEventListener("mousedown",n),document.removeEventListener("mouseup",r),document.removeEventListener("selectionchange",s)}},[ee]),(0,s.useEffect)(()=>{let e=x.current;if(!e)return;let t=t=>{let n,r;if(!e.contains(t.target)){if(t.target.closest?.("[data-inline-blame-tip]"))return;null!==es.current&&(es.current=null,ea(e=>e+1));return}let s=window.getSelection();if(s&&!s.isCollapsed&&s.toString().trim())return;let l=(n=t.target,(r=n.closest?.("[data-line]"))?parseInt(r.getAttribute("data-line")||"0",10):null);l!==es.current&&(es.current=l,requestAnimationFrame(()=>ea(e=>e+1)))};return document.addEventListener("mouseup",t),()=>document.removeEventListener("mouseup",t)},[]);let ej=(0,s.useCallback)(()=>{let e=et.current;e&&(X({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),er())},[er,et]),eC=(0,s.useCallback)(()=>{let e=et.current;e&&(Z({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),er())},[er,et]),eN=(0,s.useCallback)(()=>{let e=et.current;if(!e||!u)return;let t=e.selectedText.trim();er(),t&&u(t)},[u,er,et]),eS=(0,s.useCallback)(async e=>{q&&(await ei(q.range.start,q.range.end,e,q.selectedText),X(null))},[q,ei]),eE=(0,s.useCallback)(async e=>{if(J&&b&&r)try{let n=await (0,j.$3)(r),s=[];for(let e of n)s.push({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0});s.push({filePath:t,startLine:J.range.start,endLine:J.range.end,codeContent:J.lineSnapshot});let l=(0,j.Gw)(s,e);b.sendMessage(l),await (0,j.RP)(r),ed(),Z(null)}catch(e){console.error("Failed to send to AI:",e)}},[J,b,t,r,ed]),eL=(0,s.useCallback)((e,t,n)=>{let r=Y[e];if(!r)return t;let s=[];if($&&ex.length>0)for(let t of ex.filter(t=>t.lineIndex===e)){let n=ex[D]?.lineIndex===e&&ex[D]?.startCol===t.startCol;s.push({start:t.startCol,end:t.endCol,cls:n?"hl-cur":"hl-m"})}if(n&&!$&&n.length>=1){let e=n.toLowerCase(),t=r.toLowerCase(),l=0;for(;-1!==(l=t.indexOf(e,l));)s.push({start:l,end:l+n.length,cls:"hl-kw"}),l+=1}if(0===s.length)return t;s.sort((e,t)=>e.start-t.start||e.end-t.end);let l=[],a=0;for(let e of s){if(e.start<a)continue;e.start>a&&l.push((0,m.ZD)(r.substring(a,e.start)));let t=(0,m.ZD)(r.substring(e.start,e.end));l.push(`<span class="${e.cls}">${t}</span>`),a=e.end}if(a<r.length&&l.push((0,m.ZD)(r.substring(a))),t!==(0,m.ZD)(r)){let e=t;for(let t of s){let n=r.substring(t.start,t.end),s=(0,m.ZD)(n),l=s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),a=RegExp(`(?<=>)([^<]*?)(${l})`,""),o=`$1<span class="${t.cls}">${s}</span>`,i=e.replace(a,o);i.length>e.length+200||(e=i)}return e}return l.join("")},[$,ex,D,Y]);return{parentRef:x,containerRef:p,searchInputRef:g,floatingToolbarRef:et,suppressHoverRef:U,savedSelectionRef:K,highlightedLines:em,isMounted:h,cmdHeld:v,flashLine:E,isSearchVisible:R,searchQuery:$,caseSensitive:P,wholeWord:_,currentMatchIndex:D,viewingComment:W,bumpToolbarRef:en,addCommentInput:q,sendToAIInput:J,aiBridge:b,commentsEnabled:ee,comments:eo,updateComment:ec,deleteComment:eu,lines:Y,matches:ex,rowData:ep,virtualizer:eg,commentsByEndLine:eh,linesWithComments:ef,setIsSearchVisible:T,setSearchQuery:I,suppressMatchScrollRef:H,setCaseSensitive:A,setWholeWord:F,setViewingComment:z,setAddCommentInput:X,setSendToAIInput:Z,goToNextMatch:eb,goToPrevMatch:ev,handleSearchKeyDown:ew,handleCommentBubbleClick:ek,handleToolbarAddComment:ej,handleToolbarSendToAI:eC,handleToolbarSearch:eN,handleCommentSubmit:eS,handleSendToAISubmit:eE,getHighlightedLineHtml:eL,inlineBlameLineRef:es,inlineBlameVersion:el}}({content:e,filePath:t,showSearch:x,cwd:g,enableComments:!K&&v,scrollToLine:K?null:P,scrollToLineAlign:K?"center":A,onScrollToLineComplete:K?void 0:_,visibleLineRef:K?void 0:D,onContentSearch:el}),tu=(0,c.iN)(),td=(0,s.useRef)(null),tm=(0,s.useRef)(null),th=(0,s.useRef)({line:0,col:0}),tf=(0,s.useRef)({line:0,col:0}),tx=function({lines:e,enabled:t,onContentChange:n,onEnterInsert:r,onSave:l,getVisibleLineCount:a,scrollToLine:o,onSearchExecute:i,onSearchNext:c,onSearchPrev:u,onSearchClear:d}){let[m,h]=(0,s.useState)("normal"),[f,x]=(0,s.useState)(-1),[p,g]=(0,s.useState)(0),[b,v]=(0,s.useState)(!1),[y,w]=(0,s.useState)(""),[k,j]=(0,s.useState)(""),[C,N]=(0,s.useState)(""),[S,E]=(0,s.useState)(""),L=(0,s.useRef)([]),M=(0,s.useRef)([]),R=(0,s.useRef)([]),T=(0,s.useRef)(null),$=(0,s.useRef)(e);(0,s.useEffect)(()=>{$.current=e}),(0,s.useEffect)(()=>{0!==e.length&&queueMicrotask(()=>x(t=>Math.min(t,e.length-1)))},[e.length]);let I=(0,s.useCallback)((e,t)=>Math.max(0,Math.min(t,Math.max(0,($.current[e]??"").length-1))),[]),P=(0,s.useRef)(e.length);(0,s.useEffect)(()=>{let t=Math.abs(e.length-P.current);P.current=e.length,t>10&&(queueMicrotask(()=>{x(-1),g(0),v(!1)}),L.current=[],M.current=[],R.current=[])},[e]);let A=(0,s.useCallback)(()=>{T.current&&(clearTimeout(T.current),T.current=null),w("")},[]),_=(0,s.useCallback)(()=>{T.current&&clearTimeout(T.current),T.current=setTimeout(()=>{w(""),T.current=null},500)},[]),F=(0,s.useCallback)((e,t)=>{L.current.push(t),M.current=[],v(!0),n(e.join("\n"))},[n]),D=(0,s.useCallback)((e,t)=>{let n=Math.max(0,Math.min(e,$.current.length-1));x(n),g(I(n,t??0)),o(n,"auto")},[o,I]),O=(0,s.useCallback)(e=>{x(t=>{let n=Math.max(0,Math.min(t+e,$.current.length-1));return o(n,"auto"),g(e=>Math.max(0,Math.min(e,Math.max(0,($.current[n]??"").length-1)))),n})},[o]),V=(0,s.useCallback)(()=>{let e=$.current,t=Math.min(f,e.length-1);if(0===e.length)return;let n=e[t];R.current=[n];let r=[...e];r.splice(t,1),0===r.length&&r.push("");let s=Math.min(t,r.length-1);F(r,{lineIndex:t,oldLines:[n],newLines:[],cursorLine:t}),x(s),g(0)},[f,F]),B=(0,s.useCallback)(()=>{let e=$.current,t=Math.min(f,e.length-1);e.length>0&&(R.current=[e[t]])},[f]),H=(0,s.useCallback)(()=>{let e=R.current;if(0===e.length)return;let t=$.current,n=Math.min(f,t.length-1)+1,r=[...t];r.splice(n,0,...e),F(r,{lineIndex:n,oldLines:[],newLines:[...e],cursorLine:f}),x(n),g(0),o(n,"auto")},[f,F,o]),W=(0,s.useCallback)(()=>{let e=$.current,t=Math.min(f,e.length-1),n=e[t];if(!n||0===n.length)return;let r=n.substring(1),s=[...e];s[t]=r,F(s,{lineIndex:t,oldLines:[n],newLines:[r],cursorLine:f})},[f,F]),z=(0,s.useCallback)(()=>{let e=L.current;if(0===e.length)return;let t=e.pop(),r=[...$.current];0===t.newLines.length&&t.oldLines.length>0?r.splice(t.lineIndex,0,...t.oldLines):0===t.oldLines.length&&t.newLines.length>0?(r.splice(t.lineIndex,t.newLines.length),0===r.length&&r.push("")):r.splice(t.lineIndex,t.newLines.length,...t.oldLines),M.current.push(t),n(r.join("\n")),x(Math.min(t.cursorLine,r.length-1)),o(Math.min(t.cursorLine,r.length-1),"auto"),0===e.length&&v(!1)},[n,o]),U=(0,s.useCallback)(()=>{let e=M.current;if(0===e.length)return;let t=e.pop(),r=[...$.current];0===t.newLines.length&&t.oldLines.length>0?(r.splice(t.lineIndex,t.oldLines.length),0===r.length&&r.push("")):0===t.oldLines.length&&t.newLines.length>0?r.splice(t.lineIndex,0,...t.newLines):r.splice(t.lineIndex,t.oldLines.length,...t.newLines),L.current.push(t),v(!0),n(r.join("\n"));let s=t.lineIndex+Math.max(0,t.newLines.length-1);x(Math.min(s,r.length-1)),o(Math.min(s,r.length-1),"auto")},[n,o]),K=(0,s.useCallback)(e=>{let t=$.current,n=Math.min(f,t.length-1);if("o"===e||"O"===e){let r="o"===e?n+1:n,s=[...t];s.splice(r,0,""),F(s,{lineIndex:r,oldLines:[],newLines:[""],cursorLine:f}),n=r,x(r)}h("insert"),r(n,p,e)},[f,p,F,r]),q=(0,s.useCallback)(()=>{h("normal"),A()},[A]),X=(0,s.useCallback)(()=>{h("command"),j("")},[]),J=(0,s.useCallback)(()=>{h("normal"),j("")},[]),Z=(0,s.useCallback)(()=>{h("search"),N("")},[]),Y=(0,s.useCallback)(()=>{h("normal"),N("")},[]),Q=(0,s.useCallback)(e=>{let t=e.trim();if("w"===t){l?.(),h("normal"),j("");return}if("q"===t){h("normal"),j("");return}if("wq"===t){l?.(),h("normal"),j("");return}if("noh"===t||"nohlsearch"===t){d?.(),h("normal"),j("");return}let n=parseInt(t,10);if(!isNaN(n)&&n>0){let e=Math.min(n-1,$.current.length-1);x(e),o(e,"center"),h("normal"),j("");return}h("normal"),j("")},[l,d,o]),G=(0,s.useCallback)(e=>{if(!e){h("normal"),N("");return}E(e),i?.(e),h("normal"),N("")},[i]),ee=(0,s.useCallback)(e=>{if(!t)return!1;let n=e.ctrlKey&&"c"===e.key&&!e.metaKey&&!e.shiftKey;if("insert"===m)return("Escape"===e.key||!!n)&&(q(),!0);if("command"===m)return!e.isComposing&&("Escape"===e.key||n?J():"Enter"===e.key?Q(k):"Backspace"===e.key?0===k.length?J():j(e=>e.slice(0,-1)):1!==e.key.length||e.metaKey||e.ctrlKey||j(t=>t+e.key),!0);if("search"===m)return!e.isComposing&&("Escape"===e.key||n?Y():"Enter"===e.key?G(C):"Backspace"===e.key?0===C.length?Y():N(e=>e.slice(0,-1)):1!==e.key.length||e.metaKey||e.ctrlKey||N(t=>t+e.key),!0);if(f<0&&(x(0),g(0)),e.metaKey)return!1;if(e.ctrlKey)return"d"===e.key?(O(Math.max(1,Math.floor(a()/2))),A(),!0):"u"===e.key?(O(-Math.max(1,Math.floor(a()/2))),A(),!0):"r"===e.key&&(U(),A(),!0);let r=e.key,s=y+r;if("g"===s)return w("g"),_(),!0;if("gg"===s)return D(0),A(),!0;if("d"===s)return w("d"),_(),!0;if("dd"===s)return V(),A(),!0;if("y"===s)return w("y"),_(),!0;if("yy"===s)return B(),A(),!0;if(y&&s!==r&&A(),"j"===r||"ArrowDown"===r)return O(1),!0;if("k"===r||"ArrowUp"===r)return O(-1),!0;if("h"===r||"ArrowLeft"===r)return g(e=>Math.max(0,e-1)),!0;if("l"===r||"ArrowRight"===r){let e=Math.max(0,($.current[f]??"").length-1);return g(t=>Math.min(e,t+1)),!0}if("0"===r)return g(0),!0;if("$"===r)return g(Math.max(0,($.current[f]??"").length-1)),!0;if("^"===r){let e=($.current[f]??"").search(/\S/);return g(e>=0?e:0),!0}return"G"===r?(D($.current.length-1),!0):"x"===r?(W(),!0):"p"===r?(H(),!0):"u"===r?(z(),!0):"i"===r||"a"===r||"I"===r||"A"===r||"o"===r||"O"===r?(K(r),!0):"/"===r?(Z(),!0):"n"===r?(c?.(),!0):"N"===r?(u?.(),!0):":"===r?(X(),!0):"Escape"!==r&&1===r.length},[t,m,y,k,C,f,q,K,X,J,Z,Y,Q,G,O,D,a,V,B,H,W,z,U,A,_,c,u]);return{state:{mode:m,cursorLine:f,cursorCol:p,isDirty:b,keyBuffer:y,commandInput:k,searchInput:C,lastSearch:S},handleKeyDown:ee,enterNormal:q,enterInsert:K,setCursorLine:x,setCursorCol:g,setCommandInput:j,setSearchInput:N,setIsDirty:v,clearUndoHistory:(0,s.useCallback)(()=>{L.current=[],M.current=[]},[])}}({lines:eX,enabled:Y&&!K,onContentChange:e=>{th.current={line:tf.current.line,col:tf.current.col},Q?.(e)},onEnterInsert:(e,t,n)=>{let r=t;if("a"===n)r=t+1;else if("A"===n)r=(eX[e]??"").length;else if("I"===n){let t=(eX[e]??"").search(/\S/);r=t>=0?t:0}else("o"===n||"O"===n)&&(r=0);th.current={line:e,col:r},G?.(e)},onSave:ee,getVisibleLineCount:()=>{let e=eN.current;return e?Math.floor(e.clientHeight/20):20},scrollToLine:(e,t)=>{let n=eZ.findIndex(t=>"code"===t.type&&t.lineIndex===e);n>=0&&eY.scrollToIndex(n,{align:t||"auto"})},onSearchExecute:e=>{e1(e),e0(!1)},onSearchNext:e6,onSearchPrev:e9,onSearchClear:()=>{e1("")}});(0,s.useEffect)(()=>{et&&(et.current={cursorLine:tx.state.cursorLine,cursorCol:tx.state.cursorCol}),tf.current={line:tx.state.cursorLine,col:tx.state.cursorCol}},[et,tx.state.cursorLine,tx.state.cursorCol]);let tp=(0,s.useRef)(null);(0,s.useEffect)(()=>{Y&&!K&&null!=en&&t&&tp.current!==t&&(tp.current=t,tx.setCursorLine(en-1),null!=er&&tx.setCursorCol(er-1),es?.())},[Y,K,en,er,t]),(0,s.useEffect)(()=>{if(!Y||K)return;let e=eS.current;if(!e)return;let t=e=>{let t=e.target;"TEXTAREA"===t.tagName||"INPUT"===t.tagName||t.isContentEditable||tx.handleKeyDown(e)&&(e.preventDefault(),e.stopPropagation())};return e.addEventListener("keydown",t,!0),()=>e.removeEventListener("keydown",t,!0)},[Y,K,tx.handleKeyDown]),(0,s.useEffect)(()=>{if(!Y||K)return;let e=eS.current;e&&"normal"===tx.state.mode&&requestAnimationFrame(()=>{let t=document.activeElement;t&&("TEXTAREA"===t.tagName||"INPUT"===t.tagName||t.isContentEditable)||e.focus()})},[Y,K,tx.state.mode,e]);let tg=(0,s.useCallback)(e=>{if(!Y||K)return;let t=e.target.closest("[data-line]");if(t){let n=parseInt(t.getAttribute("data-line"),10);if(!isNaN(n)){tx.setCursorLine(n-1);let r=t.querySelector("[data-code-content]");if(r){let t=document.caretRangeFromPoint(e.clientX,e.clientY);if(t&&r.contains(t.startContainer)){let e,s=document.createTreeWalker(r,NodeFilter.SHOW_TEXT),l=0;for(;e=s.nextNode();){if(e===t.startContainer){l+=t.startOffset;break}l+=e.textContent?.length||0}let a=eX[n-1]??"";tx.setCursorCol(Math.max(0,Math.min(l,Math.max(0,a.length-1))))}}}}let n=e.target;if("TEXTAREA"===n.tagName||"INPUT"===n.tagName||n.isContentEditable)return;let r=eS.current;r&&r.focus()},[Y,K,tx.setCursorLine,tx.setCursorCol,eX]),tb=(0,s.useCallback)(e=>{Y&&!K&&requestAnimationFrame(()=>{let e=window.getSelection(),t=e?.toString().trim();t&&/^\S+$/.test(t)&&(to.current=!0,e1(t))})},[Y,K,e1,to]);(0,s.useEffect)(()=>{"command"===tx.state.mode?setTimeout(()=>td.current?.focus(),0):"search"===tx.state.mode&&setTimeout(()=>tm.current?.focus(),0)},[tx.state.mode]),(0,s.useEffect)(()=>{let e=eN.current;if(!e)return;let t=()=>{(H??B)?.()};return e.addEventListener("mousedown",t),()=>e.removeEventListener("mousedown",t)},[H,B]),(0,s.useEffect)(()=>{eH||eW?(eM.current=!0,B?.()):eL.current||(eM.current=!1)},[eH,eW,B]),(0,s.useLayoutEffect)(()=>{let e=eT.current;if(!e)return;let t=window.getSelection();if(t&&!t.isCollapsed)return;let n=eN.current;if(!n)return;let r=n.querySelector(`[data-line="${e.startLine}"]`),s=n.querySelector(`[data-line="${e.endLine}"]`);if(!r||!s)return;let l=E(r,e.startOffset),a=E(s,e.endOffset);if(l&&a)try{let e=document.createRange();e.setStart(l.node,l.offset),e.setEnd(a.node,a.offset),t?.removeAllRanges(),t?.addRange(e)}catch{}});let tv=(0,s.useCallback)((e,t,n)=>{eM.current||V?.(e,t,n)},[V]),ty=(0,s.useCallback)((e,t)=>{eM.current||O?.(e,t)},[O]),tw=Math.max(4,String(K?ef:eX.length).length),tk=(0,s.useMemo)(()=>{let e=0;for(let t of eX){let n=0;for(let e=0;e<t.length;e++)" "===t[e]?n+=2-n%2:n+=1;n>e&&(e=n)}return e},[eX]);(0,s.useEffect)(()=>{if(K){ei.current=e;let t=e.split("\n").length;ep.current=t,ex(t),ec.current=!1,ed(!1),eb({show:!1}),ew.current=q}},[K,e,q]),(0,s.useEffect)(()=>{if(!K)return;let t=ev.current;if(!t)return;let n=e.split("\n");t.innerHTML=I(n.map((e,t)=>e$[t]||(0,m.ZD)(e||" "))),requestAnimationFrame(()=>{let e,r;Y?(e=Math.max(0,Math.min(th.current.line,n.length-1)),r=th.current.col):(e=Math.max(0,Math.min((D?.current??1)-1,n.length-1)),r=0),t.focus(),$(t,{line:e,offset:r});let s=D?.current??1;ey.current&&(ey.current.scrollTop=(s-1)*20)})},[K]),(0,s.useEffect)(()=>{K&&Z?.({isDirty:eu,isSaving:em})},[K,eu,em,Z]);let tj=(0,s.useCallback)(()=>{let e=ev.current;if(!e)return ei.current;let t=[];for(let n of e.childNodes){let e=n.textContent||"";t.push(" "===e?"":e)}return t.join("\n")},[]),tC=(0,s.useCallback)(()=>{ek.current&&clearTimeout(ek.current),ek.current=setTimeout(async()=>{let e=ev.current;if(e&&!eC.current){ei.current=tj();try{let n=await (0,m.kS)(),r=(0,m.sQ)(t),s=document.documentElement.classList.contains("dark"),l=ei.current.split("\n"),a=n.codeToTokens(l.join("\n"),{lang:r,theme:s?"github-dark":"github-light"}).tokens.map(e=>(0,m.b8)(e)),o=T(e);ej.current=!0,e.innerHTML=I(a),ej.current=!1,o&&$(e,o)}catch{}}},300)},[t,tj]);(0,s.useEffect)(()=>{if(K)return()=>{ek.current&&clearTimeout(ek.current)}},[K]);let tN=(0,s.useCallback)(()=>{let e=ev.current;if(!e)return;ec.current||(ec.current=!0,ed(!0));let t=e.children.length;t!==ep.current&&(ep.current=t,ex(t))},[]),tS=(0,s.useCallback)(()=>{ej.current||eC.current||(tN(),tC())},[tN,tC]),tE=(0,s.useCallback)(e=>{if(!e.nativeEvent.isComposing&&("Tab"===e.key&&(e.preventDefault(),document.execCommand("insertText",!1," ")),"Enter"===e.key)){e.preventDefault();let t=ev.current;if(!t)return;let n=window.getSelection();if(!n?.rangeCount)return;let r=n.getRangeAt(0);r.deleteContents();let s=r.startContainer;for(;s&&s.parentElement!==t;)s=s.parentElement;if(!s||!(s instanceof HTMLElement))return;let l=T(t),a=Array.from(t.children).indexOf(s),o=s.textContent||"",i=l?.offset??o.length,c=o.substring(0,i),u=o.substring(i);s.innerHTML=(0,m.ZD)(c||" ");let d=document.createElement("div");d.setAttribute("style",R),d.innerHTML=(0,m.ZD)(u||" "),s.after(d),$(t,{line:a+1,offset:0}),tN(),tC()}},[tN,tC]),tL=(0,s.useCallback)(e=>{e.preventDefault();let t=e.clipboardData.getData("text/plain");document.execCommand("insertText",!1,t)},[]),tM=(0,s.useCallback)(async(e=!1)=>{if(!g)return;ei.current=tj(),eh(!0);let n=await o.t4.runPromiseExit((0,i.OJ)({cwd:g,path:t,content:ei.current,expectedMtime:e?void 0:ew.current}));if("Failure"===n._tag){console.error("Error saving file:",n.cause),(0,M.oR)(eo("toast.saveFailed"),"error"),eh(!1);return}let r=n.value,s=r.data;if(409===r.status&&s?.conflict){let e=await o.t4.runPromiseExit((0,i.K9)(g,t));"Success"===e._tag&&e.value.ok&&"string"==typeof e.value.data?.content?eb({show:!0,diskContent:e.value.data.content}):eb({show:!0}),eh(!1);return}if(!r.ok){console.error("Error saving file: status",r.status),(0,M.oR)(eo("toast.saveFailed"),"error"),eh(!1);return}let l=s?.mtime;l&&(ew.current=l),ec.current=!1,ed(!1),eb({show:!1}),(0,M.oR)(eo("toast.savedSuccess"),"success"),J?.(),eh(!1)},[g,t,tj,J,eo]),tR=(0,s.useCallback)(async()=>{eu&&!em&&await tM(!1)},[eu,em,tM]),tT=(0,s.useCallback)(async()=>{eb({show:!1}),await tM(!0)},[tM]),t$=(0,s.useCallback)(()=>{if(void 0!==eg.diskContent){ei.current=eg.diskContent;let t=eg.diskContent.split("\n").length;ep.current=t,ex(t);let n=eg.diskContent!==e;ec.current=n,ed(n);let r=ev.current;r&&(r.innerHTML=I(eg.diskContent.split("\n").map(e=>(0,m.ZD)(e||" "))),tC())}eb({show:!1}),J?.()},[eg.diskContent,e,J,tC]),tI=(0,s.useCallback)(()=>{let e=ey.current;return e?Math.floor(e.scrollTop/20)+1:D?.current??1},[D]),tP=(0,s.useCallback)(async()=>{(!eu||await (0,M.lJ)(eo("codeViewer.unsavedConfirm"),{danger:!0,confirmText:eo("codeViewer.discardChanges"),cancelText:eo("codeViewer.continueEditing")}))&&X?.(tI())},[eu,X,tI]);(0,s.useEffect)(()=>{if(!K)return;let e=e=>{(e.metaKey||e.ctrlKey)&&"s"===e.key&&(e.preventDefault(),tR())};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[K,tR]);let tA=(0,s.useCallback)(()=>{let e=tj();Q?.(e);let t=ev.current,n=t?T(t):null,r=tI();if(tx.enterNormal(),n){tx.setCursorLine(n.line);let t=e.split("\n")[n.line]??"";tx.setCursorCol(Math.max(0,Math.min(n.offset,Math.max(0,t.length-1))))}else tx.setCursorLine(Math.max(0,r-1));X?.(r)},[tj,Q,tI,X,tx]);(0,s.useEffect)(()=>{if(!K)return;let e=e=>{let t="Escape"===e.key,n=e.ctrlKey&&"c"===e.key&&!e.metaKey&&!e.shiftKey;(t||Y&&n)&&(e.preventDefault(),e.stopPropagation(),Y?ec.current?(0,M.lJ)(eo("codeViewer.unsavedExitConfirm"),{danger:!0,confirmText:eo("codeViewer.discardChanges"),cancelText:eo("codeViewer.continueEditing")}).then(e=>{e&&tA()}):tA():tP())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[K,Y,tP,tA]);let t_=(0,s.useCallback)(()=>{ec.current||(ec.current=!0,ed(!0))},[]);(0,s.useImperativeHandle)(ea,()=>({save:tR,close:tP,markDirty:t_,get isDirty(){return ec.current},get isSaving(){return em}}),[tR,tP,t_,em]);let tF=!!(W&&W.length>0),tD=(0,s.useMemo)(()=>{if(!W)return new Map;let e=[...new Set(W.map(e=>e.author))],t=new Map;return e.forEach((e,n)=>{t.set(e,b[n%b.length])}),t},[W]),[tO,tV]=(0,s.useState)(null),[tB,tH]=(0,s.useState)(null);(0,s.useEffect)(()=>{tV(null),tH(null)},[W]);let tW=(0,s.useCallback)((e,t)=>{tV(e.author);let n=t.currentTarget.getBoundingClientRect();tH({line:e,x:n.right+8,y:n.top})},[]),tz=(0,s.useCallback)(()=>{tV(null),tH(null)},[]),tU=(0,s.useCallback)(e=>{U&&(U({hash:e.hashFull,shortHash:e.hash,author:e.author,authorEmail:e.authorEmail,date:new Date(1e3*e.time).toISOString(),subject:e.message.split("\n")[0]||"",body:e.message.split("\n").slice(1).join("\n").trim(),time:e.time}),tH(null))},[U]),tK=`${tw+2}ch`;return(0,r.jsxs)("div",{ref:eS,className:`h-full flex flex-col outline-none ${p}`,tabIndex:0,onClick:tg,onDoubleClick:tb,children:[K&&eg.show&&(0,r.jsxs)("div",{className:"px-4 py-2 bg-amber-500/15 border-b border-amber-500/30 flex items-center gap-3 flex-shrink-0",children:[(0,r.jsx)("svg",{className:"w-5 h-5 text-amber-500 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L4.082 16.5c-.77.833.192 2.5 1.732 2.5z"})}),(0,r.jsx)("span",{className:"text-sm text-foreground flex-1",children:eo("codeViewer.fileModifiedExternally")}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("button",{onClick:t$,className:"px-3 py-1 text-sm rounded border border-border hover:bg-accent transition-colors",children:eo("codeViewer.useDiskVersion")}),(0,r.jsx)("button",{onClick:tT,className:"px-3 py-1 text-sm rounded bg-amber-500 text-white hover:bg-amber-600 transition-colors",children:eo("codeViewer.forceOverwrite")})]})]}),!K&&x&&e_&&(0,r.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-2 px-3 py-2 bg-secondary border-b border-border",children:[(0,r.jsx)("input",{ref:eE,type:"text",value:eF,onChange:e=>e1(e.target.value),onKeyDown:e7,placeholder:eo("codeViewer.searchPlaceholder"),className:"flex-1 max-w-xs px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),(0,r.jsx)("button",{onClick:()=>e2(!eD),className:`px-2 py-1 text-xs font-mono rounded border transition-colors ${eD?"bg-brand text-white border-brand":"border-border text-muted-foreground hover:bg-accent"}`,title:eo("codeViewer.caseSensitive"),children:"Aa"}),(0,r.jsx)("button",{onClick:()=>e5(!eO),className:`px-2 py-1 text-xs font-mono rounded border transition-colors ${eO?"bg-brand text-white border-brand":"border-border text-muted-foreground hover:bg-accent"}`,title:eo("codeViewer.wholeWordMatch"),children:"[ab]"}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:eJ.length>0?`${eV+1}/${eJ.length}`:eo("common.noMatch")}),(0,r.jsx)("button",{onClick:e9,disabled:0===eJ.length,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:eo("common.previous"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"})})}),(0,r.jsx)("button",{onClick:e6,disabled:0===eJ.length,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:eo("common.next"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})}),(0,r.jsx)("button",{onClick:()=>{e0(!1),e1("")},className:"p-1 rounded hover:bg-accent",title:eo("common.close"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),K?(0,r.jsx)("div",{ref:ey,className:"flex-1 overflow-auto bg-secondary",children:(0,r.jsxs)("div",{className:"flex",style:{minHeight:"100%"},children:[(0,r.jsx)("div",{className:"flex-shrink-0 font-mono text-sm select-none sticky left-0 z-[2] bg-secondary",style:{width:tK},children:Array.from({length:ef},(e,t)=>(0,r.jsx)("div",{className:"text-right text-muted-foreground/50 pr-3",style:{height:20,lineHeight:"20px"},children:t+1},t))}),(0,r.jsx)("div",{ref:ev,contentEditable:!0,suppressContentEditableWarning:!0,onInput:tS,onKeyDown:tE,onPaste:tL,onCompositionStart:()=>{eC.current=!0},onCompositionEnd:()=>{eC.current=!1,tS()},spellCheck:!1,autoCorrect:"off",autoCapitalize:"off",className:"flex-1 font-mono text-sm outline-none",style:{caretColor:"var(--foreground)",tabSize:2}})]})}):(0,r.jsx)("div",{ref:eN,className:`flex-1 overflow-auto font-mono text-sm bg-secondary${eP?" cmd-held-container":""}`,children:(0,r.jsx)("div",{style:{height:`${eY.getTotalSize()}px`,minWidth:"100%",width:tF?`calc(${tw+tk+10}ch + 13rem)`:`${tw+tk+10}ch`,position:"relative"},children:eY.getVirtualItems().map(e=>{let t=eZ[e.index];if("code"!==t.type)return null;let s=t.lineIndex,l=s+1,a=e$[s]||(0,m.ZD)(eX[s]||""),o=ta(s,a,F),i=eG.has(l),c=eQ.get(l),u=c?.[0],d=!!(eH&&l>=eH.range.start&&l<=eH.range.end),h=tc>=0?ti.current:null,f=!K&&z&&h===l?z[s]??null:null,x=tF?W[s]:void 0,p=tF&&s>0?W[s-1]:void 0,g=!!x&&(!p||p.hash!==x.hash),b=x?tD.get(x.author):void 0;return(0,r.jsx)(y,{virtualKey:e.key,lineNum:l,highlightedHtml:o,hasComments:i,firstComment:u,lineCommentsCount:c?.length,isInRange:d,showLineNumbers:n,lineNumChars:tw,commentsEnabled:eU,virtualItemSize:e.size,virtualItemStart:e.start,onCommentBubbleClick:te,onCmdClick:ty,onTokenHover:tv,onTokenHoverLeave:B,flashLine:eA,blameLine:x,showBlameInfo:g,blameAuthorColor:b,isBlameHovered:!!(x&&tO===x.author),onBlameClick:tU,onBlameMouseEnter:tW,onBlameMouseLeave:tz,inlineBlameData:f,onInlineBlameClick:tU,isCursorLine:Y&&!K&&tx.state.cursorLine===s,cursorCol:Y&&!K&&tx.state.cursorLine===s?tx.state.cursorCol:void 0},e.key)})})}),Y&&(0,r.jsxs)("div",{className:"vi-status-bar flex-shrink-0 h-6 bg-card border-t border-border flex items-center px-3 text-xs font-mono select-none",children:["normal"===tx.state.mode&&(0,r.jsx)("span",{className:"text-green-11 font-medium",children:"NORMAL"}),"insert"===tx.state.mode&&(0,r.jsx)("span",{className:"text-blue-11 font-medium",children:"INSERT"}),"command"===tx.state.mode&&(0,r.jsxs)("div",{className:"flex items-center flex-1",children:[(0,r.jsx)("span",{className:"text-foreground",children:":"}),(0,r.jsx)("input",{ref:td,value:tx.state.commandInput,onChange:e=>tx.setCommandInput(e.target.value),onKeyDown:e=>{if(e.nativeEvent.isComposing)return;let t=e.ctrlKey&&"c"===e.key&&!e.metaKey&&!e.shiftKey;("Enter"===e.key||"Escape"===e.key||t)&&(e.preventDefault(),e.stopPropagation(),tx.handleKeyDown(e.nativeEvent))},className:"flex-1 bg-transparent outline-none text-foreground ml-0.5",spellCheck:!1,autoComplete:"off"})]}),"search"===tx.state.mode&&(0,r.jsxs)("div",{className:"flex items-center flex-1",children:[(0,r.jsx)("span",{className:"text-foreground",children:"/"}),(0,r.jsx)("input",{ref:tm,value:tx.state.searchInput,onChange:e=>tx.setSearchInput(e.target.value),onKeyDown:e=>{if(e.nativeEvent.isComposing)return;let t=e.ctrlKey&&"c"===e.key&&!e.metaKey&&!e.shiftKey;("Enter"===e.key||"Escape"===e.key||t)&&(e.preventDefault(),e.stopPropagation(),tx.handleKeyDown(e.nativeEvent))},className:"flex-1 bg-transparent outline-none text-foreground ml-0.5",spellCheck:!1,autoComplete:"off"})]}),tx.state.keyBuffer&&"normal"===tx.state.mode&&(0,r.jsx)("span",{className:"ml-2 text-muted-foreground",children:tx.state.keyBuffer}),tx.state.isDirty&&("normal"===tx.state.mode||"command"===tx.state.mode)&&(0,r.jsx)("span",{className:"ml-2 text-amber-11",children:"[+]"}),(0,r.jsxs)("span",{className:"ml-auto text-muted-foreground",children:[tx.state.cursorLine+1,":",tx.state.cursorCol+1]})]}),eI&&tu&&(0,a.createPortal)((0,r.jsxs)(r.Fragment,{children:[!K&&(0,r.jsx)(h.f,{floatingToolbarRef:eL,bumpRef:eR,container:tu,onAddComment:tt,onSendToAI:tn,onSearch:el?tr:void 0,isChatLoading:ez?.isLoading}),!K&&eH&&(0,r.jsx)(u.t,{x:eH.x,y:eH.y,range:eH.range,lineSnapshot:eH.lineSnapshot,container:tu,onSubmit:ts,onClose:()=>e3(null)}),!K&&eW&&(0,r.jsx)(u.G,{x:eW.x,y:eW.y,range:eW.range,filePath:t,lineSnapshot:eW.lineSnapshot,container:tu,onSubmit:tl,onClose:()=>e8(null),isChatLoading:ez?.isLoading}),!K&&eB&&(0,r.jsx)(f.t,{x:eB.x,y:eB.y,comment:eB.comment,container:tu,onClose:()=>e4(null),onUpdateComment:eK,onDeleteComment:eq}),tB&&(0,r.jsxs)("div",{className:"fixed z-50 bg-card border border-border rounded-lg shadow-lg p-3 max-w-lg",style:{left:Math.min(tB.x,window.innerWidth-450),top:Math.max(8,Math.min(tB.y,window.innerHeight-200))},children:[(0,r.jsxs)("div",{className:"flex items-start gap-3",children:[(0,r.jsx)("div",{className:"px-2 py-0.5 rounded text-xs font-mono font-medium text-white flex-shrink-0",style:{backgroundColor:tD.get(tB.line.author)?.border||"#666"},children:tB.line.hash}),(0,r.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,r.jsx)("div",{className:"text-sm font-medium text-foreground",children:tB.line.author}),(0,r.jsx)("div",{className:"text-xs text-muted-foreground",children:tB.line.authorEmail})]})]}),(0,r.jsx)("div",{className:"mt-2 text-sm text-foreground whitespace-pre-wrap max-h-48 overflow-y-auto",children:tB.line.message}),(0,r.jsxs)("div",{className:"mt-2 text-xs text-muted-foreground border-t border-border pt-2",children:[(0,L.fw)(tB.line.time)," \xb7 ",new Date(1e3*tB.line.time).toLocaleString(),(0,r.jsx)("span",{className:"ml-2 text-brand",children:eo("codeViewer.clickToViewDetails")})]})]})]}),tu)]})});function A({content:e,filePath:t,className:n=""}){let l=(0,s.useMemo)(()=>e.split("\n"),[e]),a=(0,d.C)(l,t),o=Math.max(4,String(l.length).length);return(0,r.jsx)("pre",{className:`overflow-auto text-sm font-mono bg-secondary p-2 ${n}`,children:l.map((e,t)=>(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"text-slate-9 select-none pr-4 text-right",style:{minWidth:`${o+2}ch`},children:t+1}),(0,r.jsx)("span",{className:"flex-1",dangerouslySetInnerHTML:{__html:a[t]||(0,m.ZD)(e||" ")}})]},t))})}},46456:(e,t,n)=>{n.d(t,{$:()=>i,BC:()=>c,Tu:()=>d,lb:()=>o,tj:()=>m,vv:()=>u});var r=n(49433),s=n(82680);let l=(e,t)=>r.tryPromise({try:async()=>{let n=await fetch(e,t);if(!n.ok)throw Error(`HTTP ${n.status}`);return await n.json()},catch:n=>new s.uV({message:`${t?.method??"GET"} ${e} failed`,cause:n})}),a=(e,t)=>r.tryPromise({try:async()=>{let n=await fetch(e,t);if(!n.ok)throw Error(`HTTP ${n.status}`)},catch:n=>new s.uV({message:`${t.method} ${e} failed`,cause:n})}),o=(e,t)=>l(`/api/comments?cwd=${encodeURIComponent(e)}${t?`&filePath=${encodeURIComponent(t)}`:""}`),i=e=>l(`/api/comments?cwd=${encodeURIComponent(e)}&all=true`),c=e=>l("/api/comments",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),u=(e,t,n)=>l("/api/comments",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,id:t,content:n})}),d=(e,t)=>a(`/api/comments?cwd=${encodeURIComponent(e)}&id=${encodeURIComponent(t)}`,{method:"DELETE"}),m=e=>a(`/api/comments?cwd=${encodeURIComponent(e)}&all=true`,{method:"DELETE"})},47215:(e,t,n)=>{n.d(t,{C6:()=>a,WU:()=>v,e$:()=>b,jU:()=>l,oK:()=>y,u:()=>g,xb:()=>o,zs:()=>x});var r=n(12115),s=n(69809);function l(e){try{return JSON.parse(e),!0}catch{return!1}}function a(e){try{let t=JSON.parse(e);return JSON.stringify(t,null,2)}catch{return e}}function o(e){try{let t=JSON.parse(e);return f(t,0)}catch{return e}}let i="#79c0ff",c="#a5d6ff",u="#ff7b72",d="#8b949e",m=(e,t)=>r.createElement("span",{style:{color:e}},t);function h({label:e,labelColor:t,value:n,indent:l}){let[a,o]=r.useState(!1),[i,u]=r.useState({x:0,y:0}),x="string"==typeof n&&n.replace(/\\n/g,"\n").split("\n").length>3,p={onMouseDown:e=>{u({x:e.clientX,y:e.clientY})},onClick:e=>{let t=e.clientX-i.x,n=e.clientY-i.y;t*t+n*n>25||(e.stopPropagation(),o(e=>!e))},style:{cursor:"pointer"}};if(x&&a&&"string"==typeof n){let l=n.replace(/\\n/g,"\n").split("\n")[0],a=n.replace(/\\n/g,"\n").split("\n").length;return r.createElement("span",p,m(t,e),m(d,": "),m(c,l),m("#6e7681",` ${s.A.t("toolCall.foldedLines",{count:a})}`))}let g=r.createElement(r.Fragment,null,m(t,e),m(d,": "),f(n,l));return x?r.createElement("span",p,g):g}function f(e,t){let n=" ".repeat(t);if(null===e)return m(u,"null");if(void 0===e)return m(u,"undefined");if("string"==typeof e)return m(c,e.replace(/\\n/g,"\n").replace(/\n/g,"\n"+n));if("number"==typeof e)return m("#79c0ff",String(e));if("boolean"==typeof e)return m(u,String(e));if(Array.isArray(e))return 0===e.length?m(d,"[]"):r.createElement(r.Fragment,null,m(d,"["),"\n",...e.map((s,l)=>r.createElement("span",{key:l},n+" ",r.createElement(h,{label:`[${l}]`,labelColor:i,value:s,indent:t+1}),l<e.length-1?r.createElement(r.Fragment,null,m(d,","),"\n"):"\n")),n,m(d,"]"));if("object"==typeof e){let s=Object.entries(e);return 0===s.length?m(d,"{}"):r.createElement(r.Fragment,null,m(d,"{"),"\n",...s.map(([e,l],a)=>r.createElement("span",{key:e},n+" ",r.createElement(h,{label:e,labelColor:i,value:l,indent:t+1}),a<s.length-1?r.createElement(r.Fragment,null,m(d,","),"\n"):"\n")),n,m(d,"}"))}return String(e)}function x(e){try{let t=JSON.parse(e);if(t&&"string"==typeof t.file_path&&"string"==typeof t.old_string&&"string"==typeof t.new_string)return t}catch{}return null}let p=new Set([".png",".jpg",".jpeg",".gif",".webp",".svg",".bmp",".ico",".avif"]);function g(e){let t=e.slice(e.lastIndexOf(".")).toLowerCase();return p.has(t)}function b(e){return e.toLowerCase().endsWith(".md")}function v(e,t){let n=t.startsWith("/")?[]:e.split("/").slice(0,-1);for(let e of t.replace(/^\//,"").split("/"))""!==e&&"."!==e&&(".."===e?n.pop():n.push(e));return n.join("/")}function y(e){try{let t=JSON.parse(e);if(t&&"string"==typeof t.file_path)return t.file_path}catch{let t=e.trim();if(t.startsWith("/")&&!t.includes("\n")&&t.length<500)return t}return null}},48347:(e,t,n)=>{n.d(t,{H:()=>a,r:()=>o});var r=n(95155),s=n(12115);let l=(0,s.createContext)(null);function a({value:e,children:t}){return(0,r.jsx)(l.Provider,{value:e,children:t})}function o(){return(0,s.useContext)(l)}},48948:(e,t,n)=>{n.d(t,{F:()=>r});function r(e,t,n){let{engine:r,assistantId:s}=n;if("stream_event"===t.type){let n=t.event;if(n?.type==="content_block_delta"&&n.delta?.type==="text_delta"&&n.delta.text){let t=n.delta.text;return e.map(e=>e.id===s?{...e,content:(e.content||"")+t}:e)}return e}if("assistant"===t.type){let n=t.message?.content;if(!Array.isArray(n))return e;let l=e,a=t.message?.model==="<synthetic>";if("codex"===r||"kimi"===r||"ollama"===r||a){let e=n.filter(e=>"text"===e.type&&e.text).map(e=>e.text).join("");e&&(l=l.map(t=>t.id===s?{...t,content:(t.content||"")+e}:t))}for(let e of n)if(e.name){let t={id:e.id||`tool-${s}-${e.name}`,name:e.name,input:e.input||{},isLoading:!0};l=l.map(e=>e.id!==s||e.toolCalls?.some(e=>e.id===t.id)?e:{...e,toolCalls:[...e.toolCalls||[],t]})}return l}if("user"===t.type){let n=t.message?.content;if(!Array.isArray(n))return e;let r=e;for(let e of n)if(e.tool_use_id){let t=e.tool_use_id,n="string"==typeof e.content?e.content:JSON.stringify(e.content);r=r.map(e=>e.id===s?{...e,toolCalls:e.toolCalls?.map(e=>e.id===t?{...e,result:n,isLoading:!1}:e)}:e)}return r}if("error"===t.type){let n=t.error||"An error occurred. Please try again.";return e.map(e=>e.id===s?{...e,content:e.content?`${e.content}
4
4
 
5
- ⚠️ ${n}`:`⚠️ ${n}`,isStreaming:!1}:e)}if("result"===t.type){let n="string"==typeof t.result?t.result.trim():"";return e.map(e=>e.id===s?{...e,content:!e.content&&n?n:e.content,isStreaming:!1,toolCalls:e.toolCalls?.map(e=>({...e,isLoading:!1}))}:e)}return e}},50860:(e,t,n)=>{n.d(t,{I:()=>o});var r=n(95155),s=n(12115),l=n(86957),a=n(60938);function o(e){let{refreshKey:t,className:n="h-full flex items-center justify-center p-4 bg-secondary",imgClassName:o="max-w-full max-h-full object-contain",alt:i}=e,c="absPath"in e&&"string"==typeof e.absPath,u=c?void 0:e.cwd,d=c?void 0:e.path,m=c?e.absPath:void 0,[h,f]=(0,s.useState)({kind:"loading"}),x=(0,s.useRef)(0);if((0,s.useEffect)(()=>{let e=++x.current;return f({kind:"loading"}),(async()=>{if(c){if(e!==x.current)return;f({kind:"ready",etag:null,size:0});return}let t=await l.t4.runPromiseExit((0,a.r6)(u,d));if(e!==x.current)return;if("Failure"===t._tag){let e="Fail"===t.cause._tag?t.cause.error:null,n=e?.cause;f({kind:"error",message:n instanceof Error?n.message:"Unknown error"});return}let n=t.value;if(!n.ok)return f({kind:"error",message:`stat failed (${n.status})`});let r=n.data;r&&r.exists?"too-large"===r.category?f({kind:"too-large",size:r.size??0}):"image"!==r.category?f({kind:"error",message:`Not an image (${r.category})`}):f({kind:"ready",etag:r.etag||`t-${r.mtimeMs??Date.now()}`,size:r.size??0}):f({kind:"missing"})})(),()=>{x.current++}},[c,u,d,m,t]),"loading"===h.kind)return(0,r.jsx)("div",{className:n,children:(0,r.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})});if("missing"===h.kind)return(0,r.jsx)("div",{className:n,children:(0,r.jsx)("div",{className:"text-sm text-muted-foreground",children:"File not found"})});if("too-large"===h.kind)return(0,r.jsx)("div",{className:n,children:(0,r.jsxs)("div",{className:"text-sm text-muted-foreground",children:["Image too large to preview (",Math.round(h.size/1024/1024)," MB)"]})});if("error"===h.kind)return(0,r.jsx)("div",{className:n,children:(0,r.jsx)("div",{className:"text-sm text-red-11",children:h.message})});let p=c?`/api/file?path=${encodeURIComponent(m)}&raw=true`:`/api/files/read?cwd=${encodeURIComponent(u)}&path=${encodeURIComponent(d)}&v=${encodeURIComponent(h.etag)}`;return(0,r.jsx)("div",{className:n,children:(0,r.jsx)("img",{src:p,alt:i??(d||m),className:o})})}},56045:(e,t,n)=>{n.d(t,{_:()=>o,o:()=>a});var r=n(12115),s=n(69809);let l="json-search-highlight-style";function a(e){let[t,n]=(0,r.useState)(!1),[s,a]=(0,r.useState)(""),[o,i]=(0,r.useState)(!1),[c,u]=(0,r.useState)(0),[d,m]=(0,r.useState)(0),h=(0,r.useRef)(null),f=(0,r.useRef)([]),x=(0,r.useCallback)(()=>{let t;CSS.highlights?.delete("json-search"),CSS.highlights?.delete("json-search-current"),f.current=[];let n=e.current;if(!n||!s){u(0),m(0);return}!function(){if(document.getElementById(l))return;let e=document.createElement("style");e.id=l,e.textContent="::highlight(json-search){background:rgba(217,119,6,.3)}::highlight(json-search-current){background:rgba(217,119,6,.5)}",document.head.appendChild(e)}();let r=n.textContent||"",a=o?s:s.toLowerCase(),i=o?r:r.toLowerCase(),c=[],d=0;for(;d<i.length;){let e=i.indexOf(a,d);if(-1===e)break;c.push([e,e+a.length]),d=e+1}if(0===c.length){u(0),m(0);return}let h=document.createTreeWalker(n,NodeFilter.SHOW_TEXT),x=0,p=0,g=[],b=null,v=0;for(;(t=h.nextNode())&&p<c.length;){let e=t.textContent?.length||0,n=x,r=x+e;for(;p<c.length;){let[e,s]=c[p];if(e>=r)break;if(!b)if(e>=n)(b=document.createRange()).setStart(t,e-n),v=s;else break;if(v<=r)b.setEnd(t,v-n),g.push(b),b=null,p++;else break}x=r}f.current=g,u(g.length),m(e=>g.length>0?Math.min(e,g.length-1):0),CSS.highlights&&g.length>0&&CSS.highlights.set("json-search",new Highlight(...g))},[e,s,o]),p=(0,r.useCallback)((e,t)=>{let n=e.getBoundingClientRect();(t.top<n.top||t.bottom>n.bottom)&&(e.scrollTop+=t.top-n.top-n.height/2+t.height/2)},[]),g=(0,r.useCallback)(t=>{CSS.highlights?.delete("json-search-current");let n=f.current[t];if(!n||!CSS.highlights)return;CSS.highlights.set("json-search-current",new Highlight(n));let r=n.getBoundingClientRect(),s=e.current?.parentElement;s&&p(s,r)},[e,p]);(0,r.useEffect)(()=>{queueMicrotask(()=>x())},[x]),(0,r.useEffect)(()=>{g(d)},[d,c,g]),(0,r.useEffect)(()=>{let t=e.current;if(!t||!s)return;let n=new MutationObserver(()=>x());return n.observe(t,{childList:!0,subtree:!0,characterData:!0}),()=>n.disconnect()},[e,s,x]),(0,r.useEffect)(()=>{t||(CSS.highlights?.delete("json-search"),CSS.highlights?.delete("json-search-current"),f.current=[])},[t]),(0,r.useEffect)(()=>()=>{CSS.highlights?.delete("json-search"),CSS.highlights?.delete("json-search-current")},[]);let b=(0,r.useCallback)(()=>{0!==c&&m(e=>(e+1)%c)},[c]),v=(0,r.useCallback)(()=>{0!==c&&m(e=>(e-1+c)%c)},[c]),y=(0,r.useCallback)(()=>{n(!0),setTimeout(()=>h.current?.focus(),0)},[]),w=(0,r.useCallback)(()=>{n(!1),a(""),m(0)},[]),k=(0,r.useCallback)(e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?v():b()),"Escape"===e.key&&(e.preventDefault(),w())},[b,v,w]);return{isVisible:t,query:s,setQuery:a,caseSensitive:o,setCaseSensitive:i,matchCount:c,currentIndex:d,searchInputRef:h,open:y,close:w,goToNext:b,goToPrev:v,handleKeyDown:k}}function o({search:e}){return e.isVisible?r.createElement("div",{className:"flex-shrink-0 flex items-center gap-2 px-3 py-2 bg-secondary border-b border-border"},r.createElement("input",{ref:e.searchInputRef,type:"text",value:e.query,onChange:t=>e.setQuery(t.target.value),onKeyDown:e.handleKeyDown,placeholder:s.A.t("codeViewer.searchPlaceholder"),className:"flex-1 max-w-xs px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),r.createElement("button",{onClick:()=>e.setCaseSensitive(e=>!e),className:`px-2 py-1 text-xs font-mono rounded border transition-colors ${e.caseSensitive?"bg-brand text-white border-brand":"border-border text-muted-foreground hover:bg-accent"}`,title:s.A.t("codeViewer.caseSensitive")},"Aa"),r.createElement("span",{className:"text-xs text-muted-foreground"},e.matchCount>0?`${e.currentIndex+1}/${e.matchCount}`:s.A.t("common.noMatch")),r.createElement("button",{onClick:e.goToPrev,disabled:0===e.matchCount,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:s.A.t("common.previous")},r.createElement("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},r.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"}))),r.createElement("button",{onClick:e.goToNext,disabled:0===e.matchCount,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:s.A.t("common.next")},r.createElement("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},r.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"}))),r.createElement("button",{onClick:e.close,className:"p-1 rounded hover:bg-accent",title:s.A.t("common.close")},r.createElement("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},r.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})))):null}},56978:(e,t,n)=>{n.d(t,{C:()=>l});var r=n(12115),s=n(17196);function l(e,t){let[n,l]=(0,r.useState)(null),[a,o]=(0,r.useState)(!1);(0,r.useEffect)(()=>{let e=()=>{o(document.documentElement.classList.contains("dark"))};e();let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>t.disconnect()},[]);let i=(0,r.useMemo)(()=>e.join("\n"),[e]),c=`${i}:${t}:${a}`,u=(0,r.useMemo)(()=>n&&n.key===c?n.html:e.map(e=>(0,s.ZD)(e||" ")),[e,c,n]);return(0,r.useEffect)(()=>{if(0===e.length)return;let n=!1;return(async()=>{try{let r=await (0,s.kS)();if(n)return;let o=(0,s.sQ)(t),i=e.join("\n"),u=r.codeToTokens(i,{lang:o,theme:a?"github-dark":"github-light"}),d=[];for(let e=0;e<u.tokens.length;e++)if(d[e]=(0,s.b8)(u.tokens[e]),e%500==0&&e>0&&(await new Promise(e=>setTimeout(e,0)),n))return;l({key:c,html:d})}catch(e){console.error("Line highlight error:",e)}})(),()=>{n=!0}},[i,t,a]),u}},60938:(e,t,n)=>{n.d(t,{DZ:()=>c,Ft:()=>h,K9:()=>p,Nn:()=>w,OJ:()=>b,VK:()=>k,YW:()=>m,__:()=>y,dt:()=>v,eA:()=>g,eE:()=>f,gZ:()=>u,mP:()=>i,nM:()=>j,r6:()=>x,r9:()=>d});var r=n(49433),s=n(82680);let l=(e,t={})=>r.tryPromise({try:async()=>{let n=await fetch(e,t.init);if(t.passThroughStatuses&&t.passThroughStatuses.includes(n.status))return await n.json().catch(()=>({}));if(!n.ok){let e;try{e=(await n.json()).error}catch{}throw Error(e||`HTTP ${n.status}`)}return await n.json()},catch:t=>new s.uV({message:`GET ${e} failed`,cause:t})}),a=(e,t)=>r.tryPromise({try:async()=>{let n=await fetch(e,t),r=null;try{r=await n.json()}catch{}return{status:n.status,ok:n.ok,data:r}},catch:t=>new s.uV({message:`GET ${e} failed`,cause:t})}),o=(e,t)=>r.tryPromise({try:async()=>{let n=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!n.ok)throw Error(`HTTP ${n.status}`)},catch:t=>new s.uV({message:`POST ${e} failed`,cause:t})}),i=e=>l(`/api/files/init?cwd=${encodeURIComponent(e)}`),c=e=>l(`/api/files/index?cwd=${encodeURIComponent(e)}`),u=(e,t)=>l(`/api/files/readdir?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`),d=e=>l(`/api/files/recent?cwd=${encodeURIComponent(e)}`),m=(e,t,n)=>o("/api/files/recent",{cwd:e,file:t,...n??{}}),h=(e,t)=>o("/api/files/expanded",{cwd:e,paths:t}),f=(e,t)=>l(`/api/files/blame?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`).pipe(r.catchAll(e=>r.succeed({error:e.message}))),x=(e,t)=>a(`/api/files/stat?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`,{cache:"no-store"}),p=(e,t)=>a(`/api/files/text?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`,{cache:"no-store"}),g=e=>l(`/api/files/text?${e.toString()}`),b=e=>r.tryPromise({try:async()=>{let t=await fetch("/api/files/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),n=null;try{n=await t.json()}catch{}return{status:t.status,ok:t.ok,data:n}},catch:e=>new s.uV({message:"POST /api/files/save failed",cause:e})}),v=()=>l("/api/files/clipboard"),y=e=>r.tryPromise({try:async()=>{let t=await fetch("/api/files/clipboard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw Error(`HTTP ${t.status}`)},catch:e=>new s.uV({message:"POST /api/files/clipboard failed",cause:e})}),w=e=>r.tryPromise({try:async()=>{let t=await fetch("/api/files/paste",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),n=await t.json().catch(()=>null);if(!t.ok)throw Error(n?.error||`HTTP ${t.status}`);return n},catch:e=>new s.uV({message:"POST /api/files/paste failed",cause:e})}),k=e=>r.tryPromise({try:async()=>{let t=await fetch("/api/files/delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),n=await t.json().catch(()=>null);if(!t.ok)throw Error(n?.error||`HTTP ${t.status}`);return n},catch:e=>new s.uV({message:"POST /api/files/delete failed",cause:e})}),j=e=>l(`/api/file?path=${encodeURIComponent(e)}`)},65153:(e,t,n)=>{n.d(t,{u:()=>a});var r=n(12115),s=n(2111),l=n(48948);function a(e,t,n,a,o){let i=(0,r.useRef)(null),c=(0,r.useRef)(0),u=()=>{let e=`live-asst-${++c.current}`;return i.current=e,t(t=>[...t,{id:e,role:"assistant",content:"",isStreaming:!0}]),e},d=e=>{if("system"===e.type&&"init"===e.subtype)return void u();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}let n=i.current??u();t(t=>(0,l.F)(t,e,{engine:a,assistantId:n}))};(0,s.h)({url:e?`/ws/session-stream?sessionId=${encodeURIComponent(e)}`:"/ws/session-stream",enabled:n&&!!e,onMessage:e=>{if("run-snapshot"===e.type&&Array.isArray(e.events)){if("running"!==e.status)return void o?.onRunningChange?.(!1);let n=e.events.find(e=>e?.type==="user"&&e?._human),r=n?.message?.content,s="string"==typeof r?r:"";for(let n of(t(e=>{let t=e.filter(e=>!("string"==typeof e.id&&e.id.startsWith("live-")));if(s){let e=t[t.length-1];if(e&&"user"===e.role&&e.content===s)return t.slice(0,t.length-1)}return t}),i.current=null,c.current=0,e.events))d(n);o?.onRunningChange?.(!0)}else if("run-event"===e.type&&e.message){if("run-ended"===e.message.type){o?.onRunningChange?.(!1),o?.onComplete?.();return}d(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"),A=(0,s.useMemo)(()=>(0,f.X)(e,t),[e,t]),_=(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),H=(0,u.iN)(),W=(0,d.r)(),z=S&&!!N,{comments:U,addComment:K,updateComment:q,deleteComment:X,refresh:J}=(0,i._)({cwd:N||"",filePath:n}),[Z,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 A)("unchanged"===s.type||"added"===s.type)&&++r>=e&&r<=t&&n.push(s.content);return n.join("\n")}}),[er,es]=(0,s.useState)(null),[el,ea]=(0,s.useState)(null);(0,s.useEffect)(()=>{B(!0)},[]);let eo=(0,s.useMemo)(()=>{let e=new Set;for(let t of U)for(let n=t.startLine;n<=t.endLine;n++)e.add(n);return e},[U]),ei=(0,s.useMemo)(()=>{let e=new Map;for(let t of U){let n=t.endLine;e.has(n)||e.set(n,[]),e.get(n).push(t)}return e},[U]),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&&W&&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);W.sendMessage(s),await (0,c.RP)(N),J(),ea(null)}catch(e){console.error("Failed to send to AI:",e)}},[el,W,n,N,J]),ef=(0,s.useCallback)(async e=>{er&&(await K(er.range.start,er.range.end,e,er.selectedText),es(null))},[er,K]);(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<A.length;s++){let l=A[s];if("unchanged"===l.type){for(;e.length<t.length;)e.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});for(;t.length<e.length;)t.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});n++,r++,e.push({lineNum:n,content:l.content,type:"unchanged",originalIdx:s}),t.push({lineNum:r,content:l.content,type:"unchanged",originalIdx:s})}else"removed"===l.type?(n++,e.push({lineNum:n,content:l.content,type:"removed",originalIdx:s})):"added"===l.type&&(r++,t.push({lineNum:r,content:l.content,type:"added",originalIdx:s}))}for(;e.length<t.length;)e.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});for(;t.length<e.length;)t.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});return{leftLines:e,rightLines:t}},[A]),eg=(0,s.useMemo)(()=>A.map(e=>e.content),[A]),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:()=>_.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:_,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:_})]}),V&&H&&(0,l.createPortal)((0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(m.f,{floatingToolbarRef:ee,bumpRef:et,container:H,onAddComment:eu,onSendToAI:ed,onSearch:M?em:void 0,isChatLoading:W?.isLoading??!1}),er&&(0,r.jsx)(h.t,{x:er.x,y:er.y,range:er.range,lineSnapshot:er.lineSnapshot,container:H,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:H,onSubmit:eh,onClose:()=>ea(null),isChatLoading:W?.isLoading}),Z&&(0,r.jsx)(v.t,{x:Z.x,y:Z.y,comment:Z.comment,container:H,onClose:()=>Y(null),onUpdateComment:q,onDeleteComment:X})]}),H)]})}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:()=>b,JC:()=>d,M5:()=>c,QW:()=>f,Zr:()=>h,an:()=>g,em:()=>i,l1:()=>u,n_:()=>m,qD:()=>p,td:()=>o});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=()=>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})}),p=e=>r.gen(function*(){let t=yield*x();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*x();return"not-running"===l._tag?{_tag:"error",message:"Ollama started but cannot fetch models"}:l}),g=e=>l(`/api/file?path=${encodeURIComponent(e)}`),b=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]),A=(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:A,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})}}]);
5
+ ⚠️ ${n}`:`⚠️ ${n}`,isStreaming:!1}:e)}if("result"===t.type){let n="string"==typeof t.result?t.result.trim():"";return e.map(e=>e.id===s?{...e,content:!e.content&&n?n:e.content,isStreaming:!1,toolCalls:e.toolCalls?.map(e=>({...e,isLoading:!1}))}:e)}return e}},50860:(e,t,n)=>{n.d(t,{I:()=>o});var r=n(95155),s=n(12115),l=n(86957),a=n(60938);function o(e){let{refreshKey:t,className:n="h-full flex items-center justify-center p-4 bg-secondary",imgClassName:o="max-w-full max-h-full object-contain",alt:i}=e,c="absPath"in e&&"string"==typeof e.absPath,u=c?void 0:e.cwd,d=c?void 0:e.path,m=c?e.absPath:void 0,[h,f]=(0,s.useState)({kind:"loading"}),x=(0,s.useRef)(0);if((0,s.useEffect)(()=>{let e=++x.current;return f({kind:"loading"}),(async()=>{if(c){if(e!==x.current)return;f({kind:"ready",etag:null,size:0});return}let t=await l.t4.runPromiseExit((0,a.r6)(u,d));if(e!==x.current)return;if("Failure"===t._tag){let e="Fail"===t.cause._tag?t.cause.error:null,n=e?.cause;f({kind:"error",message:n instanceof Error?n.message:"Unknown error"});return}let n=t.value;if(!n.ok)return f({kind:"error",message:`stat failed (${n.status})`});let r=n.data;r&&r.exists?"too-large"===r.category?f({kind:"too-large",size:r.size??0}):"image"!==r.category?f({kind:"error",message:`Not an image (${r.category})`}):f({kind:"ready",etag:r.etag||`t-${r.mtimeMs??Date.now()}`,size:r.size??0}):f({kind:"missing"})})(),()=>{x.current++}},[c,u,d,m,t]),"loading"===h.kind)return(0,r.jsx)("div",{className:n,children:(0,r.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})});if("missing"===h.kind)return(0,r.jsx)("div",{className:n,children:(0,r.jsx)("div",{className:"text-sm text-muted-foreground",children:"File not found"})});if("too-large"===h.kind)return(0,r.jsx)("div",{className:n,children:(0,r.jsxs)("div",{className:"text-sm text-muted-foreground",children:["Image too large to preview (",Math.round(h.size/1024/1024)," MB)"]})});if("error"===h.kind)return(0,r.jsx)("div",{className:n,children:(0,r.jsx)("div",{className:"text-sm text-red-11",children:h.message})});let p=c?`/api/file?path=${encodeURIComponent(m)}&raw=true`:`/api/files/read?cwd=${encodeURIComponent(u)}&path=${encodeURIComponent(d)}&v=${encodeURIComponent(h.etag)}`;return(0,r.jsx)("div",{className:n,children:(0,r.jsx)("img",{src:p,alt:i??(d||m),className:o})})}},56045:(e,t,n)=>{n.d(t,{_:()=>o,o:()=>a});var r=n(12115),s=n(69809);let l="json-search-highlight-style";function a(e){let[t,n]=(0,r.useState)(!1),[s,a]=(0,r.useState)(""),[o,i]=(0,r.useState)(!1),[c,u]=(0,r.useState)(0),[d,m]=(0,r.useState)(0),h=(0,r.useRef)(null),f=(0,r.useRef)([]),x=(0,r.useCallback)(()=>{let t;CSS.highlights?.delete("json-search"),CSS.highlights?.delete("json-search-current"),f.current=[];let n=e.current;if(!n||!s){u(0),m(0);return}!function(){if(document.getElementById(l))return;let e=document.createElement("style");e.id=l,e.textContent="::highlight(json-search){background:rgba(217,119,6,.3)}::highlight(json-search-current){background:rgba(217,119,6,.5)}",document.head.appendChild(e)}();let r=n.textContent||"",a=o?s:s.toLowerCase(),i=o?r:r.toLowerCase(),c=[],d=0;for(;d<i.length;){let e=i.indexOf(a,d);if(-1===e)break;c.push([e,e+a.length]),d=e+1}if(0===c.length){u(0),m(0);return}let h=document.createTreeWalker(n,NodeFilter.SHOW_TEXT),x=0,p=0,g=[],b=null,v=0;for(;(t=h.nextNode())&&p<c.length;){let e=t.textContent?.length||0,n=x,r=x+e;for(;p<c.length;){let[e,s]=c[p];if(e>=r)break;if(!b)if(e>=n)(b=document.createRange()).setStart(t,e-n),v=s;else break;if(v<=r)b.setEnd(t,v-n),g.push(b),b=null,p++;else break}x=r}f.current=g,u(g.length),m(e=>g.length>0?Math.min(e,g.length-1):0),CSS.highlights&&g.length>0&&CSS.highlights.set("json-search",new Highlight(...g))},[e,s,o]),p=(0,r.useCallback)((e,t)=>{let n=e.getBoundingClientRect();(t.top<n.top||t.bottom>n.bottom)&&(e.scrollTop+=t.top-n.top-n.height/2+t.height/2)},[]),g=(0,r.useCallback)(t=>{CSS.highlights?.delete("json-search-current");let n=f.current[t];if(!n||!CSS.highlights)return;CSS.highlights.set("json-search-current",new Highlight(n));let r=n.getBoundingClientRect(),s=e.current?.parentElement;s&&p(s,r)},[e,p]);(0,r.useEffect)(()=>{queueMicrotask(()=>x())},[x]),(0,r.useEffect)(()=>{g(d)},[d,c,g]),(0,r.useEffect)(()=>{let t=e.current;if(!t||!s)return;let n=new MutationObserver(()=>x());return n.observe(t,{childList:!0,subtree:!0,characterData:!0}),()=>n.disconnect()},[e,s,x]),(0,r.useEffect)(()=>{t||(CSS.highlights?.delete("json-search"),CSS.highlights?.delete("json-search-current"),f.current=[])},[t]),(0,r.useEffect)(()=>()=>{CSS.highlights?.delete("json-search"),CSS.highlights?.delete("json-search-current")},[]);let b=(0,r.useCallback)(()=>{0!==c&&m(e=>(e+1)%c)},[c]),v=(0,r.useCallback)(()=>{0!==c&&m(e=>(e-1+c)%c)},[c]),y=(0,r.useCallback)(()=>{n(!0),setTimeout(()=>h.current?.focus(),0)},[]),w=(0,r.useCallback)(()=>{n(!1),a(""),m(0)},[]),k=(0,r.useCallback)(e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?v():b()),"Escape"===e.key&&(e.preventDefault(),w())},[b,v,w]);return{isVisible:t,query:s,setQuery:a,caseSensitive:o,setCaseSensitive:i,matchCount:c,currentIndex:d,searchInputRef:h,open:y,close:w,goToNext:b,goToPrev:v,handleKeyDown:k}}function o({search:e}){return e.isVisible?r.createElement("div",{className:"flex-shrink-0 flex items-center gap-2 px-3 py-2 bg-secondary border-b border-border"},r.createElement("input",{ref:e.searchInputRef,type:"text",value:e.query,onChange:t=>e.setQuery(t.target.value),onKeyDown:e.handleKeyDown,placeholder:s.A.t("codeViewer.searchPlaceholder"),className:"flex-1 max-w-xs px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),r.createElement("button",{onClick:()=>e.setCaseSensitive(e=>!e),className:`px-2 py-1 text-xs font-mono rounded border transition-colors ${e.caseSensitive?"bg-brand text-white border-brand":"border-border text-muted-foreground hover:bg-accent"}`,title:s.A.t("codeViewer.caseSensitive")},"Aa"),r.createElement("span",{className:"text-xs text-muted-foreground"},e.matchCount>0?`${e.currentIndex+1}/${e.matchCount}`:s.A.t("common.noMatch")),r.createElement("button",{onClick:e.goToPrev,disabled:0===e.matchCount,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:s.A.t("common.previous")},r.createElement("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},r.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"}))),r.createElement("button",{onClick:e.goToNext,disabled:0===e.matchCount,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:s.A.t("common.next")},r.createElement("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},r.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"}))),r.createElement("button",{onClick:e.close,className:"p-1 rounded hover:bg-accent",title:s.A.t("common.close")},r.createElement("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},r.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})))):null}},56978:(e,t,n)=>{n.d(t,{C:()=>l});var r=n(12115),s=n(17196);function l(e,t){let[n,l]=(0,r.useState)(null),[a,o]=(0,r.useState)(!1);(0,r.useEffect)(()=>{let e=()=>{o(document.documentElement.classList.contains("dark"))};e();let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>t.disconnect()},[]);let i=(0,r.useMemo)(()=>e.join("\n"),[e]),c=`${i}:${t}:${a}`,u=(0,r.useMemo)(()=>n&&n.key===c?n.html:e.map(e=>(0,s.ZD)(e||" ")),[e,c,n]);return(0,r.useEffect)(()=>{if(0===e.length)return;let n=!1;return(async()=>{try{let r=await (0,s.kS)();if(n)return;let o=(0,s.sQ)(t),i=e.join("\n"),u=r.codeToTokens(i,{lang:o,theme:a?"github-dark":"github-light"}),d=[];for(let e=0;e<u.tokens.length;e++)if(d[e]=(0,s.b8)(u.tokens[e]),e%500==0&&e>0&&(await new Promise(e=>setTimeout(e,0)),n))return;l({key:c,html:d})}catch(e){console.error("Line highlight error:",e)}})(),()=>{n=!0}},[i,t,a]),u}},60938:(e,t,n)=>{n.d(t,{DZ:()=>c,Ft:()=>h,K9:()=>p,Nn:()=>w,OJ:()=>b,VK:()=>k,YW:()=>m,__:()=>y,dt:()=>v,eA:()=>g,eE:()=>f,gZ:()=>u,mP:()=>i,nM:()=>j,r6:()=>x,r9:()=>d});var r=n(49433),s=n(82680);let l=(e,t={})=>r.tryPromise({try:async()=>{let n=await fetch(e,t.init);if(t.passThroughStatuses&&t.passThroughStatuses.includes(n.status))return await n.json().catch(()=>({}));if(!n.ok){let e;try{e=(await n.json()).error}catch{}throw Error(e||`HTTP ${n.status}`)}return await n.json()},catch:t=>new s.uV({message:`GET ${e} failed`,cause:t})}),a=(e,t)=>r.tryPromise({try:async()=>{let n=await fetch(e,t),r=null;try{r=await n.json()}catch{}return{status:n.status,ok:n.ok,data:r}},catch:t=>new s.uV({message:`GET ${e} failed`,cause:t})}),o=(e,t)=>r.tryPromise({try:async()=>{let n=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!n.ok)throw Error(`HTTP ${n.status}`)},catch:t=>new s.uV({message:`POST ${e} failed`,cause:t})}),i=e=>l(`/api/files/init?cwd=${encodeURIComponent(e)}`),c=e=>l(`/api/files/index?cwd=${encodeURIComponent(e)}`),u=(e,t)=>l(`/api/files/readdir?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`),d=e=>l(`/api/files/recent?cwd=${encodeURIComponent(e)}`),m=(e,t,n)=>o("/api/files/recent",{cwd:e,file:t,...n??{}}),h=(e,t)=>o("/api/files/expanded",{cwd:e,paths:t}),f=(e,t)=>l(`/api/files/blame?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`).pipe(r.catchAll(e=>r.succeed({error:e.message}))),x=(e,t)=>a(`/api/files/stat?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`,{cache:"no-store"}),p=(e,t)=>a(`/api/files/text?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`,{cache:"no-store"}),g=e=>l(`/api/files/text?${e.toString()}`),b=e=>r.tryPromise({try:async()=>{let t=await fetch("/api/files/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),n=null;try{n=await t.json()}catch{}return{status:t.status,ok:t.ok,data:n}},catch:e=>new s.uV({message:"POST /api/files/save failed",cause:e})}),v=()=>l("/api/files/clipboard"),y=e=>r.tryPromise({try:async()=>{let t=await fetch("/api/files/clipboard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw Error(`HTTP ${t.status}`)},catch:e=>new s.uV({message:"POST /api/files/clipboard failed",cause:e})}),w=e=>r.tryPromise({try:async()=>{let t=await fetch("/api/files/paste",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),n=await t.json().catch(()=>null);if(!t.ok)throw Error(n?.error||`HTTP ${t.status}`);return n},catch:e=>new s.uV({message:"POST /api/files/paste failed",cause:e})}),k=e=>r.tryPromise({try:async()=>{let t=await fetch("/api/files/delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),n=await t.json().catch(()=>null);if(!t.ok)throw Error(n?.error||`HTTP ${t.status}`);return n},catch:e=>new s.uV({message:"POST /api/files/delete failed",cause:e})}),j=e=>l(`/api/file?path=${encodeURIComponent(e)}`)},65153:(e,t,n)=>{n.d(t,{u:()=>a});var r=n(12115),s=n(2111),l=n(48948);function a(e,t,n,a,o){let i=(0,r.useRef)(null),c=(0,r.useRef)(0),u=()=>{let e=`live-asst-${++c.current}`;return i.current=e,t(t=>[...t,{id:e,role:"assistant",content:"",isStreaming:!0}]),e},d=e=>{if("system"===e.type&&"init"===e.subtype)return void u();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}let n=i.current??u();t(t=>(0,l.F)(t,e,{engine:a,assistantId:n}))};(0,s.h)({url:e?`/ws/session-stream?sessionId=${encodeURIComponent(e)}`:"/ws/session-stream",enabled:n&&!!e,onMessage:e=>{if("run-snapshot"===e.type&&Array.isArray(e.events)){if("running"!==e.status)return void o?.onRunningChange?.(!1);let n=e.events.find(e=>e?.type==="user"&&e?._human),r=n?.message?.content,s="string"==typeof r?r:"",l=new Set,a=new Set;for(let t of e.events){let e=t?.uuid;if("string"==typeof e&&l.add(e),t?.type==="assistant"&&Array.isArray(t.message?.content))for(let e of t.message.content)e?.name&&"string"==typeof e.id&&a.add(e.id)}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,e.events))d(n);o?.onRunningChange?.(!0)}else if("run-event"===e.type&&e.message){if("run-ended"===e.message.type){o?.onRunningChange?.(!1),o?.onComplete?.();return}d(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"),A=(0,s.useMemo)(()=>(0,f.X)(e,t),[e,t]),_=(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),H=(0,u.iN)(),W=(0,d.r)(),z=S&&!!N,{comments:U,addComment:K,updateComment:q,deleteComment:X,refresh:J}=(0,i._)({cwd:N||"",filePath:n}),[Z,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 A)("unchanged"===s.type||"added"===s.type)&&++r>=e&&r<=t&&n.push(s.content);return n.join("\n")}}),[er,es]=(0,s.useState)(null),[el,ea]=(0,s.useState)(null);(0,s.useEffect)(()=>{B(!0)},[]);let eo=(0,s.useMemo)(()=>{let e=new Set;for(let t of U)for(let n=t.startLine;n<=t.endLine;n++)e.add(n);return e},[U]),ei=(0,s.useMemo)(()=>{let e=new Map;for(let t of U){let n=t.endLine;e.has(n)||e.set(n,[]),e.get(n).push(t)}return e},[U]),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&&W&&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);W.sendMessage(s),await (0,c.RP)(N),J(),ea(null)}catch(e){console.error("Failed to send to AI:",e)}},[el,W,n,N,J]),ef=(0,s.useCallback)(async e=>{er&&(await K(er.range.start,er.range.end,e,er.selectedText),es(null))},[er,K]);(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<A.length;s++){let l=A[s];if("unchanged"===l.type){for(;e.length<t.length;)e.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});for(;t.length<e.length;)t.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});n++,r++,e.push({lineNum:n,content:l.content,type:"unchanged",originalIdx:s}),t.push({lineNum:r,content:l.content,type:"unchanged",originalIdx:s})}else"removed"===l.type?(n++,e.push({lineNum:n,content:l.content,type:"removed",originalIdx:s})):"added"===l.type&&(r++,t.push({lineNum:r,content:l.content,type:"added",originalIdx:s}))}for(;e.length<t.length;)e.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});for(;t.length<e.length;)t.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});return{leftLines:e,rightLines:t}},[A]),eg=(0,s.useMemo)(()=>A.map(e=>e.content),[A]),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:()=>_.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:_,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:_})]}),V&&H&&(0,l.createPortal)((0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(m.f,{floatingToolbarRef:ee,bumpRef:et,container:H,onAddComment:eu,onSendToAI:ed,onSearch:M?em:void 0,isChatLoading:W?.isLoading??!1}),er&&(0,r.jsx)(h.t,{x:er.x,y:er.y,range:er.range,lineSnapshot:er.lineSnapshot,container:H,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:H,onSubmit:eh,onClose:()=>ea(null),isChatLoading:W?.isLoading}),Z&&(0,r.jsx)(v.t,{x:Z.x,y:Z.y,comment:Z.comment,container:H,onClose:()=>Y(null),onUpdateComment:q,onDeleteComment:X})]}),H)]})}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]),A=(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:A,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})}}]);